1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SHAPERGUI.h"
21 #include "SHAPERGUI_DataModel.h"
22 #include "SHAPERGUI_OCCSelector.h"
23 #include "SHAPERGUI_NestedButton.h"
24 #include "SHAPERGUI_ToolbarsMgr.h"
26 #include <XGUI_Workshop.h>
27 #include <XGUI_PropertyPanel.h>
28 #include <XGUI_ContextMenuMgr.h>
29 #include <XGUI_ObjectsBrowser.h>
30 #include <XGUI_OperationMgr.h>
31 #include <XGUI_Displayer.h>
32 #include <XGUI_MenuMgr.h>
33 #include <XGUI_FacesPanel.h>
34 #include <XGUI_SelectionActivate.h>
35 #include <XGUI_InspectionPanel.h>
36 #include <XGUI_ViewerProxy.h>
38 #include <ModuleBase_Operation.h>
39 #include <ModuleBase_Preferences.h>
40 #include <ModuleBase_ActionInfo.h>
41 #include <ModuleBase_IModule.h>
43 #include <ModelAPI_Tools.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_OCCSelector.h>
48 #include <LightApp_Study.h>
50 #include <OCCViewer_ViewModel.h>
51 #include <OCCViewer_ViewPort3d.h>
53 #include <SUIT_Selector.h>
54 #include <SUIT_Desktop.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_ViewWindow.h>
57 #include <SUIT_ResourceMgr.h>
58 #include <SUIT_DataBrowser.h>
60 #include <QtxPopupMgr.h>
61 #include <QtxActionMenuMgr.h>
62 #include <QtxActionToolMgr.h>
63 #include <QtxResourceMgr.h>
65 #include <Config_PropManager.h>
66 #include <Config_ModuleReader.h>
68 #include <AIS_ListOfInteractive.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
71 #include <QDockWidget>
77 #if OCC_VERSION_HEX < 0x070400
78 #define SALOME_PATCH_FOR_CTRL_WHEEL
82 SHAPERGUI_EXPORT CAM_Module* createModule()
84 return new SHAPERGUI();
87 SHAPERGUI_EXPORT char* getModuleVersion()
94 static const QString ToolbarsSection("SHAPER_Toolbars");
95 static const QString FreeCommandsParam("OutOFToolbars");
99 * Class for preferences management
101 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
105 /// \param theMgr preferences manager of SALOME
106 /// \param theModName name of the module
107 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
108 myMgr(theMgr), myModName(theModName) {}
110 virtual int addPreference(const QString& theLbl, int pId,
111 SUIT_PreferenceMgr::PrefItemType theType,
112 const QString& theSection, const QString& theName )
114 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
117 virtual void setItemProperty(const QString& thePropName,
118 const QVariant& theValue,
119 const int theId = -1)
121 myMgr->setItemProperty(thePropName, theValue, theId);
125 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
128 LightApp_Preferences* myMgr;
135 //******************************************************
136 SHAPERGUI::SHAPERGUI()
137 : LightApp_Module("SHAPER"),
138 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
139 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false)
141 myWorkshop = new XGUI_Workshop(this);
142 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
143 this, SLOT(onUpdateCommandStatus()));
145 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
147 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
149 // It will be called in XGUI_Workshop::startApplication
150 // ModuleBase_Preferences::loadCustomProps();
153 //******************************************************
154 SHAPERGUI::~SHAPERGUI()
157 delete myProxyViewer;
160 //******************************************************
161 void SHAPERGUI::initialize(CAM_Application* theApp)
163 LightApp_Module::initialize(theApp);
165 myWorkshop->startApplication();
166 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
169 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
172 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
173 int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
175 int aId = getNextCommandId();
176 myActionsList.append(aId);
177 SUIT_Desktop* aDesk = application()->desktop();
178 QString aTip = tr("Show inspection window");
179 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
180 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
181 myWhatIsAction->setStatusTip(aTip);
182 myWhatIsAction->setData("INSPECTION_CMD");
183 createMenu(aId, aSubMenu, 0);
185 QString aToolName = tr("Inspection");
186 int aTool = createTool(aToolName);
187 int aToolId = createTool(myWhatIsAction, aTool);
188 registerCommandToolbar(aToolName, aId);
190 // Define Edit toolbars command
191 aId = getNextCommandId();
192 //myActionsList.append(aId); Do not use it for editing of toolbars
193 aTip = tr("Edit toolbars of the module");
194 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
195 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
196 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
197 int aEditItem = createMenu(aId, aEditMenu);
199 // Initialize viewer proxy if OCC viewer is already exist
200 ViewManagerList aOCCViewManagers;
201 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
202 if (aOCCViewManagers.size() > 0) {
203 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
204 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
206 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
207 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
209 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
210 aViewPort->installEventFilter(aViewer);
211 Handle(V3d_View) aView = aViewPort->getView();
212 aViewer->SetScale(aView, aView->Camera()->Scale());
213 // We can not create selector here because other modules will be deactivated later
214 //onViewManagerAdded(aMgr);
220 //******************************************************
221 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
223 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
226 //******************************************************
227 void SHAPERGUI::viewManagers(QStringList& theList) const
229 theList.append(OCCViewer_Viewer::Type());
232 //******************************************************
233 // We can not create selector in this method because it can be called when
234 // SHAPER module is not active. Take into account that creation of our selector
235 // leads to switching OFF all other selectors
236 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
238 // // if there are created viewer managers, we should try to create viewer
239 // // selector and initialize viewer with it. It sets interactive context to the
240 // // proxy viewer. If study is opened, CAM application calls this method before the open()
242 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
243 // // we need to connect to the viewer before it. Here,
244 // // it seems the most appropriate place for this
245 // // according to SALOME architecture.
246 // if (!mySelector) {
247 // ViewManagerList OCCViewManagers;
248 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
249 // if (OCCViewManagers.size() > 0) {
250 // mySelector = createSelector(OCCViewManagers.first());
253 // LightApp_Module::connectToStudy(theStudy);
256 //******************************************************
257 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
259 bool isDone = LightApp_Module::activateModule(theStudy);
260 loadToolbarsConfig();
262 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
263 aDataModel->initRootObject();
269 QObject* aObj = myWorkshop->objectBrowser()->parent();
270 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
272 myWorkshop->objectBrowser()->setVisible(true);
273 aObjDoc->setVisible(true);
274 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
275 aObjDoc->toggleViewAction()->setVisible(true);
278 if (!myInspectionPanel) {
279 myInspectionPanel = myWorkshop->inspectionPanel();
280 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
281 this, SLOT(onWhatIs(bool)));
283 myInspectionPanel->toggleViewAction()->setVisible(true);
285 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
286 if (myIsFacesPanelVisible)
287 myWorkshop->facesPanel()->show();
288 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
291 ViewManagerList OCCViewManagers;
292 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
293 if (OCCViewManagers.size() > 0) {
294 onViewManagerAdded(OCCViewManagers.first());
297 // it should be performed after the selector creation in order to have AISContext
298 myWorkshop->activateModule();
299 //action(myEraseAll)->setEnabled(false);
302 myWorkshop->objectBrowser()->rebuildDataTree();
303 myWorkshop->updateCommandStatus();
307 myWorkshop->updateCommandStatus();
309 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
310 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
311 myIsEditEnabled = getApp()->isEditEnabled();
312 getApp()->setEditEnabled(false);
314 // this following row is caused by #187 bug.
315 // SALOME saves the dock widget positions before deactivateModule() and
316 // load it after the module activation. So, if the panel is visible before
317 // deactivate, it becomes visible after activate.
318 // In order to avoid the visible property panel, the widget position save is
319 // switch off in this module
320 aResMgr->setValue("Study", "store_positions", false);
322 // Synchronize displayed objects
323 Handle(AIS_InteractiveContext) aContext;
324 if (mySelector && mySelector->viewer())
325 aContext = mySelector->viewer()->getAISContext();
327 if (!aContext.IsNull()) {
328 XGUI_Displayer* aDisp = myWorkshop->displayer();
329 QObjectPtrList aObjList = aDisp->displayedObjects();
331 //if (myHighlightPointAspect.IsNull()) {
332 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
333 // myHighlightPointAspect =
334 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
336 if (myOldSelectionColor.size() == 0)
337 myOldSelectionColor = aDisp->selectionColor();
339 AIS_ListOfInteractive aList;
340 aContext->DisplayedObjects(aList);
341 AIS_ListIteratorOfListOfInteractive aLIt;
342 Handle(AIS_InteractiveObject) anAISIO;
343 foreach (ObjectPtr aObj, aObjList) {
344 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
345 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
347 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
348 anAISIO = aLIt.Value();
349 if (anAISIO.get() == aAIS.get()) {
355 aObj->setDisplayed(false);
356 //aDisp->erase(aObj, false);
359 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
361 myProxyViewer->activateViewer(true);
363 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
364 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
365 this, SLOT(onScriptLoaded()));
367 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
368 getApp(), SLOT(onSaveDoc()));
369 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
370 getApp(), SLOT(onSaveAsDoc()));
372 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
373 this, SLOT(onSaveDocByShaper()));
374 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
375 this, SLOT(onSaveAsDocByShaper()));
380 //******************************************************
381 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
383 saveToolbarsConfig();
385 myProxyViewer->activateViewer(false);
389 myWorkshop->deactivateModule();
391 QObject* aObj = myWorkshop->objectBrowser()->parent();
392 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
394 aObjDoc->setVisible(false);
395 myWorkshop->objectBrowser()->setVisible(false);
396 aObjDoc->toggleViewAction()->setVisible(false);
399 myIsInspectionVisible = myInspectionPanel->isVisible();
400 myInspectionPanel->hide();
401 myInspectionPanel->toggleViewAction()->setVisible(false);
403 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
404 myWorkshop->facesPanel()->hide();
405 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
407 myWorkshop->propertyPanel()->hide();
408 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
410 // the active operation should be stopped for the next activation.
411 // There should not be active operation and visualized preview.
412 // Abort operation should be performed before the selection's remove
413 // because the displayed objects should be removed from the viewer, but
414 // the AIS context is obtained from the selector.
415 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
416 while (anOperation) {
417 anOperation->abort();
418 anOperation = myWorkshop->operationMgr()->currentOperation();
420 // Delete selector because it has to be redefined on next activation
422 //if (!myHighlightPointAspect.IsNull()) {
423 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
424 // aTrihedron->getHighlightPointAspect()->SetAspect(myHighlightPointAspect);
425 // myHighlightPointAspect.Nullify();
427 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
428 myProxyViewer->setSelector(0);
430 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
431 QList<SUIT_Selector*> aList;
432 aMgr->selectors(aList);
433 foreach(SUIT_Selector* aSel, aList) {
434 aSel->setEnabled(aSel != mySelector);
441 myWorkshop->hidePanel(myWorkshop->facesPanel());
442 //myWorkshop->contextMenuMgr()->disconnectViewer();
444 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
445 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
446 getApp()->setEditEnabled(myIsEditEnabled);
448 myOldSelectionColor.clear();
450 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
451 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
452 this, SLOT(onScriptLoaded()));
454 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
455 this, SLOT(onSaveDocByShaper()));
456 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
457 this, SLOT(onSaveAsDocByShaper()));
459 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
460 getApp(), SLOT(onSaveDoc()));
461 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
462 getApp(), SLOT(onSaveAsDoc()));
466 return LightApp_Module::deactivateModule(theStudy);
469 //******************************************************
470 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
473 mySelector = createSelector(theMgr);
474 myWorkshop->selectionActivate()->updateSelectionFilters();
475 myWorkshop->selectionActivate()->updateSelectionModes();
476 myWorkshop->synchronizeViewer();
480 //******************************************************
481 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
484 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
485 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
486 if (mySelector->viewer() == aViewer) {
487 XGUI_Displayer* aDisp = myWorkshop->displayer();
488 QObjectPtrList aObjects = aDisp->displayedObjects();
490 foreach(ObjectPtr aObj, aObjects) {
491 aObj->setDisplayed(false);
492 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
494 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
495 aRes->setDisplayed(false);
499 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
500 myProxyViewer->setSelector(0);
504 myWorkshop->module()->clearViewer();
510 //******************************************************
511 QtxPopupMgr* SHAPERGUI::popupMgr()
514 myPopupMgr = new QtxPopupMgr( 0, this );
518 //******************************************************
519 void SHAPERGUI::onDefaultPreferences()
521 // reset main resources
522 ModuleBase_Preferences::resetResourcePreferences(preferences());
523 // reset plugin's resources
524 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
526 myWorkshop->displayer()->redisplayObjects();
529 //******************************************************
530 void SHAPERGUI::onScriptLoaded()
532 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
533 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
534 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
535 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
536 // it manually (because this method of application is protected)
537 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
540 myWorkshop->displayer()->updateViewer();
541 myWorkshop->updateCommandStatus();
544 //******************************************************
545 void SHAPERGUI::onSaveDocByShaper()
547 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
550 getApp()->onSaveDoc();
553 //******************************************************
554 void SHAPERGUI::onSaveAsDocByShaper()
556 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
559 getApp()->onSaveAsDoc();
562 //******************************************************
563 void SHAPERGUI::onUpdateCommandStatus()
565 getApp()->updateActions();
568 //******************************************************
569 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
571 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
572 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
574 //if (myHighlightPointAspect.IsNull()) {
575 // Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
576 // myHighlightPointAspect =
577 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
579 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
580 getApp()->selectionMgr());
581 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
582 aViewer->setUseLocalSelection(true);
584 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
585 QList<SUIT_Selector*> aList;
586 aMgr->selectors(aList);
587 foreach(SUIT_Selector* aSel, aList)
589 aSel->setEnabled(aSel == aSelector);
591 myProxyViewer->setSelector(aSelector);
593 if (myOldSelectionColor.size() == 0)
594 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
596 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
597 myWorkshop->displayer()->setSelectionColor(aColor);
603 //******************************************************
604 CAM_DataModel* SHAPERGUI::createDataModel()
606 return new SHAPERGUI_DataModel(this);
609 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
610 const bool isAddSeparator)
612 return addFeature(theWBName,
616 //Issue #650: in the SALOME mode the tooltip should be same as text
625 //******************************************************
626 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
627 const QString& theId, const QString& theTitle, const QString& theTip,
628 const QIcon& theIcon, const QKeySequence& theKeys,
629 bool isCheckable, const bool isAddSeparator,
630 const QString& theStatusTip)
632 static QString aLastTool = "";
634 if (aLastTool.isEmpty())
635 aLastTool = theWBName;
636 else if (theWBName != aLastTool) {
637 aLastTool = theWBName;
639 desktop()->addToolBarBreak();
645 int aId = getNextCommandId();
646 myActionsList.append(aId);
647 SUIT_Desktop* aDesk = application()->desktop();
649 for (int i = 0; i < theKeys.count(); i++)
651 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
653 aAction->setStatusTip(theStatusTip);
655 aAction->setData(theId);
657 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
658 int aItemId = createMenu(aId, aWBMenu);
660 createMenu(separator(), aWBMenu);
662 int aWBTool = createTool(theTBName, theTBName);
663 int aToolId = createTool(aId, aWBTool);
664 registerCommandToolbar(theTBName, aId);
665 if (isAddSeparator) {
666 createTool(separator(), aWBTool);
667 registerCommandToolbar(theTBName, -1);
672 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
674 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
677 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
678 const ActionInfo& theInfo,
679 const QList<QAction*>& theNestedActions)
681 SUIT_Desktop* aDesk = application()->desktop();
682 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
683 anAction->setData(theInfo.id);
684 anAction->setCheckable(theInfo.checkable);
685 anAction->setChecked(theInfo.checked);
686 anAction->setEnabled(theInfo.enabled);
687 anAction->setVisible(theInfo.visible);
688 anAction->setIcon(theInfo.icon);
689 anAction->setText(theInfo.text);
690 anAction->setToolTip(theInfo.toolTip);
691 anAction->setShortcut(theInfo.shortcut);
692 anAction->setFont(theInfo.font);
694 int aWBMenu = createMenu(theWBName, -1, -1, 30);
695 int aItemId = createMenu(anAction, aWBMenu);
696 myActionsList.append(aItemId);
697 createMenu(separator(), aWBMenu); /// nested action is always separated of others
699 int aWBTool = createTool(theWBName, theWBName);
700 int aToolId = createTool(anAction, aWBTool);
701 registerCommandToolbar(theWBName, aItemId);
702 createTool(separator(), aWBTool); /// nested action is always separated of others
703 registerCommandToolbar(theWBName, -1);
709 //******************************************************
710 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
711 const QString& theTip, const QIcon& theIcon,
712 const QKeySequence& theKeys, bool isCheckable,
713 const char* theMenuSourceText,
714 const QString& theSubMenu,
715 const int theMenuPosition,
716 const int theSuibMenuPosition)
718 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
719 if (!theSubMenu.isNull())
720 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
722 int aId = getNextCommandId();
723 myActionsList.append(aId);
724 SUIT_Desktop* aDesk = application()->desktop();
726 for (int i = 0; i < theKeys.count(); i++)
728 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
730 aAction->setStatusTip(theTip);
731 aAction->setData(theId);
732 createMenu(aId, aMenu, theMenuPosition);
736 //******************************************************
737 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
739 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
740 createMenu(separator(), aMenu, -1, theMenuPosition);
743 //******************************************************
744 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
749 SUIT_Desktop* aDesktop = application()->desktop();
753 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
757 aToolMgr->append( theAction, theToolBarTitle );
761 //******************************************************
762 QList<QAction*> SHAPERGUI::commandList() const
764 QList<QAction*> aActions;
765 foreach (int aId, myActionsList) {
766 QAction* aCmd = action(aId);
768 aActions.append(aCmd);
774 //******************************************************
775 QMainWindow* SHAPERGUI::desktop() const
777 return application()->desktop();
780 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
781 const std::shared_ptr<Config_FeatureMessage>& theMessage)
783 myFeaturesInfo.insert(theFeatureId, theMessage);
786 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
788 std::shared_ptr<Config_FeatureMessage> aMessage;
789 if (myFeaturesInfo.contains(theFeatureId))
790 aMessage = myFeaturesInfo[theFeatureId];
794 //******************************************************
795 void SHAPERGUI::selectionChanged()
797 LightApp_Module::selectionChanged();
798 myWorkshop->salomeViewerSelectionChanged();
801 //******************************************************
802 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
804 myWorkshop->contextMenuMgr()->updateViewerMenu();
805 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
806 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
810 //******************************************************
811 void SHAPERGUI::createPreferences()
813 LightApp_Preferences* pref = preferences();
816 ModuleBase_Preferences::updateConfigByResources();
817 QString aModName = moduleName();
819 QtxPreferenceItem* item = pref->findItem(aModName, true );
820 if ( item && (!item->isEmpty() )) {
821 item->parentItem()->removeItem(item);
825 int catId = pref->addPreference(aModName, -1 );
828 SHAPERGUI_PrefMgr aMgr(pref, aModName);
829 ModuleBase_Preferences::createEditContent(&aMgr, catId);
831 int viewTab = pref->addItem(tr("Viewer"), catId);
832 // Create other parameters group in viewer tab
833 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
834 pref->setItemProperty("columns", 3, otherGroup);
835 pref->addItem(tr("Faces"), otherGroup,
836 SUIT_PreferenceMgr::Bool,
837 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
838 pref->addItem(tr("Edges"), otherGroup,
839 SUIT_PreferenceMgr::Bool,
840 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
841 pref->addItem(tr("Vertices"), otherGroup,
842 SUIT_PreferenceMgr::Bool,
843 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
845 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
846 pref->setItemProperty("columns", 2, sensitivityGroup);
847 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
848 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
849 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
850 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
852 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
853 pref->setItemProperty("columns", 2, highlightGroup);
854 pref->addItem(tr("In 3d mode"), highlightGroup,
855 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
856 pref->addItem(tr("In 2d mode"), highlightGroup,
857 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
859 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
860 pref->setItemProperty("columns", 4, colorScaleGroup);
861 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
862 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
863 pref->setItemProperty("min", 0, aItem);
864 pref->setItemProperty("max", 1, aItem);
866 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
867 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
868 pref->setItemProperty("min", 0, aItem);
869 pref->setItemProperty("max", 1, aItem);
871 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
872 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
873 pref->setItemProperty("min", 0, aItem);
874 pref->setItemProperty("max", 1, aItem);
876 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
877 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
878 pref->setItemProperty("min", 0, aItem);
879 pref->setItemProperty("max", 1, aItem);
881 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
882 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
883 pref->setItemProperty("min", 0, aItem);
884 pref->setItemProperty("max", 100, aItem);
886 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
887 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
888 pref->setItemProperty("min", 0, aItem);
889 pref->setItemProperty("max", 100, aItem);
891 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
892 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
897 //******************************************************
898 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
900 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
901 QString aVal = aResMgr->stringValue(theSection, theParam);
902 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
903 theParam.toStdString());
904 std::string aValue = aVal.toStdString();
905 if (aValue.empty()) {
906 aValue = aProp->defaultValue();
907 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
909 LightApp_Preferences* pref = preferences();
913 aProp->setValue(aValue);
915 if ((theSection == "Visualization") && (theParam == "selection_color")) {
916 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
917 myWorkshop->displayer()->setSelectionColor(aColor);
920 myWorkshop->displayer()->redisplayObjects();
923 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
925 application()->putInfo(theInfo, theMSecs);
928 bool SHAPERGUI::abortAllOperations()
930 return workshop()->operationMgr()->abortAllOperations();
933 void SHAPERGUI::createFeatureActions()
935 myWorkshop->menuMgr()->createFeatureActions();
938 void SHAPERGUI::onWhatIs(bool isToggled)
940 if (sender() == myWhatIsAction) {
941 QAction* aViewAct = myInspectionPanel->toggleViewAction();
942 aViewAct->blockSignals(true);
943 aViewAct->setChecked(isToggled);
944 aViewAct->blockSignals(false);
945 myInspectionPanel->setVisible(isToggled);
948 myWhatIsAction->blockSignals(true);
949 myWhatIsAction->setChecked(isToggled);
950 myWhatIsAction->blockSignals(false);
951 myInspectionPanel->setVisible(isToggled);
955 void SHAPERGUI::updateModuleVisibilityState()
957 LightApp_Module::updateModuleVisibilityState();
958 onWhatIs(myIsInspectionVisible);
961 void SHAPERGUI::onEditToolbars()
963 SHAPERGUI_ToolbarsDlg aDlg(this);
964 if (aDlg.exec() == QDialog::Accepted) {
968 updateToolbars(aDlg.result());
972 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
974 if (!myToolbars.contains(theToolName))
975 myToolbars[theToolName] = QList<int>();
976 myToolbars[theToolName].append(theCommandId);
979 int SHAPERGUI::getNextCommandId() const
981 QtxActionMenuMgr* aMenuMgr = menuMgr();
982 QIntList aIds = aMenuMgr->idList();
983 int aId = aIds.count();
984 while (action(aId) || myActionsList.contains(aId))
989 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
991 // Store default toolbars
992 if (myDefaultToolbars.size() == 0)
993 myDefaultToolbars = myToolbars;
995 QtxActionToolMgr* aMgr = toolMgr();
996 QStringList aToolbars = theNewToolbars.keys();
997 QIntList aCommands, aOldCmd;
1001 foreach(QString aName, aToolbars) {
1002 aCommands = theNewToolbars[aName];
1003 // Find or create toolbar
1004 if (aMgr->hasToolBar(aName)) {
1005 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1006 aOldCmd = myToolbars[aName];
1009 aToolbarId = aMgr->createToolBar(aName);
1012 foreach(int aCmd, aCommands) {
1015 aAction = separator();
1017 aAction = action(aCmd);
1018 aActionId = aMgr->actionId(aAction);
1019 if (aActionId == -1) {
1021 aMgr->insert(aAction, aToolbarId, aPos);
1024 // Change position of action
1025 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1026 if (aMgr->containsAction(aActionId, aToolbarId))
1027 aMgr->remove(aActionId, aToolbarId);
1028 aMgr->insert(aActionId, aToolbarId, aPos);
1031 aOldCmd.removeAll(aCmd);
1034 // remove extra actions
1035 foreach(int aCmd, aOldCmd) {
1036 aAction = action(aCmd);
1037 aActionId = aMgr->actionId(aAction);
1038 aMgr->remove(aActionId, aToolbarId);
1040 myToolbars.remove(aName);
1042 // Remove extra toolbars
1043 aToolbars = myToolbars.keys();
1044 foreach(QString aName, aToolbars) {
1045 aMgr->removeToolBar(aName);
1047 // Set new toolbars structure
1048 myToolbars = theNewToolbars;
1049 myIsToolbarsModified = true;
1052 void SHAPERGUI::saveToolbarsConfig()
1054 if (!myIsToolbarsModified)
1056 // Save toolbars configuration into map
1057 QMap<QString, QStringList> aToolbarsConfig;
1058 QtxActionToolMgr* aMgr = toolMgr();
1059 QStringList aToolbars = myToolbars.keys();
1060 QIntList aActionsIds;
1061 foreach(QString aName, aToolbars) {
1062 aActionsIds = myToolbars[aName];
1063 QStringList aContent;
1064 foreach(int aId, aActionsIds) {
1066 aContent.append("");
1068 aContent.append(action(aId)->data().toString());
1070 aToolbarsConfig[aName] = aContent;
1072 // Store the configuration into resources
1073 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1074 QStringList aNames = aToolbarsConfig.keys();
1075 QStringList aValues;
1076 foreach(QString aToolbar, aNames) {
1077 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1079 // Remove obsolete parameters from resources
1080 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1081 foreach(QString aName, aOldParams) {
1082 if (!aToolbars.contains(aName))
1083 aResMgr->remove(ToolbarsSection, aName);
1085 // Store current list of free commands
1086 QIntList aFreeCommands = getFreeCommands();
1087 QStringList aFreeList;
1088 foreach(int aId, aFreeCommands) {
1089 aFreeList.append(action(aId)->data().toString());
1091 if (aFreeList.size() > 0)
1092 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1094 myIsToolbarsModified = false;
1097 void SHAPERGUI::loadToolbarsConfig()
1099 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1100 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1101 if (aToolbarNames.size() == 0)
1104 // Create commands map
1105 QMap<QString, int> aCommandsMap;
1107 foreach(int aId, myActionsList) {
1108 aCmdIdStr = action(aId)->data().toString();
1109 aCommandsMap[aCmdIdStr] = aId;
1112 // Create new toolbars structure
1113 QMap<QString, QIntList> aToolbars;
1114 QStringList aCommands;
1115 QIntList aKnownCommands;
1116 QList<QAction*> aActions;
1117 foreach(QString aName, aToolbarNames) {
1118 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1119 if (aName == FreeCommandsParam) {
1120 // The value is a list of free commands
1121 foreach(QString aCommand, aCommands) {
1122 aKnownCommands.append(aCommandsMap[aCommand]);
1126 aToolbars[aName] = QIntList();
1127 if (aCommands.size() > 0) {
1128 foreach(QString aCommand, aCommands) {
1129 if (aCommand.isEmpty())
1130 aToolbars[aName].append(-1);
1131 else if (aCommandsMap.contains(aCommand)) {
1132 int aId = aCommandsMap[aCommand];
1133 aToolbars[aName].append(aId);
1134 aKnownCommands.append(aId);
1140 // Find new and obsolete commands
1141 QIntList aNewCommands = myActionsList;
1142 foreach(int aId, myActionsList) {
1143 if (aKnownCommands.contains(aId)) {
1144 aKnownCommands.removeAll(aId);
1145 aNewCommands.removeAll(aId);
1148 if (aNewCommands.size() > 0) {
1149 // Add new commands to toolbars structure
1150 QStringList aKeys = myToolbars.keys();
1151 foreach(int aNewId, aNewCommands) {
1152 foreach(QString aName, aKeys) {
1153 if (myToolbars[aName].contains(aNewId)) {
1154 if (!aToolbars.contains(aName)) {
1155 aToolbars[aName] = QIntList();
1157 aToolbars[aName].append(aNewId);
1162 if (aKnownCommands.size() > 0) {
1163 // Remove obsolete commands from the toolbars structure
1164 QStringList aKeys = aToolbars.keys();
1165 foreach(int aOldId, aKnownCommands) {
1166 foreach(QString aName, aKeys) {
1167 if (aToolbars[aName].contains(aOldId)) {
1168 aToolbars[aName].removeAll(aOldId);
1169 if (aToolbars[aName].size() == 0)
1170 aToolbars.remove(aName);
1175 updateToolbars(aToolbars);
1176 myIsToolbarsModified = false;
1180 QIntList SHAPERGUI::getFreeCommands() const
1182 QIntList aFreeCommands;
1183 QtxActionToolMgr* aMgr = toolMgr();
1186 QMap<QString, QIntList>::const_iterator aIt;
1187 QIntList aShaperActions = shaperActions();
1188 foreach(int aCmd, aShaperActions) {
1189 anAction = action(aCmd);
1190 aId = aMgr->actionId(anAction);
1191 if (!aMgr->containsAction(aId))
1192 aFreeCommands.append(aCmd);
1194 return aFreeCommands;
1197 void SHAPERGUI::resetToolbars()
1199 if (!myDefaultToolbars.isEmpty())
1200 updateToolbars(myDefaultToolbars);
1201 myIsToolbarsModified = false;
1202 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1203 aResMgr->remove(ToolbarsSection);
1206 void SHAPERGUI::publishToStudy()
1208 if (isActiveModule())
1209 myWorkshop->module()->launchOperation("PublishToStudy", false);