1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "CAM_Module.h"
25 #include "CAM_DataModel.h"
26 #include "CAM_Application.h"
27 #include "CAM_Study.h"
29 #include <QtxAction.h>
30 #include <QtxActionGroup.h>
31 #include <QtxActionMenuMgr.h>
32 #include <QtxActionToolMgr.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
42 \brief Base implementation of the module in the CAM application architecture.
44 Provides support of menu/toolbars management.
50 ActionMgrLocker( QtxActionMgr* m, bool use ) : myMgr( m ), myUseLock( use )
53 myUpdEnabled = myMgr->isUpdatesEnabled();
54 myMgr->setUpdatesEnabled( false );
60 myMgr->setUpdatesEnabled( myUpdEnabled );
71 \brief Default constructor.
73 Creates unnamed module.
75 CAM_Module::CAM_Module()
85 Creates module with the specified \a name.
87 \param name module name
89 CAM_Module::CAM_Module( const QString& name )
104 CAM_Module::~CAM_Module()
111 \brief Initialize module.
113 This method is usually called when the module is created (for example,
114 on the module library loading).
115 Successor classes can use this method to create menu/toolbar actions
116 and perform other module initialization.
118 \param app parent application object
119 \sa activateModule(), deactivateModule()
121 void CAM_Module::initialize( CAM_Application* app )
126 SUIT_Session* aSession = SUIT_Session::session();
127 connect( aSession, SIGNAL( applicationClosed( SUIT_Application* ) ),
128 this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
130 connect( myApp, SIGNAL( infoChanged( QString ) ), this, SLOT( onInfoChanged( QString ) ) );
135 \brief Get module icon.
136 \return module icon pixmap
139 QPixmap CAM_Module::moduleIcon() const
141 if ( myIcon.isNull() ) {
142 QString iname = iconName();
143 if ( !iname.isEmpty() ) {
144 CAM_Module* that = (CAM_Module*)this;
145 that->myIcon = application()->resourceMgr()->loadPixmap( name(), iname, false );
152 \brief Get module icon's name.
154 This function is used to get module icon's file name.
155 Default implementation returns empty string.
157 \return module icon's name.
160 QString CAM_Module::iconName() const
162 return application()->moduleIcon( name() );
166 \brief Get module (internal) name
168 \sa setName(), moduleName(), setModuleName()
170 QString CAM_Module::name() const
176 \brief Get module title (user name)
178 \sa setModuleName(), name(), setName()
180 QString CAM_Module::moduleName() const
186 \brief Get data model.
188 Creates data model, if it is not yet created.
190 \return data model pointer
191 \sa createDataModel()
193 CAM_DataModel* CAM_Module::dataModel() const
197 CAM_Module* that = (CAM_Module*)this;
198 that->myDataModel = that->createDataModel();
199 that->myDataModel->initialize();
205 \brief Get application.
206 \return application pointer
208 CAM_Application* CAM_Module::application() const
214 \brief If return false, selection will be cleared at module activation
216 bool CAM_Module::isSelectionCompatible()
222 \brief Activate module.
224 This method is called when the user activates module.
225 Successor classes can use this method to customize module activation process,
226 for example, to show own menus, toolbars, etc.
228 Default implementation always returns \c true.
230 \return \c true if module is activated successfully.
231 \sa initialize(), deactivateModule()
233 bool CAM_Module::activateModule( SUIT_Study* /*study*/ )
235 // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
236 // after activate/deactivate modules
237 for ( QMap<QAction*, QKeySequence>::Iterator it = myActionShortcutMap.begin(); it != myActionShortcutMap.end(); ++it )
239 // Reset actions accelerator keys
240 it.key()->setShortcut( it.value() );
242 myActionShortcutMap.clear();
247 \brief Deactivate module.
249 This method is called when the user deactivates module.
250 Successor classes can use this method to customize module deactivation process,
251 for example, to hide own menus, toolbars, etc.
253 Default implementation always returns \c true.
255 \return \c true if module is deactivated successfully.
256 \sa initialize(), activateModule()
258 bool CAM_Module::deactivateModule( SUIT_Study* )
260 // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
261 // after activate/deactivate modules
262 myActionShortcutMap.clear();
263 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
265 myActionShortcutMap.insert( it.value(), it.value()->shortcut() );
266 it.value()->setShortcut( QKeySequence() );
272 \brief Called when study is closed.
274 Removes data model from the \a study.
276 \param study study being closed
278 void CAM_Module::studyClosed( SUIT_Study* study )
280 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
284 CAM_DataModel* dm = dataModel();
285 if ( dm && camDoc->containsDataModel( dm ) ) {
287 camDoc->removeDataModel( dm );
292 \brief Called when study is changed (obsolete).
294 Default implementation does nothing.
296 \param oldStudy old study
297 \param newStudy new study
299 void CAM_Module::studyChanged( SUIT_Study* /*oldStudy*/, SUIT_Study* /*newStudy*/ )
304 \brief Check if the module is active.
305 \return \c true if module is active.
307 bool CAM_Module::isActiveModule() const
309 return application() ? application()->activeModule() == this : false;
313 \brief Put the text message into the status bar of the application main window.
315 If \a msec > 0, the message will be shown \a msec milliseconds.
316 If \a msec < 0, the message will be constantly displayed until module is active.
318 \param msg text message
319 \param msec message displaying duration in milliseconds
321 void CAM_Module::putInfo( const QString& msg, const int msec )
324 application()->putInfo( msg, msec );
331 \brief Shows the notifications with spectified text, title and automatic close timeout.
332 Notification will be automatically closed after specified timeout in msec. If
333 timeout is zero then automatic closing doesn't performed.
334 \param text - Notification text
335 \param title - Notification title
336 \param timeout - Notification close timeout in msec
337 \return notification identifier
339 int CAM_Module::showNotification( const QString& message, const QString& title, int timeout )
343 res = application()->showNotification( message, title, timeout );
348 \brief Closes the notifications with spectified text.
349 \param text - Notification text
351 void CAM_Module::hideNotification( const QString& message )
354 application()->hideNotification( message );
358 \brief Closes the notifications with spectified identifier.
359 \param text - Notification text
361 void CAM_Module::hideNotification( int id )
364 application()->hideNotification( id );
368 \brief Restore message info.
370 Restores constant text message when previous information status message is removed.
372 \param txt previous message (being removed)
375 void CAM_Module::onInfoChanged( QString txt )
377 if ( txt.isEmpty() && isActiveModule() && !myInfo.isEmpty() && application() )
378 application()->putInfo( myInfo );
382 \brief Called when application is closed.
384 Nullify application pointer if the application is being closed.
386 \param theApp application
388 void CAM_Module::onApplicationClosed( SUIT_Application* theApp )
395 \brief Create data model.
396 \return created data model object or 0 if it could not be created
398 CAM_DataModel* CAM_Module::createDataModel()
400 return new CAM_DataModel( this );
404 \brief Set module (internal) name
405 \param name new module name
406 \sa name(), moduleName(), setModuleName()
408 void CAM_Module::setName( const QString& name )
410 setObjectName( name );
414 \brief Set module title (user name)
415 \param name new module title
416 \sa moduleName(), name(), setName()
418 void CAM_Module::setModuleName( const QString& name )
424 \brief Get menu manager.
425 \return menu manager pointer
427 QtxActionMenuMgr* CAM_Module::menuMgr() const
429 QtxActionMenuMgr* mgr = 0;
430 if ( application() && application()->desktop() )
431 mgr = application()->desktop()->menuMgr();
436 \brief Get toolbar manager.
437 \return toolbar manager pointer
439 QtxActionToolMgr* CAM_Module::toolMgr() const
441 QtxActionToolMgr* mgr = 0;
442 if ( application() && application()->desktop() )
443 mgr = application()->desktop()->toolMgr();
448 \brief Create toolbar with speicifed \a name.
450 If the toolbar has been already created, its ID is just returned.
452 \param title toolbar title
453 \param name toolbar name (identifier)
454 \return toolbar ID or -1 if toolbar could not be created
456 int CAM_Module::createTool( const QString& title, const QString& name )
461 ActionMgrLocker lock( toolMgr(), !myToolShown );
463 return toolMgr()->createToolBar( title, name );
467 \brief Add toolbar item.
469 Insert action \a to the toolbar manager and register it with specified \a id.
470 Resulting action ID may differ from the requested one. This can happen if
471 requested ID is already in use.
473 If action has been already added previously, its ID is just returned.
475 If \a id < 0, the action ID is generated automatically.
477 If \a idx < 0, the action is added to the end of the toolbar.
480 \param tBar toolbar ID
481 \param id requested action ID
482 \param idx action index (desired position in the toolbar)
483 \return action ID or -1 if toolbar item could not be added
485 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
490 ActionMgrLocker lock( toolMgr(), !myToolShown );
492 int regId = registerAction( id, a );
493 int intId = toolMgr()->insert( a, tBar, idx );
496 setToolShown( a, false );
498 return intId != -1 ? regId : -1;
502 \brief Add toolbar item.
504 Insert action \a to the toolbar manager and register it with specified \a id.
505 Resulting action ID may differ from the requested one. This can happen if
506 requested ID is already in use.
508 If action has been already added previously, its ID is just returned.
510 If \a id < 0, the action ID is generated automatically.
512 If \a idx < 0, the action is added to the end of the toolbar.
515 \param tBar toolbar name
516 \param id requested action ID
517 \param idx action index (desired position in the toolbar)
518 \return action ID or -1 if toolbar item could not be added
520 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
525 ActionMgrLocker lock( toolMgr(), !myToolShown );
527 int regId = registerAction( id, a );
528 int intId = toolMgr()->insert( a, tBar, idx );
531 setToolShown( a, false );
533 return intId != -1 ? regId : -1;
537 \brief Add toolbar item.
539 Insert action with \a id identifier to the toolbar manager.
540 It is assumed that action has been already registered.
542 Resulting action ID may differ from the requested one. This can happen if
543 requested ID is already in use.
545 If action has been already added previously, its ID is just returned.
547 If \a idx < 0, the action is added to the end of the toolbar.
550 \param tBar toolbar ID
551 \param idx action index (desired position in the toolbar)
552 \return action ID or -1 if toolbar item could not be added
554 int CAM_Module::createTool( const int id, const int tBar, const int idx )
559 ActionMgrLocker lock( toolMgr(), !myToolShown );
561 int intId = toolMgr()->insert( action( id ), tBar, idx );
564 setToolShown( action( id ), false );
566 return intId != -1 ? id : -1;
570 \brief Add toolbar item.
572 Insert action with \a id identifier to the toolbar manager.
573 It is assumed that action has been already registered.
575 Resulting action ID may differ from the requested one. This can happen if
576 requested ID is already in use.
578 If action has been already added previously, its ID is just returned.
580 If \a idx < 0, the action is added to the end of the toolbar.
583 \param tBar toolbar name
584 \param idx action index (desired position in the toolbar)
585 \return action ID or -1 if toolbar item could not be added
587 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
592 ActionMgrLocker lock( toolMgr(), !myToolShown );
594 int intId = toolMgr()->insert( action( id ), tBar, idx );
597 setToolShown( action( id ), false );
599 return intId != -1 ? id : -1;
603 \brief Create menu or submenu.
605 Create main menu or popup submenu and register it with specified \a id.
606 Resulting action ID may differ from the requested one. This can happen if
607 requested ID is already in use.
609 If \a id < 0, the menu ID is generated automatically.
610 If menu has been already created previously, its ID is just returned.
612 The \a menu parameter represents the menu name - it could be a sequence
613 of strings, separated by '|' symbol. For example, "File|Edit" means
614 File->Edit submenu. If menu doesn't exist, it is created automatically.
616 Parameter \a idx defines the index of the menu item in the menu group which
617 is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
618 end of the menu group.
620 \param subMenu subMenu name
621 \param menu parent menu ID
622 \param id requested menu ID
623 \param group menu group ID
624 \param idx menu item index (desired position in the menu group)
625 \return menu item ID or -1 if menu item could not be added
627 int CAM_Module::createMenu( const QString& subMenu, const int menu,
628 const int id, const int group, const int idx, QMenu * menuObj )
633 return menuMgr()->insert( subMenu, menu, group, id, idx, menuObj );
637 \brief Create menu or submenu.
639 Create main menu or popup submenu and register it with specified \a id.
640 Resulting action ID may differ from the requested one. This can happen if
641 requested ID is already in use.
643 If \a id < 0, the menu ID is generated automatically.
644 If menu has been already created previously, its ID is just returned.
646 The \a menu parameter represents the menu name - it could be a sequence
647 of strings, separated by '|' symbol. For example, "File|Edit" means
648 File->Edit submenu. If menu doesn't exist, it is created automatically.
650 Parameter \a idx defines the index of the menu item in the menu group which
651 is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
652 end of the menu group.
654 \param subMenu subMenu name
655 \param menu parent menu name(s)
656 \param id requested menu ID
657 \param group menu group ID
658 \param idx menu item index (desired position in the menu group)
659 \return menu item ID or -1 if menu item could not be added
661 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
662 const int id, const int group, const int idx )
667 return menuMgr()->insert( subMenu, menu, group, id, idx );
671 \brief Add menu item.
673 Insert action \a to the menu manager and register it with specified \a id.
674 Resulting action ID may differ from the requested one. This can happen if
675 requested ID is already in use.
677 If \a id < 0, the action ID is generated automatically.
679 If action has been already added previously, its ID is just returned.
681 Parameter \a idx defines the index of the menu item in the menu group which
682 is defined by the \a group. If \a idx < 0, the action is added to the
683 end of the menu group.
687 \param id requested action ID
688 \param group menu group ID
689 \param idx action index (desired position in the menu group)
690 \return action ID or -1 if menu item could not be added
692 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
694 if ( !a || !menuMgr() )
697 ActionMgrLocker lock( menuMgr(), !myMenuShown );
699 int regId = registerAction( id, a );
700 int intId = menuMgr()->insert( a, menu, group, idx );
703 setMenuShown( a, false );
705 return intId != -1 ? regId : -1;
709 \brief Add menu item.
711 Insert action \a to the menu manager and register it with specified \a id.
712 Resulting action ID may differ from the requested one. This can happen if
713 requested ID is already in use.
715 If \a id < 0, the action ID is generated automatically.
717 If action has been already added previously, its ID is just returned.
719 The \a menu parameter represents the menu name - it could be a sequence
720 of strings, separated by '|' symbol. For example, "File|Edit" means
721 File->Edit submenu. If menu doesn't exist, it is created automatically.
723 Parameter \a idx defines the index of the menu item in the menu group which
724 is defined by the \a group. If \a idx < 0, the action is added to the
725 end of the menu group.
728 \param menu menu name(s)
729 \param id requested action ID
730 \param group menu group ID
731 \param idx action index (desired position in the menu group)
732 \return action ID or -1 if menu item could not be added
734 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
736 if ( !a || !menuMgr() )
739 ActionMgrLocker lock( menuMgr(), !myMenuShown );
741 int regId = registerAction( id, a );
742 int intId = menuMgr()->insert( a, menu, group, idx );
745 setMenuShown( a, false );
747 return intId != -1 ? regId : -1;
751 \brief Add menu item.
753 Insert action with \a id identifier to the menu manager.
754 It is assumed that action has been already registered.
756 Resulting action ID may differ from the requested one. This can happen if
757 requested ID is already in use.
759 If action has been already added previously, its ID is just returned.
761 Parameter \a idx defines the index of the menu item in the menu group which
762 is defined by the \a group. If \a idx < 0, the action is added to the
763 end of the menu group.
767 \param group menu group ID
768 \param idx action index (desired position in the menu group)
769 \return action ID or -1 if menu item could not be added
771 int CAM_Module::createMenu( const int id, const int menu, const int group, const int idx )
776 ActionMgrLocker lock( menuMgr(), !myMenuShown );
778 int intId = menuMgr()->insert( action( id ), menu, group, idx );
781 setMenuShown( action( id ), false );
783 return intId != -1 ? id : -1;
787 \brief Add menu item.
789 Insert action with \a id identifier to the menu manager.
790 It is assumed that action has been already registered.
792 Resulting action ID may differ from the requested one. This can happen if
793 requested ID is already in use.
795 If action has been already added previously, its ID is just returned.
797 The \a menu parameter represents the menu name - it could be a sequence
798 of strings, separated by '|' symbol. For example, "File|Edit" means
799 File->Edit submenu. If menu doesn't exist, it is created automatically.
801 Parameter \a idx defines the index of the menu item in the menu group which
802 is defined by the \a group. If \a idx < 0, the action is added to the
803 end of the menu group.
806 \param menu menu name(s)
807 \param group menu group ID
808 \param idx action index (desired position in the menu group)
809 \return action ID or -1 if menu item could not be added
811 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
816 ActionMgrLocker lock( menuMgr(), !myMenuShown );
818 int intId = menuMgr()->insert( action( id ), menu, group, idx );
821 setMenuShown( action( id ), false );
823 return intId != -1 ? id : -1;
827 \brief Show/hide all module's menus.
828 \param on if \c true, show menus, otherwise, hide all menus
831 void CAM_Module::setMenuShown( const bool on )
835 QtxActionMenuMgr* mMgr = menuMgr();
839 bool upd = mMgr->isUpdatesEnabled();
840 mMgr->setUpdatesEnabled( false );
842 QAction* sep = separator();
843 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
845 if ( it.value() != sep )
846 mMgr->setShown( mMgr->actionId( it.value() ), on );
849 mMgr->setUpdatesEnabled( upd );
855 \brief Show/hide specified menu item.
857 \param on if \c true, show menu item, otherwise, hide it
859 void CAM_Module::setMenuShown( QAction* a, const bool on )
862 menuMgr()->setShown( menuMgr()->actionId( a ), on );
866 \brief Show/hide specified menu item.
867 \param id menu item ID
868 \param on if \c true, show menu item, otherwise, hide it
870 void CAM_Module::setMenuShown( const int id, const bool on )
872 setMenuShown( action( id ), on );
876 \brief Show/hide all module's toolbars.
877 \param on if \c true, show toolbars, otherwise, hide all toolbars
880 void CAM_Module::setToolShown( const bool on )
884 QtxActionToolMgr* tMgr = toolMgr();
888 bool upd = tMgr->isUpdatesEnabled();
889 tMgr->setUpdatesEnabled( false );
891 QAction* sep = separator();
892 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
894 if ( it.value() != sep )
895 tMgr->setShown( tMgr->actionId( it.value() ), on );
898 tMgr->setUpdatesEnabled( upd );
904 \brief Show/hide specified toolbar item.
906 \param on if \c true, show toolbar item, otherwise, hide it
908 void CAM_Module::setToolShown( QAction* a, const bool on )
911 toolMgr()->setShown( toolMgr()->actionId( a ), on );
915 \brief Show/hide specified toolbar item.
916 \param id toolbar item ID
917 \param on if \c true, show toolbar item, otherwise, hide it
919 void CAM_Module::setToolShown( const int id, const bool on )
921 setToolShown( action( id ), on );
925 \brief Get action by specified \a id.
927 \return action or 0 if not found
929 QAction* CAM_Module::action( const int id ) const
932 if ( myActionMap.contains( id ) )
934 else if ( menuMgr() ) {
935 QMenu* m = menuMgr()->findMenu( id );
936 if ( m ) a = m->menuAction();
942 \brief Get action ID.
944 \return action ID or -1 if not found
946 int CAM_Module::actionId( const QAction* a ) const
949 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
951 if ( it.value() == a )
958 \brief Create new instance of QtxAction and register action with specified \a id.
960 Resulting action ID may differ from the requested one. This can happen if
961 requested ID is already in use.
963 If \a id < 0, the action ID is generated automatically.
965 \param id required action ID
966 \param text tooltip text
967 \param icon action icon
968 \param menu menu text
969 \param tip status bar tip
970 \param key keyboard accelerator
971 \param parent parent object
972 \param toggle if \c true, the action will be toggled
973 \param reciever action activation signal receiver object
974 \param member action activation signal receiver slot
976 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
977 const QString& menu, const QString& tip, const int key,
978 QObject* parent, const bool toggle, QObject* reciever,
979 const char* member, const QString& shortcutAction )
981 return createAction( id, text, icon, menu, tip, QKeySequence(key), parent, toggle, reciever, member, shortcutAction );
985 \brief Create new instance of QtxAction and register action with specified \a id.
987 Resulting action ID may differ from the requested one. This can happen if
988 requested ID is already in use.
990 If \a id < 0, the action ID is generated automatically.
992 \param id required action ID
993 \param text tooltip text
994 \param icon action icon
995 \param menu menu text
996 \param tip status bar tip
997 \param key keyboard accelerator
998 \param parent parent object
999 \param toggle if \c true, the action will be toggled
1000 \param reciever action activation signal receiver object
1001 \param member action activation signal receiver slot
1003 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
1004 const QString& menu, const QString& tip, const QKeySequence& key,
1005 QObject* parent, const bool toggle, QObject* reciever,
1006 const char* member, const QString& shortcutAction )
1008 QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
1009 a->setStatusTip( tip );
1011 if ( reciever && member )
1012 connect( a, SIGNAL( triggered( bool ) ), reciever, member );
1014 registerAction( id, a );
1020 \brief Create new action group.
1021 \param id action group ID
1022 \param exclusive \c true for exclusive action group
1023 \return created action group
1025 QtxActionGroup* CAM_Module::createActionGroup( const int id, const bool exclusive )
1027 QtxActionGroup* a = qobject_cast<QtxActionGroup*>( action( id ) );
1029 a = new QtxActionGroup( this );
1030 registerAction( id, a );
1032 a->setExclusive( exclusive );
1037 \brief Register action in the internal action map.
1039 If action has been already added previously, its ID is just returned.
1040 If \a id < 0, the action ID is generated automatically.
1042 \param id action required ID
1046 int CAM_Module::registerAction( const int id, QAction* a )
1049 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
1050 if ( it.value() == a )
1056 static int generatedId = -1;
1057 ident = id < 0 ? --generatedId : id;
1059 myActionMap.insert( ident, a );
1062 menuMgr()->registerAction( a );
1065 toolMgr()->registerAction( a );
1067 if ( application() && application()->desktop() &&
1068 a->shortcutContext() != Qt::WidgetShortcut &&
1069 a->shortcutContext() != Qt::WidgetWithChildrenShortcut )
1070 application()->desktop()->addAction( a );
1076 \brief Unregister action from the internal action map.
1079 \return \c true on success or \c false if action is in use
1081 bool CAM_Module::unregisterAction( const int id )
1083 return unregisterAction( action( id ) );
1087 \brief Unregister action from the internal action map.
1090 \return \c true on success or \c false if action is in use
1092 bool CAM_Module::unregisterAction( QAction* a )
1097 int id = menuMgr()->actionId( a );
1098 if ( id != -1 && menuMgr()->containsMenu( id, -1 ) )
1102 int id = toolMgr()->actionId( a );
1103 if ( id != -1 && toolMgr()->containsAction( id ) )
1107 menuMgr()->unRegisterAction( menuMgr()->actionId( a ) );
1109 toolMgr()->unRegisterAction( toolMgr()->actionId( a ) );
1114 \brief Create separator action.
1116 Separator action can be used in menus or toolbars.
1118 \return new separator action
1120 QAction* CAM_Module::separator()
1122 return QtxActionMgr::separator();
1126 \brief Update visibility state of the module objects.
1128 void CAM_Module::updateModuleVisibilityState() {
1133 \brief Activate GUI operation of module by its ID.
1134 This method is called from CAM_Application::startOperation().
1135 \param actionId is a numerical unique operation id.
1137 bool CAM_Module::activateOperation( int actionId )
1143 \brief Activate GUI operation of module by its ID.
1144 This method is called from CAM_Application::startOperation().
1145 \param actionId is a string unique operation id.
1147 bool CAM_Module::activateOperation( const QString& actionId )
1153 \brief Activate GUI operation of module by its ID and \a pluginName.
1154 This method is called from CAM_Application::startOperation().
1155 \param actionId is a string unique operation id.
1156 \param pluginName is a name of a plugin where the operation is implemented.
1158 bool CAM_Module::activateOperation( const QString& actionId, const QString& pluginName )
1165 \brief Connect data model of the module to the active study
1166 \param camStudy CAM study object
1168 void CAM_Module::connectToStudy( CAM_Study* camStudy )
1170 CAM_Application* app = camStudy ? dynamic_cast<CAM_Application*>( camStudy->application() ) : 0;
1174 CAM_DataModel* prev = 0;
1175 CAM_Application::ModuleList mods = app->modules();
1176 for( QList<CAM_Module*>::const_iterator it = mods.begin(); it != mods.end(); ++it )
1178 CAM_DataModel* dm = (*it)->dataModel();
1179 if( (*it) == this && !camStudy->containsDataModel( dm ) )
1182 camStudy->insertDataModel( (*it)->dataModel(), prev );
1184 camStudy->insertDataModel( (*it)->dataModel(), 0 );
1191 \fn void CAM_Module::contextMenuPopup( const QString& type, QMenu* menu, QString& title );
1192 \brief Create context popup menu.
1193 \param type popup menu context
1194 \param menu popup menu
1195 \param title popup menu title, which can be set by the module if required
1199 \fn void CAM_Module::updateCommandsStatus();
1200 \brief Update menu/toolbar actions.
1204 bool CAM_Module::abortAllOperations()