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