Back to index

salome-gui  6.5.0
SalomePyQt.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : SalomePyQt.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #ifdef WNT
00027 // E.A. : On windows with python 2.6, there is a conflict
00028 // E.A. : between pymath.h and Standard_math.h which define
00029 // E.A. : some same symbols : acosh, asinh, ...
00030 #include <Standard_math.hxx>
00031 #include <pymath.h>
00032 #endif
00033 
00034 #include <SALOME_PYQT_ModuleLight.h> // this include must be first!!!
00035 #include <SALOME_PYQT_DataModelLight.h>
00036 #include "SalomePyQt.h"
00037 
00038 #include <QApplication>
00039 #include <QMenuBar>
00040 #include <QMenu>
00041 #include <QImage>
00042 #include <QStringList>
00043 #include <QAction>
00044 
00045 #include <SALOME_Event.h>
00046 
00047 #include <QtxActionMenuMgr.h>
00048 #include <QtxActionGroup.h>
00049 #include <QtxWorkstack.h>
00050 #include <QtxTreeView.h>
00051 #include <SUIT_Session.h>
00052 #include <SUIT_Desktop.h>
00053 #include <SUIT_ResourceMgr.h>
00054 #include <SUIT_Tools.h>
00055 #include <SUIT_ViewManager.h>
00056 #include <SUIT_ViewWindow.h>
00057 #include <SUIT_DataBrowser.h>
00058 #include <STD_TabDesktop.h>
00059 #include <LightApp_Application.h>
00060 #include <LightApp_Study.h>
00061 #include <LightApp_SelectionMgr.h>
00062 #include <LogWindow.h>
00063 #include <OCCViewer_ViewWindow.h>
00064 #include <Plot2d_ViewManager.h>
00065 #include <Plot2d_ViewWindow.h>
00066 
00072 static LightApp_Application* getApplication()
00073 {
00074   if ( SUIT_Session::session() )
00075     return dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
00076   return 0;
00077 }
00078 
00084 static LightApp_Study* getActiveStudy()
00085 {
00086   if ( getApplication() )
00087     return dynamic_cast<LightApp_Study*>( getApplication()->activeStudy() );
00088   return 0;
00089 }
00090 
00097 static SALOME_PYQT_ModuleLight* getActiveModule()
00098 {
00099   SALOME_PYQT_ModuleLight* module = 0;
00100   if ( LightApp_Application* anApp = getApplication() ) {
00101     module = SALOME_PYQT_ModuleLight::getInitModule();
00102     if ( !module )
00103       module = dynamic_cast<SALOME_PYQT_ModuleLight*>( anApp->activeModule() );
00104   }
00105   return module;
00106 }
00107 
00117 static QMap<LightApp_Application*, SALOME_Selection*> SelMap;
00118 
00127 SALOME_Selection* SALOME_Selection::GetSelection( LightApp_Application* app )
00128 {
00129   SALOME_Selection* sel = 0;
00130   if ( app && SelMap.find( app ) != SelMap.end() )
00131     sel = SelMap[ app ];
00132   else 
00133     sel = SelMap[ app ] = new SALOME_Selection( app );
00134   return sel;
00135 }
00136 
00141 SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( 0 ), mySelMgr( 0 )
00142 {
00143   LightApp_Application* app = dynamic_cast<LightApp_Application*>( p );
00144   if ( app ) {
00145     mySelMgr = app->selectionMgr();
00146     connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) );
00147     connect( mySelMgr, SIGNAL( destroyed() ),        this, SLOT  ( onSelMgrDestroyed() ) );
00148   }
00149 }
00150 
00154 SALOME_Selection::~SALOME_Selection()
00155 {
00156   LightApp_Application* app = 0;
00157   QMap<LightApp_Application*, SALOME_Selection*>::Iterator it;
00158   for ( it = SelMap.begin(); it != SelMap.end() && !app; ++it ) {
00159     if ( it.value() == this ) app = it.key();
00160   }
00161   if ( app ) SelMap.remove( app );
00162 }
00163 
00168 void SALOME_Selection::onSelMgrDestroyed()
00169 {
00170   mySelMgr = 0;
00171 }
00172 
00176 void SALOME_Selection::Clear()
00177 {
00178   class TEvent: public SALOME_Event {
00179     LightApp_SelectionMgr* mySelMgr;
00180   public:
00181     TEvent( LightApp_SelectionMgr* selMgr ) 
00182       : mySelMgr( selMgr ) {}
00183     virtual void Execute() {
00184       if ( mySelMgr )
00185         mySelMgr->clearSelected();
00186     }
00187   };
00188   ProcessVoidEvent( new TEvent( mySelMgr ) );
00189 }
00190 
00194 void SALOME_Selection::ClearIObjects()
00195 {
00196   Clear();
00197 }
00198 
00202 void SALOME_Selection::ClearFilters()
00203 {
00204   class TEvent: public SALOME_Event {
00205     LightApp_SelectionMgr* mySelMgr;
00206   public:
00207     TEvent( LightApp_SelectionMgr* selMgr ) 
00208       : mySelMgr( selMgr ) {}
00209     virtual void Execute() {
00210       if ( mySelMgr )
00211         mySelMgr->clearFilters();
00212     }
00213   };
00214   ProcessVoidEvent( new TEvent( mySelMgr ) );
00215 }
00216 
00241 class TGetDesktopEvent: public SALOME_Event 
00242 {
00243 public:
00244   typedef QWidget* TResult;
00245   TResult myResult;
00246   TGetDesktopEvent() : myResult( 0 ) {}
00247   virtual void Execute()
00248   {
00249     if ( getApplication() )
00250       myResult = (QWidget*)( getApplication()->desktop() );
00251   }
00252 };
00253 QWidget* SalomePyQt::getDesktop()
00254 {
00255   return ProcessEvent( new TGetDesktopEvent() );
00256 }
00257 
00268 class TGetMainFrameEvent: public SALOME_Event
00269 {
00270 public:
00271   typedef QWidget* TResult;
00272   TResult myResult;
00273   TGetMainFrameEvent() : myResult( 0 ) {}
00274   virtual void Execute()
00275   {
00276     if ( getApplication() ) {
00277       SUIT_Desktop* aDesktop = getApplication()->desktop();
00278       myResult = (QWidget*)( aDesktop->centralWidget() );
00279     }
00280   }
00281 };
00282 QWidget* SalomePyQt::getMainFrame()
00283 {
00284   return ProcessEvent( new TGetMainFrameEvent() );
00285 }
00286 
00293 class TGetMainMenuBarEvent: public SALOME_Event
00294 {
00295 public:
00296   typedef QMenuBar* TResult;
00297   TResult myResult;
00298   TGetMainMenuBarEvent() : myResult( 0 ) {}
00299   virtual void Execute()
00300   {
00301     if ( LightApp_Application* anApp = getApplication() ) {
00302       myResult = anApp->desktop()->menuBar();
00303     }
00304   }
00305 };
00306 QMenuBar* SalomePyQt::getMainMenuBar() 
00307 {
00308   return ProcessEvent( new TGetMainMenuBarEvent() );
00309 }
00310 
00332 class TGetPopupMenuEvent: public SALOME_Event
00333 {
00334 public:
00335   typedef QMenu* TResult;
00336   TResult myResult;
00337   QString myMenuName;
00338   TGetPopupMenuEvent( const QString& menu ) : myResult( 0 ), myMenuName( menu ) {}
00339   virtual void Execute()
00340   {
00341     LightApp_Application* anApp = getApplication();
00342     if ( anApp && !myMenuName.isEmpty() ) {
00343       QtxActionMenuMgr* mgr = anApp->desktop()->menuMgr();
00344       myResult = mgr->findMenu( myMenuName, -1, false ); // search only top menu
00345     }
00346   }
00347 };
00348 
00355 static QString getMenuName( const QString& menuId )
00356 {
00357   QStringList contexts;
00358   contexts << "SalomeApp_Application" << "LightApp_Application" << "STD_TabDesktop" <<
00359     "STD_MDIDesktop" << "STD_Application" << "SUIT_Application" << "";
00360   QString menuName = menuId;
00361   for ( int i = 0; i < contexts.count() && menuName == menuId; i++ )
00362     menuName = QApplication::translate( contexts[i].toLatin1().data(), menuId.toLatin1().data() );
00363   return menuName;
00364 }
00365 
00366 QMenu* SalomePyQt::getPopupMenu( const MenuName menu )
00367 {
00368   QString menuName;
00369   switch( menu ) {
00370   case File:
00371     menuName = getMenuName( "MEN_DESK_FILE" );        break;
00372   case View:
00373     menuName = getMenuName( "MEN_DESK_VIEW" );        break;
00374   case Edit:
00375     menuName = getMenuName( "MEN_DESK_EDIT" );        break;
00376   case Preferences:
00377     menuName = getMenuName( "MEN_DESK_PREFERENCES" ); break;
00378   case Tools:
00379     menuName = getMenuName( "MEN_DESK_TOOLS" );       break;
00380   case Window:
00381     menuName = getMenuName( "MEN_DESK_WINDOW" );      break;
00382   case Help:
00383     menuName = getMenuName( "MEN_DESK_HELP" );        break;
00384   }
00385   return ProcessEvent( new TGetPopupMenuEvent( menuName ) );
00386 }
00387 QMenu* SalomePyQt::getPopupMenu( const QString& menu )
00388 {
00389   return ProcessEvent( new TGetPopupMenuEvent( menu ) );
00390 }
00391 
00398 class TGetObjectBrowserEvent: public SALOME_Event
00399 {
00400 public:
00401   typedef QTreeView* TResult;
00402   TResult myResult;
00403   TGetObjectBrowserEvent() : myResult( 0 ) {}
00404   virtual void Execute()
00405   {
00406     LightApp_Application* anApp = getApplication();
00407     if ( anApp ) {
00408       myResult = anApp->objectBrowser()->treeView();
00409     }
00410   }
00411 };
00412 QTreeView* SalomePyQt::getObjectBrowser()
00413 {
00414   return ProcessEvent( new TGetObjectBrowserEvent() );
00415 }
00416 
00423 class TGetStudyIdEvent: public SALOME_Event
00424 {
00425 public:
00426   typedef int TResult;
00427   TResult myResult;
00428   TGetStudyIdEvent() : myResult( 0 ) {}
00429   virtual void Execute()
00430   {
00431     if ( LightApp_Study* aStudy = getActiveStudy() ) {
00432       myResult = aStudy->id();
00433     }
00434   }
00435 };
00436 int SalomePyQt::getStudyId()
00437 {
00438   return ProcessEvent( new TGetStudyIdEvent() );
00439 }
00440 
00450 class TGetSelectionEvent: public SALOME_Event 
00451 {
00452 public:
00453   typedef SALOME_Selection* TResult;
00454   TResult myResult;
00455   TGetSelectionEvent() : myResult( 0 ) {}
00456   virtual void Execute() 
00457   {
00458     myResult = SALOME_Selection::GetSelection( getApplication() );
00459   }
00460 };
00461 SALOME_Selection* SalomePyQt::getSelection()
00462 {
00463   return ProcessEvent( new TGetSelectionEvent() );
00464 }
00465 
00479 class TPutInfoEvent: public SALOME_Event
00480 {
00481   QString myMsg;
00482   int     mySecs;
00483 public:
00484   TPutInfoEvent( const QString& msg, const int sec = 0 ) : myMsg( msg ), mySecs( sec ) {}
00485   virtual void Execute()
00486   {
00487     if ( LightApp_Application* anApp = getApplication() ) {
00488       anApp->putInfo( myMsg, mySecs * 1000 );
00489     }
00490   }
00491 };
00492 void SalomePyQt::putInfo( const QString& msg, const int sec )
00493 {
00494   ProcessVoidEvent( new TPutInfoEvent( msg, sec ) );
00495 }
00496 
00503 class TGetActiveComponentEvent: public SALOME_Event
00504 {
00505 public:
00506   typedef QString TResult;
00507   TResult myResult;
00508   TGetActiveComponentEvent() {}
00509   virtual void Execute() 
00510   {
00511     if ( LightApp_Application* anApp = getApplication() ) {
00512       if ( CAM_Module* mod = anApp->activeModule() ) {
00513         myResult = mod->name();
00514       }
00515     }
00516   }
00517 };
00518 const QString SalomePyQt::getActiveComponent()
00519 {
00520   return ProcessEvent( new TGetActiveComponentEvent() );
00521 }
00522 
00529 class TGetActivePyModuleEvent: public SALOME_Event
00530 {
00531 public:
00532   typedef PyObject* TResult;
00533   TResult myResult;
00534   TGetActivePyModuleEvent() : myResult( 0 ) {}
00535   virtual void Execute() 
00536   {
00537     SALOME_PYQT_ModuleLight* module = getActiveModule();
00538     if ( module )
00539       myResult = (PyObject*)module->getPythonModule();
00540   }
00541 };
00542 PyObject* SalomePyQt::getActivePythonModule()
00543 {
00544   return ProcessEvent( new TGetActivePyModuleEvent() );
00545 }
00546 
00553 class TActivateModuleEvent: public SALOME_Event
00554 {
00555 public:
00556   typedef bool TResult;
00557   TResult myResult;
00558   QString myModuleName;
00559   TActivateModuleEvent( const QString& modName ) 
00560   : myResult( false ), myModuleName( modName ) {}
00561   virtual void Execute() 
00562   {
00563     if ( LightApp_Application* anApp = getApplication() ) {
00564       myResult = anApp->activateModule( myModuleName );
00565     }
00566   }
00567 };
00568 bool SalomePyQt::activateModule( const QString& modName )
00569 {
00570   return ProcessEvent( new TActivateModuleEvent( modName ) );
00571 }
00572 
00585 void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection )
00586 {  
00587   class TEvent: public SALOME_Event
00588   {
00589     int  myStudyId;
00590     bool myUpdateSelection;
00591   public:
00592     TEvent( const int studyId, bool updateSelection ) 
00593       : myStudyId( studyId ), myUpdateSelection( updateSelection ) {}
00594     virtual void Execute()
00595     {
00596       if ( SUIT_Session::session() ) {
00597         if ( getActiveStudy() && myStudyId <= 0 )
00598           myStudyId = getActiveStudy()->id();
00599         if ( myStudyId > 0 ) {
00600           QList<SUIT_Application*> apps = SUIT_Session::session()->applications();
00601           QList<SUIT_Application*>::Iterator it;
00602           for( it = apps.begin(); it != apps.end(); ++it ) {
00603             LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( *it );
00604             if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) {
00605               anApp->updateObjectBrowser();
00606               return;
00607             }
00608           }
00609         }
00610       }
00611     }
00612   };
00613   ProcessVoidEvent( new TEvent( studyId, updateSelection ) );
00614 }
00615 
00616 
00623 class TIsModifiedEvent: public SALOME_Event
00624 {
00625 public:
00626   typedef bool TResult;
00627   TResult myResult;
00628   TIsModifiedEvent() : myResult( false ) {}
00629   virtual void Execute() 
00630   {
00631     SALOME_PYQT_ModuleLight* module = getActiveModule();
00632     if ( !module )
00633       return;
00634     
00635     SALOME_PYQT_DataModelLight* aModel =
00636       dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
00637     if ( aModel )
00638       myResult = aModel->isModified();
00639   }
00640 };
00641 bool SalomePyQt::isModified()
00642 {
00643   return ProcessEvent(new TIsModifiedEvent());
00644 }
00645 
00658 void SalomePyQt::setModified( bool flag )
00659 {  
00660   class TEvent: public SALOME_Event
00661   {
00662     bool myFlag;
00663   public:
00664     TEvent( bool flag ) 
00665       : myFlag( flag ) {}
00666     virtual void Execute()
00667     {
00668       SALOME_PYQT_ModuleLight* module = getActiveModule();
00669       if ( !module )
00670        return;
00671 
00672       SALOME_PYQT_DataModelLight* aModel =
00673        dynamic_cast<SALOME_PYQT_DataModelLight*>( module->dataModel() );
00674       LightApp_Application* aLApp = 
00675        dynamic_cast<LightApp_Application*>( module->application() );
00676       if ( !aModel || !aLApp )
00677        return;
00678 
00679       aModel->setModified( myFlag );
00680       aLApp->updateActions();
00681     }
00682   };
00683   ProcessVoidEvent( new TEvent( flag ) );
00684 }
00685 
00690 static const char* DEFAULT_SECTION = "SalomePyQt";
00691 
00706 void SalomePyQt::addStringSetting( const QString& name, const QString& value, bool autoValue )
00707 {
00708   class TEvent: public SALOME_Event
00709   {
00710     QString myName;
00711     QString myValue;
00712     bool    myAutoValue;
00713   public:
00714     TEvent( const QString& name, const QString& value, bool autoValue ) 
00715       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
00716     virtual void Execute() {
00717       if ( SUIT_Session::session() ) {
00718         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00719         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
00720         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
00721         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
00722         if ( !_sec.isEmpty() && !_nam.isEmpty() )
00723           resMgr->setValue( _sec, _nam, myValue );
00724       }
00725     }
00726   };
00727   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
00728 }
00729 
00744 void SalomePyQt::addIntSetting( const QString& name, const int value, bool autoValue)
00745 {
00746   class TEvent: public SALOME_Event 
00747   {
00748     QString myName;
00749     int     myValue;
00750     bool    myAutoValue;
00751   public:
00752     TEvent( const QString& name, const int value, bool autoValue ) 
00753       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
00754     virtual void Execute()
00755     {
00756       if ( SUIT_Session::session() ) {
00757         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00758         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
00759         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
00760         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
00761         if ( !_sec.isEmpty() && !_nam.isEmpty() )
00762           resMgr->setValue( _sec, _nam, myValue );
00763       }
00764     }
00765   };
00766   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
00767 }
00768 
00783 void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool autoValue )
00784 {
00785   class TEvent: public SALOME_Event 
00786   {
00787     QString myName;
00788     double  myValue;
00789     bool    myAutoValue;
00790   public:
00791     TEvent( const QString& name, const double value, bool autoValue ) 
00792       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
00793     virtual void Execute() 
00794     {
00795       if ( SUIT_Session::session() ) {
00796         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00797         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
00798         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
00799         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
00800         if ( !_sec.isEmpty() && !_nam.isEmpty() )
00801           resMgr->setValue( _sec, _nam, myValue );
00802       }
00803     }
00804   };
00805   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
00806 }
00807 
00822 void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue )
00823 {
00824   class TEvent: public SALOME_Event 
00825   {
00826     QString myName;
00827     bool    myValue;
00828     bool    myAutoValue;
00829   public:
00830     TEvent( const QString& name, const bool value, bool autoValue ) 
00831       : myName( name ), myValue( value ), myAutoValue( autoValue ) {}
00832     virtual void Execute() 
00833     {
00834       if ( SUIT_Session::session() ) {
00835         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00836         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
00837         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
00838         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
00839         if ( !_sec.isEmpty() && !_nam.isEmpty() )
00840           resMgr->setValue( _sec, _nam, myValue );
00841       }
00842     }
00843   };
00844   ProcessVoidEvent( new TEvent( name, value, autoValue ) );
00845 }
00846 
00855 void SalomePyQt::removeSettings( const QString& name )
00856 {
00857   class TEvent: public SALOME_Event {
00858     QString myName;
00859   public:
00860     TEvent( const QString& name ) : myName( name ) {}
00861     virtual void Execute() {
00862       if ( SUIT_Session::session() ) {
00863         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00864         QStringList sl = myName.split( ":", QString::SkipEmptyParts );
00865         QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
00866         QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
00867         if ( !_sec.isEmpty() && !_nam.isEmpty() )
00868           resMgr->remove( _sec, _nam );
00869       }
00870     }
00871   };
00872   ProcessVoidEvent( new TEvent( name ) );
00873 }
00874 
00887 class TGetSettingEvent: public SALOME_Event 
00888 {
00889 public:
00890   typedef QString TResult;
00891   TResult myResult;
00892   QString myName;
00893   TGetSettingEvent( const QString& name ) : myName( name ) {}
00894   virtual void Execute() 
00895   {
00896     if ( SUIT_Session::session() ) {
00897       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00898       QStringList sl = myName.split( ":", QString::SkipEmptyParts );
00899       QString _sec = sl.count() > 1 ? sl[ 0 ].trimmed() : QString( DEFAULT_SECTION );
00900       QString _nam = sl.count() > 1 ? sl[ 1 ].trimmed() : sl.count() > 0 ? sl[ 0 ].trimmed() : QString( "" );
00901       myResult = ( !_sec.isEmpty() && !_nam.isEmpty() ) ? resMgr->stringValue( _sec, _nam, "" ) : QString( "" );
00902     }
00903   }
00904 };
00905 QString SalomePyQt::getSetting( const QString& name )
00906 {
00907   return ProcessEvent( new TGetSettingEvent( name ) );
00908 }
00909 
00916 void SalomePyQt::addSetting( const QString& section, const QString& name, const double value )
00917 {
00918   class TEvent: public SALOME_Event 
00919   {
00920     QString mySection;
00921     QString myName;
00922     double  myValue;
00923   public:
00924     TEvent( const QString& section, const QString& name, double value ) 
00925       : mySection( section ), myName( name ), myValue( value ) {}
00926     virtual void Execute() 
00927     {
00928       if ( SUIT_Session::session() ) {
00929         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00930         if ( !mySection.isEmpty() && !myName.isEmpty() )
00931           resMgr->setValue( mySection, myName, myValue );
00932       }
00933     }
00934   };
00935   ProcessVoidEvent( new TEvent( section, name, value ) );
00936 }
00937 
00944 void SalomePyQt::addSetting( const QString& section, const QString& name, const int value )
00945 {
00946   class TEvent: public SALOME_Event 
00947   {
00948     QString mySection;
00949     QString myName;
00950     int     myValue;
00951   public:
00952     TEvent( const QString& section, const QString& name, int value ) 
00953       : mySection( section ), myName( name ), myValue( value ) {}
00954     virtual void Execute() 
00955     {
00956       if ( SUIT_Session::session() ) {
00957         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00958         if ( !mySection.isEmpty() && !myName.isEmpty() )
00959           resMgr->setValue( mySection, myName, myValue );
00960       }
00961     }
00962   };
00963   ProcessVoidEvent( new TEvent( section, name, value ) );
00964 }
00965 
00974 void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int /*dumb*/ )
00975 {
00976   class TEvent: public SALOME_Event 
00977   {
00978     QString mySection;
00979     QString myName;
00980     bool    myValue;
00981   public:
00982     TEvent( const QString& section, const QString& name, bool value ) 
00983       : mySection( section ), myName( name ), myValue( value ) {}
00984     virtual void Execute() 
00985     {
00986       if ( SUIT_Session::session() ) {
00987         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00988         if ( !mySection.isEmpty() && !myName.isEmpty() )
00989           resMgr->setValue( mySection, myName, myValue );
00990       }
00991     }
00992   };
00993   ProcessVoidEvent( new TEvent( section, name, value ) );
00994 }
00995 
01002 void SalomePyQt::addSetting( const QString& section, const QString& name, const QString& value )
01003 {
01004   class TEvent: public SALOME_Event 
01005   {
01006     QString mySection;
01007     QString myName;
01008     QString myValue;
01009   public:
01010     TEvent( const QString& section, const QString& name, const QString& value ) 
01011       : mySection( section ), myName( name ), myValue( value ) {}
01012     virtual void Execute() 
01013     {
01014       if ( SUIT_Session::session() ) {
01015         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01016         if ( !mySection.isEmpty() && !myName.isEmpty() )
01017           resMgr->setValue( mySection, myName, myValue );
01018       }
01019     }
01020   };
01021   ProcessVoidEvent( new TEvent( section, name, value ) );
01022 }
01023 
01030 void SalomePyQt::addSetting( const QString& section, const QString& name, const QColor& value )
01031 {
01032   class TEvent: public SALOME_Event 
01033   {
01034     QString mySection;
01035     QString myName;
01036     QColor  myValue;
01037   public:
01038     TEvent( const QString& section, const QString& name, const QColor& value ) 
01039       : mySection( section ), myName( name ), myValue( value ) {}
01040     virtual void Execute() 
01041     {
01042       if ( SUIT_Session::session() ) {
01043         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01044         if ( !mySection.isEmpty() && !myName.isEmpty() )
01045           resMgr->setValue( mySection, myName, myValue );
01046       }
01047     }
01048   };
01049   ProcessVoidEvent( new TEvent( section, name, value ) );
01050 }
01051 
01063 class TGetIntSettingEvent: public SALOME_Event 
01064 {
01065 public:
01066   typedef int TResult;
01067   TResult myResult;
01068   QString mySection;
01069   QString myName;
01070   TResult myDefault;
01071   TGetIntSettingEvent( const QString& section, const QString& name, const int def ) 
01072     : mySection( section ), myName( name ), myDefault( def ) {}
01073   virtual void Execute() 
01074   {
01075     if ( SUIT_Session::session() ) {
01076       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01077       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->integerValue( mySection, myName, myDefault ) : myDefault;
01078     }
01079   }
01080 };
01081 int SalomePyQt::integerSetting( const QString& section, const QString& name, const int def )
01082 {
01083   return ProcessEvent( new TGetIntSettingEvent( section, name, def ) );
01084 }
01085 
01097 class TGetDblSettingEvent: public SALOME_Event 
01098 {
01099 public:
01100   typedef double TResult;
01101   TResult myResult;
01102   QString mySection;
01103   QString myName;
01104   TResult myDefault;
01105   TGetDblSettingEvent( const QString& section, const QString& name, const double def ) 
01106     : mySection( section ), myName( name ), myDefault( def ) {}
01107   virtual void Execute() 
01108   {
01109     if ( SUIT_Session::session() ) {
01110       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01111       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->doubleValue( mySection, myName, myDefault ) : myDefault;
01112     }
01113   }
01114 };
01115 double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def )
01116 {
01117   return ProcessEvent( new TGetDblSettingEvent( section, name, def ) );
01118 }
01119 
01131 class TGetBoolSettingEvent: public SALOME_Event 
01132 {
01133 public:
01134   typedef bool TResult;
01135   TResult myResult;
01136   QString mySection;
01137   QString myName;
01138   TResult myDefault;
01139   TGetBoolSettingEvent( const QString& section, const QString& name, const bool def ) 
01140     : mySection( section ), myName( name ), myDefault( def ) {}
01141   virtual void Execute() 
01142   {
01143     if ( SUIT_Session::session() ) {
01144       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01145       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->booleanValue( mySection, myName, myDefault ) : myDefault;
01146     }
01147   }
01148 };
01149 bool SalomePyQt::boolSetting( const QString& section, const QString& name, const bool def )
01150 {
01151   return ProcessEvent( new TGetBoolSettingEvent( section, name, def ) );
01152 }
01153 
01165 class TGetStrSettingEvent: public SALOME_Event
01166 {
01167 public:
01168   typedef QString TResult;
01169   TResult myResult;
01170   QString mySection;
01171   QString myName;
01172   TResult myDefault;
01173   TGetStrSettingEvent( const QString& section, const QString& name, const QString& def ) 
01174     : mySection( section ), myName( name ), myDefault( def ) {}
01175   virtual void Execute() 
01176   {
01177     if ( SUIT_Session::session() ) {
01178       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01179       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->stringValue( mySection, myName, myDefault ) : myDefault;
01180     }
01181   }
01182 };
01183 QString SalomePyQt::stringSetting( const QString& section, const QString& name, const QString& def )
01184 {
01185   return ProcessEvent( new TGetStrSettingEvent( section, name, def ) );
01186 }
01187 
01199 class TGetColorSettingEvent: public SALOME_Event 
01200 {
01201 public:
01202   typedef QColor TResult;
01203   TResult myResult;
01204   QString mySection;
01205   QString myName;
01206   TResult myDefault;
01207   TGetColorSettingEvent( const QString& section, const QString& name, const QColor& def ) 
01208     : mySection( section ), myName( name ), myDefault( def ) {}
01209   virtual void Execute() 
01210   {
01211     if ( SUIT_Session::session() ) {
01212       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01213       myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->colorValue( mySection, myName, myDefault ) : myDefault;
01214     }
01215   }
01216 };
01217 QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, const QColor& def )
01218 {
01219   return ProcessEvent( new TGetColorSettingEvent( section, name, def ) );
01220 }
01221 
01227 void SalomePyQt::removeSetting( const QString& section, const QString& name )
01228 {
01229   class TEvent: public SALOME_Event 
01230   {
01231     QString mySection;
01232     QString myName;
01233   public:
01234     TEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {}
01235     virtual void Execute() 
01236     {
01237       if ( SUIT_Session::session() ) {
01238         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01239         if ( !mySection.isEmpty() && !myName.isEmpty() )
01240           resMgr->remove( mySection, myName );
01241       }
01242     }
01243   };
01244   ProcessVoidEvent( new TEvent( section, name ) );
01245 }
01246 
01255 class THasColorSettingEvent: public SALOME_Event 
01256 {
01257 public:
01258   typedef bool TResult;
01259   TResult myResult;
01260   QString mySection;
01261   QString myName;
01262   THasColorSettingEvent( const QString& section, const QString& name ) 
01263     : mySection( section ), myName( name ) {}
01264   virtual void Execute() 
01265   {
01266     if ( SUIT_Session::session() ) {
01267       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
01268       myResult = resMgr->hasValue( mySection, myName );
01269     }
01270   }
01271 };
01272 bool SalomePyQt::hasSetting( const QString& section, const QString& name )
01273 {
01274   return ProcessEvent( new THasColorSettingEvent( section, name ) );
01275 }
01276 
01294 class TGetFileNameEvent: public SALOME_Event 
01295 {
01296 public:
01297   typedef QString TResult;
01298   TResult     myResult;
01299   QWidget*    myParent;
01300   QString     myInitial;
01301   QStringList myFilters;
01302   QString     myCaption;
01303   bool        myOpen;
01304   TGetFileNameEvent( QWidget*           parent, 
01305                      const QString&     initial, 
01306                      const QStringList& filters, 
01307                      const QString&     caption,
01308                      bool               open ) 
01309     : myParent ( parent ), 
01310       myInitial( initial ), 
01311       myFilters( filters ), 
01312       myCaption( caption ), 
01313       myOpen ( open ) {}
01314   virtual void Execute() 
01315   {
01316     if ( LightApp_Application* anApp = getApplication() ) {
01317       myResult = anApp->getFileName( myOpen, myInitial, myFilters.join(";;"), 
01318                                      myCaption, myParent );
01319     }
01320   }
01321 };
01322 QString SalomePyQt::getFileName( QWidget*           parent, 
01323                                  const QString&     initial, 
01324                                  const QStringList& filters, 
01325                                  const QString&     caption,
01326                                  bool               open )
01327 {
01328   return ProcessEvent( new TGetFileNameEvent( parent, initial, filters, caption, open ) );
01329 }
01330 
01345 class TGetOpenFileNamesEvent: public SALOME_Event 
01346 {
01347 public:
01348   typedef QStringList TResult;
01349   TResult     myResult;
01350   QWidget*    myParent;
01351   QString     myInitial;
01352   QStringList myFilters;
01353   QString     myCaption;
01354   TGetOpenFileNamesEvent( QWidget*           parent, 
01355                           const QString&     initial, 
01356                           const QStringList& filters, 
01357                           const QString&     caption ) 
01358     : myParent ( parent ), 
01359       myInitial( initial ), 
01360       myFilters( filters ), 
01361       myCaption( caption ) {}
01362   virtual void Execute() 
01363   {
01364     if ( LightApp_Application* anApp = getApplication() ) {
01365       myResult = anApp->getOpenFileNames( myInitial, myFilters.join(";;"), myCaption, myParent );
01366     }
01367   }
01368 };
01369 QStringList SalomePyQt::getOpenFileNames( QWidget*           parent, 
01370                                           const QString&     initial, 
01371                                           const QStringList& filters, 
01372                                           const QString&     caption )
01373 {
01374   return ProcessEvent( new TGetOpenFileNamesEvent( parent, initial, filters, caption ) );
01375 }
01376 
01389 class TGetExistingDirectoryEvent: public SALOME_Event 
01390 {
01391 public:
01392   typedef QString TResult;
01393   TResult     myResult;
01394   QWidget*    myParent;
01395   QString     myInitial;
01396   QString     myCaption;
01397   TGetExistingDirectoryEvent( QWidget*           parent, 
01398                               const QString&     initial, 
01399                               const QString&     caption ) 
01400     : myParent ( parent ), 
01401       myInitial( initial ), 
01402       myCaption( caption ) {}
01403   virtual void Execute() 
01404   {
01405     if ( LightApp_Application* anApp = getApplication() ) {
01406       myResult = anApp->getDirectory( myInitial, myCaption, myParent );
01407     }
01408   }
01409 };
01410 QString SalomePyQt::getExistingDirectory( QWidget*       parent,
01411                                           const QString& initial,
01412                                           const QString& caption )
01413 {
01414   return ProcessEvent( new TGetExistingDirectoryEvent( parent, initial, caption ) );
01415 }
01416 
01423 class TLoadIconEvent: public SALOME_Event 
01424 {
01425 public:
01426   typedef QIcon TResult;
01427   TResult     myResult;
01428   QString     myModule;
01429   QString     myFileName;
01430   TLoadIconEvent( const QString& module, const QString& filename ) 
01431     : myModule( module ), 
01432       myFileName ( filename ) {}
01433   virtual void Execute() 
01434   {
01435     if ( LightApp_Application* anApp = getApplication() ) {
01436       if ( !myFileName.isEmpty() ) {
01437         QPixmap pixmap = anApp->resourceMgr()->loadPixmap( myModule, 
01438                          QApplication::translate( myModule.toLatin1().data(), 
01439                                                   myFileName.toLatin1().data() ) );
01440         if ( !pixmap.isNull() )
01441           myResult = QIcon( pixmap );
01442       }
01443     }
01444   }
01445 };
01446 QIcon SalomePyQt::loadIcon( const QString& module, const QString& filename )
01447 {
01448   return ProcessEvent( new TLoadIconEvent( module, filename ) );
01449 }
01450 
01460 void SalomePyQt::helpContext( const QString& source, const QString& context ) 
01461 {
01462   class TEvent: public SALOME_Event 
01463   {
01464     QString mySource;
01465     QString myContext;
01466   public:
01467     TEvent( const QString& source, const QString& context ) 
01468       : mySource( source ), myContext( context ) {}
01469     virtual void Execute() 
01470     {
01471       if ( LightApp_Application* anApp = getApplication() ) {
01472         anApp->onHelpContextModule( "", mySource, myContext );
01473       }
01474     }
01475   };
01476   ProcessVoidEvent( new TEvent( source, context ) );
01477 }
01478 
01492 class TDumpViewEvent: public SALOME_Event 
01493 {
01494 public:
01495   typedef bool TResult;
01496   TResult myResult;
01497   QString myFileName;
01498   TDumpViewEvent( const QString& filename ) 
01499     : myResult ( false ), myFileName( filename ) {}
01500   virtual void Execute() 
01501   {
01502     if ( LightApp_Application* anApp = getApplication() ) {
01503       SUIT_ViewManager* vm = anApp->activeViewManager();
01504       if ( vm ) { 
01505         SUIT_ViewWindow* vw = vm->getActiveView();
01506         if ( vw ) {
01507           QImage im = vw->dumpView();
01508           if ( !im.isNull() && !myFileName.isEmpty() ) {
01509             QString fmt = SUIT_Tools::extension( myFileName ).toUpper();
01510             if ( fmt.isEmpty() ) fmt = QString( "BMP" ); // default format
01511             if ( fmt == "JPG" )  fmt = "JPEG";
01512             myResult = im.save( myFileName, fmt.toLatin1() );
01513           }
01514         }
01515       }
01516     }
01517   }
01518 };
01519 bool SalomePyQt::dumpView( const QString& filename )
01520 {
01521   return ProcessEvent( new TDumpViewEvent( filename ) );
01522 }
01523 
01531 class TDefMenuGroupEvent: public SALOME_Event 
01532 {
01533 public:
01534   typedef int TResult;
01535   TResult myResult;
01536   TDefMenuGroupEvent() : myResult( -1 ) {}
01537   virtual void Execute() 
01538   {
01539     myResult = SALOME_PYQT_ModuleLight::defaultMenuGroup();
01540   }
01541 };
01542 int SalomePyQt::defaultMenuGroup()
01543 {
01544   return ProcessEvent( new TDefMenuGroupEvent() );
01545 }
01546 
01547 class CrTool
01548 {
01549 public:
01550   CrTool( const QString& tBar ) 
01551     : myCase( 0 ), myTbName( tBar ) {}
01552   CrTool( const int id, const int tBar, const int idx ) 
01553     : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {}
01554   CrTool( const int id, const QString& tBar, const int idx )
01555     : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {}
01556   CrTool( QAction* action, const int tbId, const int id, const int idx )
01557     : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {}
01558   CrTool( QAction* action, const QString& tBar, const int id, const int idx )
01559     : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {}
01560 
01561   int execute( SALOME_PYQT_ModuleLight* module ) const
01562   {
01563     if ( module ) {
01564       switch ( myCase ) {
01565       case 0:
01566         return module->createTool( myTbName );
01567       case 1:
01568         return module->createTool( myId, myTbId, myIndex );
01569       case 2:
01570         return module->createTool( myId, myTbName, myIndex );
01571       case 3:
01572         return module->createTool( myAction, myTbId, myId, myIndex );
01573       case 4:
01574         return module->createTool( myAction, myTbName, myId, myIndex );
01575       }
01576     }
01577     return -1;
01578   }
01579 private:
01580    int        myCase;
01581    QString    myTbName;
01582    int        myTbId;
01583    QAction*   myAction;
01584    int        myId;
01585    int        myIndex;
01586 };
01587 
01588 class TCreateToolEvent: public SALOME_Event 
01589 {
01590 public:
01591   typedef int TResult;
01592   TResult myResult;
01593   const CrTool& myCrTool;
01594   TCreateToolEvent( const CrTool& crTool ) 
01595     : myResult( -1 ), myCrTool( crTool ) {}
01596   virtual void Execute() 
01597   {
01598     SALOME_PYQT_ModuleLight* module = getActiveModule();
01599     if ( module )
01600       myResult = myCrTool.execute( module );
01601   }
01602 };
01603 
01609 int SalomePyQt::createTool( const QString& tBar )
01610 {
01611   return ProcessEvent( new TCreateToolEvent( CrTool( tBar ) ) );
01612 }
01613 
01621 int SalomePyQt::createTool( const int id, const int tBar, const int idx )
01622 {
01623   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
01624 }
01625 
01633 int SalomePyQt::createTool( const int id, const QString& tBar, const int idx )
01634 {
01635   return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) );
01636 }
01637 
01646 int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx )
01647 {
01648   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
01649 }
01650 
01659 int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx )
01660 {
01661   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
01662 }
01663 
01664 class CrMenu
01665 {
01666 public:
01667   CrMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx ) 
01668     : myCase( 0 ), mySubMenuName( subMenu ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
01669   CrMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx ) 
01670     : myCase( 1 ), mySubMenuName( subMenu ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
01671   CrMenu( const int id, const int menu, const int group, const int idx ) 
01672     : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {}
01673   CrMenu( const int id, const QString& menu, const int group, const int idx ) 
01674     : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {}
01675   CrMenu( QAction* action, const int menu, const int id, const int group, const int idx ) 
01676     : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
01677   CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) 
01678     : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
01679 
01680   int execute( LightApp_Module* module ) const
01681   {
01682     if ( module ) {
01683       switch ( myCase ) {
01684       case 0:
01685         return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
01686       case 1:
01687         return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
01688       case 2:
01689         return module->createMenu( myId, myMenuId, myGroup, myIndex );
01690       case 3:
01691         return module->createMenu( myId, myMenuName, myGroup, myIndex );
01692       case 4:
01693         return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
01694       case 5:
01695         return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
01696       }
01697     }
01698     return -1;
01699   }
01700 private:
01701    int        myCase;
01702    QString    myMenuName;
01703    int        myMenuId;
01704    QString    mySubMenuName;
01705    int        myGroup;
01706    QAction*   myAction;
01707    int        myId;
01708    int        myIndex;
01709 };
01710 
01711 class TCreateMenuEvent: public SALOME_Event
01712 {
01713 public:
01714   typedef int TResult;
01715   TResult myResult;
01716   const CrMenu& myCrMenu;
01717   TCreateMenuEvent( const CrMenu& crMenu ) 
01718     : myResult( -1 ), myCrMenu( crMenu ) {}
01719   virtual void Execute()
01720   {
01721     if ( LightApp_Application* anApp = getApplication() ) 
01722       {
01723         LightApp_Module* module = dynamic_cast<LightApp_Module*>( anApp->activeModule() );
01724         if ( module )
01725           myResult = myCrMenu.execute( module );
01726       }
01727   }
01728 };
01729 
01739 int SalomePyQt::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
01740 {
01741   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
01742 }
01743 
01753 int SalomePyQt::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
01754 {
01755   return ProcessEvent( new TCreateMenuEvent( CrMenu( subMenu, menu, id, group, idx ) ) );
01756 }
01757 
01766 int SalomePyQt::createMenu( const int id, const int menu, const int group, const int idx )
01767 {
01768   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
01769 }
01770 
01779 int SalomePyQt::createMenu( const int id, const QString& menu, const int group, const int idx )
01780 {
01781   return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) );
01782 }
01783 
01792 int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
01793 {
01794   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
01795 }
01796 
01805 int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
01806 {
01807   return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) );
01808 }
01809 
01816 class TCreateSepEvent: public SALOME_Event 
01817 {
01818 public:
01819   typedef QAction* TResult;
01820   TResult myResult;
01821   TCreateSepEvent() 
01822     : myResult( 0 ) {}
01823   virtual void Execute() 
01824   {
01825     SALOME_PYQT_ModuleLight* module = getActiveModule();
01826     if ( module )
01827       myResult = (QAction*)module->separator();
01828   }
01829 };
01830 QAction* SalomePyQt::createSeparator()
01831 {
01832   return ProcessEvent( new TCreateSepEvent() );
01833 }
01834 
01853 class TCreateActionEvent: public SALOME_Event 
01854 {
01855 public:
01856   typedef QAction* TResult;
01857   TResult myResult;
01858   int     myId;
01859   QString myMenuText;
01860   QString myTipText;
01861   QString myStatusText;
01862   QString myIcon;
01863   int     myKey;
01864   bool    myToggle;
01865   TCreateActionEvent( const int id, const QString& menuText, const QString& tipText, 
01866                       const QString& statusText, const QString& icon, const int key, const bool toggle ) 
01867     : myResult( 0 ), myId( id ), myMenuText( menuText ), myTipText( tipText ),
01868       myStatusText( statusText ), myIcon( icon ), myKey( key ), myToggle( toggle ) {}
01869   virtual void Execute()
01870   {
01871     SALOME_PYQT_ModuleLight* module = getActiveModule();
01872     if ( module )
01873       myResult = (QAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle );
01874   }
01875 };
01876 QAction* SalomePyQt::createAction( const int id,           const QString& menuText, 
01877                                      const QString& tipText, const QString& statusText, 
01878                                      const QString& icon,    const int key, const bool toggle )
01879 {
01880   return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) );
01881 }
01882 
01890 struct TcreateActionGroupEvent: public SALOME_Event {
01891   typedef QtxActionGroup* TResult;
01892   TResult myResult;
01893   int     myId;
01894   bool    myExclusive;
01895   TcreateActionGroupEvent( const int id, const bool exclusive )
01896     : myId( id ), myExclusive( exclusive ) {}
01897   virtual void Execute()
01898   {
01899     SALOME_PYQT_ModuleLight* module = getActiveModule();
01900     if ( module )
01901       myResult = module->createActionGroup( myId, myExclusive );
01902   }
01903 };
01904 QtxActionGroup* SalomePyQt::createActionGroup(const int id, const bool exclusive)
01905 {
01906   return ProcessEvent( new TcreateActionGroupEvent( id, exclusive ) );
01907 }
01908 
01915 class TActionEvent: public SALOME_Event 
01916 {
01917 public:
01918   typedef QAction* TResult;
01919   TResult myResult;
01920   int     myId;
01921   TActionEvent( const int id )
01922     : myResult( 0 ), myId( id ) {}
01923   virtual void Execute()
01924   {
01925     SALOME_PYQT_ModuleLight* module = getActiveModule();
01926     if ( module )
01927       myResult = (QAction*)module->action( myId );
01928   }
01929 };
01930 QAction* SalomePyQt::action( const int id )
01931 {
01932   return ProcessEvent( new TActionEvent( id ) );
01933 }
01934 
01941 class TActionIdEvent: public SALOME_Event 
01942 {
01943 public:
01944   typedef  int TResult;
01945   TResult  myResult;
01946   const QAction* myAction;
01947   TActionIdEvent( const QAction* action )
01948     : myResult( -1 ), myAction( action ) {}
01949   virtual void Execute()
01950   {
01951     SALOME_PYQT_ModuleLight* module = getActiveModule();
01952     if ( module )
01953       myResult = module->actionId( myAction );
01954   }
01955 };
01956 int SalomePyQt::actionId( const QAction* a )
01957 {
01958   return ProcessEvent( new TActionIdEvent( a ) );
01959 }
01960 
01968 class TAddGlobalPrefEvent: public SALOME_Event
01969 {
01970 public:
01971   typedef int TResult;
01972   TResult myResult;
01973   QString myLabel;
01974   TAddGlobalPrefEvent( const QString& label )
01975     : myResult( -1 ), myLabel( label ) {}
01976   virtual void Execute() 
01977   {
01978     SALOME_PYQT_ModuleLight* module = getActiveModule();
01979     if ( module )
01980       myResult = module->addGlobalPreference( myLabel );
01981   }
01982 };
01983 int SalomePyQt::addGlobalPreference( const QString& label )
01984 {
01985   return ProcessEvent( new TAddGlobalPrefEvent( label ) );
01986 }
01987 
01995 class TAddPrefEvent: public SALOME_Event 
01996 {
01997 public:
01998   typedef int TResult;
01999   TResult myResult;
02000   QString myLabel;
02001   TAddPrefEvent( const QString& label )
02002     : myResult( -1 ), myLabel( label ) {}
02003   virtual void Execute() 
02004   {
02005     SALOME_PYQT_ModuleLight* module = getActiveModule();
02006     if ( module )
02007       myResult = module->addPreference( myLabel );
02008   }
02009 };
02010 int SalomePyQt::addPreference( const QString& label )
02011 {
02012   return ProcessEvent( new TAddPrefEvent( label ) );
02013 }
02014 
02027 class TAddPrefParamEvent: public SALOME_Event
02028 {
02029 public:
02030   typedef int TResult;
02031   TResult myResult;
02032   QString myLabel;
02033   int     myPId;
02034   int     myType;
02035   QString mySection;
02036   QString myParam;
02037   TAddPrefParamEvent( const QString& label, 
02038                       const int pId, const int type,
02039                       const QString& section, 
02040                       const QString& param )
02041     : myResult( -1 ),
02042       myLabel( label ), myPId( pId ), myType( type ), 
02043       mySection( section ), myParam ( param ) {}
02044   virtual void Execute()
02045   {
02046     SALOME_PYQT_ModuleLight* module = getActiveModule();
02047     if ( module )
02048       myResult = module->addPreference( myLabel, myPId, myType, mySection, myParam );
02049   }
02050 };
02051 int SalomePyQt::addPreference( const QString& label, const int pId, const int type,
02052                                const QString& section, const QString& param )
02053 {
02054   return ProcessEvent( new TAddPrefParamEvent( label, pId, type, section, param ) );
02055 }
02056 
02065 class TPrefPropEvent: public SALOME_Event
02066 {
02067 public:
02068   typedef QVariant TResult;
02069   TResult myResult;
02070   int     myId;
02071   QString myProp;
02072   TPrefPropEvent( const int id, const QString& prop )
02073     : myId( id ), myProp( prop ) {}
02074   virtual void Execute()
02075   {
02076     SALOME_PYQT_ModuleLight* module = getActiveModule();
02077     if ( module )
02078       myResult = module->preferenceProperty( myId, myProp );
02079   }
02080 };
02081 QVariant SalomePyQt::preferenceProperty( const int id, const QString& prop )
02082 {
02083   return ProcessEvent( new TPrefPropEvent( id, prop ) );
02084 }
02085 
02092 void SalomePyQt::setPreferenceProperty( const int id, 
02093                                         const QString& prop,
02094                                         const QVariant& var )
02095 {
02096   class TEvent: public SALOME_Event
02097   {
02098     int      myId;
02099     QString  myProp;
02100     QVariant myVar;
02101   public:
02102     TEvent( const int id, const QString& prop, const QVariant& var ) 
02103       : myId( id ), myProp( prop ), myVar( var ) {}
02104     virtual void Execute() 
02105     {
02106       SALOME_PYQT_ModuleLight* module = getActiveModule();
02107       if ( module )
02108         module->setPreferenceProperty( myId, myProp, myVar );
02109     }
02110   };
02111   ProcessVoidEvent( new TEvent( id, prop, var) );
02112 }
02113 
02125 void SalomePyQt::addPreferenceProperty( const int id, 
02126                                         const QString& prop,
02127                                         const int idx, 
02128                                         const QVariant& var )
02129 {
02130   class TEvent: public SALOME_Event
02131   {
02132     int      myId;
02133     QString  myProp;
02134     int      myIdx;
02135     QVariant myVar;
02136   public:
02137     TEvent( const int id, const QString& prop, const int idx, const QVariant& var ) 
02138       : myId( id ), myProp( prop ), myIdx( idx), myVar( var ) {}
02139     virtual void Execute()
02140     {
02141       SALOME_PYQT_ModuleLight* module = getActiveModule();
02142       if ( module ) {
02143         QVariant var =  module->preferenceProperty( myId, myProp );
02144         if ( var.isValid() ) {
02145           if ( var.type() == QVariant::StringList ) {
02146             QStringList sl = var.toStringList();
02147             if ( myIdx >= 0 && myIdx < sl.count() ) 
02148               sl[myIdx] = myVar.toString();
02149             else
02150               sl.append( myVar.toString() );
02151             module->setPreferenceProperty( myId, myProp, sl );
02152           }
02153           else if ( var.type() == QVariant::List ) {
02154             QList<QVariant> vl = var.toList();
02155             if ( myIdx >= 0 && myIdx < vl.count() ) 
02156               vl[myIdx] = myVar;
02157             else
02158               vl.append( myVar );
02159             module->setPreferenceProperty( myId, myProp, vl );
02160           }
02161         }
02162         else {
02163           QList<QVariant> vl;
02164           vl.append( myVar );
02165           module->setPreferenceProperty( myId, myProp, vl );
02166         }
02167       }
02168     }
02169   };
02170   ProcessVoidEvent( new TEvent( id, prop, idx, var) );
02171 }
02172 
02179 void SalomePyQt::message( const QString& msg, bool addSeparator )
02180 {
02181   class TEvent: public SALOME_Event
02182   {
02183     QString  myMsg;
02184     bool     myAddSep;
02185   public:
02186     TEvent( const QString& msg, bool addSeparator ) 
02187       : myMsg( msg ), myAddSep( addSeparator ) {}
02188     virtual void Execute()
02189     {
02190       if ( LightApp_Application* anApp = getApplication() ) {
02191         LogWindow* lw = anApp->logWindow();
02192         if ( lw )
02193           lw->putMessage( myMsg, myAddSep );
02194       }
02195     }
02196   };
02197   ProcessVoidEvent( new TEvent( msg, addSeparator ) );
02198 }
02199 
02203 void SalomePyQt::clearMessages()
02204 {
02205   class TEvent: public SALOME_Event
02206   {
02207   public:
02208     TEvent() {}
02209     virtual void Execute()
02210     {
02211       if ( LightApp_Application* anApp = getApplication() ) {
02212         LogWindow* lw = anApp->logWindow();
02213         if ( lw )
02214           lw->clear();
02215       }
02216     }
02217   };
02218   ProcessVoidEvent( new TEvent() );
02219 }
02220 
02227 static SUIT_ViewWindow* getWnd( const int id )
02228 {
02229   SUIT_ViewWindow* resWnd = 0;
02230 
02231   LightApp_Application* app = getApplication();
02232   if ( app )
02233   {
02234     ViewManagerList vmlist = app->viewManagers();
02235     foreach( SUIT_ViewManager* vm, vmlist )
02236     {
02237       QVector<SUIT_ViewWindow*> vwlist = vm->getViews();
02238       foreach ( SUIT_ViewWindow* vw, vwlist )
02239       {
02240         if ( id == vw->getId() )
02241         {
02242           resWnd = vw;
02243           break;
02244         }
02245       }
02246     }
02247   }
02248 
02249   return resWnd;
02250 }
02251 
02258 class TGetViews: public SALOME_Event
02259 {
02260 public:
02261   typedef QList<int> TResult;
02262   TResult myResult;
02263   TGetViews() {}
02264   virtual void Execute() 
02265   {
02266     myResult.clear();
02267     LightApp_Application* app  = getApplication();
02268     if ( app )
02269     {
02270       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
02271       if ( tabDesk )
02272       {
02273         QList<SUIT_ViewWindow*> wndlist = tabDesk->windows();
02274         SUIT_ViewWindow* wnd;
02275         foreach ( wnd, wndlist )
02276           myResult.append( wnd->getId() );
02277       }
02278     }
02279   }
02280 };
02281 QList<int> SalomePyQt::getViews()
02282 {
02283   return ProcessEvent( new TGetViews() );
02284 }
02285 
02292 class TGetActiveView: public SALOME_Event
02293 {
02294 public:
02295   typedef int TResult;
02296   TResult myResult;
02297   TGetActiveView()
02298     : myResult( -1 ) {}
02299   virtual void Execute() 
02300   {
02301     LightApp_Application* app = getApplication();
02302     if ( app )
02303     {
02304       SUIT_ViewManager* viewMgr = app->activeViewManager();
02305       if ( viewMgr )
02306       {
02307         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
02308         if ( wnd )
02309           myResult = wnd->getId();
02310       }
02311     }
02312   }
02313 };
02314 int SalomePyQt::getActiveView()
02315 {
02316   return ProcessEvent( new TGetActiveView() );
02317 }
02318 
02326 class TGetViewType: public SALOME_Event
02327 {
02328 public:
02329   typedef QString TResult;
02330   TResult myResult;
02331   int myWndId;
02332   TGetViewType( const int id )
02333     : myWndId( id ) {}
02334   virtual void Execute() 
02335   {
02336     SUIT_ViewWindow* wnd = getWnd( myWndId );
02337     if ( wnd )
02338     {
02339       SUIT_ViewManager* viewMgr = wnd->getViewManager();
02340       if ( viewMgr )
02341         myResult = viewMgr->getType();
02342     }
02343   }
02344 };
02345 QString SalomePyQt::getViewType( const int id )
02346 {
02347   return ProcessEvent( new TGetViewType( id ) );
02348 }
02349 
02358 class TSetViewTitle: public SALOME_Event
02359 {
02360 public:
02361   typedef bool TResult;
02362   TResult myResult;
02363   int myWndId;
02364   QString myTitle;
02365   TSetViewTitle( const int id, const QString& title )
02366     : myResult( false ),
02367       myWndId( id ),
02368       myTitle( title ) {}
02369   virtual void Execute() 
02370   {
02371     SUIT_ViewWindow* wnd = getWnd( myWndId );
02372     if ( wnd )
02373     {
02374       wnd->setWindowTitle( myTitle );
02375       myResult = true;
02376     }
02377   }
02378 };
02379 bool SalomePyQt::setViewTitle( const int id, const QString& title )
02380 {
02381   return ProcessEvent( new TSetViewTitle( id, title ) );
02382 }
02383 
02384 
02392 class TGetViewTitle: public SALOME_Event
02393 {
02394 public:
02395   typedef QString TResult;
02396   TResult myResult;
02397   int myWndId;
02398   TGetViewTitle( const int id )
02399     : myWndId( id ) {}
02400   virtual void Execute() 
02401   {
02402     SUIT_ViewWindow* wnd = getWnd( myWndId );
02403     if ( wnd )
02404       myResult = wnd->windowTitle();
02405   }
02406 };
02407 QString SalomePyQt::getViewTitle( const int id )
02408 {
02409   return ProcessEvent( new TGetViewTitle( id ) );
02410 }
02411 
02420 class TFindViews: public SALOME_Event
02421 {
02422 public:
02423   typedef QList<int> TResult;
02424   TResult myResult;
02425   QString myType;
02426   TFindViews( const QString& type )
02427     : myType( type ) {}
02428   virtual void Execute() 
02429   {
02430     myResult.clear();
02431     LightApp_Application* app  = getApplication();
02432     if ( app )
02433     {
02434       ViewManagerList vmList;
02435       app->viewManagers( myType, vmList );
02436       SUIT_ViewManager* viewMgr;
02437       foreach ( viewMgr, vmList )
02438       {
02439         QVector<SUIT_ViewWindow*> vec = viewMgr->getViews();
02440         for ( int i = 0, n = vec.size(); i < n; i++ )
02441         {
02442           SUIT_ViewWindow* wnd = vec[ i ];
02443           if ( wnd )
02444             myResult.append( wnd->getId() );
02445         }
02446       }
02447     }
02448   }
02449 };
02450 QList<int> SalomePyQt::findViews( const QString& type )
02451 {
02452   return ProcessEvent( new TFindViews( type ) );
02453 }
02454 
02462 class TActivateView: public SALOME_Event
02463 {
02464 public:
02465   typedef bool TResult;
02466   TResult myResult;
02467   int myWndId;
02468   TActivateView( const int id )
02469     : myResult( false ),
02470       myWndId( id ) {}
02471   virtual void Execute() 
02472   {
02473     SUIT_ViewWindow* wnd = getWnd( myWndId );
02474     if ( wnd )
02475     {
02476       wnd->setFocus();
02477       myResult = true;
02478     }
02479   }
02480 };
02481 bool SalomePyQt::activateView( const int id )
02482 {
02483   return ProcessEvent( new TActivateView( id ) );
02484 }
02485 
02493 class TCreateView: public SALOME_Event
02494 {
02495 public:
02496   typedef int TResult;
02497   TResult myResult;
02498   QString myType;
02499   TCreateView( const QString& theType )
02500     : myResult( -1 ),
02501       myType( theType ) {}
02502   virtual void Execute() 
02503   {
02504     LightApp_Application* app  = getApplication();
02505     if ( app )
02506     {
02507       SUIT_ViewManager* viewMgr = app->createViewManager( myType );
02508       if ( viewMgr )
02509       {
02510         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
02511         if ( wnd )
02512           myResult = wnd->getId();
02513       }
02514     }
02515   }
02516 };
02517 int SalomePyQt::createView( const QString& type )
02518 {
02519   return ProcessEvent( new TCreateView( type ) );
02520 }
02521 
02530 class TCreateViewWg: public SALOME_Event
02531 {
02532 public:
02533   typedef int TResult;
02534   TResult myResult;
02535   QString myType;
02536   QWidget* myWidget;
02537   TCreateViewWg( const QString& theType, QWidget* w )
02538     : myResult( -1 ),
02539       myType( theType ),
02540       myWidget( w ) {}
02541   virtual void Execute() 
02542   {
02543     LightApp_Application* app  = getApplication();
02544     if ( app )
02545     {
02546       SUIT_ViewManager* viewMgr = app->createViewManager( myType, myWidget );
02547       if ( viewMgr )
02548       {
02549         SUIT_ViewWindow* wnd = viewMgr->getActiveView();
02550         if ( wnd )
02551           myResult = wnd->getId();
02552       }
02553     }
02554   }
02555 };
02556 int SalomePyQt::createView( const QString& type, QWidget* w )
02557 {
02558   return ProcessEvent( new TCreateViewWg( type, w ) );
02559 }
02560 
02568 class TCloseView: public SALOME_Event
02569 {
02570 public:
02571   typedef bool TResult;
02572   TResult myResult;
02573   int myWndId;
02574   TCloseView( const int id )
02575     : myResult( false ),
02576       myWndId( id ) {}
02577   virtual void Execute() 
02578   {
02579     SUIT_ViewWindow* wnd = getWnd( myWndId );
02580     if ( wnd )
02581     {
02582       SUIT_ViewManager* viewMgr = wnd->getViewManager();
02583       if ( viewMgr )
02584       {
02585         wnd->close();
02586         myResult = true;
02587       }
02588     }
02589   }
02590 };
02591 bool SalomePyQt::closeView( const int id )
02592 {
02593   return ProcessEvent( new TCloseView( id ) );
02594 }
02595 
02603 class TCloneView: public SALOME_Event
02604 {
02605 public:
02606   typedef int TResult;
02607   TResult myResult;
02608   int myWndId;
02609   TCloneView( const int id )
02610     : myResult( -1 ),
02611       myWndId( id ) {}
02612   virtual void Execute() 
02613   {
02614     SUIT_ViewWindow* wnd = getWnd( myWndId );
02615     if ( wnd )
02616     {
02617       SUIT_ViewManager* viewMgr = wnd->getViewManager();
02618       if ( viewMgr )
02619       {
02620         if ( wnd->inherits( "OCCViewer_ViewWindow" ) )
02621         {
02622           OCCViewer_ViewWindow* occView = (OCCViewer_ViewWindow*)( wnd );
02623           occView->onCloneView();
02624 
02625           wnd = viewMgr->getActiveView();
02626           if ( wnd )
02627             myResult = wnd->getId();
02628         }
02629         else if ( wnd->inherits( "Plot2d_ViewWindow" ) ) 
02630         {
02631           Plot2d_ViewManager* viewMgr2d = dynamic_cast<Plot2d_ViewManager*>( viewMgr );
02632           Plot2d_ViewWindow* srcWnd2d = dynamic_cast<Plot2d_ViewWindow*>( wnd );
02633           if ( viewMgr2d && srcWnd2d )
02634           {
02635             Plot2d_ViewWindow* resWnd = viewMgr2d->cloneView( srcWnd2d );
02636             myResult = resWnd->getId();
02637           }
02638         }
02639       }
02640     }
02641   }
02642 };
02643 int SalomePyQt::cloneView( const int id )
02644 {
02645   return ProcessEvent( new TCloneView( id ) );
02646 }
02647 
02655 class TIsViewVisible: public SALOME_Event
02656 {
02657 public:
02658   typedef bool TResult;
02659   TResult myResult;
02660   int myWndId;
02661   TIsViewVisible( const int id )
02662     : myResult( false ),
02663       myWndId( id ) {}
02664   virtual void Execute() 
02665   {
02666     SUIT_ViewWindow* wnd = getWnd( myWndId );
02667     if ( wnd )
02668     {
02669       QWidget* p = wnd->parentWidget();
02670       myResult = ( p && p->isVisibleTo( p->parentWidget() ) );
02671     }
02672   }
02673 };
02674 bool SalomePyQt::isViewVisible( const int id )
02675 {
02676   return ProcessEvent( new TIsViewVisible( id ) );
02677 }
02678   
02687 void SalomePyQt::setViewClosable( const int id, const bool on )
02688 {
02689   class TEvent: public SALOME_Event
02690   {
02691     int myWndId;
02692     bool myOn;
02693   public:
02694     TEvent( const int id, const bool on )
02695       : myWndId( id ), myOn( on ) {}
02696     virtual void Execute()
02697     {
02698       SUIT_ViewWindow* wnd = getWnd( myWndId );
02699       if ( wnd ) wnd->setClosable( myOn );
02700     }
02701   };
02702   ProcessVoidEvent( new TEvent( id, on ) );
02703 }
02704 
02712 class TIsViewClosable: public SALOME_Event
02713 {
02714 public:
02715   typedef bool TResult;
02716   TResult myResult;
02717   int myWndId;
02718   TIsViewClosable( const int id )
02719     : myResult( true ),
02720       myWndId( id ) {}
02721   virtual void Execute() 
02722   {
02723     SUIT_ViewWindow* wnd = getWnd( myWndId );
02724     if ( wnd )
02725       myResult = wnd->closable();
02726   }
02727 };
02728 
02729 bool SalomePyQt::isViewClosable( const int id )
02730 {
02731   return ProcessEvent( new TIsViewClosable( id ) );
02732 }
02733 
02740 class TGroupAllViews: public SALOME_Event
02741 {
02742 public:
02743   typedef bool TResult;
02744   TResult myResult;
02745   TGroupAllViews()
02746     : myResult( false ) {}
02747   virtual void Execute() 
02748   {
02749     LightApp_Application* app  = getApplication();
02750     if ( app )
02751     {
02752       STD_TabDesktop* tabDesk = dynamic_cast<STD_TabDesktop*>( app->desktop() );
02753       if ( tabDesk )
02754       {
02755         QtxWorkstack* wStack = tabDesk->workstack();
02756         if ( wStack )
02757         {
02758           wStack->stack();
02759           myResult = true;
02760         }
02761       }
02762     }
02763   }
02764 };
02765 bool SalomePyQt::groupAllViews()
02766 {
02767   return ProcessEvent( new TGroupAllViews() );
02768 }
02769 
02779 class TSplitView: public SALOME_Event
02780 {
02781 public:
02782   typedef bool TResult;
02783   TResult myResult;
02784   int myWndId;
02785   Orientation myOri;
02786   Action myAction;
02787   TSplitView( const int id, 
02788               const Orientation ori, 
02789               const Action action )
02790     : myResult( false ),
02791       myWndId( id ),
02792       myOri( ori ),
02793       myAction( action ) {}
02794   virtual void Execute() 
02795   {
02796     SUIT_ViewWindow* wnd = getWnd( myWndId );
02797     if ( wnd )
02798     {
02799       // activate view
02800       // wnd->setFocus(); ???
02801 
02802       // split workstack
02803       if ( getApplication() )
02804       {
02805         STD_TabDesktop* desk = 
02806           dynamic_cast<STD_TabDesktop*>( getApplication()->desktop() );
02807         if ( desk )
02808         {
02809           QtxWorkstack* wStack = desk->workstack();
02810           if ( wStack )
02811           {
02812             Qt::Orientation qtOri = 
02813               ( myOri == Horizontal ) ? Qt::Horizontal : Qt::Vertical;
02814 
02815             QtxWorkstack::SplitType sType;
02816             if ( myAction == MoveWidget )
02817               sType = QtxWorkstack::SplitMove;
02818             else if ( myAction == LeaveWidget )
02819               sType = QtxWorkstack::SplitStay;
02820             else 
02821               sType = QtxWorkstack::SplitAt;
02822 
02823             wStack->Split( wnd, qtOri, sType );
02824             myResult = true;
02825           }
02826         }
02827       }
02828     }
02829   }
02830 };
02831 bool SalomePyQt::splitView( const int id, const Orientation ori, const Action action )
02832 {
02833   return ProcessEvent( new TSplitView( id, ori, action ) );
02834 }
02835 
02847 class TMoveView: public SALOME_Event
02848 {
02849 public:
02850   typedef bool TResult;
02851   TResult myResult;
02852   int myWndId;
02853   int myWndToId;
02854   bool myIsBefore;
02855   TMoveView( const int id, const int id_to, const bool before )
02856     : myResult( false ),
02857     myWndId( id ),
02858     myWndToId( id_to ),
02859     myIsBefore( before ) {}
02860   virtual void Execute() 
02861   {
02862     SUIT_ViewWindow* wnd = getWnd( myWndId );
02863     SUIT_ViewWindow* wnd_to = getWnd( myWndToId );
02864     if ( wnd && wnd_to )
02865     {
02866       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
02867         getApplication()->desktop() )->workstack();
02868       if ( wStack )
02869         myResult = wStack->move( wnd, wnd_to, myIsBefore );
02870     }
02871   }
02872 };
02873 bool SalomePyQt::moveView( const int id, const int id_to, const bool before )
02874 {
02875   return ProcessEvent( new TMoveView( id, id_to, before ) );
02876 }
02877 
02886 class TNeighbourViews: public SALOME_Event
02887 {
02888 public:
02889   typedef QList<int> TResult;
02890   TResult myResult;
02891   int myWndId;
02892   TNeighbourViews( const int id )
02893     : myWndId( id ) {}
02894   virtual void Execute() 
02895   {
02896     myResult.clear();
02897     SUIT_ViewWindow* wnd = getWnd( myWndId );
02898     if ( wnd )
02899     {
02900       QtxWorkstack* wStack = dynamic_cast<STD_TabDesktop*>( 
02901         getApplication()->desktop() )->workstack();
02902       if ( wStack )
02903       {
02904         QWidgetList wgList = wStack->windowList( wnd );
02905         QWidget* wg;
02906         foreach ( wg, wgList )
02907         {
02908           SUIT_ViewWindow* tmpWnd = dynamic_cast<SUIT_ViewWindow*>( wg );
02909           if ( tmpWnd && tmpWnd != wnd )
02910             myResult.append( tmpWnd->getId() );
02911         }
02912       }
02913     }
02914   }
02915 };
02916 QList<int> SalomePyQt::neighbourViews( const int id )
02917 {
02918   return ProcessEvent( new TNeighbourViews( id ) );
02919 }
02920 
02921 
02926 class TCreateEmptyObjectEvent: public SALOME_Event {
02927 public:
02928   typedef QString TResult;
02929   TResult  myResult;
02930   QString  myParent;
02931   TCreateEmptyObjectEvent(const QString& parent) : myParent( parent ) {}
02932   virtual void Execute() {
02933     SALOME_PYQT_ModuleLight* module = getActiveModule();
02934     if ( module )
02935       myResult = (QString)module->createObject(myParent);
02936   }
02937 };
02938 QString SalomePyQt::createObject(const QString& parent)
02939 {
02940   return ProcessEvent( new TCreateEmptyObjectEvent(parent) );
02941 }
02942 
02947 class TCreateObjectEvent: public SALOME_Event {
02948 public:
02949   typedef QString TResult;
02950   TResult myResult;
02951   QString myParent;
02952   QString myName;
02953   QString myIconName;
02954   QString myToolTip;
02955   TCreateObjectEvent(const QString& name,
02956                      const QString& iconname,
02957                      const QString& tooltip,
02958                      const QString& parent) : myName(name),
02959                                               myIconName(iconname),
02960                                               myToolTip(tooltip),
02961                                               myParent( parent ){}
02962   virtual void Execute() {
02963     SALOME_PYQT_ModuleLight* module = getActiveModule();
02964     if ( module )
02965       myResult = (QString)module->createObject(myName, myIconName,
02966                                                myToolTip, myParent);
02967   }
02968 };
02969 QString SalomePyQt::createObject(const QString& name,
02970                                  const QString& iconname,
02971                                  const QString& tooltip,
02972                                  const QString& parent)
02973 {
02974   return ProcessEvent( new TCreateObjectEvent(name, iconname, tooltip, parent) );
02975 }
02976 
02977 
02982 class TSetNameEvent: public SALOME_Event
02983 {
02984 public:
02985   QString myObj;
02986   QString myName;
02987   TSetNameEvent( const QString& obj,
02988                  const QString& name) : myObj(obj),
02989                                          myName(name) {}
02990   virtual void Execute() {
02991     SALOME_PYQT_ModuleLight* module = getActiveModule();
02992     if ( module )
02993       module->setName(myObj,myName);
02994   }
02995 };
02996 void SalomePyQt::setName(const QString& obj,const QString& name)
02997 {
02998   ProcessVoidEvent(new TSetNameEvent(obj,name));
02999 }
03000 
03001 
03006 class TSetIconEvent: public SALOME_Event
03007 {
03008 public:
03009   QString myObj;
03010   QString myIconName;
03011   TSetIconEvent( const QString& obj,
03012                  const QString& iconname) : myObj(obj),
03013                                             myIconName(iconname) {}
03014   virtual void Execute() {
03015     SALOME_PYQT_ModuleLight* module = getActiveModule();
03016     if ( module )
03017       module->setIcon(myObj,myIconName);
03018   }
03019 };
03020 
03021 void SalomePyQt::setIcon(const QString& obj,const QString& iconname)
03022 {
03023   ProcessVoidEvent(new TSetIconEvent(obj,iconname));
03024 }
03025 
03030 class TSetToolTipEvent: public SALOME_Event
03031 {
03032 public:
03033   QString myObj;
03034   QString myToolTip;
03035   TSetToolTipEvent( const QString& obj,
03036                     const QString& tooltip) : myObj(obj),
03037                                               myToolTip(tooltip) {}
03038   virtual void Execute() {
03039     SALOME_PYQT_ModuleLight* module = getActiveModule();
03040     if ( module )
03041       module->setToolTip(myObj,myToolTip);
03042   }
03043 };
03044 void SalomePyQt::setToolTip(const QString& obj,const QString& tooltip)
03045 {
03046   ProcessVoidEvent(new TSetToolTipEvent(obj,tooltip));
03047 }
03048 
03053 class TSetRefEvent: public SALOME_Event
03054 {
03055 public:
03056   QString myObj;
03057   QString myRefEntry;
03058   TSetRefEvent( const QString& obj,
03059               const QString& refEntry) : myObj(obj),
03060                                       myRefEntry(refEntry) {}
03061   virtual void Execute() {
03062     SALOME_PYQT_ModuleLight* module = getActiveModule();
03063     if ( module )
03064       module->setReference(myObj,myRefEntry);
03065   }
03066 };
03067 void SalomePyQt::setReference(const QString& obj,const QString& refEntry)
03068 {
03069   ProcessVoidEvent(new TSetRefEvent(obj,refEntry));
03070 }
03071 
03076 class TSetColorEvent: public SALOME_Event
03077 {
03078 public:
03079   QString myObj;
03080   QColor  myColor;
03081   TSetColorEvent( const QString& obj,
03082                 const QColor& color) : myObj(obj),
03083                                     myColor(color) {}
03084   virtual void Execute() {
03085     SALOME_PYQT_ModuleLight* module = getActiveModule();
03086     if ( module )
03087       module->setColor(myObj,myColor);
03088   }
03089 };
03090 void SalomePyQt::setColor(const QString& obj,const QColor& color)
03091 {
03092   ProcessVoidEvent(new TSetColorEvent(obj,color));
03093 }
03094 
03099 class TGetNameEvent: public SALOME_Event
03100 {
03101 public:
03102   typedef QString TResult;
03103   TResult myResult;
03104   QString myObj;
03105   TGetNameEvent( const QString& obj ) : myObj(obj) {}
03106   virtual void Execute() {
03107     SALOME_PYQT_ModuleLight* module = getActiveModule();
03108     if ( module )
03109       myResult = (QString) module->getName(myObj);
03110   }
03111 };
03112 
03113 QString SalomePyQt::getName(const QString& obj)
03114 {
03115   return ProcessEvent(new TGetNameEvent(obj));
03116 }
03117 
03122 class TGetToolTipEvent: public SALOME_Event
03123 {
03124 public:
03125   typedef QString TResult;
03126   TResult myResult;
03127   QString myObj;
03128   TGetToolTipEvent( const QString& obj ) : myObj(obj) {}
03129   virtual void Execute() {
03130     SALOME_PYQT_ModuleLight* module = getActiveModule();
03131     if ( module )
03132       myResult = (QString)module->getToolTip(myObj);
03133   }
03134 };
03135 QString SalomePyQt::getToolTip(const QString& obj)
03136 {
03137   return ProcessEvent(new TGetToolTipEvent(obj));
03138 }
03139 
03144 class TGetRefEvent: public SALOME_Event
03145 {
03146 public:
03147   typedef QString TResult;
03148   TResult myResult;
03149   QString myObj;
03150   TGetRefEvent( const QString& obj ) : myObj(obj) {}
03151   virtual void Execute() {
03152     SALOME_PYQT_ModuleLight* module = getActiveModule();
03153     if ( module )
03154       myResult = module->getReference(myObj);
03155   }
03156 };
03157 QString SalomePyQt::getReference(const QString& obj)
03158 {
03159   return ProcessEvent(new TGetRefEvent(obj));
03160 }
03161 
03166 class TGetColorEvent: public SALOME_Event
03167 {
03168 public:
03169   typedef QColor TResult;
03170   TResult myResult;
03171   QString myObj;
03172   TGetColorEvent( const QString& obj ) : myObj(obj) {}
03173   virtual void Execute() {
03174     SALOME_PYQT_ModuleLight* module = getActiveModule();
03175     if ( module )
03176       myResult = module->getColor(myObj);
03177   }
03178 };
03179 QColor SalomePyQt::getColor(const QString& obj)
03180 {
03181   return ProcessEvent(new TGetColorEvent(obj));
03182 }
03183 
03188 class TRemoveChildEvent: public SALOME_Event
03189 {
03190 public:
03191   QString myObj;
03192   TRemoveChildEvent(const QString& obj) : myObj(obj) {}
03193   
03194   virtual void Execute() {
03195     SALOME_PYQT_ModuleLight* module = getActiveModule();
03196     if ( module )
03197       module->removeChild(myObj);
03198   }
03199 };
03200 void SalomePyQt::removeChild(const QString& obj)
03201 {
03202   ProcessVoidEvent(new TRemoveChildEvent(obj));
03203 }
03204 
03205 
03210 class TRemoveObjectEvent: public SALOME_Event
03211 {
03212 public:
03213   QString myObj;
03214   
03215   TRemoveObjectEvent( const QString& obj) : myObj(obj) {}
03216   virtual void Execute() {
03217     SALOME_PYQT_ModuleLight* module = getActiveModule();
03218     if ( module )
03219       module->removeObject(myObj);
03220   }
03221 };
03222 void SalomePyQt::removeObject(const QString& obj)
03223 {
03224   ProcessVoidEvent(new TRemoveObjectEvent(obj));
03225 }
03226 
03233 class TGetChildrenEvent: public SALOME_Event
03234 {
03235 public:
03236   typedef QStringList TResult;
03237   TResult myResult;
03238   QString myObj;
03239   bool myRec; 
03240   TGetChildrenEvent(const QString& obj, const bool rec) : myObj(obj),
03241                                                           myRec(rec) {}
03242   virtual void Execute() {
03243     SALOME_PYQT_ModuleLight* module = getActiveModule();
03244     if ( module )
03245       myResult = (QStringList)module->getChildren(myObj,myRec);
03246   }
03247 };
03248 QStringList SalomePyQt::getChildren(const QString& obj, const bool rec)
03249 {
03250   return ProcessEvent( new TGetChildrenEvent(obj,rec) ); 
03251 }