Salome HOME
Merge from V6_main 11/02/2013
[modules/gui.git] / src / CAM / CAM_Module.cxx
1 // Copyright (C) 2007-2012  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.
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 name toolbar name
400   \return toolbar ID or -1 if toolbar could not be created
401 */
402 int CAM_Module::createTool( const QString& name )
403 {
404   if ( !toolMgr() )
405     return -1;
406
407   ActionMgrLocker lock( toolMgr(), !myToolShown );
408
409   return toolMgr()->createToolBar( name, myToolShown );
410 }
411
412 /*!
413   \brief Add toolbar item.
414
415   Insert action \a to the toolbar manager and register it with specified \a id.
416   Resulting action ID may differ from the requested one. This can happen if
417   requested ID is already in use.
418
419   If action has been already added previously, its ID is just returned.
420
421   If \a id < 0, the action ID is generated automatically.
422
423   If \a idx < 0, the action is added to the end of the toolbar.
424
425   \param a action
426   \param tBar toolbar ID
427   \param id requested action ID
428   \param idx action index (desired position in the toolbar)
429   \return action ID or -1 if toolbar item could not be added
430 */
431 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
432 {
433   if ( !toolMgr() )
434     return -1;
435
436   ActionMgrLocker lock( toolMgr(), !myToolShown );
437
438   int regId = registerAction( id, a );
439   int intId = toolMgr()->insert( a, tBar, idx );
440
441   if ( !myToolShown )
442     setToolShown( a, false );
443
444   return intId != -1 ? regId : -1;
445 }
446
447 /*!
448   \brief Add toolbar item.
449
450   Insert action \a to the toolbar manager and register it with specified \a id.
451   Resulting action ID may differ from the requested one. This can happen if
452   requested ID is already in use.
453
454   If action has been already added previously, its ID is just returned.
455
456   If \a id < 0, the action ID is generated automatically.
457
458   If \a idx < 0, the action is added to the end of the toolbar.
459
460   \param a action
461   \param tBar toolbar name
462   \param id requested action ID
463   \param idx action index (desired position in the toolbar)
464   \return action ID or -1 if toolbar item could not be added
465 */
466 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
467 {
468   if ( !toolMgr() )
469     return -1;
470
471   ActionMgrLocker lock( toolMgr(), !myToolShown );
472
473   int regId = registerAction( id, a );
474   int intId = toolMgr()->insert( a, tBar, idx );
475
476   if ( !myToolShown )
477     setToolShown( a, false );
478
479   return intId != -1 ? regId : -1;
480 }
481
482 /*!
483   \brief Add toolbar item.
484
485   Insert action with \a id identifier to the toolbar manager.
486   It is assumed that action has been already registered.
487
488   Resulting action ID may differ from the requested one. This can happen if
489   requested ID is already in use.
490
491   If action has been already added previously, its ID is just returned.
492
493   If \a idx < 0, the action is added to the end of the toolbar.
494
495   \param id action ID
496   \param tBar toolbar ID
497   \param idx action index (desired position in the toolbar)
498   \return action ID or -1 if toolbar item could not be added
499 */
500 int CAM_Module::createTool( const int id, const int tBar, const int idx )
501 {
502   if ( !toolMgr() )
503     return -1;
504
505   ActionMgrLocker lock( toolMgr(), !myToolShown );
506
507   int intId = toolMgr()->insert( action( id ), tBar, idx );
508
509   if ( !myToolShown )
510     setToolShown( action( id ), false );
511
512   return intId != -1 ? id : -1;
513 }
514
515 /*!
516   \brief Add toolbar item.
517
518   Insert action with \a id identifier to the toolbar manager.
519   It is assumed that action has been already registered.
520
521   Resulting action ID may differ from the requested one. This can happen if
522   requested ID is already in use.
523
524   If action has been already added previously, its ID is just returned.
525
526   If \a idx < 0, the action is added to the end of the toolbar.
527
528   \param id action ID
529   \param tBar toolbar name
530   \param idx action index (desired position in the toolbar)
531   \return action ID or -1 if toolbar item could not be added
532 */
533 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
534 {
535   if ( !toolMgr() )
536     return -1;
537
538   ActionMgrLocker lock( toolMgr(), !myToolShown );
539
540   int intId = toolMgr()->insert( action( id ), tBar, idx );
541
542   if ( !myToolShown )
543     setToolShown( action( id ), false );
544
545   return intId != -1 ? id : -1;
546 }
547
548 /*!
549   \brief Create menu or submenu.
550
551   Create main menu or popup submenu and register it with specified \a id.
552   Resulting action ID may differ from the requested one. This can happen if
553   requested ID is already in use.
554
555   If \a id < 0, the menu ID is generated automatically.
556   If menu has been already created previously, its ID is just returned.
557
558   The \a menu parameter represents the menu name - it could be a sequence
559   of strings, separated by '|' symbol. For example, "File|Edit" means
560   File->Edit submenu. If menu doesn't exist, it is created automatically.
561
562   Parameter \a idx defines the index of the menu item in the menu group which
563   is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
564   end of the menu group.
565
566   \param subMenu subMenu name
567   \param menu parent menu ID
568   \param id requested menu ID
569   \param group menu group ID
570   \param idx menu item index (desired position in the menu group)
571   \return menu item ID or -1 if menu item could not be added
572 */
573 int CAM_Module::createMenu( const QString& subMenu, const int menu,
574                             const int id, const int group, const int idx )
575 {
576   if ( !menuMgr() )
577     return -1;
578   
579   return menuMgr()->insert( subMenu, menu, group, id, idx );
580 }
581
582 /*!
583   \brief Create menu or submenu.
584
585   Create main menu or popup submenu and register it with specified \a id.
586   Resulting action ID may differ from the requested one. This can happen if
587   requested ID is already in use.
588
589   If \a id < 0, the menu ID is generated automatically.
590   If menu has been already created previously, its ID is just returned.
591
592   The \a menu parameter represents the menu name - it could be a sequence
593   of strings, separated by '|' symbol. For example, "File|Edit" means
594   File->Edit submenu. If menu doesn't exist, it is created automatically.
595
596   Parameter \a idx defines the index of the menu item in the menu group which
597   is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
598   end of the menu group.
599
600   \param subMenu subMenu name
601   \param menu parent menu name(s)
602   \param id requested menu ID
603   \param group menu group ID
604   \param idx menu item index (desired position in the menu group)
605   \return menu item ID or -1 if menu item could not be added
606 */
607 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
608                             const int id, const int group, const int idx )
609 {
610   if ( !menuMgr() )
611     return -1;
612
613   return menuMgr()->insert( subMenu, menu, group, id, idx );
614 }
615
616 /*!
617   \brief Add menu item.
618
619   Insert action \a to the menu manager and register it with specified \a id.
620   Resulting action ID may differ from the requested one. This can happen if
621   requested ID is already in use.
622
623   If \a id < 0, the action ID is generated automatically.
624
625   If action has been already added previously, its ID is just returned.
626
627   Parameter \a idx defines the index of the menu item in the menu group which
628   is defined by the \a group. If \a idx < 0, the action is added to the
629   end of the menu group.
630
631   \param a action
632   \param menu menu ID
633   \param id requested action ID
634   \param group menu group ID
635   \param idx action index (desired position in the menu group)
636   \return action ID or -1 if menu item could not be added
637 */
638 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
639 {
640   if ( !a || !menuMgr() )
641     return -1;
642   
643   ActionMgrLocker lock( menuMgr(), !myMenuShown );
644
645   int regId = registerAction( id, a );
646   int intId = menuMgr()->insert( a, menu, group, idx );
647
648   if ( !myMenuShown )
649     setMenuShown( a, false );
650
651   return intId != -1 ? regId : -1;
652 }
653
654 /*!
655   \brief Add menu item.
656
657   Insert action \a to the menu manager and register it with specified \a id.
658   Resulting action ID may differ from the requested one. This can happen if
659   requested ID is already in use.
660
661   If \a id < 0, the action ID is generated automatically.
662
663   If action has been already added previously, its ID is just returned.
664
665   The \a menu parameter represents the menu name - it could be a sequence
666   of strings, separated by '|' symbol. For example, "File|Edit" means
667   File->Edit submenu. If menu doesn't exist, it is created automatically.
668
669   Parameter \a idx defines the index of the menu item in the menu group which
670   is defined by the \a group. If \a idx < 0, the action is added to the
671   end of the menu group.
672
673   \param a action
674   \param menu menu name(s)
675   \param id requested action ID
676   \param group menu group ID
677   \param idx action index (desired position in the menu group)
678   \return action ID or -1 if menu item could not be added
679 */
680 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
681 {
682   if ( !a || !menuMgr() )
683     return -1;
684
685   ActionMgrLocker lock( menuMgr(), !myMenuShown );
686
687   int regId = registerAction( id, a );
688   int intId = menuMgr()->insert( a, menu, group, idx );
689
690   if ( !myMenuShown )
691     setMenuShown( a, false );
692   
693   return intId != -1 ? regId : -1;
694 }
695
696 /*!
697   \brief Add menu item.
698
699   Insert action with \a id identifier to the menu manager.
700   It is assumed that action has been already registered.
701
702   Resulting action ID may differ from the requested one. This can happen if
703   requested ID is already in use.
704
705   If action has been already added previously, its ID is just returned.
706
707   Parameter \a idx defines the index of the menu item in the menu group which
708   is defined by the \a group. If \a idx < 0, the action is added to the
709   end of the menu group.
710
711   \param id action ID
712   \param menu menu ID
713   \param group menu group ID
714   \param idx action index (desired position in the menu group)
715   \return action ID or -1 if menu item could not be added
716 */
717 int CAM_Module::createMenu( const int id, const int menu, const int group, const int idx )
718 {
719   if ( !menuMgr() )
720     return -1;
721
722   ActionMgrLocker lock( menuMgr(), !myMenuShown );
723
724   int intId = menuMgr()->insert( action( id ), menu, group, idx );
725
726   if ( !myMenuShown )
727     setMenuShown( action( id ), false );
728
729   return intId != -1 ? id : -1;
730 }
731
732 /*!
733   \brief Add menu item.
734
735   Insert action with \a id identifier to the menu manager.
736   It is assumed that action has been already registered.
737
738   Resulting action ID may differ from the requested one. This can happen if
739   requested ID is already in use.
740
741   If action has been already added previously, its ID is just returned.
742
743   The \a menu parameter represents the menu name - it could be a sequence
744   of strings, separated by '|' symbol. For example, "File|Edit" means
745   File->Edit submenu. If menu doesn't exist, it is created automatically.
746
747   Parameter \a idx defines the index of the menu item in the menu group which
748   is defined by the \a group. If \a idx < 0, the action is added to the
749   end of the menu group.
750
751   \param id action ID
752   \param menu menu name(s)
753   \param group menu group ID
754   \param idx action index (desired position in the menu group)
755   \return action ID or -1 if menu item could not be added
756 */
757 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
758 {
759   if ( !menuMgr() )
760     return -1;
761
762   ActionMgrLocker lock( menuMgr(), !myMenuShown );
763
764   int intId = menuMgr()->insert( action( id ), menu, group, idx );
765
766   if ( !myMenuShown )
767     setMenuShown( action( id ), false );
768
769   return intId != -1 ? id : -1;
770 }
771
772 /*!
773   \brief Show/hide all module's menus.
774   \param on if \c true, show menus, otherwise, hide all menus
775   \sa setToolShown()
776 */
777 void CAM_Module::setMenuShown( const bool on )
778 {
779   myMenuShown = on;
780
781   QtxActionMenuMgr* mMgr = menuMgr();
782   if ( !mMgr )
783     return;
784
785   bool upd = mMgr->isUpdatesEnabled();
786   mMgr->setUpdatesEnabled( false );
787
788   QAction* sep = separator();
789   for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
790   {
791     if ( it.value() != sep )
792       mMgr->setShown( mMgr->actionId( it.value() ), on );
793   }
794
795   mMgr->setUpdatesEnabled( upd );
796   if ( upd )
797     mMgr->update();
798 }
799
800 /*!
801   \brief Show/hide specified menu item.
802   \param a action
803   \param on if \c true, show menu item, otherwise, hide it
804 */
805 void CAM_Module::setMenuShown( QAction* a, const bool on )
806 {
807   if ( menuMgr() )
808     menuMgr()->setShown( menuMgr()->actionId( a ), on );
809 }
810
811 /*!
812   \brief Show/hide specified menu item.
813   \param id menu item ID
814   \param on if \c true, show menu item, otherwise, hide it
815 */
816 void CAM_Module::setMenuShown( const int id, const bool on )
817 {
818   setMenuShown( action( id ), on );
819 }
820
821 /*!
822   \brief Show/hide all module's toolbars.
823   \param on if \c true, show toolbars, otherwise, hide all toolbars
824   \sa setMenuShown()
825 */
826 void CAM_Module::setToolShown( const bool on )
827 {
828   myToolShown = on;
829
830   QtxActionToolMgr* tMgr = toolMgr();
831   if ( !tMgr )
832     return;
833
834   bool upd = tMgr->isUpdatesEnabled();
835   tMgr->setUpdatesEnabled( false );
836
837   QAction* sep = separator();
838   for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
839   {
840     if ( it.value() != sep )
841       tMgr->setShown( tMgr->actionId( it.value() ), on );
842   }
843
844   tMgr->setUpdatesEnabled( upd );
845   if ( upd )
846     tMgr->update();
847 }
848
849 /*!
850   \brief Show/hide specified toolbar item.
851   \param a action
852   \param on if \c true, show toolbar item, otherwise, hide it
853 */
854 void CAM_Module::setToolShown( QAction* a, const bool on )
855 {
856   if ( toolMgr() )
857     toolMgr()->setShown( toolMgr()->actionId( a ), on );
858 }
859
860 /*!
861   \brief Show/hide specified toolbar item.
862   \param id toolbar item ID
863   \param on if \c true, show toolbar item, otherwise, hide it
864 */
865 void CAM_Module::setToolShown( const int id, const bool on )
866 {
867   setToolShown( action( id ), on );
868 }
869
870 /*!
871   \brief Get action by specified \a id.
872   \param id action ID
873   \return action or 0 if not found
874 */
875 QAction* CAM_Module::action( const int id ) const
876 {
877   QAction* a = 0;
878   if ( myActionMap.contains( id ) )
879     a = myActionMap[id];
880   else if ( menuMgr() ) {
881     QMenu* m = menuMgr()->findMenu( id );
882     if ( m ) a = m->menuAction();
883   }
884   return a;
885 }
886
887 /*!
888   \brief Get action ID.
889   \param a action
890   \return action ID or -1 if not found
891 */
892 int CAM_Module::actionId( const QAction* a ) const
893 {
894   int id = -1;
895   for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
896   {
897     if ( it.value() == a )
898       id = it.key();
899   }
900   return id;
901 }
902
903 /*!
904   \brief Create new instance of QtxAction and register action with specified \a id.
905
906   Resulting action ID may differ from the requested one. This can happen if
907   requested ID is already in use.
908
909   If \a id < 0, the action ID is generated automatically.
910
911   \param id required action ID
912   \param text tooltip text
913   \param icon action icon
914   \param menu menu text
915   \param tip status bar tip
916   \param key keyboard accelerator
917   \param parent parent object
918   \param toggle if \c true, the action will be toggled
919   \param reciever action activation signal receiver object
920   \param member action activation signal receiver slot
921 */
922 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
923                                    const QString& menu, const QString& tip, const int key,
924                                    QObject* parent, const bool toggle, QObject* reciever,
925                                    const char* member, const QString& shortcutAction )
926 {
927   QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
928   a->setStatusTip( tip );
929
930   if ( reciever && member )
931     connect( a, SIGNAL( triggered( bool ) ), reciever, member );
932
933   registerAction( id, a );
934
935   return a;
936 }
937
938 /*!
939   \brief Create new action group.
940   \param id action group ID
941   \param exclusive \c true for exclusive action group
942   \return created action group
943 */
944 QtxActionGroup* CAM_Module::createActionGroup( const int id, const bool exclusive )
945 {
946   QtxActionGroup* a = qobject_cast<QtxActionGroup*>( action( id ) );
947   if ( !a ) {
948     a = new QtxActionGroup( this );
949     registerAction( id, a );
950   }
951   a->setExclusive( exclusive );
952   return a;
953 }
954
955 /*!
956   \brief Register action in the internal action map.
957
958   If action has been already added previously, its ID is just returned.
959   If \a id < 0, the action ID is generated automatically.
960
961   \param id action required ID
962   \param a action
963   \return action ID
964 */
965 int CAM_Module::registerAction( const int id, QAction* a )
966 {
967   int ident = -1;
968   for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
969     if ( it.value() == a )
970       ident = it.key();
971
972   if ( ident != -1 )
973     return ident;
974
975   static int generatedId = -1;
976   ident = id < 0 ? --generatedId : id;
977
978   myActionMap.insert( ident, a );
979
980   if ( menuMgr() )
981     menuMgr()->registerAction( a );
982
983   if ( toolMgr() )
984     toolMgr()->registerAction( a );
985
986   if ( application() && application()->desktop() )
987     application()->desktop()->addAction( a );
988
989   return ident;
990 }
991
992 /*!
993   \brief Unregister action from the internal action map.
994
995   \param id action ID
996   \return \c true on success or \c false if action is in use
997 */
998 bool CAM_Module::unregisterAction( const int id )
999 {
1000   return unregisterAction( action( id ) );
1001 }
1002
1003 /*!
1004   \brief Unregister action from the internal action map.
1005
1006   \param a action
1007   \return \c true on success or \c false if action is in use
1008 */
1009 bool CAM_Module::unregisterAction( QAction* a )
1010 {
1011   if ( !a )
1012     return false;
1013   if ( menuMgr() ) {
1014     int id = menuMgr()->actionId( a );
1015     if ( id != -1 && menuMgr()->containsMenu( id, -1 ) )
1016       return false;
1017   }
1018   if ( toolMgr() ) {
1019     int id = toolMgr()->actionId( a );
1020     if ( id != -1 && toolMgr()->containsAction( id ) )
1021       return false;
1022   }
1023   if ( menuMgr() )
1024     menuMgr()->unRegisterAction( menuMgr()->actionId( a ) );
1025   if ( toolMgr() )
1026     toolMgr()->unRegisterAction( toolMgr()->actionId( a ) );
1027   return true;
1028 }
1029
1030 /*!
1031   \brief Create separator action.
1032
1033   Separator action can be used in menus or toolbars.
1034
1035   \return new separator action
1036 */
1037 QAction* CAM_Module::separator()
1038 {
1039   return QtxActionMgr::separator();
1040 }
1041
1042 /*!
1043   \brief Update visibility state of the module objects.
1044 */
1045 void CAM_Module::updateModuleVisibilityState() {
1046
1047 }
1048
1049
1050 /*!
1051   \brief Connect data model of the module to the active study
1052   \param camStudy CAM study object
1053 */
1054 void CAM_Module::connectToStudy( CAM_Study* camStudy )
1055 {
1056   CAM_Application* app = camStudy ? dynamic_cast<CAM_Application*>( camStudy->application() ) : 0;
1057   if( !app )
1058     return;
1059
1060   CAM_DataModel* prev = 0;
1061   CAM_Application::ModuleList mods = app->modules();
1062   for( QList<CAM_Module*>::const_iterator it = mods.begin(); it != mods.end(); ++it )
1063   {
1064     CAM_DataModel* dm = (*it)->dataModel();
1065     if( (*it) == this && !camStudy->containsDataModel( dm ) )
1066     {
1067       if ( prev )
1068         camStudy->insertDataModel( (*it)->dataModel(), prev );
1069       else
1070         camStudy->insertDataModel( (*it)->dataModel(), 0 );
1071     }
1072     prev = dm;
1073   }
1074 }
1075
1076 /*!
1077   \fn void CAM_Module::contextMenuPopup( const QString& type, QMenu* menu, QString& title );
1078   \brief Create context popup menu.
1079   \param type popup menu context
1080   \param menu popup menu
1081   \param title popup menu title, which can be set by the module if required
1082 */
1083
1084 /*!
1085   \fn void CAM_Module::updateCommandsStatus();
1086   \brief Update menu/toolbar actions.
1087 */