Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/modules/gui
[modules/gui.git] / src / CAM / CAM_Module.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "CAM_Module.h"
24
25 #include "CAM_DataModel.h"
26 #include "CAM_Application.h"
27 #include "CAM_Study.h"
28
29 #include <QtxAction.h>
30 #include <QtxActionGroup.h>
31 #include <QtxActionMenuMgr.h>
32 #include <QtxActionToolMgr.h>
33
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37
38 #include <QMenu>
39
40 /*!
41   \class CAM_Module
42   \brief Base implementation of the module in the CAM application architecture.
43
44   Provides support of menu/toolbars management.
45 */
46
47 class ActionMgrLocker
48 {
49 public:
50   ActionMgrLocker( QtxActionMgr* m, bool use ) : myMgr( m ), myUseLock( use )
51   {
52     if ( myUseLock ) {
53       myUpdEnabled = myMgr->isUpdatesEnabled();
54       myMgr->setUpdatesEnabled( false );
55     }
56   }
57   ~ActionMgrLocker()
58   {
59     if ( myUseLock ) {
60       myMgr->setUpdatesEnabled( myUpdEnabled );
61       //myMgr->update();
62     }
63   }
64
65   QtxActionMgr* myMgr;
66   bool          myUseLock;
67   bool          myUpdEnabled;
68 };
69
70 /*!
71   \brief Default constructor.
72
73   Creates unnamed module.
74 */
75 CAM_Module::CAM_Module()
76 : QObject(),
77   myApp( 0 ),
78   myDataModel( 0 )
79 {
80 }
81
82 /*!
83   \brief Constructor.
84
85   Creates module with the specified \a name.
86
87   \param name module name
88 */
89 CAM_Module::CAM_Module( const QString& name )
90 : QObject(),
91   myApp( 0 ),
92   myName( name ),
93   myDataModel( 0 ),
94   myMenuShown( false ),
95   myToolShown( false )
96 {
97 }
98
99 /*!
100   \brief Destructor.
101
102   Destroy data model.
103 */
104 CAM_Module::~CAM_Module()
105 {
106   delete myDataModel;
107   myDataModel = 0;
108 }
109
110 /*!
111   \brief Initialize module.
112
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.
117
118   \param app parent application object
119   \sa activateModule(), deactivateModule()
120 */
121 void CAM_Module::initialize( CAM_Application* app )
122 {
123   myApp = app;
124   if ( myApp )
125   {
126     SUIT_Session* aSession = SUIT_Session::session();
127     connect( aSession, SIGNAL( applicationClosed( SUIT_Application* ) ),
128              this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
129
130     connect( myApp, SIGNAL( infoChanged( QString ) ), this, SLOT( onInfoChanged( QString ) ) );
131   }
132 }
133
134 /*!
135   \brief Get module icon.
136   \return module icon pixmap
137   \sa iconName()
138 */
139 QPixmap CAM_Module::moduleIcon() const
140 {
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 );
146     }
147   }
148   return myIcon;
149 }
150
151 /*!
152   \brief Get module icon's name.
153
154   This function is used to get module icon's file name.
155   Default implementation returns empty string.
156
157   \return module icon's name.
158   \sa moduleIcon()
159 */
160 QString CAM_Module::iconName() const
161 {
162   return application()->moduleIcon( name() );
163 }
164
165 /*!
166   \brief Get module (internal) name
167   \return module name
168   \sa setName(), moduleName(), setModuleName()
169 */
170 QString CAM_Module::name() const
171 {
172   return objectName();
173 }
174
175 /*!
176   \brief Get module title (user name)
177   \return module title
178   \sa setModuleName(), name(), setName()
179 */
180 QString CAM_Module::moduleName() const
181 {
182   return myName;
183 }
184
185 /*!
186   \brief Get data model.
187
188   Creates data model, if it is not yet created.
189
190   \return data model pointer
191   \sa createDataModel()
192 */
193 CAM_DataModel* CAM_Module::dataModel() const
194 {
195   if ( !myDataModel )
196   {
197     CAM_Module* that = (CAM_Module*)this;
198     that->myDataModel = that->createDataModel();
199     that->myDataModel->initialize();
200   }
201   return myDataModel;
202 }
203
204 /*!
205   \brief Get application.
206   \return application pointer
207 */
208 CAM_Application* CAM_Module::application() const
209 {
210   return myApp;
211 }
212
213 /*!
214   \brief If return false, selection will be cleared at module activation
215 */
216 bool CAM_Module::isSelectionCompatible()
217 {
218   return false;
219 }
220
221 /*!
222   \brief Activate module.
223
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.
227
228   Default implementation always returns \c true.
229
230   \return \c true if module is activated successfully.
231   \sa initialize(), deactivateModule()
232  */
233 bool CAM_Module::activateModule( SUIT_Study* /*study*/ )
234 {
235   return true;
236 }
237
238 /*!
239   \brief Deactivate module.
240
241   This method is called when the user deactivates module.
242   Successor classes can use this method to customize module deactivation process,
243   for example, to hide own menus, toolbars, etc.
244
245   Default implementation always returns \c true.
246
247   \return \c true if module is deactivated successfully.
248   \sa initialize(), activateModule()
249  */
250 bool CAM_Module::deactivateModule( SUIT_Study* )
251 {
252   return true;
253 }
254
255 /*!
256   \brief Called when study is closed.
257
258   Removes data model from the \a study.
259
260   \param study study being closed
261 */
262 void CAM_Module::studyClosed( SUIT_Study* study )
263 {
264   CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
265   if ( !camDoc )
266     return;
267
268   CAM_DataModel* dm = dataModel();
269   if ( dm && camDoc->containsDataModel( dm ) ) {
270     dm->close();
271     camDoc->removeDataModel( dm );
272   }
273 }
274
275 /*!
276   \brief Called when study is changed (obsolete).
277
278   Default implementation does nothing.
279
280   \param oldStudy old study
281   \param newStudy new study
282 */
283 void CAM_Module::studyChanged( SUIT_Study* /*oldStudy*/, SUIT_Study* /*newStudy*/ )
284 {
285 }
286
287 /*!
288   \brief Check if the module is active.
289   \return \c true if module is active.
290 */
291 bool CAM_Module::isActiveModule() const
292 {
293   return application() ? application()->activeModule() == this : false;
294 }
295
296 /*!
297   \brief Put the text message into the status bar of the application main window.
298
299   If \a msec > 0, the message will be shown \a msec milliseconds.
300   If \a msec < 0, the message will be constantly displayed until module is active.
301
302   \param msg text message
303   \param msec message displaying duration in milliseconds
304 */
305 void CAM_Module::putInfo( const QString& msg, const int msec )
306 {
307   if ( application() )
308     application()->putInfo( msg, msec );
309
310   if ( msec < 0 )
311     myInfo = msg;
312 }
313
314 /*!
315   \brief Restore message info.
316
317   Restores constant text message when previous information status message is removed.
318
319   \param txt previous message (being removed)
320   \sa putInfo()
321 */
322 void CAM_Module::onInfoChanged( QString txt )
323 {
324   if ( txt.isEmpty() && isActiveModule() && !myInfo.isEmpty() && application() )
325     application()->putInfo( myInfo );
326 }
327
328 /*!
329   \brief Called when application is closed.
330
331   Nullify application pointer if the application is being closed.
332
333   \param theApp application
334 */
335 void CAM_Module::onApplicationClosed( SUIT_Application* theApp )
336 {
337   if (myApp == theApp)
338     myApp = NULL;
339 }
340
341 /*!
342   \brief Create data model.
343   \return created data model object or 0 if it could not be created
344 */
345 CAM_DataModel* CAM_Module::createDataModel()
346 {
347   return new CAM_DataModel( this );
348 }
349
350 /*!
351   \brief Set module (internal) name
352   \param name new module name
353   \sa name(), moduleName(), setModuleName()
354  */
355 void CAM_Module::setName( const QString& name )
356 {
357   setObjectName( name );
358 }
359
360 /*!
361   \brief Set module title (user name)
362   \param name new module title
363   \sa moduleName(), name(), setName()
364  */
365 void CAM_Module::setModuleName( const QString& name )
366 {
367   myName = name;
368 }
369
370 /*!
371   \brief Get menu manager.
372   \return menu manager pointer
373 */
374 QtxActionMenuMgr* CAM_Module::menuMgr() const
375 {
376   QtxActionMenuMgr* mgr = 0;
377   if ( application() && application()->desktop() )
378     mgr = application()->desktop()->menuMgr();
379   return mgr;
380 }
381
382 /*!
383   \brief Get toolbar manager.
384   \return toolbar manager pointer
385 */
386 QtxActionToolMgr* CAM_Module::toolMgr() const
387 {
388   QtxActionToolMgr* mgr = 0;
389   if ( application() && application()->desktop() )
390     mgr = application()->desktop()->toolMgr();
391   return mgr;
392 }
393
394 /*!
395   \brief Create toolbar with speicifed \a name.
396
397   If the toolbar has been already created, its ID is just returned.
398
399   \param title toolbar title
400   \param name toolbar name (identifier)
401   \return toolbar ID or -1 if toolbar could not be created
402 */
403 int CAM_Module::createTool( const QString& title, const QString& name )
404 {
405   if ( !toolMgr() )
406     return -1;
407
408   ActionMgrLocker lock( toolMgr(), !myToolShown );
409
410   return toolMgr()->createToolBar( title, name );
411 }
412
413 /*!
414   \brief Add toolbar item.
415
416   Insert action \a to the toolbar manager and register it with specified \a id.
417   Resulting action ID may differ from the requested one. This can happen if
418   requested ID is already in use.
419
420   If action has been already added previously, its ID is just returned.
421
422   If \a id < 0, the action ID is generated automatically.
423
424   If \a idx < 0, the action is added to the end of the toolbar.
425
426   \param a action
427   \param tBar toolbar ID
428   \param id requested action ID
429   \param idx action index (desired position in the toolbar)
430   \return action ID or -1 if toolbar item could not be added
431 */
432 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
433 {
434   if ( !toolMgr() )
435     return -1;
436
437   ActionMgrLocker lock( toolMgr(), !myToolShown );
438
439   int regId = registerAction( id, a );
440   int intId = toolMgr()->insert( a, tBar, idx );
441
442   if ( !myToolShown )
443     setToolShown( a, false );
444
445   return intId != -1 ? regId : -1;
446 }
447
448 /*!
449   \brief Add toolbar item.
450
451   Insert action \a to the toolbar manager and register it with specified \a id.
452   Resulting action ID may differ from the requested one. This can happen if
453   requested ID is already in use.
454
455   If action has been already added previously, its ID is just returned.
456
457   If \a id < 0, the action ID is generated automatically.
458
459   If \a idx < 0, the action is added to the end of the toolbar.
460
461   \param a action
462   \param tBar toolbar name
463   \param id requested action ID
464   \param idx action index (desired position in the toolbar)
465   \return action ID or -1 if toolbar item could not be added
466 */
467 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
468 {
469   if ( !toolMgr() )
470     return -1;
471
472   ActionMgrLocker lock( toolMgr(), !myToolShown );
473
474   int regId = registerAction( id, a );
475   int intId = toolMgr()->insert( a, tBar, idx );
476
477   if ( !myToolShown )
478     setToolShown( a, false );
479
480   return intId != -1 ? regId : -1;
481 }
482
483 /*!
484   \brief Add toolbar item.
485
486   Insert action with \a id identifier to the toolbar manager.
487   It is assumed that action has been already registered.
488
489   Resulting action ID may differ from the requested one. This can happen if
490   requested ID is already in use.
491
492   If action has been already added previously, its ID is just returned.
493
494   If \a idx < 0, the action is added to the end of the toolbar.
495
496   \param id action ID
497   \param tBar toolbar ID
498   \param idx action index (desired position in the toolbar)
499   \return action ID or -1 if toolbar item could not be added
500 */
501 int CAM_Module::createTool( const int id, const int tBar, const int idx )
502 {
503   if ( !toolMgr() )
504     return -1;
505
506   ActionMgrLocker lock( toolMgr(), !myToolShown );
507
508   int intId = toolMgr()->insert( action( id ), tBar, idx );
509
510   if ( !myToolShown )
511     setToolShown( action( id ), false );
512
513   return intId != -1 ? id : -1;
514 }
515
516 /*!
517   \brief Add toolbar item.
518
519   Insert action with \a id identifier to the toolbar manager.
520   It is assumed that action has been already registered.
521
522   Resulting action ID may differ from the requested one. This can happen if
523   requested ID is already in use.
524
525   If action has been already added previously, its ID is just returned.
526
527   If \a idx < 0, the action is added to the end of the toolbar.
528
529   \param id action ID
530   \param tBar toolbar name
531   \param idx action index (desired position in the toolbar)
532   \return action ID or -1 if toolbar item could not be added
533 */
534 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
535 {
536   if ( !toolMgr() )
537     return -1;
538
539   ActionMgrLocker lock( toolMgr(), !myToolShown );
540
541   int intId = toolMgr()->insert( action( id ), tBar, idx );
542
543   if ( !myToolShown )
544     setToolShown( action( id ), false );
545
546   return intId != -1 ? id : -1;
547 }
548
549 /*!
550   \brief Create menu or submenu.
551
552   Create main menu or popup submenu and register it with specified \a id.
553   Resulting action ID may differ from the requested one. This can happen if
554   requested ID is already in use.
555
556   If \a id < 0, the menu ID is generated automatically.
557   If menu has been already created previously, its ID is just returned.
558
559   The \a menu parameter represents the menu name - it could be a sequence
560   of strings, separated by '|' symbol. For example, "File|Edit" means
561   File->Edit submenu. If menu doesn't exist, it is created automatically.
562
563   Parameter \a idx defines the index of the menu item in the menu group which
564   is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
565   end of the menu group.
566
567   \param subMenu subMenu name
568   \param menu parent menu ID
569   \param id requested menu ID
570   \param group menu group ID
571   \param idx menu item index (desired position in the menu group)
572   \return menu item ID or -1 if menu item could not be added
573 */
574 int CAM_Module::createMenu( const QString& subMenu, const int menu,
575                             const int id, const int group, const int idx, QMenu * menuObj )
576 {
577   if ( !menuMgr() )
578     return -1;
579   
580   return menuMgr()->insert( subMenu, menu, group, id, idx, menuObj );
581 }
582
583 /*!
584   \brief Create menu or submenu.
585
586   Create main menu or popup submenu and register it with specified \a id.
587   Resulting action ID may differ from the requested one. This can happen if
588   requested ID is already in use.
589
590   If \a id < 0, the menu ID is generated automatically.
591   If menu has been already created previously, its ID is just returned.
592
593   The \a menu parameter represents the menu name - it could be a sequence
594   of strings, separated by '|' symbol. For example, "File|Edit" means
595   File->Edit submenu. If menu doesn't exist, it is created automatically.
596
597   Parameter \a idx defines the index of the menu item in the menu group which
598   is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
599   end of the menu group.
600
601   \param subMenu subMenu name
602   \param menu parent menu name(s)
603   \param id requested menu ID
604   \param group menu group ID
605   \param idx menu item index (desired position in the menu group)
606   \return menu item ID or -1 if menu item could not be added
607 */
608 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
609                             const int id, const int group, const int idx )
610 {
611   if ( !menuMgr() )
612     return -1;
613
614   return menuMgr()->insert( subMenu, menu, group, id, idx );
615 }
616
617 /*!
618   \brief Add menu item.
619
620   Insert action \a to the menu manager and register it with specified \a id.
621   Resulting action ID may differ from the requested one. This can happen if
622   requested ID is already in use.
623
624   If \a id < 0, the action ID is generated automatically.
625
626   If action has been already added previously, its ID is just returned.
627
628   Parameter \a idx defines the index of the menu item in the menu group which
629   is defined by the \a group. If \a idx < 0, the action is added to the
630   end of the menu group.
631
632   \param a action
633   \param menu menu ID
634   \param id requested action ID
635   \param group menu group ID
636   \param idx action index (desired position in the menu group)
637   \return action ID or -1 if menu item could not be added
638 */
639 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
640 {
641   if ( !a || !menuMgr() )
642     return -1;
643   
644   ActionMgrLocker lock( menuMgr(), !myMenuShown );
645
646   int regId = registerAction( id, a );
647   int intId = menuMgr()->insert( a, menu, group, idx );
648
649   if ( !myMenuShown )
650     setMenuShown( a, false );
651
652   return intId != -1 ? regId : -1;
653 }
654
655 /*!
656   \brief Add menu item.
657
658   Insert action \a to the menu manager and register it with specified \a id.
659   Resulting action ID may differ from the requested one. This can happen if
660   requested ID is already in use.
661
662   If \a id < 0, the action ID is generated automatically.
663
664   If action has been already added previously, its ID is just returned.
665
666   The \a menu parameter represents the menu name - it could be a sequence
667   of strings, separated by '|' symbol. For example, "File|Edit" means
668   File->Edit submenu. If menu doesn't exist, it is created automatically.
669
670   Parameter \a idx defines the index of the menu item in the menu group which
671   is defined by the \a group. If \a idx < 0, the action is added to the
672   end of the menu group.
673
674   \param a action
675   \param menu menu name(s)
676   \param id requested action ID
677   \param group menu group ID
678   \param idx action index (desired position in the menu group)
679   \return action ID or -1 if menu item could not be added
680 */
681 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
682 {
683   if ( !a || !menuMgr() )
684     return -1;
685
686   ActionMgrLocker lock( menuMgr(), !myMenuShown );
687
688   int regId = registerAction( id, a );
689   int intId = menuMgr()->insert( a, menu, group, idx );
690
691   if ( !myMenuShown )
692     setMenuShown( a, false );
693   
694   return intId != -1 ? regId : -1;
695 }
696
697 /*!
698   \brief Add menu item.
699
700   Insert action with \a id identifier to the menu manager.
701   It is assumed that action has been already registered.
702
703   Resulting action ID may differ from the requested one. This can happen if
704   requested ID is already in use.
705
706   If action has been already added previously, its ID is just returned.
707
708   Parameter \a idx defines the index of the menu item in the menu group which
709   is defined by the \a group. If \a idx < 0, the action is added to the
710   end of the menu group.
711
712   \param id action ID
713   \param menu menu ID
714   \param group menu group ID
715   \param idx action index (desired position in the menu group)
716   \return action ID or -1 if menu item could not be added
717 */
718 int CAM_Module::createMenu( const int id, const int menu, const int group, const int idx )
719 {
720   if ( !menuMgr() )
721     return -1;
722
723   ActionMgrLocker lock( menuMgr(), !myMenuShown );
724
725   int intId = menuMgr()->insert( action( id ), menu, group, idx );
726
727   if ( !myMenuShown )
728     setMenuShown( action( id ), false );
729
730   return intId != -1 ? id : -1;
731 }
732
733 /*!
734   \brief Add menu item.
735
736   Insert action with \a id identifier to the menu manager.
737   It is assumed that action has been already registered.
738
739   Resulting action ID may differ from the requested one. This can happen if
740   requested ID is already in use.
741
742   If action has been already added previously, its ID is just returned.
743
744   The \a menu parameter represents the menu name - it could be a sequence
745   of strings, separated by '|' symbol. For example, "File|Edit" means
746   File->Edit submenu. If menu doesn't exist, it is created automatically.
747
748   Parameter \a idx defines the index of the menu item in the menu group which
749   is defined by the \a group. If \a idx < 0, the action is added to the
750   end of the menu group.
751
752   \param id action ID
753   \param menu menu name(s)
754   \param group menu group ID
755   \param idx action index (desired position in the menu group)
756   \return action ID or -1 if menu item could not be added
757 */
758 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
759 {
760   if ( !menuMgr() )
761     return -1;
762
763   ActionMgrLocker lock( menuMgr(), !myMenuShown );
764
765   int intId = menuMgr()->insert( action( id ), menu, group, idx );
766
767   if ( !myMenuShown )
768     setMenuShown( action( id ), false );
769
770   return intId != -1 ? id : -1;
771 }
772
773 /*!
774   \brief Show/hide all module's menus.
775   \param on if \c true, show menus, otherwise, hide all menus
776   \sa setToolShown()
777 */
778 void CAM_Module::setMenuShown( const bool on )
779 {
780   myMenuShown = on;
781
782   QtxActionMenuMgr* mMgr = menuMgr();
783   if ( !mMgr )
784     return;
785
786   bool upd = mMgr->isUpdatesEnabled();
787   mMgr->setUpdatesEnabled( false );
788
789   QAction* sep = separator();
790   for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
791   {
792     if ( it.value() != sep )
793       mMgr->setShown( mMgr->actionId( it.value() ), on );
794   }
795
796   mMgr->setUpdatesEnabled( upd );
797   if ( upd )
798     mMgr->update();
799 }
800
801 /*!
802   \brief Show/hide specified menu item.
803   \param a action
804   \param on if \c true, show menu item, otherwise, hide it
805 */
806 void CAM_Module::setMenuShown( QAction* a, const bool on )
807 {
808   if ( menuMgr() )
809     menuMgr()->setShown( menuMgr()->actionId( a ), on );
810 }
811
812 /*!
813   \brief Show/hide specified menu item.
814   \param id menu item ID
815   \param on if \c true, show menu item, otherwise, hide it
816 */
817 void CAM_Module::setMenuShown( const int id, const bool on )
818 {
819   setMenuShown( action( id ), on );
820 }
821
822 /*!
823   \brief Show/hide all module's toolbars.
824   \param on if \c true, show toolbars, otherwise, hide all toolbars
825   \sa setMenuShown()
826 */
827 void CAM_Module::setToolShown( const bool on )
828 {
829   myToolShown = on;
830
831   QtxActionToolMgr* tMgr = toolMgr();
832   if ( !tMgr )
833     return;
834
835   bool upd = tMgr->isUpdatesEnabled();
836   tMgr->setUpdatesEnabled( false );
837
838   QAction* sep = separator();
839   for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
840   {
841     if ( it.value() != sep )
842       tMgr->setShown( tMgr->actionId( it.value() ), on );
843   }
844
845   tMgr->setUpdatesEnabled( upd );
846   if ( upd )
847     tMgr->update();
848 }
849
850 /*!
851   \brief Show/hide specified toolbar item.
852   \param a action
853   \param on if \c true, show toolbar item, otherwise, hide it
854 */
855 void CAM_Module::setToolShown( QAction* a, const bool on )
856 {
857   if ( toolMgr() )
858     toolMgr()->setShown( toolMgr()->actionId( a ), on );
859 }
860
861 /*!
862   \brief Show/hide specified toolbar item.
863   \param id toolbar item ID
864   \param on if \c true, show toolbar item, otherwise, hide it
865 */
866 void CAM_Module::setToolShown( const int id, const bool on )
867 {
868   setToolShown( action( id ), on );
869 }
870
871 /*!
872   \brief Get action by specified \a id.
873   \param id action ID
874   \return action or 0 if not found
875 */
876 QAction* CAM_Module::action( const int id ) const
877 {
878   QAction* a = 0;
879   if ( myActionMap.contains( id ) )
880     a = myActionMap[id];
881   else if ( menuMgr() ) {
882     QMenu* m = menuMgr()->findMenu( id );
883     if ( m ) a = m->menuAction();
884   }
885   return a;
886 }
887
888 /*!
889   \brief Get action ID.
890   \param a action
891   \return action ID or -1 if not found
892 */
893 int CAM_Module::actionId( const QAction* a ) const
894 {
895   int id = -1;
896   for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
897   {
898     if ( it.value() == a )
899       id = it.key();
900   }
901   return id;
902 }
903
904 /*!
905   \brief Create new instance of QtxAction and register action with specified \a id.
906
907   Resulting action ID may differ from the requested one. This can happen if
908   requested ID is already in use.
909
910   If \a id < 0, the action ID is generated automatically.
911
912   \param id required action ID
913   \param text tooltip text
914   \param icon action icon
915   \param menu menu text
916   \param tip status bar tip
917   \param key keyboard accelerator
918   \param parent parent object
919   \param toggle if \c true, the action will be toggled
920   \param reciever action activation signal receiver object
921   \param member action activation signal receiver slot
922 */
923 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
924                                    const QString& menu, const QString& tip, const int key,
925                                    QObject* parent, const bool toggle, QObject* reciever,
926                                    const char* member, const QString& shortcutAction )
927 {
928   QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
929   a->setStatusTip( tip );
930
931   if ( reciever && member )
932     connect( a, SIGNAL( triggered( bool ) ), reciever, member );
933
934   registerAction( id, a );
935
936   return a;
937 }
938
939 /*!
940   \brief Create new action group.
941   \param id action group ID
942   \param exclusive \c true for exclusive action group
943   \return created action group
944 */
945 QtxActionGroup* CAM_Module::createActionGroup( const int id, const bool exclusive )
946 {
947   QtxActionGroup* a = qobject_cast<QtxActionGroup*>( action( id ) );
948   if ( !a ) {
949     a = new QtxActionGroup( this );
950     registerAction( id, a );
951   }
952   a->setExclusive( exclusive );
953   return a;
954 }
955
956 /*!
957   \brief Register action in the internal action map.
958
959   If action has been already added previously, its ID is just returned.
960   If \a id < 0, the action ID is generated automatically.
961
962   \param id action required ID
963   \param a action
964   \return action ID
965 */
966 int CAM_Module::registerAction( const int id, QAction* a )
967 {
968   int ident = -1;
969   for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
970     if ( it.value() == a )
971       ident = it.key();
972
973   if ( ident != -1 )
974     return ident;
975
976   static int generatedId = -1;
977   ident = id < 0 ? --generatedId : id;
978
979   myActionMap.insert( ident, a );
980
981   if ( menuMgr() )
982     menuMgr()->registerAction( a );
983
984   if ( toolMgr() )
985     toolMgr()->registerAction( a );
986
987   if ( application() && application()->desktop() )
988     application()->desktop()->addAction( a );
989
990   return ident;
991 }
992
993 /*!
994   \brief Unregister action from the internal action map.
995
996   \param id action ID
997   \return \c true on success or \c false if action is in use
998 */
999 bool CAM_Module::unregisterAction( const int id )
1000 {
1001   return unregisterAction( action( id ) );
1002 }
1003
1004 /*!
1005   \brief Unregister action from the internal action map.
1006
1007   \param a action
1008   \return \c true on success or \c false if action is in use
1009 */
1010 bool CAM_Module::unregisterAction( QAction* a )
1011 {
1012   if ( !a )
1013     return false;
1014   if ( menuMgr() ) {
1015     int id = menuMgr()->actionId( a );
1016     if ( id != -1 && menuMgr()->containsMenu( id, -1 ) )
1017       return false;
1018   }
1019   if ( toolMgr() ) {
1020     int id = toolMgr()->actionId( a );
1021     if ( id != -1 && toolMgr()->containsAction( id ) )
1022       return false;
1023   }
1024   if ( menuMgr() )
1025     menuMgr()->unRegisterAction( menuMgr()->actionId( a ) );
1026   if ( toolMgr() )
1027     toolMgr()->unRegisterAction( toolMgr()->actionId( a ) );
1028   return true;
1029 }
1030
1031 /*!
1032   \brief Create separator action.
1033
1034   Separator action can be used in menus or toolbars.
1035
1036   \return new separator action
1037 */
1038 QAction* CAM_Module::separator()
1039 {
1040   return QtxActionMgr::separator();
1041 }
1042
1043 /*!
1044   \brief Update visibility state of the module objects.
1045 */
1046 void CAM_Module::updateModuleVisibilityState() {
1047
1048 }
1049
1050 /*!
1051   \brief Activate GUI operation of module by its ID.
1052   This method is called from CAM_Application::startOperation().
1053   \param actionId is a numerical unique operation id.
1054 */
1055 bool CAM_Module::activateOperation( int actionId )
1056 {
1057   return false;
1058 }
1059
1060 /*!
1061   \brief Activate GUI operation of module by its ID.
1062   This method is called from CAM_Application::startOperation().
1063   \param actionId is a string unique operation id.
1064 */
1065 bool CAM_Module::activateOperation( const QString& actionId )
1066 {
1067   return false;
1068 }
1069
1070 /*!
1071   \brief Activate GUI operation of module by its ID and \a pluginName.
1072   This method is called from CAM_Application::startOperation().
1073   \param actionId is a string unique operation id.
1074   \param pluginName is a name of a plugin where the operation is implemented.
1075 */
1076 bool CAM_Module::activateOperation( const QString& actionId, const QString& pluginName )
1077 {
1078   return false;
1079 }
1080
1081
1082 /*!
1083   \brief Connect data model of the module to the active study
1084   \param camStudy CAM study object
1085 */
1086 void CAM_Module::connectToStudy( CAM_Study* camStudy )
1087 {
1088   CAM_Application* app = camStudy ? dynamic_cast<CAM_Application*>( camStudy->application() ) : 0;
1089   if( !app )
1090     return;
1091
1092   CAM_DataModel* prev = 0;
1093   CAM_Application::ModuleList mods = app->modules();
1094   for( QList<CAM_Module*>::const_iterator it = mods.begin(); it != mods.end(); ++it )
1095   {
1096     CAM_DataModel* dm = (*it)->dataModel();
1097     if( (*it) == this && !camStudy->containsDataModel( dm ) )
1098     {
1099       if ( prev )
1100         camStudy->insertDataModel( (*it)->dataModel(), prev );
1101       else
1102         camStudy->insertDataModel( (*it)->dataModel(), 0 );
1103     }
1104     prev = dm;
1105   }
1106 }
1107
1108 /*!
1109   \fn void CAM_Module::contextMenuPopup( const QString& type, QMenu* menu, QString& title );
1110   \brief Create context popup menu.
1111   \param type popup menu context
1112   \param menu popup menu
1113   \param title popup menu title, which can be set by the module if required
1114 */
1115
1116 /*!
1117   \fn void CAM_Module::updateCommandsStatus();
1118   \brief Update menu/toolbar actions.
1119 */