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