Salome HOME
8dc31b792ea9b4048516a20378f52cdeb0cf42de
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasLink.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SUPERV SUPERVGUI : GUI for Supervisor component
23 //  File   : SUPERVGUI_CanvasLink.h
24 //  Author : Natalia KOPNOVA
25 //  Module : SUPERV
26 //
27 #ifndef SUPERVGUI_CanvasLink_H
28 #define SUPERVGUI_CanvasLink_H
29
30 #include "SUPERVGUI_Def.h"
31 #include <qcanvas.h>
32 #include <qvaluevector.h>
33
34 class SUPERVGUI_Main;
35 class SUPERVGUI_CanvasPort;
36
37 class SUPERVGUI_CanvasLink : public QObject {
38   Q_OBJECT
39
40   public:
41     SUPERVGUI_CanvasLink(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Link_ptr theLink=0);
42     virtual ~SUPERVGUI_CanvasLink();
43
44     void show();
45     void merge();
46
47     void setHilighted(bool state);
48     void setColor(const QColor& theColor);
49
50     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort);
51     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort, int dx, int dy);
52
53     SUPERV_Link getEngine() const { return myLink; }
54     SUPERVGUI_Main* getMain() const { return myMain; }
55
56     SUPERVGUI_CanvasPort* getInputPort() const { return myInputPort; }
57     SUPERVGUI_CanvasPort* getOutputPort() const { return myOutputPort; }
58
59     void setSelectedObject(QCanvasItem* theItem, const QPoint& thePoint);
60     virtual QPopupMenu* getPopupMenu(QWidget* theParent);
61
62     QString getToolTipText() const;
63
64   signals:
65     void objectCreatedDeleted(); // mkr : PAL8237
66
67   public slots:
68     virtual void remove();
69     void addPoint();
70     void removePoint();
71
72   protected:
73     void addPoint(const QPoint& thePoint, const int& theIndex = -1);
74
75     QColor myColor;
76     QCanvasItemList myPrs;
77
78   private:
79     void createPrs();
80
81     SUPERV_Link     myLink;
82     SUPERVGUI_Main* myMain;
83
84     SUPERVGUI_CanvasPort* myInputPort;
85     SUPERVGUI_CanvasPort* myOutputPort;
86
87     bool myHilighted;
88     QCanvasItem* mySelectedItem;
89     QPoint       mySelectedPoint;
90 };
91
92 /*
93 class SUPERVGUI_CanvasStreamLink : public SUPERVGUI_CanvasLink {
94   Q_OBJECT
95
96   public:
97     SUPERVGUI_CanvasStreamLink(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::StreamLink_ptr theLink=0);
98     ~SUPERVGUI_CanvasStreamLink() {}
99
100     SUPERV_StreamLink getStreamEngine() const { return myStreamLink; }
101
102   public slots:
103     virtual void remove();
104
105   private:
106     SUPERV_StreamLink myStreamLink;
107 };
108 */
109
110 class SUPERVGUI_CanvasLinkBuilder : public SUPERVGUI_CanvasLink {
111   Q_OBJECT
112
113   public:
114     SUPERVGUI_CanvasLinkBuilder(QObject* theParent, SUPERVGUI_Main* theMain, SUPERVGUI_CanvasPort* thePort=0);
115     virtual ~SUPERVGUI_CanvasLinkBuilder();
116
117     bool canCreateEngine(SUPERVGUI_CanvasPort* thePort);
118     void setCoords(SUPERV::Link_ptr theLink);
119
120     SUPERVGUI_CanvasPort* getStartPort() const { return myPort; }
121
122     int getPointCount() const { return (int) (myPrs.count()/2); }
123     void addNextPoint(const QPoint& thePoint, bool theOrtho = false);
124     void setFloatPoint(const QPoint& thePoint);
125     void removeLastPoint();
126
127     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort);
128     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort, int dx, int dy);
129
130   private:
131     SUPERVGUI_CanvasPort* myPort;
132
133     QCanvasLine* myFloatingEdge;
134 };
135
136
137 class SUPERVGUI_CanvasEdgePrs;
138 class SUPERVGUI_CanvasPointPrs : public QCanvasEllipse 
139 {
140   public:
141     SUPERVGUI_CanvasPointPrs(QCanvas* theCanvas, SUPERVGUI_CanvasLink* theLink, const int& theIndex = -1);
142     ~SUPERVGUI_CanvasPointPrs() {}
143
144     SUPERVGUI_CanvasLink* getLink() const { return myLink; }
145     int getIndex() const { return myIndex; }
146
147     void setInEdge(SUPERVGUI_CanvasEdgePrs* theEdge);
148     void setOutEdge(SUPERVGUI_CanvasEdgePrs* theEdge);
149
150     void moveBy(double dx, double dy);
151     void setColor(const QColor& theColor);
152
153     void setMoving(bool b) { myMoving = b; }
154     bool isMoving() const { return myMoving; }
155
156     virtual int rtti() const;
157
158   private:
159     SUPERVGUI_CanvasLink* myLink;
160     int myIndex;
161     bool myMoving;
162
163     SUPERVGUI_CanvasEdgePrs* myInEdge;
164     SUPERVGUI_CanvasEdgePrs* myOutEdge;
165 };
166
167
168 class SUPERVGUI_CanvasEdgePrs : public QCanvasLine 
169 {
170   public:
171     SUPERVGUI_CanvasEdgePrs(QCanvas* theCanvas, SUPERVGUI_CanvasLink* theLink);
172     ~SUPERVGUI_CanvasEdgePrs() {}
173
174     SUPERVGUI_CanvasLink* getLink() const { return myLink; }
175
176     void setFromPoint(SUPERVGUI_CanvasPointPrs* thePoint);
177     void setToPoint(SUPERVGUI_CanvasPointPrs* thePoint);
178
179     void moveBy(double dx, double dy);
180     void setColor(const QColor& theColor);
181
182     void setMoving(bool b) { myMoving = b; }
183     bool isMoving() const { return myMoving; }
184
185     virtual int rtti() const;
186
187   private:
188     bool myMoving;
189     SUPERVGUI_CanvasLink* myLink;
190
191     //mkr: for moving segment of link
192     SUPERVGUI_CanvasPointPrs* myStartPoint;
193     SUPERVGUI_CanvasPointPrs* myEndPoint;
194 };
195
196 #endif