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 <LightApp_Application.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <LightApp_OCCSelector.h>
46 #include <LightApp_Study.h>
48 #include <OCCViewer_ViewModel.h>
49 #include <OCCViewer_ViewPort3d.h>
51 #include <SUIT_Selector.h>
52 #include <SUIT_Desktop.h>
53 #include <SUIT_ViewManager.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_ResourceMgr.h>
56 #include <SUIT_DataBrowser.h>
58 #include <QtxPopupMgr.h>
59 #include <QtxActionMenuMgr.h>
60 #include <QtxActionToolMgr.h>
61 #include <QtxResourceMgr.h>
63 #include <Config_PropManager.h>
64 #include <Config_ModuleReader.h>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
69 #include <QDockWidget>
75 #define SALOME_PATCH_FOR_CTRL_WHEEL
78 SHAPERGUI_EXPORT CAM_Module* createModule()
80 return new SHAPERGUI();
83 SHAPERGUI_EXPORT char* getModuleVersion()
90 static const QString ToolbarsSection("SHAPER_Toolbars");
91 static const QString FreeCommandsParam("OutOFToolbars");
95 * Class for preferences management
97 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
101 /// \param theMgr preferences manager of SALOME
102 /// \param theModName name of the module
103 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
104 myMgr(theMgr), myModName(theModName) {}
106 virtual int addPreference(const QString& theLbl, int pId,
107 SUIT_PreferenceMgr::PrefItemType theType,
108 const QString& theSection, const QString& theName )
110 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
113 virtual void setItemProperty(const QString& thePropName,
114 const QVariant& theValue,
115 const int theId = -1)
117 myMgr->setItemProperty(thePropName, theValue, theId);
121 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
124 LightApp_Preferences* myMgr;
131 //******************************************************
132 SHAPERGUI::SHAPERGUI()
133 : LightApp_Module("SHAPER"),
134 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
135 myInspectionPanel(0), myIsToolbarsModified(false)
137 myWorkshop = new XGUI_Workshop(this);
138 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
139 this, SLOT(onUpdateCommandStatus()));
141 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
143 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
144 ModuleBase_Preferences::loadCustomProps();
147 //******************************************************
148 SHAPERGUI::~SHAPERGUI()
151 delete myProxyViewer;
154 //******************************************************
155 void SHAPERGUI::initialize(CAM_Application* theApp)
157 LightApp_Module::initialize(theApp);
159 myWorkshop->startApplication();
160 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
163 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
166 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
167 int aSubMenu = createMenu(tr("Information"), aMenu);
169 int aId = getNextCommandId();
170 myActionsList.append(aId);
171 SUIT_Desktop* aDesk = application()->desktop();
172 QString aTip = tr("Show inspection window");
173 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
174 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
175 myWhatIsAction->setStatusTip(aTip);
176 myWhatIsAction->setData("INSPECTION_CMD");
177 createMenu(aId, aSubMenu, 0);
179 QString aToolName = tr("Inspection tool");
180 int aTool = createTool(aToolName);
181 int aToolId = createTool(myWhatIsAction, aTool);
182 registerCommandToolbar(aToolName, aId);
184 // Define Edit toolbars command
185 aId = getNextCommandId();
186 //myActionsList.append(aId); Do not use it for editing of toolbars
187 aTip = tr("Edit toolbars of the module");
188 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
189 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
190 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
191 int aEditItem = createMenu(aId, aEditMenu);
193 // Initialize viewer proxy if OCC viewer is already exist
194 ViewManagerList aOCCViewManagers;
195 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
196 if (aOCCViewManagers.size() > 0) {
197 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
198 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
200 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
201 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
203 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
204 aViewPort->installEventFilter(aViewer);
205 Handle(V3d_View) aView = aViewPort->getView();
206 aViewer->SetScale(aView, aView->Camera()->Scale());
207 // We can not create selector here because other modules will be deactivated later
208 //onViewManagerAdded(aMgr);
214 //******************************************************
215 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
217 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
220 //******************************************************
221 void SHAPERGUI::viewManagers(QStringList& theList) const
223 theList.append(OCCViewer_Viewer::Type());
226 //******************************************************
227 // We can not create selector in this method because it can be called when
228 // SHAPER module is not active. Take into account that creation of our selector
229 // leads to switching OFF all other selectors
230 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
232 // // if there are created viewer managers, we should try to create viewer
233 // // selector and initialize viewer with it. It sets interactive context to the
234 // // proxy viewer. If study is opened, CAM application calls this method before the open()
236 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
237 // // we need to connect to the viewer before it. Here,
238 // // it seems the most appropriate place for this
239 // // according to SALOME architecture.
240 // if (!mySelector) {
241 // ViewManagerList OCCViewManagers;
242 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
243 // if (OCCViewManagers.size() > 0) {
244 // mySelector = createSelector(OCCViewManagers.first());
247 // LightApp_Module::connectToStudy(theStudy);
250 //******************************************************
251 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
253 bool isDone = LightApp_Module::activateModule(theStudy);
254 loadToolbarsConfig();
256 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
257 aDataModel->initRootObject();
263 QObject* aObj = myWorkshop->objectBrowser()->parent();
264 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
266 QAction* aViewAct = aObjDoc->toggleViewAction();
267 aViewAct->setEnabled(true);
268 myWorkshop->objectBrowser()->setVisible(true);
269 aObjDoc->setVisible(true);
270 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
273 if (!myInspectionPanel) {
274 myInspectionPanel = myWorkshop->inspectionPanel();
275 QAction* aViewAct = myInspectionPanel->toggleViewAction();
276 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
278 myInspectionPanel->toggleViewAction()->setEnabled(true);
281 ViewManagerList OCCViewManagers;
282 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
283 if (OCCViewManagers.size() > 0) {
284 mySelector = createSelector(OCCViewManagers.first());
287 // it should be performed after the selector creation in order to have AISContext
288 myWorkshop->activateModule();
289 //action(myEraseAll)->setEnabled(false);
292 myWorkshop->objectBrowser()->rebuildDataTree();
293 myWorkshop->updateCommandStatus();
297 myWorkshop->updateCommandStatus();
299 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
300 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
301 myIsEditEnabled = getApp()->isEditEnabled();
302 getApp()->setEditEnabled(false);
304 // this following row is caused by #187 bug.
305 // SALOME saves the dock widget positions before deactivateModule() and
306 // load it after the module activation. So, if the panel is visible before
307 // deactivate, it becomes visible after activate.
308 // In order to avoid the visible property panel, the widget position save is
309 // switch off in this module
310 aResMgr->setValue("Study", "store_positions", false);
312 // Synchronize displayed objects
313 Handle(AIS_InteractiveContext) aContext;
314 if (mySelector && mySelector->viewer())
315 aContext = mySelector->viewer()->getAISContext();
317 if (!aContext.IsNull()) {
318 XGUI_Displayer* aDisp = myWorkshop->displayer();
319 QObjectPtrList aObjList = aDisp->displayedObjects();
321 AIS_ListOfInteractive aList;
322 aContext->DisplayedObjects(aList);
323 AIS_ListIteratorOfListOfInteractive aLIt;
324 Handle(AIS_InteractiveObject) anAISIO;
325 foreach (ObjectPtr aObj, aObjList) {
326 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
327 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
329 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
330 anAISIO = aLIt.Value();
331 if (anAISIO.get() == aAIS.get()) {
337 aObj->setDisplayed(false);
338 //aDisp->erase(aObj, false);
341 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
343 myProxyViewer->activateViewer(true);
345 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
346 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
347 this, SLOT(onScriptLoaded()));
349 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
350 getApp(), SLOT(onSaveDoc()));
351 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
352 getApp(), SLOT(onSaveAsDoc()));
354 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
355 this, SLOT(onSaveDocByShaper()));
356 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
357 this, SLOT(onSaveAsDocByShaper()));
362 //******************************************************
363 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
365 saveToolbarsConfig();
367 myProxyViewer->activateViewer(false);
371 myWorkshop->deactivateModule();
373 QObject* aObj = myWorkshop->objectBrowser()->parent();
374 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
376 aObjDoc->setVisible(false);
377 myWorkshop->objectBrowser()->setVisible(false);
378 QAction* aViewAct = aObjDoc->toggleViewAction();
379 aViewAct->setEnabled(false);
382 myIsInspectionVisible = myInspectionPanel->isVisible();
383 myInspectionPanel->hide();
384 QAction* aViewAct = myInspectionPanel->toggleViewAction();
385 aViewAct->setEnabled(false);
387 // the active operation should be stopped for the next activation.
388 // There should not be active operation and visualized preview.
389 // Abort operation should be performed before the selection's remove
390 // because the displayed objects should be removed from the viewer, but
391 // the AIS context is obtained from the selector.
392 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
393 while (anOperation) {
394 anOperation->abort();
395 anOperation = myWorkshop->operationMgr()->currentOperation();
397 // Delete selector because it has to be redefined on next activation
399 myProxyViewer->setSelector(0);
404 myWorkshop->hidePanel(myWorkshop->facesPanel());
405 //myWorkshop->contextMenuMgr()->disconnectViewer();
407 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
408 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
409 getApp()->setEditEnabled(myIsEditEnabled);
411 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
412 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
413 this, SLOT(onScriptLoaded()));
415 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
416 this, SLOT(onSaveDocByShaper()));
417 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
418 this, SLOT(onSaveAsDocByShaper()));
420 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
421 getApp(), SLOT(onSaveDoc()));
422 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
423 getApp(), SLOT(onSaveAsDoc()));
425 return LightApp_Module::deactivateModule(theStudy);
428 //******************************************************
429 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
432 mySelector = createSelector(theMgr);
433 myWorkshop->selectionActivate()->updateSelectionFilters();
434 myWorkshop->selectionActivate()->updateSelectionModes();
435 myWorkshop->synchronizeViewer();
439 //******************************************************
440 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
443 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
444 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
445 if (mySelector->viewer() == aViewer) {
446 XGUI_Displayer* aDisp = myWorkshop->displayer();
447 QObjectPtrList aObjects = aDisp->displayedObjects();
448 foreach(ObjectPtr aObj, aObjects)
449 aObj->setDisplayed(false);
450 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
451 myProxyViewer->setSelector(0);
455 myWorkshop->module()->clearViewer();
461 //******************************************************
462 QtxPopupMgr* SHAPERGUI::popupMgr()
465 myPopupMgr = new QtxPopupMgr( 0, this );
469 //******************************************************
470 void SHAPERGUI::onDefaultPreferences()
472 // reset main resources
473 ModuleBase_Preferences::resetResourcePreferences(preferences());
474 // reset plugin's resources
475 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
477 myWorkshop->displayer()->redisplayObjects();
480 //******************************************************
481 void SHAPERGUI::onScriptLoaded()
483 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
484 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
485 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
486 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
487 // it manually (because this method of application is protected)
488 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
493 //******************************************************
494 void SHAPERGUI::onSaveDocByShaper()
496 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
499 getApp()->onSaveDoc();
502 //******************************************************
503 void SHAPERGUI::onSaveAsDocByShaper()
505 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
508 getApp()->onSaveAsDoc();
511 //******************************************************
512 void SHAPERGUI::onUpdateCommandStatus()
514 getApp()->updateActions();
517 //******************************************************
518 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
520 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
521 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
522 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
523 getApp()->selectionMgr());
524 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
525 aViewer->setUseLocalSelection(true);
527 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
528 QList<SUIT_Selector*> aList;
529 aMgr->selectors(aList);
530 foreach(SUIT_Selector* aSel, aList)
532 aSel->setEnabled(aSel == aSelector);
534 myProxyViewer->setSelector(aSelector);
540 //******************************************************
541 CAM_DataModel* SHAPERGUI::createDataModel()
543 return new SHAPERGUI_DataModel(this);
546 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
547 const bool isAddSeparator)
549 return addFeature(theWBName,
553 //Issue #650: in the SALOME mode the tooltip should be same as text
562 //******************************************************
563 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
564 const QString& theId, const QString& theTitle, const QString& theTip,
565 const QIcon& theIcon, const QKeySequence& theKeys,
566 bool isCheckable, const bool isAddSeparator,
567 const QString& theStatusTip)
569 static QString aLastTool = "";
571 if (aLastTool.isEmpty())
572 aLastTool = theWBName;
573 else if (theWBName != aLastTool) {
574 aLastTool = theWBName;
576 desktop()->addToolBarBreak();
582 int aId = getNextCommandId();
583 myActionsList.append(aId);
584 SUIT_Desktop* aDesk = application()->desktop();
586 for (int i = 0; i < theKeys.count(); i++)
588 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
590 aAction->setStatusTip(theStatusTip);
592 aAction->setData(theId);
594 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
595 int aItemId = createMenu(aId, aWBMenu);
597 createMenu(separator(), aWBMenu);
599 int aWBTool = createTool(theTBName, theTBName);
600 int aToolId = createTool(aId, aWBTool);
601 registerCommandToolbar(theTBName, aId);
602 if (isAddSeparator) {
603 createTool(separator(), aWBTool);
604 registerCommandToolbar(theTBName, -1);
609 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
611 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
614 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
615 const ActionInfo& theInfo,
616 const QList<QAction*>& theNestedActions)
618 SUIT_Desktop* aDesk = application()->desktop();
619 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
620 anAction->setData(theInfo.id);
621 anAction->setCheckable(theInfo.checkable);
622 anAction->setChecked(theInfo.checked);
623 anAction->setEnabled(theInfo.enabled);
624 anAction->setVisible(theInfo.visible);
625 anAction->setIcon(theInfo.icon);
626 anAction->setText(theInfo.text);
627 anAction->setToolTip(theInfo.toolTip);
628 anAction->setShortcut(theInfo.shortcut);
629 anAction->setFont(theInfo.font);
631 int aWBMenu = createMenu(theWBName, -1, -1, 30);
632 int aItemId = createMenu(anAction, aWBMenu);
633 myActionsList.append(aItemId);
634 createMenu(separator(), aWBMenu); /// nested action is always separated of others
636 int aWBTool = createTool(theWBName, theWBName);
637 int aToolId = createTool(anAction, aWBTool);
638 registerCommandToolbar(theWBName, aItemId);
639 createTool(separator(), aWBTool); /// nested action is always separated of others
640 registerCommandToolbar(theWBName, -1);
646 //******************************************************
647 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
648 const QString& theTip, const QIcon& theIcon,
649 const QKeySequence& theKeys, bool isCheckable,
650 const char* theMenuSourceText, const int theMenuPosition)
652 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
654 int aId = getNextCommandId();
655 myActionsList.append(aId);
656 SUIT_Desktop* aDesk = application()->desktop();
658 for (int i = 0; i < theKeys.count(); i++)
660 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
662 aAction->setStatusTip(theTip);
663 aAction->setData(theId);
664 createMenu(aId, aMenu, theMenuPosition);
668 //******************************************************
669 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
671 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
672 createMenu(separator(), aMenu, -1, theMenuPosition);
675 //******************************************************
676 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
681 SUIT_Desktop* aDesktop = application()->desktop();
685 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
689 aToolMgr->append( theAction, theToolBarTitle );
693 //******************************************************
694 QList<QAction*> SHAPERGUI::commandList() const
696 QList<QAction*> aActions;
697 foreach (int aId, myActionsList) {
698 QAction* aCmd = action(aId);
700 aActions.append(aCmd);
706 //******************************************************
707 QMainWindow* SHAPERGUI::desktop() const
709 return application()->desktop();
712 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
713 const std::shared_ptr<Config_FeatureMessage>& theMessage)
715 myFeaturesInfo.insert(theFeatureId, theMessage);
718 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
720 std::shared_ptr<Config_FeatureMessage> aMessage;
721 if (myFeaturesInfo.contains(theFeatureId))
722 aMessage = myFeaturesInfo[theFeatureId];
726 //******************************************************
727 void SHAPERGUI::selectionChanged()
729 LightApp_Module::selectionChanged();
730 myWorkshop->salomeViewerSelectionChanged();
733 //******************************************************
734 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
736 myWorkshop->contextMenuMgr()->updateViewerMenu();
737 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
738 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
742 //******************************************************
743 void SHAPERGUI::createPreferences()
745 LightApp_Preferences* pref = preferences();
748 ModuleBase_Preferences::updateConfigByResources();
749 QString aModName = moduleName();
751 QtxPreferenceItem* item = pref->findItem(aModName, true );
752 if ( item && (!item->isEmpty() )) {
753 item->parentItem()->removeItem(item);
757 int catId = pref->addPreference(aModName, -1 );
760 SHAPERGUI_PrefMgr aMgr(pref, aModName);
761 ModuleBase_Preferences::createEditContent(&aMgr, catId);
763 int viewTab = pref->addItem(tr("Viewer"), catId);
764 // Create other parameters group in viewer tab
765 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
766 pref->setItemProperty("columns", 3, otherGroup);
767 pref->addItem(tr("Faces"), otherGroup,
768 SUIT_PreferenceMgr::Bool,
769 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
770 pref->addItem(tr("Edges"), otherGroup,
771 SUIT_PreferenceMgr::Bool,
772 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
773 pref->addItem(tr("Vertices"), otherGroup,
774 SUIT_PreferenceMgr::Bool,
775 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
777 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
778 pref->setItemProperty("columns", 2, sensitivityGroup);
779 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
780 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
781 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
782 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
784 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
785 pref->setItemProperty("columns", 2, highlightGroup);
786 pref->addItem(tr("In 3d mode"), highlightGroup,
787 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
788 pref->addItem(tr("In 2d mode"), highlightGroup,
789 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
791 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
792 pref->setItemProperty("columns", 4, colorScaleGroup);
793 int aItem = pref->addItem(tr("X position"), colorScaleGroup,
794 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
795 pref->setItemProperty("min", 0, aItem);
796 pref->setItemProperty("max", 1, aItem);
798 aItem = pref->addItem(tr("Y position"), colorScaleGroup,
799 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
800 pref->setItemProperty("min", 0, aItem);
801 pref->setItemProperty("max", 1, aItem);
803 aItem = pref->addItem(tr("Width"), colorScaleGroup,
804 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
805 pref->setItemProperty("min", 0, aItem);
806 pref->setItemProperty("max", 1, aItem);
808 aItem = pref->addItem(tr("Height"), colorScaleGroup,
809 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
810 pref->setItemProperty("min", 0, aItem);
811 pref->setItemProperty("max", 1, aItem);
813 aItem = pref->addItem(tr("Intervals number"), colorScaleGroup,
814 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
815 pref->setItemProperty("min", 0, aItem);
816 pref->setItemProperty("max", 100, aItem);
818 aItem = pref->addItem(tr("Text height"), colorScaleGroup,
819 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
820 pref->setItemProperty("min", 0, aItem);
821 pref->setItemProperty("max", 100, aItem);
823 aItem = pref->addItem(tr("Text color"), colorScaleGroup,
824 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
829 //******************************************************
830 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
832 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
833 QString aVal = aResMgr->stringValue(theSection, theParam);
834 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
835 theParam.toStdString());
836 std::string aValue = aVal.toStdString();
837 if (aValue.empty()) {
838 aValue = aProp->defaultValue();
839 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
841 LightApp_Preferences* pref = preferences();
845 aProp->setValue(aValue);
847 myWorkshop->displayer()->redisplayObjects();
850 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
852 application()->putInfo(theInfo, theMSecs);
855 bool SHAPERGUI::abortAllOperations()
857 return workshop()->operationMgr()->abortAllOperations();
860 void SHAPERGUI::createFeatureActions()
862 myWorkshop->menuMgr()->createFeatureActions();
865 void SHAPERGUI::onWhatIs(bool isToggled)
867 if (sender() == myWhatIsAction) {
868 QAction* aViewAct = myInspectionPanel->toggleViewAction();
869 aViewAct->blockSignals(true);
870 aViewAct->setChecked(isToggled);
871 aViewAct->blockSignals(false);
872 myInspectionPanel->setVisible(isToggled);
875 myWhatIsAction->blockSignals(true);
876 myWhatIsAction->setChecked(isToggled);
877 myWhatIsAction->blockSignals(false);
878 myInspectionPanel->setVisible(isToggled);
882 void SHAPERGUI::updateModuleVisibilityState()
884 LightApp_Module::updateModuleVisibilityState();
885 onWhatIs(myIsInspectionVisible);
888 void SHAPERGUI::onEditToolbars()
890 SHAPERGUI_ToolbarsDlg aDlg(this);
891 if (aDlg.exec() == QDialog::Accepted) {
895 updateToolbars(aDlg.result());
899 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
901 if (!myToolbars.contains(theToolName))
902 myToolbars[theToolName] = QList<int>();
903 myToolbars[theToolName].append(theCommandId);
906 int SHAPERGUI::getNextCommandId() const
908 QtxActionMenuMgr* aMenuMgr = menuMgr();
909 QIntList aIds = aMenuMgr->idList();
910 int aId = aIds.count();
911 while (action(aId) || myActionsList.contains(aId))
916 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
918 // Store default toolbars
919 if (myDefaultToolbars.size() == 0)
920 myDefaultToolbars = myToolbars;
922 QtxActionToolMgr* aMgr = toolMgr();
923 QStringList aToolbars = theNewToolbars.keys();
924 QIntList aCommands, aOldCmd;
928 foreach(QString aName, aToolbars) {
929 aCommands = theNewToolbars[aName];
930 // Find or create toolbar
931 if (aMgr->hasToolBar(aName)) {
932 aToolbarId = aMgr->find(aMgr->toolBar(aName));
933 aOldCmd = myToolbars[aName];
936 aToolbarId = aMgr->createToolBar(aName);
939 foreach(int aCmd, aCommands) {
942 aAction = separator();
944 aAction = action(aCmd);
945 aActionId = aMgr->actionId(aAction);
946 if (aActionId == -1) {
948 aMgr->insert(aAction, aToolbarId, aPos);
951 // Change position of action
952 if (aMgr->index(aActionId, aToolbarId) != aPos) {
953 if (aMgr->containsAction(aActionId, aToolbarId))
954 aMgr->remove(aActionId, aToolbarId);
955 aMgr->insert(aActionId, aToolbarId, aPos);
958 aOldCmd.removeAll(aCmd);
961 // remove extra actions
962 foreach(int aCmd, aOldCmd) {
963 aAction = action(aCmd);
964 aActionId = aMgr->actionId(aAction);
965 aMgr->remove(aActionId, aToolbarId);
967 myToolbars.remove(aName);
969 // Remove extra toolbars
970 aToolbars = myToolbars.keys();
971 foreach(QString aName, aToolbars) {
972 aMgr->removeToolBar(aName);
974 // Set new toolbars structure
975 myToolbars = theNewToolbars;
976 myIsToolbarsModified = true;
979 void SHAPERGUI::saveToolbarsConfig()
981 if (!myIsToolbarsModified)
983 // Save toolbars configuration into map
984 QMap<QString, QStringList> aToolbarsConfig;
985 QtxActionToolMgr* aMgr = toolMgr();
986 QStringList aToolbars = myToolbars.keys();
987 QIntList aActionsIds;
988 foreach(QString aName, aToolbars) {
989 aActionsIds = myToolbars[aName];
990 QStringList aContent;
991 foreach(int aId, aActionsIds) {
995 aContent.append(action(aId)->data().toString());
997 aToolbarsConfig[aName] = aContent;
999 // Store the configuration into resources
1000 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1001 QStringList aNames = aToolbarsConfig.keys();
1002 QStringList aValues;
1003 foreach(QString aToolbar, aNames) {
1004 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1006 // Remove obsolete parameters from resources
1007 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1008 foreach(QString aName, aOldParams) {
1009 if (!aToolbars.contains(aName))
1010 aResMgr->remove(ToolbarsSection, aName);
1012 // Store current list of free commands
1013 QIntList aFreeCommands = getFreeCommands();
1014 QStringList aFreeList;
1015 foreach(int aId, aFreeCommands) {
1016 aFreeList.append(action(aId)->data().toString());
1018 if (aFreeList.size() > 0)
1019 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1021 myIsToolbarsModified = false;
1024 void SHAPERGUI::loadToolbarsConfig()
1026 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1027 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1028 if (aToolbarNames.size() == 0)
1031 // Create commands map
1032 QMap<QString, int> aCommandsMap;
1034 foreach(int aId, myActionsList) {
1035 aCmdIdStr = action(aId)->data().toString();
1036 aCommandsMap[aCmdIdStr] = aId;
1039 // Create new toolbars structure
1040 QMap<QString, QIntList> aToolbars;
1041 QStringList aCommands;
1042 QIntList aKnownCommands;
1043 QList<QAction*> aActions;
1044 foreach(QString aName, aToolbarNames) {
1045 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1046 if (aName == FreeCommandsParam) {
1047 // The value is a list of free commands
1048 foreach(QString aCommand, aCommands) {
1049 aKnownCommands.append(aCommandsMap[aCommand]);
1053 aToolbars[aName] = QIntList();
1054 if (aCommands.size() > 0) {
1055 foreach(QString aCommand, aCommands) {
1056 if (aCommand.isEmpty())
1057 aToolbars[aName].append(-1);
1058 else if (aCommandsMap.contains(aCommand)) {
1059 int aId = aCommandsMap[aCommand];
1060 aToolbars[aName].append(aId);
1061 aKnownCommands.append(aId);
1067 // Find new and obsolete commands
1068 QIntList aNewCommands = myActionsList;
1069 foreach(int aId, myActionsList) {
1070 if (aKnownCommands.contains(aId)) {
1071 aKnownCommands.removeAll(aId);
1072 aNewCommands.removeAll(aId);
1075 if (aNewCommands.size() > 0) {
1076 // Add new commands to toolbars structure
1077 QStringList aKeys = myToolbars.keys();
1078 foreach(int aNewId, aNewCommands) {
1079 foreach(QString aName, aKeys) {
1080 if (myToolbars[aName].contains(aNewId)) {
1081 if (!aToolbars.contains(aName)) {
1082 aToolbars[aName] = QIntList();
1084 aToolbars[aName].append(aNewId);
1089 if (aKnownCommands.size() > 0) {
1090 // Remove obsolete commands from the toolbars structure
1091 QStringList aKeys = aToolbars.keys();
1092 foreach(int aOldId, aKnownCommands) {
1093 foreach(QString aName, aKeys) {
1094 if (aToolbars[aName].contains(aOldId)) {
1095 aToolbars[aName].removeAll(aOldId);
1096 if (aToolbars[aName].size() == 0)
1097 aToolbars.remove(aName);
1102 updateToolbars(aToolbars);
1103 myIsToolbarsModified = false;
1107 QIntList SHAPERGUI::getFreeCommands() const
1109 QIntList aFreeCommands;
1110 QtxActionToolMgr* aMgr = toolMgr();
1113 QMap<QString, QIntList>::const_iterator aIt;
1114 QIntList aShaperActions = shaperActions();
1115 foreach(int aCmd, aShaperActions) {
1116 anAction = action(aCmd);
1117 aId = aMgr->actionId(anAction);
1118 if (!aMgr->containsAction(aId))
1119 aFreeCommands.append(aCmd);
1121 return aFreeCommands;
1124 void SHAPERGUI::resetToolbars()
1126 if (!myDefaultToolbars.isEmpty())
1127 updateToolbars(myDefaultToolbars);
1128 myIsToolbarsModified = false;
1129 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1130 aResMgr->remove(ToolbarsSection);