Salome HOME
bos #19879 [CEA] SHAPER build failure: missing method setUseLocalSelection
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI.cpp
1 // Copyright (C) 2014-2020  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "SHAPERGUI.h"
21 #include "SHAPERGUI_DataModel.h"
22 #include "SHAPERGUI_OCCSelector.h"
23 #include "SHAPERGUI_NestedButton.h"
24 #include "SHAPERGUI_ToolbarsMgr.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 #include <XGUI_ViewerProxy.h>
37
38 #include <ModuleBase_Operation.h>
39 #include <ModuleBase_Preferences.h>
40 #include <ModuleBase_ActionInfo.h>
41 #include <ModuleBase_IModule.h>
42
43 #include <ModelAPI_Tools.h>
44
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_OCCSelector.h>
48 #include <LightApp_Study.h>
49
50 #include <OCCViewer_ViewModel.h>
51 #include <OCCViewer_ViewPort3d.h>
52
53 #include <SUIT_Selector.h>
54 #include <SUIT_Desktop.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_ViewWindow.h>
57 #include <SUIT_ResourceMgr.h>
58 #include <SUIT_DataBrowser.h>
59
60 #include <QtxPopupMgr.h>
61 #include <QtxActionMenuMgr.h>
62 #include <QtxActionToolMgr.h>
63 #include <QtxResourceMgr.h>
64
65 #include <Config_PropManager.h>
66 #include <Config_ModuleReader.h>
67
68 #include <AIS_ListOfInteractive.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <Standard_Version.hxx>
71
72 #include <QDockWidget>
73 #include <QAction>
74 #include <QTimer>
75 #include <QMenu>
76 #include <QToolBar>
77
78 #include <ModelAPI_Session.h>
79
80 #if OCC_VERSION_HEX < 0x070400
81   #define SALOME_PATCH_FOR_CTRL_WHEEL
82 #endif
83
84 extern "C" {
85 SHAPERGUI_EXPORT CAM_Module* createModule()
86 {
87   return new SHAPERGUI();
88 }
89
90 SHAPERGUI_EXPORT char* getModuleVersion()
91 {
92   return (char*)"0.0";
93 }
94 } // extern "C"
95
96
97 static const QString ToolbarsSection("SHAPER_Toolbars");
98 static const QString FreeCommandsParam("OutOFToolbars");
99
100
101 /** 
102 * Class for preferences management
103 */
104 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
105 {
106 public:
107   /// Constructor
108   /// \param theMgr preferences manager of SALOME
109   /// \param theModName name of the module
110   SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
111     myMgr(theMgr), myModName(theModName) {}
112
113   virtual int addPreference(const QString& theLbl, int pId,
114                             SUIT_PreferenceMgr::PrefItemType theType,
115                             const QString& theSection, const QString& theName )
116   {
117     return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
118   }
119
120   virtual void setItemProperty(const QString& thePropName,
121                                const QVariant& theValue,
122                                const int theId = -1)
123   {
124     myMgr->setItemProperty(thePropName, theValue, theId);
125   }
126
127
128   virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
129
130 private:
131   LightApp_Preferences* myMgr;
132   QString myModName;
133 };
134
135
136
137
138 //******************************************************
139 SHAPERGUI::SHAPERGUI()
140     : LightApp_Module("SHAPER"),
141       mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
142   myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
143   myAxisArrowRate(-1)
144 {
145   myWorkshop = new XGUI_Workshop(this);
146   connect(myWorkshop, SIGNAL(commandStatusUpdated()),
147           this, SLOT(onUpdateCommandStatus()));
148
149   myProxyViewer = new SHAPERGUI_SalomeViewer(this);
150
151   ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
152
153   // It will be called in XGUI_Workshop::startApplication
154   // ModuleBase_Preferences::loadCustomProps();
155 }
156
157 //******************************************************
158 SHAPERGUI::~SHAPERGUI()
159 {
160   delete myWorkshop;
161   delete myProxyViewer;
162 }
163
164 //******************************************************
165 void SHAPERGUI::initialize(CAM_Application* theApp)
166 {
167   LightApp_Module::initialize(theApp);
168
169   myWorkshop->startApplication();
170   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
171   if (anApp)
172   {
173     connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
174   }
175
176   int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
177   int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
178
179   int aId = getNextCommandId();
180   myActionsList.append(aId);
181   SUIT_Desktop* aDesk = application()->desktop();
182   QString aTip = tr("Show inspection window");
183   myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
184     aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
185   myWhatIsAction->setStatusTip(aTip);
186   myWhatIsAction->setData("INSPECTION_CMD");
187   createMenu(aId, aSubMenu, 0);
188
189   QString aToolName = tr("Inspection");
190   int aTool = createTool(aToolName);
191 #ifdef _DEBUG
192   int aToolId =
193 #endif
194     createTool(myWhatIsAction, aTool);
195   registerCommandToolbar(aToolName, aId);
196
197   // Define Edit toolbars command
198   aId = getNextCommandId();
199   //myActionsList.append(aId); Do not use it for editing of toolbars
200   aTip = tr("Edit toolbars of the module");
201 #ifdef _DEBUG
202   QAction* aAction =
203 #endif
204     createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
205     tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
206   int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
207 #ifdef _DEBUG
208   int aEditItem =
209 #endif
210     createMenu(aId, aEditMenu);
211
212   if (!myInspectionPanel) {
213     myInspectionPanel = myWorkshop->inspectionPanel();
214     connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
215       this, SLOT(onWhatIs(bool)));
216   }
217   hideInternalWindows();
218
219   // Initialize viewer proxy if OCC viewer is already exist
220   ViewManagerList aOCCViewManagers;
221   application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
222   if (aOCCViewManagers.size() > 0) {
223     SUIT_ViewManager* aMgr = aOCCViewManagers.first();
224     SUIT_ViewWindow* aWnd = aMgr->getActiveView();
225     if (aWnd) {
226       OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
227       OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
228       if (aViewPort) {
229         XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
230         aViewPort->installEventFilter(aViewer);
231         Handle(V3d_View) aView = aViewPort->getView();
232         aViewer->SetScale(aView, aView->Camera()->Scale());
233         // We can not create selector here because other modules will be deactivated later
234         //onViewManagerAdded(aMgr);
235       }
236     }
237   }
238   SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
239   aDataModel->initRootObject();
240 }
241
242 //******************************************************
243 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
244 {
245   theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
246 }
247
248 //******************************************************
249 void SHAPERGUI::viewManagers(QStringList& theList) const
250 {
251   theList.append(OCCViewer_Viewer::Type());
252 }
253
254 //******************************************************
255 // We can not create selector in this method because it can be called when
256 // SHAPER module is not active. Take into account that creation of our selector
257 // leads to switching OFF all other selectors
258 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
259 //{
260 //  // if there are created viewer managers, we should try to create viewer
261 //  // selector and initialize viewer with it. It sets interactive context to the
262 //  // proxy viewer. If study is opened, CAM application calls this method before the open()
263 //  // of data model
264 //  // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
265 //  // we need to connect to the viewer before it. Here,
266 //  // it seems the most appropriate place for this
267 //  // according to SALOME architecture.
268 //  if (!mySelector) {
269 //    ViewManagerList OCCViewManagers;
270 //    application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
271 //    if (OCCViewManagers.size() > 0) {
272 //      mySelector = createSelector(OCCViewManagers.first());
273 //    }
274 //  }
275 //  LightApp_Module::connectToStudy(theStudy);
276 //}
277
278 //******************************************************
279 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
280 {
281   ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet
282
283   // this must be done in the initialization and in activation (on the second activation
284   // initialization in not called, so SComponent must be added anyway
285   SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
286   aDataModel->initRootObject();
287
288
289   bool isDone = LightApp_Module::activateModule(theStudy);
290   loadToolbarsConfig();
291
292   if (isDone) {
293     setMenuShown(true);
294     setToolShown(true);
295
296     QObject* aObj = myWorkshop->objectBrowser()->parent();
297     QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
298     if (aObjDoc) {
299       myWorkshop->objectBrowser()->setVisible(true);
300       aObjDoc->setVisible(true);
301       desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
302       aObjDoc->toggleViewAction()->setVisible(true);
303     }
304
305     myInspectionPanel->toggleViewAction()->setVisible(true);
306
307     myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
308     if (myIsFacesPanelVisible)
309       myWorkshop->facesPanel()->show();
310     myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
311
312     if (!mySelector) {
313       ViewManagerList OCCViewManagers;
314       application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
315       if (OCCViewManagers.size() > 0) {
316         onViewManagerAdded(OCCViewManagers.first());
317       }
318     }
319     // it should be performed after the selector creation in order to have AISContext
320     myWorkshop->activateModule();
321     //action(myEraseAll)->setEnabled(false);
322
323     if (myIsOpened) {
324       myWorkshop->objectBrowser()->rebuildDataTree();
325       myWorkshop->updateCommandStatus();
326       myIsOpened = false;
327     }
328     else
329       myWorkshop->updateCommandStatus();
330   }
331   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
332   myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
333   myIsEditEnabled = getApp()->isEditEnabled();
334   getApp()->setEditEnabled(false);
335
336   // this following row is caused by #187 bug.
337   // SALOME saves the dock widget positions before deactivateModule() and
338   // load it after the module activation. So, if the panel is visible before
339   // deactivate, it becomes visible after activate.
340   // In order to avoid the visible property panel, the widget position save is
341   // switch off in this module
342   aResMgr->setValue("Study", "store_positions", false);
343
344   // Synchronize displayed objects
345   Handle(AIS_InteractiveContext) aContext;
346   if (mySelector && mySelector->viewer())
347     aContext = mySelector->viewer()->getAISContext();
348
349   if (!aContext.IsNull()) {
350     XGUI_Displayer* aDisp = myWorkshop->displayer();
351     QObjectPtrList aObjList = aDisp->displayedObjects();
352
353     if (myOldSelectionColor.size() == 0)
354       myOldSelectionColor = aDisp->selectionColor();
355
356     AIS_ListOfInteractive aList;
357     aContext->DisplayedObjects(aList);
358     AIS_ListIteratorOfListOfInteractive aLIt;
359     Handle(AIS_InteractiveObject) anAISIO;
360     foreach (ObjectPtr aObj, aObjList) {
361       AISObjectPtr aPrs = aDisp->getAISObject(aObj);
362       Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
363       bool aFound = false;
364       for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
365         anAISIO = aLIt.Value();
366         if (anAISIO.get() == aAIS.get()) {
367           aFound = true;
368           break;
369         }
370       }
371       if (!aFound) {
372         aObj->setDisplayed(false);
373         //aDisp->erase(aObj, false);
374       }
375     }
376     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
377   }
378   myProxyViewer->activateViewer(true);
379
380   // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
381   connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
382           this, SLOT(onScriptLoaded()));
383
384   disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
385              getApp(), SLOT(onSaveDoc()));
386   disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
387              getApp(), SLOT(onSaveAsDoc()));
388
389   connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
390           this, SLOT(onSaveDocByShaper()));
391   connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
392           this, SLOT(onSaveAsDocByShaper()));
393
394   return isDone;
395 }
396
397 //******************************************************
398 void SHAPERGUI::hideInternalWindows()
399 {
400   myProxyViewer->activateViewer(false);
401   setMenuShown(false);
402   setToolShown(false);
403
404   QObject* aObj = myWorkshop->objectBrowser()->parent();
405   QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
406   if (aObjDoc) {
407     aObjDoc->setVisible(false);
408     myWorkshop->objectBrowser()->setVisible(false);
409     aObjDoc->toggleViewAction()->setVisible(false);
410   }
411
412   myInspectionPanel->hide();
413   myInspectionPanel->toggleViewAction()->setVisible(false);
414
415   myWorkshop->facesPanel()->hide();
416   myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
417
418   myWorkshop->propertyPanel()->hide();
419   myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
420
421   myWorkshop->hidePanel(myWorkshop->facesPanel());
422 }
423
424
425 //******************************************************
426 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
427 {
428   saveToolbarsConfig();
429   myWorkshop->deactivateModule();
430
431   myIsInspectionVisible = myInspectionPanel->isVisible();
432   myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
433   hideInternalWindows();
434
435
436   // the active operation should be stopped for the next activation.
437   // There should not be active operation and visualized preview.
438   // Abort operation should be performed before the selection's remove
439   // because the displayed objects should be removed from the viewer, but
440   // the AIS context is obtained from the selector.
441   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
442   while (anOperation) {
443     anOperation->abort();
444     anOperation = myWorkshop->operationMgr()->currentOperation();
445   }
446   // Delete selector because it has to be redefined on next activation
447   if (mySelector) {
448     // Restore size of arrows of trihedron
449     if (myAxisArrowRate > 0) {
450       Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
451       Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
452       aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
453       Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
454       aContext->Redisplay(aTrihedron, false);
455     }
456     myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
457     myProxyViewer->setSelector(0);
458
459     LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
460     QList<SUIT_Selector*> aList;
461     aMgr->selectors(aList);
462     foreach(SUIT_Selector* aSel, aList) {
463       aSel->setEnabled(aSel != mySelector);
464     }
465
466     delete mySelector;
467     mySelector = 0;
468   }
469
470   //myWorkshop->contextMenuMgr()->disconnectViewer();
471
472   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
473   aResMgr->setValue("Study", "store_positions", myIsStorePositions);
474   getApp()->setEditEnabled(myIsEditEnabled);
475
476   myOldSelectionColor.clear();
477
478   // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
479   disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
480              this, SLOT(onScriptLoaded()));
481
482   disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
483              this, SLOT(onSaveDocByShaper()));
484   disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
485              this, SLOT(onSaveAsDocByShaper()));
486
487   connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
488           getApp(), SLOT(onSaveDoc()));
489   connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
490           getApp(), SLOT(onSaveAsDoc()));
491
492   publishToStudy();
493
494   return LightApp_Module::deactivateModule(theStudy);
495 }
496
497 //******************************************************
498 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
499 {
500   if (!mySelector) {
501     mySelector = createSelector(theMgr);
502     myWorkshop->selectionActivate()->updateSelectionFilters();
503     myWorkshop->selectionActivate()->updateSelectionModes();
504     myWorkshop->synchronizeViewer();
505   }
506 }
507
508 //******************************************************
509 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
510 {
511   if (mySelector) {
512     if (theMgr->getType() == OCCViewer_Viewer::Type()) {
513       OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
514       if (mySelector->viewer() == aViewer) {
515         XGUI_Displayer* aDisp = myWorkshop->displayer();
516         QObjectPtrList aObjects = aDisp->displayedObjects();
517         ResultPtr aRes;
518         foreach(ObjectPtr aObj, aObjects) {
519           aObj->setDisplayed(false);
520           aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
521           if (aRes.get()) {
522             while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
523               aRes->setDisplayed(false);
524             }
525           }
526         }
527         Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
528         myProxyViewer->setSelector(0);
529         delete mySelector;
530         mySelector = 0;
531
532         myWorkshop->module()->clearViewer();
533       }
534     }
535   }
536 }
537
538 //******************************************************
539 QtxPopupMgr* SHAPERGUI::popupMgr()
540 {
541   if (!myPopupMgr)
542     myPopupMgr = new QtxPopupMgr( 0, this );
543   return myPopupMgr;
544 }
545
546 //******************************************************
547 void SHAPERGUI::onDefaultPreferences()
548 {
549   // reset main resources
550   ModuleBase_Preferences::resetResourcePreferences(preferences());
551   // reset plugin's resources
552   ModuleBase_Preferences::resetConfigPropPreferences(preferences());
553
554   myWorkshop->displayer()->redisplayObjects();
555 }
556
557 //******************************************************
558 void SHAPERGUI::onScriptLoaded()
559 {
560   // this slot is called after processing of the LoadScriptId action of SalomeApp Application
561   // Each dumped script contains updateObjBrowser() that creates a new instance of Object
562   // Browser. When SHAPER module is active, this browser should not be used. It might be removed
563   // as hidden by means of updateWindows() of SalomeApp_Application or to remove
564   // it manually (because this method of application is protected)
565   SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
566   if (aBrowser)
567     delete aBrowser;
568   myWorkshop->displayer()->updateViewer();
569   myWorkshop->updateCommandStatus();
570 }
571
572 //******************************************************
573 void SHAPERGUI::onSaveDocByShaper()
574 {
575   if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
576     return;
577
578   getApp()->onSaveDoc();
579 }
580
581 //******************************************************
582 void SHAPERGUI::onSaveAsDocByShaper()
583 {
584   if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
585     return;
586
587   getApp()->onSaveAsDoc();
588 }
589
590 //******************************************************
591 void SHAPERGUI::onUpdateCommandStatus()
592 {
593   getApp()->updateActions();
594 }
595
596 //******************************************************
597 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
598 {
599   if (theMgr->getType() == OCCViewer_Viewer::Type()) {
600     OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
601
602     // Remember current length of arrow of axis
603     Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
604     Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
605     myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
606
607     SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
608                                                                  getApp()->selectionMgr());
609 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
610     aViewer->setUseLocalSelection(true);
611 #endif
612     LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
613     QList<SUIT_Selector*> aList;
614     aMgr->selectors(aList);
615     foreach(SUIT_Selector* aSel, aList)
616     {
617       aSel->setEnabled(aSel == aSelector);
618     }
619     myProxyViewer->setSelector(aSelector);
620
621     if (myOldSelectionColor.size() == 0)
622       myOldSelectionColor = myWorkshop->displayer()->selectionColor();
623
624     std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
625     myWorkshop->displayer()->setSelectionColor(aColor);
626
627     // Cause scaling of arrows of axis and dimensions
628     myWorkshop->module()->onViewTransformed();
629
630     return aSelector;
631   }
632   return 0;
633 }
634
635 //******************************************************
636 CAM_DataModel* SHAPERGUI::createDataModel()
637 {
638   return new SHAPERGUI_DataModel(this);
639 }
640
641 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
642                                const bool isAddSeparator)
643 {
644   return addFeature(theWBName,
645                     theInfo.toolBar,
646                     theInfo.id,
647                     theInfo.text,
648                     //Issue #650: in the SALOME mode the tooltip should be same as text
649                     theInfo.text,
650                     theInfo.icon,
651                     theInfo.shortcut,
652                     theInfo.checkable,
653                     isAddSeparator,
654                     theInfo.toolTip);
655 }
656
657 //******************************************************
658 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
659                                const QString& theId, const QString& theTitle, const QString& theTip,
660                                const QIcon& theIcon, const QKeySequence& theKeys,
661                                bool isCheckable, const bool isAddSeparator,
662                                const QString& theStatusTip)
663 {
664   static QString aLastTool = "";
665   static int aNb = 0;
666   if (aLastTool.isEmpty())
667     aLastTool = theWBName;
668   else if (theWBName != aLastTool) {
669     aLastTool = theWBName;
670     if (aNb > 20) {
671       desktop()->addToolBarBreak();
672       aNb = 0;
673     }
674   }
675   aNb++;
676
677   int aId = getNextCommandId();
678   myActionsList.append(aId);
679   SUIT_Desktop* aDesk = application()->desktop();
680   int aKeys = 0;
681   for (int i = 0; i < theKeys.count(); i++)
682     aKeys += theKeys[i];
683   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
684                                   isCheckable);
685   aAction->setStatusTip(theStatusTip);
686
687   aAction->setData(theId);
688
689   int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
690 #ifdef _DEBUG
691   int aItemId =
692 #endif
693     createMenu(aId, aWBMenu);
694   if (isAddSeparator)
695     createMenu(separator(), aWBMenu);
696
697   int aWBTool = createTool(theTBName, theTBName);
698 #ifdef _DEBUG
699   int aToolId =
700 #endif
701     createTool(aId, aWBTool);
702   registerCommandToolbar(theTBName, aId);
703   if (isAddSeparator) {
704     createTool(separator(), aWBTool);
705     registerCommandToolbar(theTBName, -1);
706   }
707   return aAction;
708 }
709
710 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
711 {
712   return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
713 }
714
715 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
716                                        const ActionInfo& theInfo,
717                                        const QList<QAction*>& theNestedActions)
718 {
719   SUIT_Desktop* aDesk = application()->desktop();
720   SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
721   anAction->setData(theInfo.id);
722   anAction->setCheckable(theInfo.checkable);
723   anAction->setChecked(theInfo.checked);
724   anAction->setEnabled(theInfo.enabled);
725   anAction->setVisible(theInfo.visible);
726   anAction->setIcon(theInfo.icon);
727   anAction->setText(theInfo.text);
728   anAction->setToolTip(theInfo.toolTip);
729   anAction->setShortcut(theInfo.shortcut);
730   anAction->setFont(theInfo.font);
731
732   int aWBMenu = createMenu(theWBName, -1, -1, 30);
733   int aItemId = createMenu(anAction, aWBMenu);
734   myActionsList.append(aItemId);
735   createMenu(separator(), aWBMenu); /// nested action is always separated of others
736
737   int aWBTool = createTool(theWBName, theWBName);
738 #ifdef _DEBUG
739   int aToolId =
740 #endif
741     createTool(anAction, aWBTool);
742   registerCommandToolbar(theWBName, aItemId);
743   createTool(separator(), aWBTool); /// nested action is always separated of others
744   registerCommandToolbar(theWBName, -1);
745
746   return anAction;
747 }
748
749
750 //******************************************************
751 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
752                                            const QString& theTip, const QIcon& theIcon,
753                                            const QKeySequence& theKeys, bool isCheckable,
754                                            const char* theMenuSourceText,
755                                            const QString& theSubMenu,
756                                            const int theMenuPosition,
757                                            const int theSuibMenuPosition)
758 {
759   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
760   if (!theSubMenu.isNull())
761     aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
762
763   int aId = getNextCommandId();
764   myActionsList.append(aId);
765   SUIT_Desktop* aDesk = application()->desktop();
766   int aKeys = 0;
767   for (int i = 0; i < theKeys.count(); i++)
768     aKeys += theKeys[i];
769   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
770                                   isCheckable);
771   aAction->setStatusTip(theTip);
772   aAction->setData(theId);
773   createMenu(aId, aMenu, theMenuPosition);
774   return aAction;
775 }
776
777 //******************************************************
778 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
779 {
780   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
781   createMenu(separator(), aMenu, -1, theMenuPosition);
782 }
783
784 //******************************************************
785 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
786 {
787   if( !theAction )
788     return false;
789
790   SUIT_Desktop* aDesktop = application()->desktop();
791   if( !aDesktop )
792     return false;
793
794   QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
795   if( !aToolMgr )
796     return false;
797
798   aToolMgr->append( theAction, theToolBarTitle );
799   return true;
800 }
801
802 //******************************************************
803 QList<QAction*> SHAPERGUI::commandList() const
804 {
805   QList<QAction*> aActions;
806   foreach (int aId, myActionsList) {
807     QAction* aCmd = action(aId);
808     if (aCmd)
809       aActions.append(aCmd);
810   }
811
812   return aActions;
813 }
814
815 //******************************************************
816 QMainWindow* SHAPERGUI::desktop() const
817 {
818   return application()->desktop();
819 }
820
821 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
822                                const std::shared_ptr<Config_FeatureMessage>& theMessage)
823 {
824   myFeaturesInfo.insert(theFeatureId, theMessage);
825 }
826
827 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
828 {
829   std::shared_ptr<Config_FeatureMessage> aMessage;
830   if (myFeaturesInfo.contains(theFeatureId))
831     aMessage =  myFeaturesInfo[theFeatureId];
832   return aMessage;
833 }
834
835 //******************************************************
836 void SHAPERGUI::selectionChanged()
837 {
838   LightApp_Module::selectionChanged();
839   myWorkshop->salomeViewerSelectionChanged();
840 }
841
842 //******************************************************
843 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
844 {
845   myWorkshop->contextMenuMgr()->updateViewerMenu();
846   myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
847   LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
848 }
849
850
851 //******************************************************
852 void SHAPERGUI::createPreferences()
853 {
854   LightApp_Preferences* pref = preferences();
855   if (!pref)
856     return;
857   ModuleBase_Preferences::updateConfigByResources();
858   QString aModName = moduleName();
859
860   QtxPreferenceItem* item = pref->findItem(aModName, true );
861   if ( item && (!item->isEmpty() )) {
862     item->parentItem()->removeItem(item);
863     delete item;
864   }
865
866   int catId = pref->addPreference(aModName, -1 );
867   if ( catId == -1 )
868     return;
869   SHAPERGUI_PrefMgr aMgr(pref, aModName);
870   ModuleBase_Preferences::createEditContent(&aMgr, catId);
871
872   int viewTab = pref->addItem(tr("Viewer"), catId);
873   // Create other parameters group in viewer tab
874   int otherGroup = pref->addItem(tr("Default selection"), viewTab);
875   pref->setItemProperty("columns", 3, otherGroup);
876   pref->addItem(tr("Faces"), otherGroup,
877                          SUIT_PreferenceMgr::Bool,
878                          ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
879   pref->addItem(tr("Edges"), otherGroup,
880                          SUIT_PreferenceMgr::Bool,
881                          ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
882   pref->addItem(tr("Vertices"), otherGroup,
883                          SUIT_PreferenceMgr::Bool,
884                          ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
885
886   int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
887   pref->setItemProperty("columns", 2, sensitivityGroup);
888   pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
889                 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
890   pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
891                 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
892
893   int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
894   pref->setItemProperty("columns", 2, highlightGroup);
895   pref->addItem(tr("In 3d mode"), highlightGroup,
896     SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
897   pref->addItem(tr("In 2d mode"), highlightGroup,
898     SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
899
900   int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
901   pref->setItemProperty("columns", 4, colorScaleGroup);
902   int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
903     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
904   pref->setItemProperty("min", 0, aItem);
905   pref->setItemProperty("max", 1, aItem);
906
907   aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
908     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
909   pref->setItemProperty("min", 0, aItem);
910   pref->setItemProperty("max", 1, aItem);
911
912   aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
913     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
914   pref->setItemProperty("min", 0, aItem);
915   pref->setItemProperty("max", 1, aItem);
916
917   aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
918     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
919   pref->setItemProperty("min", 0, aItem);
920   pref->setItemProperty("max", 1, aItem);
921
922   aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
923     SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
924   pref->setItemProperty("min", 0, aItem);
925   pref->setItemProperty("max", 100, aItem);
926
927   aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
928     SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
929   pref->setItemProperty("min", 0, aItem);
930   pref->setItemProperty("max", 100, aItem);
931
932   aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
933     SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
934
935   pref->retrieve();
936 }
937
938 //******************************************************
939 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
940 {
941   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
942   QString aVal = aResMgr->stringValue(theSection, theParam);
943   Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
944                                                     theParam.toStdString());
945   std::string aValue = aVal.toStdString();
946   if (aValue.empty()) {
947     aValue = aProp->defaultValue();
948     aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
949
950     LightApp_Preferences* pref = preferences();
951     if (pref)
952       pref->retrieve();
953   }
954   aProp->setValue(aValue);
955
956   if (theSection == "Visualization") {
957     if (theParam == "selection_color") {
958       std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
959       myWorkshop->displayer()->setSelectionColor(aColor);
960     }
961     if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
962       if (mySelector) {
963         Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
964         if (!aTrihedron.IsNull()) {
965           bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
966           Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
967
968           ModuleBase_IViewer* aViewer = myWorkshop->viewer();
969           Handle(V3d_View) aView = aViewer->activeView();
970           if (aZoom) {
971             double aAxLen =
972               aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
973             Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
974             double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
975             myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
976             aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
977             aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
978             aContext->Redisplay(aTrihedron, true);
979
980           }
981           else if (myAxisArrowRate > 0) {
982             Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
983             aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
984             aContext->Redisplay(aTrihedron, true);
985           }
986         }
987       }
988     }
989   }
990   myWorkshop->displayer()->redisplayObjects();
991 }
992
993 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
994 {
995   application()->putInfo(theInfo, theMSecs);
996 }
997
998 bool SHAPERGUI::abortAllOperations()
999 {
1000   return workshop()->operationMgr()->abortAllOperations();
1001 }
1002
1003 void SHAPERGUI::createFeatureActions()
1004 {
1005   myWorkshop->menuMgr()->createFeatureActions();
1006 }
1007
1008 void SHAPERGUI::onWhatIs(bool isToggled)
1009 {
1010   if (sender() == myWhatIsAction) {
1011     QAction* aViewAct = myInspectionPanel->toggleViewAction();
1012     aViewAct->blockSignals(true);
1013     aViewAct->setChecked(isToggled);
1014     aViewAct->blockSignals(false);
1015     myInspectionPanel->setVisible(isToggled);
1016   }
1017   else {
1018     myWhatIsAction->blockSignals(true);
1019     myWhatIsAction->setChecked(isToggled);
1020     myWhatIsAction->blockSignals(false);
1021     myInspectionPanel->setVisible(isToggled);
1022   }
1023 }
1024
1025 void SHAPERGUI::updateModuleVisibilityState()
1026 {
1027   LightApp_Module::updateModuleVisibilityState();
1028   onWhatIs(myIsInspectionVisible);
1029 }
1030
1031 void SHAPERGUI::onEditToolbars()
1032 {
1033   SHAPERGUI_ToolbarsDlg aDlg(this);
1034   if (aDlg.exec() == QDialog::Accepted) {
1035     if (aDlg.isReset())
1036       resetToolbars();
1037     else
1038       updateToolbars(aDlg.result());
1039   }
1040 }
1041
1042 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1043 {
1044   if (!myToolbars.contains(theToolName))
1045     myToolbars[theToolName] = QList<int>();
1046   myToolbars[theToolName].append(theCommandId);
1047 }
1048
1049 int SHAPERGUI::getNextCommandId() const
1050 {
1051   QtxActionMenuMgr* aMenuMgr = menuMgr();
1052   QIntList aIds = aMenuMgr->idList();
1053   int aId = aIds.count();
1054   while (action(aId) || myActionsList.contains(aId))
1055     aId++;
1056   return aId;
1057 }
1058
1059 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1060 {
1061   // Store default toolbars
1062   if (myDefaultToolbars.size() == 0)
1063     myDefaultToolbars = myToolbars;
1064
1065   QtxActionToolMgr* aMgr = toolMgr();
1066   QStringList aToolbars = theNewToolbars.keys();
1067   QIntList aCommands, aOldCmd;
1068   int aToolbarId;
1069   QAction* aAction;
1070   int aActionId;
1071   foreach(QString aName, aToolbars) {
1072     aCommands = theNewToolbars[aName];
1073     // Find or create toolbar
1074     if (aMgr->hasToolBar(aName)) {
1075       aToolbarId = aMgr->find(aMgr->toolBar(aName));
1076       aOldCmd = myToolbars[aName];
1077     }
1078     else {
1079       aToolbarId = aMgr->createToolBar(aName);
1080     }
1081     int aPos = 0;
1082     foreach(int aCmd, aCommands) {
1083       // Find action
1084       if (aCmd == -1)
1085         aAction = separator();
1086       else
1087         aAction = action(aCmd);
1088       aActionId = aMgr->actionId(aAction);
1089       if (aActionId == -1) {
1090         // Add new action
1091         aMgr->insert(aAction, aToolbarId, aPos);
1092       }
1093       else {
1094         // Change position of action
1095         if (aMgr->index(aActionId, aToolbarId) != aPos) {
1096           if (aMgr->containsAction(aActionId, aToolbarId))
1097             aMgr->remove(aActionId, aToolbarId);
1098           aMgr->insert(aActionId, aToolbarId, aPos);
1099         }
1100       }
1101       aOldCmd.removeAll(aCmd);
1102       aPos++;
1103     }
1104     // remove extra actions
1105     foreach(int aCmd, aOldCmd) {
1106       aAction = action(aCmd);
1107       aActionId = aMgr->actionId(aAction);
1108       aMgr->remove(aActionId, aToolbarId);
1109     }
1110     myToolbars.remove(aName);
1111   }
1112   // Remove extra toolbars
1113   aToolbars = myToolbars.keys();
1114   foreach(QString aName, aToolbars) {
1115     aMgr->removeToolBar(aName);
1116   }
1117   // Set new toolbars structure
1118   myToolbars = theNewToolbars;
1119   myIsToolbarsModified = true;
1120 }
1121
1122 void SHAPERGUI::saveToolbarsConfig()
1123 {
1124   if (!myIsToolbarsModified)
1125     return;
1126   // Save toolbars configuration into map
1127   QMap<QString, QStringList> aToolbarsConfig;
1128 #ifdef _DEBUG
1129   QtxActionToolMgr* aMgr =
1130 #endif
1131     toolMgr();
1132   QStringList aToolbars = myToolbars.keys();
1133   QIntList aActionsIds;
1134   foreach(QString aName, aToolbars) {
1135     aActionsIds = myToolbars[aName];
1136     QStringList aContent;
1137     foreach(int aId, aActionsIds) {
1138       if (aId == -1)
1139         aContent.append("");
1140       else
1141         aContent.append(action(aId)->data().toString());
1142     }
1143     aToolbarsConfig[aName] = aContent;
1144   }
1145   // Store the configuration into resources
1146   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1147   QStringList aNames = aToolbarsConfig.keys();
1148   QStringList aValues;
1149   foreach(QString aToolbar, aNames) {
1150     aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1151   }
1152   // Remove obsolete parameters from resources
1153   QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1154   foreach(QString aName, aOldParams) {
1155     if (!aToolbars.contains(aName))
1156       aResMgr->remove(ToolbarsSection, aName);
1157   }
1158   // Store current list of free commands
1159   QIntList aFreeCommands = getFreeCommands();
1160   QStringList aFreeList;
1161   foreach(int aId, aFreeCommands) {
1162     aFreeList.append(action(aId)->data().toString());
1163   }
1164   if (aFreeList.size() > 0)
1165     aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1166
1167   myIsToolbarsModified = false;
1168 }
1169
1170 void SHAPERGUI::loadToolbarsConfig()
1171 {
1172   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1173   QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1174   if (aToolbarNames.size() == 0)
1175     return;
1176
1177   // Create commands map
1178   QMap<QString, int> aCommandsMap;
1179   QString aCmdIdStr;
1180   foreach(int aId, myActionsList) {
1181     aCmdIdStr = action(aId)->data().toString();
1182     aCommandsMap[aCmdIdStr] = aId;
1183   }
1184
1185   // Create new toolbars structure
1186   QMap<QString, QIntList> aToolbars;
1187   QStringList aCommands;
1188   QIntList aKnownCommands;
1189   QList<QAction*> aActions;
1190   foreach(QString aName, aToolbarNames) {
1191     aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1192     if (aName == FreeCommandsParam) {
1193       // The value is a list of free commands
1194       foreach(QString aCommand, aCommands) {
1195         aKnownCommands.append(aCommandsMap[aCommand]);
1196       }
1197     }
1198     else {
1199       aToolbars[aName] = QIntList();
1200       if (aCommands.size() > 0) {
1201         foreach(QString aCommand, aCommands) {
1202           if (aCommand.isEmpty())
1203             aToolbars[aName].append(-1);
1204           else if (aCommandsMap.contains(aCommand)) {
1205             int aId = aCommandsMap[aCommand];
1206             aToolbars[aName].append(aId);
1207             aKnownCommands.append(aId);
1208           }
1209         }
1210       }
1211     }
1212   }
1213   // Find new and obsolete commands
1214   QIntList aNewCommands = myActionsList;
1215   foreach(int aId, myActionsList) {
1216     if (aKnownCommands.contains(aId)) {
1217       aKnownCommands.removeAll(aId);
1218       aNewCommands.removeAll(aId);
1219     }
1220   }
1221   if (aNewCommands.size() > 0) {
1222     // Add new commands to toolbars structure
1223     QStringList aKeys = myToolbars.keys();
1224     foreach(int aNewId, aNewCommands) {
1225       foreach(QString aName, aKeys) {
1226         if (myToolbars[aName].contains(aNewId)) {
1227           if (!aToolbars.contains(aName)) {
1228             aToolbars[aName] = QIntList();
1229           }
1230           aToolbars[aName].append(aNewId);
1231         }
1232       }
1233     }
1234   }
1235   if (aKnownCommands.size() > 0) {
1236     // Remove obsolete commands from the toolbars structure
1237     QStringList aKeys = aToolbars.keys();
1238     foreach(int aOldId, aKnownCommands) {
1239       foreach(QString aName, aKeys) {
1240         if (aToolbars[aName].contains(aOldId)) {
1241           aToolbars[aName].removeAll(aOldId);
1242           if (aToolbars[aName].size() == 0)
1243             aToolbars.remove(aName);
1244         }
1245       }
1246     }
1247   }
1248   updateToolbars(aToolbars);
1249   myIsToolbarsModified = false;
1250 }
1251
1252
1253 QIntList SHAPERGUI::getFreeCommands() const
1254 {
1255   QIntList aFreeCommands;
1256   QtxActionToolMgr* aMgr = toolMgr();
1257   QAction* anAction;
1258   int aId;
1259   QMap<QString, QIntList>::const_iterator aIt;
1260   QIntList aShaperActions = shaperActions();
1261   foreach(int aCmd, aShaperActions) {
1262     anAction = action(aCmd);
1263     aId = aMgr->actionId(anAction);
1264     if (!aMgr->containsAction(aId))
1265       aFreeCommands.append(aCmd);
1266   }
1267   return aFreeCommands;
1268 }
1269
1270 void SHAPERGUI::resetToolbars()
1271 {
1272   if (!myDefaultToolbars.isEmpty())
1273     updateToolbars(myDefaultToolbars);
1274   myIsToolbarsModified = false;
1275   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1276   aResMgr->remove(ToolbarsSection);
1277 }
1278
1279 void SHAPERGUI::publishToStudy()
1280 {
1281   if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument())
1282     myWorkshop->module()->launchOperation("PublishToStudy", false);
1283 }