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