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