Salome HOME
Merge remote-tracking branch 'origin/vsr/fix_single_study_pb' into pre/fix_single_study
[modules/gui.git] / src / CAM / CAM_Module.cxx
index d3dde1a21557299bf381095074cfa5612bcc0aa7..0f0d55708f40b0bd585532f6f594eac72d7d4012 100755 (executable)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "CAM_Module.h"
 
 #include "CAM_DataModel.h"
@@ -26,6 +27,7 @@
 #include "CAM_Study.h"
 
 #include <QtxAction.h>
+#include <QtxActionGroup.h>
 #include <QtxActionMenuMgr.h>
 #include <QtxActionToolMgr.h>
 
@@ -33,6 +35,8 @@
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
 
+#include <QMenu>
+
 /*!
   \class CAM_Module
   \brief Base implementation of the module in the CAM application architecture.
   Provides support of menu/toolbars management.
 */
 
+class ActionMgrLocker
+{
+public:
+  ActionMgrLocker( QtxActionMgr* m, bool use ) : myMgr( m ), myUseLock( use )
+  {
+    if ( myUseLock ) {
+      myUpdEnabled = myMgr->isUpdatesEnabled();
+      myMgr->setUpdatesEnabled( false );
+    }
+  }
+  ~ActionMgrLocker()
+  {
+    if ( myUseLock ) {
+      myMgr->setUpdatesEnabled( myUpdEnabled );
+      //myMgr->update();
+    }
+  }
+
+  QtxActionMgr* myMgr;
+  bool          myUseLock;
+  bool          myUpdEnabled;
+};
+
 /*!
   \brief Default constructor.
 
@@ -63,7 +90,9 @@ CAM_Module::CAM_Module( const QString& name )
 : QObject(),
   myApp( 0 ),
   myName( name ),
-  myDataModel( 0 )
+  myDataModel( 0 ),
+  myMenuShown( false ),
+  myToolShown( false )
 {
 }
 
@@ -375,7 +404,9 @@ int CAM_Module::createTool( const QString& name )
   if ( !toolMgr() )
     return -1;
 
-  return toolMgr()->createToolBar( name );
+  ActionMgrLocker lock( toolMgr(), !myToolShown );
+
+  return toolMgr()->createToolBar( name, myToolShown );
 }
 
 /*!
@@ -402,8 +433,14 @@ int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int
   if ( !toolMgr() )
     return -1;
 
+  ActionMgrLocker lock( toolMgr(), !myToolShown );
+
   int regId = registerAction( id, a );
   int intId = toolMgr()->insert( a, tBar, idx );
+
+  if ( !myToolShown )
+    setToolShown( a, false );
+
   return intId != -1 ? regId : -1;
 }
 
@@ -431,8 +468,14 @@ int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const
   if ( !toolMgr() )
     return -1;
 
+  ActionMgrLocker lock( toolMgr(), !myToolShown );
+
   int regId = registerAction( id, a );
   int intId = toolMgr()->insert( a, tBar, idx );
+
+  if ( !myToolShown )
+    setToolShown( a, false );
+
   return intId != -1 ? regId : -1;
 }
 
@@ -459,7 +502,13 @@ int CAM_Module::createTool( const int id, const int tBar, const int idx )
   if ( !toolMgr() )
     return -1;
 
+  ActionMgrLocker lock( toolMgr(), !myToolShown );
+
   int intId = toolMgr()->insert( action( id ), tBar, idx );
+
+  if ( !myToolShown )
+    setToolShown( action( id ), false );
+
   return intId != -1 ? id : -1;
 }
 
@@ -486,7 +535,13 @@ int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
   if ( !toolMgr() )
     return -1;
 
+  ActionMgrLocker lock( toolMgr(), !myToolShown );
+
   int intId = toolMgr()->insert( action( id ), tBar, idx );
+
+  if ( !myToolShown )
+    setToolShown( action( id ), false );
+
   return intId != -1 ? id : -1;
 }
 
@@ -520,7 +575,7 @@ int CAM_Module::createMenu( const QString& subMenu, const int menu,
 {
   if ( !menuMgr() )
     return -1;
-
+  
   return menuMgr()->insert( subMenu, menu, group, id, idx );
 }
 
@@ -584,9 +639,15 @@ int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int
 {
   if ( !a || !menuMgr() )
     return -1;
+  
+  ActionMgrLocker lock( menuMgr(), !myMenuShown );
 
   int regId = registerAction( id, a );
   int intId = menuMgr()->insert( a, menu, group, idx );
+
+  if ( !myMenuShown )
+    setMenuShown( a, false );
+
   return intId != -1 ? regId : -1;
 }
 
@@ -621,8 +682,14 @@ int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const
   if ( !a || !menuMgr() )
     return -1;
 
+  ActionMgrLocker lock( menuMgr(), !myMenuShown );
+
   int regId = registerAction( id, a );
   int intId = menuMgr()->insert( a, menu, group, idx );
+
+  if ( !myMenuShown )
+    setMenuShown( a, false );
+  
   return intId != -1 ? regId : -1;
 }
 
@@ -652,7 +719,13 @@ int CAM_Module::createMenu( const int id, const int menu, const int group, const
   if ( !menuMgr() )
     return -1;
 
+  ActionMgrLocker lock( menuMgr(), !myMenuShown );
+
   int intId = menuMgr()->insert( action( id ), menu, group, idx );
+
+  if ( !myMenuShown )
+    setMenuShown( action( id ), false );
+
   return intId != -1 ? id : -1;
 }
 
@@ -686,7 +759,13 @@ int CAM_Module::createMenu( const int id, const QString& menu, const int group,
   if ( !menuMgr() )
     return -1;
 
+  ActionMgrLocker lock( menuMgr(), !myMenuShown );
+
   int intId = menuMgr()->insert( action( id ), menu, group, idx );
+
+  if ( !myMenuShown )
+    setMenuShown( action( id ), false );
+
   return intId != -1 ? id : -1;
 }
 
@@ -697,6 +776,8 @@ int CAM_Module::createMenu( const int id, const QString& menu, const int group,
 */
 void CAM_Module::setMenuShown( const bool on )
 {
+  myMenuShown = on;
+
   QtxActionMenuMgr* mMgr = menuMgr();
   if ( !mMgr )
     return;
@@ -744,6 +825,8 @@ void CAM_Module::setMenuShown( const int id, const bool on )
 */
 void CAM_Module::setToolShown( const bool on )
 {
+  myToolShown = on;
+
   QtxActionToolMgr* tMgr = toolMgr();
   if ( !tMgr )
     return;
@@ -794,6 +877,10 @@ QAction* CAM_Module::action( const int id ) const
   QAction* a = 0;
   if ( myActionMap.contains( id ) )
     a = myActionMap[id];
+  else if ( menuMgr() ) {
+    QMenu* m = menuMgr()->findMenu( id );
+    if ( m ) a = m->menuAction();
+  }
   return a;
 }
 
@@ -834,9 +921,10 @@ int CAM_Module::actionId( const QAction* a ) const
 */
 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
                                    const QString& menu, const QString& tip, const int key,
-                                   QObject* parent, const bool toggle, QObject* reciever, const char* member )
+                                   QObject* parent, const bool toggle, QObject* reciever,
+                                  const char* member, const QString& shortcutAction )
 {
-  QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle );
+  QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
   a->setStatusTip( tip );
 
   if ( reciever && member )
@@ -847,6 +935,23 @@ QAction* CAM_Module::createAction( const int id, const QString& text, const QIco
   return a;
 }
 
+/*!
+  \brief Create new action group.
+  \param id action group ID
+  \param exclusive \c true for exclusive action group
+  \return created action group
+*/
+QtxActionGroup* CAM_Module::createActionGroup( const int id, const bool exclusive )
+{
+  QtxActionGroup* a = qobject_cast<QtxActionGroup*>( action( id ) );
+  if ( !a ) {
+    a = new QtxActionGroup( this );
+    registerAction( id, a );
+  }
+  a->setExclusive( exclusive );
+  return a;
+}
+
 /*!
   \brief Register action in the internal action map.
 
@@ -934,6 +1039,45 @@ QAction* CAM_Module::separator()
   return QtxActionMgr::separator();
 }
 
+/*!
+  \brief Update visibility state of the module objects.
+*/
+void CAM_Module::updateModuleVisibilityState() {
+
+}
+
+/*!
+  \brief Activate GUI operation of module by its ID.
+  This method is called from CAM_Application::startOperation().
+  \param actionId is a numerical unique operation id.
+*/
+bool CAM_Module::activateOperation( int actionId )
+{
+  return false;
+}
+
+/*!
+  \brief Activate GUI operation of module by its ID.
+  This method is called from CAM_Application::startOperation().
+  \param actionId is a string unique operation id.
+*/
+bool CAM_Module::activateOperation( const QString& actionId )
+{
+  return false;
+}
+
+/*!
+  \brief Activate GUI operation of module by its ID and \a pluginName.
+  This method is called from CAM_Application::startOperation().
+  \param actionId is a string unique operation id.
+  \param pluginName is a name of a plugin where the operation is implemented.
+*/
+bool CAM_Module::activateOperation( const QString& actionId, const QString& pluginName )
+{
+  return false;
+}
+
+
 /*!
   \brief Connect data model of the module to the active study
   \param camStudy CAM study object
@@ -952,9 +1096,9 @@ void CAM_Module::connectToStudy( CAM_Study* camStudy )
     if( (*it) == this && !camStudy->containsDataModel( dm ) )
     {
       if ( prev )
-       camStudy->insertDataModel( (*it)->dataModel(), prev );
+        camStudy->insertDataModel( (*it)->dataModel(), prev );
       else
-       camStudy->insertDataModel( (*it)->dataModel(), 0 );
+        camStudy->insertDataModel( (*it)->dataModel(), 0 );
     }
     prev = dm;
   }