Salome HOME
Merging with JR_ASV_2_1_0_deb_with_KERNEL_Head branch, which contains many bug fixes...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasLink.h
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 //
5 //  File   : SUPERVGUI_CanvasLink.h
6 //  Author : Natalia KOPNOVA
7 //  Module : SUPERV
8
9 #ifndef SUPERVGUI_CanvasLink_H
10 #define SUPERVGUI_CanvasLink_H
11
12 using namespace std;
13 #include "SUPERVGUI_Def.h"
14 #include <qcanvas.h>
15 #include <qvaluevector.h>
16
17 class SUPERVGUI_Main;
18 class SUPERVGUI_CanvasPort;
19
20 class SUPERVGUI_CanvasLink : public QObject {
21   Q_OBJECT
22
23   public:
24     SUPERVGUI_CanvasLink(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Link_ptr theLink=0);
25     virtual ~SUPERVGUI_CanvasLink();
26
27     void show();
28     void merge();
29
30     void setHilighted(bool state);
31     void setColor(const QColor& theColor);
32
33     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort);
34     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort, int dx, int dy);
35
36     SUPERV_Link getEngine() const { return myLink; }
37     SUPERVGUI_Main* getMain() const { return myMain; }
38
39     SUPERVGUI_CanvasPort* getInputPort() const { return myInputPort; }
40     SUPERVGUI_CanvasPort* getOutputPort() const { return myOutputPort; }
41
42     void setSelectedObject(QCanvasItem* theItem, const QPoint& thePoint);
43     virtual QPopupMenu* getPopupMenu(QWidget* theParent);
44
45   public slots:
46     virtual void remove();
47     void addPoint();
48     void removePoint();
49
50   protected:
51     void addPoint(const QPoint& thePoint, const int& theIndex = -1);
52
53     QColor myColor;
54     QCanvasItemList myPrs;
55
56   private:
57     void createPrs();
58
59     SUPERV_Link     myLink;
60     SUPERVGUI_Main* myMain;
61
62     SUPERVGUI_CanvasPort* myInputPort;
63     SUPERVGUI_CanvasPort* myOutputPort;
64
65     bool myHilighted;
66     QCanvasItem* mySelectedItem;
67     QPoint       mySelectedPoint;
68 };
69
70 /*
71 class SUPERVGUI_CanvasStreamLink : public SUPERVGUI_CanvasLink {
72   Q_OBJECT
73
74   public:
75     SUPERVGUI_CanvasStreamLink(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::StreamLink_ptr theLink=0);
76     ~SUPERVGUI_CanvasStreamLink() {}
77
78     SUPERV_StreamLink getStreamEngine() const { return myStreamLink; }
79
80   public slots:
81     virtual void remove();
82
83   private:
84     SUPERV_StreamLink myStreamLink;
85 };
86 */
87
88 class SUPERVGUI_CanvasLinkBuilder : public SUPERVGUI_CanvasLink {
89   Q_OBJECT
90
91   public:
92     SUPERVGUI_CanvasLinkBuilder(QObject* theParent, SUPERVGUI_Main* theMain, SUPERVGUI_CanvasPort* thePort=0);
93     virtual ~SUPERVGUI_CanvasLinkBuilder();
94
95     bool canCreateEngine(SUPERVGUI_CanvasPort* thePort);
96     void setCoords(SUPERV::Link_ptr theLink);
97
98     SUPERVGUI_CanvasPort* getStartPort() const { return myPort; }
99
100     int getPointCount() const { return (int) (myPrs.count()/2); }
101     void addNextPoint(const QPoint& thePoint, bool theOrtho = false);
102     void setFloatPoint(const QPoint& thePoint);
103     void removeLastPoint();
104
105     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort);
106     virtual void moveByPort(SUPERVGUI_CanvasPort* thePort, int dx, int dy);
107
108   private:
109     SUPERVGUI_CanvasPort* myPort;
110
111     QCanvasLine* myFloatingEdge;
112 };
113
114
115 class SUPERVGUI_CanvasEdgePrs;
116 class SUPERVGUI_CanvasPointPrs : public QCanvasEllipse 
117 {
118   public:
119     SUPERVGUI_CanvasPointPrs(QCanvas* theCanvas, SUPERVGUI_CanvasLink* theLink, const int& theIndex = -1);
120     ~SUPERVGUI_CanvasPointPrs() {}
121
122     SUPERVGUI_CanvasLink* getLink() const { return myLink; }
123     int getIndex() const { return myIndex; }
124
125     void setInEdge(SUPERVGUI_CanvasEdgePrs* theEdge);
126     void setOutEdge(SUPERVGUI_CanvasEdgePrs* theEdge);
127
128     void moveBy(double dx, double dy);
129     void setColor(const QColor& theColor);
130
131     void setMoving(bool b) { myMoving = b; }
132     bool isMoving() const { return myMoving; }
133
134     virtual int rtti() const;
135
136   private:
137     SUPERVGUI_CanvasLink* myLink;
138     int myIndex;
139     bool myMoving;
140
141     SUPERVGUI_CanvasEdgePrs* myInEdge;
142     SUPERVGUI_CanvasEdgePrs* myOutEdge;
143 };
144
145
146 class SUPERVGUI_CanvasEdgePrs : public QCanvasLine 
147 {
148   public:
149     SUPERVGUI_CanvasEdgePrs(QCanvas* theCanvas, SUPERVGUI_CanvasLink* theLink);
150     ~SUPERVGUI_CanvasEdgePrs() {}
151
152     SUPERVGUI_CanvasLink* getLink() const { return myLink; }
153
154     void setFromPoint(SUPERVGUI_CanvasPointPrs* thePoint);
155     void setToPoint(SUPERVGUI_CanvasPointPrs* thePoint);
156
157     void moveBy(double dx, double dy);
158     void setColor(const QColor& theColor);
159
160     void setMoving(bool b) { myMoving = b; }
161     bool isMoving() const { return myMoving; }
162
163     virtual int rtti() const;
164
165   private:
166     bool myMoving;
167     SUPERVGUI_CanvasLink* myLink;
168
169     //mkr: for moving segment of link
170     SUPERVGUI_CanvasPointPrs* myStartPoint;
171     SUPERVGUI_CanvasPointPrs* myEndPoint;
172 };
173
174 #endif