1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SHAPERGUI.h"
22 #include "SHAPERGUI_DataModel.h"
23 #include "SHAPERGUI_OCCSelector.h"
24 #include "SHAPERGUI_NestedButton.h"
25 #include "SHAPERGUI_ToolbarsMgr.h"
27 #include <XGUI_Workshop.h>
28 #include <XGUI_PropertyPanel.h>
29 #include <XGUI_ContextMenuMgr.h>
30 #include <XGUI_ObjectsBrowser.h>
31 #include <XGUI_OperationMgr.h>
32 #include <XGUI_Displayer.h>
33 #include <XGUI_MenuMgr.h>
34 #include <XGUI_FacesPanel.h>
35 #include <XGUI_SelectionActivate.h>
36 #include <XGUI_InspectionPanel.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>
47 #include <OCCViewer_ViewModel.h>
49 #include <SUIT_Selector.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ViewManager.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_DataBrowser.h>
55 #include <QtxPopupMgr.h>
56 #include <QtxActionMenuMgr.h>
57 #include <QtxActionToolMgr.h>
58 #include <QtxResourceMgr.h>
60 #include <Config_PropManager.h>
61 #include <Config_ModuleReader.h>
63 #include <AIS_ListOfInteractive.hxx>
64 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <QDockWidget>
72 #define SALOME_PATCH_FOR_CTRL_WHEEL
75 SHAPERGUI_EXPORT CAM_Module* createModule()
77 return new SHAPERGUI();
80 SHAPERGUI_EXPORT char* getModuleVersion()
87 static const QString ToolbarsSection("SHAPER_Toolbars");
88 static const QString FreeCommandsParam("OutOFToolbars");
92 * Class for preferences management
94 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
98 /// \param theMgr preferences manager of SALOME
99 /// \param theModName name of the module
100 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
101 myMgr(theMgr), myModName(theModName) {}
103 virtual int addPreference(const QString& theLbl, int pId,
104 SUIT_PreferenceMgr::PrefItemType theType,
105 const QString& theSection, const QString& theName )
107 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
110 virtual void setItemProperty(const QString& thePropName,
111 const QVariant& theValue,
112 const int theId = -1)
114 myMgr->setItemProperty(thePropName, theValue, theId);
118 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
121 LightApp_Preferences* myMgr;
128 //******************************************************
129 SHAPERGUI::SHAPERGUI()
130 : LightApp_Module("SHAPER"),
131 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
132 myInspectionPanel(0), myIsToolbarsModified(false)
134 myWorkshop = new XGUI_Workshop(this);
135 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
136 this, SLOT(onUpdateCommandStatus()));
138 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
140 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
141 ModuleBase_Preferences::loadCustomProps();
144 //******************************************************
145 SHAPERGUI::~SHAPERGUI()
148 delete myProxyViewer;
151 //******************************************************
152 void SHAPERGUI::initialize(CAM_Application* theApp)
154 LightApp_Module::initialize(theApp);
156 myWorkshop->startApplication();
157 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
160 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
163 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
164 int aSubMenu = createMenu(tr("Information"), aMenu);
166 int aId = getNextCommandId();
167 myActionsList.append(aId);
168 SUIT_Desktop* aDesk = application()->desktop();
169 QString aTip = tr("Show inspection window");
170 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
171 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
172 myWhatIsAction->setStatusTip(aTip);
173 myWhatIsAction->setData("INSPECTION_CMD");
174 createMenu(aId, aSubMenu, 0);
176 QString aToolName = tr("Inspection tool");
177 int aTool = createTool(aToolName);
178 int aToolId = createTool(myWhatIsAction, aTool);
179 registerCommandToolbar(aToolName, aId);
181 // Define Edit toolbars command
182 aId = getNextCommandId();
183 //myActionsList.append(aId); Do not use it for editing of toolbars
184 aTip = tr("Edit toolbars of the module");
185 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
186 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
187 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
188 int aEditItem = createMenu(aId, aEditMenu);
191 //******************************************************
192 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
194 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
197 //******************************************************
198 void SHAPERGUI::viewManagers(QStringList& theList) const
200 theList.append(OCCViewer_Viewer::Type());
203 //******************************************************
204 // We can not create selector in this method because it can be called when
205 // SHAPER module is not active. Take into account that creation of our selector
206 // leads to switching OFF all other selectors
207 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
209 // // if there are created viewer managers, we should try to create viewer
210 // // selector and initialize viewer with it. It sets interactive contect to the
211 // // proxy viewer. If study is opened, CAM application calls this method before the open()
213 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
214 // // we need to connect to the viewer before it. Here,
215 // // it seems the most appropriate place for this
216 // // according to SALOME architecture.
217 // if (!mySelector) {
218 // ViewManagerList OCCViewManagers;
219 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
220 // if (OCCViewManagers.size() > 0) {
221 // mySelector = createSelector(OCCViewManagers.first());
224 // LightApp_Module::connectToStudy(theStudy);
227 //******************************************************
228 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
230 bool isDone = LightApp_Module::activateModule(theStudy);
231 loadToolbarsConfig();
233 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
234 aDataModel->initRootObject();
240 QObject* aObj = myWorkshop->objectBrowser()->parent();
241 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
243 QAction* aViewAct = aObjDoc->toggleViewAction();
244 aViewAct->setEnabled(true);
245 myWorkshop->objectBrowser()->setVisible(true);
246 aObjDoc->setVisible(true);
247 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
250 if (!myInspectionPanel) {
251 myInspectionPanel = myWorkshop->inspectionPanel();
252 QAction* aViewAct = myInspectionPanel->toggleViewAction();
253 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
255 myInspectionPanel->toggleViewAction()->setEnabled(true);
258 ViewManagerList OCCViewManagers;
259 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
260 if (OCCViewManagers.size() > 0) {
261 mySelector = createSelector(OCCViewManagers.first());
264 // it should be pefromed after the selector creation in order to have AISContext
265 myWorkshop->activateModule();
266 //action(myEraseAll)->setEnabled(false);
269 myWorkshop->objectBrowser()->rebuildDataTree();
270 myWorkshop->updateCommandStatus();
274 myWorkshop->updateCommandStatus();
276 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
277 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
278 myIsEditEnabled = getApp()->isEditEnabled();
279 getApp()->setEditEnabled(false);
281 // this following row is caused by #187 bug.
282 // SALOME saves the dock widget positions before deactivateModule() and
283 // load it after the module activation. So, if the panel is visible before
284 // deactivate, it becomes visible after activate.
285 // In order to avoid the visible property panel, the widget position save is
286 // switch off in this module
287 aResMgr->setValue("Study", "store_positions", false);
289 // Synchronize displayed objects
290 Handle(AIS_InteractiveContext) aContext;
291 if (mySelector && mySelector->viewer())
292 aContext = mySelector->viewer()->getAISContext();
294 if (!aContext.IsNull()) {
295 XGUI_Displayer* aDisp = myWorkshop->displayer();
296 QObjectPtrList aObjList = aDisp->displayedObjects();
298 AIS_ListOfInteractive aList;
299 aContext->DisplayedObjects(aList);
300 AIS_ListIteratorOfListOfInteractive aLIt;
301 Handle(AIS_InteractiveObject) anAISIO;
302 foreach (ObjectPtr aObj, aObjList) {
303 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
304 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
306 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
307 anAISIO = aLIt.Value();
308 if (anAISIO.get() == aAIS.get()) {
314 aObj->setDisplayed(false);
315 //aDisp->erase(aObj, false);
318 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
320 myProxyViewer->activateViewer(true);
322 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
323 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
324 this, SLOT(onScriptLoaded()));
326 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
327 getApp(), SLOT(onSaveDoc()));
328 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
329 getApp(), SLOT(onSaveAsDoc()));
331 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
332 this, SLOT(onSaveDocByShaper()));
333 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
334 this, SLOT(onSaveAsDocByShaper()));
339 //******************************************************
340 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
342 saveToolbarsConfig();
344 myProxyViewer->activateViewer(false);
348 myWorkshop->deactivateModule();
350 QObject* aObj = myWorkshop->objectBrowser()->parent();
351 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
353 aObjDoc->setVisible(false);
354 myWorkshop->objectBrowser()->setVisible(false);
355 QAction* aViewAct = aObjDoc->toggleViewAction();
356 aViewAct->setEnabled(false);
359 myIsInspectionVisible = myInspectionPanel->isVisible();
360 myInspectionPanel->hide();
361 QAction* aViewAct = myInspectionPanel->toggleViewAction();
362 aViewAct->setEnabled(false);
364 // the active operation should be stopped for the next activation.
365 // There should not be active operation and visualized preview.
366 // Abort operation should be performed before the selection's remove
367 // because the displayed objects should be removed from the viewer, but
368 // the AIS context is obtained from the selector.
369 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
370 while (anOperation) {
371 anOperation->abort();
372 anOperation = myWorkshop->operationMgr()->currentOperation();
374 // Delete selector because it has to be redefined on next activation
376 myProxyViewer->setSelector(0);
381 myWorkshop->hidePanel(myWorkshop->facesPanel());
382 //myWorkshop->contextMenuMgr()->disconnectViewer();
384 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
385 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
386 getApp()->setEditEnabled(myIsEditEnabled);
388 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
389 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
390 this, SLOT(onScriptLoaded()));
392 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
393 this, SLOT(onSaveDocByShaper()));
394 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
395 this, SLOT(onSaveAsDocByShaper()));
397 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
398 getApp(), SLOT(onSaveDoc()));
399 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
400 getApp(), SLOT(onSaveAsDoc()));
402 return LightApp_Module::deactivateModule(theStudy);
405 //******************************************************
406 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
409 mySelector = createSelector(theMgr);
410 myWorkshop->selectionActivate()->updateSelectionFilters();
411 myWorkshop->selectionActivate()->updateSelectionModes();
412 myWorkshop->synchronizeViewer();
416 //******************************************************
417 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
420 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
421 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
422 if (mySelector->viewer() == aViewer) {
423 XGUI_Displayer* aDisp = myWorkshop->displayer();
424 QObjectPtrList aObjects = aDisp->displayedObjects();
425 foreach(ObjectPtr aObj, aObjects)
426 aObj->setDisplayed(false);
427 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
428 myProxyViewer->setSelector(0);
432 myWorkshop->module()->clearViewer();
438 //******************************************************
439 QtxPopupMgr* SHAPERGUI::popupMgr()
442 myPopupMgr = new QtxPopupMgr( 0, this );
446 //******************************************************
447 void SHAPERGUI::onDefaultPreferences()
449 // reset main resources
450 ModuleBase_Preferences::resetResourcePreferences(preferences());
451 // reset plugin's resources
452 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
454 myWorkshop->displayer()->redisplayObjects();
457 //******************************************************
458 void SHAPERGUI::onScriptLoaded()
460 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
461 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
462 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
463 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
464 // it manually (because this method of application is protected)
465 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
470 //******************************************************
471 void SHAPERGUI::onSaveDocByShaper()
473 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
476 getApp()->onSaveDoc();
479 //******************************************************
480 void SHAPERGUI::onSaveAsDocByShaper()
482 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
485 getApp()->onSaveAsDoc();
488 //******************************************************
489 void SHAPERGUI::onUpdateCommandStatus()
491 getApp()->updateActions();
494 //******************************************************
495 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
497 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
498 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
499 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
500 getApp()->selectionMgr());
501 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
502 aViewer->setUseLocalSelection(true);
504 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
505 QList<SUIT_Selector*> aList;
506 aMgr->selectors(aList);
507 foreach(SUIT_Selector* aSel, aList)
509 aSel->setEnabled(aSel == aSelector);
511 myProxyViewer->setSelector(aSelector);
517 //******************************************************
518 CAM_DataModel* SHAPERGUI::createDataModel()
520 return new SHAPERGUI_DataModel(this);
523 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
524 const bool isAddSeparator)
526 return addFeature(theWBName,
530 //Issue #650: in the SALOME mode the tooltip should be same as text
539 //******************************************************
540 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
541 const QString& theId, const QString& theTitle, const QString& theTip,
542 const QIcon& theIcon, const QKeySequence& theKeys,
543 bool isCheckable, const bool isAddSeparator,
544 const QString& theStatusTip)
546 static QString aLastTool = "";
548 if (aLastTool.isEmpty())
549 aLastTool = theWBName;
550 else if (theWBName != aLastTool) {
551 aLastTool = theWBName;
553 desktop()->addToolBarBreak();
559 int aId = getNextCommandId();
560 myActionsList.append(aId);
561 SUIT_Desktop* aDesk = application()->desktop();
563 for (int i = 0; i < theKeys.count(); i++)
565 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
567 aAction->setStatusTip(theStatusTip);
569 aAction->setData(theId);
571 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
572 int aItemId = createMenu(aId, aWBMenu);
574 createMenu(separator(), aWBMenu);
576 int aWBTool = createTool(theTBName, theTBName);
577 int aToolId = createTool(aId, aWBTool);
578 registerCommandToolbar(theTBName, aId);
579 if (isAddSeparator) {
580 createTool(separator(), aWBTool);
581 registerCommandToolbar(theTBName, -1);
586 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
588 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
591 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
592 const ActionInfo& theInfo,
593 const QList<QAction*>& theNestedActions)
595 SUIT_Desktop* aDesk = application()->desktop();
596 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
597 anAction->setData(theInfo.id);
598 anAction->setCheckable(theInfo.checkable);
599 anAction->setChecked(theInfo.checked);
600 anAction->setEnabled(theInfo.enabled);
601 anAction->setVisible(theInfo.visible);
602 anAction->setIcon(theInfo.icon);
603 anAction->setText(theInfo.text);
604 anAction->setToolTip(theInfo.toolTip);
605 anAction->setShortcut(theInfo.shortcut);
606 anAction->setFont(theInfo.font);
608 int aWBMenu = createMenu(theWBName, -1, -1, 30);
609 int aItemId = createMenu(anAction, aWBMenu);
610 myActionsList.append(aItemId);
611 createMenu(separator(), aWBMenu); /// nested action is always separated of others
613 int aWBTool = createTool(theWBName, theWBName);
614 int aToolId = createTool(anAction, aWBTool);
615 registerCommandToolbar(theWBName, aItemId);
616 createTool(separator(), aWBTool); /// nested action is always separated of others
617 registerCommandToolbar(theWBName, -1);
623 //******************************************************
624 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
625 const QString& theTip, const QIcon& theIcon,
626 const QKeySequence& theKeys, bool isCheckable,
627 const char* theMenuSourceText, const int theMenuPosition)
629 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
631 int aId = getNextCommandId();
632 myActionsList.append(aId);
633 SUIT_Desktop* aDesk = application()->desktop();
635 for (int i = 0; i < theKeys.count(); i++)
637 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
639 aAction->setStatusTip(theTip);
640 aAction->setData(theId);
641 createMenu(aId, aMenu, theMenuPosition);
645 //******************************************************
646 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
648 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
649 createMenu(separator(), aMenu, -1, theMenuPosition);
652 //******************************************************
653 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
658 SUIT_Desktop* aDesktop = application()->desktop();
662 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
666 aToolMgr->append( theAction, theToolBarTitle );
670 //******************************************************
671 QList<QAction*> SHAPERGUI::commandList() const
673 QList<QAction*> aActions;
674 foreach (int aId, myActionsList) {
675 QAction* aCmd = action(aId);
677 aActions.append(aCmd);
683 //******************************************************
684 QMainWindow* SHAPERGUI::desktop() const
686 return application()->desktop();
689 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
690 const std::shared_ptr<Config_FeatureMessage>& theMessage)
692 myFeaturesInfo.insert(theFeatureId, theMessage);
695 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
697 std::shared_ptr<Config_FeatureMessage> aMessage;
698 if (myFeaturesInfo.contains(theFeatureId))
699 aMessage = myFeaturesInfo[theFeatureId];
703 //******************************************************
704 void SHAPERGUI::selectionChanged()
706 LightApp_Module::selectionChanged();
707 myWorkshop->salomeViewerSelectionChanged();
710 //******************************************************
711 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
713 myWorkshop->contextMenuMgr()->updateViewerMenu();
714 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
715 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
719 //******************************************************
720 void SHAPERGUI::createPreferences()
722 LightApp_Preferences* pref = preferences();
725 ModuleBase_Preferences::updateConfigByResources();
726 QString aModName = moduleName();
728 QtxPreferenceItem* item = pref->findItem(aModName, true );
729 if ( item && (!item->isEmpty() )) {
730 item->parentItem()->removeItem(item);
734 int catId = pref->addPreference(aModName, -1 );
737 SHAPERGUI_PrefMgr aMgr(pref, aModName);
738 ModuleBase_Preferences::createEditContent(&aMgr, catId);
740 int viewTab = pref->addItem(tr("Viewer"), catId);
741 // Create other parameters group in viewer tab
742 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
743 pref->setItemProperty("columns", 3, otherGroup);
744 pref->addItem(tr("Faces"), otherGroup,
745 SUIT_PreferenceMgr::Bool,
746 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
747 pref->addItem(tr("Edges"), otherGroup,
748 SUIT_PreferenceMgr::Bool,
749 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
750 pref->addItem(tr("Vertices"), otherGroup,
751 SUIT_PreferenceMgr::Bool,
752 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
754 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
755 pref->setItemProperty("columns", 2, sensitivityGroup);
756 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
757 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
758 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
759 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
763 //******************************************************
764 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
766 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
767 QString aVal = aResMgr->stringValue(theSection, theParam);
768 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
769 theParam.toStdString());
770 std::string aValue = aVal.toStdString();
771 if (aValue.empty()) {
772 aValue = aProp->defaultValue();
773 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
775 LightApp_Preferences* pref = preferences();
779 aProp->setValue(aValue);
781 myWorkshop->displayer()->redisplayObjects();
784 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
786 application()->putInfo(theInfo, theMSecs);
789 bool SHAPERGUI::abortAllOperations()
791 return workshop()->operationMgr()->abortAllOperations();
794 void SHAPERGUI::createFeatureActions()
796 myWorkshop->menuMgr()->createFeatureActions();
799 void SHAPERGUI::onWhatIs(bool isToggled)
801 if (sender() == myWhatIsAction) {
802 QAction* aViewAct = myInspectionPanel->toggleViewAction();
803 aViewAct->blockSignals(true);
804 aViewAct->setChecked(isToggled);
805 aViewAct->blockSignals(false);
806 myInspectionPanel->setVisible(isToggled);
809 myWhatIsAction->blockSignals(true);
810 myWhatIsAction->setChecked(isToggled);
811 myWhatIsAction->blockSignals(false);
812 myInspectionPanel->setVisible(isToggled);
816 void SHAPERGUI::updateModuleVisibilityState()
818 LightApp_Module::updateModuleVisibilityState();
819 onWhatIs(myIsInspectionVisible);
822 void SHAPERGUI::onEditToolbars()
824 SHAPERGUI_ToolbarsDlg aDlg(this);
825 if (aDlg.exec() == QDialog::Accepted) {
829 updateToolbars(aDlg.result());
833 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
835 if (!myToolbars.contains(theToolName))
836 myToolbars[theToolName] = QList<int>();
837 myToolbars[theToolName].append(theCommandId);
840 int SHAPERGUI::getNextCommandId() const
842 QtxActionMenuMgr* aMenuMgr = menuMgr();
843 QIntList aIds = aMenuMgr->idList();
844 int aId = aIds.count();
845 while (action(aId) || myActionsList.contains(aId))
850 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
852 // Store default toolbars
853 if (myDefaultToolbars.size() == 0)
854 myDefaultToolbars = myToolbars;
856 QtxActionToolMgr* aMgr = toolMgr();
857 QStringList aToolbars = theNewToolbars.keys();
858 QIntList aCommands, aOldCmd;
862 foreach(QString aName, aToolbars) {
863 aCommands = theNewToolbars[aName];
864 // Find or create toolbar
865 if (aMgr->hasToolBar(aName)) {
866 aToolbarId = aMgr->find(aMgr->toolBar(aName));
867 aOldCmd = myToolbars[aName];
870 aToolbarId = aMgr->createToolBar(aName);
873 foreach(int aCmd, aCommands) {
876 aAction = separator();
878 aAction = action(aCmd);
879 aActionId = aMgr->actionId(aAction);
880 if (aActionId == -1) {
882 aMgr->insert(aAction, aToolbarId, aPos);
885 // Change position of action
886 if (aMgr->index(aActionId, aToolbarId) != aPos) {
887 if (aMgr->containsAction(aActionId, aToolbarId))
888 aMgr->remove(aActionId, aToolbarId);
889 aMgr->insert(aActionId, aToolbarId, aPos);
892 aOldCmd.removeAll(aCmd);
895 // remove extra actions
896 foreach(int aCmd, aOldCmd) {
897 aAction = action(aCmd);
898 aActionId = aMgr->actionId(aAction);
899 aMgr->remove(aActionId, aToolbarId);
901 myToolbars.remove(aName);
903 // Remove extra toolbars
904 aToolbars = myToolbars.keys();
905 foreach(QString aName, aToolbars) {
906 aMgr->removeToolBar(aName);
908 // Set new toolbars structure
909 myToolbars = theNewToolbars;
910 myIsToolbarsModified = true;
913 void SHAPERGUI::saveToolbarsConfig()
915 if (!myIsToolbarsModified)
917 // Save toolbars config into map
918 QMap<QString, QStringList> aToolbarsConfig;
919 QtxActionToolMgr* aMgr = toolMgr();
920 QStringList aToolbars = myToolbars.keys();
921 QIntList aActionsIds;
922 foreach(QString aName, aToolbars) {
923 aActionsIds = myToolbars[aName];
924 QStringList aContent;
925 foreach(int aId, aActionsIds) {
929 aContent.append(action(aId)->data().toString());
931 aToolbarsConfig[aName] = aContent;
933 // Store the config into resources
934 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
935 QStringList aNames = aToolbarsConfig.keys();
937 foreach(QString aToolbar, aNames) {
938 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
940 // Remove obsolete parameters from resources
941 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
942 foreach(QString aName, aOldParams) {
943 if (!aToolbars.contains(aName))
944 aResMgr->remove(ToolbarsSection, aName);
946 // Store current list of free commands
947 QIntList aFreeCommands = getFreeCommands();
948 QStringList aFreeList;
949 foreach(int aId, aFreeCommands) {
950 aFreeList.append(action(aId)->data().toString());
952 if (aFreeList.size() > 0)
953 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
955 myIsToolbarsModified = false;
958 void SHAPERGUI::loadToolbarsConfig()
960 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
961 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
962 if (aToolbarNames.size() == 0)
965 // Create commands map
966 QMap<QString, int> aCommandsMap;
968 foreach(int aId, myActionsList) {
969 aCmdIdStr = action(aId)->data().toString();
970 aCommandsMap[aCmdIdStr] = aId;
973 // Create new toolbars structure
974 QMap<QString, QIntList> aToolbars;
975 QStringList aCommands;
976 QIntList aKnownCommands;
977 QList<QAction*> aActions;
978 foreach(QString aName, aToolbarNames) {
979 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
980 if (aName == FreeCommandsParam) {
981 // The value is a list of free commands
982 foreach(QString aCommand, aCommands) {
983 aKnownCommands.append(aCommandsMap[aCommand]);
987 aToolbars[aName] = QIntList();
988 if (aCommands.size() > 0) {
989 foreach(QString aCommand, aCommands) {
990 if (aCommand.isEmpty())
991 aToolbars[aName].append(-1);
992 else if (aCommandsMap.contains(aCommand)) {
993 int aId = aCommandsMap[aCommand];
994 aToolbars[aName].append(aId);
995 aKnownCommands.append(aId);
1001 // Find new and obsolete commands
1002 QIntList aNewCommands = myActionsList;
1003 foreach(int aId, myActionsList) {
1004 if (aKnownCommands.contains(aId)) {
1005 aKnownCommands.removeAll(aId);
1006 aNewCommands.removeAll(aId);
1009 if (aNewCommands.size() > 0) {
1010 // Add new commands to toolbars structure
1011 QStringList aKeys = myToolbars.keys();
1012 foreach(int aNewId, aNewCommands) {
1013 foreach(QString aName, aKeys) {
1014 if (myToolbars[aName].contains(aNewId)) {
1015 if (!aToolbars.contains(aName)) {
1016 aToolbars[aName] = QIntList();
1018 aToolbars[aName].append(aNewId);
1023 if (aKnownCommands.size() > 0) {
1024 // Remove obsolete commands from the toolbars structure
1025 QStringList aKeys = aToolbars.keys();
1026 foreach(int aOldId, aKnownCommands) {
1027 foreach(QString aName, aKeys) {
1028 if (aToolbars[aName].contains(aOldId)) {
1029 aToolbars[aName].removeAll(aOldId);
1030 if (aToolbars[aName].size() == 0)
1031 aToolbars.remove(aName);
1036 updateToolbars(aToolbars);
1037 myIsToolbarsModified = false;
1041 QIntList SHAPERGUI::getFreeCommands() const
1043 QIntList aFreeCommands;
1044 QtxActionToolMgr* aMgr = toolMgr();
1047 QMap<QString, QIntList>::const_iterator aIt;
1048 QIntList aShaperActions = shaperActions();
1049 foreach(int aCmd, aShaperActions) {
1050 anAction = action(aCmd);
1051 aId = aMgr->actionId(anAction);
1052 if (!aMgr->containsAction(aId))
1053 aFreeCommands.append(aCmd);
1055 return aFreeCommands;
1058 void SHAPERGUI::resetToolbars()
1060 if (!myDefaultToolbars.isEmpty())
1061 updateToolbars(myDefaultToolbars);
1062 myIsToolbarsModified = false;
1063 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1064 aResMgr->remove(ToolbarsSection);