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