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>
70 #include <Standard_Version.hxx>
72 #include <QDockWidget>
78 #include <ModelAPI_Session.h>
80 #if OCC_VERSION_HEX < 0x070400
81 #define SALOME_PATCH_FOR_CTRL_WHEEL
85 SHAPERGUI_EXPORT CAM_Module* createModule()
87 return new SHAPERGUI();
90 SHAPERGUI_EXPORT char* getModuleVersion()
97 static const QString ToolbarsSection("SHAPER_Toolbars");
98 static const QString FreeCommandsParam("OutOFToolbars");
102 * Class for preferences management
104 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
108 /// \param theMgr preferences manager of SALOME
109 /// \param theModName name of the module
110 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
111 myMgr(theMgr), myModName(theModName) {}
113 virtual int addPreference(const QString& theLbl, int pId,
114 SUIT_PreferenceMgr::PrefItemType theType,
115 const QString& theSection, const QString& theName )
117 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
120 virtual void setItemProperty(const QString& thePropName,
121 const QVariant& theValue,
122 const int theId = -1)
124 myMgr->setItemProperty(thePropName, theValue, theId);
128 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
131 LightApp_Preferences* myMgr;
138 //******************************************************
139 SHAPERGUI::SHAPERGUI()
140 : LightApp_Module("SHAPER"),
141 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
142 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
145 myWorkshop = new XGUI_Workshop(this);
146 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
147 this, SLOT(onUpdateCommandStatus()));
149 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
151 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
153 // It will be called in XGUI_Workshop::startApplication
154 // ModuleBase_Preferences::loadCustomProps();
157 //******************************************************
158 SHAPERGUI::~SHAPERGUI()
161 delete myProxyViewer;
164 //******************************************************
165 void SHAPERGUI::initialize(CAM_Application* theApp)
167 LightApp_Module::initialize(theApp);
169 myWorkshop->startApplication();
170 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
173 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
176 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
177 int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
179 int aId = getNextCommandId();
180 myActionsList.append(aId);
181 SUIT_Desktop* aDesk = application()->desktop();
182 QString aTip = tr("Show inspection window");
183 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
184 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
185 myWhatIsAction->setStatusTip(aTip);
186 myWhatIsAction->setData("INSPECTION_CMD");
187 createMenu(aId, aSubMenu, 0);
189 QString aToolName = tr("Inspection");
190 int aTool = createTool(aToolName);
194 createTool(myWhatIsAction, aTool);
195 registerCommandToolbar(aToolName, aId);
197 // Define Edit toolbars command
198 aId = getNextCommandId();
199 //myActionsList.append(aId); Do not use it for editing of toolbars
200 aTip = tr("Edit toolbars of the module");
204 createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
205 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
206 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
210 createMenu(aId, aEditMenu);
212 if (!myInspectionPanel) {
213 myInspectionPanel = myWorkshop->inspectionPanel();
214 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
215 this, SLOT(onWhatIs(bool)));
217 hideInternalWindows();
219 // Initialize viewer proxy if OCC viewer is already exist
220 ViewManagerList aOCCViewManagers;
221 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
222 if (aOCCViewManagers.size() > 0) {
223 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
224 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
226 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
227 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
229 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
230 aViewPort->installEventFilter(aViewer);
231 Handle(V3d_View) aView = aViewPort->getView();
232 aViewer->SetScale(aView, aView->Camera()->Scale());
233 // We can not create selector here because other modules will be deactivated later
234 //onViewManagerAdded(aMgr);
238 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
239 aDataModel->initRootObject();
242 //******************************************************
243 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
245 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
248 //******************************************************
249 void SHAPERGUI::viewManagers(QStringList& theList) const
251 theList.append(OCCViewer_Viewer::Type());
254 //******************************************************
255 // We can not create selector in this method because it can be called when
256 // SHAPER module is not active. Take into account that creation of our selector
257 // leads to switching OFF all other selectors
258 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
260 // // if there are created viewer managers, we should try to create viewer
261 // // selector and initialize viewer with it. It sets interactive context to the
262 // // proxy viewer. If study is opened, CAM application calls this method before the open()
264 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
265 // // we need to connect to the viewer before it. Here,
266 // // it seems the most appropriate place for this
267 // // according to SALOME architecture.
268 // if (!mySelector) {
269 // ViewManagerList OCCViewManagers;
270 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
271 // if (OCCViewManagers.size() > 0) {
272 // mySelector = createSelector(OCCViewManagers.first());
275 // LightApp_Module::connectToStudy(theStudy);
278 //******************************************************
279 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
281 ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet
283 // this must be done in the initialization and in activation (on the second activation
284 // initialization in not called, so SComponent must be added anyway
285 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
286 aDataModel->initRootObject();
289 bool isDone = LightApp_Module::activateModule(theStudy);
290 loadToolbarsConfig();
296 QObject* aObj = myWorkshop->objectBrowser()->parent();
297 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
299 myWorkshop->objectBrowser()->setVisible(true);
300 aObjDoc->setVisible(true);
301 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
302 aObjDoc->toggleViewAction()->setVisible(true);
305 myInspectionPanel->toggleViewAction()->setVisible(true);
307 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
308 if (myIsFacesPanelVisible)
309 myWorkshop->facesPanel()->show();
310 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
313 ViewManagerList OCCViewManagers;
314 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
315 if (OCCViewManagers.size() > 0) {
316 onViewManagerAdded(OCCViewManagers.first());
319 // it should be performed after the selector creation in order to have AISContext
320 myWorkshop->activateModule();
321 //action(myEraseAll)->setEnabled(false);
324 myWorkshop->objectBrowser()->rebuildDataTree();
325 myWorkshop->updateCommandStatus();
329 myWorkshop->updateCommandStatus();
331 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
332 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
333 myIsEditEnabled = getApp()->isEditEnabled();
334 getApp()->setEditEnabled(false);
336 // this following row is caused by #187 bug.
337 // SALOME saves the dock widget positions before deactivateModule() and
338 // load it after the module activation. So, if the panel is visible before
339 // deactivate, it becomes visible after activate.
340 // In order to avoid the visible property panel, the widget position save is
341 // switch off in this module
342 aResMgr->setValue("Study", "store_positions", false);
344 // Synchronize displayed objects
345 Handle(AIS_InteractiveContext) aContext;
346 if (mySelector && mySelector->viewer())
347 aContext = mySelector->viewer()->getAISContext();
349 if (!aContext.IsNull()) {
350 XGUI_Displayer* aDisp = myWorkshop->displayer();
351 QObjectPtrList aObjList = aDisp->displayedObjects();
353 if (myOldSelectionColor.size() == 0)
354 myOldSelectionColor = aDisp->selectionColor();
356 AIS_ListOfInteractive aList;
357 aContext->DisplayedObjects(aList);
358 AIS_ListIteratorOfListOfInteractive aLIt;
359 Handle(AIS_InteractiveObject) anAISIO;
360 foreach (ObjectPtr aObj, aObjList) {
361 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
362 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
364 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
365 anAISIO = aLIt.Value();
366 if (anAISIO.get() == aAIS.get()) {
372 aObj->setDisplayed(false);
373 //aDisp->erase(aObj, false);
376 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
378 myProxyViewer->activateViewer(true);
380 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
381 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
382 this, SLOT(onScriptLoaded()));
384 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
385 getApp(), SLOT(onSaveDoc()));
386 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
387 getApp(), SLOT(onSaveAsDoc()));
389 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
390 this, SLOT(onSaveDocByShaper()));
391 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
392 this, SLOT(onSaveAsDocByShaper()));
397 //******************************************************
398 void SHAPERGUI::hideInternalWindows()
400 myProxyViewer->activateViewer(false);
404 QObject* aObj = myWorkshop->objectBrowser()->parent();
405 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
407 aObjDoc->setVisible(false);
408 myWorkshop->objectBrowser()->setVisible(false);
409 aObjDoc->toggleViewAction()->setVisible(false);
412 myInspectionPanel->hide();
413 myInspectionPanel->toggleViewAction()->setVisible(false);
415 myWorkshop->facesPanel()->hide();
416 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
418 myWorkshop->propertyPanel()->hide();
419 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
421 myWorkshop->hidePanel(myWorkshop->facesPanel());
425 //******************************************************
426 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
428 saveToolbarsConfig();
429 myWorkshop->deactivateModule();
431 myIsInspectionVisible = myInspectionPanel->isVisible();
432 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
433 hideInternalWindows();
436 // the active operation should be stopped for the next activation.
437 // There should not be active operation and visualized preview.
438 // Abort operation should be performed before the selection's remove
439 // because the displayed objects should be removed from the viewer, but
440 // the AIS context is obtained from the selector.
441 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
442 while (anOperation) {
443 anOperation->abort();
444 anOperation = myWorkshop->operationMgr()->currentOperation();
446 // Delete selector because it has to be redefined on next activation
448 // Restore size of arrows of trihedron
449 if (myAxisArrowRate > 0) {
450 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
451 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
452 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
453 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
454 aContext->Redisplay(aTrihedron, false);
456 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
457 myProxyViewer->setSelector(0);
459 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
460 QList<SUIT_Selector*> aList;
461 aMgr->selectors(aList);
462 foreach(SUIT_Selector* aSel, aList) {
463 aSel->setEnabled(aSel != mySelector);
470 //myWorkshop->contextMenuMgr()->disconnectViewer();
472 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
473 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
474 getApp()->setEditEnabled(myIsEditEnabled);
476 myOldSelectionColor.clear();
478 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
479 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
480 this, SLOT(onScriptLoaded()));
482 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
483 this, SLOT(onSaveDocByShaper()));
484 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
485 this, SLOT(onSaveAsDocByShaper()));
487 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
488 getApp(), SLOT(onSaveDoc()));
489 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
490 getApp(), SLOT(onSaveAsDoc()));
494 return LightApp_Module::deactivateModule(theStudy);
497 //******************************************************
498 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
501 mySelector = createSelector(theMgr);
502 myWorkshop->selectionActivate()->updateSelectionFilters();
503 myWorkshop->selectionActivate()->updateSelectionModes();
504 myWorkshop->synchronizeViewer();
508 //******************************************************
509 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
512 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
513 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
514 if (mySelector->viewer() == aViewer) {
515 XGUI_Displayer* aDisp = myWorkshop->displayer();
516 QObjectPtrList aObjects = aDisp->displayedObjects();
518 foreach(ObjectPtr aObj, aObjects) {
519 aObj->setDisplayed(false);
520 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
522 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
523 aRes->setDisplayed(false);
527 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
528 myProxyViewer->setSelector(0);
532 myWorkshop->module()->clearViewer();
538 //******************************************************
539 QtxPopupMgr* SHAPERGUI::popupMgr()
542 myPopupMgr = new QtxPopupMgr( 0, this );
546 //******************************************************
547 void SHAPERGUI::onDefaultPreferences()
549 // reset main resources
550 ModuleBase_Preferences::resetResourcePreferences(preferences());
551 // reset plugin's resources
552 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
554 myWorkshop->displayer()->redisplayObjects();
557 //******************************************************
558 void SHAPERGUI::onScriptLoaded()
560 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
561 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
562 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
563 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
564 // it manually (because this method of application is protected)
565 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
568 myWorkshop->displayer()->updateViewer();
569 myWorkshop->updateCommandStatus();
572 //******************************************************
573 void SHAPERGUI::onSaveDocByShaper()
575 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
578 getApp()->onSaveDoc();
581 //******************************************************
582 void SHAPERGUI::onSaveAsDocByShaper()
584 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
587 getApp()->onSaveAsDoc();
590 //******************************************************
591 void SHAPERGUI::onUpdateCommandStatus()
593 getApp()->updateActions();
596 //******************************************************
597 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
599 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
600 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
602 // Remember current length of arrow of axis
603 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
604 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
605 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
607 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
608 getApp()->selectionMgr());
609 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
610 aViewer->setUseLocalSelection(true);
612 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
613 QList<SUIT_Selector*> aList;
614 aMgr->selectors(aList);
615 foreach(SUIT_Selector* aSel, aList)
617 aSel->setEnabled(aSel == aSelector);
619 myProxyViewer->setSelector(aSelector);
621 if (myOldSelectionColor.size() == 0)
622 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
624 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
625 myWorkshop->displayer()->setSelectionColor(aColor);
627 // Cause scaling of arrows of axis and dimensions
628 myWorkshop->module()->onViewTransformed();
635 //******************************************************
636 CAM_DataModel* SHAPERGUI::createDataModel()
638 return new SHAPERGUI_DataModel(this);
641 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
642 const bool isAddSeparator)
644 return addFeature(theWBName,
648 //Issue #650: in the SALOME mode the tooltip should be same as text
657 //******************************************************
658 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
659 const QString& theId, const QString& theTitle, const QString& theTip,
660 const QIcon& theIcon, const QKeySequence& theKeys,
661 bool isCheckable, const bool isAddSeparator,
662 const QString& theStatusTip)
664 static QString aLastTool = "";
666 if (aLastTool.isEmpty())
667 aLastTool = theWBName;
668 else if (theWBName != aLastTool) {
669 aLastTool = theWBName;
671 desktop()->addToolBarBreak();
677 int aId = getNextCommandId();
678 myActionsList.append(aId);
679 SUIT_Desktop* aDesk = application()->desktop();
681 for (int i = 0; i < theKeys.count(); i++)
683 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
685 aAction->setStatusTip(theStatusTip);
687 aAction->setData(theId);
689 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
693 createMenu(aId, aWBMenu);
695 createMenu(separator(), aWBMenu);
697 int aWBTool = createTool(theTBName, theTBName);
701 createTool(aId, aWBTool);
702 registerCommandToolbar(theTBName, aId);
703 if (isAddSeparator) {
704 createTool(separator(), aWBTool);
705 registerCommandToolbar(theTBName, -1);
710 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
712 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
715 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
716 const ActionInfo& theInfo,
717 const QList<QAction*>& theNestedActions)
719 SUIT_Desktop* aDesk = application()->desktop();
720 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
721 anAction->setData(theInfo.id);
722 anAction->setCheckable(theInfo.checkable);
723 anAction->setChecked(theInfo.checked);
724 anAction->setEnabled(theInfo.enabled);
725 anAction->setVisible(theInfo.visible);
726 anAction->setIcon(theInfo.icon);
727 anAction->setText(theInfo.text);
728 anAction->setToolTip(theInfo.toolTip);
729 anAction->setShortcut(theInfo.shortcut);
730 anAction->setFont(theInfo.font);
732 int aWBMenu = createMenu(theWBName, -1, -1, 30);
733 int aItemId = createMenu(anAction, aWBMenu);
734 myActionsList.append(aItemId);
735 createMenu(separator(), aWBMenu); /// nested action is always separated of others
737 int aWBTool = createTool(theWBName, theWBName);
741 createTool(anAction, aWBTool);
742 registerCommandToolbar(theWBName, aItemId);
743 createTool(separator(), aWBTool); /// nested action is always separated of others
744 registerCommandToolbar(theWBName, -1);
750 //******************************************************
751 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
752 const QString& theTip, const QIcon& theIcon,
753 const QKeySequence& theKeys, bool isCheckable,
754 const char* theMenuSourceText,
755 const QString& theSubMenu,
756 const int theMenuPosition,
757 const int theSuibMenuPosition)
759 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
760 if (!theSubMenu.isNull())
761 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
763 int aId = getNextCommandId();
764 myActionsList.append(aId);
765 SUIT_Desktop* aDesk = application()->desktop();
767 for (int i = 0; i < theKeys.count(); i++)
769 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
771 aAction->setStatusTip(theTip);
772 aAction->setData(theId);
773 createMenu(aId, aMenu, theMenuPosition);
777 //******************************************************
778 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
780 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
781 createMenu(separator(), aMenu, -1, theMenuPosition);
784 //******************************************************
785 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
790 SUIT_Desktop* aDesktop = application()->desktop();
794 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
798 aToolMgr->append( theAction, theToolBarTitle );
802 //******************************************************
803 QList<QAction*> SHAPERGUI::commandList() const
805 QList<QAction*> aActions;
806 foreach (int aId, myActionsList) {
807 QAction* aCmd = action(aId);
809 aActions.append(aCmd);
815 //******************************************************
816 QMainWindow* SHAPERGUI::desktop() const
818 return application()->desktop();
821 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
822 const std::shared_ptr<Config_FeatureMessage>& theMessage)
824 myFeaturesInfo.insert(theFeatureId, theMessage);
827 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
829 std::shared_ptr<Config_FeatureMessage> aMessage;
830 if (myFeaturesInfo.contains(theFeatureId))
831 aMessage = myFeaturesInfo[theFeatureId];
835 //******************************************************
836 void SHAPERGUI::selectionChanged()
838 LightApp_Module::selectionChanged();
839 myWorkshop->salomeViewerSelectionChanged();
842 //******************************************************
843 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
845 myWorkshop->contextMenuMgr()->updateViewerMenu();
846 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
847 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
851 //******************************************************
852 void SHAPERGUI::createPreferences()
854 LightApp_Preferences* pref = preferences();
857 ModuleBase_Preferences::updateConfigByResources();
858 QString aModName = moduleName();
860 QtxPreferenceItem* item = pref->findItem(aModName, true );
861 if ( item && (!item->isEmpty() )) {
862 item->parentItem()->removeItem(item);
866 int catId = pref->addPreference(aModName, -1 );
869 SHAPERGUI_PrefMgr aMgr(pref, aModName);
870 ModuleBase_Preferences::createEditContent(&aMgr, catId);
872 int viewTab = pref->addItem(tr("Viewer"), catId);
873 // Create other parameters group in viewer tab
874 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
875 pref->setItemProperty("columns", 3, otherGroup);
876 pref->addItem(tr("Faces"), otherGroup,
877 SUIT_PreferenceMgr::Bool,
878 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
879 pref->addItem(tr("Edges"), otherGroup,
880 SUIT_PreferenceMgr::Bool,
881 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
882 pref->addItem(tr("Vertices"), otherGroup,
883 SUIT_PreferenceMgr::Bool,
884 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
886 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
887 pref->setItemProperty("columns", 2, sensitivityGroup);
888 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
889 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
890 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
891 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
893 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
894 pref->setItemProperty("columns", 2, highlightGroup);
895 pref->addItem(tr("In 3d mode"), highlightGroup,
896 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
897 pref->addItem(tr("In 2d mode"), highlightGroup,
898 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
900 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
901 pref->setItemProperty("columns", 4, colorScaleGroup);
902 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
903 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
904 pref->setItemProperty("min", 0, aItem);
905 pref->setItemProperty("max", 1, aItem);
907 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
908 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
909 pref->setItemProperty("min", 0, aItem);
910 pref->setItemProperty("max", 1, aItem);
912 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
913 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
914 pref->setItemProperty("min", 0, aItem);
915 pref->setItemProperty("max", 1, aItem);
917 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
918 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
919 pref->setItemProperty("min", 0, aItem);
920 pref->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 pref->setItemProperty("min", 0, aItem);
925 pref->setItemProperty("max", 100, aItem);
927 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
928 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
929 pref->setItemProperty("min", 0, aItem);
930 pref->setItemProperty("max", 100, aItem);
932 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
933 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
938 //******************************************************
939 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
941 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
942 QString aVal = aResMgr->stringValue(theSection, theParam);
943 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
944 theParam.toStdString());
945 std::string aValue = aVal.toStdString();
946 if (aValue.empty()) {
947 aValue = aProp->defaultValue();
948 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
950 LightApp_Preferences* pref = preferences();
954 aProp->setValue(aValue);
956 if (theSection == "Visualization") {
957 if (theParam == "selection_color") {
958 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
959 myWorkshop->displayer()->setSelectionColor(aColor);
961 if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
963 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
964 if (!aTrihedron.IsNull()) {
965 bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
966 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
968 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
969 Handle(V3d_View) aView = aViewer->activeView();
972 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
973 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
974 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
975 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
976 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
977 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
978 aContext->Redisplay(aTrihedron, true);
981 else if (myAxisArrowRate > 0) {
982 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
983 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
984 aContext->Redisplay(aTrihedron, true);
990 myWorkshop->displayer()->redisplayObjects();
993 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
995 application()->putInfo(theInfo, theMSecs);
998 bool SHAPERGUI::abortAllOperations()
1000 return workshop()->operationMgr()->abortAllOperations();
1003 void SHAPERGUI::createFeatureActions()
1005 myWorkshop->menuMgr()->createFeatureActions();
1008 void SHAPERGUI::onWhatIs(bool isToggled)
1010 if (sender() == myWhatIsAction) {
1011 QAction* aViewAct = myInspectionPanel->toggleViewAction();
1012 aViewAct->blockSignals(true);
1013 aViewAct->setChecked(isToggled);
1014 aViewAct->blockSignals(false);
1015 myInspectionPanel->setVisible(isToggled);
1018 myWhatIsAction->blockSignals(true);
1019 myWhatIsAction->setChecked(isToggled);
1020 myWhatIsAction->blockSignals(false);
1021 myInspectionPanel->setVisible(isToggled);
1025 void SHAPERGUI::updateModuleVisibilityState()
1027 LightApp_Module::updateModuleVisibilityState();
1028 onWhatIs(myIsInspectionVisible);
1031 void SHAPERGUI::onEditToolbars()
1033 SHAPERGUI_ToolbarsDlg aDlg(this);
1034 if (aDlg.exec() == QDialog::Accepted) {
1038 updateToolbars(aDlg.result());
1042 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1044 if (!myToolbars.contains(theToolName))
1045 myToolbars[theToolName] = QList<int>();
1046 myToolbars[theToolName].append(theCommandId);
1049 int SHAPERGUI::getNextCommandId() const
1051 QtxActionMenuMgr* aMenuMgr = menuMgr();
1052 QIntList aIds = aMenuMgr->idList();
1053 int aId = aIds.count();
1054 while (action(aId) || myActionsList.contains(aId))
1059 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1061 // Store default toolbars
1062 if (myDefaultToolbars.size() == 0)
1063 myDefaultToolbars = myToolbars;
1065 QtxActionToolMgr* aMgr = toolMgr();
1066 QStringList aToolbars = theNewToolbars.keys();
1067 QIntList aCommands, aOldCmd;
1071 foreach(QString aName, aToolbars) {
1072 aCommands = theNewToolbars[aName];
1073 // Find or create toolbar
1074 if (aMgr->hasToolBar(aName)) {
1075 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1076 aOldCmd = myToolbars[aName];
1079 aToolbarId = aMgr->createToolBar(aName);
1082 foreach(int aCmd, aCommands) {
1085 aAction = separator();
1087 aAction = action(aCmd);
1088 aActionId = aMgr->actionId(aAction);
1089 if (aActionId == -1) {
1091 aMgr->insert(aAction, aToolbarId, aPos);
1094 // Change position of action
1095 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1096 if (aMgr->containsAction(aActionId, aToolbarId))
1097 aMgr->remove(aActionId, aToolbarId);
1098 aMgr->insert(aActionId, aToolbarId, aPos);
1101 aOldCmd.removeAll(aCmd);
1104 // remove extra actions
1105 foreach(int aCmd, aOldCmd) {
1106 aAction = action(aCmd);
1107 aActionId = aMgr->actionId(aAction);
1108 aMgr->remove(aActionId, aToolbarId);
1110 myToolbars.remove(aName);
1112 // Remove extra toolbars
1113 aToolbars = myToolbars.keys();
1114 foreach(QString aName, aToolbars) {
1115 aMgr->removeToolBar(aName);
1117 // Set new toolbars structure
1118 myToolbars = theNewToolbars;
1119 myIsToolbarsModified = true;
1122 void SHAPERGUI::saveToolbarsConfig()
1124 if (!myIsToolbarsModified)
1126 // Save toolbars configuration into map
1127 QMap<QString, QStringList> aToolbarsConfig;
1129 QtxActionToolMgr* aMgr =
1132 QStringList aToolbars = myToolbars.keys();
1133 QIntList aActionsIds;
1134 foreach(QString aName, aToolbars) {
1135 aActionsIds = myToolbars[aName];
1136 QStringList aContent;
1137 foreach(int aId, aActionsIds) {
1139 aContent.append("");
1141 aContent.append(action(aId)->data().toString());
1143 aToolbarsConfig[aName] = aContent;
1145 // Store the configuration into resources
1146 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1147 QStringList aNames = aToolbarsConfig.keys();
1148 QStringList aValues;
1149 foreach(QString aToolbar, aNames) {
1150 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1152 // Remove obsolete parameters from resources
1153 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1154 foreach(QString aName, aOldParams) {
1155 if (!aToolbars.contains(aName))
1156 aResMgr->remove(ToolbarsSection, aName);
1158 // Store current list of free commands
1159 QIntList aFreeCommands = getFreeCommands();
1160 QStringList aFreeList;
1161 foreach(int aId, aFreeCommands) {
1162 aFreeList.append(action(aId)->data().toString());
1164 if (aFreeList.size() > 0)
1165 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1167 myIsToolbarsModified = false;
1170 void SHAPERGUI::loadToolbarsConfig()
1172 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1173 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1174 if (aToolbarNames.size() == 0)
1177 // Create commands map
1178 QMap<QString, int> aCommandsMap;
1180 foreach(int aId, myActionsList) {
1181 aCmdIdStr = action(aId)->data().toString();
1182 aCommandsMap[aCmdIdStr] = aId;
1185 // Create new toolbars structure
1186 QMap<QString, QIntList> aToolbars;
1187 QStringList aCommands;
1188 QIntList aKnownCommands;
1189 QList<QAction*> aActions;
1190 foreach(QString aName, aToolbarNames) {
1191 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1192 if (aName == FreeCommandsParam) {
1193 // The value is a list of free commands
1194 foreach(QString aCommand, aCommands) {
1195 aKnownCommands.append(aCommandsMap[aCommand]);
1199 aToolbars[aName] = QIntList();
1200 if (aCommands.size() > 0) {
1201 foreach(QString aCommand, aCommands) {
1202 if (aCommand.isEmpty())
1203 aToolbars[aName].append(-1);
1204 else if (aCommandsMap.contains(aCommand)) {
1205 int aId = aCommandsMap[aCommand];
1206 aToolbars[aName].append(aId);
1207 aKnownCommands.append(aId);
1213 // Find new and obsolete commands
1214 QIntList aNewCommands = myActionsList;
1215 foreach(int aId, myActionsList) {
1216 if (aKnownCommands.contains(aId)) {
1217 aKnownCommands.removeAll(aId);
1218 aNewCommands.removeAll(aId);
1221 if (aNewCommands.size() > 0) {
1222 // Add new commands to toolbars structure
1223 QStringList aKeys = myToolbars.keys();
1224 foreach(int aNewId, aNewCommands) {
1225 foreach(QString aName, aKeys) {
1226 if (myToolbars[aName].contains(aNewId)) {
1227 if (!aToolbars.contains(aName)) {
1228 aToolbars[aName] = QIntList();
1230 aToolbars[aName].append(aNewId);
1235 if (aKnownCommands.size() > 0) {
1236 // Remove obsolete commands from the toolbars structure
1237 QStringList aKeys = aToolbars.keys();
1238 foreach(int aOldId, aKnownCommands) {
1239 foreach(QString aName, aKeys) {
1240 if (aToolbars[aName].contains(aOldId)) {
1241 aToolbars[aName].removeAll(aOldId);
1242 if (aToolbars[aName].size() == 0)
1243 aToolbars.remove(aName);
1248 updateToolbars(aToolbars);
1249 myIsToolbarsModified = false;
1253 QIntList SHAPERGUI::getFreeCommands() const
1255 QIntList aFreeCommands;
1256 QtxActionToolMgr* aMgr = toolMgr();
1259 QMap<QString, QIntList>::const_iterator aIt;
1260 QIntList aShaperActions = shaperActions();
1261 foreach(int aCmd, aShaperActions) {
1262 anAction = action(aCmd);
1263 aId = aMgr->actionId(anAction);
1264 if (!aMgr->containsAction(aId))
1265 aFreeCommands.append(aCmd);
1267 return aFreeCommands;
1270 void SHAPERGUI::resetToolbars()
1272 if (!myDefaultToolbars.isEmpty())
1273 updateToolbars(myDefaultToolbars);
1274 myIsToolbarsModified = false;
1275 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1276 aResMgr->remove(ToolbarsSection);
1279 void SHAPERGUI::publishToStudy()
1281 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument())
1282 myWorkshop->module()->launchOperation("PublishToStudy", false);