Salome HOME
Merge branch 'V9_2_BR'
authorvsr <vsr@opencascade.com>
Tue, 22 Jan 2019 12:54:43 +0000 (15:54 +0300)
committervsr <vsr@opencascade.com>
Tue, 22 Jan 2019 12:54:43 +0000 (15:54 +0300)
14 files changed:
CMakeLists.txt
src/CAM/CAM_Module.cxx
src/CAM/CAM_Module.h
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_Application.h
src/Qtx/QtxActionToolMgr.cxx
src/Qtx/QtxActionToolMgr.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt/SalomePyQt.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip
src/SUIT/SUIT_Application.cxx
src/SUIT/SUIT_Application.h
src/SalomeApp/salome_pluginsmanager.py
src/Session/SALOME_Session_Server.cxx

index 6dd2c7891cdf25f06f0574b0047d83bba501a9b2..3842e1e42ffccc525e88e0d90d97983745768675 100755 (executable)
@@ -37,7 +37,7 @@ SET(${PROJECT_NAME_UC}_MINOR_VERSION 2)
 SET(${PROJECT_NAME_UC}_PATCH_VERSION 0)
 SET(${PROJECT_NAME_UC}_VERSION
   ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
-SET(${PROJECT_NAME_UC}_VERSION_DEV 0)
+SET(${PROJECT_NAME_UC}_VERSION_DEV 1)
 
 # Common CMake macros
 # ===================
index fd814543e77538ce054bbbfc3e08f617c1d110c0..77877ea9782fda4354f9fdda89bae98bf2e6013c 100755 (executable)
@@ -599,6 +599,16 @@ int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
   return intId != -1 ? id : -1;
 }
 
+/*!
+  Clears given toolbar.
+  \param title - title of toolbar
+*/
+void CAM_Module::clearTool( const QString& title )
+{
+  if ( toolMgr() )
+    toolMgr()->clear( title );
+}
+
 /*!
   \brief Create menu or submenu.
 
index 3cb43c1616f826df5d00b4d12278eb9418bb54b1..55451cb99c193642288e5651341630c574fadfb9 100755 (executable)
@@ -113,6 +113,7 @@ public:
   int                    createTool( const int, const QString&, const int = -1 );
   int                    createTool( QAction*, const int, const int = -1, const int = -1 );
   int                    createTool( QAction*, const QString&, const int = -1, const int = -1 );
+  void                   clearTool( const QString& title );
 
   int                    createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1,QMenu * = 0);
   int                    createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
index 6fbc2c7a8894b4c3bb6fd28a2e208e798c3467d0..2a7d62cdcf2b48409511656863eff7888611a680 100644 (file)
@@ -1020,10 +1020,15 @@ void LightApp_Application::onOpenDoc()
 {
   SUIT_Study* study = activeStudy();
   
-  if ( !checkExistingDoc() )
+  if ( !checkExistingDoc( false ) )
+    return;
+  
+  QString aName = getFileName( true, QString(), getFileFilter( true ), QString(), 0 );
+  if ( aName.isNull() ) //Cancel
     return;
   
-  CAM_Application::onOpenDoc();
+  closeDoc();
+  onOpenDoc( aName );
   
   if ( !study ) // new study will be create in THIS application
   {
@@ -5157,7 +5162,7 @@ void LightApp_Application::onViewManagerRemoved( SUIT_ViewManager* )
 /*!
   Check existing document.
 */
-bool LightApp_Application::checkExistingDoc()
+bool LightApp_Application::checkExistingDoc( bool closeExistingDoc )
 {
   bool result = true;
   if( activeStudy() ) {
@@ -5181,7 +5186,9 @@ bool LightApp_Application::checkExistingDoc()
       }
     }
     else if( answer == 1 ) {
-      closeDoc( false );
+      if (closeExistingDoc) {
+       closeDoc( false );
+      }
     } else if( answer == 2 ) {
       result = false;
     }
index f32fd38a4cff1f3a9b23a01726f320f7f4d66cd7..11fba2006798471dbc564adeaf865da392d19b26 100644 (file)
@@ -180,7 +180,7 @@ public:
   void                                updateVisibilityState( DataObjectList& theList,
                                                              SUIT_ViewModel* theViewModel );  
 
-  virtual bool                        checkExistingDoc();
+  virtual bool                        checkExistingDoc( bool checkExistingDoc = true );
 
 #ifndef DISABLE_PYCONSOLE
   PyConsole_Interp*                   getPyInterp();
index deeb79355806307ff5645f8d400a50088cff41eb..3c47889c9d1c5ef4cd216ef20dc924654c927dd6 100644 (file)
@@ -442,6 +442,29 @@ void QtxActionToolMgr::remove( const int id, const QString& title )
   remove( id, find( title ) );
 }
 
+/*!
+  \brief Remove all actions from toolbar.
+  \param tid toolbar ID
+*/
+void QtxActionToolMgr::clear( const int tid )
+{
+  if ( !myToolBars.contains( tid ) )
+    return;
+
+  myToolBars[tid].nodes.clear();
+
+  triggerUpdate( tid );
+}
+
+/*!
+  \brief Remove all actions from toolbar.
+  \param title toolbar title
+*/
+void QtxActionToolMgr::clear( const QString& title )
+{
+  clear( find( title ) );
+}
+
 /*!
   \brief Get toolbar by given \a tid.
   \param tid toolbar ID
index 4eaedbc6a78e00515629f12df5b616e5c5f32d32..833c83b0befc6fc2042478326d06cf84cdbfcf19 100644 (file)
@@ -99,6 +99,8 @@ public:
 
   void            remove( const int, const int );
   void            remove( const int, const QString& );
+  void            clear( const int );
+  void            clear( const QString& );
 
   QToolBar*       toolBar( const int ) const;
   QToolBar*       toolBar( const QString& ) const;
index c99438ab9cc359b97d9e11a1029365c4169e8a8f..47407341271a408680bec0bc5521a25804b1b161 100644 (file)
@@ -2080,21 +2080,34 @@ public:
   CrTool( QAction* action, const QString& tBar, const int id, const int idx )
     : myCase( 4 ), myAction( action ), myTbTitle( tBar ), myId( id ), myIndex( idx ) {}
 
-  int execute( LightApp_Module* module ) const
+  int execute() const
   {
-    if ( module ) {
-      switch ( myCase ) {
-      case 0:
-        return module->createTool( myTbTitle, myTbName );
-      case 1:
-        return module->createTool( myId, myTbId, myIndex );
-      case 2:
-        return module->createTool( myId, myTbTitle, myIndex );
-      case 3:
-        return module->createTool( myAction, myTbId, myId, myIndex );
-      case 4:
-        return module->createTool( myAction, myTbTitle, myId, myIndex );
-      }
+    switch ( myCase ) {
+    case 0:
+      if ( getActiveModule() )
+        return getActiveModule()->createTool( myTbTitle, myTbName );
+      else if ( getApplication() )
+        return getApplication()->createTool( myTbTitle, myTbName );
+    case 1:
+      if ( getActiveModule() )
+        return getActiveModule()->createTool( myId, myTbId, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createTool( myId, myTbId, myIndex );
+    case 2:
+      if ( getActiveModule() )
+        return getActiveModule()->createTool( myId, myTbTitle, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createTool( myId, myTbTitle, myIndex );
+    case 3:
+      if ( getActiveModule() )
+        return getActiveModule()->createTool( myAction, myTbId, myId, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createTool( myAction, myTbId, myId, myIndex );
+    case 4:
+      if ( getActiveModule() )
+        return getActiveModule()->createTool( myAction, myTbTitle, myId, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createTool( myAction, myTbTitle, myId, myIndex );
     }
     return -1;
   }
@@ -2118,9 +2131,7 @@ public:
     : myResult( -1 ), myCrTool( crTool ) {}
   virtual void Execute() 
   {
-    LightApp_Module* module = getActiveModule();
-    if ( module )
-      myResult = myCrTool.execute( module );
+    myResult = myCrTool.execute();
   }
 };
 
@@ -2172,6 +2183,30 @@ int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int
   return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) );
 }
 
+
+/*!
+  \brief Clear given toolbar.
+  \param title toolbar's title
+*/
+void SalomePyQt::clearTool( const QString& title )
+{
+  class TEvent: public SALOME_Event
+  {
+    QString myTitle;
+  public:
+    TEvent( const QString& title ) 
+      : myTitle( title ) {}
+    virtual void Execute() 
+    {
+      if ( getActiveModule() )
+        return getActiveModule()->clearTool( myTitle );
+      else if ( getApplication() )
+        return getApplication()->clearTool( myTitle );
+    }
+  };
+  ProcessVoidEvent( new TEvent( title ) );
+}
+
 /*!
   \brief Insert action to the toolbar.
   \param a action
@@ -2201,23 +2236,39 @@ public:
   CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) 
     : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {}
 
-  int execute( LightApp_Module* module ) const
+  int execute() const
   {
-    if ( module ) {
-      switch ( myCase ) {
-      case 0:
-        return module->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
-      case 1:
-        return module->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
-      case 2:
-        return module->createMenu( myId, myMenuId, myGroup, myIndex );
-      case 3:
-        return module->createMenu( myId, myMenuName, myGroup, myIndex );
-      case 4:
-        return module->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
-      case 5:
-        return module->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
-      }
+    switch ( myCase ) {
+    case 0:
+      if ( getActiveModule() )
+        return getActiveModule()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createMenu( mySubMenuName, myMenuId, myId, myGroup, myIndex );
+    case 1:
+      if ( getActiveModule() )
+        return getActiveModule()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createMenu( mySubMenuName, myMenuName, myId, myGroup, myIndex );
+    case 2:
+      if ( getActiveModule() )
+        return getActiveModule()->createMenu( myId, myMenuId, myGroup, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createMenu( myId, myMenuId, myGroup, myIndex );
+    case 3:
+      if ( getActiveModule() )
+        return getActiveModule()->createMenu( myId, myMenuName, myGroup, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createMenu( myId, myMenuName, myGroup, myIndex );
+    case 4:
+      if ( getActiveModule() )
+        return getActiveModule()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createMenu( myAction, myMenuId, myId, myGroup, myIndex );
+    case 5:
+      if ( getActiveModule() )
+        return getActiveModule()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
+      else if ( getApplication() )
+        return getApplication()->createMenu( myAction, myMenuName, myId, myGroup, myIndex );
     }
     return -1;
   }
@@ -2242,9 +2293,7 @@ public:
     : myResult( -1 ), myCrMenu( crMenu ) {}
   virtual void Execute()
   {
-    LightApp_Module* module = getActiveModule();
-    if ( module )
-      myResult = myCrMenu.execute( module );
+    myResult = myCrMenu.execute();
   }
 };
 
index 0e463d0ff29b855a84b0cd9bc01512a8b23a6460..e911bce616fc9aa5a79ca57cbef5b0ffa27a3f23 100644 (file)
@@ -246,6 +246,7 @@ public:
   static int               createTool( const int,  const QString&, const int = -1 );
   static int               createTool( QAction*, const int,      const int = -1, const int = -1 );
   static int               createTool( QAction*, const QString&, const int = -1, const int = -1 );
+  static void              clearTool( const QString& );
 
   static int               createMenu( const QString&, const int = -1,
                                        const int = -1, const int = -1, const int = -1 );
index 2dd132ac22b4f2ba048a202c2950226ea0bcf18a..bb893ddd85d8d3f3832a89d961dc00b6b3ec6e18 100644 (file)
@@ -360,6 +360,7 @@ public:
   static int               createTool( const int,  const QString&, const int = -1 ) /ReleaseGIL/ ;
   static int               createTool( QAction*,   const int,      const int = -1, const int = -1 ) /ReleaseGIL/ ;
   static int               createTool( QAction*,   const QString&, const int = -1, const int = -1 ) /ReleaseGIL/ ;
+  static void              clearTool( const QString& ) /ReleaseGIL/ ;
 
   static int               createMenu( const QString&, const int,
                                       const int = -1, const int = -1, const int = -1 ) /ReleaseGIL/ ;
index 06d9180ed8138cd4a388437a8f8014578d1d4de2..9216b5aa86b5173d64b4fa5f8c22530b66d03780 100644 (file)
@@ -399,6 +399,16 @@ int SUIT_Application::createTool( const int id, const QString& tBar, const int i
   return intId != -1 ? id : -1;
 }
 
+/*!
+  Clears given toolbar.
+  \param title - title of toolbar
+*/
+void SUIT_Application::clearTool( const QString& title )
+{
+  if ( desktop() && desktop()->toolMgr() )
+    desktop()->toolMgr()->clear( title );
+}
+
 /*!
   Creates new menu item
   \return identificator of new action in menu manager
index 3722c93d7645a29c58c0a009b0e3c928723848cb..f415e70cfea7caef4323edf13647dc8941ef14b3 100644 (file)
@@ -118,6 +118,22 @@ public:
 
   void                  addPostRoutine( void (*theRoutine)() );
 
+  /** @name Create tool functions*/ //@{
+  int                   createTool( const QString&, const QString& = QString() );
+  int                   createTool( const int, const int, const int = -1 );
+  int                   createTool( const int, const QString&, const int = -1 );
+  int                   createTool( QAction*, const int, const int = -1, const int = -1 );
+  int                   createTool( QAction*, const QString&, const int = -1, const int = -1 );//@}
+  void                  clearTool( const QString& );
+
+  /** @name Create menu functions*/ //@{
+  int                   createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
+  int                   createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
+  int                   createMenu( const int, const int, const int = -1, const int = -1 );
+  int                   createMenu( const int, const QString&, const int = -1, const int = -1 );
+  int                   createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
+  int                   createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );//@}
+
 signals:
   void                  applicationClosed( SUIT_Application* );
   void                  activated( SUIT_Application* );
@@ -141,21 +157,6 @@ protected:
   virtual SUIT_Study*   createNewStudy();
   virtual void          setActiveStudy( SUIT_Study* );
   
-  /** @name Create tool functions*/ //@{
-  int                   createTool( const QString&, const QString& = QString() );
-  int                   createTool( const int, const int, const int = -1 );
-  int                   createTool( const int, const QString&, const int = -1 );
-  int                   createTool( QAction*, const int, const int = -1, const int = -1 );
-  int                   createTool( QAction*, const QString&, const int = -1, const int = -1 );//@}
-
-  /** @name Create menu functions*/ //@{
-  int                   createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
-  int                   createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
-  int                   createMenu( const int, const int, const int = -1, const int = -1 );
-  int                   createMenu( const int, const QString&, const int = -1, const int = -1 );
-  int                   createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
-  int                   createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );//@}
-
   /** @name Set menu shown functions*/ //@{
   void                  setMenuShown( QAction*, const bool );
   void                  setMenuShown( const int, const bool );//@}
index fefbe2c5fbdb40b3ca6de9996cb93e4d16b951aa..f17bab2c322bfc0e8002fc4fbb4754c1b2feaec1 100755 (executable)
@@ -156,6 +156,7 @@ class PluginsManager:
         self.lasttime=0
         self.plugindirs=[]
         self.plugins_files=[]
+        self.toolbar = None
 
         # MODULES plugins directory.
         # The SALOME modules may provides natively some plugins. These
@@ -205,11 +206,14 @@ class PluginsManager:
         else:
           self.menu=QMenu(self.menuname,self.basemenu)
           self.basemenu.addMenu(self.menu)
+        self.toolbar=sgPyQt.createTool(self.menuname)
 
         self.menu.menuAction().setVisible(False)
 
         self.basemenu.aboutToShow.connect(self.importPlugins)
 
+        self.importPlugins() # to create toolbar immediately
+
     def analyseFile(self,filename):
       """
       This function checks if the specified file is a plugins python
@@ -223,10 +227,10 @@ class PluginsManager:
           self.plugindirs.append(dirpath)
           logger.debug("The directory %s has been added to plugin paths"%dirpath)
         
-    def AddFunction(self,name,description,script):
+    def AddFunction(self,name,description,script,icon=None):
         """ Add a plugin function
         """
-        self.registry[name]=script,description
+        self.registry[name]=script,description,icon
         self.entries.append(name)
 
         def handler(obj=self,script=script):
@@ -287,6 +291,7 @@ class PluginsManager:
     def updateMenu(self):
         """Update the Plugins menu"""
         self.menu.clear()
+        sgPyQt.clearTool(self.menuname)
         for entry in self.entries:
           names=entry.split("/")
           if len(names) < 1:continue
@@ -312,14 +317,18 @@ class PluginsManager:
           name=names.pop(0)
           act=parentMenu.addAction(name,self.handlers[entry])
           act.setStatusTip(self.registry[entry][1])
+          icon = self.registry[entry][2] if len(self.registry[entry])>2 else None
+          if icon is not None and not icon.isNull() and icon.availableSizes():
+            act.setIcon(icon)
+            sgPyQt.createTool(act, self.toolbar)
 
         self.menu.menuAction().setVisible(True)
 
-def AddFunction(name,description,script):
+def AddFunction(name,description,script,icon=None):
    """ Add a plugin function
        Called by a user to register a function (script)
    """
-   return current_plugins_manager.AddFunction(name,description,script)
+   return current_plugins_manager.AddFunction(name,description,script,icon)
 
 def entries():
   """ Return the list of entries in menu: can be sorted or modified in place to customize menu content """
index 380ac23e8e91d1c03e68efd19081a7b0a091597e..7e1c32f05a40fbab8db4e6a250019330fb5ff553 100755 (executable)
@@ -269,25 +269,30 @@ public:
 
   virtual bool notify( QObject* receiver, QEvent* e )
   {
-
-    try {
-      return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e );
-    }
-    catch (std::exception& e) {
-      std::cerr << e.what()  << std::endl;
+    QString debug_exceptions = ::getenv("SALOME_DEBUG_EXCEPTIONS");
+    if ( debug_exceptions.length() > 0 ) {
+      return QApplication::notify( receiver, e );
     }
-    catch (CORBA::Exception& e) {
-      std::cerr << "Caught CORBA::Exception"  << std::endl;
-      CORBA::Any tmp;
-      tmp<<= e;
-      CORBA::TypeCode_var tc = tmp.type();
-      const char *p = tc->name();
-      std::cerr << "notify(): CORBA exception of the kind : " << p << " is caught" << std::endl;
-    }
-    catch (...) {
-      std::cerr << "Unknown exception caught in Qt handler: it's probably a bug in SALOME platform" << std::endl;
+    else {
+      try {
+        return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e );
+      }
+      catch (std::exception& e) {
+        std::cerr << e.what()  << std::endl;
+      }
+      catch (CORBA::Exception& e) {
+        std::cerr << "Caught CORBA::Exception"  << std::endl;
+        CORBA::Any tmp;
+        tmp<<= e;
+        CORBA::TypeCode_var tc = tmp.type();
+        const char *p = tc->name();
+        std::cerr << "notify(): CORBA exception of the kind : " << p << " is caught" << std::endl;
+      }
+      catch (...) {
+        std::cerr << "Unknown exception caught in Qt handler: it's probably a bug in SALOME platform" << std::endl;
+      }
+      return false;  // return false when exception is caught
     }
-    return false;  // return false when exception is caught
   }
   SUIT_ExceptionHandler* handler() const { return myHandler; }
   void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }