1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
24 // Author : Vitaly Smetannikov
31 #include "SALOME_Event.h"
32 #include "SalomeApp_Study.h"
33 #include "SalomeApp_Application.h"
35 #include "SUIT_Session.h"
39 * Definition of events
44 * Event which returns SalomeApp_Application instance which corresponds to th given study ID
46 struct TGetGUIApplication: public SALOME_Event
49 typedef SalomeApp_Application* TResult;
52 TGetGUIApplication(const int theStudyId):
53 myStudyId(theStudyId), myResult(0)
56 virtual void Execute()
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] );
66 MESSAGE("Error: application is not found for study with id = : " << myStudyId);
72 * Parent event for all events what is going to work with PARAVIS module instance
74 struct TModuleEvent: public SALOME_Event
76 SalomeApp_Application* myApp;
78 TModuleEvent(SalomeApp_Application* theApp ) :
82 //! Returns pointer on PARAVIS module instance
83 PVGUI_Module* getModule()
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);
98 * Event which activates PARAVIS module if it is not active
100 struct TActivateModule: public TModuleEvent
102 TActivateModule(SalomeApp_Application* theApp ) :
106 virtual void Execute()
108 PVGUI_Module* aPVModule = getModule();
109 if ((aPVModule == 0) || (myApp->activeModule() != aPVModule)) {
110 myApp->activateModule("ParaViS");
116 * Returns trace string collected in PARAVIS module in current session
118 struct TGetTrace: public TModuleEvent
120 typedef const char* TResult;
122 TGetTrace(SalomeApp_Application* theApp) :
128 virtual void Execute()
130 PVGUI_Module* aPVModule = getModule();
132 myResult = qPrintable(aPVModule->printTrace());
137 * Parent event for all operations with files across PARAVIS module
139 struct TParavisFileEvent: public TModuleEvent
143 TParavisFileEvent(SalomeApp_Application* theApp, const char* theFileName ) :
144 TModuleEvent(theApp), myName(theFileName)
149 * Event to save trace string inte disk file
151 struct TSaveTrace: public TParavisFileEvent
153 TSaveTrace(SalomeApp_Application* theApp, const char* theFileName ) :
154 TParavisFileEvent(theApp, theFileName)
157 virtual void Execute()
159 PVGUI_Module* aPVModule = getModule();
161 aPVModule->saveTrace(myName);
167 * Event to import file to PARAVIS
169 struct TImportFile: public TParavisFileEvent
171 TImportFile(SalomeApp_Application* theApp, const char* theFileName ) :
172 TParavisFileEvent(theApp, theFileName)
175 virtual void Execute()
177 PVGUI_Module* aPVModule = getModule();
179 aPVModule->openFile(myName);
185 * Event to save current Paraview state.
186 * This event is used for Study saving
188 struct TSaveStateFile: public TParavisFileEvent
190 TSaveStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
191 TParavisFileEvent(theApp, theFileName)
194 virtual void Execute()
196 PVGUI_Module* aPVModule = getModule();
198 aPVModule->saveParaviewState(myName);
204 * Event to restore Paraview state from disk file.
205 * This event is used for Study restoring
207 struct TLoadStateFile: public TParavisFileEvent
209 TLoadStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
210 TParavisFileEvent(theApp, theFileName)
213 virtual void Execute()
215 PVGUI_Module* aPVModule = getModule();
217 aPVModule->loadParaviewState(myName);
222 * Returns currently active Paraview server
224 struct TGetActiveServer: public TModuleEvent
226 typedef pqServer* TResult;
229 TGetActiveServer(SalomeApp_Application* theApp ) :
230 TModuleEvent(theApp), myResult(0)
233 virtual void Execute()
235 PVGUI_Module* aPVModule = getModule();
237 myResult = aPVModule->getActiveServer();