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