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