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