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