-// 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"
#include "CAM_Study.h"
#include <QtxAction.h>
+#include <QtxActionGroup.h>
#include <QtxActionMenuMgr.h>
#include <QtxActionToolMgr.h>
#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.
: QObject(),
myApp( 0 ),
myName( name ),
- myDataModel( 0 )
+ myDataModel( 0 ),
+ myMenuShown( false ),
+ myToolShown( false )
{
}
if ( !toolMgr() )
return -1;
- return toolMgr()->createToolBar( name );
+ ActionMgrLocker lock( toolMgr(), !myToolShown );
+
+ return toolMgr()->createToolBar( name, myToolShown );
}
/*!
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;
}
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;
}
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;
}
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;
}
{
if ( !menuMgr() )
return -1;
-
+
return menuMgr()->insert( subMenu, menu, group, id, idx );
}
{
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;
}
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;
}
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;
}
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;
}
*/
void CAM_Module::setMenuShown( const bool on )
{
+ myMenuShown = on;
+
QtxActionMenuMgr* mMgr = menuMgr();
if ( !mMgr )
return;
*/
void CAM_Module::setToolShown( const bool on )
{
+ myToolShown = on;
+
QtxActionToolMgr* tMgr = toolMgr();
if ( !tMgr )
return;
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;
}
*/
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 )
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.
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
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;
}