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>
37 #include <ModuleBase_Operation.h>
38 #include <ModuleBase_Preferences.h>
39 #include <ModuleBase_ActionInfo.h>
40 #include <ModuleBase_IModule.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <LightApp_OCCSelector.h>
45 #include <LightApp_Study.h>
46 #include <OCCViewer_ViewModel.h>
48 #include <SUIT_Selector.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ViewManager.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_DataBrowser.h>
54 #include <QtxPopupMgr.h>
55 #include <QtxActionMenuMgr.h>
56 #include <QtxActionToolMgr.h>
57 #include <QtxResourceMgr.h>
59 #include <Config_PropManager.h>
60 #include <Config_ModuleReader.h>
62 #include <AIS_ListOfInteractive.hxx>
63 #include <AIS_ListIteratorOfListOfInteractive.hxx>
65 #include <QDockWidget>
71 #define SALOME_PATCH_FOR_CTRL_WHEEL
74 SHAPERGUI_EXPORT CAM_Module* createModule()
76 return new SHAPERGUI();
79 SHAPERGUI_EXPORT char* getModuleVersion()
86 static const QString ToolbarsSection("SHAPER_Toolbars");
87 static const QString FreeCommandsParam("OutOFToolbars");
91 * Class for preferences management
93 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
97 /// \param theMgr preferences manager of SALOME
98 /// \param theModName name of the module
99 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
100 myMgr(theMgr), myModName(theModName) {}
102 virtual int addPreference(const QString& theLbl, int pId,
103 SUIT_PreferenceMgr::PrefItemType theType,
104 const QString& theSection, const QString& theName )
106 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
109 virtual void setItemProperty(const QString& thePropName,
110 const QVariant& theValue,
111 const int theId = -1)
113 myMgr->setItemProperty(thePropName, theValue, theId);
117 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
120 LightApp_Preferences* myMgr;
127 //******************************************************
128 SHAPERGUI::SHAPERGUI()
129 : LightApp_Module("SHAPER"),
130 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
131 myInspectionPanel(0), myIsToolbarsModified(false)
133 myWorkshop = new XGUI_Workshop(this);
134 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
135 this, SLOT(onUpdateCommandStatus()));
137 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
139 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
140 ModuleBase_Preferences::loadCustomProps();
143 //******************************************************
144 SHAPERGUI::~SHAPERGUI()
147 delete myProxyViewer;
150 //******************************************************
151 void SHAPERGUI::initialize(CAM_Application* theApp)
153 LightApp_Module::initialize(theApp);
155 myWorkshop->startApplication();
156 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
159 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
162 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
163 int aSubMenu = createMenu(tr("Information"), aMenu);
165 int aId = getNextCommandId();
166 myActionsList.append(aId);
167 SUIT_Desktop* aDesk = application()->desktop();
168 QString aTip = tr("Show inspection window");
169 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
170 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
171 myWhatIsAction->setStatusTip(aTip);
172 myWhatIsAction->setData("INSPECTION_CMD");
173 createMenu(aId, aSubMenu, 0);
175 QString aToolName = tr("Inspection tool");
176 int aTool = createTool(aToolName);
177 int aToolId = createTool(myWhatIsAction, aTool);
178 registerCommandToolbar(aToolName, aId);
180 // Define Edit toolbars command
181 aId = getNextCommandId();
182 //myActionsList.append(aId); Do not use it for editing of toolbars
183 aTip = tr("Edit toolbars of the module");
184 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
185 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
186 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
187 int aEditItem = createMenu(aId, aEditMenu);
190 //******************************************************
191 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
193 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
196 //******************************************************
197 void SHAPERGUI::viewManagers(QStringList& theList) const
199 theList.append(OCCViewer_Viewer::Type());
202 //******************************************************
203 // We can not create selector in this method because it can be called when
204 // SHAPER module is not active. Take into account that creation of our selector
205 // leads to switching OFF all other selectors
206 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
208 // // if there are created viewer managers, we should try to create viewer
209 // // selector and initialize viewer with it. It sets interactive contect to the
210 // // proxy viewer. If study is opened, CAM application calls this method before the open()
212 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
213 // // we need to connect to the viewer before it. Here,
214 // // it seems the most appropriate place for this
215 // // according to SALOME architecture.
216 // if (!mySelector) {
217 // ViewManagerList OCCViewManagers;
218 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
219 // if (OCCViewManagers.size() > 0) {
220 // mySelector = createSelector(OCCViewManagers.first());
223 // LightApp_Module::connectToStudy(theStudy);
226 //******************************************************
227 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
229 bool isDone = LightApp_Module::activateModule(theStudy);
230 loadToolbarsConfig();
232 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
233 aDataModel->initRootObject();
239 QObject* aObj = myWorkshop->objectBrowser()->parent();
240 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
242 QAction* aViewAct = aObjDoc->toggleViewAction();
243 aViewAct->setEnabled(true);
244 myWorkshop->objectBrowser()->setVisible(true);
245 aObjDoc->setVisible(true);
246 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
249 if (!myInspectionPanel) {
250 myInspectionPanel = myWorkshop->inspectionPanel();
251 QAction* aViewAct = myInspectionPanel->toggleViewAction();
252 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
254 myInspectionPanel->toggleViewAction()->setEnabled(true);
257 ViewManagerList OCCViewManagers;
258 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
259 if (OCCViewManagers.size() > 0) {
260 mySelector = createSelector(OCCViewManagers.first());
263 // it should be pefromed after the selector creation in order to have AISContext
264 myWorkshop->activateModule();
265 //action(myEraseAll)->setEnabled(false);
268 myWorkshop->objectBrowser()->rebuildDataTree();
269 myWorkshop->updateCommandStatus();
273 myWorkshop->updateCommandStatus();
275 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
276 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
277 myIsEditEnabled = getApp()->isEditEnabled();
278 getApp()->setEditEnabled(false);
280 // this following row is caused by #187 bug.
281 // SALOME saves the dock widget positions before deactivateModule() and
282 // load it after the module activation. So, if the panel is visible before
283 // deactivate, it becomes visible after activate.
284 // In order to avoid the visible property panel, the widget position save is
285 // switch off in this module
286 aResMgr->setValue("Study", "store_positions", false);
288 // Synchronize displayed objects
289 Handle(AIS_InteractiveContext) aContext;
290 if (mySelector && mySelector->viewer())
291 aContext = mySelector->viewer()->getAISContext();
293 if (!aContext.IsNull()) {
294 XGUI_Displayer* aDisp = myWorkshop->displayer();
295 QObjectPtrList aObjList = aDisp->displayedObjects();
297 AIS_ListOfInteractive aList;
298 aContext->DisplayedObjects(aList);
299 AIS_ListIteratorOfListOfInteractive aLIt;
300 Handle(AIS_InteractiveObject) anAISIO;
301 foreach (ObjectPtr aObj, aObjList) {
302 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
303 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
305 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
306 anAISIO = aLIt.Value();
307 if (anAISIO.get() == aAIS.get()) {
313 aObj->setDisplayed(false);
314 //aDisp->erase(aObj, false);
317 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
319 myProxyViewer->activateViewer(true);
321 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
322 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
323 this, SLOT(onScriptLoaded()));
325 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
326 getApp(), SLOT(onSaveDoc()));
327 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
328 getApp(), SLOT(onSaveAsDoc()));
330 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
331 this, SLOT(onSaveDocByShaper()));
332 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
333 this, SLOT(onSaveAsDocByShaper()));
338 //******************************************************
339 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
341 saveToolbarsConfig();
343 myProxyViewer->activateViewer(false);
347 myWorkshop->deactivateModule();
349 QObject* aObj = myWorkshop->objectBrowser()->parent();
350 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
352 aObjDoc->setVisible(false);
353 myWorkshop->objectBrowser()->setVisible(false);
354 QAction* aViewAct = aObjDoc->toggleViewAction();
355 aViewAct->setEnabled(false);
358 myIsInspectionVisible = myInspectionPanel->isVisible();
359 myInspectionPanel->hide();
360 QAction* aViewAct = myInspectionPanel->toggleViewAction();
361 aViewAct->setEnabled(false);
363 // the active operation should be stopped for the next activation.
364 // There should not be active operation and visualized preview.
365 // Abort operation should be performed before the selection's remove
366 // because the displayed objects should be removed from the viewer, but
367 // the AIS context is obtained from the selector.
368 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
369 while (anOperation) {
370 anOperation->abort();
371 anOperation = myWorkshop->operationMgr()->currentOperation();
373 // Delete selector because it has to be redefined on next activation
375 myProxyViewer->setSelector(0);
380 myWorkshop->hidePanel(myWorkshop->facesPanel());
381 //myWorkshop->contextMenuMgr()->disconnectViewer();
383 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
384 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
385 getApp()->setEditEnabled(myIsEditEnabled);
387 // Postrrocessing for LoadScriptId to remove created(if it was created) SALOME Object Browser
388 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
389 this, SLOT(onScriptLoaded()));
391 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
392 this, SLOT(onSaveDocByShaper()));
393 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
394 this, SLOT(onSaveAsDocByShaper()));
396 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
397 getApp(), SLOT(onSaveDoc()));
398 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
399 getApp(), SLOT(onSaveAsDoc()));
401 return LightApp_Module::deactivateModule(theStudy);
404 //******************************************************
405 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
408 mySelector = createSelector(theMgr);
409 myWorkshop->selectionActivate()->updateSelectionFilters();
410 myWorkshop->selectionActivate()->updateSelectionModes();
411 myWorkshop->synchronizeViewer();
415 //******************************************************
416 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
419 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
420 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
421 if (mySelector->viewer() == aViewer) {
422 XGUI_Displayer* aDisp = myWorkshop->displayer();
423 QObjectPtrList aObjects = aDisp->displayedObjects();
424 foreach(ObjectPtr aObj, aObjects)
425 aObj->setDisplayed(false);
426 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
427 myProxyViewer->setSelector(0);
431 myWorkshop->module()->clearViewer();
437 //******************************************************
438 QtxPopupMgr* SHAPERGUI::popupMgr()
441 myPopupMgr = new QtxPopupMgr( 0, this );
445 //******************************************************
446 void SHAPERGUI::onDefaultPreferences()
448 // reset main resources
449 ModuleBase_Preferences::resetResourcePreferences(preferences());
450 // reset plugin's resources
451 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
453 myWorkshop->displayer()->redisplayObjects();
456 //******************************************************
457 void SHAPERGUI::onScriptLoaded()
459 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
460 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
461 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
462 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
463 // it manually (because this method of application is protected)
464 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
469 //******************************************************
470 void SHAPERGUI::onSaveDocByShaper()
472 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
475 getApp()->onSaveDoc();
478 //******************************************************
479 void SHAPERGUI::onSaveAsDocByShaper()
481 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
484 getApp()->onSaveAsDoc();
487 //******************************************************
488 void SHAPERGUI::onUpdateCommandStatus()
490 getApp()->updateActions();
493 //******************************************************
494 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
496 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
497 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
498 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
499 getApp()->selectionMgr());
500 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
501 aViewer->setUseLocalSelection(true);
503 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
504 QList<SUIT_Selector*> aList;
505 aMgr->selectors(aList);
506 foreach(SUIT_Selector* aSel, aList)
508 aSel->setEnabled(aSel == aSelector);
510 myProxyViewer->setSelector(aSelector);
516 //******************************************************
517 CAM_DataModel* SHAPERGUI::createDataModel()
519 return new SHAPERGUI_DataModel(this);
522 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
523 const bool isAddSeparator)
525 return addFeature(theWBName,
529 //Issue #650: in the SALOME mode the tooltip should be same as text
538 //******************************************************
539 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
540 const QString& theId, const QString& theTitle, const QString& theTip,
541 const QIcon& theIcon, const QKeySequence& theKeys,
542 bool isCheckable, const bool isAddSeparator,
543 const QString& theStatusTip)
545 static QString aLastTool = "";
547 if (aLastTool.isEmpty())
548 aLastTool = theWBName;
549 else if (theWBName != aLastTool) {
550 aLastTool = theWBName;
552 desktop()->addToolBarBreak();
558 int aId = getNextCommandId();
559 myActionsList.append(aId);
560 SUIT_Desktop* aDesk = application()->desktop();
562 for (int i = 0; i < theKeys.count(); i++)
564 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
566 aAction->setStatusTip(theStatusTip);
568 aAction->setData(theId);
570 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
571 int aItemId = createMenu(aId, aWBMenu);
573 createMenu(separator(), aWBMenu);
575 int aWBTool = createTool(theTBName, theTBName);
576 int aToolId = createTool(aId, aWBTool);
577 registerCommandToolbar(theTBName, aId);
578 if (isAddSeparator) {
579 createTool(separator(), aWBTool);
580 registerCommandToolbar(theTBName, -1);
585 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
587 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
590 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
591 const ActionInfo& theInfo,
592 const QList<QAction*>& theNestedActions)
594 SUIT_Desktop* aDesk = application()->desktop();
595 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
596 anAction->setData(theInfo.id);
597 anAction->setCheckable(theInfo.checkable);
598 anAction->setChecked(theInfo.checked);
599 anAction->setEnabled(theInfo.enabled);
600 anAction->setVisible(theInfo.visible);
601 anAction->setIcon(theInfo.icon);
602 anAction->setText(theInfo.text);
603 anAction->setToolTip(theInfo.toolTip);
604 anAction->setShortcut(theInfo.shortcut);
605 anAction->setFont(theInfo.font);
607 int aWBMenu = createMenu(theWBName, -1, -1, 30);
608 int aItemId = createMenu(anAction, aWBMenu);
609 myActionsList.append(aItemId);
610 createMenu(separator(), aWBMenu); /// nested action is always separated of others
612 int aWBTool = createTool(theWBName, theWBName);
613 int aToolId = createTool(anAction, aWBTool);
614 registerCommandToolbar(theWBName, aItemId);
615 createTool(separator(), aWBTool); /// nested action is always separated of others
616 registerCommandToolbar(theWBName, -1);
622 //******************************************************
623 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
624 const QString& theTip, const QIcon& theIcon,
625 const QKeySequence& theKeys, bool isCheckable,
626 const char* theMenuSourceText, const int theMenuPosition)
628 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
630 int aId = getNextCommandId();
631 myActionsList.append(aId);
632 SUIT_Desktop* aDesk = application()->desktop();
634 for (int i = 0; i < theKeys.count(); i++)
636 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
638 aAction->setStatusTip(theTip);
639 aAction->setData(theId);
640 createMenu(aId, aMenu, theMenuPosition);
644 //******************************************************
645 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
647 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
648 createMenu(separator(), aMenu, -1, theMenuPosition);
651 //******************************************************
652 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
657 SUIT_Desktop* aDesktop = application()->desktop();
661 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
665 aToolMgr->append( theAction, theToolBarTitle );
669 //******************************************************
670 QList<QAction*> SHAPERGUI::commandList() const
672 QList<QAction*> aActions;
673 foreach (int aId, myActionsList) {
674 QAction* aCmd = action(aId);
676 aActions.append(aCmd);
682 //******************************************************
683 QMainWindow* SHAPERGUI::desktop() const
685 return application()->desktop();
688 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
689 const std::shared_ptr<Config_FeatureMessage>& theMessage)
691 myFeaturesInfo.insert(theFeatureId, theMessage);
694 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
696 std::shared_ptr<Config_FeatureMessage> aMessage;
697 if (myFeaturesInfo.contains(theFeatureId))
698 aMessage = myFeaturesInfo[theFeatureId];
702 //******************************************************
703 void SHAPERGUI::selectionChanged()
705 LightApp_Module::selectionChanged();
706 myWorkshop->salomeViewerSelectionChanged();
709 //******************************************************
710 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
712 myWorkshop->contextMenuMgr()->updateViewerMenu();
713 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
714 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
718 //******************************************************
719 void SHAPERGUI::createPreferences()
721 LightApp_Preferences* pref = preferences();
724 ModuleBase_Preferences::updateConfigByResources();
725 QString aModName = moduleName();
727 QtxPreferenceItem* item = pref->findItem(aModName, true );
728 if ( item && (!item->isEmpty() )) {
729 item->parentItem()->removeItem(item);
733 int catId = pref->addPreference(aModName, -1 );
736 SHAPERGUI_PrefMgr aMgr(pref, aModName);
737 ModuleBase_Preferences::createEditContent(&aMgr, catId);
739 int viewTab = pref->addItem(tr("Viewer"), catId);
740 // Create other parameters group in viewer tab
741 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
742 pref->setItemProperty("columns", 3, otherGroup);
743 pref->addItem(tr("Faces"), otherGroup,
744 SUIT_PreferenceMgr::Bool,
745 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
746 pref->addItem(tr("Edges"), otherGroup,
747 SUIT_PreferenceMgr::Bool,
748 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
749 pref->addItem(tr("Vertices"), otherGroup,
750 SUIT_PreferenceMgr::Bool,
751 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
753 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
754 pref->setItemProperty("columns", 2, sensitivityGroup);
755 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
756 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
757 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
758 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
762 //******************************************************
763 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
765 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
766 QString aVal = aResMgr->stringValue(theSection, theParam);
767 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
768 theParam.toStdString());
769 std::string aValue = aVal.toStdString();
770 if (aValue.empty()) {
771 aValue = aProp->defaultValue();
772 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
774 LightApp_Preferences* pref = preferences();
778 aProp->setValue(aValue);
780 myWorkshop->displayer()->redisplayObjects();
783 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
785 application()->putInfo(theInfo, theMSecs);
788 bool SHAPERGUI::abortAllOperations()
790 return workshop()->operationMgr()->abortAllOperations();
793 void SHAPERGUI::createFeatureActions()
795 myWorkshop->menuMgr()->createFeatureActions();
798 void SHAPERGUI::onWhatIs(bool isToggled)
800 if (sender() == myWhatIsAction) {
801 QAction* aViewAct = myInspectionPanel->toggleViewAction();
802 aViewAct->blockSignals(true);
803 aViewAct->setChecked(isToggled);
804 aViewAct->blockSignals(false);
805 myInspectionPanel->setVisible(isToggled);
808 myWhatIsAction->blockSignals(true);
809 myWhatIsAction->setChecked(isToggled);
810 myWhatIsAction->blockSignals(false);
811 myInspectionPanel->setVisible(isToggled);
815 void SHAPERGUI::updateModuleVisibilityState()
817 LightApp_Module::updateModuleVisibilityState();
818 onWhatIs(myIsInspectionVisible);
821 void SHAPERGUI::onEditToolbars()
823 SHAPERGUI_ToolbarsDlg aDlg(this);
824 if (aDlg.exec() == QDialog::Accepted) {
828 updateToolbars(aDlg.result());
832 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
834 if (!myToolbars.contains(theToolName))
835 myToolbars[theToolName] = QList<int>();
836 myToolbars[theToolName].append(theCommandId);
839 int SHAPERGUI::getNextCommandId() const
841 QtxActionMenuMgr* aMenuMgr = menuMgr();
842 QIntList aIds = aMenuMgr->idList();
843 int aId = aIds.count();
844 while (action(aId) || myActionsList.contains(aId))
849 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
851 // Store default toolbars
852 if (myDefaultToolbars.size() == 0)
853 myDefaultToolbars = myToolbars;
855 QtxActionToolMgr* aMgr = toolMgr();
856 QStringList aToolbars = theNewToolbars.keys();
857 QIntList aCommands, aOldCmd;
861 foreach(QString aName, aToolbars) {
862 aCommands = theNewToolbars[aName];
863 // Find or create toolbar
864 if (aMgr->hasToolBar(aName)) {
865 aToolbarId = aMgr->find(aMgr->toolBar(aName));
866 aOldCmd = myToolbars[aName];
869 aToolbarId = aMgr->createToolBar(aName);
872 foreach(int aCmd, aCommands) {
875 aAction = separator();
877 aAction = action(aCmd);
878 aActionId = aMgr->actionId(aAction);
879 if (aActionId == -1) {
881 aMgr->insert(aAction, aToolbarId, aPos);
884 // Change position of action
885 if (aMgr->index(aActionId, aToolbarId) != aPos) {
886 if (aMgr->containsAction(aActionId, aToolbarId))
887 aMgr->remove(aActionId, aToolbarId);
888 aMgr->insert(aActionId, aToolbarId, aPos);
891 aOldCmd.removeAll(aCmd);
894 // remove extra actions
895 foreach(int aCmd, aOldCmd) {
896 aAction = action(aCmd);
897 aActionId = aMgr->actionId(aAction);
898 aMgr->remove(aActionId, aToolbarId);
900 myToolbars.remove(aName);
902 // Remove extra toolbars
903 aToolbars = myToolbars.keys();
904 foreach(QString aName, aToolbars) {
905 aMgr->removeToolBar(aName);
907 // Set new toolbars structure
908 myToolbars = theNewToolbars;
909 myIsToolbarsModified = true;
912 void SHAPERGUI::saveToolbarsConfig()
914 if (!myIsToolbarsModified)
916 // Save toolbars config into map
917 QMap<QString, QStringList> aToolbarsConfig;
918 QtxActionToolMgr* aMgr = toolMgr();
919 QStringList aToolbars = myToolbars.keys();
920 QIntList aActionsIds;
921 foreach(QString aName, aToolbars) {
922 aActionsIds = myToolbars[aName];
923 QStringList aContent;
924 foreach(int aId, aActionsIds) {
928 aContent.append(action(aId)->data().toString());
930 aToolbarsConfig[aName] = aContent;
932 // Store the config into resources
933 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
934 QStringList aNames = aToolbarsConfig.keys();
936 foreach(QString aToolbar, aNames) {
937 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
939 // Remove obsolete parameters from resources
940 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
941 foreach(QString aName, aOldParams) {
942 if (!aToolbars.contains(aName))
943 aResMgr->remove(ToolbarsSection, aName);
945 // Store current list of free commands
946 QIntList aFreeCommands = getFreeCommands();
947 QStringList aFreeList;
948 foreach(int aId, aFreeCommands) {
949 aFreeList.append(action(aId)->data().toString());
951 if (aFreeList.size() > 0)
952 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
954 myIsToolbarsModified = false;
957 void SHAPERGUI::loadToolbarsConfig()
959 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
960 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
961 if (aToolbarNames.size() == 0)
964 // Create commands map
965 QMap<QString, int> aCommandsMap;
967 foreach(int aId, myActionsList) {
968 aCmdIdStr = action(aId)->data().toString();
969 aCommandsMap[aCmdIdStr] = aId;
972 // Create new toolbars structure
973 QMap<QString, QIntList> aToolbars;
974 QStringList aCommands;
975 QIntList aKnownCommands;
976 QList<QAction*> aActions;
977 foreach(QString aName, aToolbarNames) {
978 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
979 if (aName == FreeCommandsParam) {
980 // The value is a list of free commands
981 foreach(QString aCommand, aCommands) {
982 aKnownCommands.append(aCommandsMap[aCommand]);
986 aToolbars[aName] = QIntList();
987 if (aCommands.size() > 0) {
988 foreach(QString aCommand, aCommands) {
989 if (aCommand.isEmpty())
990 aToolbars[aName].append(-1);
991 else if (aCommandsMap.contains(aCommand)) {
992 int aId = aCommandsMap[aCommand];
993 aToolbars[aName].append(aId);
994 aKnownCommands.append(aId);
1000 // Find new and obsolete commands
1001 QIntList aNewCommands = myActionsList;
1002 foreach(int aId, myActionsList) {
1003 if (aKnownCommands.contains(aId)) {
1004 aKnownCommands.removeAll(aId);
1005 aNewCommands.removeAll(aId);
1008 if (aNewCommands.size() > 0) {
1009 // Add new commands to toolbars structure
1010 QStringList aKeys = myToolbars.keys();
1011 foreach(int aNewId, aNewCommands) {
1012 foreach(QString aName, aKeys) {
1013 if (myToolbars[aName].contains(aNewId)) {
1014 if (!aToolbars.contains(aName)) {
1015 aToolbars[aName] = QIntList();
1017 aToolbars[aName].append(aNewId);
1022 if (aKnownCommands.size() > 0) {
1023 // Remove obsolete commands from the toolbars structure
1024 QStringList aKeys = aToolbars.keys();
1025 foreach(int aOldId, aKnownCommands) {
1026 foreach(QString aName, aKeys) {
1027 if (aToolbars[aName].contains(aOldId)) {
1028 aToolbars[aName].removeAll(aOldId);
1029 if (aToolbars[aName].size() == 0)
1030 aToolbars.remove(aName);
1035 updateToolbars(aToolbars);
1036 myIsToolbarsModified = false;
1040 QIntList SHAPERGUI::getFreeCommands() const
1042 QIntList aFreeCommands;
1043 QtxActionToolMgr* aMgr = toolMgr();
1046 QMap<QString, QIntList>::const_iterator aIt;
1047 QIntList aShaperActions = shaperActions();
1048 foreach(int aCmd, aShaperActions) {
1049 anAction = action(aCmd);
1050 aId = aMgr->actionId(anAction);
1051 if (!aMgr->containsAction(aId))
1052 aFreeCommands.append(aCmd);
1054 return aFreeCommands;
1057 void SHAPERGUI::resetToolbars()
1059 if (!myDefaultToolbars.isEmpty())
1060 updateToolbars(myDefaultToolbars);
1061 myIsToolbarsModified = false;
1062 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1063 aResMgr->remove(ToolbarsSection);