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 * Class for preferences management
89 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
93 /// \param theMgr preferences manager of SALOME
94 /// \param theModName name of the module
95 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
96 myMgr(theMgr), myModName(theModName) {}
98 virtual int addPreference(const QString& theLbl, int pId,
99 SUIT_PreferenceMgr::PrefItemType theType,
100 const QString& theSection, const QString& theName )
102 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
105 virtual void setItemProperty(const QString& thePropName,
106 const QVariant& theValue,
107 const int theId = -1)
109 myMgr->setItemProperty(thePropName, theValue, theId);
113 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
116 LightApp_Preferences* myMgr;
123 //******************************************************
124 SHAPERGUI::SHAPERGUI()
125 : LightApp_Module("SHAPER"),
126 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
127 myInspectionPanel(0), myIsToolbarsModified(false)
129 myWorkshop = new XGUI_Workshop(this);
130 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
131 this, SLOT(onUpdateCommandStatus()));
133 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
135 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
136 ModuleBase_Preferences::loadCustomProps();
139 //******************************************************
140 SHAPERGUI::~SHAPERGUI()
143 delete myProxyViewer;
146 //******************************************************
147 void SHAPERGUI::initialize(CAM_Application* theApp)
149 LightApp_Module::initialize(theApp);
151 myWorkshop->startApplication();
152 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
155 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
158 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
159 int aSubMenu = createMenu(tr("Information"), aMenu);
161 int aId = getNextCommandId();
162 myActionsList.append(aId);
163 SUIT_Desktop* aDesk = application()->desktop();
164 QString aTip = tr("Show inspection window");
165 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
166 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
167 myWhatIsAction->setStatusTip(aTip);
168 myWhatIsAction->setData("INSPECTION_CMD");
169 createMenu(aId, aSubMenu, 0);
171 QString aToolName = tr("Inspection tool");
172 int aTool = createTool(aToolName);
173 int aToolId = createTool(myWhatIsAction, aTool);
174 registerCommandToolbar(aToolName, aId);
176 // Define Edit toolbars command
177 aId = getNextCommandId();
178 //myActionsList.append(aId); Do not use it for editing of toolbars
179 aTip = tr("Edit toolbars of the module");
180 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
181 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
182 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
183 int aEditItem = createMenu(aId, aEditMenu);
186 //******************************************************
187 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
189 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
192 //******************************************************
193 void SHAPERGUI::viewManagers(QStringList& theList) const
195 theList.append(OCCViewer_Viewer::Type());
198 //******************************************************
199 // We can not create selector in this method because it can be called when
200 // SHAPER module is not active. Take into account that creation of our selector
201 // leads to switching OFF all other selectors
202 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
204 // // if there are created viewer managers, we should try to create viewer
205 // // selector and initialize viewer with it. It sets interactive contect to the
206 // // proxy viewer. If study is opened, CAM application calls this method before the open()
208 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
209 // // we need to connect to the viewer before it. Here,
210 // // it seems the most appropriate place for this
211 // // according to SALOME architecture.
212 // if (!mySelector) {
213 // ViewManagerList OCCViewManagers;
214 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
215 // if (OCCViewManagers.size() > 0) {
216 // mySelector = createSelector(OCCViewManagers.first());
219 // LightApp_Module::connectToStudy(theStudy);
222 //******************************************************
223 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
225 bool isDone = LightApp_Module::activateModule(theStudy);
226 loadToolbarsConfig();
228 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
229 aDataModel->initRootObject();
235 QObject* aObj = myWorkshop->objectBrowser()->parent();
236 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
238 QAction* aViewAct = aObjDoc->toggleViewAction();
239 aViewAct->setEnabled(true);
240 myWorkshop->objectBrowser()->setVisible(true);
241 aObjDoc->setVisible(true);
242 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
245 if (!myInspectionPanel) {
246 myInspectionPanel = myWorkshop->inspectionPanel();
247 QAction* aViewAct = myInspectionPanel->toggleViewAction();
248 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
250 myInspectionPanel->toggleViewAction()->setEnabled(true);
253 ViewManagerList OCCViewManagers;
254 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
255 if (OCCViewManagers.size() > 0) {
256 mySelector = createSelector(OCCViewManagers.first());
259 // it should be pefromed after the selector creation in order to have AISContext
260 myWorkshop->activateModule();
261 //action(myEraseAll)->setEnabled(false);
264 myWorkshop->objectBrowser()->rebuildDataTree();
265 myWorkshop->updateCommandStatus();
269 myWorkshop->updateCommandStatus();
271 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
272 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
273 myIsEditEnabled = getApp()->isEditEnabled();
274 getApp()->setEditEnabled(false);
276 // this following row is caused by #187 bug.
277 // SALOME saves the dock widget positions before deactivateModule() and
278 // load it after the module activation. So, if the panel is visible before
279 // deactivate, it becomes visible after activate.
280 // In order to avoid the visible property panel, the widget position save is
281 // switch off in this module
282 aResMgr->setValue("Study", "store_positions", false);
284 // Synchronize displayed objects
285 Handle(AIS_InteractiveContext) aContext;
286 if (mySelector && mySelector->viewer())
287 aContext = mySelector->viewer()->getAISContext();
289 if (!aContext.IsNull()) {
290 XGUI_Displayer* aDisp = myWorkshop->displayer();
291 QObjectPtrList aObjList = aDisp->displayedObjects();
293 AIS_ListOfInteractive aList;
294 aContext->DisplayedObjects(aList);
295 AIS_ListIteratorOfListOfInteractive aLIt;
296 Handle(AIS_InteractiveObject) anAISIO;
297 foreach (ObjectPtr aObj, aObjList) {
298 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
299 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
301 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
302 anAISIO = aLIt.Value();
303 if (anAISIO.get() == aAIS.get()) {
309 aObj->setDisplayed(false);
310 //aDisp->erase(aObj, false);
313 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
315 myProxyViewer->activateViewer(true);
317 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
318 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
319 this, SLOT(onScriptLoaded()));
321 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
322 getApp(), SLOT(onSaveDoc()));
323 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
324 getApp(), SLOT(onSaveAsDoc()));
326 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
327 this, SLOT(onSaveDocByShaper()));
328 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
329 this, SLOT(onSaveAsDocByShaper()));
334 //******************************************************
335 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
337 saveToolbarsConfig();
339 myProxyViewer->activateViewer(false);
343 myWorkshop->deactivateModule();
345 QObject* aObj = myWorkshop->objectBrowser()->parent();
346 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
348 aObjDoc->setVisible(false);
349 myWorkshop->objectBrowser()->setVisible(false);
350 QAction* aViewAct = aObjDoc->toggleViewAction();
351 aViewAct->setEnabled(false);
354 myIsInspectionVisible = myInspectionPanel->isVisible();
355 myInspectionPanel->hide();
356 QAction* aViewAct = myInspectionPanel->toggleViewAction();
357 aViewAct->setEnabled(false);
359 // the active operation should be stopped for the next activation.
360 // There should not be active operation and visualized preview.
361 // Abort operation should be performed before the selection's remove
362 // because the displayed objects should be removed from the viewer, but
363 // the AIS context is obtained from the selector.
364 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
365 while (anOperation) {
366 anOperation->abort();
367 anOperation = myWorkshop->operationMgr()->currentOperation();
369 // Delete selector because it has to be redefined on next activation
371 myProxyViewer->setSelector(0);
376 myWorkshop->hidePanel(myWorkshop->facesPanel());
377 //myWorkshop->contextMenuMgr()->disconnectViewer();
379 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
380 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
381 getApp()->setEditEnabled(myIsEditEnabled);
383 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
384 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
385 this, SLOT(onScriptLoaded()));
387 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
388 this, SLOT(onSaveDocByShaper()));
389 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
390 this, SLOT(onSaveAsDocByShaper()));
392 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
393 getApp(), SLOT(onSaveDoc()));
394 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
395 getApp(), SLOT(onSaveAsDoc()));
397 return LightApp_Module::deactivateModule(theStudy);
400 //******************************************************
401 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
404 mySelector = createSelector(theMgr);
405 myWorkshop->selectionActivate()->updateSelectionFilters();
406 myWorkshop->selectionActivate()->updateSelectionModes();
407 myWorkshop->synchronizeViewer();
411 //******************************************************
412 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
415 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
416 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
417 if (mySelector->viewer() == aViewer) {
418 XGUI_Displayer* aDisp = myWorkshop->displayer();
419 QObjectPtrList aObjects = aDisp->displayedObjects();
420 foreach(ObjectPtr aObj, aObjects)
421 aObj->setDisplayed(false);
422 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
423 myProxyViewer->setSelector(0);
427 myWorkshop->module()->clearViewer();
433 //******************************************************
434 QtxPopupMgr* SHAPERGUI::popupMgr()
437 myPopupMgr = new QtxPopupMgr( 0, this );
441 //******************************************************
442 void SHAPERGUI::onDefaultPreferences()
444 // reset main resources
445 ModuleBase_Preferences::resetResourcePreferences(preferences());
446 // reset plugin's resources
447 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
449 myWorkshop->displayer()->redisplayObjects();
452 //******************************************************
453 void SHAPERGUI::onScriptLoaded()
455 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
456 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
457 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
458 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
459 // it manually (because this method of application is protected)
460 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
465 //******************************************************
466 void SHAPERGUI::onSaveDocByShaper()
468 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
471 getApp()->onSaveDoc();
474 //******************************************************
475 void SHAPERGUI::onSaveAsDocByShaper()
477 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
480 getApp()->onSaveAsDoc();
483 //******************************************************
484 void SHAPERGUI::onUpdateCommandStatus()
486 getApp()->updateActions();
489 //******************************************************
490 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
492 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
493 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
494 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
495 getApp()->selectionMgr());
496 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
497 aViewer->setUseLocalSelection(true);
499 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
500 QList<SUIT_Selector*> aList;
501 aMgr->selectors(aList);
502 foreach(SUIT_Selector* aSel, aList)
504 aSel->setEnabled(aSel == aSelector);
506 myProxyViewer->setSelector(aSelector);
512 //******************************************************
513 CAM_DataModel* SHAPERGUI::createDataModel()
515 return new SHAPERGUI_DataModel(this);
518 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
519 const bool isAddSeparator)
521 return addFeature(theWBName,
525 //Issue #650: in the SALOME mode the tooltip should be same as text
534 //******************************************************
535 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
536 const QString& theId, const QString& theTitle, const QString& theTip,
537 const QIcon& theIcon, const QKeySequence& theKeys,
538 bool isCheckable, const bool isAddSeparator,
539 const QString& theStatusTip)
541 static QString aLastTool = "";
543 if (aLastTool.isEmpty())
544 aLastTool = theWBName;
545 else if (theWBName != aLastTool) {
546 aLastTool = theWBName;
548 desktop()->addToolBarBreak();
554 int aId = getNextCommandId();
555 myActionsList.append(aId);
556 SUIT_Desktop* aDesk = application()->desktop();
558 for (int i = 0; i < theKeys.count(); i++)
560 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
562 aAction->setStatusTip(theStatusTip);
564 aAction->setData(theId);
566 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
567 int aItemId = createMenu(aId, aWBMenu);
569 createMenu(separator(), aWBMenu);
571 int aWBTool = createTool(theTBName, theTBName);
572 int aToolId = createTool(aId, aWBTool);
573 registerCommandToolbar(theTBName, aId);
574 if (isAddSeparator) {
575 createTool(separator(), aWBTool);
576 registerCommandToolbar(theTBName, -1);
581 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
583 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
586 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
587 const ActionInfo& theInfo,
588 const QList<QAction*>& theNestedActions)
590 SUIT_Desktop* aDesk = application()->desktop();
591 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
592 anAction->setData(theInfo.id);
593 anAction->setCheckable(theInfo.checkable);
594 anAction->setChecked(theInfo.checked);
595 anAction->setEnabled(theInfo.enabled);
596 anAction->setVisible(theInfo.visible);
597 anAction->setIcon(theInfo.icon);
598 anAction->setText(theInfo.text);
599 anAction->setToolTip(theInfo.toolTip);
600 anAction->setShortcut(theInfo.shortcut);
601 anAction->setFont(theInfo.font);
603 int aWBMenu = createMenu(theWBName, -1, -1, 30);
604 int aItemId = createMenu(anAction, aWBMenu);
605 myActionsList.append(aItemId);
606 createMenu(separator(), aWBMenu); /// nested action is always separated of others
608 int aWBTool = createTool(theWBName, theWBName);
609 int aToolId = createTool(anAction, aWBTool);
610 registerCommandToolbar(theWBName, aItemId);
611 createTool(separator(), aWBTool); /// nested action is always separated of others
612 registerCommandToolbar(theWBName, -1);
618 //******************************************************
619 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
620 const QString& theTip, const QIcon& theIcon,
621 const QKeySequence& theKeys, bool isCheckable,
622 const char* theMenuSourceText, const int theMenuPosition)
624 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
626 int aId = getNextCommandId();
627 myActionsList.append(aId);
628 SUIT_Desktop* aDesk = application()->desktop();
630 for (int i = 0; i < theKeys.count(); i++)
632 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
634 aAction->setStatusTip(theTip);
635 aAction->setData(theId);
636 createMenu(aId, aMenu, theMenuPosition);
640 //******************************************************
641 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
643 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
644 createMenu(separator(), aMenu, -1, theMenuPosition);
647 //******************************************************
648 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
653 SUIT_Desktop* aDesktop = application()->desktop();
657 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
661 aToolMgr->append( theAction, theToolBarTitle );
665 //******************************************************
666 QList<QAction*> SHAPERGUI::commandList() const
668 QList<QAction*> aActions;
669 foreach (int aId, myActionsList) {
670 QAction* aCmd = action(aId);
672 aActions.append(aCmd);
678 //******************************************************
679 QMainWindow* SHAPERGUI::desktop() const
681 return application()->desktop();
684 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
685 const std::shared_ptr<Config_FeatureMessage>& theMessage)
687 myFeaturesInfo.insert(theFeatureId, theMessage);
690 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
692 std::shared_ptr<Config_FeatureMessage> aMessage;
693 if (myFeaturesInfo.contains(theFeatureId))
694 aMessage = myFeaturesInfo[theFeatureId];
698 //******************************************************
699 void SHAPERGUI::selectionChanged()
701 LightApp_Module::selectionChanged();
702 myWorkshop->salomeViewerSelectionChanged();
705 //******************************************************
706 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
708 myWorkshop->contextMenuMgr()->updateViewerMenu();
709 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
710 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
714 //******************************************************
715 void SHAPERGUI::createPreferences()
717 LightApp_Preferences* pref = preferences();
720 ModuleBase_Preferences::updateConfigByResources();
721 QString aModName = moduleName();
723 QtxPreferenceItem* item = pref->findItem(aModName, true );
724 if ( item && (!item->isEmpty() )) {
725 item->parentItem()->removeItem(item);
729 int catId = pref->addPreference(aModName, -1 );
732 SHAPERGUI_PrefMgr aMgr(pref, aModName);
733 ModuleBase_Preferences::createEditContent(&aMgr, catId);
735 int viewTab = pref->addItem(tr("Viewer"), catId);
736 // Create other parameters group in viewer tab
737 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
738 pref->setItemProperty("columns", 3, otherGroup);
739 pref->addItem(tr("Faces"), otherGroup,
740 SUIT_PreferenceMgr::Bool,
741 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
742 pref->addItem(tr("Edges"), otherGroup,
743 SUIT_PreferenceMgr::Bool,
744 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
745 pref->addItem(tr("Vertices"), otherGroup,
746 SUIT_PreferenceMgr::Bool,
747 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
749 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
750 pref->setItemProperty("columns", 2, sensitivityGroup);
751 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
752 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
753 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
754 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
758 //******************************************************
759 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
761 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
762 QString aVal = aResMgr->stringValue(theSection, theParam);
763 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
764 theParam.toStdString());
765 std::string aValue = aVal.toStdString();
766 if (aValue.empty()) {
767 aValue = aProp->defaultValue();
768 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
770 LightApp_Preferences* pref = preferences();
774 aProp->setValue(aValue);
776 myWorkshop->displayer()->redisplayObjects();
779 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
781 application()->putInfo(theInfo, theMSecs);
784 bool SHAPERGUI::abortAllOperations()
786 return workshop()->operationMgr()->abortAllOperations();
789 void SHAPERGUI::createFeatureActions()
791 myWorkshop->menuMgr()->createFeatureActions();
794 void SHAPERGUI::onWhatIs(bool isToggled)
796 if (sender() == myWhatIsAction) {
797 QAction* aViewAct = myInspectionPanel->toggleViewAction();
798 aViewAct->blockSignals(true);
799 aViewAct->setChecked(isToggled);
800 aViewAct->blockSignals(false);
801 myInspectionPanel->setVisible(isToggled);
804 myWhatIsAction->blockSignals(true);
805 myWhatIsAction->setChecked(isToggled);
806 myWhatIsAction->blockSignals(false);
807 myInspectionPanel->setVisible(isToggled);
811 void SHAPERGUI::updateModuleVisibilityState()
813 LightApp_Module::updateModuleVisibilityState();
814 onWhatIs(myIsInspectionVisible);
817 void SHAPERGUI::onEditToolbars()
819 SHAPERGUI_ToolbarsDlg aDlg(this);
820 if (aDlg.exec() == QDialog::Accepted) {
821 updateToolbars(aDlg.result());
825 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
827 if (!myToolbars.contains(theToolName))
828 myToolbars[theToolName] = QList<int>();
829 myToolbars[theToolName].append(theCommandId);
832 int SHAPERGUI::getNextCommandId() const
834 QtxActionMenuMgr* aMenuMgr = menuMgr();
835 QIntList aIds = aMenuMgr->idList();
836 int aId = aIds.count();
837 while (action(aId) || myActionsList.contains(aId))
842 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
844 QtxActionToolMgr* aMgr = toolMgr();
845 QStringList aToolbars = theNewToolbars.keys();
846 QIntList aCommands, aOldCmd;
850 foreach(QString aName, aToolbars) {
851 aCommands = theNewToolbars[aName];
852 // Find or create toolbar
853 if (aMgr->hasToolBar(aName)) {
854 aToolbarId = aMgr->find(aMgr->toolBar(aName));
855 aOldCmd = myToolbars[aName];
858 aToolbarId = aMgr->createToolBar(aName);
861 foreach(int aCmd, aCommands) {
864 aAction = separator();
866 aAction = action(aCmd);
867 aActionId = aMgr->actionId(aAction);
868 if (aActionId == -1) {
870 aMgr->insert(aAction, aToolbarId, aPos);
873 // Change position of action
874 if (aMgr->index(aActionId, aToolbarId) != aPos) {
875 if (aMgr->containsAction(aActionId, aToolbarId))
876 aMgr->remove(aActionId, aToolbarId);
877 aMgr->insert(aActionId, aToolbarId, aPos);
880 aOldCmd.removeAll(aCmd);
883 // remove extra actions
884 foreach(int aCmd, aOldCmd) {
885 aAction = action(aCmd);
886 aActionId = aMgr->actionId(aAction);
887 aMgr->remove(aActionId, aToolbarId);
889 myToolbars.remove(aName);
891 // Remove extra toolbars
892 aToolbars = myToolbars.keys();
893 foreach(QString aName, aToolbars) {
894 aMgr->removeToolBar(aName);
896 // Set new toolbars structure
897 myToolbars = theNewToolbars;
898 myIsToolbarsModified = true;
901 void SHAPERGUI::saveToolbarsConfig()
903 if (!myIsToolbarsModified)
905 // Set toolbars config
906 QMap<QString, QStringList> aToolbarsConfig;
907 QtxActionToolMgr* aMgr = toolMgr();
908 QStringList aToolbars = myToolbars.keys();
909 QIntList aActionsIds;
910 foreach(QString aName, aToolbars) {
911 aActionsIds = myToolbars[aName];
912 QStringList aContent;
913 foreach(int aId, aActionsIds) {
917 aContent.append(action(aId)->data().toString());
919 aToolbarsConfig[aName] = aContent;
922 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
923 QStringList aNames = aToolbarsConfig.keys();
925 const QString aSection("SHAPER_Toolbars");
926 foreach(QString aToolbar, aNames) {
927 aResMgr->setValue(aSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
929 QStringList aOldParams = aResMgr->parameters(aSection);
930 foreach(QString aName, aOldParams) {
931 if (!aToolbars.contains(aName))
932 aResMgr->remove(aSection, aName);
934 myIsToolbarsModified = false;
937 void SHAPERGUI::loadToolbarsConfig()
939 const QString aSection("SHAPER_Toolbars");
940 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
941 QStringList aToolbarNames = aResMgr->parameters(aSection);
942 if (aToolbarNames.size() == 0)
945 QMap<QString, int> aCommandsMap;
947 foreach(int aId, myActionsList) {
948 aCmdIdStr = action(aId)->data().toString();
949 aCommandsMap[aCmdIdStr] = aId;
952 QMap<QString, QIntList> aToolbars;
953 QStringList aCommands;
954 QList<QAction*> aActions;
955 foreach(QString aName, aToolbarNames) {
956 aCommands = aResMgr->stringValue(aSection, aName).split(",");
958 aToolbars[aName] = QIntList();
959 if (aCommands.size() > 0) {
960 foreach(QString aCommand, aCommands) {
961 if (aCommand.isEmpty())
962 aToolbars[aName].append(-1);
963 else if (aCommandsMap.contains(aCommand)) {
964 aToolbars[aName].append(aCommandsMap[aCommand]);
969 updateToolbars(aToolbars);
970 myIsToolbarsModified = false;