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