Back to index

salome-paravis  6.5.0
PV_Events.h
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 //  File   : PV_Events.h
00020 //  Author : Vitaly Smetannikov 
00021 //  Module : PARAVIS
00022 //
00023 
00024 #ifndef PV_EVENTS_H
00025 #define PV_EVENTS_H
00026 
00027 #include "SALOME_Event.h"
00028 #include "SalomeApp_Study.h"
00029 #include "SalomeApp_Application.h"
00030 
00031 #include "SUIT_Session.h"
00032 
00033 
00037 namespace PARAVIS {
00038   
00042   struct TGetGUIApplication: public SALOME_Event
00043   {
00044     int myStudyId;
00045     typedef SalomeApp_Application* TResult;
00046     TResult myResult;
00047     
00048     TGetGUIApplication(const int theStudyId):myStudyId(theStudyId), myResult(0) {}
00049     
00050     virtual void Execute()
00051     {
00052       MESSAGE("Find application for study with id = : " << myStudyId);
00053       SUIT_Session* aSession = SUIT_Session::session();
00054       QList<SUIT_Application*> anApplications = aSession->applications();
00055       for (int i = 0; i < anApplications.count() && !myResult; i++ ){
00056         if ( anApplications[i]->activeStudy() && anApplications[i]->activeStudy()->id() == myStudyId )
00057           myResult = dynamic_cast<SalomeApp_Application*>( anApplications[i] );
00058       }
00059       if ( !myResult ) {
00060         MESSAGE("Error: application is not found for study with id = : " << myStudyId);
00061       }
00062     }
00063   };
00064   
00068   struct TModuleEvent: public SALOME_Event
00069   {
00070     SalomeApp_Application* myApp;
00071 
00072     TModuleEvent(SalomeApp_Application* theApp ):myApp(theApp) {}
00073 
00075     PVGUI_Module* getModule() 
00076     {
00077       PVGUI_Module* aPVModule = 0;
00078       CAM_Application::ModuleList aList = myApp->modules();
00079       foreach(CAM_Module* aModule, aList) {
00080         if (aModule->moduleName() == "ParaViS") {
00081           aPVModule = dynamic_cast<PVGUI_Module*>(aModule);
00082           break;
00083         }
00084       }
00085       return aPVModule;
00086     }
00087   };
00088 
00092   struct TActivateModule: public TModuleEvent
00093   {
00094     TActivateModule(SalomeApp_Application* theApp ):TModuleEvent(theApp) {}
00095     
00096     virtual void Execute()
00097     {
00098       PVGUI_Module* aPVModule = getModule();
00099       if ((aPVModule == 0) || (myApp->activeModule() != aPVModule)) {
00100         myApp->activateModule("ParaViS");
00101       }
00102     }
00103   };
00104 
00108   struct TGetTrace: public TModuleEvent
00109   {
00110     typedef std::string TResult;
00111     TResult myResult;
00112     TGetTrace(SalomeApp_Application* theApp) :
00113       TModuleEvent(theApp)
00114     {
00115       myResult = "";
00116     }
00117 
00118     virtual void Execute()
00119     {
00120       PVGUI_Module* aPVModule = getModule();
00121       if (aPVModule)
00122         myResult = qPrintable(aPVModule->getTraceString());
00123     }
00124   };
00125 
00129   struct TParavisFileEvent: public TModuleEvent
00130   {
00131     const char* myName;
00132 
00133     TParavisFileEvent(SalomeApp_Application* theApp, const char* theFileName ) :
00134       TModuleEvent(theApp), myName(theFileName)
00135     {}
00136   };
00137 
00141   struct TSaveTrace: public TParavisFileEvent
00142   {
00143     TSaveTrace(SalomeApp_Application* theApp, const char* theFileName ) :
00144       TParavisFileEvent(theApp, theFileName)
00145     {}
00146     
00147     virtual void Execute()
00148     {
00149       PVGUI_Module* aPVModule = getModule();
00150       if (aPVModule)
00151         aPVModule->saveTrace(myName);
00152     }
00153   };
00154 
00155 
00159   struct TImportFile: public TParavisFileEvent
00160   {
00161     TImportFile(SalomeApp_Application* theApp, const char* theFileName ) :
00162       TParavisFileEvent(theApp, theFileName)
00163     {}
00164     
00165     virtual void Execute()
00166     {
00167       PVGUI_Module* aPVModule = getModule();
00168       if (aPVModule)
00169         aPVModule->openFile(myName);
00170     }
00171   };
00172 
00176   struct TExecuteScript: public TParavisFileEvent
00177   {
00178     TExecuteScript(SalomeApp_Application* theApp, const char* theFileName ) :
00179       TParavisFileEvent(theApp, theFileName)
00180     {}
00181     
00182     virtual void Execute()
00183     {
00184       PVGUI_Module* aPVModule = getModule();
00185       if (aPVModule)
00186         aPVModule->executeScript(myName);
00187     }
00188   };
00189 
00194   struct TSaveStateFile: public TParavisFileEvent
00195   {
00196     TSaveStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
00197       TParavisFileEvent(theApp, theFileName)      
00198     {}
00199     
00200     virtual void Execute()
00201     {
00202       PVGUI_Module* aPVModule = getModule();
00203       if (aPVModule)
00204         aPVModule->saveParaviewState(myName);
00205     }
00206   };
00207 
00208 
00213   struct TLoadStateFile: public TParavisFileEvent
00214   {
00215     TLoadStateFile(SalomeApp_Application* theApp, const char* theFileName ) :
00216       TParavisFileEvent(theApp, theFileName)      
00217     {}
00218     
00219     virtual void Execute()
00220     {
00221       PVGUI_Module* aPVModule = getModule();
00222       if (aPVModule)
00223         aPVModule->loadParaviewState(myName);
00224     }
00225   };
00226 
00230   struct TGetActiveServer: public TModuleEvent
00231   {
00232     typedef pqServer* TResult;
00233     TResult myResult;
00234 
00235     TGetActiveServer(SalomeApp_Application* theApp ) :
00236       TModuleEvent(theApp), myResult(0)   
00237     {}
00238     
00239     virtual void Execute()
00240     {
00241       PVGUI_Module* aPVModule = getModule();
00242       if (aPVModule)
00243         myResult = aPVModule->getActiveServer();
00244     }
00245   };
00246 
00247 };
00248 
00249 
00250 #endif  //PV_EVENTS_H