Salome HOME
Merge from BR_PARAVIS_DEV 29Dec09
[modules/paravis.git] / src / PVGUI / PV_Events.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : PV_Events.h
24 //  Author : Vitaly Smetannikov 
25 //  Module : PARAVIS
26 //
27
28 #ifndef PV_EVENTS_H
29 #define PV_EVENTS_H
30
31 #include "SALOME_Event.h"
32 #include "SalomeApp_Study.h"
33 #include "SalomeApp_Application.h"
34
35 #include "SUIT_Session.h"
36
37
38 /*!
39  * Definition of events
40  */
41 namespace PARAVIS {
42   
43   /*!
44    * Event which returns SalomeApp_Application instance which corresponds to th given study ID
45    */
46   struct TGetGUIApplication: public SALOME_Event
47   {
48     int myStudyId;
49     typedef SalomeApp_Application* TResult;
50     TResult myResult;
51     
52      TGetGUIApplication(const int theStudyId):
53       myStudyId(theStudyId), myResult(0)
54     {}
55     
56     virtual void Execute()
57     {
58       MESSAGE("Find application for study with id = : " << myStudyId);
59       SUIT_Session* aSession = SUIT_Session::session();
60       QList<SUIT_Application*> anApplications = aSession->applications();
61       for (int i = 0; i < anApplications.count() && !myResult; i++ ){
62         if ( anApplications[i]->activeStudy() && anApplications[i]->activeStudy()->id() == myStudyId )
63           myResult = dynamic_cast<SalomeApp_Application*>( anApplications[i] );
64       }
65       if ( !myResult ) {
66         MESSAGE("Error: application is not found for study with id = : " << myStudyId);
67       }
68     }
69   };
70   
71   /*!
72    * Parent event for all events what is going to work with PARAVIS module instance
73    */
74   struct TModuleEvent: public SALOME_Event
75   {
76     SalomeApp_Application* myApp;
77
78     TModuleEvent(SalomeApp_Application* theApp ) :
79       myApp(theApp)
80     {}
81
82       //! Returns pointer on PARAVIS module instance
83     PVGUI_Module* getModule() 
84     {
85       PVGUI_Module* aPVModule = 0;
86       CAM_Application::ModuleList aList = myApp->modules();
87       foreach(CAM_Module* aModule, aList) {
88         if (aModule->moduleName() == "ParaViS") {
89           aPVModule = dynamic_cast<PVGUI_Module*>(aModule);
90           break;
91         }
92       }
93       return aPVModule;
94     }
95   };
96
97   /*!
98    * Event which activates PARAVIS module if it is not active
99    */
100   struct TActivateModule: public TModuleEvent
101   {
102     TActivateModule(SalomeApp_Application* theApp ) :
103       TModuleEvent(theApp)
104    {}
105     
106     virtual void Execute()
107     {
108       PVGUI_Module* aPVModule = getModule();
109       if ((aPVModule == 0) || (myApp->activeModule() != aPVModule)) {
110         myApp->activateModule("ParaViS");
111       }
112     }
113   };
114
115   /*!
116    * Returns trace string collected in PARAVIS module in current session
117    */
118   struct TGetTrace: public TModuleEvent
119   {
120     typedef const char* TResult;
121     TResult myResult;
122     TGetTrace(SalomeApp_Application* theApp) :
123       TModuleEvent(theApp)
124     {
125       myResult = "";
126     }
127
128     virtual void Execute()
129     {
130       PVGUI_Module* aPVModule = getModule();
131       if (aPVModule)
132         myResult = qPrintable(aPVModule->printTrace());
133     }
134   };
135
136   /*!
137    * Parent event for all operations with files across PARAVIS module
138    */
139   struct TParavisFileEvent: public TModuleEvent
140   {
141     const char* myName;
142
143     TParavisFileEvent(SalomeApp_Application* theApp, const char* theFileName ) :
144       TModuleEvent(theApp), myName(theFileName)
145     {}
146   };
147
148   /*!
149    * Event to save trace string inte disk file
150    */
151   struct TSaveTrace: public TParavisFileEvent
152   {
153     TSaveTrace(SalomeApp_Application* theApp, const char* theFileName ) :
154       TParavisFileEvent(theApp, theFileName)
155     {}
156     
157     virtual void Execute()
158     {
159       PVGUI_Module* aPVModule = getModule();
160       if (aPVModule)
161         aPVModule->saveTrace(myName);
162     }
163   };
164
165
166   /*!
167    * Event to import file to PARAVIS
168    */
169   struct TImportFile: public TParavisFileEvent
170   {
171     TImportFile(SalomeApp_Application* theApp, const char* theFileName ) :
172       TParavisFileEvent(theApp, theFileName)
173     {}
174     
175     virtual void Execute()
176     {
177       PVGUI_Module* aPVModule = getModule();
178       if (aPVModule)
179         aPVModule->openFile(myName);
180     }
181   };
182
183
184   /*!
185    * Event to save current Paraview state.
186    * This event is used for Study saving
187    */
188   struct TSaveStateFile: public TParavisFileEvent
189   {
190     TSaveStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
191       TParavisFileEvent(theApp, theFileName)      
192     {}
193     
194     virtual void Execute()
195     {
196       PVGUI_Module* aPVModule = getModule();
197       if (aPVModule)
198         aPVModule->saveParaviewState(myName);
199     }
200   };
201
202
203   /*!
204    * Event to restore Paraview state from disk file.
205    * This event is used for Study restoring
206    */
207   struct TLoadStateFile: public TParavisFileEvent
208   {
209     TLoadStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
210       TParavisFileEvent(theApp, theFileName)      
211     {}
212     
213     virtual void Execute()
214     {
215       PVGUI_Module* aPVModule = getModule();
216       if (aPVModule)
217         aPVModule->loadParaviewState(myName);
218     }
219   };
220
221   /*!
222    * Returns currently active Paraview server
223    */
224   struct TGetActiveServer: public TModuleEvent
225   {
226     typedef pqServer* TResult;
227     TResult myResult;
228
229     TGetActiveServer(SalomeApp_Application* theApp ) :
230       TModuleEvent(theApp), myResult(0)   
231     {}
232     
233     virtual void Execute()
234     {
235       PVGUI_Module* aPVModule = getModule();
236       if (aPVModule)
237         myResult = aPVModule->getActiveServer();
238     }
239   };
240
241 };
242
243
244 #endif  //PV_EVENTS_H