Salome HOME
Fix for IPAL10387 ( Supervisor viewer has no "View Operations" toolbar ) :
[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
141   public slots:
142     void execute(char * theNodeNode, SUPERV::GraphState theNodeState);
143     void sync();
144     void syncAsync();
145     void addDataflowToStudy();
146     void insertFile();
147     void addNode();
148     void changeInformation();
149     void copy();
150
151     void showCanvasTable();
152     void showContolFlow();
153     void showCanvas();
154
155     void filterNotification();
156     void changeDSGraphParameters();
157     void onSubGraphClosed( SUIT_ViewWindow* );
158     void onSubGraphActivated( SUIT_ViewWindow* );
159
160     void onShowToolbar();
161  
162   private slots:
163     void chooseData(QListViewItem* item);
164     void checkExecution();
165
166   private:
167     void init(SUIT_Desktop* parent);
168     void syncNotification();
169     bool isFiltered(char* graph, char* node, char* type, char* message, char* sender, long counter, char* date, long stamp);
170     void closeEvent(QCloseEvent*);
171
172     SUPERV_Graph            dataflow;
173
174     QMap<QString, SUIT_ViewWindow*> mySubGraphs;
175     QMap<QString, QString>          mySubGraphMap;
176     SUIT_ViewWindow*                myLastGraph;
177
178     SUIT_Study*                     study;
179     OB_Browser*                     objectBrowser;
180     LogWindow*                      message;
181
182     GraphViewType           myCurrentView;
183     SUPERVGUI_CanvasArray*  myArray;
184     SUPERVGUI_ArrayView*    myArrayView;
185     SUPERVGUI_Canvas*       myCanvas;
186     SUPERVGUI_CanvasView*   myCanvasView;
187
188     bool                    choosing;
189
190     QString                 myHashCode;
191     
192     bool                    myIsFromStudy;
193     int                     myCopyNum;
194
195     SALOME_NamingService*   myNService;
196     QDateTime               myRunTime; // mpv 23.12.2002: we need time of running of dataflow
197                                        // for correct Study document modification
198     /* notification data */                            
199     NOTIFICATION_Consumer*  notification;
200     bool                    myFiltered;
201     bool                    myLogged;
202     QString                 myLogFileName;
203     FILE*                   myLogFile;
204     bool                    myWarning;
205     bool                    myStep;
206     bool                    myTrace;
207     bool                    myVerbose;
208     bool                    myIsLocked;
209
210     SUPERVGUI_Thread*       myThread; 
211
212     QPtrList< char * >                myEventNodes ;
213     QPtrList< SUPERV::GraphState >    myStates ;
214     QTimer*                 myTimer;
215 };
216
217 class SUPERVGUI_Thread : public QObject, public QThread {
218   Q_OBJECT;
219  public:
220   SUPERVGUI_Thread();
221   ~SUPERVGUI_Thread();
222
223   void startThread(const char* m);
224   void setMain(SUPERVGUI_Main* theMain);
225
226  public slots:
227    void KillThread(bool theValue); 
228   
229  protected:
230   virtual void run();
231   void main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState);
232
233  private:
234   bool                myIsActive;
235   SUPERVGUI_Main*     myMain;
236   QMutex              myMutex;
237
238 };
239
240 /**
241  * A dialog for setting Graph execution parameters
242  */
243 class SUPERVGUI_DSGraphParameters: public QDialog {
244   Q_OBJECT
245
246   public:
247     SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly);
248     virtual ~SUPERVGUI_DSGraphParameters();
249
250   private slots:
251     void accept();
252
253   private:
254
255     void setData();
256
257     QtxDblSpinBox*       myDeltaTime;
258     QLineEdit*           myTimeOut;
259     QComboBox*           myDataStreamTrace;
260
261     SUPERV_Graph    myGraph;
262 };
263
264 #endif