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 if (myOldSelectionColor.size() == 0)
326 myOldSelectionColor = aDisp->selectionColor();
328 AIS_ListOfInteractive aList;
329 aContext->DisplayedObjects(aList);
330 AIS_ListIteratorOfListOfInteractive aLIt;
331 Handle(AIS_InteractiveObject) anAISIO;
332 foreach (ObjectPtr aObj, aObjList) {
333 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
334 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
336 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
337 anAISIO = aLIt.Value();
338 if (anAISIO.get() == aAIS.get()) {
344 aObj->setDisplayed(false);
345 //aDisp->erase(aObj, false);
348 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
350 myProxyViewer->activateViewer(true);
352 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
353 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
354 this, SLOT(onScriptLoaded()));
356 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
357 getApp(), SLOT(onSaveDoc()));
358 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
359 getApp(), SLOT(onSaveAsDoc()));
361 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
362 this, SLOT(onSaveDocByShaper()));
363 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
364 this, SLOT(onSaveAsDocByShaper()));
369 //******************************************************
370 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
372 saveToolbarsConfig();
374 myProxyViewer->activateViewer(false);
378 myWorkshop->deactivateModule();
380 QObject* aObj = myWorkshop->objectBrowser()->parent();
381 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
383 aObjDoc->setVisible(false);
384 myWorkshop->objectBrowser()->setVisible(false);
385 QAction* aViewAct = aObjDoc->toggleViewAction();
386 aViewAct->setEnabled(false);
389 myIsInspectionVisible = myInspectionPanel->isVisible();
390 myInspectionPanel->hide();
391 QAction* aViewAct = myInspectionPanel->toggleViewAction();
392 aViewAct->setEnabled(false);
394 // the active operation should be stopped for the next activation.
395 // There should not be active operation and visualized preview.
396 // Abort operation should be performed before the selection's remove
397 // because the displayed objects should be removed from the viewer, but
398 // the AIS context is obtained from the selector.
399 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
400 while (anOperation) {
401 anOperation->abort();
402 anOperation = myWorkshop->operationMgr()->currentOperation();
404 // Delete selector because it has to be redefined on next activation
406 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
407 myProxyViewer->setSelector(0);
412 myWorkshop->hidePanel(myWorkshop->facesPanel());
413 //myWorkshop->contextMenuMgr()->disconnectViewer();
415 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
416 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
417 getApp()->setEditEnabled(myIsEditEnabled);
419 myOldSelectionColor.clear();
421 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
422 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
423 this, SLOT(onScriptLoaded()));
425 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
426 this, SLOT(onSaveDocByShaper()));
427 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
428 this, SLOT(onSaveAsDocByShaper()));
430 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
431 getApp(), SLOT(onSaveDoc()));
432 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
433 getApp(), SLOT(onSaveAsDoc()));
435 return LightApp_Module::deactivateModule(theStudy);
438 //******************************************************
439 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
442 mySelector = createSelector(theMgr);
443 myWorkshop->selectionActivate()->updateSelectionFilters();
444 myWorkshop->selectionActivate()->updateSelectionModes();
445 myWorkshop->synchronizeViewer();
449 //******************************************************
450 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
453 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
454 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
455 if (mySelector->viewer() == aViewer) {
456 XGUI_Displayer* aDisp = myWorkshop->displayer();
457 QObjectPtrList aObjects = aDisp->displayedObjects();
459 foreach(ObjectPtr aObj, aObjects) {
460 aObj->setDisplayed(false);
461 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
463 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
464 aRes->setDisplayed(false);
468 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
469 myProxyViewer->setSelector(0);
473 myWorkshop->module()->clearViewer();
479 //******************************************************
480 QtxPopupMgr* SHAPERGUI::popupMgr()
483 myPopupMgr = new QtxPopupMgr( 0, this );
487 //******************************************************
488 void SHAPERGUI::onDefaultPreferences()
490 // reset main resources
491 ModuleBase_Preferences::resetResourcePreferences(preferences());
492 // reset plugin's resources
493 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
495 myWorkshop->displayer()->redisplayObjects();
498 //******************************************************
499 void SHAPERGUI::onScriptLoaded()
501 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
502 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
503 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
504 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
505 // it manually (because this method of application is protected)
506 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
511 //******************************************************
512 void SHAPERGUI::onSaveDocByShaper()
514 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
517 getApp()->onSaveDoc();
520 //******************************************************
521 void SHAPERGUI::onSaveAsDocByShaper()
523 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
526 getApp()->onSaveAsDoc();
529 //******************************************************
530 void SHAPERGUI::onUpdateCommandStatus()
532 getApp()->updateActions();
535 //******************************************************
536 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
538 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
539 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
540 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
541 getApp()->selectionMgr());
542 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
543 aViewer->setUseLocalSelection(true);
545 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
546 QList<SUIT_Selector*> aList;
547 aMgr->selectors(aList);
548 foreach(SUIT_Selector* aSel, aList)
550 aSel->setEnabled(aSel == aSelector);
552 myProxyViewer->setSelector(aSelector);
554 if (myOldSelectionColor.size() == 0)
555 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
557 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
558 myWorkshop->displayer()->setSelectionColor(aColor);
564 //******************************************************
565 CAM_DataModel* SHAPERGUI::createDataModel()
567 return new SHAPERGUI_DataModel(this);
570 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
571 const bool isAddSeparator)
573 return addFeature(theWBName,
577 //Issue #650: in the SALOME mode the tooltip should be same as text
586 //******************************************************
587 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
588 const QString& theId, const QString& theTitle, const QString& theTip,
589 const QIcon& theIcon, const QKeySequence& theKeys,
590 bool isCheckable, const bool isAddSeparator,
591 const QString& theStatusTip)
593 static QString aLastTool = "";
595 if (aLastTool.isEmpty())
596 aLastTool = theWBName;
597 else if (theWBName != aLastTool) {
598 aLastTool = theWBName;
600 desktop()->addToolBarBreak();
606 int aId = getNextCommandId();
607 myActionsList.append(aId);
608 SUIT_Desktop* aDesk = application()->desktop();
610 for (int i = 0; i < theKeys.count(); i++)
612 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
614 aAction->setStatusTip(theStatusTip);
616 aAction->setData(theId);
618 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
619 int aItemId = createMenu(aId, aWBMenu);
621 createMenu(separator(), aWBMenu);
623 int aWBTool = createTool(theTBName, theTBName);
624 int aToolId = createTool(aId, aWBTool);
625 registerCommandToolbar(theTBName, aId);
626 if (isAddSeparator) {
627 createTool(separator(), aWBTool);
628 registerCommandToolbar(theTBName, -1);
633 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
635 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
638 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
639 const ActionInfo& theInfo,
640 const QList<QAction*>& theNestedActions)
642 SUIT_Desktop* aDesk = application()->desktop();
643 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
644 anAction->setData(theInfo.id);
645 anAction->setCheckable(theInfo.checkable);
646 anAction->setChecked(theInfo.checked);
647 anAction->setEnabled(theInfo.enabled);
648 anAction->setVisible(theInfo.visible);
649 anAction->setIcon(theInfo.icon);
650 anAction->setText(theInfo.text);
651 anAction->setToolTip(theInfo.toolTip);
652 anAction->setShortcut(theInfo.shortcut);
653 anAction->setFont(theInfo.font);
655 int aWBMenu = createMenu(theWBName, -1, -1, 30);
656 int aItemId = createMenu(anAction, aWBMenu);
657 myActionsList.append(aItemId);
658 createMenu(separator(), aWBMenu); /// nested action is always separated of others
660 int aWBTool = createTool(theWBName, theWBName);
661 int aToolId = createTool(anAction, aWBTool);
662 registerCommandToolbar(theWBName, aItemId);
663 createTool(separator(), aWBTool); /// nested action is always separated of others
664 registerCommandToolbar(theWBName, -1);
670 //******************************************************
671 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
672 const QString& theTip, const QIcon& theIcon,
673 const QKeySequence& theKeys, bool isCheckable,
674 const char* theMenuSourceText, const int theMenuPosition)
676 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
678 int aId = getNextCommandId();
679 myActionsList.append(aId);
680 SUIT_Desktop* aDesk = application()->desktop();
682 for (int i = 0; i < theKeys.count(); i++)
684 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
686 aAction->setStatusTip(theTip);
687 aAction->setData(theId);
688 createMenu(aId, aMenu, theMenuPosition);
692 //******************************************************
693 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
695 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
696 createMenu(separator(), aMenu, -1, theMenuPosition);
699 //******************************************************
700 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
705 SUIT_Desktop* aDesktop = application()->desktop();
709 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
713 aToolMgr->append( theAction, theToolBarTitle );
717 //******************************************************
718 QList<QAction*> SHAPERGUI::commandList() const
720 QList<QAction*> aActions;
721 foreach (int aId, myActionsList) {
722 QAction* aCmd = action(aId);
724 aActions.append(aCmd);
730 //******************************************************
731 QMainWindow* SHAPERGUI::desktop() const
733 return application()->desktop();
736 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
737 const std::shared_ptr<Config_FeatureMessage>& theMessage)
739 myFeaturesInfo.insert(theFeatureId, theMessage);
742 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
744 std::shared_ptr<Config_FeatureMessage> aMessage;
745 if (myFeaturesInfo.contains(theFeatureId))
746 aMessage = myFeaturesInfo[theFeatureId];
750 //******************************************************
751 void SHAPERGUI::selectionChanged()
753 LightApp_Module::selectionChanged();
754 myWorkshop->salomeViewerSelectionChanged();
757 //******************************************************
758 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
760 myWorkshop->contextMenuMgr()->updateViewerMenu();
761 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
762 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
766 //******************************************************
767 void SHAPERGUI::createPreferences()
769 LightApp_Preferences* pref = preferences();
772 ModuleBase_Preferences::updateConfigByResources();
773 QString aModName = moduleName();
775 QtxPreferenceItem* item = pref->findItem(aModName, true );
776 if ( item && (!item->isEmpty() )) {
777 item->parentItem()->removeItem(item);
781 int catId = pref->addPreference(aModName, -1 );
784 SHAPERGUI_PrefMgr aMgr(pref, aModName);
785 ModuleBase_Preferences::createEditContent(&aMgr, catId);
787 int viewTab = pref->addItem(tr("Viewer"), catId);
788 // Create other parameters group in viewer tab
789 int otherGroup = pref->addItem(tr("Default selection"), viewTab);
790 pref->setItemProperty("columns", 3, otherGroup);
791 pref->addItem(tr("Faces"), otherGroup,
792 SUIT_PreferenceMgr::Bool,
793 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
794 pref->addItem(tr("Edges"), otherGroup,
795 SUIT_PreferenceMgr::Bool,
796 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
797 pref->addItem(tr("Vertices"), otherGroup,
798 SUIT_PreferenceMgr::Bool,
799 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
801 int sensitivityGroup = pref->addItem(tr("Selection sensitivity"), viewTab);
802 pref->setItemProperty("columns", 2, sensitivityGroup);
803 pref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
804 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
805 pref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
806 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
808 int highlightGroup = pref->addItem(tr("Additional highlighting"), viewTab);
809 pref->setItemProperty("columns", 2, highlightGroup);
810 pref->addItem(tr("In 3d mode"), highlightGroup,
811 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
812 pref->addItem(tr("In 2d mode"), highlightGroup,
813 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
815 int colorScaleGroup = pref->addItem(tr("Color scale"), viewTab);
816 pref->setItemProperty("columns", 4, colorScaleGroup);
817 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
818 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
819 pref->setItemProperty("min", 0, aItem);
820 pref->setItemProperty("max", 1, aItem);
822 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
823 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
824 pref->setItemProperty("min", 0, aItem);
825 pref->setItemProperty("max", 1, aItem);
827 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
828 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
829 pref->setItemProperty("min", 0, aItem);
830 pref->setItemProperty("max", 1, aItem);
832 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
833 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
834 pref->setItemProperty("min", 0, aItem);
835 pref->setItemProperty("max", 1, aItem);
837 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
838 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
839 pref->setItemProperty("min", 0, aItem);
840 pref->setItemProperty("max", 100, aItem);
842 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
843 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
844 pref->setItemProperty("min", 0, aItem);
845 pref->setItemProperty("max", 100, aItem);
847 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
848 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
853 //******************************************************
854 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
856 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
857 QString aVal = aResMgr->stringValue(theSection, theParam);
858 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
859 theParam.toStdString());
860 std::string aValue = aVal.toStdString();
861 if (aValue.empty()) {
862 aValue = aProp->defaultValue();
863 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
865 LightApp_Preferences* pref = preferences();
869 aProp->setValue(aValue);
871 if ((theSection == "Visualization") && (theParam == "selection_color")) {
872 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
873 myWorkshop->displayer()->setSelectionColor(aColor);
876 myWorkshop->displayer()->redisplayObjects();
879 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
881 application()->putInfo(theInfo, theMSecs);
884 bool SHAPERGUI::abortAllOperations()
886 return workshop()->operationMgr()->abortAllOperations();
889 void SHAPERGUI::createFeatureActions()
891 myWorkshop->menuMgr()->createFeatureActions();
894 void SHAPERGUI::onWhatIs(bool isToggled)
896 if (sender() == myWhatIsAction) {
897 QAction* aViewAct = myInspectionPanel->toggleViewAction();
898 aViewAct->blockSignals(true);
899 aViewAct->setChecked(isToggled);
900 aViewAct->blockSignals(false);
901 myInspectionPanel->setVisible(isToggled);
904 myWhatIsAction->blockSignals(true);
905 myWhatIsAction->setChecked(isToggled);
906 myWhatIsAction->blockSignals(false);
907 myInspectionPanel->setVisible(isToggled);
911 void SHAPERGUI::updateModuleVisibilityState()
913 LightApp_Module::updateModuleVisibilityState();
914 onWhatIs(myIsInspectionVisible);
917 void SHAPERGUI::onEditToolbars()
919 SHAPERGUI_ToolbarsDlg aDlg(this);
920 if (aDlg.exec() == QDialog::Accepted) {
924 updateToolbars(aDlg.result());
928 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
930 if (!myToolbars.contains(theToolName))
931 myToolbars[theToolName] = QList<int>();
932 myToolbars[theToolName].append(theCommandId);
935 int SHAPERGUI::getNextCommandId() const
937 QtxActionMenuMgr* aMenuMgr = menuMgr();
938 QIntList aIds = aMenuMgr->idList();
939 int aId = aIds.count();
940 while (action(aId) || myActionsList.contains(aId))
945 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
947 // Store default toolbars
948 if (myDefaultToolbars.size() == 0)
949 myDefaultToolbars = myToolbars;
951 QtxActionToolMgr* aMgr = toolMgr();
952 QStringList aToolbars = theNewToolbars.keys();
953 QIntList aCommands, aOldCmd;
957 foreach(QString aName, aToolbars) {
958 aCommands = theNewToolbars[aName];
959 // Find or create toolbar
960 if (aMgr->hasToolBar(aName)) {
961 aToolbarId = aMgr->find(aMgr->toolBar(aName));
962 aOldCmd = myToolbars[aName];
965 aToolbarId = aMgr->createToolBar(aName);
968 foreach(int aCmd, aCommands) {
971 aAction = separator();
973 aAction = action(aCmd);
974 aActionId = aMgr->actionId(aAction);
975 if (aActionId == -1) {
977 aMgr->insert(aAction, aToolbarId, aPos);
980 // Change position of action
981 if (aMgr->index(aActionId, aToolbarId) != aPos) {
982 if (aMgr->containsAction(aActionId, aToolbarId))
983 aMgr->remove(aActionId, aToolbarId);
984 aMgr->insert(aActionId, aToolbarId, aPos);
987 aOldCmd.removeAll(aCmd);
990 // remove extra actions
991 foreach(int aCmd, aOldCmd) {
992 aAction = action(aCmd);
993 aActionId = aMgr->actionId(aAction);
994 aMgr->remove(aActionId, aToolbarId);
996 myToolbars.remove(aName);
998 // Remove extra toolbars
999 aToolbars = myToolbars.keys();
1000 foreach(QString aName, aToolbars) {
1001 aMgr->removeToolBar(aName);
1003 // Set new toolbars structure
1004 myToolbars = theNewToolbars;
1005 myIsToolbarsModified = true;
1008 void SHAPERGUI::saveToolbarsConfig()
1010 if (!myIsToolbarsModified)
1012 // Save toolbars configuration into map
1013 QMap<QString, QStringList> aToolbarsConfig;
1014 QtxActionToolMgr* aMgr = toolMgr();
1015 QStringList aToolbars = myToolbars.keys();
1016 QIntList aActionsIds;
1017 foreach(QString aName, aToolbars) {
1018 aActionsIds = myToolbars[aName];
1019 QStringList aContent;
1020 foreach(int aId, aActionsIds) {
1022 aContent.append("");
1024 aContent.append(action(aId)->data().toString());
1026 aToolbarsConfig[aName] = aContent;
1028 // Store the configuration into resources
1029 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1030 QStringList aNames = aToolbarsConfig.keys();
1031 QStringList aValues;
1032 foreach(QString aToolbar, aNames) {
1033 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1035 // Remove obsolete parameters from resources
1036 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1037 foreach(QString aName, aOldParams) {
1038 if (!aToolbars.contains(aName))
1039 aResMgr->remove(ToolbarsSection, aName);
1041 // Store current list of free commands
1042 QIntList aFreeCommands = getFreeCommands();
1043 QStringList aFreeList;
1044 foreach(int aId, aFreeCommands) {
1045 aFreeList.append(action(aId)->data().toString());
1047 if (aFreeList.size() > 0)
1048 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1050 myIsToolbarsModified = false;
1053 void SHAPERGUI::loadToolbarsConfig()
1055 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1056 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1057 if (aToolbarNames.size() == 0)
1060 // Create commands map
1061 QMap<QString, int> aCommandsMap;
1063 foreach(int aId, myActionsList) {
1064 aCmdIdStr = action(aId)->data().toString();
1065 aCommandsMap[aCmdIdStr] = aId;
1068 // Create new toolbars structure
1069 QMap<QString, QIntList> aToolbars;
1070 QStringList aCommands;
1071 QIntList aKnownCommands;
1072 QList<QAction*> aActions;
1073 foreach(QString aName, aToolbarNames) {
1074 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1075 if (aName == FreeCommandsParam) {
1076 // The value is a list of free commands
1077 foreach(QString aCommand, aCommands) {
1078 aKnownCommands.append(aCommandsMap[aCommand]);
1082 aToolbars[aName] = QIntList();
1083 if (aCommands.size() > 0) {
1084 foreach(QString aCommand, aCommands) {
1085 if (aCommand.isEmpty())
1086 aToolbars[aName].append(-1);
1087 else if (aCommandsMap.contains(aCommand)) {
1088 int aId = aCommandsMap[aCommand];
1089 aToolbars[aName].append(aId);
1090 aKnownCommands.append(aId);
1096 // Find new and obsolete commands
1097 QIntList aNewCommands = myActionsList;
1098 foreach(int aId, myActionsList) {
1099 if (aKnownCommands.contains(aId)) {
1100 aKnownCommands.removeAll(aId);
1101 aNewCommands.removeAll(aId);
1104 if (aNewCommands.size() > 0) {
1105 // Add new commands to toolbars structure
1106 QStringList aKeys = myToolbars.keys();
1107 foreach(int aNewId, aNewCommands) {
1108 foreach(QString aName, aKeys) {
1109 if (myToolbars[aName].contains(aNewId)) {
1110 if (!aToolbars.contains(aName)) {
1111 aToolbars[aName] = QIntList();
1113 aToolbars[aName].append(aNewId);
1118 if (aKnownCommands.size() > 0) {
1119 // Remove obsolete commands from the toolbars structure
1120 QStringList aKeys = aToolbars.keys();
1121 foreach(int aOldId, aKnownCommands) {
1122 foreach(QString aName, aKeys) {
1123 if (aToolbars[aName].contains(aOldId)) {
1124 aToolbars[aName].removeAll(aOldId);
1125 if (aToolbars[aName].size() == 0)
1126 aToolbars.remove(aName);
1131 updateToolbars(aToolbars);
1132 myIsToolbarsModified = false;
1136 QIntList SHAPERGUI::getFreeCommands() const
1138 QIntList aFreeCommands;
1139 QtxActionToolMgr* aMgr = toolMgr();
1142 QMap<QString, QIntList>::const_iterator aIt;
1143 QIntList aShaperActions = shaperActions();
1144 foreach(int aCmd, aShaperActions) {
1145 anAction = action(aCmd);
1146 aId = aMgr->actionId(anAction);
1147 if (!aMgr->containsAction(aId))
1148 aFreeCommands.append(aCmd);
1150 return aFreeCommands;
1153 void SHAPERGUI::resetToolbars()
1155 if (!myDefaultToolbars.isEmpty())
1156 updateToolbars(myDefaultToolbars);
1157 myIsToolbarsModified = false;
1158 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1159 aResMgr->remove(ToolbarsSection);