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());
212 //******************************************************
213 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
215 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
218 //******************************************************
219 void SHAPERGUI::viewManagers(QStringList& theList) const
221 theList.append(OCCViewer_Viewer::Type());
224 //******************************************************
225 // We can not create selector in this method because it can be called when
226 // SHAPER module is not active. Take into account that creation of our selector
227 // leads to switching OFF all other selectors
228 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
230 // // if there are created viewer managers, we should try to create viewer
231 // // selector and initialize viewer with it. It sets interactive contect to the
232 // // proxy viewer. If study is opened, CAM application calls this method before the open()
234 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
235 // // we need to connect to the viewer before it. Here,
236 // // it seems the most appropriate place for this
237 // // according to SALOME architecture.
238 // if (!mySelector) {
239 // ViewManagerList OCCViewManagers;
240 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
241 // if (OCCViewManagers.size() > 0) {
242 // mySelector = createSelector(OCCViewManagers.first());
245 // LightApp_Module::connectToStudy(theStudy);
248 //******************************************************
249 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
251 bool isDone = LightApp_Module::activateModule(theStudy);
252 loadToolbarsConfig();
254 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
255 aDataModel->initRootObject();
261 QObject* aObj = myWorkshop->objectBrowser()->parent();
262 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
264 QAction* aViewAct = aObjDoc->toggleViewAction();
265 aViewAct->setEnabled(true);
266 myWorkshop->objectBrowser()->setVisible(true);
267 aObjDoc->setVisible(true);
268 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
271 if (!myInspectionPanel) {
272 myInspectionPanel = myWorkshop->inspectionPanel();
273 QAction* aViewAct = myInspectionPanel->toggleViewAction();
274 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
276 myInspectionPanel->toggleViewAction()->setEnabled(true);
279 ViewManagerList OCCViewManagers;
280 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
281 if (OCCViewManagers.size() > 0) {
282 mySelector = createSelector(OCCViewManagers.first());
285 // it should be pefromed after the selector creation in order to have AISContext
286 myWorkshop->activateModule();
287 //action(myEraseAll)->setEnabled(false);
290 myWorkshop->objectBrowser()->rebuildDataTree();
291 myWorkshop->updateCommandStatus();
295 myWorkshop->updateCommandStatus();
297 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
298 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
299 myIsEditEnabled = getApp()->isEditEnabled();
300 getApp()->setEditEnabled(false);
302 // this following row is caused by #187 bug.
303 // SALOME saves the dock widget positions before deactivateModule() and
304 // load it after the module activation. So, if the panel is visible before
305 // deactivate, it becomes visible after activate.
306 // In order to avoid the visible property panel, the widget position save is
307 // switch off in this module
308 aResMgr->setValue("Study", "store_positions", false);
310 // Synchronize displayed objects
311 Handle(AIS_InteractiveContext) aContext;
312 if (mySelector && mySelector->viewer())
313 aContext = mySelector->viewer()->getAISContext();
315 if (!aContext.IsNull()) {
316 XGUI_Displayer* aDisp = myWorkshop->displayer();
317 QObjectPtrList aObjList = aDisp->displayedObjects();
319 AIS_ListOfInteractive aList;
320 aContext->DisplayedObjects(aList);
321 AIS_ListIteratorOfListOfInteractive aLIt;
322 Handle(AIS_InteractiveObject) anAISIO;
323 foreach (ObjectPtr aObj, aObjList) {
324 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
325 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
327 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
328 anAISIO = aLIt.Value();
329 if (anAISIO.get() == aAIS.get()) {
335 aObj->setDisplayed(false);
336 //aDisp->erase(aObj, false);
339 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
341 myProxyViewer->activateViewer(true);
343 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
344 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
345 this, SLOT(onScriptLoaded()));
347 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
348 getApp(), SLOT(onSaveDoc()));
349 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
350 getApp(), SLOT(onSaveAsDoc()));
352 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
353 this, SLOT(onSaveDocByShaper()));
354 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
355 this, SLOT(onSaveAsDocByShaper()));
360 //******************************************************
361 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
363 saveToolbarsConfig();
365 myProxyViewer->activateViewer(false);
369 myWorkshop->deactivateModule();
371 QObject* aObj = myWorkshop->objectBrowser()->parent();
372 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
374 aObjDoc->setVisible(false);
375 myWorkshop->objectBrowser()->setVisible(false);
376 QAction* aViewAct = aObjDoc->toggleViewAction();
377 aViewAct->setEnabled(false);
380 myIsInspectionVisible = myInspectionPanel->isVisible();
381 myInspectionPanel->hide();
382 QAction* aViewAct = myInspectionPanel->toggleViewAction();
383 aViewAct->setEnabled(false);
385 // the active operation should be stopped for the next activation.
386 // There should not be active operation and visualized preview.
387 // Abort operation should be performed before the selection's remove
388 // because the displayed objects should be removed from the viewer, but
389 // the AIS context is obtained from the selector.
390 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
391 while (anOperation) {
392 anOperation->abort();
393 anOperation = myWorkshop->operationMgr()->currentOperation();
395 // Delete selector because it has to be redefined on next activation
397 myProxyViewer->setSelector(0);
402 myWorkshop->hidePanel(myWorkshop->facesPanel());
403 //myWorkshop->contextMenuMgr()->disconnectViewer();
405 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
406 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
407 getApp()->setEditEnabled(myIsEditEnabled);
409 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
410 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
411 this, SLOT(onScriptLoaded()));
413 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
414 this, SLOT(onSaveDocByShaper()));
415 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
416 this, SLOT(onSaveAsDocByShaper()));
418 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
419 getApp(), SLOT(onSaveDoc()));
420 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
421 getApp(), SLOT(onSaveAsDoc()));
423 return LightApp_Module::deactivateModule(theStudy);
426 //******************************************************
427 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
430 mySelector = createSelector(theMgr);
431 myWorkshop->selectionActivate()->updateSelectionFilters();
432 myWorkshop->selectionActivate()->updateSelectionModes();
433 myWorkshop->synchronizeViewer();
437 //******************************************************
438 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
441 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
442 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
443 if (mySelector->viewer() == aViewer) {
444 XGUI_Displayer* aDisp = myWorkshop->displayer();
445 QObjectPtrList aObjects = aDisp->displayedObjects();
446 foreach(ObjectPtr aObj, aObjects)
447 aObj->setDisplayed(false);
448 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
449 myProxyViewer->setSelector(0);
453 myWorkshop->module()->clearViewer();
459 //******************************************************
460 QtxPopupMgr* SHAPERGUI::popupMgr()
463 myPopupMgr = new QtxPopupMgr( 0, this );
467 //******************************************************
468 void SHAPERGUI::onDefaultPreferences()
470 // reset main resources
471 ModuleBase_Preferences::resetResourcePreferences(preferences());
472 // reset plugin's resources
473 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
475 myWorkshop->displayer()->redisplayObjects();
478 //******************************************************
479 void SHAPERGUI::onScriptLoaded()
481 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
482 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
483 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
484 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
485 // it manually (because this method of application is protected)
486 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
491 //******************************************************
492 void SHAPERGUI::onSaveDocByShaper()
494 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
497 getApp()->onSaveDoc();
500 //******************************************************
501 void SHAPERGUI::onSaveAsDocByShaper()
503 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
506 getApp()->onSaveAsDoc();
509 //******************************************************
510 void SHAPERGUI::onUpdateCommandStatus()
512 getApp()->updateActions();
515 //******************************************************
516 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
518 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
519 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
520 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
521 getApp()->selectionMgr());
522 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
523 aViewer->setUseLocalSelection(true);
525 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
526 QList<SUIT_Selector*> aList;
527 aMgr->selectors(aList);
528 foreach(SUIT_Selector* aSel, aList)
530 aSel->setEnabled(aSel == aSelector);
532 myProxyViewer->setSelector(aSelector);
538 //******************************************************
539 CAM_DataModel* SHAPERGUI::createDataModel()
541 return new SHAPERGUI_DataModel(this);
544 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
545 const bool isAddSeparator)
547 return addFeature(theWBName,
551 //Issue #650: in the SALOME mode the tooltip should be same as text
560 //******************************************************
561 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
562 const QString& theId, const QString& theTitle, const QString& theTip,
563 const QIcon& theIcon, const QKeySequence& theKeys,
564 bool isCheckable, const bool isAddSeparator,
565 const QString& theStatusTip)
567 static QString aLastTool = "";
569 if (aLastTool.isEmpty())
570 aLastTool = theWBName;
571 else if (theWBName != aLastTool) {
572 aLastTool = theWBName;
574 desktop()->addToolBarBreak();
580 int aId = getNextCommandId();
581 myActionsList.append(aId);
582 SUIT_Desktop* aDesk = application()->desktop();
584 for (int i = 0; i < theKeys.count(); i++)
586 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
588 aAction->setStatusTip(theStatusTip);
590 aAction->setData(theId);
592 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
593 int aItemId = createMenu(aId, aWBMenu);
595 createMenu(separator(), aWBMenu);
597 int aWBTool = createTool(theTBName, theTBName);
598 int aToolId = createTool(aId, aWBTool);
599 registerCommandToolbar(theTBName, aId);
600 if (isAddSeparator) {
601 createTool(separator(), aWBTool);
602 registerCommandToolbar(theTBName, -1);
607 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
609 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
612 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
613 const ActionInfo& theInfo,
614 const QList<QAction*>& theNestedActions)
616 SUIT_Desktop* aDesk = application()->desktop();
617 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
618 anAction->setData(theInfo.id);
619 anAction->setCheckable(theInfo.checkable);
620 anAction->setChecked(theInfo.checked);
621 anAction->setEnabled(theInfo.enabled);
622 anAction->setVisible(theInfo.visible);
623 anAction->setIcon(theInfo.icon);
624 anAction->setText(theInfo.text);
625 anAction->setToolTip(theInfo.toolTip);
626 anAction->setShortcut(theInfo.shortcut);
627 anAction->setFont(theInfo.font);
629 int aWBMenu = createMenu(theWBName, -1, -1, 30);
630 int aItemId = createMenu(anAction, aWBMenu);
631 myActionsList.append(aItemId);
632 createMenu(separator(), aWBMenu); /// nested action is always separated of others
634 int aWBTool = createTool(theWBName, theWBName);
635 int aToolId = createTool(anAction, aWBTool);
636 registerCommandToolbar(theWBName, aItemId);
637 createTool(separator(), aWBTool); /// nested action is always separated of others
638 registerCommandToolbar(theWBName, -1);
644 //******************************************************
645 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
646 const QString& theTip, const QIcon& theIcon,
647 const QKeySequence& theKeys, bool isCheckable,
648 const char* theMenuSourceText, const int theMenuPosition)
650 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
652 int aId = getNextCommandId();
653 myActionsList.append(aId);
654 SUIT_Desktop* aDesk = application()->desktop();
656 for (int i = 0; i < theKeys.count(); i++)
658 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
660 aAction->setStatusTip(theTip);
661 aAction->setData(theId);
662 createMenu(aId, aMenu, theMenuPosition);
666 //******************************************************
667 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
669 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
670 createMenu(separator(), aMenu, -1, theMenuPosition);
673 //******************************************************
674 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
679 SUIT_Desktop* aDesktop = application()->desktop();
683 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
687 aToolMgr->append( theAction, theToolBarTitle );
691 //******************************************************
692 QList<QAction*> SHAPERGUI::commandList() const
694 QList<QAction*> aActions;
695 foreach (int aId, myActionsList) {
696 QAction* aCmd = action(aId);
698 aActions.append(aCmd);
704 //******************************************************
705 QMainWindow* SHAPERGUI::desktop() const
707 return application()->desktop();
710 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
711 const std::shared_ptr<Config_FeatureMessage>& theMessage)
713 myFeaturesInfo.insert(theFeatureId, theMessage);
716 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
718 std::shared_ptr<Config_FeatureMessage> aMessage;
719 if (myFeaturesInfo.contains(theFeatureId))
720 aMessage = myFeaturesInfo[theFeatureId];
724 //******************************************************
725 void SHAPERGUI::selectionChanged()
727 LightApp_Module::selectionChanged();
728 myWorkshop->salomeViewerSelectionChanged();
731 //******************************************************
732 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
734 myWorkshop->contextMenuMgr()->updateViewerMenu();
735 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
736 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
740 //******************************************************
741 void SHAPERGUI::createPreferences()
743 LightApp_Preferences* pref = preferences();
746 ModuleBase_Preferences::updateConfigByResources();
747 QString aModName = moduleName();
749 QtxPreferenceItem* item = pref->findItem(aModName, true );
750 if ( item && (!item->isEmpty() )) {
751 item->parentItem()->removeItem(item);
755 int catId = pref->addPreference(aModName, -1 );
758 SHAPERGUI_PrefMgr aMgr(pref, aModName);
759 ModuleBase_Preferences::createEditContent(&aMgr, catId);
761 int viewTab = pref->addItem(tr("Viewer"), catId);
762 // Create other parameters group in viewer tab
763 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
764 pref->setItemProperty("columns", 3, otherGroup);
765 pref->addItem(tr("Faces"), otherGroup,
766 SUIT_PreferenceMgr::Bool,
767 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
768 pref->addItem(tr("Edges"), otherGroup,
769 SUIT_PreferenceMgr::Bool,
770 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
771 pref->addItem(tr("Vertices"), otherGroup,
772 SUIT_PreferenceMgr::Bool,
773 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
775 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
776 pref->setItemProperty("columns", 2, sensitivityGroup);
777 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
778 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
779 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
780 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
784 //******************************************************
785 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
787 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
788 QString aVal = aResMgr->stringValue(theSection, theParam);
789 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
790 theParam.toStdString());
791 std::string aValue = aVal.toStdString();
792 if (aValue.empty()) {
793 aValue = aProp->defaultValue();
794 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
796 LightApp_Preferences* pref = preferences();
800 aProp->setValue(aValue);
802 myWorkshop->displayer()->redisplayObjects();
805 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
807 application()->putInfo(theInfo, theMSecs);
810 bool SHAPERGUI::abortAllOperations()
812 return workshop()->operationMgr()->abortAllOperations();
815 void SHAPERGUI::createFeatureActions()
817 myWorkshop->menuMgr()->createFeatureActions();
820 void SHAPERGUI::onWhatIs(bool isToggled)
822 if (sender() == myWhatIsAction) {
823 QAction* aViewAct = myInspectionPanel->toggleViewAction();
824 aViewAct->blockSignals(true);
825 aViewAct->setChecked(isToggled);
826 aViewAct->blockSignals(false);
827 myInspectionPanel->setVisible(isToggled);
830 myWhatIsAction->blockSignals(true);
831 myWhatIsAction->setChecked(isToggled);
832 myWhatIsAction->blockSignals(false);
833 myInspectionPanel->setVisible(isToggled);
837 void SHAPERGUI::updateModuleVisibilityState()
839 LightApp_Module::updateModuleVisibilityState();
840 onWhatIs(myIsInspectionVisible);
843 void SHAPERGUI::onEditToolbars()
845 SHAPERGUI_ToolbarsDlg aDlg(this);
846 if (aDlg.exec() == QDialog::Accepted) {
850 updateToolbars(aDlg.result());
854 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
856 if (!myToolbars.contains(theToolName))
857 myToolbars[theToolName] = QList<int>();
858 myToolbars[theToolName].append(theCommandId);
861 int SHAPERGUI::getNextCommandId() const
863 QtxActionMenuMgr* aMenuMgr = menuMgr();
864 QIntList aIds = aMenuMgr->idList();
865 int aId = aIds.count();
866 while (action(aId) || myActionsList.contains(aId))
871 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
873 // Store default toolbars
874 if (myDefaultToolbars.size() == 0)
875 myDefaultToolbars = myToolbars;
877 QtxActionToolMgr* aMgr = toolMgr();
878 QStringList aToolbars = theNewToolbars.keys();
879 QIntList aCommands, aOldCmd;
883 foreach(QString aName, aToolbars) {
884 aCommands = theNewToolbars[aName];
885 // Find or create toolbar
886 if (aMgr->hasToolBar(aName)) {
887 aToolbarId = aMgr->find(aMgr->toolBar(aName));
888 aOldCmd = myToolbars[aName];
891 aToolbarId = aMgr->createToolBar(aName);
894 foreach(int aCmd, aCommands) {
897 aAction = separator();
899 aAction = action(aCmd);
900 aActionId = aMgr->actionId(aAction);
901 if (aActionId == -1) {
903 aMgr->insert(aAction, aToolbarId, aPos);
906 // Change position of action
907 if (aMgr->index(aActionId, aToolbarId) != aPos) {
908 if (aMgr->containsAction(aActionId, aToolbarId))
909 aMgr->remove(aActionId, aToolbarId);
910 aMgr->insert(aActionId, aToolbarId, aPos);
913 aOldCmd.removeAll(aCmd);
916 // remove extra actions
917 foreach(int aCmd, aOldCmd) {
918 aAction = action(aCmd);
919 aActionId = aMgr->actionId(aAction);
920 aMgr->remove(aActionId, aToolbarId);
922 myToolbars.remove(aName);
924 // Remove extra toolbars
925 aToolbars = myToolbars.keys();
926 foreach(QString aName, aToolbars) {
927 aMgr->removeToolBar(aName);
929 // Set new toolbars structure
930 myToolbars = theNewToolbars;
931 myIsToolbarsModified = true;
934 void SHAPERGUI::saveToolbarsConfig()
936 if (!myIsToolbarsModified)
938 // Save toolbars config into map
939 QMap<QString, QStringList> aToolbarsConfig;
940 QtxActionToolMgr* aMgr = toolMgr();
941 QStringList aToolbars = myToolbars.keys();
942 QIntList aActionsIds;
943 foreach(QString aName, aToolbars) {
944 aActionsIds = myToolbars[aName];
945 QStringList aContent;
946 foreach(int aId, aActionsIds) {
950 aContent.append(action(aId)->data().toString());
952 aToolbarsConfig[aName] = aContent;
954 // Store the config into resources
955 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
956 QStringList aNames = aToolbarsConfig.keys();
958 foreach(QString aToolbar, aNames) {
959 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
961 // Remove obsolete parameters from resources
962 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
963 foreach(QString aName, aOldParams) {
964 if (!aToolbars.contains(aName))
965 aResMgr->remove(ToolbarsSection, aName);
967 // Store current list of free commands
968 QIntList aFreeCommands = getFreeCommands();
969 QStringList aFreeList;
970 foreach(int aId, aFreeCommands) {
971 aFreeList.append(action(aId)->data().toString());
973 if (aFreeList.size() > 0)
974 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
976 myIsToolbarsModified = false;
979 void SHAPERGUI::loadToolbarsConfig()
981 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
982 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
983 if (aToolbarNames.size() == 0)
986 // Create commands map
987 QMap<QString, int> aCommandsMap;
989 foreach(int aId, myActionsList) {
990 aCmdIdStr = action(aId)->data().toString();
991 aCommandsMap[aCmdIdStr] = aId;
994 // Create new toolbars structure
995 QMap<QString, QIntList> aToolbars;
996 QStringList aCommands;
997 QIntList aKnownCommands;
998 QList<QAction*> aActions;
999 foreach(QString aName, aToolbarNames) {
1000 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1001 if (aName == FreeCommandsParam) {
1002 // The value is a list of free commands
1003 foreach(QString aCommand, aCommands) {
1004 aKnownCommands.append(aCommandsMap[aCommand]);
1008 aToolbars[aName] = QIntList();
1009 if (aCommands.size() > 0) {
1010 foreach(QString aCommand, aCommands) {
1011 if (aCommand.isEmpty())
1012 aToolbars[aName].append(-1);
1013 else if (aCommandsMap.contains(aCommand)) {
1014 int aId = aCommandsMap[aCommand];
1015 aToolbars[aName].append(aId);
1016 aKnownCommands.append(aId);
1022 // Find new and obsolete commands
1023 QIntList aNewCommands = myActionsList;
1024 foreach(int aId, myActionsList) {
1025 if (aKnownCommands.contains(aId)) {
1026 aKnownCommands.removeAll(aId);
1027 aNewCommands.removeAll(aId);
1030 if (aNewCommands.size() > 0) {
1031 // Add new commands to toolbars structure
1032 QStringList aKeys = myToolbars.keys();
1033 foreach(int aNewId, aNewCommands) {
1034 foreach(QString aName, aKeys) {
1035 if (myToolbars[aName].contains(aNewId)) {
1036 if (!aToolbars.contains(aName)) {
1037 aToolbars[aName] = QIntList();
1039 aToolbars[aName].append(aNewId);
1044 if (aKnownCommands.size() > 0) {
1045 // Remove obsolete commands from the toolbars structure
1046 QStringList aKeys = aToolbars.keys();
1047 foreach(int aOldId, aKnownCommands) {
1048 foreach(QString aName, aKeys) {
1049 if (aToolbars[aName].contains(aOldId)) {
1050 aToolbars[aName].removeAll(aOldId);
1051 if (aToolbars[aName].size() == 0)
1052 aToolbars.remove(aName);
1057 updateToolbars(aToolbars);
1058 myIsToolbarsModified = false;
1062 QIntList SHAPERGUI::getFreeCommands() const
1064 QIntList aFreeCommands;
1065 QtxActionToolMgr* aMgr = toolMgr();
1068 QMap<QString, QIntList>::const_iterator aIt;
1069 QIntList aShaperActions = shaperActions();
1070 foreach(int aCmd, aShaperActions) {
1071 anAction = action(aCmd);
1072 aId = aMgr->actionId(anAction);
1073 if (!aMgr->containsAction(aId))
1074 aFreeCommands.append(aCmd);
1076 return aFreeCommands;
1079 void SHAPERGUI::resetToolbars()
1081 if (!myDefaultToolbars.isEmpty())
1082 updateToolbars(myDefaultToolbars);
1083 myIsToolbarsModified = false;
1084 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1085 aResMgr->remove(ToolbarsSection);