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), 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 QAction* aViewAct = aObjDoc->toggleViewAction();
273 aViewAct->setEnabled(true);
274 myWorkshop->objectBrowser()->setVisible(true);
275 aObjDoc->setVisible(true);
276 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
279 if (!myInspectionPanel) {
280 myInspectionPanel = myWorkshop->inspectionPanel();
281 QAction* aViewAct = myInspectionPanel->toggleViewAction();
282 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
284 myInspectionPanel->toggleViewAction()->setEnabled(true);
287 ViewManagerList OCCViewManagers;
288 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
289 if (OCCViewManagers.size() > 0) {
290 onViewManagerAdded(OCCViewManagers.first());
293 // it should be performed after the selector creation in order to have AISContext
294 myWorkshop->activateModule();
295 //action(myEraseAll)->setEnabled(false);
298 myWorkshop->objectBrowser()->rebuildDataTree();
299 myWorkshop->updateCommandStatus();
303 myWorkshop->updateCommandStatus();
305 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
306 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
307 myIsEditEnabled = getApp()->isEditEnabled();
308 getApp()->setEditEnabled(false);
310 // this following row is caused by #187 bug.
311 // SALOME saves the dock widget positions before deactivateModule() and
312 // load it after the module activation. So, if the panel is visible before
313 // deactivate, it becomes visible after activate.
314 // In order to avoid the visible property panel, the widget position save is
315 // switch off in this module
316 aResMgr->setValue("Study", "store_positions", false);
318 // Synchronize displayed objects
319 Handle(AIS_InteractiveContext) aContext;
320 if (mySelector && mySelector->viewer())
321 aContext = mySelector->viewer()->getAISContext();
323 if (!aContext.IsNull()) {
324 XGUI_Displayer* aDisp = myWorkshop->displayer();
325 QObjectPtrList aObjList = aDisp->displayedObjects();
327 //if (myHighlightPointAspect.IsNull()) {
328 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
329 // myHighlightPointAspect =
330 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
332 if (myOldSelectionColor.size() == 0)
333 myOldSelectionColor = aDisp->selectionColor();
335 AIS_ListOfInteractive aList;
336 aContext->DisplayedObjects(aList);
337 AIS_ListIteratorOfListOfInteractive aLIt;
338 Handle(AIS_InteractiveObject) anAISIO;
339 foreach (ObjectPtr aObj, aObjList) {
340 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
341 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
343 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
344 anAISIO = aLIt.Value();
345 if (anAISIO.get() == aAIS.get()) {
351 aObj->setDisplayed(false);
352 //aDisp->erase(aObj, false);
355 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
357 myProxyViewer->activateViewer(true);
359 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
360 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
361 this, SLOT(onScriptLoaded()));
363 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
364 getApp(), SLOT(onSaveDoc()));
365 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
366 getApp(), SLOT(onSaveAsDoc()));
368 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
369 this, SLOT(onSaveDocByShaper()));
370 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
371 this, SLOT(onSaveAsDocByShaper()));
376 //******************************************************
377 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
379 saveToolbarsConfig();
381 myProxyViewer->activateViewer(false);
385 myWorkshop->deactivateModule();
387 QObject* aObj = myWorkshop->objectBrowser()->parent();
388 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
390 aObjDoc->setVisible(false);
391 myWorkshop->objectBrowser()->setVisible(false);
392 QAction* aViewAct = aObjDoc->toggleViewAction();
393 aViewAct->setEnabled(false);
396 myIsInspectionVisible = myInspectionPanel->isVisible();
397 myInspectionPanel->hide();
398 QAction* aViewAct = myInspectionPanel->toggleViewAction();
399 aViewAct->setEnabled(false);
401 // the active operation should be stopped for the next activation.
402 // There should not be active operation and visualized preview.
403 // Abort operation should be performed before the selection's remove
404 // because the displayed objects should be removed from the viewer, but
405 // the AIS context is obtained from the selector.
406 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
407 while (anOperation) {
408 anOperation->abort();
409 anOperation = myWorkshop->operationMgr()->currentOperation();
411 // Delete selector because it has to be redefined on next activation
413 //if (!myHighlightPointAspect.IsNull()) {
414 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
415 // aTrihedron->getHighlightPointAspect()->SetAspect(myHighlightPointAspect);
416 // myHighlightPointAspect.Nullify();
418 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
419 myProxyViewer->setSelector(0);
421 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
422 QList<SUIT_Selector*> aList;
423 aMgr->selectors(aList);
424 foreach(SUIT_Selector* aSel, aList) {
425 aSel->setEnabled(aSel != mySelector);
432 myWorkshop->hidePanel(myWorkshop->facesPanel());
433 //myWorkshop->contextMenuMgr()->disconnectViewer();
435 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
436 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
437 getApp()->setEditEnabled(myIsEditEnabled);
439 myOldSelectionColor.clear();
441 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
442 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
443 this, SLOT(onScriptLoaded()));
445 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
446 this, SLOT(onSaveDocByShaper()));
447 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
448 this, SLOT(onSaveAsDocByShaper()));
450 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
451 getApp(), SLOT(onSaveDoc()));
452 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
453 getApp(), SLOT(onSaveAsDoc()));
455 return LightApp_Module::deactivateModule(theStudy);
458 //******************************************************
459 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
462 mySelector = createSelector(theMgr);
463 myWorkshop->selectionActivate()->updateSelectionFilters();
464 myWorkshop->selectionActivate()->updateSelectionModes();
465 myWorkshop->synchronizeViewer();
469 //******************************************************
470 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
473 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
474 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
475 if (mySelector->viewer() == aViewer) {
476 XGUI_Displayer* aDisp = myWorkshop->displayer();
477 QObjectPtrList aObjects = aDisp->displayedObjects();
479 foreach(ObjectPtr aObj, aObjects) {
480 aObj->setDisplayed(false);
481 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
483 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
484 aRes->setDisplayed(false);
488 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
489 myProxyViewer->setSelector(0);
493 myWorkshop->module()->clearViewer();
499 //******************************************************
500 QtxPopupMgr* SHAPERGUI::popupMgr()
503 myPopupMgr = new QtxPopupMgr( 0, this );
507 //******************************************************
508 void SHAPERGUI::onDefaultPreferences()
510 // reset main resources
511 ModuleBase_Preferences::resetResourcePreferences(preferences());
512 // reset plugin's resources
513 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
515 myWorkshop->displayer()->redisplayObjects();
518 //******************************************************
519 void SHAPERGUI::onScriptLoaded()
521 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
522 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
523 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
524 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
525 // it manually (because this method of application is protected)
526 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
529 myWorkshop->displayer()->updateViewer();
530 myWorkshop->updateCommandStatus();
533 //******************************************************
534 void SHAPERGUI::onSaveDocByShaper()
536 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
539 getApp()->onSaveDoc();
542 //******************************************************
543 void SHAPERGUI::onSaveAsDocByShaper()
545 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
548 getApp()->onSaveAsDoc();
551 //******************************************************
552 void SHAPERGUI::onUpdateCommandStatus()
554 getApp()->updateActions();
557 //******************************************************
558 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
560 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
561 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
563 //if (myHighlightPointAspect.IsNull()) {
564 // Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
565 // myHighlightPointAspect =
566 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
568 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
569 getApp()->selectionMgr());
570 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
571 aViewer->setUseLocalSelection(true);
573 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
574 QList<SUIT_Selector*> aList;
575 aMgr->selectors(aList);
576 foreach(SUIT_Selector* aSel, aList)
578 aSel->setEnabled(aSel == aSelector);
580 myProxyViewer->setSelector(aSelector);
582 if (myOldSelectionColor.size() == 0)
583 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
585 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
586 myWorkshop->displayer()->setSelectionColor(aColor);
592 //******************************************************
593 CAM_DataModel* SHAPERGUI::createDataModel()
595 return new SHAPERGUI_DataModel(this);
598 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
599 const bool isAddSeparator)
601 return addFeature(theWBName,
605 //Issue #650: in the SALOME mode the tooltip should be same as text
614 //******************************************************
615 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
616 const QString& theId, const QString& theTitle, const QString& theTip,
617 const QIcon& theIcon, const QKeySequence& theKeys,
618 bool isCheckable, const bool isAddSeparator,
619 const QString& theStatusTip)
621 static QString aLastTool = "";
623 if (aLastTool.isEmpty())
624 aLastTool = theWBName;
625 else if (theWBName != aLastTool) {
626 aLastTool = theWBName;
628 desktop()->addToolBarBreak();
634 int aId = getNextCommandId();
635 myActionsList.append(aId);
636 SUIT_Desktop* aDesk = application()->desktop();
638 for (int i = 0; i < theKeys.count(); i++)
640 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
642 aAction->setStatusTip(theStatusTip);
644 aAction->setData(theId);
646 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
647 int aItemId = createMenu(aId, aWBMenu);
649 createMenu(separator(), aWBMenu);
651 int aWBTool = createTool(theTBName, theTBName);
652 int aToolId = createTool(aId, aWBTool);
653 registerCommandToolbar(theTBName, aId);
654 if (isAddSeparator) {
655 createTool(separator(), aWBTool);
656 registerCommandToolbar(theTBName, -1);
661 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
663 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
666 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
667 const ActionInfo& theInfo,
668 const QList<QAction*>& theNestedActions)
670 SUIT_Desktop* aDesk = application()->desktop();
671 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
672 anAction->setData(theInfo.id);
673 anAction->setCheckable(theInfo.checkable);
674 anAction->setChecked(theInfo.checked);
675 anAction->setEnabled(theInfo.enabled);
676 anAction->setVisible(theInfo.visible);
677 anAction->setIcon(theInfo.icon);
678 anAction->setText(theInfo.text);
679 anAction->setToolTip(theInfo.toolTip);
680 anAction->setShortcut(theInfo.shortcut);
681 anAction->setFont(theInfo.font);
683 int aWBMenu = createMenu(theWBName, -1, -1, 30);
684 int aItemId = createMenu(anAction, aWBMenu);
685 myActionsList.append(aItemId);
686 createMenu(separator(), aWBMenu); /// nested action is always separated of others
688 int aWBTool = createTool(theWBName, theWBName);
689 int aToolId = createTool(anAction, aWBTool);
690 registerCommandToolbar(theWBName, aItemId);
691 createTool(separator(), aWBTool); /// nested action is always separated of others
692 registerCommandToolbar(theWBName, -1);
698 //******************************************************
699 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
700 const QString& theTip, const QIcon& theIcon,
701 const QKeySequence& theKeys, bool isCheckable,
702 const char* theMenuSourceText,
703 const QString& theSubMenu,
704 const int theMenuPosition,
705 const int theSuibMenuPosition)
707 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
708 if (!theSubMenu.isNull())
709 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
711 int aId = getNextCommandId();
712 myActionsList.append(aId);
713 SUIT_Desktop* aDesk = application()->desktop();
715 for (int i = 0; i < theKeys.count(); i++)
717 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
719 aAction->setStatusTip(theTip);
720 aAction->setData(theId);
721 createMenu(aId, aMenu, theMenuPosition);
725 //******************************************************
726 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
728 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
729 createMenu(separator(), aMenu, -1, theMenuPosition);
732 //******************************************************
733 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
738 SUIT_Desktop* aDesktop = application()->desktop();
742 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
746 aToolMgr->append( theAction, theToolBarTitle );
750 //******************************************************
751 QList<QAction*> SHAPERGUI::commandList() const
753 QList<QAction*> aActions;
754 foreach (int aId, myActionsList) {
755 QAction* aCmd = action(aId);
757 aActions.append(aCmd);
763 //******************************************************
764 QMainWindow* SHAPERGUI::desktop() const
766 return application()->desktop();
769 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
770 const std::shared_ptr<Config_FeatureMessage>& theMessage)
772 myFeaturesInfo.insert(theFeatureId, theMessage);
775 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
777 std::shared_ptr<Config_FeatureMessage> aMessage;
778 if (myFeaturesInfo.contains(theFeatureId))
779 aMessage = myFeaturesInfo[theFeatureId];
783 //******************************************************
784 void SHAPERGUI::selectionChanged()
786 LightApp_Module::selectionChanged();
787 myWorkshop->salomeViewerSelectionChanged();
790 //******************************************************
791 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
793 myWorkshop->contextMenuMgr()->updateViewerMenu();
794 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
795 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
799 //******************************************************
800 void SHAPERGUI::createPreferences()
802 LightApp_Preferences* pref = preferences();
805 ModuleBase_Preferences::updateConfigByResources();
806 QString aModName = moduleName();
808 QtxPreferenceItem* item = pref->findItem(aModName, true );
809 if ( item && (!item->isEmpty() )) {
810 item->parentItem()->removeItem(item);
814 int catId = pref->addPreference(aModName, -1 );
817 SHAPERGUI_PrefMgr aMgr(pref, aModName);
818 ModuleBase_Preferences::createEditContent(&aMgr, catId);
820 int viewTab = pref->addItem(tr("Viewer"), catId);
821 // Create other parameters group in viewer tab
822 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
823 pref->setItemProperty("columns", 3, otherGroup);
824 pref->addItem(tr("Faces"), otherGroup,
825 SUIT_PreferenceMgr::Bool,
826 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
827 pref->addItem(tr("Edges"), otherGroup,
828 SUIT_PreferenceMgr::Bool,
829 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
830 pref->addItem(tr("Vertices"), otherGroup,
831 SUIT_PreferenceMgr::Bool,
832 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
834 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
835 pref->setItemProperty("columns", 2, sensitivityGroup);
836 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
837 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
838 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
839 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
841 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
842 pref->setItemProperty("columns", 2, highlightGroup);
843 pref->addItem(tr("In 3d mode"), highlightGroup,
844 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
845 pref->addItem(tr("In 2d mode"), highlightGroup,
846 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
848 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
849 pref->setItemProperty("columns", 4, colorScaleGroup);
850 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
851 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
852 pref->setItemProperty("min", 0, aItem);
853 pref->setItemProperty("max", 1, aItem);
855 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
856 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
857 pref->setItemProperty("min", 0, aItem);
858 pref->setItemProperty("max", 1, aItem);
860 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
861 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
862 pref->setItemProperty("min", 0, aItem);
863 pref->setItemProperty("max", 1, aItem);
865 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
866 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
867 pref->setItemProperty("min", 0, aItem);
868 pref->setItemProperty("max", 1, aItem);
870 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
871 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
872 pref->setItemProperty("min", 0, aItem);
873 pref->setItemProperty("max", 100, aItem);
875 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
876 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
877 pref->setItemProperty("min", 0, aItem);
878 pref->setItemProperty("max", 100, aItem);
880 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
881 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
886 //******************************************************
887 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
889 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
890 QString aVal = aResMgr->stringValue(theSection, theParam);
891 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
892 theParam.toStdString());
893 std::string aValue = aVal.toStdString();
894 if (aValue.empty()) {
895 aValue = aProp->defaultValue();
896 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
898 LightApp_Preferences* pref = preferences();
902 aProp->setValue(aValue);
904 if ((theSection == "Visualization") && (theParam == "selection_color")) {
905 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
906 myWorkshop->displayer()->setSelectionColor(aColor);
909 myWorkshop->displayer()->redisplayObjects();
912 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
914 application()->putInfo(theInfo, theMSecs);
917 bool SHAPERGUI::abortAllOperations()
919 return workshop()->operationMgr()->abortAllOperations();
922 void SHAPERGUI::createFeatureActions()
924 myWorkshop->menuMgr()->createFeatureActions();
927 void SHAPERGUI::onWhatIs(bool isToggled)
929 if (sender() == myWhatIsAction) {
930 QAction* aViewAct = myInspectionPanel->toggleViewAction();
931 aViewAct->blockSignals(true);
932 aViewAct->setChecked(isToggled);
933 aViewAct->blockSignals(false);
934 myInspectionPanel->setVisible(isToggled);
937 myWhatIsAction->blockSignals(true);
938 myWhatIsAction->setChecked(isToggled);
939 myWhatIsAction->blockSignals(false);
940 myInspectionPanel->setVisible(isToggled);
944 void SHAPERGUI::updateModuleVisibilityState()
946 LightApp_Module::updateModuleVisibilityState();
947 onWhatIs(myIsInspectionVisible);
950 void SHAPERGUI::onEditToolbars()
952 SHAPERGUI_ToolbarsDlg aDlg(this);
953 if (aDlg.exec() == QDialog::Accepted) {
957 updateToolbars(aDlg.result());
961 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
963 if (!myToolbars.contains(theToolName))
964 myToolbars[theToolName] = QList<int>();
965 myToolbars[theToolName].append(theCommandId);
968 int SHAPERGUI::getNextCommandId() const
970 QtxActionMenuMgr* aMenuMgr = menuMgr();
971 QIntList aIds = aMenuMgr->idList();
972 int aId = aIds.count();
973 while (action(aId) || myActionsList.contains(aId))
978 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
980 // Store default toolbars
981 if (myDefaultToolbars.size() == 0)
982 myDefaultToolbars = myToolbars;
984 QtxActionToolMgr* aMgr = toolMgr();
985 QStringList aToolbars = theNewToolbars.keys();
986 QIntList aCommands, aOldCmd;
990 foreach(QString aName, aToolbars) {
991 aCommands = theNewToolbars[aName];
992 // Find or create toolbar
993 if (aMgr->hasToolBar(aName)) {
994 aToolbarId = aMgr->find(aMgr->toolBar(aName));
995 aOldCmd = myToolbars[aName];
998 aToolbarId = aMgr->createToolBar(aName);
1001 foreach(int aCmd, aCommands) {
1004 aAction = separator();
1006 aAction = action(aCmd);
1007 aActionId = aMgr->actionId(aAction);
1008 if (aActionId == -1) {
1010 aMgr->insert(aAction, aToolbarId, aPos);
1013 // Change position of action
1014 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1015 if (aMgr->containsAction(aActionId, aToolbarId))
1016 aMgr->remove(aActionId, aToolbarId);
1017 aMgr->insert(aActionId, aToolbarId, aPos);
1020 aOldCmd.removeAll(aCmd);
1023 // remove extra actions
1024 foreach(int aCmd, aOldCmd) {
1025 aAction = action(aCmd);
1026 aActionId = aMgr->actionId(aAction);
1027 aMgr->remove(aActionId, aToolbarId);
1029 myToolbars.remove(aName);
1031 // Remove extra toolbars
1032 aToolbars = myToolbars.keys();
1033 foreach(QString aName, aToolbars) {
1034 aMgr->removeToolBar(aName);
1036 // Set new toolbars structure
1037 myToolbars = theNewToolbars;
1038 myIsToolbarsModified = true;
1041 void SHAPERGUI::saveToolbarsConfig()
1043 if (!myIsToolbarsModified)
1045 // Save toolbars configuration into map
1046 QMap<QString, QStringList> aToolbarsConfig;
1047 QtxActionToolMgr* aMgr = toolMgr();
1048 QStringList aToolbars = myToolbars.keys();
1049 QIntList aActionsIds;
1050 foreach(QString aName, aToolbars) {
1051 aActionsIds = myToolbars[aName];
1052 QStringList aContent;
1053 foreach(int aId, aActionsIds) {
1055 aContent.append("");
1057 aContent.append(action(aId)->data().toString());
1059 aToolbarsConfig[aName] = aContent;
1061 // Store the configuration into resources
1062 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1063 QStringList aNames = aToolbarsConfig.keys();
1064 QStringList aValues;
1065 foreach(QString aToolbar, aNames) {
1066 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1068 // Remove obsolete parameters from resources
1069 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1070 foreach(QString aName, aOldParams) {
1071 if (!aToolbars.contains(aName))
1072 aResMgr->remove(ToolbarsSection, aName);
1074 // Store current list of free commands
1075 QIntList aFreeCommands = getFreeCommands();
1076 QStringList aFreeList;
1077 foreach(int aId, aFreeCommands) {
1078 aFreeList.append(action(aId)->data().toString());
1080 if (aFreeList.size() > 0)
1081 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1083 myIsToolbarsModified = false;
1086 void SHAPERGUI::loadToolbarsConfig()
1088 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1089 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1090 if (aToolbarNames.size() == 0)
1093 // Create commands map
1094 QMap<QString, int> aCommandsMap;
1096 foreach(int aId, myActionsList) {
1097 aCmdIdStr = action(aId)->data().toString();
1098 aCommandsMap[aCmdIdStr] = aId;
1101 // Create new toolbars structure
1102 QMap<QString, QIntList> aToolbars;
1103 QStringList aCommands;
1104 QIntList aKnownCommands;
1105 QList<QAction*> aActions;
1106 foreach(QString aName, aToolbarNames) {
1107 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1108 if (aName == FreeCommandsParam) {
1109 // The value is a list of free commands
1110 foreach(QString aCommand, aCommands) {
1111 aKnownCommands.append(aCommandsMap[aCommand]);
1115 aToolbars[aName] = QIntList();
1116 if (aCommands.size() > 0) {
1117 foreach(QString aCommand, aCommands) {
1118 if (aCommand.isEmpty())
1119 aToolbars[aName].append(-1);
1120 else if (aCommandsMap.contains(aCommand)) {
1121 int aId = aCommandsMap[aCommand];
1122 aToolbars[aName].append(aId);
1123 aKnownCommands.append(aId);
1129 // Find new and obsolete commands
1130 QIntList aNewCommands = myActionsList;
1131 foreach(int aId, myActionsList) {
1132 if (aKnownCommands.contains(aId)) {
1133 aKnownCommands.removeAll(aId);
1134 aNewCommands.removeAll(aId);
1137 if (aNewCommands.size() > 0) {
1138 // Add new commands to toolbars structure
1139 QStringList aKeys = myToolbars.keys();
1140 foreach(int aNewId, aNewCommands) {
1141 foreach(QString aName, aKeys) {
1142 if (myToolbars[aName].contains(aNewId)) {
1143 if (!aToolbars.contains(aName)) {
1144 aToolbars[aName] = QIntList();
1146 aToolbars[aName].append(aNewId);
1151 if (aKnownCommands.size() > 0) {
1152 // Remove obsolete commands from the toolbars structure
1153 QStringList aKeys = aToolbars.keys();
1154 foreach(int aOldId, aKnownCommands) {
1155 foreach(QString aName, aKeys) {
1156 if (aToolbars[aName].contains(aOldId)) {
1157 aToolbars[aName].removeAll(aOldId);
1158 if (aToolbars[aName].size() == 0)
1159 aToolbars.remove(aName);
1164 updateToolbars(aToolbars);
1165 myIsToolbarsModified = false;
1169 QIntList SHAPERGUI::getFreeCommands() const
1171 QIntList aFreeCommands;
1172 QtxActionToolMgr* aMgr = toolMgr();
1175 QMap<QString, QIntList>::const_iterator aIt;
1176 QIntList aShaperActions = shaperActions();
1177 foreach(int aCmd, aShaperActions) {
1178 anAction = action(aCmd);
1179 aId = aMgr->actionId(anAction);
1180 if (!aMgr->containsAction(aId))
1181 aFreeCommands.append(aCmd);
1183 return aFreeCommands;
1186 void SHAPERGUI::resetToolbars()
1188 if (!myDefaultToolbars.isEmpty())
1189 updateToolbars(myDefaultToolbars);
1190 myIsToolbarsModified = false;
1191 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1192 aResMgr->remove(ToolbarsSection);