1 #ifndef __ABSTRACTBOXITEM_H__
2 #define __ABSTRACTBOXITEM_H__
8 #include <QGraphicsItem>
12 #include "Parameters.h"
16 class ConnectedInterface;
18 #define ABI_TO_BI(ptr) ((BoxItem*)ptr)
19 #define ABI_TO_GI(ptr) ((GroupItem*)ptr)
20 #define ABI_TO_SI(ptr) ((StimuliItem*)ptr)
22 class AbstractBoxItem : public QGraphicsItem {
26 enum BorderType { NoBorder = 0, BorderEast, BorderNorth, BorderWest, BorderSouth, CornerSouthEast, Title};
27 enum ChangeType { Creation = 0, Resize, InterfaceMove };
32 static int Interfaces;
35 AbstractBoxItem(AbstractBlock *_refBlock, Dispatcher *_dispatcher, Parameters *_params, int _lock = NoLock, QGraphicsItem* parent = Q_NULLPTR);
36 AbstractBoxItem(Dispatcher *_dispatcher, Parameters *_params, int _lock = NoLock, QGraphicsItem* parent = Q_NULLPTR);
38 virtual ~AbstractBoxItem();
41 inline AbstractBlock* getRefBlock() { return refBlock; }
42 inline int getWidth() { return boxWidth;}
43 inline int getHeight() { return boxHeight;}
44 inline int getTotalWidth() { return totalWidth;}
45 inline int getTotalHeight() { return totalHeight; }
46 inline QList<InterfaceItem* > getInterfaces() { return interfaces; }
47 inline InterfaceItem *getCurrentInterface() { return currentInterface; }
48 inline int getId(){ return id; }
49 inline GroupScene* getScene() { return (GroupScene*)(scene()); }
50 inline int getIfaceMargin() { return ifaceMargin; }
51 inline int getNameMargin() { return nameMargin; }
52 inline QPointF getOriginPoint() { return originPoint; }
53 inline int getMinimumBoxWidth() { return minimumBoxWidth; }
54 inline int getMinimumBoxHeight() { return minimumBoxHeight; }
57 void setRefBlock(AbstractBlock* _refBlock);
58 inline void setId(int _id){ id = _id; }
59 inline void setSelected(bool _selected) { selected = _selected; }
60 inline void setVisible(bool state) { visible = state; }
61 void setRstClkVisible(bool b);
62 void setWishboneVisible(bool b);
63 void setDimension(int x, int y);
64 inline void setWidth(int width) { boxWidth = width; }
65 inline void setHeight(int height) {boxHeight = height; }
66 inline void setCurrentInterface(InterfaceItem* iface) { currentInterface = iface; }
67 inline void setLock(int _lock) { lock = _lock; }
68 inline void lockPosition() { lock = lock | Position; }
69 inline void unlockPosition() { lock = (lock&Position)^lock; }
70 inline void lockDimension() { lock = lock | Dimension; }
71 inline void unlockDimension() { lock = (lock&Dimension)^lock; }
72 inline void lockInterfaces() { lock = lock | Interfaces; }
73 inline void unlockInterfaces() { lock = (lock&Interfaces)^lock; }
74 inline void lockNames() { lock = lock | Names; }
75 inline void unlockNames() { lock = (lock&Names)^lock; }
78 virtual bool isBoxItem();
79 virtual bool isGroupItem();
80 virtual bool isStimuliItem();
81 inline bool isVisible() { return visible; }
82 inline bool isSelected() { return selected; }
83 inline bool isRstClkVisible(){ return rstClkVisible;}
84 inline bool isWishboneVisible(){ return wishboneVisible;}
85 bool isInterfaces(int orientation) const;
86 inline bool isPositionLock() { return (lock&Position)!=0?true:false; }
87 inline bool isDimensionLock() { return (lock&Dimension)!=0?true:false; }
88 inline bool isInterfacesLock() { return (lock&Interfaces)!=0?true:false; }
89 inline bool isNamesLock() { return (lock&Names)!=0?true:false; }
91 QRectF boundingRectInScene();
92 virtual void nameChanged() = 0; // called when an interface or box name have changed
93 void addInterfaceItem(InterfaceItem* i, bool resetPosition = false);
94 void removeInterfaceItem(InterfaceItem* i);
95 void resetInterfaceItemsPosition();
97 * \brief moveInterfaceTo
98 * \param pos the new position (in scene) of the interface
100 * This method is called when user moves an InterfaceItem.
101 * see BoxItem::mouseMoveEvent() and GroupItem::mouseMoveEvent()
103 void moveInterfaceItemTo(QPointF pos);
105 * \brief updateInterfacesAndConnections
107 * This method allows to recompute the absolute position of the interfaces of this box
108 * taking into account their relative position (see positionRatio atribute) in the width/height
109 * of the box border they are located on. It allows update the shape of all ConnectionItem
110 * connected to this box.
112 * CAUTION: this method supposes that before its call, a call to prepareGeometryChange() hase been
113 * done for the BoxItem that owns this InterfaceItem, so that the scene will readraw automatically
114 * the BoxItem. For the connections, the call to prepareGeometryChange() is done within setPath()
115 * that is called in this method. Thus, there is no need to call update() after the termination of
118 void updateInterfaceAndConnectionItems();
120 InterfaceItem *searchInterfaceItemByName(QString name);
121 InterfaceItem *searchInterfaceItemByRef(ConnectedInterface* ref);
122 InterfaceItem* getInterfaceItemFromCursor(qreal x, qreal y);
124 QRectF boundingRect() const;
127 Dispatcher *dispatcher;
129 QList<InterfaceItem*> interfaces;
130 /* NOTE : the reference block may be a FunctionalBlock or a GroupBlock, depending on the fact
131 that the real instace will be of FunctionalBlock or GroupBlock
133 AbstractBlock *refBlock;
135 InterfaceItem* currentInterface; // currently clicked interface in ItemEdition mode
137 BorderType currentBorder; // which border cursor is on
138 QPointF cursorPosition;
141 int boxWidth; // the width of the main box (without interface, title, ...)
142 int boxHeight; // the height of the main box (without interface, title, ...)
143 int minimumBoxWidth; // minimum width of the main box: may be recomputed if position/number of interface changes
144 int minimumBoxHeight; // minimum height of the main box: may be recomputed if position/number of interface changes
145 int totalWidth; // width and heigth taking into account interfaces,title, ...
147 int nameWidth; // the width of the box (group or block) name in Arial 10
148 int nameHeight; // the height of the name in Arial 10
149 int nameMargin; // the margin around each side of the name
150 int ifaceMargin; // the margin around each side of interfaces' name
151 QPointF originPoint; // the left-top point that is the origin of the bounding box, in the item coordinates
155 bool visible; //! true if the box is shown
156 bool rstClkVisible; //! true if clock/reset interfaces are visible
157 bool wishboneVisible; //! true if wishbone interfaces are visible
159 QPointF currentPosition; // the start point for resize, i.e. the position of the lef-top corner of the box, in the scene coordinates
161 virtual void updateMinimumSize() = 0; // modify the minimum size
162 virtual bool updateGeometry(ChangeType type) = 0; // modify the originPoint and the total dimension
165 /* pure virtual method inherited from QGraphicsItem :
166 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) =0;
167 virtual QRectF boundingRect() const =0;
170 void createInterfaceItems(Parameters::Direction posInputs = Parameters::West, Parameters::Direction posOutputs = Parameters::East, Parameters::Direction posBidirs = Parameters::South);
171 int nbInterfacesByOrientation(int orientation);
174 #endif // __ABSTRACTBOXITEM_H__