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