Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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     // srn: marks an active study as being modified by the Supervisor
144     // Note: to set the modified flag the method requires that Supervision
145     //       component was previously added to study.
146     static void setModifiedFlag();
147
148   signals:
149     void KillMyThread(bool theValue);
150     void EventToSync(); // mkr : IPAL11362
151
152   public slots:
153     void execute(char * theNodeNode, SUPERV::GraphState theNodeState);
154     void sync();
155     void syncAsync();
156     void addDataflowToStudy();
157     void insertFile();
158     void addNode();
159     void changeInformation();
160     void copy();
161
162     void showCanvasTable();
163     void showContolFlow();
164     void showCanvas();
165
166     void filterNotification();
167     void changeDSGraphParameters();
168     void onSubGraphClosed( SUIT_ViewWindow* );
169     void onSubGraphActivated( SUIT_ViewWindow* );
170
171     void onShowToolbar();
172
173     void onObjectCreatedDeleted(); // mkr : PAL8237
174     void onPutInStudy( QString* ); // mkr : PAL8150
175  
176   private slots:
177     void chooseData(QListViewItem* item);
178     void checkExecution();
179
180   private:
181     void init(SUIT_Desktop* parent);
182     void syncNotification();
183     bool isFiltered(char* graph, char* node, char* type, char* message, char* sender, long counter, char* date, long stamp);
184     void closeEvent(QCloseEvent*);
185     void syncPutInStudy(); // mkr : PAL8150
186     
187     SUPERV_Graph            dataflow;
188
189     QMap<QString, SUIT_ViewWindow*> mySubGraphs;
190     QMap<QString, QString>  mySubGraphMap;
191     SUIT_ViewWindow*        myLastGraph;
192
193     SUIT_Study*             study;
194     OB_Browser*             objectBrowser;
195     LogWindow*              message;
196
197     GraphViewType           myCurrentView;
198     SUPERVGUI_CanvasArray*  myArray;
199     SUPERVGUI_ArrayView*    myArrayView;
200     SUPERVGUI_Canvas*       myCanvas;
201     SUPERVGUI_CanvasView*   myCanvasView;
202
203     bool                    choosing;
204
205     QString                 myHashCode;
206     
207     bool                    myIsFromStudy;
208     int                     myCopyNum;
209
210     SALOME_NamingService*   myNService;
211     QDateTime               myRunTime; // mpv 23.12.2002: we need time of running of dataflow
212                                        // for correct Study document modification
213     /* notification data */                            
214     NOTIFICATION_Consumer*  notification;
215     bool                    myFiltered;
216     bool                    myLogged;
217     QString                 myLogFileName;
218     FILE*                   myLogFile;
219     bool                    myWarning;
220     bool                    myStep;
221     bool                    myTrace;
222     bool                    myVerbose;
223     bool                    myIsLocked;
224
225     SUPERVGUI_Thread*       myThread; 
226
227     QPtrList<char*>         myEventNodes ;
228     QPtrList<SUPERV::GraphState> myStates ;
229     QTimer*                 myTimer;
230 };
231
232 class SUPERVGUI_Thread : public QObject, public QThread {
233   Q_OBJECT;
234  public:
235   SUPERVGUI_Thread();
236   ~SUPERVGUI_Thread();
237
238   void startThread(const char* m);
239   void setMain(SUPERVGUI_Main* theMain);
240
241  public slots:
242    void KillThread(bool theValue); 
243   
244  protected:
245   virtual void run();
246   void main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState);
247
248  private:
249   bool                myIsActive;
250   SUPERVGUI_Main*     myMain;
251   QMutex              myMutex;
252
253 };
254
255 /**
256  * A dialog for setting Graph execution parameters
257  */
258 class SUPERVGUI_DSGraphParameters: public QDialog {
259   Q_OBJECT
260
261   public:
262     SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly);
263     virtual ~SUPERVGUI_DSGraphParameters();
264
265   private slots:
266     void accept();
267
268   private:
269
270     void setData();
271
272     QtxDblSpinBox*       myDeltaTime;
273     QLineEdit*           myTimeOut;
274     QComboBox*           myDataStreamTrace;
275
276     SUPERV_Graph    myGraph;
277 };
278
279 #endif