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 mySelector = createSelector(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 AIS_ListOfInteractive aList;
326 aContext->DisplayedObjects(aList);
327 AIS_ListIteratorOfListOfInteractive aLIt;
328 Handle(AIS_InteractiveObject) anAISIO;
329 foreach (ObjectPtr aObj, aObjList) {
330 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
331 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
333 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
334 anAISIO = aLIt.Value();
335 if (anAISIO.get() == aAIS.get()) {
341 aObj->setDisplayed(false);
342 //aDisp->erase(aObj, false);
345 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
347 myProxyViewer->activateViewer(true);
349 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
350 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
351 this, SLOT(onScriptLoaded()));
353 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
354 getApp(), SLOT(onSaveDoc()));
355 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
356 getApp(), SLOT(onSaveAsDoc()));
358 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
359 this, SLOT(onSaveDocByShaper()));
360 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
361 this, SLOT(onSaveAsDocByShaper()));
366 //******************************************************
367 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
369 saveToolbarsConfig();
371 myProxyViewer->activateViewer(false);
375 myWorkshop->deactivateModule();
377 QObject* aObj = myWorkshop->objectBrowser()->parent();
378 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
380 aObjDoc->setVisible(false);
381 myWorkshop->objectBrowser()->setVisible(false);
382 QAction* aViewAct = aObjDoc->toggleViewAction();
383 aViewAct->setEnabled(false);
386 myIsInspectionVisible = myInspectionPanel->isVisible();
387 myInspectionPanel->hide();
388 QAction* aViewAct = myInspectionPanel->toggleViewAction();
389 aViewAct->setEnabled(false);
391 // the active operation should be stopped for the next activation.
392 // There should not be active operation and visualized preview.
393 // Abort operation should be performed before the selection's remove
394 // because the displayed objects should be removed from the viewer, but
395 // the AIS context is obtained from the selector.
396 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
397 while (anOperation) {
398 anOperation->abort();
399 anOperation = myWorkshop->operationMgr()->currentOperation();
401 // Delete selector because it has to be redefined on next activation
403 myProxyViewer->setSelector(0);
408 myWorkshop->hidePanel(myWorkshop->facesPanel());
409 //myWorkshop->contextMenuMgr()->disconnectViewer();
411 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
412 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
413 getApp()->setEditEnabled(myIsEditEnabled);
415 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
416 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
417 this, SLOT(onScriptLoaded()));
419 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
420 this, SLOT(onSaveDocByShaper()));
421 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
422 this, SLOT(onSaveAsDocByShaper()));
424 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
425 getApp(), SLOT(onSaveDoc()));
426 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
427 getApp(), SLOT(onSaveAsDoc()));
429 return LightApp_Module::deactivateModule(theStudy);
432 //******************************************************
433 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
436 mySelector = createSelector(theMgr);
437 myWorkshop->selectionActivate()->updateSelectionFilters();
438 myWorkshop->selectionActivate()->updateSelectionModes();
439 myWorkshop->synchronizeViewer();
443 //******************************************************
444 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
447 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
448 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
449 if (mySelector->viewer() == aViewer) {
450 XGUI_Displayer* aDisp = myWorkshop->displayer();
451 QObjectPtrList aObjects = aDisp->displayedObjects();
453 foreach(ObjectPtr aObj, aObjects) {
454 aObj->setDisplayed(false);
455 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
457 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
458 aRes->setDisplayed(false);
462 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
463 myProxyViewer->setSelector(0);
467 myWorkshop->module()->clearViewer();
473 //******************************************************
474 QtxPopupMgr* SHAPERGUI::popupMgr()
477 myPopupMgr = new QtxPopupMgr( 0, this );
481 //******************************************************
482 void SHAPERGUI::onDefaultPreferences()
484 // reset main resources
485 ModuleBase_Preferences::resetResourcePreferences(preferences());
486 // reset plugin's resources
487 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
489 myWorkshop->displayer()->redisplayObjects();
492 //******************************************************
493 void SHAPERGUI::onScriptLoaded()
495 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
496 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
497 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
498 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
499 // it manually (because this method of application is protected)
500 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
505 //******************************************************
506 void SHAPERGUI::onSaveDocByShaper()
508 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
511 getApp()->onSaveDoc();
514 //******************************************************
515 void SHAPERGUI::onSaveAsDocByShaper()
517 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
520 getApp()->onSaveAsDoc();
523 //******************************************************
524 void SHAPERGUI::onUpdateCommandStatus()
526 getApp()->updateActions();
529 //******************************************************
530 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
532 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
533 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
534 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
535 getApp()->selectionMgr());
536 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
537 aViewer->setUseLocalSelection(true);
539 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
540 QList<SUIT_Selector*> aList;
541 aMgr->selectors(aList);
542 foreach(SUIT_Selector* aSel, aList)
544 aSel->setEnabled(aSel == aSelector);
546 myProxyViewer->setSelector(aSelector);
552 //******************************************************
553 CAM_DataModel* SHAPERGUI::createDataModel()
555 return new SHAPERGUI_DataModel(this);
558 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
559 const bool isAddSeparator)
561 return addFeature(theWBName,
565 //Issue #650: in the SALOME mode the tooltip should be same as text
574 //******************************************************
575 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
576 const QString& theId, const QString& theTitle, const QString& theTip,
577 const QIcon& theIcon, const QKeySequence& theKeys,
578 bool isCheckable, const bool isAddSeparator,
579 const QString& theStatusTip)
581 static QString aLastTool = "";
583 if (aLastTool.isEmpty())
584 aLastTool = theWBName;
585 else if (theWBName != aLastTool) {
586 aLastTool = theWBName;
588 desktop()->addToolBarBreak();
594 int aId = getNextCommandId();
595 myActionsList.append(aId);
596 SUIT_Desktop* aDesk = application()->desktop();
598 for (int i = 0; i < theKeys.count(); i++)
600 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
602 aAction->setStatusTip(theStatusTip);
604 aAction->setData(theId);
606 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
607 int aItemId = createMenu(aId, aWBMenu);
609 createMenu(separator(), aWBMenu);
611 int aWBTool = createTool(theTBName, theTBName);
612 int aToolId = createTool(aId, aWBTool);
613 registerCommandToolbar(theTBName, aId);
614 if (isAddSeparator) {
615 createTool(separator(), aWBTool);
616 registerCommandToolbar(theTBName, -1);
621 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
623 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
626 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
627 const ActionInfo& theInfo,
628 const QList<QAction*>& theNestedActions)
630 SUIT_Desktop* aDesk = application()->desktop();
631 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
632 anAction->setData(theInfo.id);
633 anAction->setCheckable(theInfo.checkable);
634 anAction->setChecked(theInfo.checked);
635 anAction->setEnabled(theInfo.enabled);
636 anAction->setVisible(theInfo.visible);
637 anAction->setIcon(theInfo.icon);
638 anAction->setText(theInfo.text);
639 anAction->setToolTip(theInfo.toolTip);
640 anAction->setShortcut(theInfo.shortcut);
641 anAction->setFont(theInfo.font);
643 int aWBMenu = createMenu(theWBName, -1, -1, 30);
644 int aItemId = createMenu(anAction, aWBMenu);
645 myActionsList.append(aItemId);
646 createMenu(separator(), aWBMenu); /// nested action is always separated of others
648 int aWBTool = createTool(theWBName, theWBName);
649 int aToolId = createTool(anAction, aWBTool);
650 registerCommandToolbar(theWBName, aItemId);
651 createTool(separator(), aWBTool); /// nested action is always separated of others
652 registerCommandToolbar(theWBName, -1);
658 //******************************************************
659 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
660 const QString& theTip, const QIcon& theIcon,
661 const QKeySequence& theKeys, bool isCheckable,
662 const char* theMenuSourceText, const int theMenuPosition)
664 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
666 int aId = getNextCommandId();
667 myActionsList.append(aId);
668 SUIT_Desktop* aDesk = application()->desktop();
670 for (int i = 0; i < theKeys.count(); i++)
672 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
674 aAction->setStatusTip(theTip);
675 aAction->setData(theId);
676 createMenu(aId, aMenu, theMenuPosition);
680 //******************************************************
681 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
683 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
684 createMenu(separator(), aMenu, -1, theMenuPosition);
687 //******************************************************
688 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
693 SUIT_Desktop* aDesktop = application()->desktop();
697 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
701 aToolMgr->append( theAction, theToolBarTitle );
705 //******************************************************
706 QList<QAction*> SHAPERGUI::commandList() const
708 QList<QAction*> aActions;
709 foreach (int aId, myActionsList) {
710 QAction* aCmd = action(aId);
712 aActions.append(aCmd);
718 //******************************************************
719 QMainWindow* SHAPERGUI::desktop() const
721 return application()->desktop();
724 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
725 const std::shared_ptr<Config_FeatureMessage>& theMessage)
727 myFeaturesInfo.insert(theFeatureId, theMessage);
730 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
732 std::shared_ptr<Config_FeatureMessage> aMessage;
733 if (myFeaturesInfo.contains(theFeatureId))
734 aMessage = myFeaturesInfo[theFeatureId];
738 //******************************************************
739 void SHAPERGUI::selectionChanged()
741 LightApp_Module::selectionChanged();
742 myWorkshop->salomeViewerSelectionChanged();
745 //******************************************************
746 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
748 myWorkshop->contextMenuMgr()->updateViewerMenu();
749 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
750 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
754 //******************************************************
755 void SHAPERGUI::createPreferences()
757 LightApp_Preferences* pref = preferences();
760 ModuleBase_Preferences::updateConfigByResources();
761 QString aModName = moduleName();
763 QtxPreferenceItem* item = pref->findItem(aModName, true );
764 if ( item && (!item->isEmpty() )) {
765 item->parentItem()->removeItem(item);
769 int catId = pref->addPreference(aModName, -1 );
772 SHAPERGUI_PrefMgr aMgr(pref, aModName);
773 ModuleBase_Preferences::createEditContent(&aMgr, catId);
775 int viewTab = pref->addItem(tr("Viewer"), catId);
776 // Create other parameters group in viewer tab
777 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
778 pref->setItemProperty("columns", 3, otherGroup);
779 pref->addItem(tr("Faces"), otherGroup,
780 SUIT_PreferenceMgr::Bool,
781 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
782 pref->addItem(tr("Edges"), otherGroup,
783 SUIT_PreferenceMgr::Bool,
784 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
785 pref->addItem(tr("Vertices"), otherGroup,
786 SUIT_PreferenceMgr::Bool,
787 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
789 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
790 pref->setItemProperty("columns", 2, sensitivityGroup);
791 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
792 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
793 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
794 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
796 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
797 pref->setItemProperty("columns", 2, highlightGroup);
798 pref->addItem(tr("In 3d mode"), highlightGroup,
799 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
800 pref->addItem(tr("In 2d mode"), highlightGroup,
801 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
803 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
804 pref->setItemProperty("columns", 4, colorScaleGroup);
805 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
806 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
807 pref->setItemProperty("min", 0, aItem);
808 pref->setItemProperty("max", 1, aItem);
810 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
811 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
812 pref->setItemProperty("min", 0, aItem);
813 pref->setItemProperty("max", 1, aItem);
815 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
816 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
817 pref->setItemProperty("min", 0, aItem);
818 pref->setItemProperty("max", 1, aItem);
820 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
821 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
822 pref->setItemProperty("min", 0, aItem);
823 pref->setItemProperty("max", 1, aItem);
825 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
826 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
827 pref->setItemProperty("min", 0, aItem);
828 pref->setItemProperty("max", 100, aItem);
830 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
831 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
832 pref->setItemProperty("min", 0, aItem);
833 pref->setItemProperty("max", 100, aItem);
835 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
836 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
841 //******************************************************
842 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
844 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
845 QString aVal = aResMgr->stringValue(theSection, theParam);
846 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
847 theParam.toStdString());
848 std::string aValue = aVal.toStdString();
849 if (aValue.empty()) {
850 aValue = aProp->defaultValue();
851 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
853 LightApp_Preferences* pref = preferences();
857 aProp->setValue(aValue);
859 myWorkshop->displayer()->redisplayObjects();
862 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
864 application()->putInfo(theInfo, theMSecs);
867 bool SHAPERGUI::abortAllOperations()
869 return workshop()->operationMgr()->abortAllOperations();
872 void SHAPERGUI::createFeatureActions()
874 myWorkshop->menuMgr()->createFeatureActions();
877 void SHAPERGUI::onWhatIs(bool isToggled)
879 if (sender() == myWhatIsAction) {
880 QAction* aViewAct = myInspectionPanel->toggleViewAction();
881 aViewAct->blockSignals(true);
882 aViewAct->setChecked(isToggled);
883 aViewAct->blockSignals(false);
884 myInspectionPanel->setVisible(isToggled);
887 myWhatIsAction->blockSignals(true);
888 myWhatIsAction->setChecked(isToggled);
889 myWhatIsAction->blockSignals(false);
890 myInspectionPanel->setVisible(isToggled);
894 void SHAPERGUI::updateModuleVisibilityState()
896 LightApp_Module::updateModuleVisibilityState();
897 onWhatIs(myIsInspectionVisible);
900 void SHAPERGUI::onEditToolbars()
902 SHAPERGUI_ToolbarsDlg aDlg(this);
903 if (aDlg.exec() == QDialog::Accepted) {
907 updateToolbars(aDlg.result());
911 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
913 if (!myToolbars.contains(theToolName))
914 myToolbars[theToolName] = QList<int>();
915 myToolbars[theToolName].append(theCommandId);
918 int SHAPERGUI::getNextCommandId() const
920 QtxActionMenuMgr* aMenuMgr = menuMgr();
921 QIntList aIds = aMenuMgr->idList();
922 int aId = aIds.count();
923 while (action(aId) || myActionsList.contains(aId))
928 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
930 // Store default toolbars
931 if (myDefaultToolbars.size() == 0)
932 myDefaultToolbars = myToolbars;
934 QtxActionToolMgr* aMgr = toolMgr();
935 QStringList aToolbars = theNewToolbars.keys();
936 QIntList aCommands, aOldCmd;
940 foreach(QString aName, aToolbars) {
941 aCommands = theNewToolbars[aName];
942 // Find or create toolbar
943 if (aMgr->hasToolBar(aName)) {
944 aToolbarId = aMgr->find(aMgr->toolBar(aName));
945 aOldCmd = myToolbars[aName];
948 aToolbarId = aMgr->createToolBar(aName);
951 foreach(int aCmd, aCommands) {
954 aAction = separator();
956 aAction = action(aCmd);
957 aActionId = aMgr->actionId(aAction);
958 if (aActionId == -1) {
960 aMgr->insert(aAction, aToolbarId, aPos);
963 // Change position of action
964 if (aMgr->index(aActionId, aToolbarId) != aPos) {
965 if (aMgr->containsAction(aActionId, aToolbarId))
966 aMgr->remove(aActionId, aToolbarId);
967 aMgr->insert(aActionId, aToolbarId, aPos);
970 aOldCmd.removeAll(aCmd);
973 // remove extra actions
974 foreach(int aCmd, aOldCmd) {
975 aAction = action(aCmd);
976 aActionId = aMgr->actionId(aAction);
977 aMgr->remove(aActionId, aToolbarId);
979 myToolbars.remove(aName);
981 // Remove extra toolbars
982 aToolbars = myToolbars.keys();
983 foreach(QString aName, aToolbars) {
984 aMgr->removeToolBar(aName);
986 // Set new toolbars structure
987 myToolbars = theNewToolbars;
988 myIsToolbarsModified = true;
991 void SHAPERGUI::saveToolbarsConfig()
993 if (!myIsToolbarsModified)
995 // Save toolbars configuration into map
996 QMap<QString, QStringList> aToolbarsConfig;
997 QtxActionToolMgr* aMgr = toolMgr();
998 QStringList aToolbars = myToolbars.keys();
999 QIntList aActionsIds;
1000 foreach(QString aName, aToolbars) {
1001 aActionsIds = myToolbars[aName];
1002 QStringList aContent;
1003 foreach(int aId, aActionsIds) {
1005 aContent.append("");
1007 aContent.append(action(aId)->data().toString());
1009 aToolbarsConfig[aName] = aContent;
1011 // Store the configuration into resources
1012 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1013 QStringList aNames = aToolbarsConfig.keys();
1014 QStringList aValues;
1015 foreach(QString aToolbar, aNames) {
1016 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1018 // Remove obsolete parameters from resources
1019 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1020 foreach(QString aName, aOldParams) {
1021 if (!aToolbars.contains(aName))
1022 aResMgr->remove(ToolbarsSection, aName);
1024 // Store current list of free commands
1025 QIntList aFreeCommands = getFreeCommands();
1026 QStringList aFreeList;
1027 foreach(int aId, aFreeCommands) {
1028 aFreeList.append(action(aId)->data().toString());
1030 if (aFreeList.size() > 0)
1031 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1033 myIsToolbarsModified = false;
1036 void SHAPERGUI::loadToolbarsConfig()
1038 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1039 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1040 if (aToolbarNames.size() == 0)
1043 // Create commands map
1044 QMap<QString, int> aCommandsMap;
1046 foreach(int aId, myActionsList) {
1047 aCmdIdStr = action(aId)->data().toString();
1048 aCommandsMap[aCmdIdStr] = aId;
1051 // Create new toolbars structure
1052 QMap<QString, QIntList> aToolbars;
1053 QStringList aCommands;
1054 QIntList aKnownCommands;
1055 QList<QAction*> aActions;
1056 foreach(QString aName, aToolbarNames) {
1057 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1058 if (aName == FreeCommandsParam) {
1059 // The value is a list of free commands
1060 foreach(QString aCommand, aCommands) {
1061 aKnownCommands.append(aCommandsMap[aCommand]);
1065 aToolbars[aName] = QIntList();
1066 if (aCommands.size() > 0) {
1067 foreach(QString aCommand, aCommands) {
1068 if (aCommand.isEmpty())
1069 aToolbars[aName].append(-1);
1070 else if (aCommandsMap.contains(aCommand)) {
1071 int aId = aCommandsMap[aCommand];
1072 aToolbars[aName].append(aId);
1073 aKnownCommands.append(aId);
1079 // Find new and obsolete commands
1080 QIntList aNewCommands = myActionsList;
1081 foreach(int aId, myActionsList) {
1082 if (aKnownCommands.contains(aId)) {
1083 aKnownCommands.removeAll(aId);
1084 aNewCommands.removeAll(aId);
1087 if (aNewCommands.size() > 0) {
1088 // Add new commands to toolbars structure
1089 QStringList aKeys = myToolbars.keys();
1090 foreach(int aNewId, aNewCommands) {
1091 foreach(QString aName, aKeys) {
1092 if (myToolbars[aName].contains(aNewId)) {
1093 if (!aToolbars.contains(aName)) {
1094 aToolbars[aName] = QIntList();
1096 aToolbars[aName].append(aNewId);
1101 if (aKnownCommands.size() > 0) {
1102 // Remove obsolete commands from the toolbars structure
1103 QStringList aKeys = aToolbars.keys();
1104 foreach(int aOldId, aKnownCommands) {
1105 foreach(QString aName, aKeys) {
1106 if (aToolbars[aName].contains(aOldId)) {
1107 aToolbars[aName].removeAll(aOldId);
1108 if (aToolbars[aName].size() == 0)
1109 aToolbars.remove(aName);
1114 updateToolbars(aToolbars);
1115 myIsToolbarsModified = false;
1119 QIntList SHAPERGUI::getFreeCommands() const
1121 QIntList aFreeCommands;
1122 QtxActionToolMgr* aMgr = toolMgr();
1125 QMap<QString, QIntList>::const_iterator aIt;
1126 QIntList aShaperActions = shaperActions();
1127 foreach(int aCmd, aShaperActions) {
1128 anAction = action(aCmd);
1129 aId = aMgr->actionId(anAction);
1130 if (!aMgr->containsAction(aId))
1131 aFreeCommands.append(aCmd);
1133 return aFreeCommands;
1136 void SHAPERGUI::resetToolbars()
1138 if (!myDefaultToolbars.isEmpty())
1139 updateToolbars(myDefaultToolbars);
1140 myIsToolbarsModified = false;
1141 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1142 aResMgr->remove(ToolbarsSection);