Salome HOME
Re-wrote PARAVIS CORBA engine
[modules/paravis.git] / src / PVGUI / PVGUI_Module.h
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2010-2014  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 // File   : PVGUI_Module.h
22 // Author : Sergey ANIKIN
23 //
24
25
26 #ifndef PVGUI_Module_H
27 #define PVGUI_Module_H
28
29 #include <SalomeApp_Module.h>
30 #include "SALOMEconfig.h"
31 #include CORBA_SERVER_HEADER(SALOMEDS)
32 #ifndef PARAVIS_WITH_FULL_CORBA
33 #    include CORBA_SERVER_HEADER(PARAVIS_Gen)
34 #endif
35
36 #include <ostream>
37 #include <vtkType.h>
38 #include <QTimer>
39
40 #include <pqVariableType.h>
41
42 class QMenu;
43 class QDockWidget;
44 class QToolBar;
45 class vtkPVMain;
46 class pqOptions;
47 class pqServer;
48 class pqTabbedMultiViewWidget;
49 class pqMainWindowCore;
50 class vtkEventQtSlotConnect;
51 class pqPythonScriptEditor;
52 class pqPVApplicationCore;
53 class pqDataRepresentation;
54 class pqRepresentation;
55
56 class PyConsole_Interp;
57
58 class PVGUI_Module : public SalomeApp_Module
59 {
60   Q_OBJECT
61    
62   //! Menu actions
63   enum { // Menu "File"
64      OpenFileId,
65
66      LoadStateId,
67      SaveStateId,
68
69      SaveDataId,
70      SaveScreenshotId,
71      ExportId,
72
73      SaveAnimationId,
74      SaveGeometryId,
75
76      ConnectId,
77      DisconnectId,
78
79      // Menu "Edit"
80      UndoId,
81      RedoId,
82
83      CameraUndoId,
84      CameraRedoId,
85
86      FindDataId,
87      ChangeInputId,
88      IgnoreTimeId,
89      DeleteId,
90      DeleteAllId,
91
92      SettingsId,
93      ViewSettingsId,
94
95      // Menu "View"
96      FullScreenId,
97
98      // Menu "Animation"
99      FirstFrameId,
100      PreviousFrameId,
101      PlayId,
102      NextFrameId,
103      LastFrameId,
104      LoopId,
105
106      // Menu "Tools"
107      CreateCustomFilterId,
108      ManageCustomFiltersId,
109      CreateLookmarkId,
110      ManageLinksId,
111      AddCameraLinkId,
112      ManagePluginsExtensionsId,
113      DumpWidgetNamesId,
114      RecordTestId,
115      RecordTestScreenshotId,
116      PlayTestId,
117      MaxWindowSizeId,
118      CustomWindowSizeId,
119      TimerLogId,
120      OutputWindowId,
121      PythonShellId,
122      ShowTraceId,
123      RestartTraceId,
124
125      // Menu "Help"
126      AboutParaViewId,
127      ParaViewHelpId,
128      EnableTooltipsId,
129
130      // Menu "Window" - "New Window"
131      ParaViewNewWindowId,
132
133      // "Save state" ParaVis module root object popup
134      SaveStatePopupId,
135
136      // "Add state" and "Reload state" popups
137      AddStatePopupId,
138      CleanAndAddStatePopupId,
139
140      // "Rename" and "Delete" popups (Object Browser)
141      ParaVisRenameId,
142      ParaVisDeleteId
143   };
144
145 public:
146   PVGUI_Module();
147   ~PVGUI_Module();
148
149   static PARAVIS_ORB::PARAVIS_Gen_var GetEngine();
150
151   virtual void           initialize( CAM_Application* );
152   virtual void           windows( QMap<int, int>& ) const;
153
154   pqTabbedMultiViewWidget*         getMultiViewManager() const;
155
156   virtual QString engineIOR() const;
157
158   void openFile(const char* theName);
159   void executeScript(const char *script);
160   void saveParaviewState(const char* theFileName);
161   void loadParaviewState(const char* theFileName);
162   void clearParaviewState();
163
164   QString getTraceString();
165   void saveTrace(const char* theName);
166
167   pqServer* getActiveServer();
168
169   virtual void createPreferences();
170
171   virtual void contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle);
172
173 public slots:
174   //void onImportFromVisu(QString theEntry);
175
176 private:
177   //! Initialize ParaView if not yet done (once per session)
178   static bool            pvInit();  
179  
180   //! Create actions for ParaView GUI operations
181   void                   pvCreateActions();
182
183   //! Create menus for ParaView GUI operations duplicating menus in pqMainWindow ParaView class
184   void                   pvCreateMenus();
185
186   //! Create toolbars for ParaView GUI operations duplicating toolbars in pqMainWindow ParaView class
187   void                   pvCreateToolBars();
188
189   //! Create dock widgets for ParaView widgets
190   void                   setupDockWidgets();
191
192   //! Save states of dockable ParaView widgets
193   void                   saveDockWidgetsState();
194
195   //! Restore states of dockable ParaView widgets
196   void                   restoreDockWidgetsState();
197
198   //! Shows or hides ParaView view window
199   void                   showView( bool );    
200
201   //! Returns QMenu object for a given menu id
202   QMenu*                 getMenu( const int );
203   
204   //! Discover help project files from the resources.
205   QString getHelpFileName();
206
207   void                   deleteTemporaryFiles();
208   
209   //QList<QToolBar*>       getParaViewToolbars();
210
211   //! Create actions for ParaViS
212   void createActions();
213
214   //! Create menus for ParaViS
215   void createMenus();
216
217   //! Load selected state
218   void loadSelectedState(bool toClear);
219
220   //! Get list of embedded macros files
221   QStringList getEmbeddedMacrosList();
222
223   //! update macros state
224   void updateMacros();
225
226   //! store visibility of the common dockable windows (OB, PyConsole, ... etc.)
227   void storeCommonWindowsState();
228
229   //! restore visibility of the common dockable windows (OB, PyConsole, ... etc.)
230   void restoreCommonWindowsState();
231
232   //! run Python command (either in SALOME's Python interpreter, or in ParaView's Python's interpreter)
233   void execPythonCommand(const QString& cmd, bool inSalomeConsole=false);
234
235   //! Connect to the external PVServer, using the PARAVIS engine to launch it if it is not
236   //! already up.
237   bool connectToExternalPVServer();
238
239 private slots:
240
241   void showHelpForProxy( const QString&, const QString& );
242   
243   void onPreAccept();
244   void onPostAccept();
245   void endWaitCursor();
246
247   //  void buildToolbarsMenu();
248
249   //void showParaViewHelp();
250   //void showHelp(const QString& url);
251
252   void onFinishedAddingServer(pqServer*);
253   void onDataRepresentationCreated(pqDataRepresentation*);
254   void onDataRepresentationUpdated();
255   void onVariableChanged(pqVariableType, const QString);
256   void onRepresentationChanged(pqRepresentation*);
257
258   void onStartProgress();
259   void onEndProgress();
260   void onShowTrace();
261   void onRestartTrace();
262
263   void onNewParaViewWindow();
264
265   void onSaveMultiState();
266   void onAddState();
267   void onCleanAddState();
268
269   void onRename();
270   void onDelete();
271
272 public slots:
273   virtual bool           activateModule( SUIT_Study* );
274   virtual bool           deactivateModule( SUIT_Study* );
275   virtual void           onApplicationClosed( SUIT_Application* );
276   virtual void           studyClosed( SUIT_Study* );
277
278 protected slots:
279   virtual void           onModelOpened();
280   virtual void           onPushTraceTimer();
281
282 protected:
283   void timerEvent(QTimerEvent *event);
284
285 private:
286   class pqImplementation;
287   pqImplementation*      Implementation;
288
289   int                    mySelectionControlsTb;
290   int                    mySourcesMenuId;
291   int                    myFiltersMenuId;
292   int                    myToolbarsMenuId;
293   int                    myMacrosMenuId;
294   int                    myRecentMenuId;
295   
296   typedef QMap<QWidget*, bool> WgMap;
297   WgMap                  myDockWidgets;
298   WgMap                  myToolbars;
299   WgMap                  myToolbarBreaks;
300   QList<QMenu*>          myMenus;
301
302   typedef QMap<int, bool> DockWindowMap;         
303   DockWindowMap           myCommonMap; 
304
305   QStringList            myTemporaryFiles;
306
307   QtMsgHandler           myOldMsgHandler;
308
309   vtkEventQtSlotConnect *VTKConnect;
310
311   pqPythonScriptEditor* myTraceWindow;
312
313   int myStateCounter;
314
315   static pqPVApplicationCore* MyCoreApp;
316
317   static PARAVIS_ORB::PARAVIS_Gen_var myEngine;
318
319   QTimer             * myPushTraceTimer;
320 };
321
322 #endif // PVGUI_Module_H