1 // Copyright (C) 2014-2023 CEA, EDF
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()));
387 //connect(myWorkshop->operationMgr(), SIGNAL(operationResumed(ModuleBase_Operation*)),
388 // this, SLOT(onOperationResumed(ModuleBase_Operation*)));
389 //connect(myWorkshop->operationMgr(), SIGNAL(operationStopped(ModuleBase_Operation*)),
390 // this, SLOT(onOperationStopped(ModuleBase_Operation*)));
391 connect(myWorkshop->operationMgr(), SIGNAL(operationCommitted(ModuleBase_Operation*)),
392 this, SLOT(onOperationCommitted(ModuleBase_Operation*)));
393 connect(myWorkshop->operationMgr(), SIGNAL(operationAborted(ModuleBase_Operation*)),
394 this, SLOT(onOperationAborted(ModuleBase_Operation*)));
399 //******************************************************
400 void SHAPERGUI::hideInternalWindows()
402 myProxyViewer->activateViewer(false);
406 QObject* aObj = myWorkshop->objectBrowser()->parent();
407 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
409 aObjDoc->setVisible(false);
410 myWorkshop->objectBrowser()->setVisible(false);
411 aObjDoc->toggleViewAction()->setVisible(false);
414 myInspectionPanel->hide();
415 myInspectionPanel->toggleViewAction()->setVisible(false);
417 myWorkshop->facesPanel()->hide();
418 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
420 myWorkshop->propertyPanel()->hide();
421 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
423 myWorkshop->hidePanel(myWorkshop->facesPanel());
427 //******************************************************
428 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
430 saveToolbarsConfig();
431 myWorkshop->deactivateModule();
433 myIsInspectionVisible = myInspectionPanel->isVisible();
434 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
435 hideInternalWindows();
438 // the active operation should be stopped for the next activation.
439 // There should not be active operation and visualized preview.
440 // Abort operation should be performed before the selection's remove
441 // because the displayed objects should be removed from the viewer, but
442 // the AIS context is obtained from the selector.
443 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
444 while (anOperation) {
445 anOperation->abort();
446 anOperation = myWorkshop->operationMgr()->currentOperation();
448 // Delete selector because it has to be redefined on next activation
450 // Restore size of arrows of trihedron
451 if (myAxisArrowRate > 0) {
452 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
453 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
454 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
455 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
456 aContext->Redisplay(aTrihedron, false);
458 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
459 myProxyViewer->setSelector(0);
461 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
462 QList<SUIT_Selector*> aList;
463 aMgr->selectors(aList);
464 foreach(SUIT_Selector* aSel, aList) {
465 aSel->setEnabled(aSel != mySelector);
472 //myWorkshop->contextMenuMgr()->disconnectViewer();
474 getApp()->setEditEnabled(myIsEditEnabled);
476 myOldSelectionColor.clear();
478 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
479 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
480 this, SLOT(onScriptLoaded()));
482 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
483 this, SLOT(onSaveDocByShaper()));
484 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
485 this, SLOT(onSaveAsDocByShaper()));
487 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
488 getApp(), SLOT(onSaveDoc()));
489 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
490 getApp(), SLOT(onSaveAsDoc()));
494 return LightApp_Module::deactivateModule(theStudy);
497 //******************************************************
498 void SHAPERGUI::logShaperGUIEvent()
500 QAction* anAction = static_cast<QAction*>(sender());
503 QString anId = anAction->data().toString();
504 QStringList message = (QStringList() << moduleName());
505 if (anId.contains("Sketch"))
506 message << tr("sketcher");
507 message << tr("operation %1 has been activated").arg(anAction->text());
508 CAM_Application::logUserEvent(message.join(": "));
511 //******************************************************
512 void SHAPERGUI::onOperationCommitted(ModuleBase_Operation* theOperation)
514 QStringList message = (QStringList() << moduleName());
515 QString anId = theOperation->id();
516 if (anId.contains("Sketch"))
518 message << tr("sketcher");
519 anId.remove("Sketch");
521 message << tr("operation %1 has been committed").arg(anId);
522 CAM_Application::logUserEvent(message.join(": "));
525 //******************************************************
526 void SHAPERGUI::onOperationAborted(ModuleBase_Operation* theOperation)
528 QStringList message = (QStringList() << moduleName());
529 QString anId = theOperation->id();
530 if (anId.contains("Sketch"))
532 message << tr("sketcher");
533 anId.remove("Sketch");
535 message << tr("operation %1 has been aborted").arg(anId);
536 CAM_Application::logUserEvent(message.join(": "));
539 //******************************************************
540 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
543 mySelector = createSelector(theMgr);
544 myWorkshop->selectionActivate()->updateSelectionFilters();
545 myWorkshop->selectionActivate()->updateSelectionModes();
546 myWorkshop->synchronizeViewer();
550 //******************************************************
551 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
554 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
555 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
556 if (mySelector->viewer() == aViewer) {
557 XGUI_Displayer* aDisp = myWorkshop->displayer();
558 QObjectPtrList aObjects = aDisp->displayedObjects();
560 foreach(ObjectPtr aObj, aObjects) {
561 aObj->setDisplayed(false);
562 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
564 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
565 aRes->setDisplayed(false);
569 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
570 myProxyViewer->setSelector(0);
574 myWorkshop->module()->clearViewer();
580 //******************************************************
581 QtxPopupMgr* SHAPERGUI::popupMgr()
584 myPopupMgr = new QtxPopupMgr( 0, this );
588 //******************************************************
589 void SHAPERGUI::onDefaultPreferences()
591 // reset main resources
592 ModuleBase_Preferences::resetResourcePreferences(preferences());
593 // reset plugin's resources
594 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
596 myWorkshop->displayer()->redisplayObjects();
599 //******************************************************
600 void SHAPERGUI::onScriptLoaded()
602 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
603 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
604 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
605 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
606 // it manually (because this method of application is protected)
607 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
610 myWorkshop->displayer()->updateViewer();
611 myWorkshop->updateCommandStatus();
614 //******************************************************
615 void SHAPERGUI::onSaveDocByShaper()
617 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
620 getApp()->onSaveDoc();
623 //******************************************************
624 void SHAPERGUI::onSaveAsDocByShaper()
626 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
629 getApp()->onSaveAsDoc();
632 //******************************************************
633 void SHAPERGUI::onUpdateCommandStatus()
635 getApp()->updateActions();
637 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
638 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
639 if (aInfoPanel->isVisible())
643 //******************************************************
644 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
646 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
647 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
649 // Remember current length of arrow of axis
650 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
651 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
652 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
654 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
655 getApp()->selectionMgr());
656 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
657 aViewer->setUseLocalSelection(true);
659 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
660 QList<SUIT_Selector*> aList;
661 aMgr->selectors(aList);
662 foreach(SUIT_Selector* aSel, aList)
664 aSel->setEnabled(aSel == aSelector);
666 myProxyViewer->setSelector(aSelector);
668 if (myOldSelectionColor.size() == 0)
669 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
671 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
672 myWorkshop->displayer()->setSelectionColor(aColor);
674 // Cause scaling of arrows of axis and dimensions
675 myWorkshop->module()->onViewTransformed();
682 //******************************************************
683 CAM_DataModel* SHAPERGUI::createDataModel()
685 return new SHAPERGUI_DataModel(this);
688 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
689 const bool isAddSeparator)
691 return addFeature(theWBName,
695 //Issue #650: in the SALOME mode the tooltip should be same as text
704 //******************************************************
705 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
706 const QString& theId, const QString& theTitle, const QString& theTip,
707 const QIcon& theIcon, const QKeySequence& theKeys,
708 bool isCheckable, const bool isAddSeparator,
709 const QString& theStatusTip)
711 static QString aLastTool = "";
713 if (aLastTool.isEmpty())
714 aLastTool = theWBName;
715 else if (theWBName != aLastTool) {
716 aLastTool = theWBName;
718 desktop()->addToolBarBreak();
724 int aId = getNextCommandId();
725 myActionsList.append(aId);
726 SUIT_Desktop* aDesk = application()->desktop();
728 for (int i = 0; i < theKeys.count(); i++)
730 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
732 aAction->setStatusTip(theStatusTip);
734 aAction->setData(theId);
736 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
738 if( theId == "PointCoordinates" )
739 createMenu(separator(), aWBMenu);
744 createMenu(aId, aWBMenu);
747 createMenu(separator(), aWBMenu);
749 int aWBTool = createTool(theTBName, theTBName);
753 createTool(aId, aWBTool);
754 registerCommandToolbar(theTBName, aId);
755 if (isAddSeparator) {
756 createTool(separator(), aWBTool);
757 registerCommandToolbar(theTBName, -1);
759 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(logShaperGUIEvent()));
763 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
765 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
768 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
769 const ActionInfo& theInfo,
770 const QList<QAction*>& theNestedActions)
772 SUIT_Desktop* aDesk = application()->desktop();
773 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
774 anAction->setData(theInfo.id);
775 anAction->setCheckable(theInfo.checkable);
776 anAction->setChecked(theInfo.checked);
777 anAction->setEnabled(theInfo.enabled);
778 anAction->setVisible(theInfo.visible);
779 anAction->setIcon(theInfo.icon);
780 anAction->setText(theInfo.text);
781 anAction->setToolTip(theInfo.toolTip);
782 anAction->setShortcut(theInfo.shortcut);
783 anAction->setFont(theInfo.font);
785 int aWBMenu = createMenu(theWBName, -1, -1, 30);
786 int aItemId = createMenu(anAction, aWBMenu);
787 myActionsList.append(aItemId);
788 createMenu(separator(), aWBMenu); /// nested action is always separated of others
790 int aWBTool = createTool(theWBName, theWBName);
794 createTool(anAction, aWBTool);
795 registerCommandToolbar(theWBName, aItemId);
796 createTool(separator(), aWBTool); /// nested action is always separated of others
797 registerCommandToolbar(theWBName, -1);
799 connect(anAction, SIGNAL(triggered(bool)), this, SLOT(logShaperGUIEvent()));
805 //******************************************************
806 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
807 const QString& theTip, const QIcon& theIcon,
808 const QKeySequence& theKeys, bool isCheckable,
809 const char* theMenuSourceText,
810 const QString& theSubMenu,
811 const int theMenuPosition,
812 const int theSuibMenuPosition)
814 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
815 if (!theSubMenu.isNull())
816 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
818 int aId = getNextCommandId();
819 myActionsList.append(aId);
820 SUIT_Desktop* aDesk = application()->desktop();
822 for (int i = 0; i < theKeys.count(); i++)
824 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
826 aAction->setStatusTip(theTip);
827 aAction->setData(theId);
828 createMenu(aId, aMenu, theMenuPosition);
830 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(logShaperGUIEvent()));
835 //******************************************************
836 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
838 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
839 createMenu(separator(), aMenu, -1, theMenuPosition);
842 //******************************************************
843 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
848 SUIT_Desktop* aDesktop = application()->desktop();
852 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
856 aToolMgr->append( theAction, theToolBarTitle );
860 //******************************************************
861 QList<QAction*> SHAPERGUI::commandList() const
863 QList<QAction*> aActions;
864 foreach (int aId, myActionsList) {
865 QAction* aCmd = action(aId);
867 aActions.append(aCmd);
873 //******************************************************
874 QMainWindow* SHAPERGUI::desktop() const
876 return application()->desktop();
879 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
880 const std::shared_ptr<Config_FeatureMessage>& theMessage)
882 myFeaturesInfo.insert(theFeatureId, theMessage);
885 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
887 std::shared_ptr<Config_FeatureMessage> aMessage;
888 if (myFeaturesInfo.contains(theFeatureId))
889 aMessage = myFeaturesInfo[theFeatureId];
893 //******************************************************
894 void SHAPERGUI::selectionChanged()
896 LightApp_Module::selectionChanged();
897 myWorkshop->salomeViewerSelectionChanged();
900 //******************************************************
901 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
903 myWorkshop->contextMenuMgr()->updateViewerMenu();
904 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
905 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
909 //******************************************************
910 void SHAPERGUI::createPreferences()
912 LightApp_Preferences* aPref = preferences();
915 ModuleBase_Preferences::updateConfigByResources();
916 QString aModName = moduleName();
918 QtxPreferenceItem* item = aPref->findItem(aModName, true );
919 if ( item && (!item->isEmpty() )) {
920 item->parentItem()->removeItem(item);
924 int catId = aPref->addPreference(aModName, -1 );
927 SHAPERGUI_PrefMgr aMgr(aPref, aModName);
928 ModuleBase_Preferences::createEditContent(&aMgr, catId);
930 int viewTab = aPref->addItem(tr("Viewer"), catId);
931 // Create other parameters group in viewer tab
932 int otherGroup = aPref->addItem(tr("Default selection"), viewTab);
933 aPref->setItemProperty("columns", 3, otherGroup);
934 aPref->addItem(tr("Faces"), otherGroup,
935 SUIT_PreferenceMgr::Bool,
936 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
937 aPref->addItem(tr("Edges"), otherGroup,
938 SUIT_PreferenceMgr::Bool,
939 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
940 aPref->addItem(tr("Vertices"), otherGroup,
941 SUIT_PreferenceMgr::Bool,
942 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
944 int sensitivityGroup = aPref->addItem(tr("Selection sensitivity"), viewTab);
945 aPref->setItemProperty("columns", 2, sensitivityGroup);
946 aPref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
947 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
948 aPref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
949 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
951 int highlightGroup = aPref->addItem(tr("Additional highlighting"), viewTab);
952 aPref->setItemProperty("columns", 2, highlightGroup);
953 aPref->addItem(tr("In 3d mode"), highlightGroup,
954 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
955 aPref->addItem(tr("In 2d mode"), highlightGroup,
956 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
958 int colorScaleGroup = aPref->addItem(tr("Color scale"), viewTab);
959 aPref->setItemProperty("columns", 4, colorScaleGroup);
960 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
961 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
962 aPref->setItemProperty("min", 0, aItem);
963 aPref->setItemProperty("max", 1, aItem);
964 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
965 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
966 aPref->setItemProperty("min", 0, aItem);
967 aPref->setItemProperty("max", 1, aItem);
968 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
969 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
970 aPref->setItemProperty("min", 0, aItem);
971 aPref->setItemProperty("max", 1, aItem);
972 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
973 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
974 aPref->setItemProperty("min", 0, aItem);
975 aPref->setItemProperty("max", 1, aItem);
976 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
977 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
978 aPref->setItemProperty("min", 0, aItem);
979 aPref->setItemProperty("max", 100, aItem);
980 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
981 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
982 aPref->setItemProperty("min", 0, aItem);
983 aPref->setItemProperty("max", 100, aItem);
984 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
985 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
987 int aGroupNamesGroup = aMgr.addPreference(tr("Group names display"), viewTab,
988 SUIT_PreferenceMgr::GroupBox , ModuleBase_Preferences::VIEWER_SECTION, "group_names_display");
989 aPref->setItemProperty("columns", 3, aGroupNamesGroup);
990 aMgr.addPreference(tr("Text font"), aGroupNamesGroup,
991 SUIT_PreferenceMgr::String, ModuleBase_Preferences::VIEWER_SECTION, "group_names_font");
992 aItem = aMgr.addPreference(tr("Text size"), aGroupNamesGroup,
993 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "group_names_size");
994 aPref->setItemProperty("min", 8, aItem);
995 aPref->setItemProperty("max", 100, aItem);
996 aItem = aMgr.addPreference(tr("Text color"), aGroupNamesGroup,
997 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "group_names_color");
1002 //******************************************************
1003 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
1005 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1006 QString aVal = aResMgr->stringValue(theSection, theParam);
1007 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
1008 theParam.toStdString());
1010 return; // invalid case, the property default value must be registered in XML file
1011 std::string aValue = aVal.toStdString();
1012 if (aValue.empty()) {
1013 aValue = aProp->defaultValue();
1014 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
1016 LightApp_Preferences* aPref = preferences();
1020 aProp->setValue(aValue);
1022 if (theSection == "Visualization") {
1023 if (theParam == "selection_color") {
1024 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
1025 myWorkshop->displayer()->setSelectionColor(aColor);
1027 if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
1029 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
1030 if (!aTrihedron.IsNull()) {
1031 bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
1032 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
1034 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1035 Handle(V3d_View) aView = aViewer->activeView();
1038 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1039 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1040 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1041 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
1042 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1043 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1044 aContext->Redisplay(aTrihedron, true);
1047 else if (myAxisArrowRate > 0) {
1048 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1049 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
1050 aContext->Redisplay(aTrihedron, true);
1056 else if (theSection == ModuleBase_Preferences::GENERAL_SECTION && theParam == "create_init_part") {
1057 bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
1058 ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
1059 Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
1062 else if (theSection == ModuleBase_Preferences::VIEWER_SECTION &&
1063 theParam.startsWith("group_names_"))
1064 { // one of the group names parameter changed, so, update the groups names vizualization
1065 myWorkshop->updateGroupsText();
1066 myWorkshop->displayer()->updateViewer();
1068 myWorkshop->displayer()->redisplayObjects();
1071 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
1073 application()->putInfo(theInfo, theMSecs);
1076 bool SHAPERGUI::abortAllOperations()
1078 return workshop()->operationMgr()->abortAllOperations();
1081 void SHAPERGUI::createFeatureActions()
1083 myWorkshop->menuMgr()->createFeatureActions();
1086 void SHAPERGUI::onWhatIs(bool isToggled)
1088 if (sender() == myWhatIsAction) {
1089 QAction* aViewAct = myInspectionPanel->toggleViewAction();
1090 aViewAct->blockSignals(true);
1091 aViewAct->setChecked(isToggled);
1092 aViewAct->blockSignals(false);
1093 myInspectionPanel->setVisible(isToggled);
1096 myWhatIsAction->blockSignals(true);
1097 myWhatIsAction->setChecked(isToggled);
1098 myWhatIsAction->blockSignals(false);
1099 myInspectionPanel->setVisible(isToggled);
1103 void SHAPERGUI::updateModuleVisibilityState()
1105 LightApp_Module::updateModuleVisibilityState();
1106 onWhatIs(myIsInspectionVisible);
1108 // the following code is caused by #187 bug.
1109 // SALOME saves the dock widget positions before deactivateModule() and
1110 // load it after the module activation. So, if the panel is visible before
1111 // deactivate, it becomes visible after activate.
1112 // In order to avoid the visible property panel, we hide it here
1113 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
1115 myWorkshop->hidePanel(myWorkshop->propertyPanel());
1119 void SHAPERGUI::onEditToolbars()
1121 SHAPERGUI_ToolbarsDlg aDlg(this);
1122 if (aDlg.exec() == QDialog::Accepted) {
1126 updateToolbars(aDlg.result());
1130 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1132 if (!myToolbars.contains(theToolName))
1133 myToolbars[theToolName] = QList<int>();
1134 myToolbars[theToolName].append(theCommandId);
1137 int SHAPERGUI::getNextCommandId() const
1139 QtxActionMenuMgr* aMenuMgr = menuMgr();
1140 QIntList aIds = aMenuMgr->idList();
1141 int aId = aIds.count();
1142 while (action(aId) || myActionsList.contains(aId))
1147 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1149 // Store default toolbars
1150 if (myDefaultToolbars.size() == 0)
1151 myDefaultToolbars = myToolbars;
1153 QtxActionToolMgr* aMgr = toolMgr();
1154 QStringList aToolbars = theNewToolbars.keys();
1155 QIntList aCommands, aOldCmd;
1159 foreach(QString aName, aToolbars) {
1160 aCommands = theNewToolbars[aName];
1161 // Find or create toolbar
1162 if (aMgr->hasToolBar(aName)) {
1163 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1164 aOldCmd = myToolbars[aName];
1167 aToolbarId = aMgr->createToolBar(aName);
1170 foreach(int aCmd, aCommands) {
1173 aAction = separator();
1175 aAction = action(aCmd);
1176 aActionId = aMgr->actionId(aAction);
1177 if (aActionId == -1) {
1179 aMgr->insert(aAction, aToolbarId, aPos);
1182 // Change position of action
1183 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1184 if (aMgr->containsAction(aActionId, aToolbarId))
1185 aMgr->remove(aActionId, aToolbarId);
1186 aMgr->insert(aActionId, aToolbarId, aPos);
1189 aOldCmd.removeAll(aCmd);
1192 // remove extra actions
1193 foreach(int aCmd, aOldCmd) {
1194 aAction = action(aCmd);
1195 aActionId = aMgr->actionId(aAction);
1196 aMgr->remove(aActionId, aToolbarId);
1198 myToolbars.remove(aName);
1200 // Remove extra toolbars
1201 aToolbars = myToolbars.keys();
1202 foreach(QString aName, aToolbars) {
1203 aMgr->removeToolBar(aName);
1205 // Set new toolbars structure
1206 myToolbars = theNewToolbars;
1207 myIsToolbarsModified = true;
1210 void SHAPERGUI::saveToolbarsConfig()
1212 if (!myIsToolbarsModified)
1214 // Save toolbars configuration into map
1215 QMap<QString, QStringList> aToolbarsConfig;
1217 QtxActionToolMgr* aMgr =
1220 QStringList aToolbars = myToolbars.keys();
1221 QIntList aActionsIds;
1222 foreach(QString aName, aToolbars) {
1223 aActionsIds = myToolbars[aName];
1224 QStringList aContent;
1225 foreach(int aId, aActionsIds) {
1227 aContent.append("");
1229 aContent.append(action(aId)->data().toString());
1231 aToolbarsConfig[aName] = aContent;
1233 // Store the configuration into resources
1234 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1235 QStringList aNames = aToolbarsConfig.keys();
1236 QStringList aValues;
1237 foreach(QString aToolbar, aNames) {
1238 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1240 // Remove obsolete parameters from resources
1241 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1242 foreach(QString aName, aOldParams) {
1243 if (!aToolbars.contains(aName))
1244 aResMgr->remove(ToolbarsSection, aName);
1246 // Store current list of free commands
1247 QIntList aFreeCommands = getFreeCommands();
1248 QStringList aFreeList;
1249 foreach(int aId, aFreeCommands) {
1250 aFreeList.append(action(aId)->data().toString());
1252 if (aFreeList.size() > 0)
1253 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1255 myIsToolbarsModified = false;
1258 void SHAPERGUI::loadToolbarsConfig()
1260 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1261 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1262 if (aToolbarNames.size() == 0)
1265 // Create commands map
1266 QMap<QString, int> aCommandsMap;
1268 foreach(int aId, myActionsList) {
1269 aCmdIdStr = action(aId)->data().toString();
1270 aCommandsMap[aCmdIdStr] = aId;
1273 // Create new toolbars structure
1274 QMap<QString, QIntList> aToolbars;
1275 QStringList aCommands;
1276 QIntList aKnownCommands;
1277 QList<QAction*> aActions;
1278 foreach(QString aName, aToolbarNames) {
1279 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1280 if (aName == FreeCommandsParam) {
1281 // The value is a list of free commands
1282 foreach(QString aCommand, aCommands) {
1283 aKnownCommands.append(aCommandsMap[aCommand]);
1287 aToolbars[aName] = QIntList();
1288 if (aCommands.size() > 0) {
1289 foreach(QString aCommand, aCommands) {
1290 if (aCommand.isEmpty())
1291 aToolbars[aName].append(-1);
1292 else if (aCommandsMap.contains(aCommand)) {
1293 int aId = aCommandsMap[aCommand];
1294 aToolbars[aName].append(aId);
1295 aKnownCommands.append(aId);
1301 // Find new and obsolete commands
1302 QIntList aNewCommands = myActionsList;
1303 foreach(int aId, myActionsList) {
1304 if (aKnownCommands.contains(aId)) {
1305 aKnownCommands.removeAll(aId);
1306 aNewCommands.removeAll(aId);
1309 if (aNewCommands.size() > 0) {
1310 // Add new commands to toolbars structure
1311 QStringList aKeys = myToolbars.keys();
1312 foreach(int aNewId, aNewCommands) {
1313 foreach(QString aName, aKeys) {
1314 if (myToolbars[aName].contains(aNewId)) {
1315 if (!aToolbars.contains(aName)) {
1316 aToolbars[aName] = QIntList();
1318 aToolbars[aName].append(aNewId);
1323 if (aKnownCommands.size() > 0) {
1324 // Remove obsolete commands from the toolbars structure
1325 QStringList aKeys = aToolbars.keys();
1326 foreach(int aOldId, aKnownCommands) {
1327 foreach(QString aName, aKeys) {
1328 if (aToolbars[aName].contains(aOldId)) {
1329 aToolbars[aName].removeAll(aOldId);
1330 if (aToolbars[aName].size() == 0)
1331 aToolbars.remove(aName);
1336 updateToolbars(aToolbars);
1337 myIsToolbarsModified = false;
1341 QIntList SHAPERGUI::getFreeCommands() const
1343 QIntList aFreeCommands;
1344 QtxActionToolMgr* aMgr = toolMgr();
1347 QMap<QString, QIntList>::const_iterator aIt;
1348 QIntList aShaperActions = shaperActions();
1349 foreach(int aCmd, aShaperActions) {
1350 anAction = action(aCmd);
1351 aId = aMgr->actionId(anAction);
1352 if (!aMgr->containsAction(aId))
1353 aFreeCommands.append(aCmd);
1355 return aFreeCommands;
1358 void SHAPERGUI::resetToolbars()
1360 if (!myDefaultToolbars.isEmpty())
1361 updateToolbars(myDefaultToolbars);
1362 myIsToolbarsModified = false;
1363 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1364 aResMgr->remove(ToolbarsSection);
1367 void SHAPERGUI::publishToStudy()
1369 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) {
1370 myWorkshop->module()->launchOperation("PublishToStudy", false);
1372 // update SHAPERSTUDY objects in OCC and VTK viewers
1373 QStringList aVMList;
1374 aVMList << "OCCViewer" << "VTKViewer";
1375 getApp()->updatePresentations("SHAPERSTUDY", aVMList);
1379 void SHAPERGUI::fillPartSetInfoPanel(QtxInfoPanel* theInfoPanel)
1381 QIntList aShaperActions = shaperActions();
1382 theInfoPanel->addLabel(tr("Current mode: Part set mode"));
1384 addActionsToInfoGroup(theInfoPanel, tr("Parts management"),
1385 { "Part", "Duplicate", "Remove" });
1386 addActionsToInfoGroup(theInfoPanel, tr("Import operations"),
1387 { "OPEN_CMD", "IMPORT_PART_CMD", "IMPORT_SHAPE_CMD" });
1388 addActionsToInfoGroup(theInfoPanel, tr("Export operations"),
1389 { "SAVEAS_CMD", "EXPORT_PART_CMD", "EXPORT_SHAPE_CMD" });
1390 addActionsToInfoGroup(theInfoPanel, tr("Arrangement of parts"),
1391 { "Placement", "Translation", "Rotation" });
1394 void SHAPERGUI::fillPartInfoPanel(QtxInfoPanel* theInfoPanel)
1396 QIntList aShaperActions = shaperActions();
1397 theInfoPanel->addLabel(tr("Current mode: Part mode"));
1399 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1400 { "Box", "Cylinder", "Sphere" });
1401 addActionsToInfoGroup(theInfoPanel, tr("Geometry"),
1402 { "Vertex", "Edge", "Wire", "Face" });
1403 addActionsToInfoGroup(theInfoPanel, tr("Features"),
1404 { "Extrusion", "Revolution", "Cut", "Fuse", "Fillet" });
1407 void SHAPERGUI::fillSketcherInfoPanel(QtxInfoPanel* theInfoPanel)
1409 QIntList aShaperActions = shaperActions();
1410 theInfoPanel->addLabel(tr("Current mode: Sketcher mode"));
1412 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1413 { "SketchPoint", "SketchLine", "SketchCircle", "SketchRectangle" });
1414 addActionsToInfoGroup(theInfoPanel, tr("Dimensions"),
1415 { "SketchConstraintLength", "SketchConstraintRadius", "SketchConstraintAngle" });
1416 addActionsToInfoGroup(theInfoPanel, tr("Constraints"),
1417 { "SketchConstraintParallel", "SketchConstraintPerpendicular",
1418 "SketchConstraintEqual", "SketchConstraintCoincidence" });
1421 void SHAPERGUI::addActionsToInfoGroup(QtxInfoPanel* theInfoPanel,
1422 const QString& theGroup, const QSet<QString>& theActions)
1424 QIntList aShaperActions = shaperActions();
1426 int aGroup = theInfoPanel->addGroup(theGroup);
1428 foreach(int aCmd, aShaperActions) {
1429 QAction* aAction = action(aCmd);
1430 if (theActions.contains(aAction->data().toString()))
1432 theInfoPanel->addAction(aAction, aGroup);
1435 if (aCount >= theActions.size())
1440 void SHAPERGUI::updateInfoPanel()
1442 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
1443 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
1444 aInfoPanel->clear();
1445 aInfoPanel->setTitle(tr("Welcome to SHAPER"));
1447 SessionPtr aMgr = ModelAPI_Session::get();
1448 QList<DocumentPtr> aDocs;
1449 DocumentPtr aActiveDoc = aMgr->activeDocument();
1450 DocumentPtr aModuleDoc = aMgr->moduleDocument();
1452 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
1453 QStringList aOpList = aOpMgr->operationList();
1454 bool isSketcher = false;
1455 if (aOpList.size() > 0)
1456 isSketcher = (aOpList.first() == "Sketch");
1458 if (isSketcher) // Sketcher mode
1459 fillSketcherInfoPanel(aInfoPanel);
1460 else if (aActiveDoc == aModuleDoc) // Part set mode
1461 fillPartSetInfoPanel(aInfoPanel);
1463 fillPartInfoPanel(aInfoPanel);