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 onViewManagerAdded(aMgr);
213 //******************************************************
214 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
216 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
219 //******************************************************
220 void SHAPERGUI::viewManagers(QStringList& theList) const
222 theList.append(OCCViewer_Viewer::Type());
225 //******************************************************
226 // We can not create selector in this method because it can be called when
227 // SHAPER module is not active. Take into account that creation of our selector
228 // leads to switching OFF all other selectors
229 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
231 // // if there are created viewer managers, we should try to create viewer
232 // // selector and initialize viewer with it. It sets interactive contect to the
233 // // proxy viewer. If study is opened, CAM application calls this method before the open()
235 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
236 // // we need to connect to the viewer before it. Here,
237 // // it seems the most appropriate place for this
238 // // according to SALOME architecture.
239 // if (!mySelector) {
240 // ViewManagerList OCCViewManagers;
241 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
242 // if (OCCViewManagers.size() > 0) {
243 // mySelector = createSelector(OCCViewManagers.first());
246 // LightApp_Module::connectToStudy(theStudy);
249 //******************************************************
250 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
252 bool isDone = LightApp_Module::activateModule(theStudy);
253 loadToolbarsConfig();
255 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
256 aDataModel->initRootObject();
262 QObject* aObj = myWorkshop->objectBrowser()->parent();
263 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
265 QAction* aViewAct = aObjDoc->toggleViewAction();
266 aViewAct->setEnabled(true);
267 myWorkshop->objectBrowser()->setVisible(true);
268 aObjDoc->setVisible(true);
269 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
272 if (!myInspectionPanel) {
273 myInspectionPanel = myWorkshop->inspectionPanel();
274 QAction* aViewAct = myInspectionPanel->toggleViewAction();
275 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
277 myInspectionPanel->toggleViewAction()->setEnabled(true);
280 ViewManagerList OCCViewManagers;
281 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
282 if (OCCViewManagers.size() > 0) {
283 mySelector = createSelector(OCCViewManagers.first());
286 // it should be pefromed after the selector creation in order to have AISContext
287 myWorkshop->activateModule();
288 //action(myEraseAll)->setEnabled(false);
291 myWorkshop->objectBrowser()->rebuildDataTree();
292 myWorkshop->updateCommandStatus();
296 myWorkshop->updateCommandStatus();
298 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
299 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
300 myIsEditEnabled = getApp()->isEditEnabled();
301 getApp()->setEditEnabled(false);
303 // this following row is caused by #187 bug.
304 // SALOME saves the dock widget positions before deactivateModule() and
305 // load it after the module activation. So, if the panel is visible before
306 // deactivate, it becomes visible after activate.
307 // In order to avoid the visible property panel, the widget position save is
308 // switch off in this module
309 aResMgr->setValue("Study", "store_positions", false);
311 // Synchronize displayed objects
312 Handle(AIS_InteractiveContext) aContext;
313 if (mySelector && mySelector->viewer())
314 aContext = mySelector->viewer()->getAISContext();
316 if (!aContext.IsNull()) {
317 XGUI_Displayer* aDisp = myWorkshop->displayer();
318 QObjectPtrList aObjList = aDisp->displayedObjects();
320 AIS_ListOfInteractive aList;
321 aContext->DisplayedObjects(aList);
322 AIS_ListIteratorOfListOfInteractive aLIt;
323 Handle(AIS_InteractiveObject) anAISIO;
324 foreach (ObjectPtr aObj, aObjList) {
325 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
326 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
328 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
329 anAISIO = aLIt.Value();
330 if (anAISIO.get() == aAIS.get()) {
336 aObj->setDisplayed(false);
337 //aDisp->erase(aObj, false);
340 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
342 myProxyViewer->activateViewer(true);
344 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
345 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
346 this, SLOT(onScriptLoaded()));
348 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
349 getApp(), SLOT(onSaveDoc()));
350 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
351 getApp(), SLOT(onSaveAsDoc()));
353 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
354 this, SLOT(onSaveDocByShaper()));
355 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
356 this, SLOT(onSaveAsDocByShaper()));
361 //******************************************************
362 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
364 saveToolbarsConfig();
366 myProxyViewer->activateViewer(false);
370 myWorkshop->deactivateModule();
372 QObject* aObj = myWorkshop->objectBrowser()->parent();
373 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
375 aObjDoc->setVisible(false);
376 myWorkshop->objectBrowser()->setVisible(false);
377 QAction* aViewAct = aObjDoc->toggleViewAction();
378 aViewAct->setEnabled(false);
381 myIsInspectionVisible = myInspectionPanel->isVisible();
382 myInspectionPanel->hide();
383 QAction* aViewAct = myInspectionPanel->toggleViewAction();
384 aViewAct->setEnabled(false);
386 // the active operation should be stopped for the next activation.
387 // There should not be active operation and visualized preview.
388 // Abort operation should be performed before the selection's remove
389 // because the displayed objects should be removed from the viewer, but
390 // the AIS context is obtained from the selector.
391 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
392 while (anOperation) {
393 anOperation->abort();
394 anOperation = myWorkshop->operationMgr()->currentOperation();
396 // Delete selector because it has to be redefined on next activation
398 myProxyViewer->setSelector(0);
403 myWorkshop->hidePanel(myWorkshop->facesPanel());
404 //myWorkshop->contextMenuMgr()->disconnectViewer();
406 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
407 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
408 getApp()->setEditEnabled(myIsEditEnabled);
410 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
411 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
412 this, SLOT(onScriptLoaded()));
414 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
415 this, SLOT(onSaveDocByShaper()));
416 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
417 this, SLOT(onSaveAsDocByShaper()));
419 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
420 getApp(), SLOT(onSaveDoc()));
421 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
422 getApp(), SLOT(onSaveAsDoc()));
424 return LightApp_Module::deactivateModule(theStudy);
427 //******************************************************
428 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
431 mySelector = createSelector(theMgr);
432 myWorkshop->selectionActivate()->updateSelectionFilters();
433 myWorkshop->selectionActivate()->updateSelectionModes();
434 myWorkshop->synchronizeViewer();
438 //******************************************************
439 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
442 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
443 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
444 if (mySelector->viewer() == aViewer) {
445 XGUI_Displayer* aDisp = myWorkshop->displayer();
446 QObjectPtrList aObjects = aDisp->displayedObjects();
447 foreach(ObjectPtr aObj, aObjects)
448 aObj->setDisplayed(false);
449 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
450 myProxyViewer->setSelector(0);
454 myWorkshop->module()->clearViewer();
460 //******************************************************
461 QtxPopupMgr* SHAPERGUI::popupMgr()
464 myPopupMgr = new QtxPopupMgr( 0, this );
468 //******************************************************
469 void SHAPERGUI::onDefaultPreferences()
471 // reset main resources
472 ModuleBase_Preferences::resetResourcePreferences(preferences());
473 // reset plugin's resources
474 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
476 myWorkshop->displayer()->redisplayObjects();
479 //******************************************************
480 void SHAPERGUI::onScriptLoaded()
482 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
483 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
484 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
485 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
486 // it manually (because this method of application is protected)
487 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
492 //******************************************************
493 void SHAPERGUI::onSaveDocByShaper()
495 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
498 getApp()->onSaveDoc();
501 //******************************************************
502 void SHAPERGUI::onSaveAsDocByShaper()
504 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
507 getApp()->onSaveAsDoc();
510 //******************************************************
511 void SHAPERGUI::onUpdateCommandStatus()
513 getApp()->updateActions();
516 //******************************************************
517 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
519 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
520 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
521 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
522 getApp()->selectionMgr());
523 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
524 aViewer->setUseLocalSelection(true);
526 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
527 QList<SUIT_Selector*> aList;
528 aMgr->selectors(aList);
529 foreach(SUIT_Selector* aSel, aList)
531 aSel->setEnabled(aSel == aSelector);
533 myProxyViewer->setSelector(aSelector);
539 //******************************************************
540 CAM_DataModel* SHAPERGUI::createDataModel()
542 return new SHAPERGUI_DataModel(this);
545 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
546 const bool isAddSeparator)
548 return addFeature(theWBName,
552 //Issue #650: in the SALOME mode the tooltip should be same as text
561 //******************************************************
562 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
563 const QString& theId, const QString& theTitle, const QString& theTip,
564 const QIcon& theIcon, const QKeySequence& theKeys,
565 bool isCheckable, const bool isAddSeparator,
566 const QString& theStatusTip)
568 static QString aLastTool = "";
570 if (aLastTool.isEmpty())
571 aLastTool = theWBName;
572 else if (theWBName != aLastTool) {
573 aLastTool = theWBName;
575 desktop()->addToolBarBreak();
581 int aId = getNextCommandId();
582 myActionsList.append(aId);
583 SUIT_Desktop* aDesk = application()->desktop();
585 for (int i = 0; i < theKeys.count(); i++)
587 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
589 aAction->setStatusTip(theStatusTip);
591 aAction->setData(theId);
593 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
594 int aItemId = createMenu(aId, aWBMenu);
596 createMenu(separator(), aWBMenu);
598 int aWBTool = createTool(theTBName, theTBName);
599 int aToolId = createTool(aId, aWBTool);
600 registerCommandToolbar(theTBName, aId);
601 if (isAddSeparator) {
602 createTool(separator(), aWBTool);
603 registerCommandToolbar(theTBName, -1);
608 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
610 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
613 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
614 const ActionInfo& theInfo,
615 const QList<QAction*>& theNestedActions)
617 SUIT_Desktop* aDesk = application()->desktop();
618 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
619 anAction->setData(theInfo.id);
620 anAction->setCheckable(theInfo.checkable);
621 anAction->setChecked(theInfo.checked);
622 anAction->setEnabled(theInfo.enabled);
623 anAction->setVisible(theInfo.visible);
624 anAction->setIcon(theInfo.icon);
625 anAction->setText(theInfo.text);
626 anAction->setToolTip(theInfo.toolTip);
627 anAction->setShortcut(theInfo.shortcut);
628 anAction->setFont(theInfo.font);
630 int aWBMenu = createMenu(theWBName, -1, -1, 30);
631 int aItemId = createMenu(anAction, aWBMenu);
632 myActionsList.append(aItemId);
633 createMenu(separator(), aWBMenu); /// nested action is always separated of others
635 int aWBTool = createTool(theWBName, theWBName);
636 int aToolId = createTool(anAction, aWBTool);
637 registerCommandToolbar(theWBName, aItemId);
638 createTool(separator(), aWBTool); /// nested action is always separated of others
639 registerCommandToolbar(theWBName, -1);
645 //******************************************************
646 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
647 const QString& theTip, const QIcon& theIcon,
648 const QKeySequence& theKeys, bool isCheckable,
649 const char* theMenuSourceText, const int theMenuPosition)
651 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
653 int aId = getNextCommandId();
654 myActionsList.append(aId);
655 SUIT_Desktop* aDesk = application()->desktop();
657 for (int i = 0; i < theKeys.count(); i++)
659 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
661 aAction->setStatusTip(theTip);
662 aAction->setData(theId);
663 createMenu(aId, aMenu, theMenuPosition);
667 //******************************************************
668 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
670 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
671 createMenu(separator(), aMenu, -1, theMenuPosition);
674 //******************************************************
675 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
680 SUIT_Desktop* aDesktop = application()->desktop();
684 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
688 aToolMgr->append( theAction, theToolBarTitle );
692 //******************************************************
693 QList<QAction*> SHAPERGUI::commandList() const
695 QList<QAction*> aActions;
696 foreach (int aId, myActionsList) {
697 QAction* aCmd = action(aId);
699 aActions.append(aCmd);
705 //******************************************************
706 QMainWindow* SHAPERGUI::desktop() const
708 return application()->desktop();
711 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
712 const std::shared_ptr<Config_FeatureMessage>& theMessage)
714 myFeaturesInfo.insert(theFeatureId, theMessage);
717 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
719 std::shared_ptr<Config_FeatureMessage> aMessage;
720 if (myFeaturesInfo.contains(theFeatureId))
721 aMessage = myFeaturesInfo[theFeatureId];
725 //******************************************************
726 void SHAPERGUI::selectionChanged()
728 LightApp_Module::selectionChanged();
729 myWorkshop->salomeViewerSelectionChanged();
732 //******************************************************
733 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
735 myWorkshop->contextMenuMgr()->updateViewerMenu();
736 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
737 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
741 //******************************************************
742 void SHAPERGUI::createPreferences()
744 LightApp_Preferences* pref = preferences();
747 ModuleBase_Preferences::updateConfigByResources();
748 QString aModName = moduleName();
750 QtxPreferenceItem* item = pref->findItem(aModName, true );
751 if ( item && (!item->isEmpty() )) {
752 item->parentItem()->removeItem(item);
756 int catId = pref->addPreference(aModName, -1 );
759 SHAPERGUI_PrefMgr aMgr(pref, aModName);
760 ModuleBase_Preferences::createEditContent(&aMgr, catId);
762 int viewTab = pref->addItem(tr("Viewer"), catId);
763 // Create other parameters group in viewer tab
764 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
765 pref->setItemProperty("columns", 3, otherGroup);
766 pref->addItem(tr("Faces"), otherGroup,
767 SUIT_PreferenceMgr::Bool,
768 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
769 pref->addItem(tr("Edges"), otherGroup,
770 SUIT_PreferenceMgr::Bool,
771 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
772 pref->addItem(tr("Vertices"), otherGroup,
773 SUIT_PreferenceMgr::Bool,
774 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
776 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
777 pref->setItemProperty("columns", 2, sensitivityGroup);
778 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
779 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
780 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
781 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
785 //******************************************************
786 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
788 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
789 QString aVal = aResMgr->stringValue(theSection, theParam);
790 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
791 theParam.toStdString());
792 std::string aValue = aVal.toStdString();
793 if (aValue.empty()) {
794 aValue = aProp->defaultValue();
795 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
797 LightApp_Preferences* pref = preferences();
801 aProp->setValue(aValue);
803 myWorkshop->displayer()->redisplayObjects();
806 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
808 application()->putInfo(theInfo, theMSecs);
811 bool SHAPERGUI::abortAllOperations()
813 return workshop()->operationMgr()->abortAllOperations();
816 void SHAPERGUI::createFeatureActions()
818 myWorkshop->menuMgr()->createFeatureActions();
821 void SHAPERGUI::onWhatIs(bool isToggled)
823 if (sender() == myWhatIsAction) {
824 QAction* aViewAct = myInspectionPanel->toggleViewAction();
825 aViewAct->blockSignals(true);
826 aViewAct->setChecked(isToggled);
827 aViewAct->blockSignals(false);
828 myInspectionPanel->setVisible(isToggled);
831 myWhatIsAction->blockSignals(true);
832 myWhatIsAction->setChecked(isToggled);
833 myWhatIsAction->blockSignals(false);
834 myInspectionPanel->setVisible(isToggled);
838 void SHAPERGUI::updateModuleVisibilityState()
840 LightApp_Module::updateModuleVisibilityState();
841 onWhatIs(myIsInspectionVisible);
844 void SHAPERGUI::onEditToolbars()
846 SHAPERGUI_ToolbarsDlg aDlg(this);
847 if (aDlg.exec() == QDialog::Accepted) {
851 updateToolbars(aDlg.result());
855 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
857 if (!myToolbars.contains(theToolName))
858 myToolbars[theToolName] = QList<int>();
859 myToolbars[theToolName].append(theCommandId);
862 int SHAPERGUI::getNextCommandId() const
864 QtxActionMenuMgr* aMenuMgr = menuMgr();
865 QIntList aIds = aMenuMgr->idList();
866 int aId = aIds.count();
867 while (action(aId) || myActionsList.contains(aId))
872 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
874 // Store default toolbars
875 if (myDefaultToolbars.size() == 0)
876 myDefaultToolbars = myToolbars;
878 QtxActionToolMgr* aMgr = toolMgr();
879 QStringList aToolbars = theNewToolbars.keys();
880 QIntList aCommands, aOldCmd;
884 foreach(QString aName, aToolbars) {
885 aCommands = theNewToolbars[aName];
886 // Find or create toolbar
887 if (aMgr->hasToolBar(aName)) {
888 aToolbarId = aMgr->find(aMgr->toolBar(aName));
889 aOldCmd = myToolbars[aName];
892 aToolbarId = aMgr->createToolBar(aName);
895 foreach(int aCmd, aCommands) {
898 aAction = separator();
900 aAction = action(aCmd);
901 aActionId = aMgr->actionId(aAction);
902 if (aActionId == -1) {
904 aMgr->insert(aAction, aToolbarId, aPos);
907 // Change position of action
908 if (aMgr->index(aActionId, aToolbarId) != aPos) {
909 if (aMgr->containsAction(aActionId, aToolbarId))
910 aMgr->remove(aActionId, aToolbarId);
911 aMgr->insert(aActionId, aToolbarId, aPos);
914 aOldCmd.removeAll(aCmd);
917 // remove extra actions
918 foreach(int aCmd, aOldCmd) {
919 aAction = action(aCmd);
920 aActionId = aMgr->actionId(aAction);
921 aMgr->remove(aActionId, aToolbarId);
923 myToolbars.remove(aName);
925 // Remove extra toolbars
926 aToolbars = myToolbars.keys();
927 foreach(QString aName, aToolbars) {
928 aMgr->removeToolBar(aName);
930 // Set new toolbars structure
931 myToolbars = theNewToolbars;
932 myIsToolbarsModified = true;
935 void SHAPERGUI::saveToolbarsConfig()
937 if (!myIsToolbarsModified)
939 // Save toolbars config into map
940 QMap<QString, QStringList> aToolbarsConfig;
941 QtxActionToolMgr* aMgr = toolMgr();
942 QStringList aToolbars = myToolbars.keys();
943 QIntList aActionsIds;
944 foreach(QString aName, aToolbars) {
945 aActionsIds = myToolbars[aName];
946 QStringList aContent;
947 foreach(int aId, aActionsIds) {
951 aContent.append(action(aId)->data().toString());
953 aToolbarsConfig[aName] = aContent;
955 // Store the config into resources
956 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
957 QStringList aNames = aToolbarsConfig.keys();
959 foreach(QString aToolbar, aNames) {
960 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
962 // Remove obsolete parameters from resources
963 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
964 foreach(QString aName, aOldParams) {
965 if (!aToolbars.contains(aName))
966 aResMgr->remove(ToolbarsSection, aName);
968 // Store current list of free commands
969 QIntList aFreeCommands = getFreeCommands();
970 QStringList aFreeList;
971 foreach(int aId, aFreeCommands) {
972 aFreeList.append(action(aId)->data().toString());
974 if (aFreeList.size() > 0)
975 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
977 myIsToolbarsModified = false;
980 void SHAPERGUI::loadToolbarsConfig()
982 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
983 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
984 if (aToolbarNames.size() == 0)
987 // Create commands map
988 QMap<QString, int> aCommandsMap;
990 foreach(int aId, myActionsList) {
991 aCmdIdStr = action(aId)->data().toString();
992 aCommandsMap[aCmdIdStr] = aId;
995 // Create new toolbars structure
996 QMap<QString, QIntList> aToolbars;
997 QStringList aCommands;
998 QIntList aKnownCommands;
999 QList<QAction*> aActions;
1000 foreach(QString aName, aToolbarNames) {
1001 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1002 if (aName == FreeCommandsParam) {
1003 // The value is a list of free commands
1004 foreach(QString aCommand, aCommands) {
1005 aKnownCommands.append(aCommandsMap[aCommand]);
1009 aToolbars[aName] = QIntList();
1010 if (aCommands.size() > 0) {
1011 foreach(QString aCommand, aCommands) {
1012 if (aCommand.isEmpty())
1013 aToolbars[aName].append(-1);
1014 else if (aCommandsMap.contains(aCommand)) {
1015 int aId = aCommandsMap[aCommand];
1016 aToolbars[aName].append(aId);
1017 aKnownCommands.append(aId);
1023 // Find new and obsolete commands
1024 QIntList aNewCommands = myActionsList;
1025 foreach(int aId, myActionsList) {
1026 if (aKnownCommands.contains(aId)) {
1027 aKnownCommands.removeAll(aId);
1028 aNewCommands.removeAll(aId);
1031 if (aNewCommands.size() > 0) {
1032 // Add new commands to toolbars structure
1033 QStringList aKeys = myToolbars.keys();
1034 foreach(int aNewId, aNewCommands) {
1035 foreach(QString aName, aKeys) {
1036 if (myToolbars[aName].contains(aNewId)) {
1037 if (!aToolbars.contains(aName)) {
1038 aToolbars[aName] = QIntList();
1040 aToolbars[aName].append(aNewId);
1045 if (aKnownCommands.size() > 0) {
1046 // Remove obsolete commands from the toolbars structure
1047 QStringList aKeys = aToolbars.keys();
1048 foreach(int aOldId, aKnownCommands) {
1049 foreach(QString aName, aKeys) {
1050 if (aToolbars[aName].contains(aOldId)) {
1051 aToolbars[aName].removeAll(aOldId);
1052 if (aToolbars[aName].size() == 0)
1053 aToolbars.remove(aName);
1058 updateToolbars(aToolbars);
1059 myIsToolbarsModified = false;
1063 QIntList SHAPERGUI::getFreeCommands() const
1065 QIntList aFreeCommands;
1066 QtxActionToolMgr* aMgr = toolMgr();
1069 QMap<QString, QIntList>::const_iterator aIt;
1070 QIntList aShaperActions = shaperActions();
1071 foreach(int aCmd, aShaperActions) {
1072 anAction = action(aCmd);
1073 aId = aMgr->actionId(anAction);
1074 if (!aMgr->containsAction(aId))
1075 aFreeCommands.append(aCmd);
1077 return aFreeCommands;
1080 void SHAPERGUI::resetToolbars()
1082 if (!myDefaultToolbars.isEmpty())
1083 updateToolbars(myDefaultToolbars);
1084 myIsToolbarsModified = false;
1085 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1086 aResMgr->remove(ToolbarsSection);