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),
142 myWorkshop = new XGUI_Workshop(this);
143 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
144 this, SLOT(onUpdateCommandStatus()));
146 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
148 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
150 // It will be called in XGUI_Workshop::startApplication
151 // ModuleBase_Preferences::loadCustomProps();
154 //******************************************************
155 SHAPERGUI::~SHAPERGUI()
158 delete myProxyViewer;
161 //******************************************************
162 void SHAPERGUI::initialize(CAM_Application* theApp)
164 LightApp_Module::initialize(theApp);
166 myWorkshop->startApplication();
167 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
170 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
173 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
174 int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
176 int aId = getNextCommandId();
177 myActionsList.append(aId);
178 SUIT_Desktop* aDesk = application()->desktop();
179 QString aTip = tr("Show inspection window");
180 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
181 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
182 myWhatIsAction->setStatusTip(aTip);
183 myWhatIsAction->setData("INSPECTION_CMD");
184 createMenu(aId, aSubMenu, 0);
186 QString aToolName = tr("Inspection");
187 int aTool = createTool(aToolName);
188 int aToolId = createTool(myWhatIsAction, aTool);
189 registerCommandToolbar(aToolName, aId);
191 // Define Edit toolbars command
192 aId = getNextCommandId();
193 //myActionsList.append(aId); Do not use it for editing of toolbars
194 aTip = tr("Edit toolbars of the module");
195 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
196 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
197 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
198 int aEditItem = createMenu(aId, aEditMenu);
200 // Initialize viewer proxy if OCC viewer is already exist
201 ViewManagerList aOCCViewManagers;
202 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
203 if (aOCCViewManagers.size() > 0) {
204 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
205 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
207 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
208 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
210 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
211 aViewPort->installEventFilter(aViewer);
212 Handle(V3d_View) aView = aViewPort->getView();
213 aViewer->SetScale(aView, aView->Camera()->Scale());
214 // We can not create selector here because other modules will be deactivated later
215 //onViewManagerAdded(aMgr);
221 //******************************************************
222 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
224 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
227 //******************************************************
228 void SHAPERGUI::viewManagers(QStringList& theList) const
230 theList.append(OCCViewer_Viewer::Type());
233 //******************************************************
234 // We can not create selector in this method because it can be called when
235 // SHAPER module is not active. Take into account that creation of our selector
236 // leads to switching OFF all other selectors
237 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
239 // // if there are created viewer managers, we should try to create viewer
240 // // selector and initialize viewer with it. It sets interactive context to the
241 // // proxy viewer. If study is opened, CAM application calls this method before the open()
243 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
244 // // we need to connect to the viewer before it. Here,
245 // // it seems the most appropriate place for this
246 // // according to SALOME architecture.
247 // if (!mySelector) {
248 // ViewManagerList OCCViewManagers;
249 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
250 // if (OCCViewManagers.size() > 0) {
251 // mySelector = createSelector(OCCViewManagers.first());
254 // LightApp_Module::connectToStudy(theStudy);
257 //******************************************************
258 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
260 bool isDone = LightApp_Module::activateModule(theStudy);
261 loadToolbarsConfig();
263 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
264 aDataModel->initRootObject();
270 QObject* aObj = myWorkshop->objectBrowser()->parent();
271 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
273 myWorkshop->objectBrowser()->setVisible(true);
274 aObjDoc->setVisible(true);
275 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
276 aObjDoc->toggleViewAction()->setVisible(true);
279 if (!myInspectionPanel) {
280 myInspectionPanel = myWorkshop->inspectionPanel();
281 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
282 this, SLOT(onWhatIs(bool)));
284 myInspectionPanel->toggleViewAction()->setVisible(true);
286 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
287 if (myIsFacesPanelVisible)
288 myWorkshop->facesPanel()->show();
289 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
292 ViewManagerList OCCViewManagers;
293 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
294 if (OCCViewManagers.size() > 0) {
295 onViewManagerAdded(OCCViewManagers.first());
298 // it should be performed after the selector creation in order to have AISContext
299 myWorkshop->activateModule();
300 //action(myEraseAll)->setEnabled(false);
303 myWorkshop->objectBrowser()->rebuildDataTree();
304 myWorkshop->updateCommandStatus();
308 myWorkshop->updateCommandStatus();
310 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
311 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
312 myIsEditEnabled = getApp()->isEditEnabled();
313 getApp()->setEditEnabled(false);
315 // this following row is caused by #187 bug.
316 // SALOME saves the dock widget positions before deactivateModule() and
317 // load it after the module activation. So, if the panel is visible before
318 // deactivate, it becomes visible after activate.
319 // In order to avoid the visible property panel, the widget position save is
320 // switch off in this module
321 aResMgr->setValue("Study", "store_positions", false);
323 // Synchronize displayed objects
324 Handle(AIS_InteractiveContext) aContext;
325 if (mySelector && mySelector->viewer())
326 aContext = mySelector->viewer()->getAISContext();
328 if (!aContext.IsNull()) {
329 XGUI_Displayer* aDisp = myWorkshop->displayer();
330 QObjectPtrList aObjList = aDisp->displayedObjects();
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 aObjDoc->toggleViewAction()->setVisible(false);
395 myIsInspectionVisible = myInspectionPanel->isVisible();
396 myInspectionPanel->hide();
397 myInspectionPanel->toggleViewAction()->setVisible(false);
399 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
400 myWorkshop->facesPanel()->hide();
401 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
403 myWorkshop->propertyPanel()->hide();
404 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
406 // the active operation should be stopped for the next activation.
407 // There should not be active operation and visualized preview.
408 // Abort operation should be performed before the selection's remove
409 // because the displayed objects should be removed from the viewer, but
410 // the AIS context is obtained from the selector.
411 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
412 while (anOperation) {
413 anOperation->abort();
414 anOperation = myWorkshop->operationMgr()->currentOperation();
416 // Delete selector because it has to be redefined on next activation
418 // Restore size of arrows of trihedron
419 if (myAxisArrowRate > 0) {
420 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
421 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
422 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
423 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
424 aContext->Redisplay(aTrihedron, false);
426 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
427 myProxyViewer->setSelector(0);
429 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
430 QList<SUIT_Selector*> aList;
431 aMgr->selectors(aList);
432 foreach(SUIT_Selector* aSel, aList) {
433 aSel->setEnabled(aSel != mySelector);
440 myWorkshop->hidePanel(myWorkshop->facesPanel());
441 //myWorkshop->contextMenuMgr()->disconnectViewer();
443 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
444 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
445 getApp()->setEditEnabled(myIsEditEnabled);
447 myOldSelectionColor.clear();
449 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
450 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
451 this, SLOT(onScriptLoaded()));
453 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
454 this, SLOT(onSaveDocByShaper()));
455 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
456 this, SLOT(onSaveAsDocByShaper()));
458 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
459 getApp(), SLOT(onSaveDoc()));
460 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
461 getApp(), SLOT(onSaveAsDoc()));
465 return LightApp_Module::deactivateModule(theStudy);
468 //******************************************************
469 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
472 mySelector = createSelector(theMgr);
473 myWorkshop->selectionActivate()->updateSelectionFilters();
474 myWorkshop->selectionActivate()->updateSelectionModes();
475 myWorkshop->synchronizeViewer();
479 //******************************************************
480 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
483 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
484 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
485 if (mySelector->viewer() == aViewer) {
486 XGUI_Displayer* aDisp = myWorkshop->displayer();
487 QObjectPtrList aObjects = aDisp->displayedObjects();
489 foreach(ObjectPtr aObj, aObjects) {
490 aObj->setDisplayed(false);
491 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
493 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
494 aRes->setDisplayed(false);
498 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
499 myProxyViewer->setSelector(0);
503 myWorkshop->module()->clearViewer();
509 //******************************************************
510 QtxPopupMgr* SHAPERGUI::popupMgr()
513 myPopupMgr = new QtxPopupMgr( 0, this );
517 //******************************************************
518 void SHAPERGUI::onDefaultPreferences()
520 // reset main resources
521 ModuleBase_Preferences::resetResourcePreferences(preferences());
522 // reset plugin's resources
523 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
525 myWorkshop->displayer()->redisplayObjects();
528 //******************************************************
529 void SHAPERGUI::onScriptLoaded()
531 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
532 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
533 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
534 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
535 // it manually (because this method of application is protected)
536 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
539 myWorkshop->displayer()->updateViewer();
540 myWorkshop->updateCommandStatus();
543 //******************************************************
544 void SHAPERGUI::onSaveDocByShaper()
546 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
549 getApp()->onSaveDoc();
552 //******************************************************
553 void SHAPERGUI::onSaveAsDocByShaper()
555 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
558 getApp()->onSaveAsDoc();
561 //******************************************************
562 void SHAPERGUI::onUpdateCommandStatus()
564 getApp()->updateActions();
567 //******************************************************
568 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
570 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
571 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
573 // Remember current length of arrow of axis
574 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
575 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
576 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
578 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
579 getApp()->selectionMgr());
580 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
581 aViewer->setUseLocalSelection(true);
583 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
584 QList<SUIT_Selector*> aList;
585 aMgr->selectors(aList);
586 foreach(SUIT_Selector* aSel, aList)
588 aSel->setEnabled(aSel == aSelector);
590 myProxyViewer->setSelector(aSelector);
592 if (myOldSelectionColor.size() == 0)
593 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
595 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
596 myWorkshop->displayer()->setSelectionColor(aColor);
598 // Cause scaling of arrows of axis and dimensions
599 myWorkshop->module()->onViewTransformed();
606 //******************************************************
607 CAM_DataModel* SHAPERGUI::createDataModel()
609 return new SHAPERGUI_DataModel(this);
612 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
613 const bool isAddSeparator)
615 return addFeature(theWBName,
619 //Issue #650: in the SALOME mode the tooltip should be same as text
628 //******************************************************
629 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
630 const QString& theId, const QString& theTitle, const QString& theTip,
631 const QIcon& theIcon, const QKeySequence& theKeys,
632 bool isCheckable, const bool isAddSeparator,
633 const QString& theStatusTip)
635 static QString aLastTool = "";
637 if (aLastTool.isEmpty())
638 aLastTool = theWBName;
639 else if (theWBName != aLastTool) {
640 aLastTool = theWBName;
642 desktop()->addToolBarBreak();
648 int aId = getNextCommandId();
649 myActionsList.append(aId);
650 SUIT_Desktop* aDesk = application()->desktop();
652 for (int i = 0; i < theKeys.count(); i++)
654 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
656 aAction->setStatusTip(theStatusTip);
658 aAction->setData(theId);
660 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
661 int aItemId = createMenu(aId, aWBMenu);
663 createMenu(separator(), aWBMenu);
665 int aWBTool = createTool(theTBName, theTBName);
666 int aToolId = createTool(aId, aWBTool);
667 registerCommandToolbar(theTBName, aId);
668 if (isAddSeparator) {
669 createTool(separator(), aWBTool);
670 registerCommandToolbar(theTBName, -1);
675 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
677 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
680 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
681 const ActionInfo& theInfo,
682 const QList<QAction*>& theNestedActions)
684 SUIT_Desktop* aDesk = application()->desktop();
685 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
686 anAction->setData(theInfo.id);
687 anAction->setCheckable(theInfo.checkable);
688 anAction->setChecked(theInfo.checked);
689 anAction->setEnabled(theInfo.enabled);
690 anAction->setVisible(theInfo.visible);
691 anAction->setIcon(theInfo.icon);
692 anAction->setText(theInfo.text);
693 anAction->setToolTip(theInfo.toolTip);
694 anAction->setShortcut(theInfo.shortcut);
695 anAction->setFont(theInfo.font);
697 int aWBMenu = createMenu(theWBName, -1, -1, 30);
698 int aItemId = createMenu(anAction, aWBMenu);
699 myActionsList.append(aItemId);
700 createMenu(separator(), aWBMenu); /// nested action is always separated of others
702 int aWBTool = createTool(theWBName, theWBName);
703 int aToolId = createTool(anAction, aWBTool);
704 registerCommandToolbar(theWBName, aItemId);
705 createTool(separator(), aWBTool); /// nested action is always separated of others
706 registerCommandToolbar(theWBName, -1);
712 //******************************************************
713 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
714 const QString& theTip, const QIcon& theIcon,
715 const QKeySequence& theKeys, bool isCheckable,
716 const char* theMenuSourceText,
717 const QString& theSubMenu,
718 const int theMenuPosition,
719 const int theSuibMenuPosition)
721 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
722 if (!theSubMenu.isNull())
723 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
725 int aId = getNextCommandId();
726 myActionsList.append(aId);
727 SUIT_Desktop* aDesk = application()->desktop();
729 for (int i = 0; i < theKeys.count(); i++)
731 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
733 aAction->setStatusTip(theTip);
734 aAction->setData(theId);
735 createMenu(aId, aMenu, theMenuPosition);
739 //******************************************************
740 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
742 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
743 createMenu(separator(), aMenu, -1, theMenuPosition);
746 //******************************************************
747 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
752 SUIT_Desktop* aDesktop = application()->desktop();
756 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
760 aToolMgr->append( theAction, theToolBarTitle );
764 //******************************************************
765 QList<QAction*> SHAPERGUI::commandList() const
767 QList<QAction*> aActions;
768 foreach (int aId, myActionsList) {
769 QAction* aCmd = action(aId);
771 aActions.append(aCmd);
777 //******************************************************
778 QMainWindow* SHAPERGUI::desktop() const
780 return application()->desktop();
783 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
784 const std::shared_ptr<Config_FeatureMessage>& theMessage)
786 myFeaturesInfo.insert(theFeatureId, theMessage);
789 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
791 std::shared_ptr<Config_FeatureMessage> aMessage;
792 if (myFeaturesInfo.contains(theFeatureId))
793 aMessage = myFeaturesInfo[theFeatureId];
797 //******************************************************
798 void SHAPERGUI::selectionChanged()
800 LightApp_Module::selectionChanged();
801 myWorkshop->salomeViewerSelectionChanged();
804 //******************************************************
805 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
807 myWorkshop->contextMenuMgr()->updateViewerMenu();
808 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
809 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
813 //******************************************************
814 void SHAPERGUI::createPreferences()
816 LightApp_Preferences* pref = preferences();
819 ModuleBase_Preferences::updateConfigByResources();
820 QString aModName = moduleName();
822 QtxPreferenceItem* item = pref->findItem(aModName, true );
823 if ( item && (!item->isEmpty() )) {
824 item->parentItem()->removeItem(item);
828 int catId = pref->addPreference(aModName, -1 );
831 SHAPERGUI_PrefMgr aMgr(pref, aModName);
832 ModuleBase_Preferences::createEditContent(&aMgr, catId);
834 int viewTab = pref->addItem(tr("Viewer"), catId);
835 // Create other parameters group in viewer tab
836 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
837 pref->setItemProperty("columns", 3, otherGroup);
838 pref->addItem(tr("Faces"), otherGroup,
839 SUIT_PreferenceMgr::Bool,
840 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
841 pref->addItem(tr("Edges"), otherGroup,
842 SUIT_PreferenceMgr::Bool,
843 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
844 pref->addItem(tr("Vertices"), otherGroup,
845 SUIT_PreferenceMgr::Bool,
846 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
848 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
849 pref->setItemProperty("columns", 2, sensitivityGroup);
850 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
851 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
852 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
853 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
855 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
856 pref->setItemProperty("columns", 2, highlightGroup);
857 pref->addItem(tr("In 3d mode"), highlightGroup,
858 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
859 pref->addItem(tr("In 2d mode"), highlightGroup,
860 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
862 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
863 pref->setItemProperty("columns", 4, colorScaleGroup);
864 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
865 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
866 pref->setItemProperty("min", 0, aItem);
867 pref->setItemProperty("max", 1, aItem);
869 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
870 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
871 pref->setItemProperty("min", 0, aItem);
872 pref->setItemProperty("max", 1, aItem);
874 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
875 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
876 pref->setItemProperty("min", 0, aItem);
877 pref->setItemProperty("max", 1, aItem);
879 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
880 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
881 pref->setItemProperty("min", 0, aItem);
882 pref->setItemProperty("max", 1, aItem);
884 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
885 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
886 pref->setItemProperty("min", 0, aItem);
887 pref->setItemProperty("max", 100, aItem);
889 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
890 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
891 pref->setItemProperty("min", 0, aItem);
892 pref->setItemProperty("max", 100, aItem);
894 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
895 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
900 //******************************************************
901 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
903 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
904 QString aVal = aResMgr->stringValue(theSection, theParam);
905 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
906 theParam.toStdString());
907 std::string aValue = aVal.toStdString();
908 if (aValue.empty()) {
909 aValue = aProp->defaultValue();
910 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
912 LightApp_Preferences* pref = preferences();
916 aProp->setValue(aValue);
918 if ((theSection == "Visualization") && (theParam == "selection_color")) {
919 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
920 myWorkshop->displayer()->setSelectionColor(aColor);
923 myWorkshop->displayer()->redisplayObjects();
926 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
928 application()->putInfo(theInfo, theMSecs);
931 bool SHAPERGUI::abortAllOperations()
933 return workshop()->operationMgr()->abortAllOperations();
936 void SHAPERGUI::createFeatureActions()
938 myWorkshop->menuMgr()->createFeatureActions();
941 void SHAPERGUI::onWhatIs(bool isToggled)
943 if (sender() == myWhatIsAction) {
944 QAction* aViewAct = myInspectionPanel->toggleViewAction();
945 aViewAct->blockSignals(true);
946 aViewAct->setChecked(isToggled);
947 aViewAct->blockSignals(false);
948 myInspectionPanel->setVisible(isToggled);
951 myWhatIsAction->blockSignals(true);
952 myWhatIsAction->setChecked(isToggled);
953 myWhatIsAction->blockSignals(false);
954 myInspectionPanel->setVisible(isToggled);
958 void SHAPERGUI::updateModuleVisibilityState()
960 LightApp_Module::updateModuleVisibilityState();
961 onWhatIs(myIsInspectionVisible);
964 void SHAPERGUI::onEditToolbars()
966 SHAPERGUI_ToolbarsDlg aDlg(this);
967 if (aDlg.exec() == QDialog::Accepted) {
971 updateToolbars(aDlg.result());
975 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
977 if (!myToolbars.contains(theToolName))
978 myToolbars[theToolName] = QList<int>();
979 myToolbars[theToolName].append(theCommandId);
982 int SHAPERGUI::getNextCommandId() const
984 QtxActionMenuMgr* aMenuMgr = menuMgr();
985 QIntList aIds = aMenuMgr->idList();
986 int aId = aIds.count();
987 while (action(aId) || myActionsList.contains(aId))
992 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
994 // Store default toolbars
995 if (myDefaultToolbars.size() == 0)
996 myDefaultToolbars = myToolbars;
998 QtxActionToolMgr* aMgr = toolMgr();
999 QStringList aToolbars = theNewToolbars.keys();
1000 QIntList aCommands, aOldCmd;
1004 foreach(QString aName, aToolbars) {
1005 aCommands = theNewToolbars[aName];
1006 // Find or create toolbar
1007 if (aMgr->hasToolBar(aName)) {
1008 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1009 aOldCmd = myToolbars[aName];
1012 aToolbarId = aMgr->createToolBar(aName);
1015 foreach(int aCmd, aCommands) {
1018 aAction = separator();
1020 aAction = action(aCmd);
1021 aActionId = aMgr->actionId(aAction);
1022 if (aActionId == -1) {
1024 aMgr->insert(aAction, aToolbarId, aPos);
1027 // Change position of action
1028 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1029 if (aMgr->containsAction(aActionId, aToolbarId))
1030 aMgr->remove(aActionId, aToolbarId);
1031 aMgr->insert(aActionId, aToolbarId, aPos);
1034 aOldCmd.removeAll(aCmd);
1037 // remove extra actions
1038 foreach(int aCmd, aOldCmd) {
1039 aAction = action(aCmd);
1040 aActionId = aMgr->actionId(aAction);
1041 aMgr->remove(aActionId, aToolbarId);
1043 myToolbars.remove(aName);
1045 // Remove extra toolbars
1046 aToolbars = myToolbars.keys();
1047 foreach(QString aName, aToolbars) {
1048 aMgr->removeToolBar(aName);
1050 // Set new toolbars structure
1051 myToolbars = theNewToolbars;
1052 myIsToolbarsModified = true;
1055 void SHAPERGUI::saveToolbarsConfig()
1057 if (!myIsToolbarsModified)
1059 // Save toolbars configuration into map
1060 QMap<QString, QStringList> aToolbarsConfig;
1061 QtxActionToolMgr* aMgr = toolMgr();
1062 QStringList aToolbars = myToolbars.keys();
1063 QIntList aActionsIds;
1064 foreach(QString aName, aToolbars) {
1065 aActionsIds = myToolbars[aName];
1066 QStringList aContent;
1067 foreach(int aId, aActionsIds) {
1069 aContent.append("");
1071 aContent.append(action(aId)->data().toString());
1073 aToolbarsConfig[aName] = aContent;
1075 // Store the configuration into resources
1076 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1077 QStringList aNames = aToolbarsConfig.keys();
1078 QStringList aValues;
1079 foreach(QString aToolbar, aNames) {
1080 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1082 // Remove obsolete parameters from resources
1083 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1084 foreach(QString aName, aOldParams) {
1085 if (!aToolbars.contains(aName))
1086 aResMgr->remove(ToolbarsSection, aName);
1088 // Store current list of free commands
1089 QIntList aFreeCommands = getFreeCommands();
1090 QStringList aFreeList;
1091 foreach(int aId, aFreeCommands) {
1092 aFreeList.append(action(aId)->data().toString());
1094 if (aFreeList.size() > 0)
1095 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1097 myIsToolbarsModified = false;
1100 void SHAPERGUI::loadToolbarsConfig()
1102 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1103 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1104 if (aToolbarNames.size() == 0)
1107 // Create commands map
1108 QMap<QString, int> aCommandsMap;
1110 foreach(int aId, myActionsList) {
1111 aCmdIdStr = action(aId)->data().toString();
1112 aCommandsMap[aCmdIdStr] = aId;
1115 // Create new toolbars structure
1116 QMap<QString, QIntList> aToolbars;
1117 QStringList aCommands;
1118 QIntList aKnownCommands;
1119 QList<QAction*> aActions;
1120 foreach(QString aName, aToolbarNames) {
1121 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1122 if (aName == FreeCommandsParam) {
1123 // The value is a list of free commands
1124 foreach(QString aCommand, aCommands) {
1125 aKnownCommands.append(aCommandsMap[aCommand]);
1129 aToolbars[aName] = QIntList();
1130 if (aCommands.size() > 0) {
1131 foreach(QString aCommand, aCommands) {
1132 if (aCommand.isEmpty())
1133 aToolbars[aName].append(-1);
1134 else if (aCommandsMap.contains(aCommand)) {
1135 int aId = aCommandsMap[aCommand];
1136 aToolbars[aName].append(aId);
1137 aKnownCommands.append(aId);
1143 // Find new and obsolete commands
1144 QIntList aNewCommands = myActionsList;
1145 foreach(int aId, myActionsList) {
1146 if (aKnownCommands.contains(aId)) {
1147 aKnownCommands.removeAll(aId);
1148 aNewCommands.removeAll(aId);
1151 if (aNewCommands.size() > 0) {
1152 // Add new commands to toolbars structure
1153 QStringList aKeys = myToolbars.keys();
1154 foreach(int aNewId, aNewCommands) {
1155 foreach(QString aName, aKeys) {
1156 if (myToolbars[aName].contains(aNewId)) {
1157 if (!aToolbars.contains(aName)) {
1158 aToolbars[aName] = QIntList();
1160 aToolbars[aName].append(aNewId);
1165 if (aKnownCommands.size() > 0) {
1166 // Remove obsolete commands from the toolbars structure
1167 QStringList aKeys = aToolbars.keys();
1168 foreach(int aOldId, aKnownCommands) {
1169 foreach(QString aName, aKeys) {
1170 if (aToolbars[aName].contains(aOldId)) {
1171 aToolbars[aName].removeAll(aOldId);
1172 if (aToolbars[aName].size() == 0)
1173 aToolbars.remove(aName);
1178 updateToolbars(aToolbars);
1179 myIsToolbarsModified = false;
1183 QIntList SHAPERGUI::getFreeCommands() const
1185 QIntList aFreeCommands;
1186 QtxActionToolMgr* aMgr = toolMgr();
1189 QMap<QString, QIntList>::const_iterator aIt;
1190 QIntList aShaperActions = shaperActions();
1191 foreach(int aCmd, aShaperActions) {
1192 anAction = action(aCmd);
1193 aId = aMgr->actionId(anAction);
1194 if (!aMgr->containsAction(aId))
1195 aFreeCommands.append(aCmd);
1197 return aFreeCommands;
1200 void SHAPERGUI::resetToolbars()
1202 if (!myDefaultToolbars.isEmpty())
1203 updateToolbars(myDefaultToolbars);
1204 myIsToolbarsModified = false;
1205 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1206 aResMgr->remove(ToolbarsSection);
1209 void SHAPERGUI::publishToStudy()
1211 if (isActiveModule())
1212 myWorkshop->module()->launchOperation("PublishToStudy", false);