1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SHAPERGUI.h"
21 #include "SHAPERGUI_DataModel.h"
22 #include "SHAPERGUI_OCCSelector.h"
23 #include "SHAPERGUI_NestedButton.h"
24 #include "SHAPERGUI_ToolbarsMgr.h"
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>
38 #include <ModuleBase_Operation.h>
39 #include <ModuleBase_Preferences.h>
40 #include <ModuleBase_ActionInfo.h>
41 #include <ModuleBase_IModule.h>
43 #include <ModelAPI_Tools.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_OCCSelector.h>
48 #include <LightApp_Study.h>
50 #include <OCCViewer_ViewModel.h>
51 #include <OCCViewer_ViewPort3d.h>
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>
60 #include <QtxPopupMgr.h>
61 #include <QtxActionMenuMgr.h>
62 #include <QtxActionToolMgr.h>
63 #include <QtxResourceMgr.h>
65 #include <Config_PropManager.h>
66 #include <Config_ModuleReader.h>
68 #include <AIS_ListOfInteractive.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
71 #include <QDockWidget>
77 #if OCC_VERSION_HEX < 0x070400
78 #define SALOME_PATCH_FOR_CTRL_WHEEL
82 SHAPERGUI_EXPORT CAM_Module* createModule()
84 return new SHAPERGUI();
87 SHAPERGUI_EXPORT char* getModuleVersion()
94 static const QString ToolbarsSection("SHAPER_Toolbars");
95 static const QString FreeCommandsParam("OutOFToolbars");
99 * Class for preferences management
101 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
105 /// \param theMgr preferences manager of SALOME
106 /// \param theModName name of the module
107 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
108 myMgr(theMgr), myModName(theModName) {}
110 virtual int addPreference(const QString& theLbl, int pId,
111 SUIT_PreferenceMgr::PrefItemType theType,
112 const QString& theSection, const QString& theName )
114 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
117 virtual void setItemProperty(const QString& thePropName,
118 const QVariant& theValue,
119 const int theId = -1)
121 myMgr->setItemProperty(thePropName, theValue, theId);
125 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
128 LightApp_Preferences* myMgr;
135 //******************************************************
136 SHAPERGUI::SHAPERGUI()
137 : LightApp_Module("SHAPER"),
138 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
139 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false)
141 myWorkshop = new XGUI_Workshop(this);
142 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
143 this, SLOT(onUpdateCommandStatus()));
145 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
147 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
149 // It will be called in XGUI_Workshop::startApplication
150 // ModuleBase_Preferences::loadCustomProps();
153 //******************************************************
154 SHAPERGUI::~SHAPERGUI()
157 delete myProxyViewer;
160 //******************************************************
161 void SHAPERGUI::initialize(CAM_Application* theApp)
163 LightApp_Module::initialize(theApp);
165 myWorkshop->startApplication();
166 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
169 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
172 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
173 int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
175 int aId = getNextCommandId();
176 myActionsList.append(aId);
177 SUIT_Desktop* aDesk = application()->desktop();
178 QString aTip = tr("Show inspection window");
179 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
180 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
181 myWhatIsAction->setStatusTip(aTip);
182 myWhatIsAction->setData("INSPECTION_CMD");
183 createMenu(aId, aSubMenu, 0);
185 QString aToolName = tr("Inspection");
186 int aTool = createTool(aToolName);
190 createTool(myWhatIsAction, aTool);
191 registerCommandToolbar(aToolName, aId);
193 // Define Edit toolbars command
194 aId = getNextCommandId();
195 //myActionsList.append(aId); Do not use it for editing of toolbars
196 aTip = tr("Edit toolbars of the module");
200 createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
201 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
202 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
206 createMenu(aId, aEditMenu);
208 // Initialize viewer proxy if OCC viewer is already exist
209 ViewManagerList aOCCViewManagers;
210 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
211 if (aOCCViewManagers.size() > 0) {
212 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
213 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
215 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
216 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
218 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
219 aViewPort->installEventFilter(aViewer);
220 Handle(V3d_View) aView = aViewPort->getView();
221 aViewer->SetScale(aView, aView->Camera()->Scale());
222 // We can not create selector here because other modules will be deactivated later
223 //onViewManagerAdded(aMgr);
229 //******************************************************
230 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
232 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
235 //******************************************************
236 void SHAPERGUI::viewManagers(QStringList& theList) const
238 theList.append(OCCViewer_Viewer::Type());
241 //******************************************************
242 // We can not create selector in this method because it can be called when
243 // SHAPER module is not active. Take into account that creation of our selector
244 // leads to switching OFF all other selectors
245 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
247 // // if there are created viewer managers, we should try to create viewer
248 // // selector and initialize viewer with it. It sets interactive context to the
249 // // proxy viewer. If study is opened, CAM application calls this method before the open()
251 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
252 // // we need to connect to the viewer before it. Here,
253 // // it seems the most appropriate place for this
254 // // according to SALOME architecture.
255 // if (!mySelector) {
256 // ViewManagerList OCCViewManagers;
257 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
258 // if (OCCViewManagers.size() > 0) {
259 // mySelector = createSelector(OCCViewManagers.first());
262 // LightApp_Module::connectToStudy(theStudy);
265 //******************************************************
266 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
268 bool isDone = LightApp_Module::activateModule(theStudy);
269 loadToolbarsConfig();
271 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
272 aDataModel->initRootObject();
278 QObject* aObj = myWorkshop->objectBrowser()->parent();
279 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
281 myWorkshop->objectBrowser()->setVisible(true);
282 aObjDoc->setVisible(true);
283 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
284 aObjDoc->toggleViewAction()->setVisible(true);
287 if (!myInspectionPanel) {
288 myInspectionPanel = myWorkshop->inspectionPanel();
289 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
290 this, SLOT(onWhatIs(bool)));
292 myInspectionPanel->toggleViewAction()->setVisible(true);
294 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
295 if (myIsFacesPanelVisible)
296 myWorkshop->facesPanel()->show();
297 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
300 ViewManagerList OCCViewManagers;
301 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
302 if (OCCViewManagers.size() > 0) {
303 onViewManagerAdded(OCCViewManagers.first());
306 // it should be performed after the selector creation in order to have AISContext
307 myWorkshop->activateModule();
308 //action(myEraseAll)->setEnabled(false);
311 myWorkshop->objectBrowser()->rebuildDataTree();
312 myWorkshop->updateCommandStatus();
316 myWorkshop->updateCommandStatus();
318 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
319 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
320 myIsEditEnabled = getApp()->isEditEnabled();
321 getApp()->setEditEnabled(false);
323 // this following row is caused by #187 bug.
324 // SALOME saves the dock widget positions before deactivateModule() and
325 // load it after the module activation. So, if the panel is visible before
326 // deactivate, it becomes visible after activate.
327 // In order to avoid the visible property panel, the widget position save is
328 // switch off in this module
329 aResMgr->setValue("Study", "store_positions", false);
331 // Synchronize displayed objects
332 Handle(AIS_InteractiveContext) aContext;
333 if (mySelector && mySelector->viewer())
334 aContext = mySelector->viewer()->getAISContext();
336 if (!aContext.IsNull()) {
337 XGUI_Displayer* aDisp = myWorkshop->displayer();
338 QObjectPtrList aObjList = aDisp->displayedObjects();
340 //if (myHighlightPointAspect.IsNull()) {
341 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
342 // myHighlightPointAspect =
343 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
345 if (myOldSelectionColor.size() == 0)
346 myOldSelectionColor = aDisp->selectionColor();
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)>();
356 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
357 anAISIO = aLIt.Value();
358 if (anAISIO.get() == aAIS.get()) {
364 aObj->setDisplayed(false);
365 //aDisp->erase(aObj, false);
368 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
370 myProxyViewer->activateViewer(true);
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()));
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()));
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()));
389 //******************************************************
390 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
392 saveToolbarsConfig();
394 myProxyViewer->activateViewer(false);
398 myWorkshop->deactivateModule();
400 QObject* aObj = myWorkshop->objectBrowser()->parent();
401 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
403 aObjDoc->setVisible(false);
404 myWorkshop->objectBrowser()->setVisible(false);
405 aObjDoc->toggleViewAction()->setVisible(false);
408 myIsInspectionVisible = myInspectionPanel->isVisible();
409 myInspectionPanel->hide();
410 myInspectionPanel->toggleViewAction()->setVisible(false);
412 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
413 myWorkshop->facesPanel()->hide();
414 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
416 myWorkshop->propertyPanel()->hide();
417 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
419 // the active operation should be stopped for the next activation.
420 // There should not be active operation and visualized preview.
421 // Abort operation should be performed before the selection's remove
422 // because the displayed objects should be removed from the viewer, but
423 // the AIS context is obtained from the selector.
424 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
425 while (anOperation) {
426 anOperation->abort();
427 anOperation = myWorkshop->operationMgr()->currentOperation();
429 // Delete selector because it has to be redefined on next activation
431 //if (!myHighlightPointAspect.IsNull()) {
432 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
433 // aTrihedron->getHighlightPointAspect()->SetAspect(myHighlightPointAspect);
434 // myHighlightPointAspect.Nullify();
436 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
437 myProxyViewer->setSelector(0);
439 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
440 QList<SUIT_Selector*> aList;
441 aMgr->selectors(aList);
442 foreach(SUIT_Selector* aSel, aList) {
443 aSel->setEnabled(aSel != mySelector);
450 myWorkshop->hidePanel(myWorkshop->facesPanel());
451 //myWorkshop->contextMenuMgr()->disconnectViewer();
453 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
454 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
455 getApp()->setEditEnabled(myIsEditEnabled);
457 myOldSelectionColor.clear();
459 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
460 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
461 this, SLOT(onScriptLoaded()));
463 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
464 this, SLOT(onSaveDocByShaper()));
465 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
466 this, SLOT(onSaveAsDocByShaper()));
468 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
469 getApp(), SLOT(onSaveDoc()));
470 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
471 getApp(), SLOT(onSaveAsDoc()));
475 return LightApp_Module::deactivateModule(theStudy);
478 //******************************************************
479 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
482 mySelector = createSelector(theMgr);
483 myWorkshop->selectionActivate()->updateSelectionFilters();
484 myWorkshop->selectionActivate()->updateSelectionModes();
485 myWorkshop->synchronizeViewer();
489 //******************************************************
490 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
493 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
494 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
495 if (mySelector->viewer() == aViewer) {
496 XGUI_Displayer* aDisp = myWorkshop->displayer();
497 QObjectPtrList aObjects = aDisp->displayedObjects();
499 foreach(ObjectPtr aObj, aObjects) {
500 aObj->setDisplayed(false);
501 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
503 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
504 aRes->setDisplayed(false);
508 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
509 myProxyViewer->setSelector(0);
513 myWorkshop->module()->clearViewer();
519 //******************************************************
520 QtxPopupMgr* SHAPERGUI::popupMgr()
523 myPopupMgr = new QtxPopupMgr( 0, this );
527 //******************************************************
528 void SHAPERGUI::onDefaultPreferences()
530 // reset main resources
531 ModuleBase_Preferences::resetResourcePreferences(preferences());
532 // reset plugin's resources
533 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
535 myWorkshop->displayer()->redisplayObjects();
538 //******************************************************
539 void SHAPERGUI::onScriptLoaded()
541 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
542 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
543 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
544 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
545 // it manually (because this method of application is protected)
546 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
549 myWorkshop->displayer()->updateViewer();
550 myWorkshop->updateCommandStatus();
553 //******************************************************
554 void SHAPERGUI::onSaveDocByShaper()
556 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
559 getApp()->onSaveDoc();
562 //******************************************************
563 void SHAPERGUI::onSaveAsDocByShaper()
565 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
568 getApp()->onSaveAsDoc();
571 //******************************************************
572 void SHAPERGUI::onUpdateCommandStatus()
574 getApp()->updateActions();
577 //******************************************************
578 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
580 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
581 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
583 //if (myHighlightPointAspect.IsNull()) {
584 // Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
585 // myHighlightPointAspect =
586 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
588 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
589 getApp()->selectionMgr());
590 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
591 aViewer->setUseLocalSelection(true);
593 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
594 QList<SUIT_Selector*> aList;
595 aMgr->selectors(aList);
596 foreach(SUIT_Selector* aSel, aList)
598 aSel->setEnabled(aSel == aSelector);
600 myProxyViewer->setSelector(aSelector);
602 if (myOldSelectionColor.size() == 0)
603 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
605 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
606 myWorkshop->displayer()->setSelectionColor(aColor);
612 //******************************************************
613 CAM_DataModel* SHAPERGUI::createDataModel()
615 return new SHAPERGUI_DataModel(this);
618 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
619 const bool isAddSeparator)
621 return addFeature(theWBName,
625 //Issue #650: in the SALOME mode the tooltip should be same as text
634 //******************************************************
635 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
636 const QString& theId, const QString& theTitle, const QString& theTip,
637 const QIcon& theIcon, const QKeySequence& theKeys,
638 bool isCheckable, const bool isAddSeparator,
639 const QString& theStatusTip)
641 static QString aLastTool = "";
643 if (aLastTool.isEmpty())
644 aLastTool = theWBName;
645 else if (theWBName != aLastTool) {
646 aLastTool = theWBName;
648 desktop()->addToolBarBreak();
654 int aId = getNextCommandId();
655 myActionsList.append(aId);
656 SUIT_Desktop* aDesk = application()->desktop();
658 for (int i = 0; i < theKeys.count(); i++)
660 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
662 aAction->setStatusTip(theStatusTip);
664 aAction->setData(theId);
666 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
670 createMenu(aId, aWBMenu);
672 createMenu(separator(), aWBMenu);
674 int aWBTool = createTool(theTBName, theTBName);
678 createTool(aId, aWBTool);
679 registerCommandToolbar(theTBName, aId);
680 if (isAddSeparator) {
681 createTool(separator(), aWBTool);
682 registerCommandToolbar(theTBName, -1);
687 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
689 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
692 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
693 const ActionInfo& theInfo,
694 const QList<QAction*>& theNestedActions)
696 SUIT_Desktop* aDesk = application()->desktop();
697 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
698 anAction->setData(theInfo.id);
699 anAction->setCheckable(theInfo.checkable);
700 anAction->setChecked(theInfo.checked);
701 anAction->setEnabled(theInfo.enabled);
702 anAction->setVisible(theInfo.visible);
703 anAction->setIcon(theInfo.icon);
704 anAction->setText(theInfo.text);
705 anAction->setToolTip(theInfo.toolTip);
706 anAction->setShortcut(theInfo.shortcut);
707 anAction->setFont(theInfo.font);
709 int aWBMenu = createMenu(theWBName, -1, -1, 30);
710 int aItemId = createMenu(anAction, aWBMenu);
711 myActionsList.append(aItemId);
712 createMenu(separator(), aWBMenu); /// nested action is always separated of others
714 int aWBTool = createTool(theWBName, theWBName);
718 createTool(anAction, aWBTool);
719 registerCommandToolbar(theWBName, aItemId);
720 createTool(separator(), aWBTool); /// nested action is always separated of others
721 registerCommandToolbar(theWBName, -1);
727 //******************************************************
728 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
729 const QString& theTip, const QIcon& theIcon,
730 const QKeySequence& theKeys, bool isCheckable,
731 const char* theMenuSourceText,
732 const QString& theSubMenu,
733 const int theMenuPosition,
734 const int theSuibMenuPosition)
736 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
737 if (!theSubMenu.isNull())
738 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
740 int aId = getNextCommandId();
741 myActionsList.append(aId);
742 SUIT_Desktop* aDesk = application()->desktop();
744 for (int i = 0; i < theKeys.count(); i++)
746 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
748 aAction->setStatusTip(theTip);
749 aAction->setData(theId);
750 createMenu(aId, aMenu, theMenuPosition);
754 //******************************************************
755 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
757 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
758 createMenu(separator(), aMenu, -1, theMenuPosition);
761 //******************************************************
762 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
767 SUIT_Desktop* aDesktop = application()->desktop();
771 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
775 aToolMgr->append( theAction, theToolBarTitle );
779 //******************************************************
780 QList<QAction*> SHAPERGUI::commandList() const
782 QList<QAction*> aActions;
783 foreach (int aId, myActionsList) {
784 QAction* aCmd = action(aId);
786 aActions.append(aCmd);
792 //******************************************************
793 QMainWindow* SHAPERGUI::desktop() const
795 return application()->desktop();
798 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
799 const std::shared_ptr<Config_FeatureMessage>& theMessage)
801 myFeaturesInfo.insert(theFeatureId, theMessage);
804 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
806 std::shared_ptr<Config_FeatureMessage> aMessage;
807 if (myFeaturesInfo.contains(theFeatureId))
808 aMessage = myFeaturesInfo[theFeatureId];
812 //******************************************************
813 void SHAPERGUI::selectionChanged()
815 LightApp_Module::selectionChanged();
816 myWorkshop->salomeViewerSelectionChanged();
819 //******************************************************
820 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
822 myWorkshop->contextMenuMgr()->updateViewerMenu();
823 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
824 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
828 //******************************************************
829 void SHAPERGUI::createPreferences()
831 LightApp_Preferences* pref = preferences();
834 ModuleBase_Preferences::updateConfigByResources();
835 QString aModName = moduleName();
837 QtxPreferenceItem* item = pref->findItem(aModName, true );
838 if ( item && (!item->isEmpty() )) {
839 item->parentItem()->removeItem(item);
843 int catId = pref->addPreference(aModName, -1 );
846 SHAPERGUI_PrefMgr aMgr(pref, aModName);
847 ModuleBase_Preferences::createEditContent(&aMgr, catId);
849 int viewTab = pref->addItem(tr("Viewer"), catId);
850 // Create other parameters group in viewer tab
851 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
852 pref->setItemProperty("columns", 3, otherGroup);
853 pref->addItem(tr("Faces"), otherGroup,
854 SUIT_PreferenceMgr::Bool,
855 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
856 pref->addItem(tr("Edges"), otherGroup,
857 SUIT_PreferenceMgr::Bool,
858 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
859 pref->addItem(tr("Vertices"), otherGroup,
860 SUIT_PreferenceMgr::Bool,
861 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
863 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
864 pref->setItemProperty("columns", 2, sensitivityGroup);
865 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
866 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
867 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
868 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
870 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
871 pref->setItemProperty("columns", 2, highlightGroup);
872 pref->addItem(tr("In 3d mode"), highlightGroup,
873 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
874 pref->addItem(tr("In 2d mode"), highlightGroup,
875 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
877 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
878 pref->setItemProperty("columns", 4, colorScaleGroup);
879 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
880 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
881 pref->setItemProperty("min", 0, aItem);
882 pref->setItemProperty("max", 1, aItem);
884 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
885 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
886 pref->setItemProperty("min", 0, aItem);
887 pref->setItemProperty("max", 1, aItem);
889 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
890 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
891 pref->setItemProperty("min", 0, aItem);
892 pref->setItemProperty("max", 1, aItem);
894 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
895 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
896 pref->setItemProperty("min", 0, aItem);
897 pref->setItemProperty("max", 1, aItem);
899 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
900 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
901 pref->setItemProperty("min", 0, aItem);
902 pref->setItemProperty("max", 100, aItem);
904 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
905 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
906 pref->setItemProperty("min", 0, aItem);
907 pref->setItemProperty("max", 100, aItem);
909 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
910 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
915 //******************************************************
916 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
918 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
919 QString aVal = aResMgr->stringValue(theSection, theParam);
920 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
921 theParam.toStdString());
922 std::string aValue = aVal.toStdString();
923 if (aValue.empty()) {
924 aValue = aProp->defaultValue();
925 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
927 LightApp_Preferences* pref = preferences();
931 aProp->setValue(aValue);
933 if ((theSection == "Visualization") && (theParam == "selection_color")) {
934 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
935 myWorkshop->displayer()->setSelectionColor(aColor);
938 myWorkshop->displayer()->redisplayObjects();
941 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
943 application()->putInfo(theInfo, theMSecs);
946 bool SHAPERGUI::abortAllOperations()
948 return workshop()->operationMgr()->abortAllOperations();
951 void SHAPERGUI::createFeatureActions()
953 myWorkshop->menuMgr()->createFeatureActions();
956 void SHAPERGUI::onWhatIs(bool isToggled)
958 if (sender() == myWhatIsAction) {
959 QAction* aViewAct = myInspectionPanel->toggleViewAction();
960 aViewAct->blockSignals(true);
961 aViewAct->setChecked(isToggled);
962 aViewAct->blockSignals(false);
963 myInspectionPanel->setVisible(isToggled);
966 myWhatIsAction->blockSignals(true);
967 myWhatIsAction->setChecked(isToggled);
968 myWhatIsAction->blockSignals(false);
969 myInspectionPanel->setVisible(isToggled);
973 void SHAPERGUI::updateModuleVisibilityState()
975 LightApp_Module::updateModuleVisibilityState();
976 onWhatIs(myIsInspectionVisible);
979 void SHAPERGUI::onEditToolbars()
981 SHAPERGUI_ToolbarsDlg aDlg(this);
982 if (aDlg.exec() == QDialog::Accepted) {
986 updateToolbars(aDlg.result());
990 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
992 if (!myToolbars.contains(theToolName))
993 myToolbars[theToolName] = QList<int>();
994 myToolbars[theToolName].append(theCommandId);
997 int SHAPERGUI::getNextCommandId() const
999 QtxActionMenuMgr* aMenuMgr = menuMgr();
1000 QIntList aIds = aMenuMgr->idList();
1001 int aId = aIds.count();
1002 while (action(aId) || myActionsList.contains(aId))
1007 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1009 // Store default toolbars
1010 if (myDefaultToolbars.size() == 0)
1011 myDefaultToolbars = myToolbars;
1013 QtxActionToolMgr* aMgr = toolMgr();
1014 QStringList aToolbars = theNewToolbars.keys();
1015 QIntList aCommands, aOldCmd;
1019 foreach(QString aName, aToolbars) {
1020 aCommands = theNewToolbars[aName];
1021 // Find or create toolbar
1022 if (aMgr->hasToolBar(aName)) {
1023 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1024 aOldCmd = myToolbars[aName];
1027 aToolbarId = aMgr->createToolBar(aName);
1030 foreach(int aCmd, aCommands) {
1033 aAction = separator();
1035 aAction = action(aCmd);
1036 aActionId = aMgr->actionId(aAction);
1037 if (aActionId == -1) {
1039 aMgr->insert(aAction, aToolbarId, aPos);
1042 // Change position of action
1043 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1044 if (aMgr->containsAction(aActionId, aToolbarId))
1045 aMgr->remove(aActionId, aToolbarId);
1046 aMgr->insert(aActionId, aToolbarId, aPos);
1049 aOldCmd.removeAll(aCmd);
1052 // remove extra actions
1053 foreach(int aCmd, aOldCmd) {
1054 aAction = action(aCmd);
1055 aActionId = aMgr->actionId(aAction);
1056 aMgr->remove(aActionId, aToolbarId);
1058 myToolbars.remove(aName);
1060 // Remove extra toolbars
1061 aToolbars = myToolbars.keys();
1062 foreach(QString aName, aToolbars) {
1063 aMgr->removeToolBar(aName);
1065 // Set new toolbars structure
1066 myToolbars = theNewToolbars;
1067 myIsToolbarsModified = true;
1070 void SHAPERGUI::saveToolbarsConfig()
1072 if (!myIsToolbarsModified)
1074 // Save toolbars configuration into map
1075 QMap<QString, QStringList> aToolbarsConfig;
1077 QtxActionToolMgr* aMgr =
1080 QStringList aToolbars = myToolbars.keys();
1081 QIntList aActionsIds;
1082 foreach(QString aName, aToolbars) {
1083 aActionsIds = myToolbars[aName];
1084 QStringList aContent;
1085 foreach(int aId, aActionsIds) {
1087 aContent.append("");
1089 aContent.append(action(aId)->data().toString());
1091 aToolbarsConfig[aName] = aContent;
1093 // Store the configuration into resources
1094 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1095 QStringList aNames = aToolbarsConfig.keys();
1096 QStringList aValues;
1097 foreach(QString aToolbar, aNames) {
1098 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1100 // Remove obsolete parameters from resources
1101 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1102 foreach(QString aName, aOldParams) {
1103 if (!aToolbars.contains(aName))
1104 aResMgr->remove(ToolbarsSection, aName);
1106 // Store current list of free commands
1107 QIntList aFreeCommands = getFreeCommands();
1108 QStringList aFreeList;
1109 foreach(int aId, aFreeCommands) {
1110 aFreeList.append(action(aId)->data().toString());
1112 if (aFreeList.size() > 0)
1113 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1115 myIsToolbarsModified = false;
1118 void SHAPERGUI::loadToolbarsConfig()
1120 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1121 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1122 if (aToolbarNames.size() == 0)
1125 // Create commands map
1126 QMap<QString, int> aCommandsMap;
1128 foreach(int aId, myActionsList) {
1129 aCmdIdStr = action(aId)->data().toString();
1130 aCommandsMap[aCmdIdStr] = aId;
1133 // Create new toolbars structure
1134 QMap<QString, QIntList> aToolbars;
1135 QStringList aCommands;
1136 QIntList aKnownCommands;
1137 QList<QAction*> aActions;
1138 foreach(QString aName, aToolbarNames) {
1139 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1140 if (aName == FreeCommandsParam) {
1141 // The value is a list of free commands
1142 foreach(QString aCommand, aCommands) {
1143 aKnownCommands.append(aCommandsMap[aCommand]);
1147 aToolbars[aName] = QIntList();
1148 if (aCommands.size() > 0) {
1149 foreach(QString aCommand, aCommands) {
1150 if (aCommand.isEmpty())
1151 aToolbars[aName].append(-1);
1152 else if (aCommandsMap.contains(aCommand)) {
1153 int aId = aCommandsMap[aCommand];
1154 aToolbars[aName].append(aId);
1155 aKnownCommands.append(aId);
1161 // Find new and obsolete commands
1162 QIntList aNewCommands = myActionsList;
1163 foreach(int aId, myActionsList) {
1164 if (aKnownCommands.contains(aId)) {
1165 aKnownCommands.removeAll(aId);
1166 aNewCommands.removeAll(aId);
1169 if (aNewCommands.size() > 0) {
1170 // Add new commands to toolbars structure
1171 QStringList aKeys = myToolbars.keys();
1172 foreach(int aNewId, aNewCommands) {
1173 foreach(QString aName, aKeys) {
1174 if (myToolbars[aName].contains(aNewId)) {
1175 if (!aToolbars.contains(aName)) {
1176 aToolbars[aName] = QIntList();
1178 aToolbars[aName].append(aNewId);
1183 if (aKnownCommands.size() > 0) {
1184 // Remove obsolete commands from the toolbars structure
1185 QStringList aKeys = aToolbars.keys();
1186 foreach(int aOldId, aKnownCommands) {
1187 foreach(QString aName, aKeys) {
1188 if (aToolbars[aName].contains(aOldId)) {
1189 aToolbars[aName].removeAll(aOldId);
1190 if (aToolbars[aName].size() == 0)
1191 aToolbars.remove(aName);
1196 updateToolbars(aToolbars);
1197 myIsToolbarsModified = false;
1201 QIntList SHAPERGUI::getFreeCommands() const
1203 QIntList aFreeCommands;
1204 QtxActionToolMgr* aMgr = toolMgr();
1207 QMap<QString, QIntList>::const_iterator aIt;
1208 QIntList aShaperActions = shaperActions();
1209 foreach(int aCmd, aShaperActions) {
1210 anAction = action(aCmd);
1211 aId = aMgr->actionId(anAction);
1212 if (!aMgr->containsAction(aId))
1213 aFreeCommands.append(aCmd);
1215 return aFreeCommands;
1218 void SHAPERGUI::resetToolbars()
1220 if (!myDefaultToolbars.isEmpty())
1221 updateToolbars(myDefaultToolbars);
1222 myIsToolbarsModified = false;
1223 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1224 aResMgr->remove(ToolbarsSection);
1227 void SHAPERGUI::publishToStudy()
1229 if (isActiveModule())
1230 myWorkshop->module()->launchOperation("PublishToStudy", false);