1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef YACSPRS_LINK_H
21 #define YACSPRS_LINK_H
23 #include <guiObservers.hxx>
25 #include "QxGraph_ActiveItem.h"
30 class SUIT_ResourceMgr;
33 class YACSPrs_InOutPort;
34 class YACSPrs_LabelPort;
35 class YACSPrs_ElementaryNode;
37 class YACSPrs_Link : public QObject {
41 YACSPrs_Link( SUIT_ResourceMgr*, QCanvas* theCanvas);
42 virtual ~YACSPrs_Link();
48 void setCanvas(QCanvas* theCanvas);
50 std::list<QPoint> getPoints() const { return myPoints; }
51 void setPoints(std::list<QPoint> thePoints) { myPoints = thePoints; }
52 void updatePoints(QCanvasItem* thePointItem);
54 bool isEmptyPrs() const { return myPrs.isEmpty(); }
56 virtual void setHilighted(bool state);
57 virtual void setSelected(bool state);
58 void setColor(const QColor& theColor);
60 virtual void moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints=false, QRect theArea=QRect()) {}
61 virtual void moveByPort(YACSPrs_Port* thePort, int dx, int dy) {}
63 void setSelectedObject(QCanvasItem* theItem, const QPoint& thePoint);
65 virtual QString getToolTipText() const;
67 bool isFirst(QCanvasEllipse* thePoint);
68 bool isLast(QCanvasEllipse* thePoint);
70 QCanvasItem* getFirstPoint() const { return myPrs.first(); }
71 QCanvasItem* getLastPoint() const { return myPrs.last(); }
73 void setMyZ(double z);
80 virtual void remove();
85 QPoint getConnectionPoint(YACSPrs_Port* thePort);
88 void addPoint(const QPoint& thePoint, const int& theIndex = -1);
89 virtual void createPrs();
91 SUIT_ResourceMgr* myMgr;
93 QCanvasItemList myPrs;
95 std::list<QPoint> myPoints; //for read/write from/to xml
103 QCanvasItem* mySelectedItem;
104 QPoint mySelectedPoint;
109 class YACSPrs_PortLink : public YACSPrs_Link, public YACS::HMI::GuiObserver {
112 YACSPrs_PortLink(SUIT_ResourceMgr* theMgr, QCanvas* theCanvas, YACSPrs_InOutPort* theInputPort, YACSPrs_InOutPort* theOutputPort);
113 virtual ~YACSPrs_PortLink();
115 virtual void select( bool isSelected );
116 virtual void update( YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
118 YACS::HMI::Subject* getSubject() const;
120 virtual void moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints=false, QRect theArea=QRect());
121 virtual void moveByPort(YACSPrs_Port* thePort, int dx, int dy);
123 virtual QString getToolTipText() const;
125 virtual void remove();
127 YACSPrs_InOutPort* getInputPort() const { return myInputPort; }
128 void setInputPort(YACSPrs_InOutPort* thePort) { myInputPort = thePort; }
130 YACSPrs_InOutPort* getOutputPort() const { return myOutputPort; }
131 void setOutputPort(YACSPrs_InOutPort* thePort) { myOutputPort = thePort; }
133 virtual void setHilighted(bool state);
134 virtual void setSelected(bool state);
137 virtual void createPrs();
140 YACSPrs_InOutPort* myInputPort;
141 YACSPrs_InOutPort* myOutputPort;
144 class YACSPrs_LabelLink : public YACSPrs_Link {
147 YACSPrs_LabelLink(SUIT_ResourceMgr* theMgr, QCanvas* theCanvas, YACSPrs_LabelPort* theOutputPort, YACSPrs_ElementaryNode* theSlaveNode);
148 virtual ~YACSPrs_LabelLink();
150 virtual void moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints=false, QRect theArea=QRect());
151 virtual void moveByPort(YACSPrs_Port* thePort, int dx, int dy);
153 void moveByNode(YACSPrs_ElementaryNode* theNode);
154 void moveByNode(YACSPrs_ElementaryNode* theNode, int dx, int dy);
156 virtual QString getToolTipText() const;
158 virtual void remove();
160 YACSPrs_LabelPort* getOutputPort() const { return myOutputPort; }
161 void setOutputPort(YACSPrs_LabelPort* thePort) { myOutputPort = thePort; }
163 YACSPrs_ElementaryNode* getSlaveNode() const { return mySlaveNode; }
164 void setSlaveNode(YACSPrs_ElementaryNode* theNode) { mySlaveNode = theNode; }
166 virtual void setHilighted(bool state);
167 virtual void setSelected(bool state);
169 QPoint getConnectionMasterPoint();
172 virtual void createPrs();
175 YACSPrs_LabelPort* myOutputPort;
176 YACSPrs_ElementaryNode* mySlaveNode;
181 /*! Link point presentation.
183 class YACSPrs_Point : public QxGraph_ActiveItem, public QCanvasEllipse {
186 YACSPrs_Point(QCanvas* theCanvas, YACSPrs_Link* theLink, const int& theIndex = -1);
189 /* reimplement functions from QxGraph_ActiveItem */
190 virtual bool isMoveable();
191 virtual void beforeMoving() {}
192 virtual void afterMoving() {}
193 virtual void hilight(const QPoint& theMousePos, const bool toHilight = true);
194 virtual void select(const QPoint& theMousePos, const bool toSelect = true);
195 virtual void showPopup(QWidget* theParent, QMouseEvent* theEvent, const QPoint& theMousePos = QPoint());
196 virtual QString getToolTipText(const QPoint& theMousePos, QRect& theRect) const;
197 virtual bool arePartsOfOtherItem(QxGraph_ActiveItem* theSecondItem);
199 YACSPrs_Link* getLink() const { return myLink; }
200 void setIndex(int theIndex) { myIndex = theIndex; }
201 int getIndex() const { return myIndex; }
203 void setInEdge(YACSPrs_Edge* theEdge);
204 void setOutEdge(YACSPrs_Edge* theEdge);
206 void moveBy(double dx, double dy);
207 void setColor(const QColor& theColor);
209 void setMoving(bool b) { myMoving = b; }
210 bool isMoving() const { return myMoving; }
212 void setSelected(bool b) { mySelected = b; }
214 virtual int rtti() const;
217 YACSPrs_Link* myLink;
221 YACSPrs_Edge* myInEdge;
222 YACSPrs_Edge* myOutEdge;
227 /*! Link edge presentation.
229 class YACSPrs_Edge : public QxGraph_ActiveItem, public QCanvasLine {
232 YACSPrs_Edge(QCanvas* theCanvas, YACSPrs_Link* theLink);
235 /* reimplement functions from QxGraph_ActiveItem */
236 virtual bool isMoveable();
237 virtual void beforeMoving() {}
238 virtual void afterMoving() {}
239 virtual void hilight(const QPoint& theMousePos, const bool toHilight = true);
240 virtual void select(const QPoint& theMousePos, const bool toSelect = true);
241 virtual void showPopup(QWidget* theParent, QMouseEvent* theEvent, const QPoint& theMousePos = QPoint());
242 virtual QString getToolTipText(const QPoint& theMousePos, QRect& theRect) const;
243 virtual bool arePartsOfOtherItem(QxGraph_ActiveItem* theSecondItem);
244 void setCanvas(QCanvas* theCanvas);
246 YACSPrs_Link* getLink() const { return myLink; }
248 void setFromPoint(YACSPrs_Point* thePoint);
249 void setToPoint(YACSPrs_Point* thePoint);
251 void moveBy(double dx, double dy);
252 void setColor(const QColor& theColor);
254 void setMoving(bool b) { myMoving = b; }
255 bool isMoving() const { return myMoving; }
257 void setSelected(bool b) { mySelected = b; }
258 virtual void setArrow();
259 virtual void setVisible ( bool ) ;
260 virtual void setZ ( double z );
262 virtual int rtti() const;
266 YACSPrs_Link* myLink;
268 // for moving segment of link
269 YACSPrs_Point* myStartPoint;
270 YACSPrs_Point* myEndPoint;
273 QCanvasPolygon* myArrow;