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