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