Salome HOME
Issue #2490: Place toolbars into 3 rows by default
[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.toolBar,
475                     theInfo.id,
476                     theInfo.text,
477                     //Issue #650: in the SALOME mode the tooltip should be same as text
478                     theInfo.text,
479                     theInfo.icon,
480                     theInfo.shortcut,
481                     theInfo.checkable,
482                     isAddSeparator,
483                     theInfo.toolTip);
484 }
485
486 //******************************************************
487 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
488                                const QString& theId, const QString& theTitle, const QString& theTip,
489                                const QIcon& theIcon, const QKeySequence& theKeys,
490                                bool isCheckable, const bool isAddSeparator,
491                                const QString& theStatusTip)
492 {
493   static QString aLastTool = "";
494   static int aNb = 0;
495   if (aLastTool.isEmpty())
496     aLastTool = theWBName;
497   else if (theWBName != aLastTool) {
498     aLastTool = theWBName;
499     if (aNb > 20) {
500       desktop()->addToolBarBreak();
501       aNb = 0;
502     }
503   }
504   aNb++;
505
506   int aId = myActionsList.size();
507   myActionsList.append(theId);
508   SUIT_Desktop* aDesk = application()->desktop();
509   int aKeys = 0;
510   for (int i = 0; i < theKeys.count(); i++)
511     aKeys += theKeys[i];
512   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
513                                   isCheckable);
514   aAction->setStatusTip(theStatusTip);
515
516   aAction->setData(theId);
517
518   int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
519   int aItemId = createMenu(aId, aWBMenu);
520   if (isAddSeparator)
521     createMenu(separator(), aWBMenu);
522
523   int aWBTool = createTool(theTBName, theTBName);
524   int aToolId = createTool(aId, aWBTool);
525   if (isAddSeparator)
526     createTool(separator(), aWBTool);
527
528   return aAction;
529 }
530
531 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
532 {
533   return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
534 }
535
536 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
537                                        const ActionInfo& theInfo,
538                                        const QList<QAction*>& theNestedActions)
539 {
540   myActionsList.append(theInfo.id);
541   SUIT_Desktop* aDesk = application()->desktop();
542   SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
543   anAction->setData(theInfo.id);
544   anAction->setCheckable(theInfo.checkable);
545   anAction->setChecked(theInfo.checked);
546   anAction->setEnabled(theInfo.enabled);
547   anAction->setVisible(theInfo.visible);
548   anAction->setIcon(theInfo.icon);
549   anAction->setText(theInfo.text);
550   anAction->setToolTip(theInfo.toolTip);
551   anAction->setShortcut(theInfo.shortcut);
552   anAction->setFont(theInfo.font);
553
554   int aWBMenu = createMenu(theWBName, -1, -1, 30);
555   int aItemId = createMenu(anAction, aWBMenu);
556   createMenu(separator(), aWBMenu); /// nested action is always separated of others
557
558   int aWBTool = createTool(theWBName, theWBName);
559   int aToolId = createTool(anAction, aWBTool);
560   createTool(separator(), aWBTool); /// nested action is always separated of others
561
562   return anAction;
563 }
564
565
566 //******************************************************
567 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
568                                            const QString& theTip, const QIcon& theIcon,
569                                            const QKeySequence& theKeys, bool isCheckable,
570                                            const char* theMenuSourceText, const int theMenuPosition)
571 {
572   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
573
574   int aId = myActionsList.size();
575   myActionsList.append(theId);
576   SUIT_Desktop* aDesk = application()->desktop();
577   int aKeys = 0;
578   for (int i = 0; i < theKeys.count(); i++)
579     aKeys += theKeys[i];
580   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
581                                   isCheckable);
582   aAction->setStatusTip(theTip);
583   aAction->setData(theId);
584   createMenu(aId, aMenu, theMenuPosition);
585   return aAction;
586 }
587
588 //******************************************************
589 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
590 {
591   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
592   createMenu(separator(), aMenu, -1, theMenuPosition);
593 }
594
595 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
596 {
597   if( !theAction )
598     return false;
599
600   SUIT_Desktop* aDesktop = application()->desktop();
601   if( !aDesktop )
602     return false;
603
604   QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
605   if( !aToolMgr )
606     return false;
607
608   aToolMgr->append( theAction, theToolBarTitle );
609   return true;
610 }
611
612 //******************************************************
613 QList<QAction*> SHAPERGUI::commandList() const
614 {
615   QList<QAction*> aActions;
616   for (int i = 0; i < myActionsList.size(); i++) {
617     QAction* aCmd = action(i);
618     if (aCmd && myActionsList.contains(aCmd->data().toString()))
619       aActions.append(aCmd);
620   }
621
622   return aActions;
623 }
624
625 //******************************************************
626 QMainWindow* SHAPERGUI::desktop() const
627 {
628   return application()->desktop();
629 }
630
631 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
632                                const std::shared_ptr<Config_FeatureMessage>& theMessage)
633 {
634   myFeaturesInfo.insert(theFeatureId, theMessage);
635 }
636
637 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
638 {
639   std::shared_ptr<Config_FeatureMessage> aMessage;
640   if (myFeaturesInfo.contains(theFeatureId))
641     aMessage =  myFeaturesInfo[theFeatureId];
642   return aMessage;
643 }
644
645 //******************************************************
646 void SHAPERGUI::selectionChanged()
647 {
648   LightApp_Module::selectionChanged();
649   myWorkshop->salomeViewerSelectionChanged();
650 }
651
652 //******************************************************
653 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
654 {
655   myWorkshop->contextMenuMgr()->updateViewerMenu();
656   myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
657   LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
658 }
659
660
661 //******************************************************
662 void SHAPERGUI::createPreferences()
663 {
664   LightApp_Preferences* pref = preferences();
665   if (!pref)
666     return;
667   ModuleBase_Preferences::updateConfigByResources();
668   QString aModName = moduleName();
669
670   QtxPreferenceItem* item = pref->findItem(aModName, true );
671   if ( item && (!item->isEmpty() )) {
672     item->parentItem()->removeItem(item);
673     delete item;
674   }
675
676   int catId = pref->addPreference(aModName, -1 );
677   if ( catId == -1 )
678     return;
679   SHAPERGUI_PrefMgr aMgr(pref, aModName);
680   ModuleBase_Preferences::createEditContent(&aMgr, catId);
681
682   int viewTab = pref->addItem(tr("Viewer"), catId);
683   // Create other parameters group in viewer tab
684   int otherGroup = pref->addItem(tr("Default selection"), viewTab);
685   pref->setItemProperty("columns", 3, otherGroup);
686   pref->addItem(tr("Faces"), otherGroup,
687                          SUIT_PreferenceMgr::Bool,
688                          ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
689   pref->addItem(tr("Edges"), otherGroup,
690                          SUIT_PreferenceMgr::Bool,
691                          ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
692   pref->addItem(tr("Vertices"), otherGroup,
693                          SUIT_PreferenceMgr::Bool,
694                          ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
695
696   int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
697   pref->setItemProperty("columns", 2, sensitivityGroup);
698   pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
699                 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
700   pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
701                 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
702   pref->retrieve();
703 }
704
705 //******************************************************
706 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
707 {
708   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
709   QString aVal = aResMgr->stringValue(theSection, theParam);
710   Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
711                                                     theParam.toStdString());
712   std::string aValue = aVal.toStdString();
713   if (aValue.empty()) {
714     aValue = aProp->defaultValue();
715     aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
716
717     LightApp_Preferences* pref = preferences();
718     if (pref)
719       pref->retrieve();
720   }
721   aProp->setValue(aValue);
722
723   myWorkshop->displayer()->redisplayObjects();
724 }
725
726 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
727 {
728   application()->putInfo(theInfo, theMSecs);
729 }
730
731 bool SHAPERGUI::abortAllOperations()
732 {
733   return workshop()->operationMgr()->abortAllOperations();
734 }
735
736 void SHAPERGUI::createFeatureActions()
737 {
738   myWorkshop->menuMgr()->createFeatureActions();
739 }