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 #include <ModelAPI_Session.h>
79 #if OCC_VERSION_HEX < 0x070400
80 #define SALOME_PATCH_FOR_CTRL_WHEEL
84 SHAPERGUI_EXPORT CAM_Module* createModule()
86 return new SHAPERGUI();
89 SHAPERGUI_EXPORT char* getModuleVersion()
96 static const QString ToolbarsSection("SHAPER_Toolbars");
97 static const QString FreeCommandsParam("OutOFToolbars");
101 * Class for preferences management
103 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
107 /// \param theMgr preferences manager of SALOME
108 /// \param theModName name of the module
109 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
110 myMgr(theMgr), myModName(theModName) {}
112 virtual int addPreference(const QString& theLbl, int pId,
113 SUIT_PreferenceMgr::PrefItemType theType,
114 const QString& theSection, const QString& theName )
116 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
119 virtual void setItemProperty(const QString& thePropName,
120 const QVariant& theValue,
121 const int theId = -1)
123 myMgr->setItemProperty(thePropName, theValue, theId);
127 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
130 LightApp_Preferences* myMgr;
137 //******************************************************
138 SHAPERGUI::SHAPERGUI()
139 : LightApp_Module("SHAPER"),
140 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
141 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
144 myWorkshop = new XGUI_Workshop(this);
145 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
146 this, SLOT(onUpdateCommandStatus()));
148 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
150 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
152 // It will be called in XGUI_Workshop::startApplication
153 // ModuleBase_Preferences::loadCustomProps();
156 //******************************************************
157 SHAPERGUI::~SHAPERGUI()
160 delete myProxyViewer;
163 //******************************************************
164 void SHAPERGUI::initialize(CAM_Application* theApp)
166 LightApp_Module::initialize(theApp);
168 myWorkshop->startApplication();
169 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
172 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
175 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
176 int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
178 int aId = getNextCommandId();
179 myActionsList.append(aId);
180 SUIT_Desktop* aDesk = application()->desktop();
181 QString aTip = tr("Show inspection window");
182 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
183 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
184 myWhatIsAction->setStatusTip(aTip);
185 myWhatIsAction->setData("INSPECTION_CMD");
186 createMenu(aId, aSubMenu, 0);
188 QString aToolName = tr("Inspection");
189 int aTool = createTool(aToolName);
193 createTool(myWhatIsAction, aTool);
194 registerCommandToolbar(aToolName, aId);
196 // Define Edit toolbars command
197 aId = getNextCommandId();
198 //myActionsList.append(aId); Do not use it for editing of toolbars
199 aTip = tr("Edit toolbars of the module");
203 createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
204 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
205 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
209 createMenu(aId, aEditMenu);
211 if (!myInspectionPanel) {
212 myInspectionPanel = myWorkshop->inspectionPanel();
213 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
214 this, SLOT(onWhatIs(bool)));
216 hideInternalWindows();
218 // Initialize viewer proxy if OCC viewer is already exist
219 ViewManagerList aOCCViewManagers;
220 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
221 if (aOCCViewManagers.size() > 0) {
222 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
223 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
225 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
226 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
228 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
229 aViewPort->installEventFilter(aViewer);
230 Handle(V3d_View) aView = aViewPort->getView();
231 aViewer->SetScale(aView, aView->Camera()->Scale());
232 // We can not create selector here because other modules will be deactivated later
233 //onViewManagerAdded(aMgr);
237 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
238 aDataModel->initRootObject();
241 //******************************************************
242 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
244 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
247 //******************************************************
248 void SHAPERGUI::viewManagers(QStringList& theList) const
250 theList.append(OCCViewer_Viewer::Type());
253 //******************************************************
254 // We can not create selector in this method because it can be called when
255 // SHAPER module is not active. Take into account that creation of our selector
256 // leads to switching OFF all other selectors
257 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
259 // // if there are created viewer managers, we should try to create viewer
260 // // selector and initialize viewer with it. It sets interactive context to the
261 // // proxy viewer. If study is opened, CAM application calls this method before the open()
263 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
264 // // we need to connect to the viewer before it. Here,
265 // // it seems the most appropriate place for this
266 // // according to SALOME architecture.
267 // if (!mySelector) {
268 // ViewManagerList OCCViewManagers;
269 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
270 // if (OCCViewManagers.size() > 0) {
271 // mySelector = createSelector(OCCViewManagers.first());
274 // LightApp_Module::connectToStudy(theStudy);
277 //******************************************************
278 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
280 ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet
282 // this must be done in the initialization and in activation (on the second activation
283 // initialization in not called, so SComponent must be added anyway
284 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
285 aDataModel->initRootObject();
288 bool isDone = LightApp_Module::activateModule(theStudy);
289 loadToolbarsConfig();
295 QObject* aObj = myWorkshop->objectBrowser()->parent();
296 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
298 myWorkshop->objectBrowser()->setVisible(true);
299 aObjDoc->setVisible(true);
300 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
301 aObjDoc->toggleViewAction()->setVisible(true);
304 myInspectionPanel->toggleViewAction()->setVisible(true);
306 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
307 if (myIsFacesPanelVisible)
308 myWorkshop->facesPanel()->show();
309 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
312 ViewManagerList OCCViewManagers;
313 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
314 if (OCCViewManagers.size() > 0) {
315 onViewManagerAdded(OCCViewManagers.first());
318 // it should be performed after the selector creation in order to have AISContext
319 myWorkshop->activateModule();
320 //action(myEraseAll)->setEnabled(false);
323 myWorkshop->objectBrowser()->rebuildDataTree();
324 myWorkshop->updateCommandStatus();
328 myWorkshop->updateCommandStatus();
330 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
331 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
332 myIsEditEnabled = getApp()->isEditEnabled();
333 getApp()->setEditEnabled(false);
335 // this following row is caused by #187 bug.
336 // SALOME saves the dock widget positions before deactivateModule() and
337 // load it after the module activation. So, if the panel is visible before
338 // deactivate, it becomes visible after activate.
339 // In order to avoid the visible property panel, the widget position save is
340 // switch off in this module
341 aResMgr->setValue("Study", "store_positions", false);
343 // Synchronize displayed objects
344 Handle(AIS_InteractiveContext) aContext;
345 if (mySelector && mySelector->viewer())
346 aContext = mySelector->viewer()->getAISContext();
348 if (!aContext.IsNull()) {
349 XGUI_Displayer* aDisp = myWorkshop->displayer();
350 QObjectPtrList aObjList = aDisp->displayedObjects();
352 if (myOldSelectionColor.size() == 0)
353 myOldSelectionColor = aDisp->selectionColor();
355 AIS_ListOfInteractive aList;
356 aContext->DisplayedObjects(aList);
357 AIS_ListIteratorOfListOfInteractive aLIt;
358 Handle(AIS_InteractiveObject) anAISIO;
359 foreach (ObjectPtr aObj, aObjList) {
360 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
361 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
363 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
364 anAISIO = aLIt.Value();
365 if (anAISIO.get() == aAIS.get()) {
371 aObj->setDisplayed(false);
372 //aDisp->erase(aObj, false);
375 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
377 myProxyViewer->activateViewer(true);
379 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
380 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
381 this, SLOT(onScriptLoaded()));
383 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
384 getApp(), SLOT(onSaveDoc()));
385 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
386 getApp(), SLOT(onSaveAsDoc()));
388 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
389 this, SLOT(onSaveDocByShaper()));
390 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
391 this, SLOT(onSaveAsDocByShaper()));
396 //******************************************************
397 void SHAPERGUI::hideInternalWindows()
399 myProxyViewer->activateViewer(false);
403 QObject* aObj = myWorkshop->objectBrowser()->parent();
404 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
406 aObjDoc->setVisible(false);
407 myWorkshop->objectBrowser()->setVisible(false);
408 aObjDoc->toggleViewAction()->setVisible(false);
411 myInspectionPanel->hide();
412 myInspectionPanel->toggleViewAction()->setVisible(false);
414 myWorkshop->facesPanel()->hide();
415 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
417 myWorkshop->propertyPanel()->hide();
418 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
420 myWorkshop->hidePanel(myWorkshop->facesPanel());
424 //******************************************************
425 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
427 saveToolbarsConfig();
428 myWorkshop->deactivateModule();
430 myIsInspectionVisible = myInspectionPanel->isVisible();
431 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
432 hideInternalWindows();
435 // the active operation should be stopped for the next activation.
436 // There should not be active operation and visualized preview.
437 // Abort operation should be performed before the selection's remove
438 // because the displayed objects should be removed from the viewer, but
439 // the AIS context is obtained from the selector.
440 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
441 while (anOperation) {
442 anOperation->abort();
443 anOperation = myWorkshop->operationMgr()->currentOperation();
445 // Delete selector because it has to be redefined on next activation
447 // Restore size of arrows of trihedron
448 if (myAxisArrowRate > 0) {
449 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
450 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
451 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
452 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
453 aContext->Redisplay(aTrihedron, false);
455 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
456 myProxyViewer->setSelector(0);
458 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
459 QList<SUIT_Selector*> aList;
460 aMgr->selectors(aList);
461 foreach(SUIT_Selector* aSel, aList) {
462 aSel->setEnabled(aSel != mySelector);
469 //myWorkshop->contextMenuMgr()->disconnectViewer();
471 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
472 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
473 getApp()->setEditEnabled(myIsEditEnabled);
475 myOldSelectionColor.clear();
477 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
478 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
479 this, SLOT(onScriptLoaded()));
481 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
482 this, SLOT(onSaveDocByShaper()));
483 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
484 this, SLOT(onSaveAsDocByShaper()));
486 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
487 getApp(), SLOT(onSaveDoc()));
488 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
489 getApp(), SLOT(onSaveAsDoc()));
493 return LightApp_Module::deactivateModule(theStudy);
496 //******************************************************
497 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
500 mySelector = createSelector(theMgr);
501 myWorkshop->selectionActivate()->updateSelectionFilters();
502 myWorkshop->selectionActivate()->updateSelectionModes();
503 myWorkshop->synchronizeViewer();
507 //******************************************************
508 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
511 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
512 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
513 if (mySelector->viewer() == aViewer) {
514 XGUI_Displayer* aDisp = myWorkshop->displayer();
515 QObjectPtrList aObjects = aDisp->displayedObjects();
517 foreach(ObjectPtr aObj, aObjects) {
518 aObj->setDisplayed(false);
519 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
521 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
522 aRes->setDisplayed(false);
526 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
527 myProxyViewer->setSelector(0);
531 myWorkshop->module()->clearViewer();
537 //******************************************************
538 QtxPopupMgr* SHAPERGUI::popupMgr()
541 myPopupMgr = new QtxPopupMgr( 0, this );
545 //******************************************************
546 void SHAPERGUI::onDefaultPreferences()
548 // reset main resources
549 ModuleBase_Preferences::resetResourcePreferences(preferences());
550 // reset plugin's resources
551 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
553 myWorkshop->displayer()->redisplayObjects();
556 //******************************************************
557 void SHAPERGUI::onScriptLoaded()
559 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
560 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
561 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
562 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
563 // it manually (because this method of application is protected)
564 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
567 myWorkshop->displayer()->updateViewer();
568 myWorkshop->updateCommandStatus();
571 //******************************************************
572 void SHAPERGUI::onSaveDocByShaper()
574 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
577 getApp()->onSaveDoc();
580 //******************************************************
581 void SHAPERGUI::onSaveAsDocByShaper()
583 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
586 getApp()->onSaveAsDoc();
589 //******************************************************
590 void SHAPERGUI::onUpdateCommandStatus()
592 getApp()->updateActions();
595 //******************************************************
596 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
598 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
599 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
601 // Remember current length of arrow of axis
602 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
603 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
604 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
606 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
607 getApp()->selectionMgr());
608 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
609 aViewer->setUseLocalSelection(true);
611 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
612 QList<SUIT_Selector*> aList;
613 aMgr->selectors(aList);
614 foreach(SUIT_Selector* aSel, aList)
616 aSel->setEnabled(aSel == aSelector);
618 myProxyViewer->setSelector(aSelector);
620 if (myOldSelectionColor.size() == 0)
621 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
623 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
624 myWorkshop->displayer()->setSelectionColor(aColor);
626 // Cause scaling of arrows of axis and dimensions
627 myWorkshop->module()->onViewTransformed();
634 //******************************************************
635 CAM_DataModel* SHAPERGUI::createDataModel()
637 return new SHAPERGUI_DataModel(this);
640 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
641 const bool isAddSeparator)
643 return addFeature(theWBName,
647 //Issue #650: in the SALOME mode the tooltip should be same as text
656 //******************************************************
657 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
658 const QString& theId, const QString& theTitle, const QString& theTip,
659 const QIcon& theIcon, const QKeySequence& theKeys,
660 bool isCheckable, const bool isAddSeparator,
661 const QString& theStatusTip)
663 static QString aLastTool = "";
665 if (aLastTool.isEmpty())
666 aLastTool = theWBName;
667 else if (theWBName != aLastTool) {
668 aLastTool = theWBName;
670 desktop()->addToolBarBreak();
676 int aId = getNextCommandId();
677 myActionsList.append(aId);
678 SUIT_Desktop* aDesk = application()->desktop();
680 for (int i = 0; i < theKeys.count(); i++)
682 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
684 aAction->setStatusTip(theStatusTip);
686 aAction->setData(theId);
688 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
692 createMenu(aId, aWBMenu);
694 createMenu(separator(), aWBMenu);
696 int aWBTool = createTool(theTBName, theTBName);
700 createTool(aId, aWBTool);
701 registerCommandToolbar(theTBName, aId);
702 if (isAddSeparator) {
703 createTool(separator(), aWBTool);
704 registerCommandToolbar(theTBName, -1);
709 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
711 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
714 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
715 const ActionInfo& theInfo,
716 const QList<QAction*>& theNestedActions)
718 SUIT_Desktop* aDesk = application()->desktop();
719 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
720 anAction->setData(theInfo.id);
721 anAction->setCheckable(theInfo.checkable);
722 anAction->setChecked(theInfo.checked);
723 anAction->setEnabled(theInfo.enabled);
724 anAction->setVisible(theInfo.visible);
725 anAction->setIcon(theInfo.icon);
726 anAction->setText(theInfo.text);
727 anAction->setToolTip(theInfo.toolTip);
728 anAction->setShortcut(theInfo.shortcut);
729 anAction->setFont(theInfo.font);
731 int aWBMenu = createMenu(theWBName, -1, -1, 30);
732 int aItemId = createMenu(anAction, aWBMenu);
733 myActionsList.append(aItemId);
734 createMenu(separator(), aWBMenu); /// nested action is always separated of others
736 int aWBTool = createTool(theWBName, theWBName);
740 createTool(anAction, aWBTool);
741 registerCommandToolbar(theWBName, aItemId);
742 createTool(separator(), aWBTool); /// nested action is always separated of others
743 registerCommandToolbar(theWBName, -1);
749 //******************************************************
750 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
751 const QString& theTip, const QIcon& theIcon,
752 const QKeySequence& theKeys, bool isCheckable,
753 const char* theMenuSourceText,
754 const QString& theSubMenu,
755 const int theMenuPosition,
756 const int theSuibMenuPosition)
758 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
759 if (!theSubMenu.isNull())
760 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
762 int aId = getNextCommandId();
763 myActionsList.append(aId);
764 SUIT_Desktop* aDesk = application()->desktop();
766 for (int i = 0; i < theKeys.count(); i++)
768 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
770 aAction->setStatusTip(theTip);
771 aAction->setData(theId);
772 createMenu(aId, aMenu, theMenuPosition);
776 //******************************************************
777 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
779 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
780 createMenu(separator(), aMenu, -1, theMenuPosition);
783 //******************************************************
784 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
789 SUIT_Desktop* aDesktop = application()->desktop();
793 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
797 aToolMgr->append( theAction, theToolBarTitle );
801 //******************************************************
802 QList<QAction*> SHAPERGUI::commandList() const
804 QList<QAction*> aActions;
805 foreach (int aId, myActionsList) {
806 QAction* aCmd = action(aId);
808 aActions.append(aCmd);
814 //******************************************************
815 QMainWindow* SHAPERGUI::desktop() const
817 return application()->desktop();
820 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
821 const std::shared_ptr<Config_FeatureMessage>& theMessage)
823 myFeaturesInfo.insert(theFeatureId, theMessage);
826 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
828 std::shared_ptr<Config_FeatureMessage> aMessage;
829 if (myFeaturesInfo.contains(theFeatureId))
830 aMessage = myFeaturesInfo[theFeatureId];
834 //******************************************************
835 void SHAPERGUI::selectionChanged()
837 LightApp_Module::selectionChanged();
838 myWorkshop->salomeViewerSelectionChanged();
841 //******************************************************
842 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
844 myWorkshop->contextMenuMgr()->updateViewerMenu();
845 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
846 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
850 //******************************************************
851 void SHAPERGUI::createPreferences()
853 LightApp_Preferences* pref = preferences();
856 ModuleBase_Preferences::updateConfigByResources();
857 QString aModName = moduleName();
859 QtxPreferenceItem* item = pref->findItem(aModName, true );
860 if ( item && (!item->isEmpty() )) {
861 item->parentItem()->removeItem(item);
865 int catId = pref->addPreference(aModName, -1 );
868 SHAPERGUI_PrefMgr aMgr(pref, aModName);
869 ModuleBase_Preferences::createEditContent(&aMgr, catId);
871 int viewTab = pref->addItem(tr("Viewer"), catId);
872 // Create other parameters group in viewer tab
873 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
874 pref->setItemProperty("columns", 3, otherGroup);
875 pref->addItem(tr("Faces"), otherGroup,
876 SUIT_PreferenceMgr::Bool,
877 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
878 pref->addItem(tr("Edges"), otherGroup,
879 SUIT_PreferenceMgr::Bool,
880 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
881 pref->addItem(tr("Vertices"), otherGroup,
882 SUIT_PreferenceMgr::Bool,
883 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
885 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
886 pref->setItemProperty("columns", 2, sensitivityGroup);
887 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
888 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
889 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
890 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
892 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
893 pref->setItemProperty("columns", 2, highlightGroup);
894 pref->addItem(tr("In 3d mode"), highlightGroup,
895 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
896 pref->addItem(tr("In 2d mode"), highlightGroup,
897 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
899 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
900 pref->setItemProperty("columns", 4, colorScaleGroup);
901 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
902 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
903 pref->setItemProperty("min", 0, aItem);
904 pref->setItemProperty("max", 1, aItem);
906 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
907 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
908 pref->setItemProperty("min", 0, aItem);
909 pref->setItemProperty("max", 1, aItem);
911 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
912 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
913 pref->setItemProperty("min", 0, aItem);
914 pref->setItemProperty("max", 1, aItem);
916 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
917 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
918 pref->setItemProperty("min", 0, aItem);
919 pref->setItemProperty("max", 1, aItem);
921 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
922 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
923 pref->setItemProperty("min", 0, aItem);
924 pref->setItemProperty("max", 100, aItem);
926 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
927 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
928 pref->setItemProperty("min", 0, aItem);
929 pref->setItemProperty("max", 100, aItem);
931 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
932 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
937 //******************************************************
938 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
940 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
941 QString aVal = aResMgr->stringValue(theSection, theParam);
942 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
943 theParam.toStdString());
944 std::string aValue = aVal.toStdString();
945 if (aValue.empty()) {
946 aValue = aProp->defaultValue();
947 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
949 LightApp_Preferences* pref = preferences();
953 aProp->setValue(aValue);
955 if ((theSection == "Visualization") && (theParam == "selection_color")) {
956 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
957 myWorkshop->displayer()->setSelectionColor(aColor);
960 myWorkshop->displayer()->redisplayObjects();
963 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
965 application()->putInfo(theInfo, theMSecs);
968 bool SHAPERGUI::abortAllOperations()
970 return workshop()->operationMgr()->abortAllOperations();
973 void SHAPERGUI::createFeatureActions()
975 myWorkshop->menuMgr()->createFeatureActions();
978 void SHAPERGUI::onWhatIs(bool isToggled)
980 if (sender() == myWhatIsAction) {
981 QAction* aViewAct = myInspectionPanel->toggleViewAction();
982 aViewAct->blockSignals(true);
983 aViewAct->setChecked(isToggled);
984 aViewAct->blockSignals(false);
985 myInspectionPanel->setVisible(isToggled);
988 myWhatIsAction->blockSignals(true);
989 myWhatIsAction->setChecked(isToggled);
990 myWhatIsAction->blockSignals(false);
991 myInspectionPanel->setVisible(isToggled);
995 void SHAPERGUI::updateModuleVisibilityState()
997 LightApp_Module::updateModuleVisibilityState();
998 onWhatIs(myIsInspectionVisible);
1001 void SHAPERGUI::onEditToolbars()
1003 SHAPERGUI_ToolbarsDlg aDlg(this);
1004 if (aDlg.exec() == QDialog::Accepted) {
1008 updateToolbars(aDlg.result());
1012 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1014 if (!myToolbars.contains(theToolName))
1015 myToolbars[theToolName] = QList<int>();
1016 myToolbars[theToolName].append(theCommandId);
1019 int SHAPERGUI::getNextCommandId() const
1021 QtxActionMenuMgr* aMenuMgr = menuMgr();
1022 QIntList aIds = aMenuMgr->idList();
1023 int aId = aIds.count();
1024 while (action(aId) || myActionsList.contains(aId))
1029 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1031 // Store default toolbars
1032 if (myDefaultToolbars.size() == 0)
1033 myDefaultToolbars = myToolbars;
1035 QtxActionToolMgr* aMgr = toolMgr();
1036 QStringList aToolbars = theNewToolbars.keys();
1037 QIntList aCommands, aOldCmd;
1041 foreach(QString aName, aToolbars) {
1042 aCommands = theNewToolbars[aName];
1043 // Find or create toolbar
1044 if (aMgr->hasToolBar(aName)) {
1045 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1046 aOldCmd = myToolbars[aName];
1049 aToolbarId = aMgr->createToolBar(aName);
1052 foreach(int aCmd, aCommands) {
1055 aAction = separator();
1057 aAction = action(aCmd);
1058 aActionId = aMgr->actionId(aAction);
1059 if (aActionId == -1) {
1061 aMgr->insert(aAction, aToolbarId, aPos);
1064 // Change position of action
1065 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1066 if (aMgr->containsAction(aActionId, aToolbarId))
1067 aMgr->remove(aActionId, aToolbarId);
1068 aMgr->insert(aActionId, aToolbarId, aPos);
1071 aOldCmd.removeAll(aCmd);
1074 // remove extra actions
1075 foreach(int aCmd, aOldCmd) {
1076 aAction = action(aCmd);
1077 aActionId = aMgr->actionId(aAction);
1078 aMgr->remove(aActionId, aToolbarId);
1080 myToolbars.remove(aName);
1082 // Remove extra toolbars
1083 aToolbars = myToolbars.keys();
1084 foreach(QString aName, aToolbars) {
1085 aMgr->removeToolBar(aName);
1087 // Set new toolbars structure
1088 myToolbars = theNewToolbars;
1089 myIsToolbarsModified = true;
1092 void SHAPERGUI::saveToolbarsConfig()
1094 if (!myIsToolbarsModified)
1096 // Save toolbars configuration into map
1097 QMap<QString, QStringList> aToolbarsConfig;
1099 QtxActionToolMgr* aMgr =
1102 QStringList aToolbars = myToolbars.keys();
1103 QIntList aActionsIds;
1104 foreach(QString aName, aToolbars) {
1105 aActionsIds = myToolbars[aName];
1106 QStringList aContent;
1107 foreach(int aId, aActionsIds) {
1109 aContent.append("");
1111 aContent.append(action(aId)->data().toString());
1113 aToolbarsConfig[aName] = aContent;
1115 // Store the configuration into resources
1116 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1117 QStringList aNames = aToolbarsConfig.keys();
1118 QStringList aValues;
1119 foreach(QString aToolbar, aNames) {
1120 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1122 // Remove obsolete parameters from resources
1123 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1124 foreach(QString aName, aOldParams) {
1125 if (!aToolbars.contains(aName))
1126 aResMgr->remove(ToolbarsSection, aName);
1128 // Store current list of free commands
1129 QIntList aFreeCommands = getFreeCommands();
1130 QStringList aFreeList;
1131 foreach(int aId, aFreeCommands) {
1132 aFreeList.append(action(aId)->data().toString());
1134 if (aFreeList.size() > 0)
1135 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1137 myIsToolbarsModified = false;
1140 void SHAPERGUI::loadToolbarsConfig()
1142 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1143 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1144 if (aToolbarNames.size() == 0)
1147 // Create commands map
1148 QMap<QString, int> aCommandsMap;
1150 foreach(int aId, myActionsList) {
1151 aCmdIdStr = action(aId)->data().toString();
1152 aCommandsMap[aCmdIdStr] = aId;
1155 // Create new toolbars structure
1156 QMap<QString, QIntList> aToolbars;
1157 QStringList aCommands;
1158 QIntList aKnownCommands;
1159 QList<QAction*> aActions;
1160 foreach(QString aName, aToolbarNames) {
1161 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1162 if (aName == FreeCommandsParam) {
1163 // The value is a list of free commands
1164 foreach(QString aCommand, aCommands) {
1165 aKnownCommands.append(aCommandsMap[aCommand]);
1169 aToolbars[aName] = QIntList();
1170 if (aCommands.size() > 0) {
1171 foreach(QString aCommand, aCommands) {
1172 if (aCommand.isEmpty())
1173 aToolbars[aName].append(-1);
1174 else if (aCommandsMap.contains(aCommand)) {
1175 int aId = aCommandsMap[aCommand];
1176 aToolbars[aName].append(aId);
1177 aKnownCommands.append(aId);
1183 // Find new and obsolete commands
1184 QIntList aNewCommands = myActionsList;
1185 foreach(int aId, myActionsList) {
1186 if (aKnownCommands.contains(aId)) {
1187 aKnownCommands.removeAll(aId);
1188 aNewCommands.removeAll(aId);
1191 if (aNewCommands.size() > 0) {
1192 // Add new commands to toolbars structure
1193 QStringList aKeys = myToolbars.keys();
1194 foreach(int aNewId, aNewCommands) {
1195 foreach(QString aName, aKeys) {
1196 if (myToolbars[aName].contains(aNewId)) {
1197 if (!aToolbars.contains(aName)) {
1198 aToolbars[aName] = QIntList();
1200 aToolbars[aName].append(aNewId);
1205 if (aKnownCommands.size() > 0) {
1206 // Remove obsolete commands from the toolbars structure
1207 QStringList aKeys = aToolbars.keys();
1208 foreach(int aOldId, aKnownCommands) {
1209 foreach(QString aName, aKeys) {
1210 if (aToolbars[aName].contains(aOldId)) {
1211 aToolbars[aName].removeAll(aOldId);
1212 if (aToolbars[aName].size() == 0)
1213 aToolbars.remove(aName);
1218 updateToolbars(aToolbars);
1219 myIsToolbarsModified = false;
1223 QIntList SHAPERGUI::getFreeCommands() const
1225 QIntList aFreeCommands;
1226 QtxActionToolMgr* aMgr = toolMgr();
1229 QMap<QString, QIntList>::const_iterator aIt;
1230 QIntList aShaperActions = shaperActions();
1231 foreach(int aCmd, aShaperActions) {
1232 anAction = action(aCmd);
1233 aId = aMgr->actionId(anAction);
1234 if (!aMgr->containsAction(aId))
1235 aFreeCommands.append(aCmd);
1237 return aFreeCommands;
1240 void SHAPERGUI::resetToolbars()
1242 if (!myDefaultToolbars.isEmpty())
1243 updateToolbars(myDefaultToolbars);
1244 myIsToolbarsModified = false;
1245 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1246 aResMgr->remove(ToolbarsSection);
1249 void SHAPERGUI::publishToStudy()
1251 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument())
1252 myWorkshop->module()->launchOperation("PublishToStudy", false);