1 // Copyright (C) 2014-2022 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>
64 #include <QtxInfoPanel.h>
66 #include <Config_PropManager.h>
67 #include <Config_ModuleReader.h>
69 #include <AIS_ListOfInteractive.hxx>
70 #include <AIS_ListIteratorOfListOfInteractive.hxx>
71 #include <Standard_Version.hxx>
73 #include <QDockWidget>
79 #include <ModelAPI_Session.h>
80 #include <Events_MessageBool.h>
82 #if OCC_VERSION_HEX < 0x070400
83 #define SALOME_PATCH_FOR_CTRL_WHEEL
87 SHAPERGUI_EXPORT CAM_Module* createModule()
89 return new SHAPERGUI();
92 SHAPERGUI_EXPORT char* getModuleVersion()
99 static const QString ToolbarsSection("SHAPER_Toolbars");
100 static const QString FreeCommandsParam("OutOFToolbars");
104 * Class for preferences management
106 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
110 /// \param theMgr preferences manager of SALOME
111 /// \param theModName name of the module
112 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
113 myMgr(theMgr), myModName(theModName) {}
115 virtual int addPreference(const QString& theLbl, int pId,
116 SUIT_PreferenceMgr::PrefItemType theType,
117 const QString& theSection, const QString& theName )
119 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
122 virtual void setItemProperty(const QString& thePropName,
123 const QVariant& theValue,
124 const int theId = -1)
126 myMgr->setItemProperty(thePropName, theValue, theId);
130 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
133 LightApp_Preferences* myMgr;
140 //******************************************************
141 SHAPERGUI::SHAPERGUI()
142 : LightApp_Module("SHAPER"),
143 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
144 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
147 myWorkshop = new XGUI_Workshop(this);
148 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
149 this, SLOT(onUpdateCommandStatus()));
151 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
153 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
155 // It will be called in XGUI_Workshop::startApplication
156 // ModuleBase_Preferences::loadCustomProps();
159 //******************************************************
160 SHAPERGUI::~SHAPERGUI()
163 delete myProxyViewer;
166 //******************************************************
167 void SHAPERGUI::initialize(CAM_Application* theApp)
169 LightApp_Module::initialize(theApp);
171 myWorkshop->startApplication();
172 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
175 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
178 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
180 int aId = getNextCommandId();
181 myActionsList.append(aId);
182 SUIT_Desktop* aDesk = application()->desktop();
183 QString aTip = tr("Show inspection window");
184 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
185 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
186 myWhatIsAction->setStatusTip(aTip);
187 myWhatIsAction->setData("INSPECTION_CMD");
188 createMenu(aId, aMenu, 0);
190 QString aToolName = tr("Inspection");
191 int aTool = createTool(aToolName);
195 createTool(myWhatIsAction, aTool);
196 registerCommandToolbar(aToolName, aId);
198 // Define Edit toolbars command
199 aId = getNextCommandId();
200 //myActionsList.append(aId); Do not use it for editing of toolbars
201 aTip = tr("Edit toolbars of the module");
205 createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
206 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
207 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
211 createMenu(aId, aEditMenu);
213 if (!myInspectionPanel) {
214 myInspectionPanel = myWorkshop->inspectionPanel();
215 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
216 this, SLOT(onWhatIs(bool)));
218 hideInternalWindows();
220 // Initialize viewer proxy if OCC viewer is already exist
221 ViewManagerList aOCCViewManagers;
222 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
223 if (aOCCViewManagers.size() > 0) {
224 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
225 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
227 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
228 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
230 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
231 aViewPort->installEventFilter(aViewer);
232 Handle(V3d_View) aView = aViewPort->getView();
233 aViewer->SetScale(aView, aView->Camera()->Scale());
234 // We can not create selector here because other modules will be deactivated later
235 //onViewManagerAdded(aMgr);
239 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
240 aDataModel->initRootObject();
243 //******************************************************
244 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
246 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
247 theWndMap.insert(LightApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
250 //******************************************************
251 void SHAPERGUI::viewManagers(QStringList& theList) const
253 theList.append(OCCViewer_Viewer::Type());
256 //******************************************************
257 // We can not create selector in this method because it can be called when
258 // SHAPER module is not active. Take into account that creation of our selector
259 // leads to switching OFF all other selectors
260 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
262 // // if there are created viewer managers, we should try to create viewer
263 // // selector and initialize viewer with it. It sets interactive context to the
264 // // proxy viewer. If study is opened, CAM application calls this method before the open()
266 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
267 // // we need to connect to the viewer before it. Here,
268 // // it seems the most appropriate place for this
269 // // according to SALOME architecture.
270 // if (!mySelector) {
271 // ViewManagerList OCCViewManagers;
272 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
273 // if (OCCViewManagers.size() > 0) {
274 // mySelector = createSelector(OCCViewManagers.first());
277 // LightApp_Module::connectToStudy(theStudy);
280 //******************************************************
281 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
283 ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet
285 // this must be done in the initialization and in activation (on the second activation
286 // initialization in not called, so SComponent must be added anyway
287 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
288 aDataModel->initRootObject();
291 bool isDone = LightApp_Module::activateModule(theStudy);
292 loadToolbarsConfig();
298 QObject* aObj = myWorkshop->objectBrowser()->parent();
299 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
301 myWorkshop->objectBrowser()->setVisible(true);
302 aObjDoc->setVisible(true);
303 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
304 aObjDoc->toggleViewAction()->setVisible(true);
307 myInspectionPanel->toggleViewAction()->setVisible(true);
309 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
310 if (myIsFacesPanelVisible)
311 myWorkshop->facesPanel()->show();
312 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
315 ViewManagerList OCCViewManagers;
316 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
317 if (OCCViewManagers.size() > 0) {
318 onViewManagerAdded(OCCViewManagers.first());
321 // it should be performed after the selector creation in order to have AISContext
322 myWorkshop->activateModule();
323 //action(myEraseAll)->setEnabled(false);
326 myWorkshop->objectBrowser()->rebuildDataTree();
327 myWorkshop->updateCommandStatus();
331 myWorkshop->updateCommandStatus();
333 myIsEditEnabled = getApp()->isEditEnabled();
334 getApp()->setEditEnabled(false);
336 // Synchronize displayed objects
337 Handle(AIS_InteractiveContext) aContext;
338 if (mySelector && mySelector->viewer())
339 aContext = mySelector->viewer()->getAISContext();
341 if (!aContext.IsNull()) {
342 XGUI_Displayer* aDisp = myWorkshop->displayer();
343 QObjectPtrList aObjList = aDisp->displayedObjects();
345 if (myOldSelectionColor.size() == 0)
346 myOldSelectionColor = aDisp->selectionColor();
348 AIS_ListOfInteractive aList;
349 aContext->DisplayedObjects(aList);
350 AIS_ListIteratorOfListOfInteractive aLIt;
351 Handle(AIS_InteractiveObject) anAISIO;
352 foreach (ObjectPtr aObj, aObjList) {
353 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
354 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
356 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
357 anAISIO = aLIt.Value();
358 if (anAISIO.get() == aAIS.get()) {
364 aObj->setDisplayed(false);
365 //aDisp->erase(aObj, false);
368 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
370 myProxyViewer->activateViewer(true);
372 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
373 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
374 this, SLOT(onScriptLoaded()));
376 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
377 getApp(), SLOT(onSaveDoc()));
378 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
379 getApp(), SLOT(onSaveAsDoc()));
381 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
382 this, SLOT(onSaveDocByShaper()));
383 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
384 this, SLOT(onSaveAsDocByShaper()));
389 //******************************************************
390 void SHAPERGUI::hideInternalWindows()
392 myProxyViewer->activateViewer(false);
396 QObject* aObj = myWorkshop->objectBrowser()->parent();
397 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
399 aObjDoc->setVisible(false);
400 myWorkshop->objectBrowser()->setVisible(false);
401 aObjDoc->toggleViewAction()->setVisible(false);
404 myInspectionPanel->hide();
405 myInspectionPanel->toggleViewAction()->setVisible(false);
407 myWorkshop->facesPanel()->hide();
408 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
410 myWorkshop->propertyPanel()->hide();
411 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
413 myWorkshop->hidePanel(myWorkshop->facesPanel());
417 //******************************************************
418 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
420 saveToolbarsConfig();
421 myWorkshop->deactivateModule();
423 myIsInspectionVisible = myInspectionPanel->isVisible();
424 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
425 hideInternalWindows();
428 // the active operation should be stopped for the next activation.
429 // There should not be active operation and visualized preview.
430 // Abort operation should be performed before the selection's remove
431 // because the displayed objects should be removed from the viewer, but
432 // the AIS context is obtained from the selector.
433 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
434 while (anOperation) {
435 anOperation->abort();
436 anOperation = myWorkshop->operationMgr()->currentOperation();
438 // Delete selector because it has to be redefined on next activation
440 // Restore size of arrows of trihedron
441 if (myAxisArrowRate > 0) {
442 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
443 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
444 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
445 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
446 aContext->Redisplay(aTrihedron, false);
448 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
449 myProxyViewer->setSelector(0);
451 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
452 QList<SUIT_Selector*> aList;
453 aMgr->selectors(aList);
454 foreach(SUIT_Selector* aSel, aList) {
455 aSel->setEnabled(aSel != mySelector);
462 //myWorkshop->contextMenuMgr()->disconnectViewer();
464 getApp()->setEditEnabled(myIsEditEnabled);
466 myOldSelectionColor.clear();
468 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
469 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
470 this, SLOT(onScriptLoaded()));
472 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
473 this, SLOT(onSaveDocByShaper()));
474 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
475 this, SLOT(onSaveAsDocByShaper()));
477 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
478 getApp(), SLOT(onSaveDoc()));
479 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
480 getApp(), SLOT(onSaveAsDoc()));
484 return LightApp_Module::deactivateModule(theStudy);
487 //******************************************************
488 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
491 mySelector = createSelector(theMgr);
492 myWorkshop->selectionActivate()->updateSelectionFilters();
493 myWorkshop->selectionActivate()->updateSelectionModes();
494 myWorkshop->synchronizeViewer();
498 //******************************************************
499 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
502 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
503 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
504 if (mySelector->viewer() == aViewer) {
505 XGUI_Displayer* aDisp = myWorkshop->displayer();
506 QObjectPtrList aObjects = aDisp->displayedObjects();
508 foreach(ObjectPtr aObj, aObjects) {
509 aObj->setDisplayed(false);
510 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
512 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
513 aRes->setDisplayed(false);
517 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
518 myProxyViewer->setSelector(0);
522 myWorkshop->module()->clearViewer();
528 //******************************************************
529 QtxPopupMgr* SHAPERGUI::popupMgr()
532 myPopupMgr = new QtxPopupMgr( 0, this );
536 //******************************************************
537 void SHAPERGUI::onDefaultPreferences()
539 // reset main resources
540 ModuleBase_Preferences::resetResourcePreferences(preferences());
541 // reset plugin's resources
542 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
544 myWorkshop->displayer()->redisplayObjects();
547 //******************************************************
548 void SHAPERGUI::onScriptLoaded()
550 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
551 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
552 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
553 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
554 // it manually (because this method of application is protected)
555 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
558 myWorkshop->displayer()->updateViewer();
559 myWorkshop->updateCommandStatus();
562 //******************************************************
563 void SHAPERGUI::onSaveDocByShaper()
565 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
568 getApp()->onSaveDoc();
571 //******************************************************
572 void SHAPERGUI::onSaveAsDocByShaper()
574 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
577 getApp()->onSaveAsDoc();
580 //******************************************************
581 void SHAPERGUI::onUpdateCommandStatus()
583 getApp()->updateActions();
585 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
586 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
587 if (aInfoPanel->isVisible())
591 //******************************************************
592 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
594 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
595 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
597 // Remember current length of arrow of axis
598 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
599 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
600 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
602 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
603 getApp()->selectionMgr());
604 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
605 aViewer->setUseLocalSelection(true);
607 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
608 QList<SUIT_Selector*> aList;
609 aMgr->selectors(aList);
610 foreach(SUIT_Selector* aSel, aList)
612 aSel->setEnabled(aSel == aSelector);
614 myProxyViewer->setSelector(aSelector);
616 if (myOldSelectionColor.size() == 0)
617 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
619 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
620 myWorkshop->displayer()->setSelectionColor(aColor);
622 // Cause scaling of arrows of axis and dimensions
623 myWorkshop->module()->onViewTransformed();
630 //******************************************************
631 CAM_DataModel* SHAPERGUI::createDataModel()
633 return new SHAPERGUI_DataModel(this);
636 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
637 const bool isAddSeparator)
639 return addFeature(theWBName,
643 //Issue #650: in the SALOME mode the tooltip should be same as text
652 //******************************************************
653 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
654 const QString& theId, const QString& theTitle, const QString& theTip,
655 const QIcon& theIcon, const QKeySequence& theKeys,
656 bool isCheckable, const bool isAddSeparator,
657 const QString& theStatusTip)
659 static QString aLastTool = "";
661 if (aLastTool.isEmpty())
662 aLastTool = theWBName;
663 else if (theWBName != aLastTool) {
664 aLastTool = theWBName;
666 desktop()->addToolBarBreak();
672 int aId = getNextCommandId();
673 myActionsList.append(aId);
674 SUIT_Desktop* aDesk = application()->desktop();
676 for (int i = 0; i < theKeys.count(); i++)
678 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
680 aAction->setStatusTip(theStatusTip);
682 aAction->setData(theId);
684 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
686 if( theId == "PointCoordinates" )
687 createMenu(separator(), aWBMenu);
692 createMenu(aId, aWBMenu);
695 createMenu(separator(), aWBMenu);
697 int aWBTool = createTool(theTBName, theTBName);
701 createTool(aId, aWBTool);
702 registerCommandToolbar(theTBName, aId);
703 if (isAddSeparator) {
704 createTool(separator(), aWBTool);
705 registerCommandToolbar(theTBName, -1);
710 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
712 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
715 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
716 const ActionInfo& theInfo,
717 const QList<QAction*>& theNestedActions)
719 SUIT_Desktop* aDesk = application()->desktop();
720 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
721 anAction->setData(theInfo.id);
722 anAction->setCheckable(theInfo.checkable);
723 anAction->setChecked(theInfo.checked);
724 anAction->setEnabled(theInfo.enabled);
725 anAction->setVisible(theInfo.visible);
726 anAction->setIcon(theInfo.icon);
727 anAction->setText(theInfo.text);
728 anAction->setToolTip(theInfo.toolTip);
729 anAction->setShortcut(theInfo.shortcut);
730 anAction->setFont(theInfo.font);
732 int aWBMenu = createMenu(theWBName, -1, -1, 30);
733 int aItemId = createMenu(anAction, aWBMenu);
734 myActionsList.append(aItemId);
735 createMenu(separator(), aWBMenu); /// nested action is always separated of others
737 int aWBTool = createTool(theWBName, theWBName);
741 createTool(anAction, aWBTool);
742 registerCommandToolbar(theWBName, aItemId);
743 createTool(separator(), aWBTool); /// nested action is always separated of others
744 registerCommandToolbar(theWBName, -1);
750 //******************************************************
751 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
752 const QString& theTip, const QIcon& theIcon,
753 const QKeySequence& theKeys, bool isCheckable,
754 const char* theMenuSourceText,
755 const QString& theSubMenu,
756 const int theMenuPosition,
757 const int theSuibMenuPosition)
759 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
760 if (!theSubMenu.isNull())
761 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
763 int aId = getNextCommandId();
764 myActionsList.append(aId);
765 SUIT_Desktop* aDesk = application()->desktop();
767 for (int i = 0; i < theKeys.count(); i++)
769 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
771 aAction->setStatusTip(theTip);
772 aAction->setData(theId);
773 createMenu(aId, aMenu, theMenuPosition);
777 //******************************************************
778 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
780 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
781 createMenu(separator(), aMenu, -1, theMenuPosition);
784 //******************************************************
785 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
790 SUIT_Desktop* aDesktop = application()->desktop();
794 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
798 aToolMgr->append( theAction, theToolBarTitle );
802 //******************************************************
803 QList<QAction*> SHAPERGUI::commandList() const
805 QList<QAction*> aActions;
806 foreach (int aId, myActionsList) {
807 QAction* aCmd = action(aId);
809 aActions.append(aCmd);
815 //******************************************************
816 QMainWindow* SHAPERGUI::desktop() const
818 return application()->desktop();
821 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
822 const std::shared_ptr<Config_FeatureMessage>& theMessage)
824 myFeaturesInfo.insert(theFeatureId, theMessage);
827 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
829 std::shared_ptr<Config_FeatureMessage> aMessage;
830 if (myFeaturesInfo.contains(theFeatureId))
831 aMessage = myFeaturesInfo[theFeatureId];
835 //******************************************************
836 void SHAPERGUI::selectionChanged()
838 LightApp_Module::selectionChanged();
839 myWorkshop->salomeViewerSelectionChanged();
842 //******************************************************
843 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
845 myWorkshop->contextMenuMgr()->updateViewerMenu();
846 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
847 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
851 //******************************************************
852 void SHAPERGUI::createPreferences()
854 LightApp_Preferences* aPref = preferences();
857 ModuleBase_Preferences::updateConfigByResources();
858 QString aModName = moduleName();
860 QtxPreferenceItem* item = aPref->findItem(aModName, true );
861 if ( item && (!item->isEmpty() )) {
862 item->parentItem()->removeItem(item);
866 int catId = aPref->addPreference(aModName, -1 );
869 SHAPERGUI_PrefMgr aMgr(aPref, aModName);
870 ModuleBase_Preferences::createEditContent(&aMgr, catId);
872 int viewTab = aPref->addItem(tr("Viewer"), catId);
873 // Create other parameters group in viewer tab
874 int otherGroup = aPref->addItem(tr("Default selection"), viewTab);
875 aPref->setItemProperty("columns", 3, otherGroup);
876 aPref->addItem(tr("Faces"), otherGroup,
877 SUIT_PreferenceMgr::Bool,
878 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
879 aPref->addItem(tr("Edges"), otherGroup,
880 SUIT_PreferenceMgr::Bool,
881 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
882 aPref->addItem(tr("Vertices"), otherGroup,
883 SUIT_PreferenceMgr::Bool,
884 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
886 int sensitivityGroup = aPref->addItem(tr("Selection sensitivity"), viewTab);
887 aPref->setItemProperty("columns", 2, sensitivityGroup);
888 aPref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
889 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
890 aPref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
891 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
893 int highlightGroup = aPref->addItem(tr("Additional highlighting"), viewTab);
894 aPref->setItemProperty("columns", 2, highlightGroup);
895 aPref->addItem(tr("In 3d mode"), highlightGroup,
896 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
897 aPref->addItem(tr("In 2d mode"), highlightGroup,
898 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
900 int colorScaleGroup = aPref->addItem(tr("Color scale"), viewTab);
901 aPref->setItemProperty("columns", 4, colorScaleGroup);
902 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
903 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
904 aPref->setItemProperty("min", 0, aItem);
905 aPref->setItemProperty("max", 1, aItem);
906 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
907 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
908 aPref->setItemProperty("min", 0, aItem);
909 aPref->setItemProperty("max", 1, aItem);
910 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
911 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
912 aPref->setItemProperty("min", 0, aItem);
913 aPref->setItemProperty("max", 1, aItem);
914 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
915 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
916 aPref->setItemProperty("min", 0, aItem);
917 aPref->setItemProperty("max", 1, aItem);
918 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
919 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
920 aPref->setItemProperty("min", 0, aItem);
921 aPref->setItemProperty("max", 100, aItem);
922 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
923 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
924 aPref->setItemProperty("min", 0, aItem);
925 aPref->setItemProperty("max", 100, aItem);
926 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
927 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
929 int aGroupNamesGroup = aMgr.addPreference(tr("Group names display"), viewTab,
930 SUIT_PreferenceMgr::GroupBox , ModuleBase_Preferences::VIEWER_SECTION, "group_names_display");
931 aPref->setItemProperty("columns", 3, aGroupNamesGroup);
932 aMgr.addPreference(tr("Text font"), aGroupNamesGroup,
933 SUIT_PreferenceMgr::String, ModuleBase_Preferences::VIEWER_SECTION, "group_names_font");
934 aItem = aMgr.addPreference(tr("Text size"), aGroupNamesGroup,
935 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "group_names_size");
936 aPref->setItemProperty("min", 8, aItem);
937 aPref->setItemProperty("max", 100, aItem);
938 aItem = aMgr.addPreference(tr("Text color"), aGroupNamesGroup,
939 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "group_names_color");
944 //******************************************************
945 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
947 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
948 QString aVal = aResMgr->stringValue(theSection, theParam);
949 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
950 theParam.toStdString());
952 return; // invalid case, the property default value must be registered in XML file
953 std::string aValue = aVal.toStdString();
954 if (aValue.empty()) {
955 aValue = aProp->defaultValue();
956 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
958 LightApp_Preferences* aPref = preferences();
962 aProp->setValue(aValue);
964 if (theSection == "Visualization") {
965 if (theParam == "selection_color") {
966 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
967 myWorkshop->displayer()->setSelectionColor(aColor);
969 if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
971 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
972 if (!aTrihedron.IsNull()) {
973 bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
974 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
976 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
977 Handle(V3d_View) aView = aViewer->activeView();
980 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
981 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
982 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
983 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
984 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
985 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
986 aContext->Redisplay(aTrihedron, true);
989 else if (myAxisArrowRate > 0) {
990 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
991 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
992 aContext->Redisplay(aTrihedron, true);
998 else if (theSection == ModuleBase_Preferences::GENERAL_SECTION && theParam == "create_init_part") {
999 bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
1000 ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
1001 Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
1004 else if (theSection == ModuleBase_Preferences::VIEWER_SECTION &&
1005 theParam.startsWith("group_names_"))
1006 { // one of the group names parameter changed, so, update the groups names vizualization
1007 myWorkshop->updateGroupsText();
1008 myWorkshop->displayer()->updateViewer();
1010 myWorkshop->displayer()->redisplayObjects();
1013 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
1015 application()->putInfo(theInfo, theMSecs);
1018 bool SHAPERGUI::abortAllOperations()
1020 return workshop()->operationMgr()->abortAllOperations();
1023 void SHAPERGUI::createFeatureActions()
1025 myWorkshop->menuMgr()->createFeatureActions();
1028 void SHAPERGUI::onWhatIs(bool isToggled)
1030 if (sender() == myWhatIsAction) {
1031 QAction* aViewAct = myInspectionPanel->toggleViewAction();
1032 aViewAct->blockSignals(true);
1033 aViewAct->setChecked(isToggled);
1034 aViewAct->blockSignals(false);
1035 myInspectionPanel->setVisible(isToggled);
1038 myWhatIsAction->blockSignals(true);
1039 myWhatIsAction->setChecked(isToggled);
1040 myWhatIsAction->blockSignals(false);
1041 myInspectionPanel->setVisible(isToggled);
1045 void SHAPERGUI::updateModuleVisibilityState()
1047 LightApp_Module::updateModuleVisibilityState();
1048 onWhatIs(myIsInspectionVisible);
1050 // the following code is caused by #187 bug.
1051 // SALOME saves the dock widget positions before deactivateModule() and
1052 // load it after the module activation. So, if the panel is visible before
1053 // deactivate, it becomes visible after activate.
1054 // In order to avoid the visible property panel, we hide it here
1055 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
1057 myWorkshop->hidePanel(myWorkshop->propertyPanel());
1061 void SHAPERGUI::onEditToolbars()
1063 SHAPERGUI_ToolbarsDlg aDlg(this);
1064 if (aDlg.exec() == QDialog::Accepted) {
1068 updateToolbars(aDlg.result());
1072 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1074 if (!myToolbars.contains(theToolName))
1075 myToolbars[theToolName] = QList<int>();
1076 myToolbars[theToolName].append(theCommandId);
1079 int SHAPERGUI::getNextCommandId() const
1081 QtxActionMenuMgr* aMenuMgr = menuMgr();
1082 QIntList aIds = aMenuMgr->idList();
1083 int aId = aIds.count();
1084 while (action(aId) || myActionsList.contains(aId))
1089 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1091 // Store default toolbars
1092 if (myDefaultToolbars.size() == 0)
1093 myDefaultToolbars = myToolbars;
1095 QtxActionToolMgr* aMgr = toolMgr();
1096 QStringList aToolbars = theNewToolbars.keys();
1097 QIntList aCommands, aOldCmd;
1101 foreach(QString aName, aToolbars) {
1102 aCommands = theNewToolbars[aName];
1103 // Find or create toolbar
1104 if (aMgr->hasToolBar(aName)) {
1105 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1106 aOldCmd = myToolbars[aName];
1109 aToolbarId = aMgr->createToolBar(aName);
1112 foreach(int aCmd, aCommands) {
1115 aAction = separator();
1117 aAction = action(aCmd);
1118 aActionId = aMgr->actionId(aAction);
1119 if (aActionId == -1) {
1121 aMgr->insert(aAction, aToolbarId, aPos);
1124 // Change position of action
1125 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1126 if (aMgr->containsAction(aActionId, aToolbarId))
1127 aMgr->remove(aActionId, aToolbarId);
1128 aMgr->insert(aActionId, aToolbarId, aPos);
1131 aOldCmd.removeAll(aCmd);
1134 // remove extra actions
1135 foreach(int aCmd, aOldCmd) {
1136 aAction = action(aCmd);
1137 aActionId = aMgr->actionId(aAction);
1138 aMgr->remove(aActionId, aToolbarId);
1140 myToolbars.remove(aName);
1142 // Remove extra toolbars
1143 aToolbars = myToolbars.keys();
1144 foreach(QString aName, aToolbars) {
1145 aMgr->removeToolBar(aName);
1147 // Set new toolbars structure
1148 myToolbars = theNewToolbars;
1149 myIsToolbarsModified = true;
1152 void SHAPERGUI::saveToolbarsConfig()
1154 if (!myIsToolbarsModified)
1156 // Save toolbars configuration into map
1157 QMap<QString, QStringList> aToolbarsConfig;
1159 QtxActionToolMgr* aMgr =
1162 QStringList aToolbars = myToolbars.keys();
1163 QIntList aActionsIds;
1164 foreach(QString aName, aToolbars) {
1165 aActionsIds = myToolbars[aName];
1166 QStringList aContent;
1167 foreach(int aId, aActionsIds) {
1169 aContent.append("");
1171 aContent.append(action(aId)->data().toString());
1173 aToolbarsConfig[aName] = aContent;
1175 // Store the configuration into resources
1176 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1177 QStringList aNames = aToolbarsConfig.keys();
1178 QStringList aValues;
1179 foreach(QString aToolbar, aNames) {
1180 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1182 // Remove obsolete parameters from resources
1183 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1184 foreach(QString aName, aOldParams) {
1185 if (!aToolbars.contains(aName))
1186 aResMgr->remove(ToolbarsSection, aName);
1188 // Store current list of free commands
1189 QIntList aFreeCommands = getFreeCommands();
1190 QStringList aFreeList;
1191 foreach(int aId, aFreeCommands) {
1192 aFreeList.append(action(aId)->data().toString());
1194 if (aFreeList.size() > 0)
1195 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1197 myIsToolbarsModified = false;
1200 void SHAPERGUI::loadToolbarsConfig()
1202 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1203 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1204 if (aToolbarNames.size() == 0)
1207 // Create commands map
1208 QMap<QString, int> aCommandsMap;
1210 foreach(int aId, myActionsList) {
1211 aCmdIdStr = action(aId)->data().toString();
1212 aCommandsMap[aCmdIdStr] = aId;
1215 // Create new toolbars structure
1216 QMap<QString, QIntList> aToolbars;
1217 QStringList aCommands;
1218 QIntList aKnownCommands;
1219 QList<QAction*> aActions;
1220 foreach(QString aName, aToolbarNames) {
1221 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1222 if (aName == FreeCommandsParam) {
1223 // The value is a list of free commands
1224 foreach(QString aCommand, aCommands) {
1225 aKnownCommands.append(aCommandsMap[aCommand]);
1229 aToolbars[aName] = QIntList();
1230 if (aCommands.size() > 0) {
1231 foreach(QString aCommand, aCommands) {
1232 if (aCommand.isEmpty())
1233 aToolbars[aName].append(-1);
1234 else if (aCommandsMap.contains(aCommand)) {
1235 int aId = aCommandsMap[aCommand];
1236 aToolbars[aName].append(aId);
1237 aKnownCommands.append(aId);
1243 // Find new and obsolete commands
1244 QIntList aNewCommands = myActionsList;
1245 foreach(int aId, myActionsList) {
1246 if (aKnownCommands.contains(aId)) {
1247 aKnownCommands.removeAll(aId);
1248 aNewCommands.removeAll(aId);
1251 if (aNewCommands.size() > 0) {
1252 // Add new commands to toolbars structure
1253 QStringList aKeys = myToolbars.keys();
1254 foreach(int aNewId, aNewCommands) {
1255 foreach(QString aName, aKeys) {
1256 if (myToolbars[aName].contains(aNewId)) {
1257 if (!aToolbars.contains(aName)) {
1258 aToolbars[aName] = QIntList();
1260 aToolbars[aName].append(aNewId);
1265 if (aKnownCommands.size() > 0) {
1266 // Remove obsolete commands from the toolbars structure
1267 QStringList aKeys = aToolbars.keys();
1268 foreach(int aOldId, aKnownCommands) {
1269 foreach(QString aName, aKeys) {
1270 if (aToolbars[aName].contains(aOldId)) {
1271 aToolbars[aName].removeAll(aOldId);
1272 if (aToolbars[aName].size() == 0)
1273 aToolbars.remove(aName);
1278 updateToolbars(aToolbars);
1279 myIsToolbarsModified = false;
1283 QIntList SHAPERGUI::getFreeCommands() const
1285 QIntList aFreeCommands;
1286 QtxActionToolMgr* aMgr = toolMgr();
1289 QMap<QString, QIntList>::const_iterator aIt;
1290 QIntList aShaperActions = shaperActions();
1291 foreach(int aCmd, aShaperActions) {
1292 anAction = action(aCmd);
1293 aId = aMgr->actionId(anAction);
1294 if (!aMgr->containsAction(aId))
1295 aFreeCommands.append(aCmd);
1297 return aFreeCommands;
1300 void SHAPERGUI::resetToolbars()
1302 if (!myDefaultToolbars.isEmpty())
1303 updateToolbars(myDefaultToolbars);
1304 myIsToolbarsModified = false;
1305 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1306 aResMgr->remove(ToolbarsSection);
1309 void SHAPERGUI::publishToStudy()
1311 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) {
1312 myWorkshop->module()->launchOperation("PublishToStudy", false);
1314 // update SHAPERSTUDY objects in OCC and VTK viewers
1315 QStringList aVMList;
1316 aVMList << "OCCViewer" << "VTKViewer";
1317 getApp()->updatePresentations("SHAPERSTUDY", aVMList);
1321 void SHAPERGUI::fillPartSetInfoPanel(QtxInfoPanel* theInfoPanel)
1323 QIntList aShaperActions = shaperActions();
1324 theInfoPanel->addLabel(tr("Current mode: Part set mode"));
1326 addActionsToInfoGroup(theInfoPanel, tr("Parts management"),
1327 { "Part", "Duplicate", "Remove" });
1328 addActionsToInfoGroup(theInfoPanel, tr("Import operations"),
1329 { "OPEN_CMD", "IMPORT_PART_CMD", "IMPORT_SHAPE_CMD" });
1330 addActionsToInfoGroup(theInfoPanel, tr("Export operations"),
1331 { "SAVEAS_CMD", "EXPORT_PART_CMD", "EXPORT_SHAPE_CMD" });
1332 addActionsToInfoGroup(theInfoPanel, tr("Arrangement of parts"),
1333 { "Placement", "Translation", "Rotation" });
1336 void SHAPERGUI::fillPartInfoPanel(QtxInfoPanel* theInfoPanel)
1338 QIntList aShaperActions = shaperActions();
1339 theInfoPanel->addLabel(tr("Current mode: Part mode"));
1341 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1342 { "Box", "Cylinder", "Sphere" });
1343 addActionsToInfoGroup(theInfoPanel, tr("Geometry"),
1344 { "Vertex", "Edge", "Wire", "Face" });
1345 addActionsToInfoGroup(theInfoPanel, tr("Features"),
1346 { "Extrusion", "Revolution", "Cut", "Fuse", "Fillet" });
1349 void SHAPERGUI::fillSketcherInfoPanel(QtxInfoPanel* theInfoPanel)
1351 QIntList aShaperActions = shaperActions();
1352 theInfoPanel->addLabel(tr("Current mode: Sketcher mode"));
1354 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1355 { "SketchPoint", "SketchLine", "SketchCircle", "SketchRectangle" });
1356 addActionsToInfoGroup(theInfoPanel, tr("Dimensions"),
1357 { "SketchConstraintLength", "SketchConstraintRadius", "SketchConstraintAngle" });
1358 addActionsToInfoGroup(theInfoPanel, tr("Constraints"),
1359 { "SketchConstraintParallel", "SketchConstraintPerpendicular",
1360 "SketchConstraintEqual", "SketchConstraintCoincidence" });
1363 void SHAPERGUI::addActionsToInfoGroup(QtxInfoPanel* theInfoPanel,
1364 const QString& theGroup, const QSet<QString>& theActions)
1366 QIntList aShaperActions = shaperActions();
1368 int aGroup = theInfoPanel->addGroup(theGroup);
1370 foreach(int aCmd, aShaperActions) {
1371 QAction* aAction = action(aCmd);
1372 if (theActions.contains(aAction->data().toString()))
1374 theInfoPanel->addAction(aAction, aGroup);
1377 if (aCount >= theActions.size())
1382 void SHAPERGUI::updateInfoPanel()
1384 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
1385 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
1386 aInfoPanel->clear();
1387 aInfoPanel->setTitle(tr("Welcome to SHAPER"));
1389 SessionPtr aMgr = ModelAPI_Session::get();
1390 QList<DocumentPtr> aDocs;
1391 DocumentPtr aActiveDoc = aMgr->activeDocument();
1392 DocumentPtr aModuleDoc = aMgr->moduleDocument();
1394 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
1395 QStringList aOpList = aOpMgr->operationList();
1396 bool isSketcher = false;
1397 if (aOpList.size() > 0)
1398 isSketcher = (aOpList.first() == "Sketch");
1400 if (isSketcher) // Sketcher mode
1401 fillSketcherInfoPanel(aInfoPanel);
1402 else if (aActiveDoc == aModuleDoc) // Part set mode
1403 fillPartSetInfoPanel(aInfoPanel);
1405 fillPartInfoPanel(aInfoPanel);