1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SHAPERGUI.h"
21 #include "SHAPERGUI_DataModel.h"
22 #include "SHAPERGUI_OCCSelector.h"
23 #include "SHAPERGUI_NestedButton.h"
24 #include "SHAPERGUI_ToolbarsMgr.h"
26 #include <XGUI_Workshop.h>
27 #include <XGUI_PropertyPanel.h>
28 #include <XGUI_ContextMenuMgr.h>
29 #include <XGUI_ObjectsBrowser.h>
30 #include <XGUI_OperationMgr.h>
31 #include <XGUI_Displayer.h>
32 #include <XGUI_MenuMgr.h>
33 #include <XGUI_FacesPanel.h>
34 #include <XGUI_SelectionActivate.h>
35 #include <XGUI_InspectionPanel.h>
36 #include <XGUI_ViewerProxy.h>
38 #include <ModuleBase_Operation.h>
39 #include <ModuleBase_Preferences.h>
40 #include <ModuleBase_ActionInfo.h>
41 #include <ModuleBase_IModule.h>
43 #include <ModelAPI_Tools.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_OCCSelector.h>
48 #include <LightApp_Study.h>
50 #include <OCCViewer_ViewModel.h>
51 #include <OCCViewer_ViewPort3d.h>
53 #include <SUIT_Selector.h>
54 #include <SUIT_Desktop.h>
55 #include <SUIT_ViewManager.h>
56 #include <SUIT_ViewWindow.h>
57 #include <SUIT_ResourceMgr.h>
58 #include <SUIT_DataBrowser.h>
60 #include <QtxPopupMgr.h>
61 #include <QtxActionMenuMgr.h>
62 #include <QtxActionToolMgr.h>
63 #include <QtxResourceMgr.h>
65 #include <Config_PropManager.h>
66 #include <Config_ModuleReader.h>
68 #include <AIS_ListOfInteractive.hxx>
69 #include <AIS_ListIteratorOfListOfInteractive.hxx>
71 #include <QDockWidget>
77 #define SALOME_PATCH_FOR_CTRL_WHEEL
80 SHAPERGUI_EXPORT CAM_Module* createModule()
82 return new SHAPERGUI();
85 SHAPERGUI_EXPORT char* getModuleVersion()
92 static const QString ToolbarsSection("SHAPER_Toolbars");
93 static const QString FreeCommandsParam("OutOFToolbars");
97 * Class for preferences management
99 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
103 /// \param theMgr preferences manager of SALOME
104 /// \param theModName name of the module
105 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
106 myMgr(theMgr), myModName(theModName) {}
108 virtual int addPreference(const QString& theLbl, int pId,
109 SUIT_PreferenceMgr::PrefItemType theType,
110 const QString& theSection, const QString& theName )
112 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
115 virtual void setItemProperty(const QString& thePropName,
116 const QVariant& theValue,
117 const int theId = -1)
119 myMgr->setItemProperty(thePropName, theValue, theId);
123 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
126 LightApp_Preferences* myMgr;
133 //******************************************************
134 SHAPERGUI::SHAPERGUI()
135 : LightApp_Module("SHAPER"),
136 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
137 myInspectionPanel(0), myIsToolbarsModified(false)
139 myWorkshop = new XGUI_Workshop(this);
140 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
141 this, SLOT(onUpdateCommandStatus()));
143 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
145 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
147 // It will be called in XGUI_Workshop::startApplication
148 // ModuleBase_Preferences::loadCustomProps();
151 //******************************************************
152 SHAPERGUI::~SHAPERGUI()
155 delete myProxyViewer;
158 //******************************************************
159 void SHAPERGUI::initialize(CAM_Application* theApp)
161 LightApp_Module::initialize(theApp);
163 myWorkshop->startApplication();
164 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
167 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
170 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
171 int aSubMenu = createMenu(tr("Information"), aMenu);
173 int aId = getNextCommandId();
174 myActionsList.append(aId);
175 SUIT_Desktop* aDesk = application()->desktop();
176 QString aTip = tr("Show inspection window");
177 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
178 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
179 myWhatIsAction->setStatusTip(aTip);
180 myWhatIsAction->setData("INSPECTION_CMD");
181 createMenu(aId, aSubMenu, 0);
183 QString aToolName = tr("Inspection tool");
184 int aTool = createTool(aToolName);
185 int aToolId = createTool(myWhatIsAction, aTool);
186 registerCommandToolbar(aToolName, aId);
188 // Define Edit toolbars command
189 aId = getNextCommandId();
190 //myActionsList.append(aId); Do not use it for editing of toolbars
191 aTip = tr("Edit toolbars of the module");
192 QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
193 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
194 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
195 int aEditItem = createMenu(aId, aEditMenu);
197 // Initialize viewer proxy if OCC viewer is already exist
198 ViewManagerList aOCCViewManagers;
199 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
200 if (aOCCViewManagers.size() > 0) {
201 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
202 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
204 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
205 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
207 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
208 aViewPort->installEventFilter(aViewer);
209 Handle(V3d_View) aView = aViewPort->getView();
210 aViewer->SetScale(aView, aView->Camera()->Scale());
211 // We can not create selector here because other modules will be deactivated later
212 //onViewManagerAdded(aMgr);
218 //******************************************************
219 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
221 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
224 //******************************************************
225 void SHAPERGUI::viewManagers(QStringList& theList) const
227 theList.append(OCCViewer_Viewer::Type());
230 //******************************************************
231 // We can not create selector in this method because it can be called when
232 // SHAPER module is not active. Take into account that creation of our selector
233 // leads to switching OFF all other selectors
234 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
236 // // if there are created viewer managers, we should try to create viewer
237 // // selector and initialize viewer with it. It sets interactive context to the
238 // // proxy viewer. If study is opened, CAM application calls this method before the open()
240 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
241 // // we need to connect to the viewer before it. Here,
242 // // it seems the most appropriate place for this
243 // // according to SALOME architecture.
244 // if (!mySelector) {
245 // ViewManagerList OCCViewManagers;
246 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
247 // if (OCCViewManagers.size() > 0) {
248 // mySelector = createSelector(OCCViewManagers.first());
251 // LightApp_Module::connectToStudy(theStudy);
254 //******************************************************
255 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
257 bool isDone = LightApp_Module::activateModule(theStudy);
258 loadToolbarsConfig();
260 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
261 aDataModel->initRootObject();
267 QObject* aObj = myWorkshop->objectBrowser()->parent();
268 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
270 QAction* aViewAct = aObjDoc->toggleViewAction();
271 aViewAct->setEnabled(true);
272 myWorkshop->objectBrowser()->setVisible(true);
273 aObjDoc->setVisible(true);
274 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
277 if (!myInspectionPanel) {
278 myInspectionPanel = myWorkshop->inspectionPanel();
279 QAction* aViewAct = myInspectionPanel->toggleViewAction();
280 connect(aViewAct, SIGNAL(toggled(bool)), this, SLOT(onWhatIs(bool)));
282 myInspectionPanel->toggleViewAction()->setEnabled(true);
285 ViewManagerList OCCViewManagers;
286 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
287 if (OCCViewManagers.size() > 0) {
288 onViewManagerAdded(OCCViewManagers.first());
291 // it should be performed after the selector creation in order to have AISContext
292 myWorkshop->activateModule();
293 //action(myEraseAll)->setEnabled(false);
296 myWorkshop->objectBrowser()->rebuildDataTree();
297 myWorkshop->updateCommandStatus();
301 myWorkshop->updateCommandStatus();
303 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
304 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
305 myIsEditEnabled = getApp()->isEditEnabled();
306 getApp()->setEditEnabled(false);
308 // this following row is caused by #187 bug.
309 // SALOME saves the dock widget positions before deactivateModule() and
310 // load it after the module activation. So, if the panel is visible before
311 // deactivate, it becomes visible after activate.
312 // In order to avoid the visible property panel, the widget position save is
313 // switch off in this module
314 aResMgr->setValue("Study", "store_positions", false);
316 // Synchronize displayed objects
317 Handle(AIS_InteractiveContext) aContext;
318 if (mySelector && mySelector->viewer())
319 aContext = mySelector->viewer()->getAISContext();
321 if (!aContext.IsNull()) {
322 XGUI_Displayer* aDisp = myWorkshop->displayer();
323 QObjectPtrList aObjList = aDisp->displayedObjects();
325 AIS_ListOfInteractive aList;
326 aContext->DisplayedObjects(aList);
327 AIS_ListIteratorOfListOfInteractive aLIt;
328 Handle(AIS_InteractiveObject) anAISIO;
329 foreach (ObjectPtr aObj, aObjList) {
330 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
331 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
333 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
334 anAISIO = aLIt.Value();
335 if (anAISIO.get() == aAIS.get()) {
341 aObj->setDisplayed(false);
342 //aDisp->erase(aObj, false);
345 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
347 myProxyViewer->activateViewer(true);
349 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
350 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
351 this, SLOT(onScriptLoaded()));
353 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
354 getApp(), SLOT(onSaveDoc()));
355 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
356 getApp(), SLOT(onSaveAsDoc()));
358 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
359 this, SLOT(onSaveDocByShaper()));
360 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
361 this, SLOT(onSaveAsDocByShaper()));
366 //******************************************************
367 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
369 saveToolbarsConfig();
371 myProxyViewer->activateViewer(false);
375 myWorkshop->deactivateModule();
377 QObject* aObj = myWorkshop->objectBrowser()->parent();
378 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
380 aObjDoc->setVisible(false);
381 myWorkshop->objectBrowser()->setVisible(false);
382 QAction* aViewAct = aObjDoc->toggleViewAction();
383 aViewAct->setEnabled(false);
386 myIsInspectionVisible = myInspectionPanel->isVisible();
387 myInspectionPanel->hide();
388 QAction* aViewAct = myInspectionPanel->toggleViewAction();
389 aViewAct->setEnabled(false);
391 // the active operation should be stopped for the next activation.
392 // There should not be active operation and visualized preview.
393 // Abort operation should be performed before the selection's remove
394 // because the displayed objects should be removed from the viewer, but
395 // the AIS context is obtained from the selector.
396 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
397 while (anOperation) {
398 anOperation->abort();
399 anOperation = myWorkshop->operationMgr()->currentOperation();
401 // Delete selector because it has to be redefined on next activation
403 myProxyViewer->setSelector(0);
408 myWorkshop->hidePanel(myWorkshop->facesPanel());
409 //myWorkshop->contextMenuMgr()->disconnectViewer();
411 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
412 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
413 getApp()->setEditEnabled(myIsEditEnabled);
415 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
416 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
417 this, SLOT(onScriptLoaded()));
419 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
420 this, SLOT(onSaveDocByShaper()));
421 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
422 this, SLOT(onSaveAsDocByShaper()));
424 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
425 getApp(), SLOT(onSaveDoc()));
426 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
427 getApp(), SLOT(onSaveAsDoc()));
429 return LightApp_Module::deactivateModule(theStudy);
432 //******************************************************
433 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
436 mySelector = createSelector(theMgr);
437 myWorkshop->selectionActivate()->updateSelectionFilters();
438 myWorkshop->selectionActivate()->updateSelectionModes();
439 myWorkshop->synchronizeViewer();
443 //******************************************************
444 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
447 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
448 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
449 if (mySelector->viewer() == aViewer) {
450 XGUI_Displayer* aDisp = myWorkshop->displayer();
451 QObjectPtrList aObjects = aDisp->displayedObjects();
453 foreach(ObjectPtr aObj, aObjects) {
454 aObj->setDisplayed(false);
455 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
457 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
458 aRes->setDisplayed(false);
462 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
463 myProxyViewer->setSelector(0);
467 myWorkshop->module()->clearViewer();
473 //******************************************************
474 QtxPopupMgr* SHAPERGUI::popupMgr()
477 myPopupMgr = new QtxPopupMgr( 0, this );
481 //******************************************************
482 void SHAPERGUI::onDefaultPreferences()
484 // reset main resources
485 ModuleBase_Preferences::resetResourcePreferences(preferences());
486 // reset plugin's resources
487 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
489 myWorkshop->displayer()->redisplayObjects();
492 //******************************************************
493 void SHAPERGUI::onScriptLoaded()
495 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
496 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
497 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
498 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
499 // it manually (because this method of application is protected)
500 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
503 myWorkshop->displayer()->updateViewer();
506 //******************************************************
507 void SHAPERGUI::onSaveDocByShaper()
509 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
512 getApp()->onSaveDoc();
515 //******************************************************
516 void SHAPERGUI::onSaveAsDocByShaper()
518 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
521 getApp()->onSaveAsDoc();
524 //******************************************************
525 void SHAPERGUI::onUpdateCommandStatus()
527 getApp()->updateActions();
530 //******************************************************
531 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
533 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
534 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
535 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
536 getApp()->selectionMgr());
537 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
538 aViewer->setUseLocalSelection(true);
540 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
541 QList<SUIT_Selector*> aList;
542 aMgr->selectors(aList);
543 foreach(SUIT_Selector* aSel, aList)
545 aSel->setEnabled(aSel == aSelector);
547 myProxyViewer->setSelector(aSelector);
553 //******************************************************
554 CAM_DataModel* SHAPERGUI::createDataModel()
556 return new SHAPERGUI_DataModel(this);
559 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
560 const bool isAddSeparator)
562 return addFeature(theWBName,
566 //Issue #650: in the SALOME mode the tooltip should be same as text
575 //******************************************************
576 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
577 const QString& theId, const QString& theTitle, const QString& theTip,
578 const QIcon& theIcon, const QKeySequence& theKeys,
579 bool isCheckable, const bool isAddSeparator,
580 const QString& theStatusTip)
582 static QString aLastTool = "";
584 if (aLastTool.isEmpty())
585 aLastTool = theWBName;
586 else if (theWBName != aLastTool) {
587 aLastTool = theWBName;
589 desktop()->addToolBarBreak();
595 int aId = getNextCommandId();
596 myActionsList.append(aId);
597 SUIT_Desktop* aDesk = application()->desktop();
599 for (int i = 0; i < theKeys.count(); i++)
601 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
603 aAction->setStatusTip(theStatusTip);
605 aAction->setData(theId);
607 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
608 int aItemId = createMenu(aId, aWBMenu);
610 createMenu(separator(), aWBMenu);
612 int aWBTool = createTool(theTBName, theTBName);
613 int aToolId = createTool(aId, aWBTool);
614 registerCommandToolbar(theTBName, aId);
615 if (isAddSeparator) {
616 createTool(separator(), aWBTool);
617 registerCommandToolbar(theTBName, -1);
622 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
624 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
627 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
628 const ActionInfo& theInfo,
629 const QList<QAction*>& theNestedActions)
631 SUIT_Desktop* aDesk = application()->desktop();
632 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
633 anAction->setData(theInfo.id);
634 anAction->setCheckable(theInfo.checkable);
635 anAction->setChecked(theInfo.checked);
636 anAction->setEnabled(theInfo.enabled);
637 anAction->setVisible(theInfo.visible);
638 anAction->setIcon(theInfo.icon);
639 anAction->setText(theInfo.text);
640 anAction->setToolTip(theInfo.toolTip);
641 anAction->setShortcut(theInfo.shortcut);
642 anAction->setFont(theInfo.font);
644 int aWBMenu = createMenu(theWBName, -1, -1, 30);
645 int aItemId = createMenu(anAction, aWBMenu);
646 myActionsList.append(aItemId);
647 createMenu(separator(), aWBMenu); /// nested action is always separated of others
649 int aWBTool = createTool(theWBName, theWBName);
650 int aToolId = createTool(anAction, aWBTool);
651 registerCommandToolbar(theWBName, aItemId);
652 createTool(separator(), aWBTool); /// nested action is always separated of others
653 registerCommandToolbar(theWBName, -1);
659 //******************************************************
660 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
661 const QString& theTip, const QIcon& theIcon,
662 const QKeySequence& theKeys, bool isCheckable,
663 const char* theMenuSourceText, const int theMenuPosition)
665 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
667 int aId = getNextCommandId();
668 myActionsList.append(aId);
669 SUIT_Desktop* aDesk = application()->desktop();
671 for (int i = 0; i < theKeys.count(); i++)
673 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
675 aAction->setStatusTip(theTip);
676 aAction->setData(theId);
677 createMenu(aId, aMenu, theMenuPosition);
681 //******************************************************
682 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
684 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
685 createMenu(separator(), aMenu, -1, theMenuPosition);
688 //******************************************************
689 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
694 SUIT_Desktop* aDesktop = application()->desktop();
698 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
702 aToolMgr->append( theAction, theToolBarTitle );
706 //******************************************************
707 QList<QAction*> SHAPERGUI::commandList() const
709 QList<QAction*> aActions;
710 foreach (int aId, myActionsList) {
711 QAction* aCmd = action(aId);
713 aActions.append(aCmd);
719 //******************************************************
720 QMainWindow* SHAPERGUI::desktop() const
722 return application()->desktop();
725 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
726 const std::shared_ptr<Config_FeatureMessage>& theMessage)
728 myFeaturesInfo.insert(theFeatureId, theMessage);
731 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
733 std::shared_ptr<Config_FeatureMessage> aMessage;
734 if (myFeaturesInfo.contains(theFeatureId))
735 aMessage = myFeaturesInfo[theFeatureId];
739 //******************************************************
740 void SHAPERGUI::selectionChanged()
742 LightApp_Module::selectionChanged();
743 myWorkshop->salomeViewerSelectionChanged();
746 //******************************************************
747 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
749 myWorkshop->contextMenuMgr()->updateViewerMenu();
750 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
751 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
755 //******************************************************
756 void SHAPERGUI::createPreferences()
758 LightApp_Preferences* pref = preferences();
761 ModuleBase_Preferences::updateConfigByResources();
762 QString aModName = moduleName();
764 QtxPreferenceItem* item = pref->findItem(aModName, true );
765 if ( item && (!item->isEmpty() )) {
766 item->parentItem()->removeItem(item);
770 int catId = pref->addPreference(aModName, -1 );
773 SHAPERGUI_PrefMgr aMgr(pref, aModName);
774 ModuleBase_Preferences::createEditContent(&aMgr, catId);
776 int viewTab = pref->addItem(tr("Viewer"), catId);
777 // Create other parameters group in viewer tab
778 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
779 pref->setItemProperty("columns", 3, otherGroup);
780 pref->addItem(tr("Faces"), otherGroup,
781 SUIT_PreferenceMgr::Bool,
782 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
783 pref->addItem(tr("Edges"), otherGroup,
784 SUIT_PreferenceMgr::Bool,
785 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
786 pref->addItem(tr("Vertices"), otherGroup,
787 SUIT_PreferenceMgr::Bool,
788 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
790 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
791 pref->setItemProperty("columns", 2, sensitivityGroup);
792 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
793 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
794 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
795 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
797 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
798 pref->setItemProperty("columns", 2, highlightGroup);
799 pref->addItem(tr("In 3d mode"), highlightGroup,
800 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
801 pref->addItem(tr("In 2d mode"), highlightGroup,
802 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
804 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
805 pref->setItemProperty("columns", 4, colorScaleGroup);
806 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
807 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
808 pref->setItemProperty("min", 0, aItem);
809 pref->setItemProperty("max", 1, aItem);
811 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
812 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
813 pref->setItemProperty("min", 0, aItem);
814 pref->setItemProperty("max", 1, aItem);
816 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
817 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
818 pref->setItemProperty("min", 0, aItem);
819 pref->setItemProperty("max", 1, aItem);
821 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
822 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
823 pref->setItemProperty("min", 0, aItem);
824 pref->setItemProperty("max", 1, aItem);
826 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
827 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
828 pref->setItemProperty("min", 0, aItem);
829 pref->setItemProperty("max", 100, aItem);
831 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
832 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
833 pref->setItemProperty("min", 0, aItem);
834 pref->setItemProperty("max", 100, aItem);
836 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
837 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
842 //******************************************************
843 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
845 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
846 QString aVal = aResMgr->stringValue(theSection, theParam);
847 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
848 theParam.toStdString());
849 std::string aValue = aVal.toStdString();
850 if (aValue.empty()) {
851 aValue = aProp->defaultValue();
852 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
854 LightApp_Preferences* pref = preferences();
858 aProp->setValue(aValue);
860 myWorkshop->displayer()->redisplayObjects();
863 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
865 application()->putInfo(theInfo, theMSecs);
868 bool SHAPERGUI::abortAllOperations()
870 return workshop()->operationMgr()->abortAllOperations();
873 void SHAPERGUI::createFeatureActions()
875 myWorkshop->menuMgr()->createFeatureActions();
878 void SHAPERGUI::onWhatIs(bool isToggled)
880 if (sender() == myWhatIsAction) {
881 QAction* aViewAct = myInspectionPanel->toggleViewAction();
882 aViewAct->blockSignals(true);
883 aViewAct->setChecked(isToggled);
884 aViewAct->blockSignals(false);
885 myInspectionPanel->setVisible(isToggled);
888 myWhatIsAction->blockSignals(true);
889 myWhatIsAction->setChecked(isToggled);
890 myWhatIsAction->blockSignals(false);
891 myInspectionPanel->setVisible(isToggled);
895 void SHAPERGUI::updateModuleVisibilityState()
897 LightApp_Module::updateModuleVisibilityState();
898 onWhatIs(myIsInspectionVisible);
901 void SHAPERGUI::onEditToolbars()
903 SHAPERGUI_ToolbarsDlg aDlg(this);
904 if (aDlg.exec() == QDialog::Accepted) {
908 updateToolbars(aDlg.result());
912 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
914 if (!myToolbars.contains(theToolName))
915 myToolbars[theToolName] = QList<int>();
916 myToolbars[theToolName].append(theCommandId);
919 int SHAPERGUI::getNextCommandId() const
921 QtxActionMenuMgr* aMenuMgr = menuMgr();
922 QIntList aIds = aMenuMgr->idList();
923 int aId = aIds.count();
924 while (action(aId) || myActionsList.contains(aId))
929 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
931 // Store default toolbars
932 if (myDefaultToolbars.size() == 0)
933 myDefaultToolbars = myToolbars;
935 QtxActionToolMgr* aMgr = toolMgr();
936 QStringList aToolbars = theNewToolbars.keys();
937 QIntList aCommands, aOldCmd;
941 foreach(QString aName, aToolbars) {
942 aCommands = theNewToolbars[aName];
943 // Find or create toolbar
944 if (aMgr->hasToolBar(aName)) {
945 aToolbarId = aMgr->find(aMgr->toolBar(aName));
946 aOldCmd = myToolbars[aName];
949 aToolbarId = aMgr->createToolBar(aName);
952 foreach(int aCmd, aCommands) {
955 aAction = separator();
957 aAction = action(aCmd);
958 aActionId = aMgr->actionId(aAction);
959 if (aActionId == -1) {
961 aMgr->insert(aAction, aToolbarId, aPos);
964 // Change position of action
965 if (aMgr->index(aActionId, aToolbarId) != aPos) {
966 if (aMgr->containsAction(aActionId, aToolbarId))
967 aMgr->remove(aActionId, aToolbarId);
968 aMgr->insert(aActionId, aToolbarId, aPos);
971 aOldCmd.removeAll(aCmd);
974 // remove extra actions
975 foreach(int aCmd, aOldCmd) {
976 aAction = action(aCmd);
977 aActionId = aMgr->actionId(aAction);
978 aMgr->remove(aActionId, aToolbarId);
980 myToolbars.remove(aName);
982 // Remove extra toolbars
983 aToolbars = myToolbars.keys();
984 foreach(QString aName, aToolbars) {
985 aMgr->removeToolBar(aName);
987 // Set new toolbars structure
988 myToolbars = theNewToolbars;
989 myIsToolbarsModified = true;
992 void SHAPERGUI::saveToolbarsConfig()
994 if (!myIsToolbarsModified)
996 // Save toolbars configuration into map
997 QMap<QString, QStringList> aToolbarsConfig;
998 QtxActionToolMgr* aMgr = toolMgr();
999 QStringList aToolbars = myToolbars.keys();
1000 QIntList aActionsIds;
1001 foreach(QString aName, aToolbars) {
1002 aActionsIds = myToolbars[aName];
1003 QStringList aContent;
1004 foreach(int aId, aActionsIds) {
1006 aContent.append("");
1008 aContent.append(action(aId)->data().toString());
1010 aToolbarsConfig[aName] = aContent;
1012 // Store the configuration into resources
1013 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1014 QStringList aNames = aToolbarsConfig.keys();
1015 QStringList aValues;
1016 foreach(QString aToolbar, aNames) {
1017 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1019 // Remove obsolete parameters from resources
1020 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1021 foreach(QString aName, aOldParams) {
1022 if (!aToolbars.contains(aName))
1023 aResMgr->remove(ToolbarsSection, aName);
1025 // Store current list of free commands
1026 QIntList aFreeCommands = getFreeCommands();
1027 QStringList aFreeList;
1028 foreach(int aId, aFreeCommands) {
1029 aFreeList.append(action(aId)->data().toString());
1031 if (aFreeList.size() > 0)
1032 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1034 myIsToolbarsModified = false;
1037 void SHAPERGUI::loadToolbarsConfig()
1039 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1040 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1041 if (aToolbarNames.size() == 0)
1044 // Create commands map
1045 QMap<QString, int> aCommandsMap;
1047 foreach(int aId, myActionsList) {
1048 aCmdIdStr = action(aId)->data().toString();
1049 aCommandsMap[aCmdIdStr] = aId;
1052 // Create new toolbars structure
1053 QMap<QString, QIntList> aToolbars;
1054 QStringList aCommands;
1055 QIntList aKnownCommands;
1056 QList<QAction*> aActions;
1057 foreach(QString aName, aToolbarNames) {
1058 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1059 if (aName == FreeCommandsParam) {
1060 // The value is a list of free commands
1061 foreach(QString aCommand, aCommands) {
1062 aKnownCommands.append(aCommandsMap[aCommand]);
1066 aToolbars[aName] = QIntList();
1067 if (aCommands.size() > 0) {
1068 foreach(QString aCommand, aCommands) {
1069 if (aCommand.isEmpty())
1070 aToolbars[aName].append(-1);
1071 else if (aCommandsMap.contains(aCommand)) {
1072 int aId = aCommandsMap[aCommand];
1073 aToolbars[aName].append(aId);
1074 aKnownCommands.append(aId);
1080 // Find new and obsolete commands
1081 QIntList aNewCommands = myActionsList;
1082 foreach(int aId, myActionsList) {
1083 if (aKnownCommands.contains(aId)) {
1084 aKnownCommands.removeAll(aId);
1085 aNewCommands.removeAll(aId);
1088 if (aNewCommands.size() > 0) {
1089 // Add new commands to toolbars structure
1090 QStringList aKeys = myToolbars.keys();
1091 foreach(int aNewId, aNewCommands) {
1092 foreach(QString aName, aKeys) {
1093 if (myToolbars[aName].contains(aNewId)) {
1094 if (!aToolbars.contains(aName)) {
1095 aToolbars[aName] = QIntList();
1097 aToolbars[aName].append(aNewId);
1102 if (aKnownCommands.size() > 0) {
1103 // Remove obsolete commands from the toolbars structure
1104 QStringList aKeys = aToolbars.keys();
1105 foreach(int aOldId, aKnownCommands) {
1106 foreach(QString aName, aKeys) {
1107 if (aToolbars[aName].contains(aOldId)) {
1108 aToolbars[aName].removeAll(aOldId);
1109 if (aToolbars[aName].size() == 0)
1110 aToolbars.remove(aName);
1115 updateToolbars(aToolbars);
1116 myIsToolbarsModified = false;
1120 QIntList SHAPERGUI::getFreeCommands() const
1122 QIntList aFreeCommands;
1123 QtxActionToolMgr* aMgr = toolMgr();
1126 QMap<QString, QIntList>::const_iterator aIt;
1127 QIntList aShaperActions = shaperActions();
1128 foreach(int aCmd, aShaperActions) {
1129 anAction = action(aCmd);
1130 aId = aMgr->actionId(anAction);
1131 if (!aMgr->containsAction(aId))
1132 aFreeCommands.append(aCmd);
1134 return aFreeCommands;
1137 void SHAPERGUI::resetToolbars()
1139 if (!myDefaultToolbars.isEmpty())
1140 updateToolbars(myDefaultToolbars);
1141 myIsToolbarsModified = false;
1142 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1143 aResMgr->remove(ToolbarsSection);