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