Salome HOME
Issue #3274: Update trihedron after change of preferences
[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
71 #include <QDockWidget>
72 #include <QAction>
73 #include <QTimer>
74 #include <QMenu>
75 #include <QToolBar>
76
77 #include <ModelAPI_Session.h>
78
79 #if OCC_VERSION_HEX < 0x070400
80   #define SALOME_PATCH_FOR_CTRL_WHEEL
81 #endif
82
83 extern "C" {
84 SHAPERGUI_EXPORT CAM_Module* createModule()
85 {
86   return new SHAPERGUI();
87 }
88
89 SHAPERGUI_EXPORT char* getModuleVersion()
90 {
91   return (char*)"0.0";
92 }
93 } // extern "C"
94
95
96 static const QString ToolbarsSection("SHAPER_Toolbars");
97 static const QString FreeCommandsParam("OutOFToolbars");
98
99
100 /** 
101 * Class for preferences management
102 */
103 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
104 {
105 public:
106   /// Constructor
107   /// \param theMgr preferences manager of SALOME
108   /// \param theModName name of the module
109   SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
110     myMgr(theMgr), myModName(theModName) {}
111
112   virtual int addPreference(const QString& theLbl, int pId,
113                             SUIT_PreferenceMgr::PrefItemType theType,
114                             const QString& theSection, const QString& theName )
115   {
116     return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
117   }
118
119   virtual void setItemProperty(const QString& thePropName,
120                                const QVariant& theValue,
121                                const int theId = -1)
122   {
123     myMgr->setItemProperty(thePropName, theValue, theId);
124   }
125
126
127   virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
128
129 private:
130   LightApp_Preferences* myMgr;
131   QString myModName;
132 };
133
134
135
136
137 //******************************************************
138 SHAPERGUI::SHAPERGUI()
139     : LightApp_Module("SHAPER"),
140       mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
141   myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
142   myAxisArrowRate(-1)
143 {
144   myWorkshop = new XGUI_Workshop(this);
145   connect(myWorkshop, SIGNAL(commandStatusUpdated()),
146           this, SLOT(onUpdateCommandStatus()));
147
148   myProxyViewer = new SHAPERGUI_SalomeViewer(this);
149
150   ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
151
152   // It will be called in XGUI_Workshop::startApplication
153   // ModuleBase_Preferences::loadCustomProps();
154 }
155
156 //******************************************************
157 SHAPERGUI::~SHAPERGUI()
158 {
159   delete myWorkshop;
160   delete myProxyViewer;
161 }
162
163 //******************************************************
164 void SHAPERGUI::initialize(CAM_Application* theApp)
165 {
166   LightApp_Module::initialize(theApp);
167
168   myWorkshop->startApplication();
169   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
170   if (anApp)
171   {
172     connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
173   }
174
175   int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
176   int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
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, aSubMenu, 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 #ifdef _DEBUG
690   int aItemId =
691 #endif
692     createMenu(aId, aWBMenu);
693   if (isAddSeparator)
694     createMenu(separator(), aWBMenu);
695
696   int aWBTool = createTool(theTBName, theTBName);
697 #ifdef _DEBUG
698   int aToolId =
699 #endif
700     createTool(aId, aWBTool);
701   registerCommandToolbar(theTBName, aId);
702   if (isAddSeparator) {
703     createTool(separator(), aWBTool);
704     registerCommandToolbar(theTBName, -1);
705   }
706   return aAction;
707 }
708
709 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
710 {
711   return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
712 }
713
714 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
715                                        const ActionInfo& theInfo,
716                                        const QList<QAction*>& theNestedActions)
717 {
718   SUIT_Desktop* aDesk = application()->desktop();
719   SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
720   anAction->setData(theInfo.id);
721   anAction->setCheckable(theInfo.checkable);
722   anAction->setChecked(theInfo.checked);
723   anAction->setEnabled(theInfo.enabled);
724   anAction->setVisible(theInfo.visible);
725   anAction->setIcon(theInfo.icon);
726   anAction->setText(theInfo.text);
727   anAction->setToolTip(theInfo.toolTip);
728   anAction->setShortcut(theInfo.shortcut);
729   anAction->setFont(theInfo.font);
730
731   int aWBMenu = createMenu(theWBName, -1, -1, 30);
732   int aItemId = createMenu(anAction, aWBMenu);
733   myActionsList.append(aItemId);
734   createMenu(separator(), aWBMenu); /// nested action is always separated of others
735
736   int aWBTool = createTool(theWBName, theWBName);
737 #ifdef _DEBUG
738   int aToolId =
739 #endif
740     createTool(anAction, aWBTool);
741   registerCommandToolbar(theWBName, aItemId);
742   createTool(separator(), aWBTool); /// nested action is always separated of others
743   registerCommandToolbar(theWBName, -1);
744
745   return anAction;
746 }
747
748
749 //******************************************************
750 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
751                                            const QString& theTip, const QIcon& theIcon,
752                                            const QKeySequence& theKeys, bool isCheckable,
753                                            const char* theMenuSourceText,
754                                            const QString& theSubMenu,
755                                            const int theMenuPosition,
756                                            const int theSuibMenuPosition)
757 {
758   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
759   if (!theSubMenu.isNull())
760     aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
761
762   int aId = getNextCommandId();
763   myActionsList.append(aId);
764   SUIT_Desktop* aDesk = application()->desktop();
765   int aKeys = 0;
766   for (int i = 0; i < theKeys.count(); i++)
767     aKeys += theKeys[i];
768   QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
769                                   isCheckable);
770   aAction->setStatusTip(theTip);
771   aAction->setData(theId);
772   createMenu(aId, aMenu, theMenuPosition);
773   return aAction;
774 }
775
776 //******************************************************
777 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
778 {
779   int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
780   createMenu(separator(), aMenu, -1, theMenuPosition);
781 }
782
783 //******************************************************
784 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
785 {
786   if( !theAction )
787     return false;
788
789   SUIT_Desktop* aDesktop = application()->desktop();
790   if( !aDesktop )
791     return false;
792
793   QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
794   if( !aToolMgr )
795     return false;
796
797   aToolMgr->append( theAction, theToolBarTitle );
798   return true;
799 }
800
801 //******************************************************
802 QList<QAction*> SHAPERGUI::commandList() const
803 {
804   QList<QAction*> aActions;
805   foreach (int aId, myActionsList) {
806     QAction* aCmd = action(aId);
807     if (aCmd)
808       aActions.append(aCmd);
809   }
810
811   return aActions;
812 }
813
814 //******************************************************
815 QMainWindow* SHAPERGUI::desktop() const
816 {
817   return application()->desktop();
818 }
819
820 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
821                                const std::shared_ptr<Config_FeatureMessage>& theMessage)
822 {
823   myFeaturesInfo.insert(theFeatureId, theMessage);
824 }
825
826 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
827 {
828   std::shared_ptr<Config_FeatureMessage> aMessage;
829   if (myFeaturesInfo.contains(theFeatureId))
830     aMessage =  myFeaturesInfo[theFeatureId];
831   return aMessage;
832 }
833
834 //******************************************************
835 void SHAPERGUI::selectionChanged()
836 {
837   LightApp_Module::selectionChanged();
838   myWorkshop->salomeViewerSelectionChanged();
839 }
840
841 //******************************************************
842 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
843 {
844   myWorkshop->contextMenuMgr()->updateViewerMenu();
845   myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
846   LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
847 }
848
849
850 //******************************************************
851 void SHAPERGUI::createPreferences()
852 {
853   LightApp_Preferences* pref = preferences();
854   if (!pref)
855     return;
856   ModuleBase_Preferences::updateConfigByResources();
857   QString aModName = moduleName();
858
859   QtxPreferenceItem* item = pref->findItem(aModName, true );
860   if ( item && (!item->isEmpty() )) {
861     item->parentItem()->removeItem(item);
862     delete item;
863   }
864
865   int catId = pref->addPreference(aModName, -1 );
866   if ( catId == -1 )
867     return;
868   SHAPERGUI_PrefMgr aMgr(pref, aModName);
869   ModuleBase_Preferences::createEditContent(&aMgr, catId);
870
871   int viewTab = pref->addItem(tr("Viewer"), catId);
872   // Create other parameters group in viewer tab
873   int otherGroup = pref->addItem(tr("Default selection"), viewTab);
874   pref->setItemProperty("columns", 3, otherGroup);
875   pref->addItem(tr("Faces"), otherGroup,
876                          SUIT_PreferenceMgr::Bool,
877                          ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
878   pref->addItem(tr("Edges"), otherGroup,
879                          SUIT_PreferenceMgr::Bool,
880                          ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
881   pref->addItem(tr("Vertices"), otherGroup,
882                          SUIT_PreferenceMgr::Bool,
883                          ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
884
885   int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
886   pref->setItemProperty("columns", 2, sensitivityGroup);
887   pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
888                 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
889   pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
890                 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
891
892   int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
893   pref->setItemProperty("columns", 2, highlightGroup);
894   pref->addItem(tr("In 3d mode"), highlightGroup,
895     SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
896   pref->addItem(tr("In 2d mode"), highlightGroup,
897     SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
898
899   int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
900   pref->setItemProperty("columns", 4, colorScaleGroup);
901   int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
902     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
903   pref->setItemProperty("min", 0, aItem);
904   pref->setItemProperty("max", 1, aItem);
905
906   aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
907     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
908   pref->setItemProperty("min", 0, aItem);
909   pref->setItemProperty("max", 1, aItem);
910
911   aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
912     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
913   pref->setItemProperty("min", 0, aItem);
914   pref->setItemProperty("max", 1, aItem);
915
916   aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
917     SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
918   pref->setItemProperty("min", 0, aItem);
919   pref->setItemProperty("max", 1, aItem);
920
921   aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
922     SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
923   pref->setItemProperty("min", 0, aItem);
924   pref->setItemProperty("max", 100, aItem);
925
926   aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
927     SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
928   pref->setItemProperty("min", 0, aItem);
929   pref->setItemProperty("max", 100, aItem);
930
931   aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
932     SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
933
934   pref->retrieve();
935 }
936
937 //******************************************************
938 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
939 {
940   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
941   QString aVal = aResMgr->stringValue(theSection, theParam);
942   Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
943                                                     theParam.toStdString());
944   std::string aValue = aVal.toStdString();
945   if (aValue.empty()) {
946     aValue = aProp->defaultValue();
947     aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
948
949     LightApp_Preferences* pref = preferences();
950     if (pref)
951       pref->retrieve();
952   }
953   aProp->setValue(aValue);
954
955   if (theSection == "Visualization") {
956     if (theParam == "selection_color") {
957       std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
958       myWorkshop->displayer()->setSelectionColor(aColor);
959     }
960     if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
961       if (mySelector) {
962         Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
963         if (!aTrihedron.IsNull()) {
964           bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
965           Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
966
967           ModuleBase_IViewer* aViewer = myWorkshop->viewer();
968           Handle(V3d_View) aView = aViewer->activeView();
969           if (aZoom) {
970             double aAxLen =
971               aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
972             Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
973             double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
974             myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
975             aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
976             aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
977             aContext->Redisplay(aTrihedron, true);
978
979           }
980           else if (myAxisArrowRate > 0) {
981             Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
982             aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
983             aContext->Redisplay(aTrihedron, true);
984           }
985         }
986       }
987     }
988   }
989   myWorkshop->displayer()->redisplayObjects();
990 }
991
992 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
993 {
994   application()->putInfo(theInfo, theMSecs);
995 }
996
997 bool SHAPERGUI::abortAllOperations()
998 {
999   return workshop()->operationMgr()->abortAllOperations();
1000 }
1001
1002 void SHAPERGUI::createFeatureActions()
1003 {
1004   myWorkshop->menuMgr()->createFeatureActions();
1005 }
1006
1007 void SHAPERGUI::onWhatIs(bool isToggled)
1008 {
1009   if (sender() == myWhatIsAction) {
1010     QAction* aViewAct = myInspectionPanel->toggleViewAction();
1011     aViewAct->blockSignals(true);
1012     aViewAct->setChecked(isToggled);
1013     aViewAct->blockSignals(false);
1014     myInspectionPanel->setVisible(isToggled);
1015   }
1016   else {
1017     myWhatIsAction->blockSignals(true);
1018     myWhatIsAction->setChecked(isToggled);
1019     myWhatIsAction->blockSignals(false);
1020     myInspectionPanel->setVisible(isToggled);
1021   }
1022 }
1023
1024 void SHAPERGUI::updateModuleVisibilityState()
1025 {
1026   LightApp_Module::updateModuleVisibilityState();
1027   onWhatIs(myIsInspectionVisible);
1028 }
1029
1030 void SHAPERGUI::onEditToolbars()
1031 {
1032   SHAPERGUI_ToolbarsDlg aDlg(this);
1033   if (aDlg.exec() == QDialog::Accepted) {
1034     if (aDlg.isReset())
1035       resetToolbars();
1036     else
1037       updateToolbars(aDlg.result());
1038   }
1039 }
1040
1041 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1042 {
1043   if (!myToolbars.contains(theToolName))
1044     myToolbars[theToolName] = QList<int>();
1045   myToolbars[theToolName].append(theCommandId);
1046 }
1047
1048 int SHAPERGUI::getNextCommandId() const
1049 {
1050   QtxActionMenuMgr* aMenuMgr = menuMgr();
1051   QIntList aIds = aMenuMgr->idList();
1052   int aId = aIds.count();
1053   while (action(aId) || myActionsList.contains(aId))
1054     aId++;
1055   return aId;
1056 }
1057
1058 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1059 {
1060   // Store default toolbars
1061   if (myDefaultToolbars.size() == 0)
1062     myDefaultToolbars = myToolbars;
1063
1064   QtxActionToolMgr* aMgr = toolMgr();
1065   QStringList aToolbars = theNewToolbars.keys();
1066   QIntList aCommands, aOldCmd;
1067   int aToolbarId;
1068   QAction* aAction;
1069   int aActionId;
1070   foreach(QString aName, aToolbars) {
1071     aCommands = theNewToolbars[aName];
1072     // Find or create toolbar
1073     if (aMgr->hasToolBar(aName)) {
1074       aToolbarId = aMgr->find(aMgr->toolBar(aName));
1075       aOldCmd = myToolbars[aName];
1076     }
1077     else {
1078       aToolbarId = aMgr->createToolBar(aName);
1079     }
1080     int aPos = 0;
1081     foreach(int aCmd, aCommands) {
1082       // Find action
1083       if (aCmd == -1)
1084         aAction = separator();
1085       else
1086         aAction = action(aCmd);
1087       aActionId = aMgr->actionId(aAction);
1088       if (aActionId == -1) {
1089         // Add new action
1090         aMgr->insert(aAction, aToolbarId, aPos);
1091       }
1092       else {
1093         // Change position of action
1094         if (aMgr->index(aActionId, aToolbarId) != aPos) {
1095           if (aMgr->containsAction(aActionId, aToolbarId))
1096             aMgr->remove(aActionId, aToolbarId);
1097           aMgr->insert(aActionId, aToolbarId, aPos);
1098         }
1099       }
1100       aOldCmd.removeAll(aCmd);
1101       aPos++;
1102     }
1103     // remove extra actions
1104     foreach(int aCmd, aOldCmd) {
1105       aAction = action(aCmd);
1106       aActionId = aMgr->actionId(aAction);
1107       aMgr->remove(aActionId, aToolbarId);
1108     }
1109     myToolbars.remove(aName);
1110   }
1111   // Remove extra toolbars
1112   aToolbars = myToolbars.keys();
1113   foreach(QString aName, aToolbars) {
1114     aMgr->removeToolBar(aName);
1115   }
1116   // Set new toolbars structure
1117   myToolbars = theNewToolbars;
1118   myIsToolbarsModified = true;
1119 }
1120
1121 void SHAPERGUI::saveToolbarsConfig()
1122 {
1123   if (!myIsToolbarsModified)
1124     return;
1125   // Save toolbars configuration into map
1126   QMap<QString, QStringList> aToolbarsConfig;
1127 #ifdef _DEBUG
1128   QtxActionToolMgr* aMgr =
1129 #endif
1130     toolMgr();
1131   QStringList aToolbars = myToolbars.keys();
1132   QIntList aActionsIds;
1133   foreach(QString aName, aToolbars) {
1134     aActionsIds = myToolbars[aName];
1135     QStringList aContent;
1136     foreach(int aId, aActionsIds) {
1137       if (aId == -1)
1138         aContent.append("");
1139       else
1140         aContent.append(action(aId)->data().toString());
1141     }
1142     aToolbarsConfig[aName] = aContent;
1143   }
1144   // Store the configuration into resources
1145   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1146   QStringList aNames = aToolbarsConfig.keys();
1147   QStringList aValues;
1148   foreach(QString aToolbar, aNames) {
1149     aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1150   }
1151   // Remove obsolete parameters from resources
1152   QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1153   foreach(QString aName, aOldParams) {
1154     if (!aToolbars.contains(aName))
1155       aResMgr->remove(ToolbarsSection, aName);
1156   }
1157   // Store current list of free commands
1158   QIntList aFreeCommands = getFreeCommands();
1159   QStringList aFreeList;
1160   foreach(int aId, aFreeCommands) {
1161     aFreeList.append(action(aId)->data().toString());
1162   }
1163   if (aFreeList.size() > 0)
1164     aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1165
1166   myIsToolbarsModified = false;
1167 }
1168
1169 void SHAPERGUI::loadToolbarsConfig()
1170 {
1171   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1172   QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1173   if (aToolbarNames.size() == 0)
1174     return;
1175
1176   // Create commands map
1177   QMap<QString, int> aCommandsMap;
1178   QString aCmdIdStr;
1179   foreach(int aId, myActionsList) {
1180     aCmdIdStr = action(aId)->data().toString();
1181     aCommandsMap[aCmdIdStr] = aId;
1182   }
1183
1184   // Create new toolbars structure
1185   QMap<QString, QIntList> aToolbars;
1186   QStringList aCommands;
1187   QIntList aKnownCommands;
1188   QList<QAction*> aActions;
1189   foreach(QString aName, aToolbarNames) {
1190     aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1191     if (aName == FreeCommandsParam) {
1192       // The value is a list of free commands
1193       foreach(QString aCommand, aCommands) {
1194         aKnownCommands.append(aCommandsMap[aCommand]);
1195       }
1196     }
1197     else {
1198       aToolbars[aName] = QIntList();
1199       if (aCommands.size() > 0) {
1200         foreach(QString aCommand, aCommands) {
1201           if (aCommand.isEmpty())
1202             aToolbars[aName].append(-1);
1203           else if (aCommandsMap.contains(aCommand)) {
1204             int aId = aCommandsMap[aCommand];
1205             aToolbars[aName].append(aId);
1206             aKnownCommands.append(aId);
1207           }
1208         }
1209       }
1210     }
1211   }
1212   // Find new and obsolete commands
1213   QIntList aNewCommands = myActionsList;
1214   foreach(int aId, myActionsList) {
1215     if (aKnownCommands.contains(aId)) {
1216       aKnownCommands.removeAll(aId);
1217       aNewCommands.removeAll(aId);
1218     }
1219   }
1220   if (aNewCommands.size() > 0) {
1221     // Add new commands to toolbars structure
1222     QStringList aKeys = myToolbars.keys();
1223     foreach(int aNewId, aNewCommands) {
1224       foreach(QString aName, aKeys) {
1225         if (myToolbars[aName].contains(aNewId)) {
1226           if (!aToolbars.contains(aName)) {
1227             aToolbars[aName] = QIntList();
1228           }
1229           aToolbars[aName].append(aNewId);
1230         }
1231       }
1232     }
1233   }
1234   if (aKnownCommands.size() > 0) {
1235     // Remove obsolete commands from the toolbars structure
1236     QStringList aKeys = aToolbars.keys();
1237     foreach(int aOldId, aKnownCommands) {
1238       foreach(QString aName, aKeys) {
1239         if (aToolbars[aName].contains(aOldId)) {
1240           aToolbars[aName].removeAll(aOldId);
1241           if (aToolbars[aName].size() == 0)
1242             aToolbars.remove(aName);
1243         }
1244       }
1245     }
1246   }
1247   updateToolbars(aToolbars);
1248   myIsToolbarsModified = false;
1249 }
1250
1251
1252 QIntList SHAPERGUI::getFreeCommands() const
1253 {
1254   QIntList aFreeCommands;
1255   QtxActionToolMgr* aMgr = toolMgr();
1256   QAction* anAction;
1257   int aId;
1258   QMap<QString, QIntList>::const_iterator aIt;
1259   QIntList aShaperActions = shaperActions();
1260   foreach(int aCmd, aShaperActions) {
1261     anAction = action(aCmd);
1262     aId = aMgr->actionId(anAction);
1263     if (!aMgr->containsAction(aId))
1264       aFreeCommands.append(aCmd);
1265   }
1266   return aFreeCommands;
1267 }
1268
1269 void SHAPERGUI::resetToolbars()
1270 {
1271   if (!myDefaultToolbars.isEmpty())
1272     updateToolbars(myDefaultToolbars);
1273   myIsToolbarsModified = false;
1274   SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1275   aResMgr->remove(ToolbarsSection);
1276 }
1277
1278 void SHAPERGUI::publishToStudy()
1279 {
1280   if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument())
1281     myWorkshop->module()->launchOperation("PublishToStudy", false);
1282 }