1 // Copyright (C) 2014-2022 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>
79 #include <Events_MessageBool.h>
81 #if OCC_VERSION_HEX < 0x070400
82 #define SALOME_PATCH_FOR_CTRL_WHEEL
86 SHAPERGUI_EXPORT CAM_Module* createModule()
88 return new SHAPERGUI();
91 SHAPERGUI_EXPORT char* getModuleVersion()
98 static const QString ToolbarsSection("SHAPER_Toolbars");
99 static const QString FreeCommandsParam("OutOFToolbars");
103 * Class for preferences management
105 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
109 /// \param theMgr preferences manager of SALOME
110 /// \param theModName name of the module
111 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
112 myMgr(theMgr), myModName(theModName) {}
114 virtual int addPreference(const QString& theLbl, int pId,
115 SUIT_PreferenceMgr::PrefItemType theType,
116 const QString& theSection, const QString& theName )
118 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
121 virtual void setItemProperty(const QString& thePropName,
122 const QVariant& theValue,
123 const int theId = -1)
125 myMgr->setItemProperty(thePropName, theValue, theId);
129 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
132 LightApp_Preferences* myMgr;
139 //******************************************************
140 SHAPERGUI::SHAPERGUI()
141 : LightApp_Module("SHAPER"),
142 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
143 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
146 myWorkshop = new XGUI_Workshop(this);
147 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
148 this, SLOT(onUpdateCommandStatus()));
150 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
152 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
154 // It will be called in XGUI_Workshop::startApplication
155 // ModuleBase_Preferences::loadCustomProps();
158 //******************************************************
159 SHAPERGUI::~SHAPERGUI()
162 delete myProxyViewer;
165 //******************************************************
166 void SHAPERGUI::initialize(CAM_Application* theApp)
168 LightApp_Module::initialize(theApp);
170 myWorkshop->startApplication();
171 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
174 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
177 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
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, aMenu, 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*/);
691 if( theId == "PointCoordinates" )
692 createMenu(separator(), aWBMenu);
697 createMenu(aId, aWBMenu);
700 createMenu(separator(), aWBMenu);
702 int aWBTool = createTool(theTBName, theTBName);
706 createTool(aId, aWBTool);
707 registerCommandToolbar(theTBName, aId);
708 if (isAddSeparator) {
709 createTool(separator(), aWBTool);
710 registerCommandToolbar(theTBName, -1);
715 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
717 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
720 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
721 const ActionInfo& theInfo,
722 const QList<QAction*>& theNestedActions)
724 SUIT_Desktop* aDesk = application()->desktop();
725 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
726 anAction->setData(theInfo.id);
727 anAction->setCheckable(theInfo.checkable);
728 anAction->setChecked(theInfo.checked);
729 anAction->setEnabled(theInfo.enabled);
730 anAction->setVisible(theInfo.visible);
731 anAction->setIcon(theInfo.icon);
732 anAction->setText(theInfo.text);
733 anAction->setToolTip(theInfo.toolTip);
734 anAction->setShortcut(theInfo.shortcut);
735 anAction->setFont(theInfo.font);
737 int aWBMenu = createMenu(theWBName, -1, -1, 30);
738 int aItemId = createMenu(anAction, aWBMenu);
739 myActionsList.append(aItemId);
740 createMenu(separator(), aWBMenu); /// nested action is always separated of others
742 int aWBTool = createTool(theWBName, theWBName);
746 createTool(anAction, aWBTool);
747 registerCommandToolbar(theWBName, aItemId);
748 createTool(separator(), aWBTool); /// nested action is always separated of others
749 registerCommandToolbar(theWBName, -1);
755 //******************************************************
756 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
757 const QString& theTip, const QIcon& theIcon,
758 const QKeySequence& theKeys, bool isCheckable,
759 const char* theMenuSourceText,
760 const QString& theSubMenu,
761 const int theMenuPosition,
762 const int theSuibMenuPosition)
764 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
765 if (!theSubMenu.isNull())
766 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
768 int aId = getNextCommandId();
769 myActionsList.append(aId);
770 SUIT_Desktop* aDesk = application()->desktop();
772 for (int i = 0; i < theKeys.count(); i++)
774 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
776 aAction->setStatusTip(theTip);
777 aAction->setData(theId);
778 createMenu(aId, aMenu, theMenuPosition);
782 //******************************************************
783 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
785 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
786 createMenu(separator(), aMenu, -1, theMenuPosition);
789 //******************************************************
790 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
795 SUIT_Desktop* aDesktop = application()->desktop();
799 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
803 aToolMgr->append( theAction, theToolBarTitle );
807 //******************************************************
808 QList<QAction*> SHAPERGUI::commandList() const
810 QList<QAction*> aActions;
811 foreach (int aId, myActionsList) {
812 QAction* aCmd = action(aId);
814 aActions.append(aCmd);
820 //******************************************************
821 QMainWindow* SHAPERGUI::desktop() const
823 return application()->desktop();
826 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
827 const std::shared_ptr<Config_FeatureMessage>& theMessage)
829 myFeaturesInfo.insert(theFeatureId, theMessage);
832 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
834 std::shared_ptr<Config_FeatureMessage> aMessage;
835 if (myFeaturesInfo.contains(theFeatureId))
836 aMessage = myFeaturesInfo[theFeatureId];
840 //******************************************************
841 void SHAPERGUI::selectionChanged()
843 LightApp_Module::selectionChanged();
844 myWorkshop->salomeViewerSelectionChanged();
847 //******************************************************
848 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
850 myWorkshop->contextMenuMgr()->updateViewerMenu();
851 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
852 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
856 //******************************************************
857 void SHAPERGUI::createPreferences()
859 LightApp_Preferences* aPref = preferences();
862 ModuleBase_Preferences::updateConfigByResources();
863 QString aModName = moduleName();
865 QtxPreferenceItem* item = aPref->findItem(aModName, true );
866 if ( item && (!item->isEmpty() )) {
867 item->parentItem()->removeItem(item);
871 int catId = aPref->addPreference(aModName, -1 );
874 SHAPERGUI_PrefMgr aMgr(aPref, aModName);
875 ModuleBase_Preferences::createEditContent(&aMgr, catId);
877 int viewTab = aPref->addItem(tr("Viewer"), catId);
878 // Create other parameters group in viewer tab
879 int otherGroup = aPref->addItem(tr("Default selection"), viewTab);
880 aPref->setItemProperty("columns", 3, otherGroup);
881 aPref->addItem(tr("Faces"), otherGroup,
882 SUIT_PreferenceMgr::Bool,
883 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
884 aPref->addItem(tr("Edges"), otherGroup,
885 SUIT_PreferenceMgr::Bool,
886 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
887 aPref->addItem(tr("Vertices"), otherGroup,
888 SUIT_PreferenceMgr::Bool,
889 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
891 int sensitivityGroup = aPref->addItem(tr("Selection sensitivity"), viewTab);
892 aPref->setItemProperty("columns", 2, sensitivityGroup);
893 aPref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
894 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
895 aPref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
896 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
898 int highlightGroup = aPref->addItem(tr("Additional highlighting"), viewTab);
899 aPref->setItemProperty("columns", 2, highlightGroup);
900 aPref->addItem(tr("In 3d mode"), highlightGroup,
901 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
902 aPref->addItem(tr("In 2d mode"), highlightGroup,
903 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
905 int colorScaleGroup = aPref->addItem(tr("Color scale"), viewTab);
906 aPref->setItemProperty("columns", 4, colorScaleGroup);
907 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
908 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
909 aPref->setItemProperty("min", 0, aItem);
910 aPref->setItemProperty("max", 1, aItem);
911 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
912 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
913 aPref->setItemProperty("min", 0, aItem);
914 aPref->setItemProperty("max", 1, aItem);
915 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
916 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
917 aPref->setItemProperty("min", 0, aItem);
918 aPref->setItemProperty("max", 1, aItem);
919 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
920 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
921 aPref->setItemProperty("min", 0, aItem);
922 aPref->setItemProperty("max", 1, aItem);
923 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
924 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
925 aPref->setItemProperty("min", 0, aItem);
926 aPref->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 aPref->setItemProperty("min", 0, aItem);
930 aPref->setItemProperty("max", 100, aItem);
931 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
932 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
934 int aGroupNamesGroup = aMgr.addPreference(tr("Group names display"), viewTab,
935 SUIT_PreferenceMgr::GroupBox , ModuleBase_Preferences::VIEWER_SECTION, "group_names_display");
936 aPref->setItemProperty("columns", 3, aGroupNamesGroup);
937 aMgr.addPreference(tr("Text font"), aGroupNamesGroup,
938 SUIT_PreferenceMgr::String, ModuleBase_Preferences::VIEWER_SECTION, "group_names_font");
939 aItem = aMgr.addPreference(tr("Text size"), aGroupNamesGroup,
940 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "group_names_size");
941 aPref->setItemProperty("min", 8, aItem);
942 aPref->setItemProperty("max", 100, aItem);
943 aItem = aMgr.addPreference(tr("Text color"), aGroupNamesGroup,
944 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "group_names_color");
949 //******************************************************
950 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
952 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
953 QString aVal = aResMgr->stringValue(theSection, theParam);
954 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
955 theParam.toStdString());
957 return; // invalid case, the property default value must be registered in XML file
958 std::string aValue = aVal.toStdString();
959 if (aValue.empty()) {
960 aValue = aProp->defaultValue();
961 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
963 LightApp_Preferences* aPref = preferences();
967 aProp->setValue(aValue);
969 if (theSection == "Visualization") {
970 if (theParam == "selection_color") {
971 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
972 myWorkshop->displayer()->setSelectionColor(aColor);
974 if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
976 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
977 if (!aTrihedron.IsNull()) {
978 bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
979 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
981 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
982 Handle(V3d_View) aView = aViewer->activeView();
985 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
986 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
987 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
988 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
989 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
990 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
991 aContext->Redisplay(aTrihedron, true);
994 else if (myAxisArrowRate > 0) {
995 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
996 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
997 aContext->Redisplay(aTrihedron, true);
1003 else if (theSection == ModuleBase_Preferences::GENERAL_SECTION && theParam == "create_init_part") {
1004 bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
1005 ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
1006 Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
1009 else if (theSection == ModuleBase_Preferences::VIEWER_SECTION &&
1010 theParam.startsWith("group_names_"))
1011 { // one of the group names parameter changed, so, update the groups names vizualization
1012 myWorkshop->updateGroupsText();
1013 myWorkshop->displayer()->updateViewer();
1015 myWorkshop->displayer()->redisplayObjects();
1018 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
1020 application()->putInfo(theInfo, theMSecs);
1023 bool SHAPERGUI::abortAllOperations()
1025 return workshop()->operationMgr()->abortAllOperations();
1028 void SHAPERGUI::createFeatureActions()
1030 myWorkshop->menuMgr()->createFeatureActions();
1033 void SHAPERGUI::onWhatIs(bool isToggled)
1035 if (sender() == myWhatIsAction) {
1036 QAction* aViewAct = myInspectionPanel->toggleViewAction();
1037 aViewAct->blockSignals(true);
1038 aViewAct->setChecked(isToggled);
1039 aViewAct->blockSignals(false);
1040 myInspectionPanel->setVisible(isToggled);
1043 myWhatIsAction->blockSignals(true);
1044 myWhatIsAction->setChecked(isToggled);
1045 myWhatIsAction->blockSignals(false);
1046 myInspectionPanel->setVisible(isToggled);
1050 void SHAPERGUI::updateModuleVisibilityState()
1052 LightApp_Module::updateModuleVisibilityState();
1053 onWhatIs(myIsInspectionVisible);
1056 void SHAPERGUI::onEditToolbars()
1058 SHAPERGUI_ToolbarsDlg aDlg(this);
1059 if (aDlg.exec() == QDialog::Accepted) {
1063 updateToolbars(aDlg.result());
1067 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1069 if (!myToolbars.contains(theToolName))
1070 myToolbars[theToolName] = QList<int>();
1071 myToolbars[theToolName].append(theCommandId);
1074 int SHAPERGUI::getNextCommandId() const
1076 QtxActionMenuMgr* aMenuMgr = menuMgr();
1077 QIntList aIds = aMenuMgr->idList();
1078 int aId = aIds.count();
1079 while (action(aId) || myActionsList.contains(aId))
1084 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1086 // Store default toolbars
1087 if (myDefaultToolbars.size() == 0)
1088 myDefaultToolbars = myToolbars;
1090 QtxActionToolMgr* aMgr = toolMgr();
1091 QStringList aToolbars = theNewToolbars.keys();
1092 QIntList aCommands, aOldCmd;
1096 foreach(QString aName, aToolbars) {
1097 aCommands = theNewToolbars[aName];
1098 // Find or create toolbar
1099 if (aMgr->hasToolBar(aName)) {
1100 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1101 aOldCmd = myToolbars[aName];
1104 aToolbarId = aMgr->createToolBar(aName);
1107 foreach(int aCmd, aCommands) {
1110 aAction = separator();
1112 aAction = action(aCmd);
1113 aActionId = aMgr->actionId(aAction);
1114 if (aActionId == -1) {
1116 aMgr->insert(aAction, aToolbarId, aPos);
1119 // Change position of action
1120 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1121 if (aMgr->containsAction(aActionId, aToolbarId))
1122 aMgr->remove(aActionId, aToolbarId);
1123 aMgr->insert(aActionId, aToolbarId, aPos);
1126 aOldCmd.removeAll(aCmd);
1129 // remove extra actions
1130 foreach(int aCmd, aOldCmd) {
1131 aAction = action(aCmd);
1132 aActionId = aMgr->actionId(aAction);
1133 aMgr->remove(aActionId, aToolbarId);
1135 myToolbars.remove(aName);
1137 // Remove extra toolbars
1138 aToolbars = myToolbars.keys();
1139 foreach(QString aName, aToolbars) {
1140 aMgr->removeToolBar(aName);
1142 // Set new toolbars structure
1143 myToolbars = theNewToolbars;
1144 myIsToolbarsModified = true;
1147 void SHAPERGUI::saveToolbarsConfig()
1149 if (!myIsToolbarsModified)
1151 // Save toolbars configuration into map
1152 QMap<QString, QStringList> aToolbarsConfig;
1154 QtxActionToolMgr* aMgr =
1157 QStringList aToolbars = myToolbars.keys();
1158 QIntList aActionsIds;
1159 foreach(QString aName, aToolbars) {
1160 aActionsIds = myToolbars[aName];
1161 QStringList aContent;
1162 foreach(int aId, aActionsIds) {
1164 aContent.append("");
1166 aContent.append(action(aId)->data().toString());
1168 aToolbarsConfig[aName] = aContent;
1170 // Store the configuration into resources
1171 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1172 QStringList aNames = aToolbarsConfig.keys();
1173 QStringList aValues;
1174 foreach(QString aToolbar, aNames) {
1175 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1177 // Remove obsolete parameters from resources
1178 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1179 foreach(QString aName, aOldParams) {
1180 if (!aToolbars.contains(aName))
1181 aResMgr->remove(ToolbarsSection, aName);
1183 // Store current list of free commands
1184 QIntList aFreeCommands = getFreeCommands();
1185 QStringList aFreeList;
1186 foreach(int aId, aFreeCommands) {
1187 aFreeList.append(action(aId)->data().toString());
1189 if (aFreeList.size() > 0)
1190 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1192 myIsToolbarsModified = false;
1195 void SHAPERGUI::loadToolbarsConfig()
1197 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1198 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1199 if (aToolbarNames.size() == 0)
1202 // Create commands map
1203 QMap<QString, int> aCommandsMap;
1205 foreach(int aId, myActionsList) {
1206 aCmdIdStr = action(aId)->data().toString();
1207 aCommandsMap[aCmdIdStr] = aId;
1210 // Create new toolbars structure
1211 QMap<QString, QIntList> aToolbars;
1212 QStringList aCommands;
1213 QIntList aKnownCommands;
1214 QList<QAction*> aActions;
1215 foreach(QString aName, aToolbarNames) {
1216 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1217 if (aName == FreeCommandsParam) {
1218 // The value is a list of free commands
1219 foreach(QString aCommand, aCommands) {
1220 aKnownCommands.append(aCommandsMap[aCommand]);
1224 aToolbars[aName] = QIntList();
1225 if (aCommands.size() > 0) {
1226 foreach(QString aCommand, aCommands) {
1227 if (aCommand.isEmpty())
1228 aToolbars[aName].append(-1);
1229 else if (aCommandsMap.contains(aCommand)) {
1230 int aId = aCommandsMap[aCommand];
1231 aToolbars[aName].append(aId);
1232 aKnownCommands.append(aId);
1238 // Find new and obsolete commands
1239 QIntList aNewCommands = myActionsList;
1240 foreach(int aId, myActionsList) {
1241 if (aKnownCommands.contains(aId)) {
1242 aKnownCommands.removeAll(aId);
1243 aNewCommands.removeAll(aId);
1246 if (aNewCommands.size() > 0) {
1247 // Add new commands to toolbars structure
1248 QStringList aKeys = myToolbars.keys();
1249 foreach(int aNewId, aNewCommands) {
1250 foreach(QString aName, aKeys) {
1251 if (myToolbars[aName].contains(aNewId)) {
1252 if (!aToolbars.contains(aName)) {
1253 aToolbars[aName] = QIntList();
1255 aToolbars[aName].append(aNewId);
1260 if (aKnownCommands.size() > 0) {
1261 // Remove obsolete commands from the toolbars structure
1262 QStringList aKeys = aToolbars.keys();
1263 foreach(int aOldId, aKnownCommands) {
1264 foreach(QString aName, aKeys) {
1265 if (aToolbars[aName].contains(aOldId)) {
1266 aToolbars[aName].removeAll(aOldId);
1267 if (aToolbars[aName].size() == 0)
1268 aToolbars.remove(aName);
1273 updateToolbars(aToolbars);
1274 myIsToolbarsModified = false;
1278 QIntList SHAPERGUI::getFreeCommands() const
1280 QIntList aFreeCommands;
1281 QtxActionToolMgr* aMgr = toolMgr();
1284 QMap<QString, QIntList>::const_iterator aIt;
1285 QIntList aShaperActions = shaperActions();
1286 foreach(int aCmd, aShaperActions) {
1287 anAction = action(aCmd);
1288 aId = aMgr->actionId(anAction);
1289 if (!aMgr->containsAction(aId))
1290 aFreeCommands.append(aCmd);
1292 return aFreeCommands;
1295 void SHAPERGUI::resetToolbars()
1297 if (!myDefaultToolbars.isEmpty())
1298 updateToolbars(myDefaultToolbars);
1299 myIsToolbarsModified = false;
1300 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1301 aResMgr->remove(ToolbarsSection);
1304 void SHAPERGUI::publishToStudy()
1306 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) {
1307 myWorkshop->module()->launchOperation("PublishToStudy", false);
1309 // update SHAPERSTUDY objects in OCC and VTK viewers
1310 QStringList aVMList;
1311 aVMList << "OCCViewer" << "VTKViewer";
1312 getApp()->updatePresentations("SHAPERSTUDY", aVMList);