1 // Copyright (C) 2010-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author : Vitaly Smetannikov
27 #include "SALOME_Event.h"
28 #include "SalomeApp_Study.h"
29 #include "SalomeApp_Application.h"
31 #include "SUIT_Session.h"
35 * Definition of events
40 * Event which returns SalomeApp_Application instance which corresponds to th given study ID
42 struct TGetGUIApplication: public SALOME_Event
45 typedef SalomeApp_Application* TResult;
48 TGetGUIApplication(const int theStudyId):myStudyId(theStudyId), myResult(0) {}
50 virtual void Execute()
52 MESSAGE("Find application for study with id = : " << myStudyId);
53 SUIT_Session* aSession = SUIT_Session::session();
54 QList<SUIT_Application*> anApplications = aSession->applications();
55 for (int i = 0; i < anApplications.count() && !myResult; i++ ){
56 if ( anApplications[i]->activeStudy() && anApplications[i]->activeStudy()->id() == myStudyId )
57 myResult = dynamic_cast<SalomeApp_Application*>( anApplications[i] );
60 MESSAGE("Error: application is not found for study with id = : " << myStudyId);
66 * Parent event for all events what is going to work with PARAVIS module instance
68 struct TModuleEvent: public SALOME_Event
70 SalomeApp_Application* myApp;
72 TModuleEvent(SalomeApp_Application* theApp ):myApp(theApp) {}
74 //! Returns pointer on PARAVIS module instance
75 PVGUI_Module* getModule()
77 PVGUI_Module* aPVModule = 0;
78 CAM_Application::ModuleList aList = myApp->modules();
79 foreach(CAM_Module* aModule, aList) {
80 if (aModule->moduleName() == "ParaViS") {
81 aPVModule = dynamic_cast<PVGUI_Module*>(aModule);
90 * Event which activates PARAVIS module if it is not active
92 struct TActivateModule: public TModuleEvent
94 TActivateModule(SalomeApp_Application* theApp ):TModuleEvent(theApp) {}
96 virtual void Execute()
98 PVGUI_Module* aPVModule = getModule();
99 if ((aPVModule == 0) || (myApp->activeModule() != aPVModule)) {
100 myApp->activateModule("ParaViS");
106 * Returns trace string collected in PARAVIS module in current session
108 struct TGetTrace: public TModuleEvent
110 typedef std::string TResult;
112 TGetTrace(SalomeApp_Application* theApp) :
118 virtual void Execute()
120 PVGUI_Module* aPVModule = getModule();
122 myResult = qPrintable(aPVModule->getTraceString());
127 * Parent event for all operations with files across PARAVIS module
129 struct TParavisFileEvent: public TModuleEvent
133 TParavisFileEvent(SalomeApp_Application* theApp, const char* theFileName ) :
134 TModuleEvent(theApp), myName(theFileName)
139 * Event to save trace string inte disk file
141 struct TSaveTrace: public TParavisFileEvent
143 TSaveTrace(SalomeApp_Application* theApp, const char* theFileName ) :
144 TParavisFileEvent(theApp, theFileName)
147 virtual void Execute()
149 PVGUI_Module* aPVModule = getModule();
151 aPVModule->saveTrace(myName);
157 * Event to import file to PARAVIS
159 struct TImportFile: public TParavisFileEvent
161 TImportFile(SalomeApp_Application* theApp, const char* theFileName ) :
162 TParavisFileEvent(theApp, theFileName)
165 virtual void Execute()
167 PVGUI_Module* aPVModule = getModule();
169 aPVModule->openFile(myName);
174 * Event to execute a script to PARAVIS
176 struct TExecuteScript: public TParavisFileEvent
178 TExecuteScript(SalomeApp_Application* theApp, const char* theFileName ) :
179 TParavisFileEvent(theApp, theFileName)
182 virtual void Execute()
184 PVGUI_Module* aPVModule = getModule();
186 aPVModule->executeScript(myName);
191 * Event to save current Paraview state.
192 * This event is used for Study saving
194 struct TSaveStateFile: public TParavisFileEvent
196 TSaveStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
197 TParavisFileEvent(theApp, theFileName)
200 virtual void Execute()
202 PVGUI_Module* aPVModule = getModule();
204 aPVModule->saveParaviewState(myName);
210 * Event to restore Paraview state from disk file.
211 * This event is used for Study restoring
213 struct TLoadStateFile: public TParavisFileEvent
215 TLoadStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
216 TParavisFileEvent(theApp, theFileName)
219 virtual void Execute()
221 PVGUI_Module* aPVModule = getModule();
223 aPVModule->loadParaviewState(myName);
228 * Returns currently active Paraview server
230 struct TGetActiveServer: public TModuleEvent
232 typedef pqServer* TResult;
235 TGetActiveServer(SalomeApp_Application* theApp ) :
236 TModuleEvent(theApp), myResult(0)
239 virtual void Execute()
241 PVGUI_Module* aPVModule = getModule();
243 myResult = aPVModule->getActiveServer();