Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / prs / YACSPrs_Link.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef YACSPRS_LINK_H
21 #define YACSPRS_LINK_H
22
23 #include <guiObservers.hxx>
24
25 #include "QxGraph_ActiveItem.h"
26
27 #include <qcanvas.h>
28 #include <qobject.h>
29
30 class SUIT_ResourceMgr;
31
32 class YACSPrs_Port;
33 class YACSPrs_InOutPort;
34 class YACSPrs_LabelPort;
35 class YACSPrs_ElementaryNode;
36
37 class YACSPrs_Link : public QObject {
38  Q_OBJECT
39
40  public:
41   YACSPrs_Link( SUIT_ResourceMgr*, QCanvas* theCanvas);
42   virtual ~YACSPrs_Link();
43   
44   void show();
45   void hide();
46   void merge();
47
48   void setCanvas(QCanvas* theCanvas);
49
50   std::list<QPoint> getPoints() const { return myPoints; }
51   void              setPoints(std::list<QPoint> thePoints) { myPoints = thePoints; }
52   void              updatePoints(QCanvasItem* thePointItem);
53
54   bool isEmptyPrs() const { return myPrs.isEmpty(); }
55   
56   virtual void setHilighted(bool state);
57   virtual void setSelected(bool state);
58   void setColor(const QColor& theColor);
59   
60   virtual void moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints=false, QRect theArea=QRect()) {}
61   virtual void moveByPort(YACSPrs_Port* thePort, int dx, int dy) {}
62   
63   void setSelectedObject(QCanvasItem* theItem, const QPoint& thePoint);
64     
65   virtual QString getToolTipText() const;
66   
67   bool isFirst(QCanvasEllipse* thePoint);
68   bool isLast(QCanvasEllipse* thePoint);
69
70   QCanvasItem* getFirstPoint() const { return myPrs.first(); }
71   QCanvasItem* getLastPoint() const { return myPrs.last(); }
72
73   void setMyZ(double z);
74   double getMyZ();
75
76   void setZ(double z);
77   double z();
78
79  public slots:
80   virtual void remove();
81  
82   void addPoint();
83   void removePoint();
84
85   QPoint getConnectionPoint(YACSPrs_Port* thePort);
86
87  protected:
88   void addPoint(const QPoint& thePoint, const int& theIndex = -1);
89   virtual void createPrs();
90
91   SUIT_ResourceMgr* myMgr;
92   QCanvas*          myCanvas;
93   QCanvasItemList   myPrs;
94
95   std::list<QPoint> myPoints; //for read/write from/to xml
96   
97   QColor myColor;
98   
99  private:
100   bool myHilighted;
101   bool mySelected;
102
103   QCanvasItem* mySelectedItem;
104   QPoint       mySelectedPoint;
105   
106   double myZ;
107 };
108
109 class YACSPrs_PortLink : public YACSPrs_Link, public YACS::HMI::GuiObserver {
110
111  public:
112   YACSPrs_PortLink(SUIT_ResourceMgr* theMgr, QCanvas* theCanvas, YACSPrs_InOutPort* theInputPort, YACSPrs_InOutPort* theOutputPort);
113   virtual ~YACSPrs_PortLink();
114
115   virtual void select( bool isSelected );
116   virtual void update( YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
117
118   YACS::HMI::Subject* getSubject() const;
119
120   virtual void moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints=false, QRect theArea=QRect());
121   virtual void moveByPort(YACSPrs_Port* thePort, int dx, int dy);
122
123   virtual QString getToolTipText() const;
124
125   virtual void remove();
126
127   YACSPrs_InOutPort* getInputPort() const { return myInputPort; }
128   void               setInputPort(YACSPrs_InOutPort* thePort) { myInputPort = thePort; }
129
130   YACSPrs_InOutPort* getOutputPort() const { return myOutputPort; }
131   void               setOutputPort(YACSPrs_InOutPort* thePort) { myOutputPort = thePort; }
132
133   virtual void setHilighted(bool state);
134   virtual void setSelected(bool state);
135
136  protected:
137   virtual void createPrs();
138   
139  private:
140   YACSPrs_InOutPort* myInputPort;
141   YACSPrs_InOutPort* myOutputPort;
142 };
143
144 class YACSPrs_LabelLink : public YACSPrs_Link {
145
146  public:
147   YACSPrs_LabelLink(SUIT_ResourceMgr* theMgr, QCanvas* theCanvas, YACSPrs_LabelPort* theOutputPort, YACSPrs_ElementaryNode* theSlaveNode);
148   virtual ~YACSPrs_LabelLink();
149
150   virtual void moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints=false, QRect theArea=QRect());
151   virtual void moveByPort(YACSPrs_Port* thePort, int dx, int dy);
152
153   void moveByNode(YACSPrs_ElementaryNode* theNode);
154   void moveByNode(YACSPrs_ElementaryNode* theNode, int dx, int dy);
155
156   virtual QString getToolTipText() const;
157
158   virtual void remove();
159
160   YACSPrs_LabelPort*      getOutputPort() const { return myOutputPort; }
161   void                    setOutputPort(YACSPrs_LabelPort* thePort) { myOutputPort = thePort; }
162
163   YACSPrs_ElementaryNode* getSlaveNode() const { return mySlaveNode; }
164   void                    setSlaveNode(YACSPrs_ElementaryNode* theNode) { mySlaveNode = theNode; }
165
166   virtual void setHilighted(bool state);
167   virtual void setSelected(bool state);
168   
169   QPoint getConnectionMasterPoint();
170
171  protected:
172   virtual void createPrs();
173   
174  private:
175   YACSPrs_LabelPort*      myOutputPort;
176   YACSPrs_ElementaryNode* mySlaveNode;
177 };
178
179 class YACSPrs_Edge;
180
181 /*! Link point presentation.
182  */
183 class YACSPrs_Point : public QxGraph_ActiveItem, public QCanvasEllipse {
184
185   public:
186     YACSPrs_Point(QCanvas* theCanvas, YACSPrs_Link* theLink, const int& theIndex = -1);
187     ~YACSPrs_Point() {}
188
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);
198     
199     YACSPrs_Link* getLink() const { return myLink; }
200     void setIndex(int theIndex) { myIndex = theIndex; }
201     int getIndex() const { return myIndex; }
202
203     void setInEdge(YACSPrs_Edge* theEdge);
204     void setOutEdge(YACSPrs_Edge* theEdge);
205
206     void moveBy(double dx, double dy);
207     void setColor(const QColor& theColor);
208
209     void setMoving(bool b) { myMoving = b; }
210     bool isMoving() const { return myMoving; }
211
212     void setSelected(bool b) { mySelected = b; }
213
214     virtual int rtti() const;
215
216   private:
217     YACSPrs_Link* myLink;
218     int myIndex;
219     bool myMoving;
220
221     YACSPrs_Edge* myInEdge;
222     YACSPrs_Edge* myOutEdge;
223
224     bool mySelected;
225 };
226
227 /*! Link edge presentation.
228  */
229 class YACSPrs_Edge : public QxGraph_ActiveItem, public QCanvasLine {
230
231   public:
232     YACSPrs_Edge(QCanvas* theCanvas, YACSPrs_Link* theLink);
233     ~YACSPrs_Edge();
234
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);
245
246     YACSPrs_Link* getLink() const { return myLink; }
247
248     void setFromPoint(YACSPrs_Point* thePoint);
249     void setToPoint(YACSPrs_Point* thePoint);
250
251     void moveBy(double dx, double dy);
252     void setColor(const QColor& theColor);
253
254     void setMoving(bool b) { myMoving = b; }
255     bool isMoving() const { return myMoving; }
256
257     void setSelected(bool b) { mySelected = b; }
258     virtual void setArrow();
259     virtual void setVisible ( bool ) ;
260     virtual void setZ ( double z );
261
262     virtual int rtti() const;
263
264   private:
265     bool myMoving;
266     YACSPrs_Link* myLink;
267
268     // for moving segment of link
269     YACSPrs_Point* myStartPoint;
270     YACSPrs_Point* myEndPoint;
271
272     bool mySelected;
273     QCanvasPolygon* myArrow;
274 };
275
276 #endif