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