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