Salome HOME
Merge from OCC_development_generic_2006
[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     SUIT_ResourceMgr* resMgr() const;
61
62     void run( const bool andSuspend );
63     void kill();
64     void suspendResume();
65     //void stopRestart();
66     void openSubGraph(SUPERV_CNode theNode, bool correct = false);
67
68     bool putDataStudy(SUPERV_Port port, const char* inout);
69
70     SUPERVGUI_CanvasArray*  getCanvasArray();
71     SUPERVGUI_ArrayView* getArrayView();
72     SUPERVGUI_Canvas* getCanvas();
73     SUPERVGUI_CanvasView* getCanvasView();
74     SUPERV_Graph getDataflow();
75     LogWindow* getMessage();
76     SUIT_Study* getStudy();
77     bool isArrayShown();
78     void showPopup(QPopupMenu* p, QMouseEvent* e);
79
80     void ActivatePanning();
81     void ResetView();
82
83     void setHashCode(QString theCode) 
84       { myHashCode = theCode; };
85
86     QString getHashCode() 
87       { return myHashCode; };
88     
89     bool isDataflowInStudy() const;
90     
91     bool isEditable() 
92       { if (SUPERV_isNull(dataflow)) return false;
93       return !dataflow->IsReadOnly(); };
94
95     void addComputeNode(SUPERV_CNode theNode);
96     void addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update);
97     void addGOTONode(SUPERV_CNode theNode);
98     void addMacroNode(SUPERV_CNode theNode);
99
100     void setPaletteBackgroundColor(const QColor& color);
101
102     void lockedGraph(bool theLock) { myIsLocked = theLock; }
103     bool isLocked() { return myIsLocked; }
104
105     SUPERV::GraphState getNodeExecState();
106     void setNodeExecState(SUPERV::GraphState theNodeExecState);
107
108     QPtrList< char * > getEventNodes();
109     void setEventNodes(QPtrList< char * > theEventNodes);
110     bool removeFirstEN() { return myEventNodes.removeFirst(); }
111     void removeEventNodes() { myEventNodes.clear(); }
112
113     QPtrList< SUPERV::GraphState > getStates();
114     void setStates(QPtrList< SUPERV::GraphState > theStates);
115     bool removeFirstS() { return myStates.removeFirst(); }
116     void removeStates() { myStates.clear(); }
117
118     int getNodesNumber();
119     SUPERVGUI_Thread* getMyThread();
120
121     void startTimer();
122     void executionFinished();
123
124     bool eventFilter( QObject* o, QEvent* e);
125
126     void Editing(); // any Editing operation is to be performed ->
127                     // activate Editors data model in Engine
128     bool ReadyToModify(); // must be called before any modification
129                     // operation - asks to kill execution of dataflow.  If returns false -
130                     // modification (==Editing() ) is not allowed.
131
132     void removeArrayChild(SUPERV::CNode_ptr theNode);
133
134     GraphViewType getViewType() { return myCurrentView; }
135
136     virtual void resizeView( QResizeEvent* theEvent );
137
138   signals:
139     void KillMyThread(bool theValue);
140     void EventToSync(); // mkr : IPAL11362
141
142   public slots:
143     void execute(char * theNodeNode, SUPERV::GraphState theNodeState);
144     void sync();
145     void syncAsync();
146     void addDataflowToStudy();
147     void insertFile();
148     void addNode();
149     void changeInformation();
150     void copy();
151
152     void showCanvasTable();
153     void showContolFlow();
154     void showCanvas();
155
156     void filterNotification();
157     void changeDSGraphParameters();
158     void onSubGraphClosed( SUIT_ViewWindow* );
159     void onSubGraphActivated( SUIT_ViewWindow* );
160
161     void onShowToolbar();
162
163     void onObjectCreatedDeleted(); // mkr : PAL8237
164  
165   private slots:
166     void chooseData(QListViewItem* item);
167     void checkExecution();
168
169   private:
170     void init(SUIT_Desktop* parent);
171     void syncNotification();
172     bool isFiltered(char* graph, char* node, char* type, char* message, char* sender, long counter, char* date, long stamp);
173     void closeEvent(QCloseEvent*);
174
175     SUPERV_Graph            dataflow;
176
177     QMap<QString, SUIT_ViewWindow*> mySubGraphs;
178     QMap<QString, QString>  mySubGraphMap;
179     SUIT_ViewWindow*        myLastGraph;
180
181     SUIT_Study*             study;
182     OB_Browser*             objectBrowser;
183     LogWindow*              message;
184
185     GraphViewType           myCurrentView;
186     SUPERVGUI_CanvasArray*  myArray;
187     SUPERVGUI_ArrayView*    myArrayView;
188     SUPERVGUI_Canvas*       myCanvas;
189     SUPERVGUI_CanvasView*   myCanvasView;
190
191     bool                    choosing;
192
193     QString                 myHashCode;
194     
195     bool                    myIsFromStudy;
196     int                     myCopyNum;
197
198     SALOME_NamingService*   myNService;
199     QDateTime               myRunTime; // mpv 23.12.2002: we need time of running of dataflow
200                                        // for correct Study document modification
201     /* notification data */                            
202     NOTIFICATION_Consumer*  notification;
203     bool                    myFiltered;
204     bool                    myLogged;
205     QString                 myLogFileName;
206     FILE*                   myLogFile;
207     bool                    myWarning;
208     bool                    myStep;
209     bool                    myTrace;
210     bool                    myVerbose;
211     bool                    myIsLocked;
212
213     SUPERVGUI_Thread*       myThread; 
214
215     QPtrList<char*>         myEventNodes ;
216     QPtrList<SUPERV::GraphState> myStates ;
217     QTimer*                 myTimer;
218 };
219
220 class SUPERVGUI_Thread : public QObject, public QThread {
221   Q_OBJECT;
222  public:
223   SUPERVGUI_Thread();
224   ~SUPERVGUI_Thread();
225
226   void startThread(const char* m);
227   void setMain(SUPERVGUI_Main* theMain);
228
229  public slots:
230    void KillThread(bool theValue); 
231   
232  protected:
233   virtual void run();
234   void main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState);
235
236  private:
237   bool                myIsActive;
238   SUPERVGUI_Main*     myMain;
239   QMutex              myMutex;
240
241 };
242
243 /**
244  * A dialog for setting Graph execution parameters
245  */
246 class SUPERVGUI_DSGraphParameters: public QDialog {
247   Q_OBJECT
248
249   public:
250     SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly);
251     virtual ~SUPERVGUI_DSGraphParameters();
252
253   private slots:
254     void accept();
255
256   private:
257
258     void setData();
259
260     QtxDblSpinBox*       myDeltaTime;
261     QLineEdit*           myTimeOut;
262     QComboBox*           myDataStreamTrace;
263
264     SUPERV_Graph    myGraph;
265 };
266
267 #endif