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