Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.h
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Main.h
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 #ifndef SUPERVGUI_Main_H
29 #define SUPERVGUI_Main_H
30
31 #include "SUPERVGraph_ViewFrame.h"
32 #include "SUPERVGUI_Canvas.h"
33 #include "SUPERVGUI_CanvasView.h"
34 #include "SUPERVGUI_ArrayView.h"
35
36 #include <qobject.h>
37 #include <qapplication.h>
38 #include <qthread.h>
39
40 class SUIT_Study;
41 class OB_Browser;
42 class LogWindow;
43 class QtxDblSpinBox;
44 class QLineEdit;
45 class QComboBox;
46 class NOTIFICATION_Consumer;
47 class SUPERVGUI_Thread;
48
49 class SUPERVGUI_Main: public SUPERVGraph_View {
50   Q_OBJECT
51
52   // asv : 18.11.04 : making Thread class a friend in order to allow it to modify
53   // a private field myGUIEventLoopFinished
54   friend class SUPERVGUI_Thread;
55
56   public:
57     SUPERVGUI_Main(SUPERVGraph_ViewFrame*, SUIT_Desktop*/*QAD_Desktop**/, SUPERV_Graph);
58     virtual ~SUPERVGUI_Main();
59
60     void run( const bool andSuspend );
61     void kill();
62     void suspendResume();
63     //void stopRestart();
64     void openSubGraph(SUPERV_CNode theNode, bool correct = false);
65
66     bool putDataStudy(SUPERV_Port port, const char* inout);
67
68     SUPERVGUI_CanvasArray*  getCanvasArray();
69     SUPERVGUI_ArrayView* getArrayView();
70     SUPERVGUI_Canvas* getCanvas();
71     SUPERVGUI_CanvasView* getCanvasView();
72     SUPERV_Graph getDataflow();
73     LogWindow* getMessage();
74     SUIT_Study* getStudy();
75     bool isArrayShown();
76     void showPopup(QPopupMenu* p, QMouseEvent* e);
77
78     void ActivatePanning();
79     void ResetView();
80
81     void setHashCode(QString theCode) 
82       { myHashCode = theCode; };
83
84     QString getHashCode() 
85       { return myHashCode; };
86     
87     bool isDataflowInStudy() const;
88     
89     bool isEditable() 
90       { if (SUPERV_isNull(dataflow)) return false;
91       return !dataflow->IsReadOnly(); };
92
93     void addComputeNode(SUPERV_CNode theNode);
94     void addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update);
95     void addGOTONode(SUPERV_CNode theNode);
96     void addMacroNode(SUPERV_CNode theNode);
97
98     void setPaletteBackgroundColor(const QColor& color);
99
100     void lockedGraph(bool theLock) { myIsLocked = theLock; }
101     bool isLocked() { return myIsLocked; }
102
103     SUPERV::GraphState getNodeExecState();
104     void setNodeExecState(SUPERV::GraphState theNodeExecState);
105
106     QPtrList< char * > getEventNodes();
107     void setEventNodes(QPtrList< char * > theEventNodes);
108     bool removeFirstEN() { return myEventNodes.removeFirst(); }
109     void removeEventNodes() { myEventNodes.clear(); }
110
111     QPtrList< SUPERV::GraphState > getStates();
112     void setStates(QPtrList< SUPERV::GraphState > theStates);
113     bool removeFirstS() { return myStates.removeFirst(); }
114     void removeStates() { myStates.clear(); }
115
116     int getNodesNumber();
117     SUPERVGUI_Thread* getMyThread();
118
119     void startTimer();
120     void executionFinished();
121
122     bool eventFilter( QObject* o, QEvent* e);
123
124     void Editing(); // any Editing operation is to be performed ->
125                     // activate Editors data model in Engine
126     bool ReadyToModify(); // must be called before any modification
127                     // operation - asks to kill execution of dataflow.  If returns false -
128                     // modification (==Editing() ) is not allowed.
129
130     void removeArrayChild(SUPERV::CNode_ptr theNode);
131
132     GraphViewType getViewType() { return myCurrentView; }
133
134   signals:
135     void KillMyThread(bool theValue);
136
137   public slots:
138     void execute(char * theNodeNode, SUPERV::GraphState theNodeState);
139     void sync();
140     void syncAsync();
141     void addDataflowToStudy();
142     void insertFile();
143     void addNode();
144     void changeInformation();
145     void copy();
146
147     void showCanvasTable();
148     void showContolFlow();
149     void showCanvas();
150
151     void filterNotification();
152     void changeDSGraphParameters();
153     void onSubGraphClosed( SUIT_ViewWindow* );
154     void onSubGraphActivated( SUIT_ViewWindow* );
155  
156   private slots:
157     void chooseData(QListViewItem* item);
158     void checkExecution();
159
160   private:
161     void init(SUIT_Desktop* parent);
162     void syncNotification();
163     bool isFiltered(char* graph, char* node, char* type, char* message, char* sender, long counter, char* date, long stamp);
164     void closeEvent(QCloseEvent*);
165
166     SUPERV_Graph            dataflow;
167
168     QMap<QString, SUIT_ViewWindow*> mySubGraphs;
169     QMap<QString, QString>          mySubGraphMap;
170     SUIT_ViewWindow*                myLastGraph;
171
172     SUIT_Study*                     study;
173     OB_Browser*                     objectBrowser;
174     LogWindow*                      message;
175
176     GraphViewType           myCurrentView;
177     SUPERVGUI_CanvasArray*  myArray;
178     SUPERVGUI_ArrayView*    myArrayView;
179     SUPERVGUI_Canvas*       myCanvas;
180     SUPERVGUI_CanvasView*   myCanvasView;
181
182     bool                    choosing;
183
184     QString                 myHashCode;
185     
186     bool                    myIsFromStudy;
187     int                     myCopyNum;
188
189     SALOME_NamingService*   myNService;
190     QDateTime               myRunTime; // mpv 23.12.2002: we need time of running of dataflow
191                                        // for correct Study document modification
192     /* notification data */                            
193     NOTIFICATION_Consumer*  notification;
194     bool                    myFiltered;
195     bool                    myLogged;
196     QString                 myLogFileName;
197     FILE*                   myLogFile;
198     bool                    myWarning;
199     bool                    myStep;
200     bool                    myTrace;
201     bool                    myVerbose;
202     bool                    myIsLocked;
203
204     SUPERVGUI_Thread*       myThread; 
205
206     QPtrList< char * >                myEventNodes ;
207     QPtrList< SUPERV::GraphState >    myStates ;
208     QTimer*                 myTimer;
209 };
210
211 class SUPERVGUI_Thread : public QObject, public QThread {
212   Q_OBJECT;
213  public:
214   SUPERVGUI_Thread();
215   ~SUPERVGUI_Thread();
216
217   void startThread(const char* m);
218   void setMain(SUPERVGUI_Main* theMain);
219
220  public slots:
221    void KillThread(bool theValue); 
222   
223  protected:
224   virtual void run();
225
226  private:
227   bool                myIsActive;
228   SUPERVGUI_Main*     myMain;
229   QMutex              myMutex;
230
231 };
232
233 /**
234  * A dialog for setting Graph execution parameters
235  */
236 class SUPERVGUI_DSGraphParameters: public QDialog {
237   Q_OBJECT
238
239   public:
240     SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly);
241     virtual ~SUPERVGUI_DSGraphParameters();
242
243   private slots:
244     void accept();
245
246   private:
247
248     void setData();
249
250     QtxDblSpinBox*       myDeltaTime;
251     QLineEdit*           myTimeOut;
252     QComboBox*           myDataStreamTrace;
253
254     SUPERV_Graph    myGraph;
255 };
256
257 #endif