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