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