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 #define SALOME_PATCH_FOR_CTRL_WHEEL
80 SHAPERGUI_EXPORT CAM_Module* createModule()
82 return new SHAPERGUI();
85 SHAPERGUI_EXPORT char* getModuleVersion()
92 static const QString ToolbarsSection("SHAPER_Toolbars");
93 static const QString FreeCommandsParam("OutOFToolbars");
97 * Class for preferences management
99 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
103 /// \param theMgr preferences manager of SALOME
104 /// \param theModName name of the module
105 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
106 myMgr(theMgr), myModName(theModName) {}
108 virtual int addPreference(const QString& theLbl, int pId,
109 SUIT_PreferenceMgr::PrefItemType theType,
110 const QString& theSection, const QString& theName )
112 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
115 virtual void setItemProperty(const QString& thePropName,
116 const QVariant& theValue,
117 const int theId = -1)
119 myMgr->setItemProperty(thePropName, theValue, theId);
123 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
126 LightApp_Preferences* myMgr;
133 //******************************************************
134 SHAPERGUI::SHAPERGUI()
135 : LightApp_Module("SHAPER"),
136 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
137 myInspectionPanel(0), myIsToolbarsModified(false)
139 myWorkshop = new XGUI_Workshop(this);
140 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
141 this, SLOT(onUpdateCommandStatus()));
143 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
145 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
147 // It will be called in XGUI_Workshop::startApplication
148 // ModuleBase_Preferences::loadCustomProps();
151 //******************************************************
152 SHAPERGUI::~SHAPERGUI()
155 delete myProxyViewer;
158 //******************************************************
159 void SHAPERGUI::initialize(CAM_Application* theApp)
161 LightApp_Module::initialize(theApp);
163 myWorkshop->startApplication();
164 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
167 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
170 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
171 int aSubMenu = createMenu(tr("Information"), aMenu);
173 int aId = getNextCommandId();
174 myActionsList.append(aId);
175 SUIT_Desktop* aDesk = application()->desktop();
176 QString aTip = tr("Show inspection window");
177 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
178 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
179 myWhatIsAction->setStatusTip(aTip);
180 myWhatIsAction->setData("INSPECTION_CMD");
181 createMenu(aId, aSubMenu, 0);
183 QString aToolName = tr("Inspection tool");
184 int aTool = createTool(aToolName);
185 int aToolId = createTool(myWhatIsAction, aTool);
186 registerCommandToolbar(aToolName, aId);
188 // Define Edit toolbars command
189 aId = getNextCommandId();
190 //myActionsList.append(aId); Do not use it for editing of toolbars
191 aTip = tr("Edit toolbars of the module");
192 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
193 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
194 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
195 int aEditItem = createMenu(aId, aEditMenu);
197 // Initialize viewer proxy if OCC viewer is already exist
198 ViewManagerList aOCCViewManagers;
199 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
200 if (aOCCViewManagers.size() > 0) {
201 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
202 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
204 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
205 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
207 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
208 aViewPort->installEventFilter(aViewer);
209 Handle(V3d_View) aView = aViewPort->getView();
210 aViewer->SetScale(aView, aView->Camera()->Scale());
211 // We can not create selector here because other modules will be deactivated later
212 //onViewManagerAdded(aMgr);
218 //******************************************************
219 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
221 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
224 //******************************************************
225 void SHAPERGUI::viewManagers(QStringList& theList) const
227 theList.append(OCCViewer_Viewer::Type());
230 //******************************************************
231 // We can not create selector in this method because it can be called when
232 // SHAPER module is not active. Take into account that creation of our selector
233 // leads to switching OFF all other selectors
234 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
236 // // if there are created viewer managers, we should try to create viewer
237 // // selector and initialize viewer with it. It sets interactive context to the
238 // // proxy viewer. If study is opened, CAM application calls this method before the open()
240 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
241 // // we need to connect to the viewer before it. Here,
242 // // it seems the most appropriate place for this
243 // // according to SALOME architecture.
244 // if (!mySelector) {
245 // ViewManagerList OCCViewManagers;
246 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
247 // if (OCCViewManagers.size() > 0) {
248 // mySelector = createSelector(OCCViewManagers.first());
251 // LightApp_Module::connectToStudy(theStudy);
254 //******************************************************
255 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
257 bool isDone = LightApp_Module::activateModule(theStudy);
258 loadToolbarsConfig();
260 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
261 aDataModel->initRootObject();
267 QObject* aObj = myWorkshop->objectBrowser()->parent();
268 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
270 QAction* aViewAct = aObjDoc->toggleViewAction();
271 aViewAct->setEnabled(true);
272 myWorkshop->objectBrowser()->setVisible(true);
273 aObjDoc->setVisible(true);
274 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
277 if (!myInspectionPanel) {
278 myInspectionPanel = myWorkshop->inspectionPanel();
279 QAction* aViewAct = myInspectionPanel->toggleViewAction();
280 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
282 myInspectionPanel->toggleViewAction()->setEnabled(true);
285 ViewManagerList OCCViewManagers;
286 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
287 if (OCCViewManagers.size() > 0) {
288 onViewManagerAdded(OCCViewManagers.first());
291 // it should be performed after the selector creation in order to have AISContext
292 myWorkshop->activateModule();
293 //action(myEraseAll)->setEnabled(false);
296 myWorkshop->objectBrowser()->rebuildDataTree();
297 myWorkshop->updateCommandStatus();
301 myWorkshop->updateCommandStatus();
303 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
304 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
305 myIsEditEnabled = getApp()->isEditEnabled();
306 getApp()->setEditEnabled(false);
308 // this following row is caused by #187 bug.
309 // SALOME saves the dock widget positions before deactivateModule() and
310 // load it after the module activation. So, if the panel is visible before
311 // deactivate, it becomes visible after activate.
312 // In order to avoid the visible property panel, the widget position save is
313 // switch off in this module
314 aResMgr->setValue("Study", "store_positions", false);
316 // Synchronize displayed objects
317 Handle(AIS_InteractiveContext) aContext;
318 if (mySelector && mySelector->viewer())
319 aContext = mySelector->viewer()->getAISContext();
321 if (!aContext.IsNull()) {
322 XGUI_Displayer* aDisp = myWorkshop->displayer();
323 QObjectPtrList aObjList = aDisp->displayedObjects();
325 //if (myHighlightPointAspect.IsNull()) {
326 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
327 // myHighlightPointAspect =
328 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
330 if (myOldSelectionColor.size() == 0)
331 myOldSelectionColor = aDisp->selectionColor();
333 AIS_ListOfInteractive aList;
334 aContext->DisplayedObjects(aList);
335 AIS_ListIteratorOfListOfInteractive aLIt;
336 Handle(AIS_InteractiveObject) anAISIO;
337 foreach (ObjectPtr aObj, aObjList) {
338 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
339 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
341 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
342 anAISIO = aLIt.Value();
343 if (anAISIO.get() == aAIS.get()) {
349 aObj->setDisplayed(false);
350 //aDisp->erase(aObj, false);
353 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
355 myProxyViewer->activateViewer(true);
357 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
358 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
359 this, SLOT(onScriptLoaded()));
361 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
362 getApp(), SLOT(onSaveDoc()));
363 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
364 getApp(), SLOT(onSaveAsDoc()));
366 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
367 this, SLOT(onSaveDocByShaper()));
368 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
369 this, SLOT(onSaveAsDocByShaper()));
374 //******************************************************
375 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
377 saveToolbarsConfig();
379 myProxyViewer->activateViewer(false);
383 myWorkshop->deactivateModule();
385 QObject* aObj = myWorkshop->objectBrowser()->parent();
386 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
388 aObjDoc->setVisible(false);
389 myWorkshop->objectBrowser()->setVisible(false);
390 QAction* aViewAct = aObjDoc->toggleViewAction();
391 aViewAct->setEnabled(false);
394 myIsInspectionVisible = myInspectionPanel->isVisible();
395 myInspectionPanel->hide();
396 QAction* aViewAct = myInspectionPanel->toggleViewAction();
397 aViewAct->setEnabled(false);
399 // the active operation should be stopped for the next activation.
400 // There should not be active operation and visualized preview.
401 // Abort operation should be performed before the selection's remove
402 // because the displayed objects should be removed from the viewer, but
403 // the AIS context is obtained from the selector.
404 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
405 while (anOperation) {
406 anOperation->abort();
407 anOperation = myWorkshop->operationMgr()->currentOperation();
409 // Delete selector because it has to be redefined on next activation
411 //if (!myHighlightPointAspect.IsNull()) {
412 // Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
413 // aTrihedron->getHighlightPointAspect()->SetAspect(myHighlightPointAspect);
414 // myHighlightPointAspect.Nullify();
416 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
417 myProxyViewer->setSelector(0);
422 myWorkshop->hidePanel(myWorkshop->facesPanel());
423 //myWorkshop->contextMenuMgr()->disconnectViewer();
425 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
426 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
427 getApp()->setEditEnabled(myIsEditEnabled);
429 myOldSelectionColor.clear();
431 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
432 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
433 this, SLOT(onScriptLoaded()));
435 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
436 this, SLOT(onSaveDocByShaper()));
437 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
438 this, SLOT(onSaveAsDocByShaper()));
440 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
441 getApp(), SLOT(onSaveDoc()));
442 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
443 getApp(), SLOT(onSaveAsDoc()));
447 return LightApp_Module::deactivateModule(theStudy);
450 //******************************************************
451 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
454 mySelector = createSelector(theMgr);
455 myWorkshop->selectionActivate()->updateSelectionFilters();
456 myWorkshop->selectionActivate()->updateSelectionModes();
457 myWorkshop->synchronizeViewer();
461 //******************************************************
462 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
465 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
466 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
467 if (mySelector->viewer() == aViewer) {
468 XGUI_Displayer* aDisp = myWorkshop->displayer();
469 QObjectPtrList aObjects = aDisp->displayedObjects();
471 foreach(ObjectPtr aObj, aObjects) {
472 aObj->setDisplayed(false);
473 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
475 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
476 aRes->setDisplayed(false);
480 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
481 myProxyViewer->setSelector(0);
485 myWorkshop->module()->clearViewer();
491 //******************************************************
492 QtxPopupMgr* SHAPERGUI::popupMgr()
495 myPopupMgr = new QtxPopupMgr( 0, this );
499 //******************************************************
500 void SHAPERGUI::onDefaultPreferences()
502 // reset main resources
503 ModuleBase_Preferences::resetResourcePreferences(preferences());
504 // reset plugin's resources
505 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
507 myWorkshop->displayer()->redisplayObjects();
510 //******************************************************
511 void SHAPERGUI::onScriptLoaded()
513 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
514 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
515 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
516 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
517 // it manually (because this method of application is protected)
518 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
521 myWorkshop->displayer()->updateViewer();
522 myWorkshop->updateCommandStatus();
525 //******************************************************
526 void SHAPERGUI::onSaveDocByShaper()
528 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
531 getApp()->onSaveDoc();
534 //******************************************************
535 void SHAPERGUI::onSaveAsDocByShaper()
537 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
540 getApp()->onSaveAsDoc();
543 //******************************************************
544 void SHAPERGUI::onUpdateCommandStatus()
546 getApp()->updateActions();
549 //******************************************************
550 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
552 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
553 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
555 //if (myHighlightPointAspect.IsNull()) {
556 // Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
557 // myHighlightPointAspect =
558 // new Graphic3d_AspectMarker3d(aTrihedron->getHighlightPointAspect()->Aspect().operator*());
560 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
561 getApp()->selectionMgr());
562 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
563 aViewer->setUseLocalSelection(true);
565 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
566 QList<SUIT_Selector*> aList;
567 aMgr->selectors(aList);
568 foreach(SUIT_Selector* aSel, aList)
570 aSel->setEnabled(aSel == aSelector);
572 myProxyViewer->setSelector(aSelector);
574 if (myOldSelectionColor.size() == 0)
575 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
577 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
578 myWorkshop->displayer()->setSelectionColor(aColor);
584 //******************************************************
585 CAM_DataModel* SHAPERGUI::createDataModel()
587 return new SHAPERGUI_DataModel(this);
590 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
591 const bool isAddSeparator)
593 return addFeature(theWBName,
597 //Issue #650: in the SALOME mode the tooltip should be same as text
606 //******************************************************
607 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
608 const QString& theId, const QString& theTitle, const QString& theTip,
609 const QIcon& theIcon, const QKeySequence& theKeys,
610 bool isCheckable, const bool isAddSeparator,
611 const QString& theStatusTip)
613 static QString aLastTool = "";
615 if (aLastTool.isEmpty())
616 aLastTool = theWBName;
617 else if (theWBName != aLastTool) {
618 aLastTool = theWBName;
620 desktop()->addToolBarBreak();
626 int aId = getNextCommandId();
627 myActionsList.append(aId);
628 SUIT_Desktop* aDesk = application()->desktop();
630 for (int i = 0; i < theKeys.count(); i++)
632 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
634 aAction->setStatusTip(theStatusTip);
636 aAction->setData(theId);
638 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
639 int aItemId = createMenu(aId, aWBMenu);
641 createMenu(separator(), aWBMenu);
643 int aWBTool = createTool(theTBName, theTBName);
644 int aToolId = createTool(aId, aWBTool);
645 registerCommandToolbar(theTBName, aId);
646 if (isAddSeparator) {
647 createTool(separator(), aWBTool);
648 registerCommandToolbar(theTBName, -1);
653 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
655 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
658 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
659 const ActionInfo& theInfo,
660 const QList<QAction*>& theNestedActions)
662 SUIT_Desktop* aDesk = application()->desktop();
663 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
664 anAction->setData(theInfo.id);
665 anAction->setCheckable(theInfo.checkable);
666 anAction->setChecked(theInfo.checked);
667 anAction->setEnabled(theInfo.enabled);
668 anAction->setVisible(theInfo.visible);
669 anAction->setIcon(theInfo.icon);
670 anAction->setText(theInfo.text);
671 anAction->setToolTip(theInfo.toolTip);
672 anAction->setShortcut(theInfo.shortcut);
673 anAction->setFont(theInfo.font);
675 int aWBMenu = createMenu(theWBName, -1, -1, 30);
676 int aItemId = createMenu(anAction, aWBMenu);
677 myActionsList.append(aItemId);
678 createMenu(separator(), aWBMenu); /// nested action is always separated of others
680 int aWBTool = createTool(theWBName, theWBName);
681 int aToolId = createTool(anAction, aWBTool);
682 registerCommandToolbar(theWBName, aItemId);
683 createTool(separator(), aWBTool); /// nested action is always separated of others
684 registerCommandToolbar(theWBName, -1);
690 //******************************************************
691 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
692 const QString& theTip, const QIcon& theIcon,
693 const QKeySequence& theKeys, bool isCheckable,
694 const char* theMenuSourceText, const int theMenuPosition)
696 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
698 int aId = getNextCommandId();
699 myActionsList.append(aId);
700 SUIT_Desktop* aDesk = application()->desktop();
702 for (int i = 0; i < theKeys.count(); i++)
704 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
706 aAction->setStatusTip(theTip);
707 aAction->setData(theId);
708 createMenu(aId, aMenu, theMenuPosition);
712 //******************************************************
713 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
715 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
716 createMenu(separator(), aMenu, -1, theMenuPosition);
719 //******************************************************
720 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
725 SUIT_Desktop* aDesktop = application()->desktop();
729 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
733 aToolMgr->append( theAction, theToolBarTitle );
737 //******************************************************
738 QList<QAction*> SHAPERGUI::commandList() const
740 QList<QAction*> aActions;
741 foreach (int aId, myActionsList) {
742 QAction* aCmd = action(aId);
744 aActions.append(aCmd);
750 //******************************************************
751 QMainWindow* SHAPERGUI::desktop() const
753 return application()->desktop();
756 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
757 const std::shared_ptr<Config_FeatureMessage>& theMessage)
759 myFeaturesInfo.insert(theFeatureId, theMessage);
762 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
764 std::shared_ptr<Config_FeatureMessage> aMessage;
765 if (myFeaturesInfo.contains(theFeatureId))
766 aMessage = myFeaturesInfo[theFeatureId];
770 //******************************************************
771 void SHAPERGUI::selectionChanged()
773 LightApp_Module::selectionChanged();
774 myWorkshop->salomeViewerSelectionChanged();
777 //******************************************************
778 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
780 myWorkshop->contextMenuMgr()->updateViewerMenu();
781 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
782 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
786 //******************************************************
787 void SHAPERGUI::createPreferences()
789 LightApp_Preferences* pref = preferences();
792 ModuleBase_Preferences::updateConfigByResources();
793 QString aModName = moduleName();
795 QtxPreferenceItem* item = pref->findItem(aModName, true );
796 if ( item && (!item->isEmpty() )) {
797 item->parentItem()->removeItem(item);
801 int catId = pref->addPreference(aModName, -1 );
804 SHAPERGUI_PrefMgr aMgr(pref, aModName);
805 ModuleBase_Preferences::createEditContent(&aMgr, catId);
807 int viewTab = pref->addItem(tr("Viewer"), catId);
808 // Create other parameters group in viewer tab
809 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
810 pref->setItemProperty("columns", 3, otherGroup);
811 pref->addItem(tr("Faces"), otherGroup,
812 SUIT_PreferenceMgr::Bool,
813 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
814 pref->addItem(tr("Edges"), otherGroup,
815 SUIT_PreferenceMgr::Bool,
816 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
817 pref->addItem(tr("Vertices"), otherGroup,
818 SUIT_PreferenceMgr::Bool,
819 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
821 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
822 pref->setItemProperty("columns", 2, sensitivityGroup);
823 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
824 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
825 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
826 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
828 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
829 pref->setItemProperty("columns", 2, highlightGroup);
830 pref->addItem(tr("In 3d mode"), highlightGroup,
831 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
832 pref->addItem(tr("In 2d mode"), highlightGroup,
833 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
835 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
836 pref->setItemProperty("columns", 4, colorScaleGroup);
837 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
838 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
839 pref->setItemProperty("min", 0, aItem);
840 pref->setItemProperty("max", 1, aItem);
842 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
843 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
844 pref->setItemProperty("min", 0, aItem);
845 pref->setItemProperty("max", 1, aItem);
847 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
848 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
849 pref->setItemProperty("min", 0, aItem);
850 pref->setItemProperty("max", 1, aItem);
852 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
853 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
854 pref->setItemProperty("min", 0, aItem);
855 pref->setItemProperty("max", 1, aItem);
857 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
858 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
859 pref->setItemProperty("min", 0, aItem);
860 pref->setItemProperty("max", 100, aItem);
862 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
863 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
864 pref->setItemProperty("min", 0, aItem);
865 pref->setItemProperty("max", 100, aItem);
867 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
868 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
873 //******************************************************
874 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
876 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
877 QString aVal = aResMgr->stringValue(theSection, theParam);
878 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
879 theParam.toStdString());
880 std::string aValue = aVal.toStdString();
881 if (aValue.empty()) {
882 aValue = aProp->defaultValue();
883 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
885 LightApp_Preferences* pref = preferences();
889 aProp->setValue(aValue);
891 if ((theSection == "Visualization") && (theParam == "selection_color")) {
892 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
893 myWorkshop->displayer()->setSelectionColor(aColor);
896 myWorkshop->displayer()->redisplayObjects();
899 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
901 application()->putInfo(theInfo, theMSecs);
904 bool SHAPERGUI::abortAllOperations()
906 return workshop()->operationMgr()->abortAllOperations();
909 void SHAPERGUI::createFeatureActions()
911 myWorkshop->menuMgr()->createFeatureActions();
914 void SHAPERGUI::onWhatIs(bool isToggled)
916 if (sender() == myWhatIsAction) {
917 QAction* aViewAct = myInspectionPanel->toggleViewAction();
918 aViewAct->blockSignals(true);
919 aViewAct->setChecked(isToggled);
920 aViewAct->blockSignals(false);
921 myInspectionPanel->setVisible(isToggled);
924 myWhatIsAction->blockSignals(true);
925 myWhatIsAction->setChecked(isToggled);
926 myWhatIsAction->blockSignals(false);
927 myInspectionPanel->setVisible(isToggled);
931 void SHAPERGUI::updateModuleVisibilityState()
933 LightApp_Module::updateModuleVisibilityState();
934 onWhatIs(myIsInspectionVisible);
937 void SHAPERGUI::onEditToolbars()
939 SHAPERGUI_ToolbarsDlg aDlg(this);
940 if (aDlg.exec() == QDialog::Accepted) {
944 updateToolbars(aDlg.result());
948 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
950 if (!myToolbars.contains(theToolName))
951 myToolbars[theToolName] = QList<int>();
952 myToolbars[theToolName].append(theCommandId);
955 int SHAPERGUI::getNextCommandId() const
957 QtxActionMenuMgr* aMenuMgr = menuMgr();
958 QIntList aIds = aMenuMgr->idList();
959 int aId = aIds.count();
960 while (action(aId) || myActionsList.contains(aId))
965 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
967 // Store default toolbars
968 if (myDefaultToolbars.size() == 0)
969 myDefaultToolbars = myToolbars;
971 QtxActionToolMgr* aMgr = toolMgr();
972 QStringList aToolbars = theNewToolbars.keys();
973 QIntList aCommands, aOldCmd;
977 foreach(QString aName, aToolbars) {
978 aCommands = theNewToolbars[aName];
979 // Find or create toolbar
980 if (aMgr->hasToolBar(aName)) {
981 aToolbarId = aMgr->find(aMgr->toolBar(aName));
982 aOldCmd = myToolbars[aName];
985 aToolbarId = aMgr->createToolBar(aName);
988 foreach(int aCmd, aCommands) {
991 aAction = separator();
993 aAction = action(aCmd);
994 aActionId = aMgr->actionId(aAction);
995 if (aActionId == -1) {
997 aMgr->insert(aAction, aToolbarId, aPos);
1000 // Change position of action
1001 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1002 if (aMgr->containsAction(aActionId, aToolbarId))
1003 aMgr->remove(aActionId, aToolbarId);
1004 aMgr->insert(aActionId, aToolbarId, aPos);
1007 aOldCmd.removeAll(aCmd);
1010 // remove extra actions
1011 foreach(int aCmd, aOldCmd) {
1012 aAction = action(aCmd);
1013 aActionId = aMgr->actionId(aAction);
1014 aMgr->remove(aActionId, aToolbarId);
1016 myToolbars.remove(aName);
1018 // Remove extra toolbars
1019 aToolbars = myToolbars.keys();
1020 foreach(QString aName, aToolbars) {
1021 aMgr->removeToolBar(aName);
1023 // Set new toolbars structure
1024 myToolbars = theNewToolbars;
1025 myIsToolbarsModified = true;
1028 void SHAPERGUI::saveToolbarsConfig()
1030 if (!myIsToolbarsModified)
1032 // Save toolbars configuration into map
1033 QMap<QString, QStringList> aToolbarsConfig;
1034 QtxActionToolMgr* aMgr = toolMgr();
1035 QStringList aToolbars = myToolbars.keys();
1036 QIntList aActionsIds;
1037 foreach(QString aName, aToolbars) {
1038 aActionsIds = myToolbars[aName];
1039 QStringList aContent;
1040 foreach(int aId, aActionsIds) {
1042 aContent.append("");
1044 aContent.append(action(aId)->data().toString());
1046 aToolbarsConfig[aName] = aContent;
1048 // Store the configuration into resources
1049 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1050 QStringList aNames = aToolbarsConfig.keys();
1051 QStringList aValues;
1052 foreach(QString aToolbar, aNames) {
1053 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1055 // Remove obsolete parameters from resources
1056 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1057 foreach(QString aName, aOldParams) {
1058 if (!aToolbars.contains(aName))
1059 aResMgr->remove(ToolbarsSection, aName);
1061 // Store current list of free commands
1062 QIntList aFreeCommands = getFreeCommands();
1063 QStringList aFreeList;
1064 foreach(int aId, aFreeCommands) {
1065 aFreeList.append(action(aId)->data().toString());
1067 if (aFreeList.size() > 0)
1068 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1070 myIsToolbarsModified = false;
1073 void SHAPERGUI::loadToolbarsConfig()
1075 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1076 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1077 if (aToolbarNames.size() == 0)
1080 // Create commands map
1081 QMap<QString, int> aCommandsMap;
1083 foreach(int aId, myActionsList) {
1084 aCmdIdStr = action(aId)->data().toString();
1085 aCommandsMap[aCmdIdStr] = aId;
1088 // Create new toolbars structure
1089 QMap<QString, QIntList> aToolbars;
1090 QStringList aCommands;
1091 QIntList aKnownCommands;
1092 QList<QAction*> aActions;
1093 foreach(QString aName, aToolbarNames) {
1094 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1095 if (aName == FreeCommandsParam) {
1096 // The value is a list of free commands
1097 foreach(QString aCommand, aCommands) {
1098 aKnownCommands.append(aCommandsMap[aCommand]);
1102 aToolbars[aName] = QIntList();
1103 if (aCommands.size() > 0) {
1104 foreach(QString aCommand, aCommands) {
1105 if (aCommand.isEmpty())
1106 aToolbars[aName].append(-1);
1107 else if (aCommandsMap.contains(aCommand)) {
1108 int aId = aCommandsMap[aCommand];
1109 aToolbars[aName].append(aId);
1110 aKnownCommands.append(aId);
1116 // Find new and obsolete commands
1117 QIntList aNewCommands = myActionsList;
1118 foreach(int aId, myActionsList) {
1119 if (aKnownCommands.contains(aId)) {
1120 aKnownCommands.removeAll(aId);
1121 aNewCommands.removeAll(aId);
1124 if (aNewCommands.size() > 0) {
1125 // Add new commands to toolbars structure
1126 QStringList aKeys = myToolbars.keys();
1127 foreach(int aNewId, aNewCommands) {
1128 foreach(QString aName, aKeys) {
1129 if (myToolbars[aName].contains(aNewId)) {
1130 if (!aToolbars.contains(aName)) {
1131 aToolbars[aName] = QIntList();
1133 aToolbars[aName].append(aNewId);
1138 if (aKnownCommands.size() > 0) {
1139 // Remove obsolete commands from the toolbars structure
1140 QStringList aKeys = aToolbars.keys();
1141 foreach(int aOldId, aKnownCommands) {
1142 foreach(QString aName, aKeys) {
1143 if (aToolbars[aName].contains(aOldId)) {
1144 aToolbars[aName].removeAll(aOldId);
1145 if (aToolbars[aName].size() == 0)
1146 aToolbars.remove(aName);
1151 updateToolbars(aToolbars);
1152 myIsToolbarsModified = false;
1156 QIntList SHAPERGUI::getFreeCommands() const
1158 QIntList aFreeCommands;
1159 QtxActionToolMgr* aMgr = toolMgr();
1162 QMap<QString, QIntList>::const_iterator aIt;
1163 QIntList aShaperActions = shaperActions();
1164 foreach(int aCmd, aShaperActions) {
1165 anAction = action(aCmd);
1166 aId = aMgr->actionId(anAction);
1167 if (!aMgr->containsAction(aId))
1168 aFreeCommands.append(aCmd);
1170 return aFreeCommands;
1173 void SHAPERGUI::resetToolbars()
1175 if (!myDefaultToolbars.isEmpty())
1176 updateToolbars(myDefaultToolbars);
1177 myIsToolbarsModified = false;
1178 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1179 aResMgr->remove(ToolbarsSection);
1182 void SHAPERGUI::publishToStudy()
1184 if (isActiveModule())
1185 myWorkshop->module()->launchOperation("PublishToStudy", false);