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 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
334 myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
335 myIsEditEnabled = getApp()->isEditEnabled();
336 getApp()->setEditEnabled(false);
338 // Synchronize displayed objects
339 Handle(AIS_InteractiveContext) aContext;
340 if (mySelector && mySelector->viewer())
341 aContext = mySelector->viewer()->getAISContext();
343 if (!aContext.IsNull()) {
344 XGUI_Displayer* aDisp = myWorkshop->displayer();
345 QObjectPtrList aObjList = aDisp->displayedObjects();
347 if (myOldSelectionColor.size() == 0)
348 myOldSelectionColor = aDisp->selectionColor();
350 AIS_ListOfInteractive aList;
351 aContext->DisplayedObjects(aList);
352 AIS_ListIteratorOfListOfInteractive aLIt;
353 Handle(AIS_InteractiveObject) anAISIO;
354 foreach (ObjectPtr aObj, aObjList) {
355 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
356 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
358 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
359 anAISIO = aLIt.Value();
360 if (anAISIO.get() == aAIS.get()) {
366 aObj->setDisplayed(false);
367 //aDisp->erase(aObj, false);
370 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
372 myProxyViewer->activateViewer(true);
374 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
375 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
376 this, SLOT(onScriptLoaded()));
378 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
379 getApp(), SLOT(onSaveDoc()));
380 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
381 getApp(), SLOT(onSaveAsDoc()));
383 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
384 this, SLOT(onSaveDocByShaper()));
385 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
386 this, SLOT(onSaveAsDocByShaper()));
391 //******************************************************
392 void SHAPERGUI::hideInternalWindows()
394 myProxyViewer->activateViewer(false);
398 QObject* aObj = myWorkshop->objectBrowser()->parent();
399 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
401 aObjDoc->setVisible(false);
402 myWorkshop->objectBrowser()->setVisible(false);
403 aObjDoc->toggleViewAction()->setVisible(false);
406 myInspectionPanel->hide();
407 myInspectionPanel->toggleViewAction()->setVisible(false);
409 myWorkshop->facesPanel()->hide();
410 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
412 myWorkshop->propertyPanel()->hide();
413 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
415 myWorkshop->hidePanel(myWorkshop->facesPanel());
419 //******************************************************
420 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
422 saveToolbarsConfig();
423 myWorkshop->deactivateModule();
425 myIsInspectionVisible = myInspectionPanel->isVisible();
426 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
427 hideInternalWindows();
430 // the active operation should be stopped for the next activation.
431 // There should not be active operation and visualized preview.
432 // Abort operation should be performed before the selection's remove
433 // because the displayed objects should be removed from the viewer, but
434 // the AIS context is obtained from the selector.
435 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
436 while (anOperation) {
437 anOperation->abort();
438 anOperation = myWorkshop->operationMgr()->currentOperation();
440 // Delete selector because it has to be redefined on next activation
442 // Restore size of arrows of trihedron
443 if (myAxisArrowRate > 0) {
444 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
445 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
446 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
447 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
448 aContext->Redisplay(aTrihedron, false);
450 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
451 myProxyViewer->setSelector(0);
453 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
454 QList<SUIT_Selector*> aList;
455 aMgr->selectors(aList);
456 foreach(SUIT_Selector* aSel, aList) {
457 aSel->setEnabled(aSel != mySelector);
464 //myWorkshop->contextMenuMgr()->disconnectViewer();
466 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
467 aResMgr->setValue("Study", "store_positions", myIsStorePositions);
468 getApp()->setEditEnabled(myIsEditEnabled);
470 myOldSelectionColor.clear();
472 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
473 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
474 this, SLOT(onScriptLoaded()));
476 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
477 this, SLOT(onSaveDocByShaper()));
478 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
479 this, SLOT(onSaveAsDocByShaper()));
481 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
482 getApp(), SLOT(onSaveDoc()));
483 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
484 getApp(), SLOT(onSaveAsDoc()));
488 return LightApp_Module::deactivateModule(theStudy);
491 //******************************************************
492 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
495 mySelector = createSelector(theMgr);
496 myWorkshop->selectionActivate()->updateSelectionFilters();
497 myWorkshop->selectionActivate()->updateSelectionModes();
498 myWorkshop->synchronizeViewer();
502 //******************************************************
503 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
506 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
507 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
508 if (mySelector->viewer() == aViewer) {
509 XGUI_Displayer* aDisp = myWorkshop->displayer();
510 QObjectPtrList aObjects = aDisp->displayedObjects();
512 foreach(ObjectPtr aObj, aObjects) {
513 aObj->setDisplayed(false);
514 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
516 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
517 aRes->setDisplayed(false);
521 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
522 myProxyViewer->setSelector(0);
526 myWorkshop->module()->clearViewer();
532 //******************************************************
533 QtxPopupMgr* SHAPERGUI::popupMgr()
536 myPopupMgr = new QtxPopupMgr( 0, this );
540 //******************************************************
541 void SHAPERGUI::onDefaultPreferences()
543 // reset main resources
544 ModuleBase_Preferences::resetResourcePreferences(preferences());
545 // reset plugin's resources
546 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
548 myWorkshop->displayer()->redisplayObjects();
551 //******************************************************
552 void SHAPERGUI::onScriptLoaded()
554 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
555 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
556 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
557 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
558 // it manually (because this method of application is protected)
559 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
562 myWorkshop->displayer()->updateViewer();
563 myWorkshop->updateCommandStatus();
566 //******************************************************
567 void SHAPERGUI::onSaveDocByShaper()
569 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
572 getApp()->onSaveDoc();
575 //******************************************************
576 void SHAPERGUI::onSaveAsDocByShaper()
578 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
581 getApp()->onSaveAsDoc();
584 //******************************************************
585 void SHAPERGUI::onUpdateCommandStatus()
587 getApp()->updateActions();
589 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
590 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
591 if (aInfoPanel->isVisible())
595 //******************************************************
596 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
598 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
599 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
601 // Remember current length of arrow of axis
602 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
603 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
604 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
606 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
607 getApp()->selectionMgr());
608 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
609 aViewer->setUseLocalSelection(true);
611 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
612 QList<SUIT_Selector*> aList;
613 aMgr->selectors(aList);
614 foreach(SUIT_Selector* aSel, aList)
616 aSel->setEnabled(aSel == aSelector);
618 myProxyViewer->setSelector(aSelector);
620 if (myOldSelectionColor.size() == 0)
621 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
623 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
624 myWorkshop->displayer()->setSelectionColor(aColor);
626 // Cause scaling of arrows of axis and dimensions
627 myWorkshop->module()->onViewTransformed();
634 //******************************************************
635 CAM_DataModel* SHAPERGUI::createDataModel()
637 return new SHAPERGUI_DataModel(this);
640 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
641 const bool isAddSeparator)
643 return addFeature(theWBName,
647 //Issue #650: in the SALOME mode the tooltip should be same as text
656 //******************************************************
657 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
658 const QString& theId, const QString& theTitle, const QString& theTip,
659 const QIcon& theIcon, const QKeySequence& theKeys,
660 bool isCheckable, const bool isAddSeparator,
661 const QString& theStatusTip)
663 static QString aLastTool = "";
665 if (aLastTool.isEmpty())
666 aLastTool = theWBName;
667 else if (theWBName != aLastTool) {
668 aLastTool = theWBName;
670 desktop()->addToolBarBreak();
676 int aId = getNextCommandId();
677 myActionsList.append(aId);
678 SUIT_Desktop* aDesk = application()->desktop();
680 for (int i = 0; i < theKeys.count(); i++)
682 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
684 aAction->setStatusTip(theStatusTip);
686 aAction->setData(theId);
688 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
690 if( theId == "PointCoordinates" )
691 createMenu(separator(), aWBMenu);
696 createMenu(aId, aWBMenu);
699 createMenu(separator(), aWBMenu);
701 int aWBTool = createTool(theTBName, theTBName);
705 createTool(aId, aWBTool);
706 registerCommandToolbar(theTBName, aId);
707 if (isAddSeparator) {
708 createTool(separator(), aWBTool);
709 registerCommandToolbar(theTBName, -1);
714 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
716 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
719 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
720 const ActionInfo& theInfo,
721 const QList<QAction*>& theNestedActions)
723 SUIT_Desktop* aDesk = application()->desktop();
724 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
725 anAction->setData(theInfo.id);
726 anAction->setCheckable(theInfo.checkable);
727 anAction->setChecked(theInfo.checked);
728 anAction->setEnabled(theInfo.enabled);
729 anAction->setVisible(theInfo.visible);
730 anAction->setIcon(theInfo.icon);
731 anAction->setText(theInfo.text);
732 anAction->setToolTip(theInfo.toolTip);
733 anAction->setShortcut(theInfo.shortcut);
734 anAction->setFont(theInfo.font);
736 int aWBMenu = createMenu(theWBName, -1, -1, 30);
737 int aItemId = createMenu(anAction, aWBMenu);
738 myActionsList.append(aItemId);
739 createMenu(separator(), aWBMenu); /// nested action is always separated of others
741 int aWBTool = createTool(theWBName, theWBName);
745 createTool(anAction, aWBTool);
746 registerCommandToolbar(theWBName, aItemId);
747 createTool(separator(), aWBTool); /// nested action is always separated of others
748 registerCommandToolbar(theWBName, -1);
754 //******************************************************
755 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
756 const QString& theTip, const QIcon& theIcon,
757 const QKeySequence& theKeys, bool isCheckable,
758 const char* theMenuSourceText,
759 const QString& theSubMenu,
760 const int theMenuPosition,
761 const int theSuibMenuPosition)
763 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
764 if (!theSubMenu.isNull())
765 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
767 int aId = getNextCommandId();
768 myActionsList.append(aId);
769 SUIT_Desktop* aDesk = application()->desktop();
771 for (int i = 0; i < theKeys.count(); i++)
773 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
775 aAction->setStatusTip(theTip);
776 aAction->setData(theId);
777 createMenu(aId, aMenu, theMenuPosition);
781 //******************************************************
782 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
784 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
785 createMenu(separator(), aMenu, -1, theMenuPosition);
788 //******************************************************
789 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
794 SUIT_Desktop* aDesktop = application()->desktop();
798 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
802 aToolMgr->append( theAction, theToolBarTitle );
806 //******************************************************
807 QList<QAction*> SHAPERGUI::commandList() const
809 QList<QAction*> aActions;
810 foreach (int aId, myActionsList) {
811 QAction* aCmd = action(aId);
813 aActions.append(aCmd);
819 //******************************************************
820 QMainWindow* SHAPERGUI::desktop() const
822 return application()->desktop();
825 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
826 const std::shared_ptr<Config_FeatureMessage>& theMessage)
828 myFeaturesInfo.insert(theFeatureId, theMessage);
831 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
833 std::shared_ptr<Config_FeatureMessage> aMessage;
834 if (myFeaturesInfo.contains(theFeatureId))
835 aMessage = myFeaturesInfo[theFeatureId];
839 //******************************************************
840 void SHAPERGUI::selectionChanged()
842 LightApp_Module::selectionChanged();
843 myWorkshop->salomeViewerSelectionChanged();
846 //******************************************************
847 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
849 myWorkshop->contextMenuMgr()->updateViewerMenu();
850 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
851 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
855 //******************************************************
856 void SHAPERGUI::createPreferences()
858 LightApp_Preferences* aPref = preferences();
861 ModuleBase_Preferences::updateConfigByResources();
862 QString aModName = moduleName();
864 QtxPreferenceItem* item = aPref->findItem(aModName, true );
865 if ( item && (!item->isEmpty() )) {
866 item->parentItem()->removeItem(item);
870 int catId = aPref->addPreference(aModName, -1 );
873 SHAPERGUI_PrefMgr aMgr(aPref, aModName);
874 ModuleBase_Preferences::createEditContent(&aMgr, catId);
876 int viewTab = aPref->addItem(tr("Viewer"), catId);
877 // Create other parameters group in viewer tab
878 int otherGroup = aPref->addItem(tr("Default selection"), viewTab);
879 aPref->setItemProperty("columns", 3, otherGroup);
880 aPref->addItem(tr("Faces"), otherGroup,
881 SUIT_PreferenceMgr::Bool,
882 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
883 aPref->addItem(tr("Edges"), otherGroup,
884 SUIT_PreferenceMgr::Bool,
885 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
886 aPref->addItem(tr("Vertices"), otherGroup,
887 SUIT_PreferenceMgr::Bool,
888 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
890 int sensitivityGroup = aPref->addItem(tr("Selection sensitivity"), viewTab);
891 aPref->setItemProperty("columns", 2, sensitivityGroup);
892 aPref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
893 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
894 aPref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
895 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
897 int highlightGroup = aPref->addItem(tr("Additional highlighting"), viewTab);
898 aPref->setItemProperty("columns", 2, highlightGroup);
899 aPref->addItem(tr("In 3d mode"), highlightGroup,
900 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
901 aPref->addItem(tr("In 2d mode"), highlightGroup,
902 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
904 int colorScaleGroup = aPref->addItem(tr("Color scale"), viewTab);
905 aPref->setItemProperty("columns", 4, colorScaleGroup);
906 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
907 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
908 aPref->setItemProperty("min", 0, aItem);
909 aPref->setItemProperty("max", 1, aItem);
910 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
911 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
912 aPref->setItemProperty("min", 0, aItem);
913 aPref->setItemProperty("max", 1, aItem);
914 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
915 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
916 aPref->setItemProperty("min", 0, aItem);
917 aPref->setItemProperty("max", 1, aItem);
918 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
919 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
920 aPref->setItemProperty("min", 0, aItem);
921 aPref->setItemProperty("max", 1, aItem);
922 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
923 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
924 aPref->setItemProperty("min", 0, aItem);
925 aPref->setItemProperty("max", 100, aItem);
926 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
927 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
928 aPref->setItemProperty("min", 0, aItem);
929 aPref->setItemProperty("max", 100, aItem);
930 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
931 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
933 int aGroupNamesGroup = aMgr.addPreference(tr("Group names display"), viewTab,
934 SUIT_PreferenceMgr::GroupBox , ModuleBase_Preferences::VIEWER_SECTION, "group_names_display");
935 aPref->setItemProperty("columns", 3, aGroupNamesGroup);
936 aMgr.addPreference(tr("Text font"), aGroupNamesGroup,
937 SUIT_PreferenceMgr::String, ModuleBase_Preferences::VIEWER_SECTION, "group_names_font");
938 aItem = aMgr.addPreference(tr("Text size"), aGroupNamesGroup,
939 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "group_names_size");
940 aPref->setItemProperty("min", 8, aItem);
941 aPref->setItemProperty("max", 100, aItem);
942 aItem = aMgr.addPreference(tr("Text color"), aGroupNamesGroup,
943 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "group_names_color");
948 //******************************************************
949 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
951 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
952 QString aVal = aResMgr->stringValue(theSection, theParam);
953 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
954 theParam.toStdString());
956 return; // invalid case, the property default value must be registered in XML file
957 std::string aValue = aVal.toStdString();
958 if (aValue.empty()) {
959 aValue = aProp->defaultValue();
960 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
962 LightApp_Preferences* aPref = preferences();
966 aProp->setValue(aValue);
968 if (theSection == "Visualization") {
969 if (theParam == "selection_color") {
970 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
971 myWorkshop->displayer()->setSelectionColor(aColor);
973 if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
975 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
976 if (!aTrihedron.IsNull()) {
977 bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
978 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
980 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
981 Handle(V3d_View) aView = aViewer->activeView();
984 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
985 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
986 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
987 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
988 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
989 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
990 aContext->Redisplay(aTrihedron, true);
993 else if (myAxisArrowRate > 0) {
994 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
995 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
996 aContext->Redisplay(aTrihedron, true);
1002 else if (theSection == ModuleBase_Preferences::GENERAL_SECTION && theParam == "create_init_part") {
1003 bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
1004 ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
1005 Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
1008 else if (theSection == ModuleBase_Preferences::VIEWER_SECTION &&
1009 theParam.startsWith("group_names_"))
1010 { // one of the group names parameter changed, so, update the groups names vizualization
1011 myWorkshop->updateGroupsText();
1012 myWorkshop->displayer()->updateViewer();
1014 myWorkshop->displayer()->redisplayObjects();
1017 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
1019 application()->putInfo(theInfo, theMSecs);
1022 bool SHAPERGUI::abortAllOperations()
1024 return workshop()->operationMgr()->abortAllOperations();
1027 void SHAPERGUI::createFeatureActions()
1029 myWorkshop->menuMgr()->createFeatureActions();
1032 void SHAPERGUI::onWhatIs(bool isToggled)
1034 if (sender() == myWhatIsAction) {
1035 QAction* aViewAct = myInspectionPanel->toggleViewAction();
1036 aViewAct->blockSignals(true);
1037 aViewAct->setChecked(isToggled);
1038 aViewAct->blockSignals(false);
1039 myInspectionPanel->setVisible(isToggled);
1042 myWhatIsAction->blockSignals(true);
1043 myWhatIsAction->setChecked(isToggled);
1044 myWhatIsAction->blockSignals(false);
1045 myInspectionPanel->setVisible(isToggled);
1049 void SHAPERGUI::updateModuleVisibilityState()
1051 LightApp_Module::updateModuleVisibilityState();
1052 onWhatIs(myIsInspectionVisible);
1054 // the following code is caused by #187 bug.
1055 // SALOME saves the dock widget positions before deactivateModule() and
1056 // load it after the module activation. So, if the panel is visible before
1057 // deactivate, it becomes visible after activate.
1058 // In order to avoid the visible property panel, we hide it here
1059 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
1061 myWorkshop->hidePanel(myWorkshop->propertyPanel());
1065 void SHAPERGUI::onEditToolbars()
1067 SHAPERGUI_ToolbarsDlg aDlg(this);
1068 if (aDlg.exec() == QDialog::Accepted) {
1072 updateToolbars(aDlg.result());
1076 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1078 if (!myToolbars.contains(theToolName))
1079 myToolbars[theToolName] = QList<int>();
1080 myToolbars[theToolName].append(theCommandId);
1083 int SHAPERGUI::getNextCommandId() const
1085 QtxActionMenuMgr* aMenuMgr = menuMgr();
1086 QIntList aIds = aMenuMgr->idList();
1087 int aId = aIds.count();
1088 while (action(aId) || myActionsList.contains(aId))
1093 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1095 // Store default toolbars
1096 if (myDefaultToolbars.size() == 0)
1097 myDefaultToolbars = myToolbars;
1099 QtxActionToolMgr* aMgr = toolMgr();
1100 QStringList aToolbars = theNewToolbars.keys();
1101 QIntList aCommands, aOldCmd;
1105 foreach(QString aName, aToolbars) {
1106 aCommands = theNewToolbars[aName];
1107 // Find or create toolbar
1108 if (aMgr->hasToolBar(aName)) {
1109 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1110 aOldCmd = myToolbars[aName];
1113 aToolbarId = aMgr->createToolBar(aName);
1116 foreach(int aCmd, aCommands) {
1119 aAction = separator();
1121 aAction = action(aCmd);
1122 aActionId = aMgr->actionId(aAction);
1123 if (aActionId == -1) {
1125 aMgr->insert(aAction, aToolbarId, aPos);
1128 // Change position of action
1129 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1130 if (aMgr->containsAction(aActionId, aToolbarId))
1131 aMgr->remove(aActionId, aToolbarId);
1132 aMgr->insert(aActionId, aToolbarId, aPos);
1135 aOldCmd.removeAll(aCmd);
1138 // remove extra actions
1139 foreach(int aCmd, aOldCmd) {
1140 aAction = action(aCmd);
1141 aActionId = aMgr->actionId(aAction);
1142 aMgr->remove(aActionId, aToolbarId);
1144 myToolbars.remove(aName);
1146 // Remove extra toolbars
1147 aToolbars = myToolbars.keys();
1148 foreach(QString aName, aToolbars) {
1149 aMgr->removeToolBar(aName);
1151 // Set new toolbars structure
1152 myToolbars = theNewToolbars;
1153 myIsToolbarsModified = true;
1156 void SHAPERGUI::saveToolbarsConfig()
1158 if (!myIsToolbarsModified)
1160 // Save toolbars configuration into map
1161 QMap<QString, QStringList> aToolbarsConfig;
1163 QtxActionToolMgr* aMgr =
1166 QStringList aToolbars = myToolbars.keys();
1167 QIntList aActionsIds;
1168 foreach(QString aName, aToolbars) {
1169 aActionsIds = myToolbars[aName];
1170 QStringList aContent;
1171 foreach(int aId, aActionsIds) {
1173 aContent.append("");
1175 aContent.append(action(aId)->data().toString());
1177 aToolbarsConfig[aName] = aContent;
1179 // Store the configuration into resources
1180 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1181 QStringList aNames = aToolbarsConfig.keys();
1182 QStringList aValues;
1183 foreach(QString aToolbar, aNames) {
1184 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1186 // Remove obsolete parameters from resources
1187 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1188 foreach(QString aName, aOldParams) {
1189 if (!aToolbars.contains(aName))
1190 aResMgr->remove(ToolbarsSection, aName);
1192 // Store current list of free commands
1193 QIntList aFreeCommands = getFreeCommands();
1194 QStringList aFreeList;
1195 foreach(int aId, aFreeCommands) {
1196 aFreeList.append(action(aId)->data().toString());
1198 if (aFreeList.size() > 0)
1199 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1201 myIsToolbarsModified = false;
1204 void SHAPERGUI::loadToolbarsConfig()
1206 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1207 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1208 if (aToolbarNames.size() == 0)
1211 // Create commands map
1212 QMap<QString, int> aCommandsMap;
1214 foreach(int aId, myActionsList) {
1215 aCmdIdStr = action(aId)->data().toString();
1216 aCommandsMap[aCmdIdStr] = aId;
1219 // Create new toolbars structure
1220 QMap<QString, QIntList> aToolbars;
1221 QStringList aCommands;
1222 QIntList aKnownCommands;
1223 QList<QAction*> aActions;
1224 foreach(QString aName, aToolbarNames) {
1225 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1226 if (aName == FreeCommandsParam) {
1227 // The value is a list of free commands
1228 foreach(QString aCommand, aCommands) {
1229 aKnownCommands.append(aCommandsMap[aCommand]);
1233 aToolbars[aName] = QIntList();
1234 if (aCommands.size() > 0) {
1235 foreach(QString aCommand, aCommands) {
1236 if (aCommand.isEmpty())
1237 aToolbars[aName].append(-1);
1238 else if (aCommandsMap.contains(aCommand)) {
1239 int aId = aCommandsMap[aCommand];
1240 aToolbars[aName].append(aId);
1241 aKnownCommands.append(aId);
1247 // Find new and obsolete commands
1248 QIntList aNewCommands = myActionsList;
1249 foreach(int aId, myActionsList) {
1250 if (aKnownCommands.contains(aId)) {
1251 aKnownCommands.removeAll(aId);
1252 aNewCommands.removeAll(aId);
1255 if (aNewCommands.size() > 0) {
1256 // Add new commands to toolbars structure
1257 QStringList aKeys = myToolbars.keys();
1258 foreach(int aNewId, aNewCommands) {
1259 foreach(QString aName, aKeys) {
1260 if (myToolbars[aName].contains(aNewId)) {
1261 if (!aToolbars.contains(aName)) {
1262 aToolbars[aName] = QIntList();
1264 aToolbars[aName].append(aNewId);
1269 if (aKnownCommands.size() > 0) {
1270 // Remove obsolete commands from the toolbars structure
1271 QStringList aKeys = aToolbars.keys();
1272 foreach(int aOldId, aKnownCommands) {
1273 foreach(QString aName, aKeys) {
1274 if (aToolbars[aName].contains(aOldId)) {
1275 aToolbars[aName].removeAll(aOldId);
1276 if (aToolbars[aName].size() == 0)
1277 aToolbars.remove(aName);
1282 updateToolbars(aToolbars);
1283 myIsToolbarsModified = false;
1287 QIntList SHAPERGUI::getFreeCommands() const
1289 QIntList aFreeCommands;
1290 QtxActionToolMgr* aMgr = toolMgr();
1293 QMap<QString, QIntList>::const_iterator aIt;
1294 QIntList aShaperActions = shaperActions();
1295 foreach(int aCmd, aShaperActions) {
1296 anAction = action(aCmd);
1297 aId = aMgr->actionId(anAction);
1298 if (!aMgr->containsAction(aId))
1299 aFreeCommands.append(aCmd);
1301 return aFreeCommands;
1304 void SHAPERGUI::resetToolbars()
1306 if (!myDefaultToolbars.isEmpty())
1307 updateToolbars(myDefaultToolbars);
1308 myIsToolbarsModified = false;
1309 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1310 aResMgr->remove(ToolbarsSection);
1313 void SHAPERGUI::publishToStudy()
1315 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) {
1316 myWorkshop->module()->launchOperation("PublishToStudy", false);
1318 // update SHAPERSTUDY objects in OCC and VTK viewers
1319 QStringList aVMList;
1320 aVMList << "OCCViewer" << "VTKViewer";
1321 getApp()->updatePresentations("SHAPERSTUDY", aVMList);
1325 void SHAPERGUI::fillPartSetInfoPanel(QtxInfoPanel* theInfoPanel)
1327 QIntList aShaperActions = shaperActions();
1328 theInfoPanel->addLabel(tr("Current mode: Part set mode"));
1330 addActionsToInfoGroup(theInfoPanel, tr("Parts management"),
1331 { "Part", "Duplicate", "Remove" });
1332 addActionsToInfoGroup(theInfoPanel, tr("Import operations"),
1333 { "OPEN_CMD", "IMPORT_PART_CMD", "IMPORT_SHAPE_CMD" });
1334 addActionsToInfoGroup(theInfoPanel, tr("Export operations"),
1335 { "SAVEAS_CMD", "EXPORT_PART_CMD", "EXPORT_SHAPE_CMD" });
1336 addActionsToInfoGroup(theInfoPanel, tr("Arrangement of parts"),
1337 { "Placement", "Translation", "Rotation" });
1340 void SHAPERGUI::fillPartInfoPanel(QtxInfoPanel* theInfoPanel)
1342 QIntList aShaperActions = shaperActions();
1343 theInfoPanel->addLabel(tr("Current mode: Part mode"));
1345 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1346 { "Box", "Cylinder", "Sphere" });
1347 addActionsToInfoGroup(theInfoPanel, tr("Geometry"),
1348 { "Vertex", "Edge", "Wire", "Face" });
1349 addActionsToInfoGroup(theInfoPanel, tr("Features"),
1350 { "Extrusion", "Revolution", "Cut", "Fuse", "Fillet" });
1353 void SHAPERGUI::fillSketcherInfoPanel(QtxInfoPanel* theInfoPanel)
1355 QIntList aShaperActions = shaperActions();
1356 theInfoPanel->addLabel(tr("Current mode: Sketcher mode"));
1358 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1359 { "SketchPoint", "SketchLine", "SketchCircle", "SketchRectangle" });
1360 addActionsToInfoGroup(theInfoPanel, tr("Dimensions"),
1361 { "SketchConstraintLength", "SketchConstraintRadius", "SketchConstraintAngle" });
1362 addActionsToInfoGroup(theInfoPanel, tr("Constraints"),
1363 { "SketchConstraintParallel", "SketchConstraintPerpendicular",
1364 "SketchConstraintEqual", "SketchConstraintCoincidence" });
1367 void SHAPERGUI::addActionsToInfoGroup(QtxInfoPanel* theInfoPanel,
1368 const QString& theGroup, const QSet<QString>& theActions)
1370 QIntList aShaperActions = shaperActions();
1372 int aGroup = theInfoPanel->addGroup(theGroup);
1374 foreach(int aCmd, aShaperActions) {
1375 QAction* aAction = action(aCmd);
1376 if (theActions.contains(aAction->data().toString()))
1378 theInfoPanel->addAction(aAction, aGroup);
1381 if (aCount >= theActions.size())
1386 void SHAPERGUI::updateInfoPanel()
1388 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
1389 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
1390 aInfoPanel->clear();
1391 aInfoPanel->setTitle(tr("Welcome to SHAPER"));
1393 SessionPtr aMgr = ModelAPI_Session::get();
1394 QList<DocumentPtr> aDocs;
1395 DocumentPtr aActiveDoc = aMgr->activeDocument();
1396 DocumentPtr aModuleDoc = aMgr->moduleDocument();
1398 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
1399 QStringList aOpList = aOpMgr->operationList();
1400 bool isSketcher = false;
1401 if (aOpList.size() > 0)
1402 isSketcher = (aOpList.first() == "Sketch");
1404 if (isSketcher) // Sketcher mode
1405 fillSketcherInfoPanel(aInfoPanel);
1406 else if (aActiveDoc == aModuleDoc) // Part set mode
1407 fillPartSetInfoPanel(aInfoPanel);
1409 fillPartInfoPanel(aInfoPanel);