Salome HOME
Issue #2582: Show/Hide inspection panel on activate/deactivate SHAPER module.
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "SHAPERGUI.h"
22 #include "SHAPERGUI_DataModel.h"
23 #include "SHAPERGUI_OCCSelector.h"
24 #include <SHAPERGUI_NestedButton.h>
25
26 #include <XGUI_Workshop.h>
27 #include <XGUI_PropertyPanel.h>
28 #include <XGUI_ContextMenuMgr.h>
29 #include <XGUI_ObjectsBrowser.h>
30 #include <XGUI_OperationMgr.h>
31 #include <XGUI_Displayer.h>
32 #include <XGUI_MenuMgr.h>
33 #include <XGUI_FacesPanel.h>
34 #include <XGUI_SelectionActivate.h>
35
36 #include <ModuleBase_Operation.h>
37 #include <ModuleBase_Preferences.h>
38 #include <ModuleBase_ActionInfo.h>
39 #include <ModuleBase_IModule.h>
40
41 #include <LightApp_Application.h>
42 #include <LightApp_SelectionMgr.h>
43 #include <LightApp_OCCSelector.h>
44 #include <LightApp_Study.h>
45 #include <OCCViewer_ViewModel.h>
46
47 #include <SUIT_Selector.h>
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ViewManager.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_DataBrowser.h>
52
53 #include <QtxPopupMgr.h>
54 #include <QtxActionMenuMgr.h>
55 #include <QtxActionToolMgr.h>
56 #include <QtxResourceMgr.h>
57
58 #include <Config_PropManager.h>
59 #include <Config_ModuleReader.h>
60
61 #include <AIS_ListOfInteractive.hxx>
62 #include <AIS_ListIteratorOfListOfInteractive.hxx>
63
64 #include <QDockWidget>
65 #include <QAction>
66 #include <QTimer>
67 #include <QMenu>
68
69 #define SALOME_PATCH_FOR_CTRL_WHEEL
70
71 extern "C" {
72 SHAPERGUI_EXPORT CAM_Module* createModule()
73 {
74   return new SHAPERGUI();
75 }
76
77 SHAPERGUI_EXPORT char* getModuleVersion()
78 {
79   return (char*)"0.0";
80 }
81 } // extern "C"
82
83 /** 
84 * Class for preferences management
85 */
86 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
87 {
88 public:
89   /// Constructor
90   /// \param theMgr preferences manager of SALOME
91   /// \param theModName name of the module
92   SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
93     myMgr(theMgr), myModName(theModName) {}
94
95   virtual int addPreference(const QString& theLbl, int pId,
96                             SUIT_PreferenceMgr::PrefItemType theType,
97                             const QString& theSection, const QString& theName )
98   {
99     return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
100   }
101
102   virtual void setItemProperty(const QString& thePropName,
103                                const QVariant& theValue,
104                                const int theId = -1)
105   {
106     myMgr->setItemProperty(thePropName, theValue, theId);
107   }
108
109
110   virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
111
112 private:
113   LightApp_Preferences* myMgr;
114   QString myModName;
115 };
116
117
118
119
120 //******************************************************
121 SHAPERGUI::SHAPERGUI()
122     : LightApp_Module("SHAPER"),
123       mySelector(0), myIsOpened(0), myPopupMgr(0)
124 {
125   myWorkshop = new XGUI_Workshop(this);
126   connect(myWorkshop, SIGNAL(commandStatusUpdated()),
127           this, SLOT(onUpdateCommandStatus()));
128
129   myProxyViewer = new SHAPERGUI_SalomeViewer(this);
130
131   ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
132   ModuleBase_Preferences::loadCustomProps();
133 }
134
135 //******************************************************
136 SHAPERGUI::~SHAPERGUI()
137 {
138 }
139
140 //******************************************************
141 void SHAPERGUI::initialize(CAM_Application* theApp)
142 {
143   LightApp_Module::initialize(theApp);
144
145   myWorkshop->startApplication();
146   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
147   if (anApp)
148   {
149     connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
150   }
151 }
152
153 //******************************************************
154 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
155 {
156   theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
157 }
158
159 //******************************************************
160 void SHAPERGUI::viewManagers(QStringList& theList) const
161 {
162   theList.append(OCCViewer_Viewer::Type());
163 }
164
165 //******************************************************
166 // We can not create selector in this method because it can be called when
167 // SHAPER module is not active. Take into account that creation of our selector
168 // leads to switching OFF all other selectors
169 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
170 //{
171 //  // if there are created viewer managers, we should try to create viewer
172 //  // selector and initialize viewer with it. It sets interactive contect to the
173 //  // proxy viewer. If study is opened, CAM application calls this method before the open()
174 //  // of data model
175 //  // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
176 //  // we need to connect to the viewer before it. Here,
177 //  // it seems the most appropriate place for this
178 //  // according to SALOME architecture.
179 //  if (!mySelector) {
180 //    ViewManagerList OCCViewManagers;
181 //    application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
182 //    if (OCCViewManagers.size() > 0) {
183 //      mySelector = createSelector(OCCViewManagers.first());
184 //    }
185 //  }
186 //  LightApp_Module::connectToStudy(theStudy);
187 //}
188
189 //******************************************************
190 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
191 {
192   bool isDone = LightApp_Module::activateModule(theStudy);
193   SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
194   aDataModel->initRootObject();
195
196   if (isDone) {
197     setMenuShown(true);
198     setToolShown(true);
199
200     QObject* aObj = myWorkshop->objectBrowser()->parent();
201     QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
202     if (aObjDoc) {
203       QAction* aViewAct = aObjDoc->toggleViewAction();
204       aViewAct->setEnabled(true);
205       myWorkshop->objectBrowser()->setVisible(true);
206       aObjDoc->setVisible(true);
207       desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
208     }
209
210     DockWidget* aInspection = myWorkshop->inspectionPanel();
211     if (aInspection) {
212       QAction* aViewAct = aInspection->toggleViewAction();
213       aViewAct->setEnabled(true);
214       aInspection->setVisible(true);
215     }
216
217     if (!mySelector) {
218       ViewManagerList OCCViewManagers;
219       application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
220       if (OCCViewManagers.size() > 0) {
221         mySelector = createSelector(OCCViewManagers.first());
222       }
223     }
224     // it should be pefromed after the selector creation in order to have AISContext
225     myWorkshop->activateModule();
226     //action(myEraseAll)->setEnabled(false);
227
228     if (myIsOpened) {
229       myWorkshop->objectBrowser()->rebuildDataTree();
230       myWorkshop->updateCommandStatus();
231       myIsOpened = false;
232     }
233     else
234       myWorkshop->updateCommandStatus();
235   }
236   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
237   myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
238   myIsEditEnabled = getApp()->isEditEnabled();
239   getApp()->setEditEnabled(false);
240
241   // this following row is caused by #187 bug.
242   // SALOME saves the dock widget positions before deactivateModule() and
243   // load it after the module activation. So, if the panel is visible before
244   // deactivate, it becomes visible after activate.
245   // In order to avoid the visible property panel, the widget position save is
246   // switch off in this module
247   aResMgr->setValue("Study", "store_positions", false);
248
249   // Synchronize displayed objects
250   Handle(AIS_InteractiveContext) aContext;
251   if (mySelector && mySelector->viewer())
252     aContext = mySelector->viewer()->getAISContext();
253
254   if (!aContext.IsNull()) {
255     XGUI_Displayer* aDisp = myWorkshop->displayer();
256     QObjectPtrList aObjList = aDisp->displayedObjects();
257
258     AIS_ListOfInteractive aList;
259     aContext->DisplayedObjects(aList);
260     AIS_ListIteratorOfListOfInteractive aLIt;
261     Handle(AIS_InteractiveObject) anAISIO;
262     foreach (ObjectPtr aObj, aObjList) {
263       AISObjectPtr aPrs = aDisp->getAISObject(aObj);
264       Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
265       bool aFound = false;
266       for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
267         anAISIO = aLIt.Value();
268         if (anAISIO.get() == aAIS.get()) {
269           aFound = true;
270           break;
271         }
272       }
273       if (!aFound) {
274         aObj->setDisplayed(false);
275         //aDisp->erase(aObj, false);
276       }
277     }
278     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
279   }
280   myProxyViewer->activateViewer(true);
281
282   // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
283   connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
284           this, SLOT(onScriptLoaded()));
285
286   disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
287              getApp(), SLOT(onSaveDoc()));
288   disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
289              getApp(), SLOT(onSaveAsDoc()));
290
291   connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
292           this, SLOT(onSaveDocByShaper()));
293   connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
294           this, SLOT(onSaveAsDocByShaper()));
295
296   return isDone;
297 }
298
299 //******************************************************
300 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
301 {
302   myProxyViewer->activateViewer(false);
303   setMenuShown(false);
304   setToolShown(false);
305
306   myWorkshop->deactivateModule();
307
308   QObject* aObj = myWorkshop->objectBrowser()->parent();
309   QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
310   if (aObjDoc) {
311     aObjDoc->setVisible(false);
312     myWorkshop->objectBrowser()->setVisible(false);
313     QAction* aViewAct = aObjDoc->toggleViewAction();
314     aViewAct->setEnabled(false);
315   }
316   DockWidget* aInspection = myWorkshop->inspectionPanel();
317   if (aInspection) {
318     aInspection->setVisible(false);
319     QAction* aViewAct = aInspection->toggleViewAction();
320     aViewAct->setEnabled(false);
321   }
322
323   // the active operation should be stopped for the next activation.
324   // There should not be active operation and visualized preview.
325   // Abort operation should be performed before the selection's remove
326   // because the displayed objects should be removed from the viewer, but
327   // the AIS context is obtained from the selector.
328   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
329   while (anOperation) {
330     anOperation->abort();
331     anOperation = myWorkshop->operationMgr()->currentOperation();
332   }
333   // Delete selector because it has to be redefined on next activation
334   if (mySelector) {
335     myProxyViewer->setSelector(0);
336     delete mySelector;
337     mySelector = 0;
338   }
339
340   myWorkshop->hidePanel(myWorkshop->facesPanel());
341   //myWorkshop->contextMenuMgr()->disconnectViewer();
342
343   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
344   aResMgr->setValue("Study", "store_positions", myIsStorePositions);
345   getApp()->setEditEnabled(myIsEditEnabled);
346
347   // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
348   disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
349              this, SLOT(onScriptLoaded()));
350
351   disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
352              this, SLOT(onSaveDocByShaper()));
353   disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
354              this, SLOT(onSaveAsDocByShaper()));
355
356   connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
357           getApp(), SLOT(onSaveDoc()));
358   connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
359           getApp(), SLOT(onSaveAsDoc()));
360
361
362   return LightApp_Module::deactivateModule(theStudy);
363 }
364
365 //******************************************************
366 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
367 {
368   if (!mySelector) {
369     mySelector = createSelector(theMgr);
370     myWorkshop->selectionActivate()->updateSelectionFilters();
371     myWorkshop->selectionActivate()->updateSelectionModes();
372     myWorkshop->synchronizeViewer();
373   }
374 }
375
376 //******************************************************
377 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
378 {
379   if (mySelector) {
380     if (theMgr->getType() == OCCViewer_Viewer::Type()) {
381       OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
382       if (mySelector->viewer() == aViewer) {
383         XGUI_Displayer* aDisp = myWorkshop->displayer();
384         QObjectPtrList aObjects = aDisp->displayedObjects();
385         foreach(ObjectPtr aObj, aObjects)
386           aObj->setDisplayed(false);
387         Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
388         myProxyViewer->setSelector(0);
389         delete mySelector;
390         mySelector = 0;
391
392         myWorkshop->module()->clearViewer();
393       }
394     }
395   }
396 }
397
398 //******************************************************
399 QtxPopupMgr* SHAPERGUI::popupMgr()
400 {
401   if (!myPopupMgr)
402     myPopupMgr = new QtxPopupMgr( 0, this );
403   return myPopupMgr;
404 }
405
406 //******************************************************
407 void SHAPERGUI::onDefaultPreferences()
408 {
409   // reset main resources
410   ModuleBase_Preferences::resetResourcePreferences(preferences());
411   // reset plugin's resources
412   ModuleBase_Preferences::resetConfigPropPreferences(preferences());
413
414   myWorkshop->displayer()->redisplayObjects();
415 }
416
417 //******************************************************
418 void SHAPERGUI::onScriptLoaded()
419 {
420   // this slot is called after processing of the LoadScriptId action of SalomeApp Application
421   // Each dumped script contains updateObjBrowser() that creates a new instance of Object
422   // Browser. When SHAPER module is active, this browser should not be used. It might be removed
423   // as hidden by means of updateWindows() of SalomeApp_Application or to remove
424   // it manually (because this method of application is protected)
425   SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
426   if (aBrowser)
427     delete aBrowser;
428 }
429
430 //******************************************************
431 void SHAPERGUI::onSaveDocByShaper()
432 {
433   if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
434     return;
435
436   getApp()->onSaveDoc();
437 }
438
439 //******************************************************
440 void SHAPERGUI::onSaveAsDocByShaper()
441 {
442   if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
443     return;
444
445   getApp()->onSaveAsDoc();
446 }
447
448 //******************************************************
449 void SHAPERGUI::onUpdateCommandStatus()
450 {
451   getApp()->updateActions();
452 }
453
454 //******************************************************
455 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
456 {
457   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
458     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
459     SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
460                                                                  getApp()->selectionMgr());
461 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
462     aViewer->setUseLocalSelection(true);
463 #endif
464     LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
465     QList<SUIT_Selector*> aList;
466     aMgr->selectors(aList);
467     foreach(SUIT_Selector* aSel, aList)
468     {
469       aSel->setEnabled(aSel == aSelector);
470     }
471     myProxyViewer->setSelector(aSelector);
472     return aSelector;
473   }
474   return 0;
475 }
476
477 //******************************************************
478 CAM_DataModel* SHAPERGUI::createDataModel()
479 {
480   return new SHAPERGUI_DataModel(this);
481 }
482
483 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
484                                const bool isAddSeparator)
485 {
486   return addFeature(theWBName,
487                     theInfo.toolBar,
488                     theInfo.id,
489                     theInfo.text,
490                     //Issue #650: in the SALOME mode the tooltip should be same as text
491                     theInfo.text,
492                     theInfo.icon,
493                     theInfo.shortcut,
494                     theInfo.checkable,
495                     isAddSeparator,
496                     theInfo.toolTip);
497 }
498
499 //******************************************************
500 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
501                                const QString& theId, const QString& theTitle, const QString& theTip,
502                                const QIcon& theIcon, const QKeySequence& theKeys,
503                                bool isCheckable, const bool isAddSeparator,
504                                const QString& theStatusTip)
505 {
506   static QString aLastTool = "";
507   static int aNb = 0;
508   if (aLastTool.isEmpty())
509     aLastTool = theWBName;
510   else if (theWBName != aLastTool) {
511     aLastTool = theWBName;
512     if (aNb > 20) {
513       desktop()->addToolBarBreak();
514       aNb = 0;
515     }
516   }
517   aNb++;
518
519   int aId = myActionsList.size();
520   myActionsList.append(theId);
521   SUIT_Desktop* aDesk = application()->desktop();
522   int aKeys = 0;
523   for (int i = 0; i < theKeys.count(); i++)
524     aKeys += theKeys[i];
525   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
526                                   isCheckable);
527   aAction->setStatusTip(theStatusTip);
528
529   aAction->setData(theId);
530
531   int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
532   int aItemId = createMenu(aId, aWBMenu);
533   if (isAddSeparator)
534     createMenu(separator(), aWBMenu);
535
536   int aWBTool = createTool(theTBName, theTBName);
537   int aToolId = createTool(aId, aWBTool);
538   if (isAddSeparator)
539     createTool(separator(), aWBTool);
540
541   return aAction;
542 }
543
544 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
545 {
546   return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
547 }
548
549 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
550                                        const ActionInfo& theInfo,
551                                        const QList<QAction*>& theNestedActions)
552 {
553   myActionsList.append(theInfo.id);
554   SUIT_Desktop* aDesk = application()->desktop();
555   SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
556   anAction->setData(theInfo.id);
557   anAction->setCheckable(theInfo.checkable);
558   anAction->setChecked(theInfo.checked);
559   anAction->setEnabled(theInfo.enabled);
560   anAction->setVisible(theInfo.visible);
561   anAction->setIcon(theInfo.icon);
562   anAction->setText(theInfo.text);
563   anAction->setToolTip(theInfo.toolTip);
564   anAction->setShortcut(theInfo.shortcut);
565   anAction->setFont(theInfo.font);
566
567   int aWBMenu = createMenu(theWBName, -1, -1, 30);
568   int aItemId = createMenu(anAction, aWBMenu);
569   createMenu(separator(), aWBMenu); /// nested action is always separated of others
570
571   int aWBTool = createTool(theWBName, theWBName);
572   int aToolId = createTool(anAction, aWBTool);
573   createTool(separator(), aWBTool); /// nested action is always separated of others
574
575   return anAction;
576 }
577
578
579 //******************************************************
580 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
581                                            const QString& theTip, const QIcon& theIcon,
582                                            const QKeySequence& theKeys, bool isCheckable,
583                                            const char* theMenuSourceText, const int theMenuPosition)
584 {
585   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
586
587   int aId = myActionsList.size();
588   myActionsList.append(theId);
589   SUIT_Desktop* aDesk = application()->desktop();
590   int aKeys = 0;
591   for (int i = 0; i < theKeys.count(); i++)
592     aKeys += theKeys[i];
593   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
594                                   isCheckable);
595   aAction->setStatusTip(theTip);
596   aAction->setData(theId);
597   createMenu(aId, aMenu, theMenuPosition);
598   return aAction;
599 }
600
601 //******************************************************
602 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
603 {
604   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
605   createMenu(separator(), aMenu, -1, theMenuPosition);
606 }
607
608 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
609 {
610   if( !theAction )
611     return false;
612
613   SUIT_Desktop* aDesktop = application()->desktop();
614   if( !aDesktop )
615     return false;
616
617   QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
618   if( !aToolMgr )
619     return false;
620
621   aToolMgr->append( theAction, theToolBarTitle );
622   return true;
623 }
624
625 //******************************************************
626 QList<QAction*> SHAPERGUI::commandList() const
627 {
628   QList<QAction*> aActions;
629   for (int i = 0; i < myActionsList.size(); i++) {
630     QAction* aCmd = action(i);
631     if (aCmd && myActionsList.contains(aCmd->data().toString()))
632       aActions.append(aCmd);
633   }
634
635   return aActions;
636 }
637
638 //******************************************************
639 QMainWindow* SHAPERGUI::desktop() const
640 {
641   return application()->desktop();
642 }
643
644 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
645                                const std::shared_ptr<Config_FeatureMessage>& theMessage)
646 {
647   myFeaturesInfo.insert(theFeatureId, theMessage);
648 }
649
650 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
651 {
652   std::shared_ptr<Config_FeatureMessage> aMessage;
653   if (myFeaturesInfo.contains(theFeatureId))
654     aMessage =  myFeaturesInfo[theFeatureId];
655   return aMessage;
656 }
657
658 //******************************************************
659 void SHAPERGUI::selectionChanged()
660 {
661   LightApp_Module::selectionChanged();
662   myWorkshop->salomeViewerSelectionChanged();
663 }
664
665 //******************************************************
666 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
667 {
668   myWorkshop->contextMenuMgr()->updateViewerMenu();
669   myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
670   LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
671 }
672
673
674 //******************************************************
675 void SHAPERGUI::createPreferences()
676 {
677   LightApp_Preferences* pref = preferences();
678   if (!pref)
679     return;
680   ModuleBase_Preferences::updateConfigByResources();
681   QString aModName = moduleName();
682
683   QtxPreferenceItem* item = pref->findItem(aModName, true );
684   if ( item && (!item->isEmpty() )) {
685     item->parentItem()->removeItem(item);
686     delete item;
687   }
688
689   int catId = pref->addPreference(aModName, -1 );
690   if ( catId == -1 )
691     return;
692   SHAPERGUI_PrefMgr aMgr(pref, aModName);
693   ModuleBase_Preferences::createEditContent(&aMgr, catId);
694
695   int viewTab = pref->addItem(tr("Viewer"), catId);
696   // Create other parameters group in viewer tab
697   int otherGroup = pref->addItem(tr("Default selection"), viewTab);
698   pref->setItemProperty("columns", 3, otherGroup);
699   pref->addItem(tr("Faces"), otherGroup,
700                          SUIT_PreferenceMgr::Bool,
701                          ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
702   pref->addItem(tr("Edges"), otherGroup,
703                          SUIT_PreferenceMgr::Bool,
704                          ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
705   pref->addItem(tr("Vertices"), otherGroup,
706                          SUIT_PreferenceMgr::Bool,
707                          ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
708
709   int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
710   pref->setItemProperty("columns", 2, sensitivityGroup);
711   pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
712                 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
713   pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
714                 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
715   pref->retrieve();
716 }
717
718 //******************************************************
719 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
720 {
721   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
722   QString aVal = aResMgr->stringValue(theSection, theParam);
723   Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
724                                                     theParam.toStdString());
725   std::string aValue = aVal.toStdString();
726   if (aValue.empty()) {
727     aValue = aProp->defaultValue();
728     aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
729
730     LightApp_Preferences* pref = preferences();
731     if (pref)
732       pref->retrieve();
733   }
734   aProp->setValue(aValue);
735
736   myWorkshop->displayer()->redisplayObjects();
737 }
738
739 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
740 {
741   application()->putInfo(theInfo, theMSecs);
742 }
743
744 bool SHAPERGUI::abortAllOperations()
745 {
746   return workshop()->operationMgr()->abortAllOperations();
747 }
748
749 void SHAPERGUI::createFeatureActions()
750 {
751   myWorkshop->menuMgr()->createFeatureActions();
752 }