Salome HOME
DCQ:prepare 2.0.0
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Link.h
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SUPERVGUI_Link.h
8 //  Author : Vitaly SMETANNIKOV
9 //  Module : SUPERV
10
11 #ifndef SUPERVGUI_Link_H
12 #define SUPERVGUI_Link_H
13
14 using namespace std;
15
16 #include "SUPERVGUI_Def.h"
17 #include "SUPERVGUI_Port.h"
18 //_CS_PhB BUG QT erreur de compilation #include <qvaluevector.h>
19 #include <vector.h>
20
21 class SUPERVGUI_Graph;
22
23 int distance(int x1, int y1, int x2, int y2);
24 int distance(QPoint thePnt, QPoint thePntLn1, QPoint thePntLn2);
25
26
27 class SUPERVGUI_Link: public QObject {
28   Q_OBJECT
29   
30 public:
31   SUPERVGUI_Link(SUPERVGUI_Graph* theGraph, SUPERV_Link theLink=0);
32
33   virtual ~SUPERVGUI_Link();
34
35   void setBeginPort(SUPERVGUI_Port* theBeginPort);
36   SUPERVGUI_Port* getBeginPort();
37
38   void setInputPort(SUPERVGUI_PortIn* thePortIn);
39   SUPERVGUI_PortIn* getInputPort()
40     { return myPortIn; };
41
42   void setInputPortES(SUPERVGUI_PortInESNode* thePortInES);
43   SUPERVGUI_PortInESNode* getInputPortES()
44     { return myPortInES; };
45
46   bool isESInputPort();
47
48   void destroyEngine();
49
50   void setOutputPort(SUPERVGUI_PortOut* thePortOut);
51   SUPERVGUI_PortOut* getOutputPort()
52     { return myPortOut; };
53
54   void addPoint(long theX, long theY);
55   void removeLastPoint();
56
57   void repaint();
58   void paint(bool toErase);
59   void paint(QPainter* thePainter, bool toErase);
60   void drawLink(QPainter* thePainter);
61
62   bool isInRect(int theX, int theY, int theW, int theH);
63   
64   SUPERV_Link getEngineLink()
65     { return myEngine; };
66
67   void drawTo(QPoint thePnt);
68   void abortCreation();
69
70   void repaintSketch();
71   void addTmpPoint(QPoint thePnt);
72   void delLastTmpPoint();
73
74   bool isCreationComplete();
75   bool createEngine();
76
77   bool isSelected()
78     { return myIsSelected; };
79
80   bool haveSelectedPoint()
81     { return (myHltPnt > -1); };
82
83   int getSelectedPoint() 
84     { return myHltPnt; };
85
86   void removePoint(int thePnt);
87
88   void setVisible(bool theVisible);
89
90   static void setOrthoMode(bool theIsOrtho)
91     { OrthoMode = theIsOrtho; };
92   
93   static bool isOrthoMode()
94     { return OrthoMode; };
95
96   static SUPERVGUI_Link* getSelectedLink()
97     { return SelectedLink; };
98
99 signals:
100   void linkDeleted(SUPERVGUI_Link*);
101
102 public slots:
103   void onMouseMove(QMouseEvent* theEvent);
104   void onMousePress(QMouseEvent* theEvent);
105   void onMouseRelease(QMouseEvent* theEvent);
106
107
108 private:
109   void connectToEvents();
110   bool isSelected(QPoint thePnt);
111
112
113   SUPERVGUI_Graph* myGraph;
114   SUPERVGUI_Port* myBeginPort;
115   SUPERVGUI_PortIn* myPortIn;
116   SUPERVGUI_PortInESNode* myPortInES;  
117   SUPERVGUI_PortOut* myPortOut;
118
119   SUPERV_Link myEngine;
120
121   QPoint myPrevPoint; // used for sketching only
122   //_CS_PhB BUG QT erreur de compilation   QValueVector<QPoint> myTmpPoints;
123   vector<QPoint> myTmpPoints;
124
125   SUPERVGUI_Port* myStartPort;
126
127   QPen myTmpPen;
128   
129   // Points highlighting management
130   int myHltPnt; // number of point or -1
131
132   // Points moving management
133   void drawSegments();
134   bool myPntMovingState;
135   QPoint myBeforePnt, myMovedPnt, myAfterPnt;
136   QPainter* myPainter;
137
138   // Selection of Link
139   bool myIsSelected;
140
141   bool myIsVisible;
142   
143   static bool OrthoMode;
144   static bool LinkIsMoving;
145   static SUPERVGUI_Link* SelectedLink;
146 };
147
148 #endif