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