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>
52 #include <OCCViewer_ViewManager.h>
54 #include <SUIT_Selector.h>
55 #include <SUIT_Desktop.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ViewWindow.h>
58 #include <SUIT_ResourceMgr.h>
59 #include <SUIT_DataBrowser.h>
61 #include <QtxPopupMgr.h>
62 #include <QtxActionMenuMgr.h>
63 #include <QtxActionToolMgr.h>
64 #include <QtxResourceMgr.h>
65 #include <QtxInfoPanel.h>
67 #include <Config_PropManager.h>
68 #include <Config_ModuleReader.h>
70 #include <AIS_ListOfInteractive.hxx>
71 #include <AIS_ListIteratorOfListOfInteractive.hxx>
72 #include <Standard_Version.hxx>
74 #include <QDockWidget>
80 #include <ModelAPI_Session.h>
81 #include <Events_MessageBool.h>
83 #if OCC_VERSION_HEX < 0x070400
84 #define SALOME_PATCH_FOR_CTRL_WHEEL
88 SHAPERGUI_EXPORT CAM_Module* createModule()
90 return new SHAPERGUI();
93 SHAPERGUI_EXPORT char* getModuleVersion()
100 static const QString ToolbarsSection("SHAPER_Toolbars");
101 static const QString FreeCommandsParam("OutOFToolbars");
105 * Class for preferences management
107 class SHAPERGUI_PrefMgr: public ModuleBase_IPrefMgr
111 /// \param theMgr preferences manager of SALOME
112 /// \param theModName name of the module
113 SHAPERGUI_PrefMgr(LightApp_Preferences* theMgr, const QString& theModName):
114 myMgr(theMgr), myModName(theModName) {}
116 virtual int addPreference(const QString& theLbl, int pId,
117 SUIT_PreferenceMgr::PrefItemType theType,
118 const QString& theSection, const QString& theName )
120 return myMgr->addPreference(myModName, theLbl, pId, theType, theSection, theName);
123 virtual void setItemProperty(const QString& thePropName,
124 const QVariant& theValue,
125 const int theId = -1)
127 myMgr->setItemProperty(thePropName, theValue, theId);
131 virtual SUIT_PreferenceMgr* prefMgr() const { return myMgr; }
134 LightApp_Preferences* myMgr;
141 //******************************************************
142 SHAPERGUI::SHAPERGUI()
143 : LightApp_Module("SHAPER"),
144 mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false),
145 myInspectionPanel(0), myIsFacesPanelVisible(false), myIsToolbarsModified(false),
148 myWorkshop = new XGUI_Workshop(this);
149 connect(myWorkshop, SIGNAL(commandStatusUpdated()),
150 this, SLOT(onUpdateCommandStatus()));
152 myProxyViewer = new SHAPERGUI_SalomeViewer(this);
154 ModuleBase_Preferences::setResourceMgr(application()->resourceMgr());
156 // It will be called in XGUI_Workshop::startApplication
157 // ModuleBase_Preferences::loadCustomProps();
160 //******************************************************
161 SHAPERGUI::~SHAPERGUI()
164 delete myProxyViewer;
167 //******************************************************
168 void SHAPERGUI::initialize(CAM_Application* theApp)
170 LightApp_Module::initialize(theApp);
172 myWorkshop->startApplication();
173 LightApp_Application* anApp = dynamic_cast<LightApp_Application*>(theApp);
176 connect(anApp, SIGNAL(preferenceResetToDefaults()), this, SLOT(onDefaultPreferences()));
179 int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
181 int aId = getNextCommandId();
182 myActionsList.append(aId);
183 SUIT_Desktop* aDesk = application()->desktop();
184 QString aTip = tr("Show inspection window");
185 myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"),
186 aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
187 myWhatIsAction->setStatusTip(aTip);
188 myWhatIsAction->setData("INSPECTION_CMD");
189 createMenu(aId, aMenu, 0);
191 QString aToolName = tr("Inspection");
192 int aTool = createTool(aToolName);
196 createTool(myWhatIsAction, aTool);
197 registerCommandToolbar(aToolName, aId);
199 // Define Edit toolbars command
200 aId = getNextCommandId();
201 //myActionsList.append(aId); Do not use it for editing of toolbars
202 aTip = tr("Edit toolbars of the module");
206 createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"),
207 tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars()));
208 int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30);
212 createMenu(aId, aEditMenu);
214 if (!myInspectionPanel) {
215 myInspectionPanel = myWorkshop->inspectionPanel();
216 connect(myInspectionPanel->toggleViewAction(), SIGNAL(toggled(bool)),
217 this, SLOT(onWhatIs(bool)));
219 hideInternalWindows();
221 // Initialize viewer proxy if OCC viewer is already exist
222 ViewManagerList aOCCViewManagers;
223 application()->viewManagers(OCCViewer_Viewer::Type(), aOCCViewManagers);
224 if (aOCCViewManagers.size() > 0) {
225 SUIT_ViewManager* aMgr = aOCCViewManagers.first();
226 SUIT_ViewWindow* aWnd = aMgr->getActiveView();
228 OCCViewer_ViewWindow* aOccWnd = static_cast<OCCViewer_ViewWindow*>(aWnd);
229 OCCViewer_ViewPort3d* aViewPort = aOccWnd->getViewPort();
231 XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
232 aViewPort->installEventFilter(aViewer);
233 Handle(V3d_View) aView = aViewPort->getView();
234 aViewer->SetScale(aView, aView->Camera()->Scale());
235 // We can not create selector here because other modules will be deactivated later
236 //onViewManagerAdded(aMgr);
240 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
241 aDataModel->initRootObject();
244 //******************************************************
245 void SHAPERGUI::windows(QMap<int, int>& theWndMap) const
247 theWndMap.insert(LightApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea);
248 theWndMap.insert(LightApp_Application::WT_InfoPanel, Qt::RightDockWidgetArea);
251 //******************************************************
252 void SHAPERGUI::viewManagers(QStringList& theList) const
254 theList.append(OCCViewer_Viewer::Type());
257 //******************************************************
258 // We can not create selector in this method because it can be called when
259 // SHAPER module is not active. Take into account that creation of our selector
260 // leads to switching OFF all other selectors
261 //void SHAPERGUI::connectToStudy(CAM_Study* theStudy)
263 // // if there are created viewer managers, we should try to create viewer
264 // // selector and initialize viewer with it. It sets interactive context to the
265 // // proxy viewer. If study is opened, CAM application calls this method before the open()
267 // // the SHAPER data model is specific and during open(load) redisplay signals are flushed, so
268 // // we need to connect to the viewer before it. Here,
269 // // it seems the most appropriate place for this
270 // // according to SALOME architecture.
271 // if (!mySelector) {
272 // ViewManagerList OCCViewManagers;
273 // application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
274 // if (OCCViewManagers.size() > 0) {
275 // mySelector = createSelector(OCCViewManagers.first());
278 // LightApp_Module::connectToStudy(theStudy);
281 //******************************************************
282 bool SHAPERGUI::activateModule(SUIT_Study* theStudy)
284 ModelAPI_Session::get()->moduleDocument(); // initialize a root document if not done yet
286 // this must be done in the initialization and in activation (on the second activation
287 // initialization in not called, so SComponent must be added anyway
288 SHAPERGUI_DataModel* aDataModel = dynamic_cast<SHAPERGUI_DataModel*>(dataModel());
289 aDataModel->initRootObject();
292 bool isDone = LightApp_Module::activateModule(theStudy);
293 loadToolbarsConfig();
299 QObject* aObj = myWorkshop->objectBrowser()->parent();
300 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
302 myWorkshop->objectBrowser()->setVisible(true);
303 aObjDoc->setVisible(true);
304 desktop()->tabifyDockWidget(aObjDoc, myWorkshop->propertyPanel());
305 aObjDoc->toggleViewAction()->setVisible(true);
308 myInspectionPanel->toggleViewAction()->setVisible(true);
310 myWorkshop->facesPanel()->toggleViewAction()->setVisible(true);
311 if (myIsFacesPanelVisible)
312 myWorkshop->facesPanel()->show();
313 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(true);
316 ViewManagerList OCCViewManagers;
317 application()->viewManagers(OCCViewer_Viewer::Type(), OCCViewManagers);
318 if (OCCViewManagers.size() > 0) {
319 onViewManagerAdded(OCCViewManagers.first());
322 // it should be performed after the selector creation in order to have AISContext
323 myWorkshop->activateModule();
324 //action(myEraseAll)->setEnabled(false);
327 myWorkshop->objectBrowser()->rebuildDataTree();
328 myWorkshop->updateCommandStatus();
332 myWorkshop->updateCommandStatus();
334 myIsEditEnabled = getApp()->isEditEnabled();
335 getApp()->setEditEnabled(false);
337 // Synchronize displayed objects
338 Handle(AIS_InteractiveContext) aContext;
339 if (mySelector && mySelector->viewer())
340 aContext = mySelector->viewer()->getAISContext();
342 if (!aContext.IsNull()) {
343 XGUI_Displayer* aDisp = myWorkshop->displayer();
344 QObjectPtrList aObjList = aDisp->displayedObjects();
346 if (myOldSelectionColor.size() == 0)
347 myOldSelectionColor = aDisp->selectionColor();
349 AIS_ListOfInteractive aList;
350 aContext->DisplayedObjects(aList);
351 AIS_ListIteratorOfListOfInteractive aLIt;
352 Handle(AIS_InteractiveObject) anAISIO;
353 foreach (ObjectPtr aObj, aObjList) {
354 AISObjectPtr aPrs = aDisp->getAISObject(aObj);
355 Handle(AIS_InteractiveObject) aAIS = aPrs->impl<Handle(AIS_InteractiveObject)>();
357 for (aLIt.Initialize(aList); aLIt.More(); aLIt.Next()) {
358 anAISIO = aLIt.Value();
359 if (anAISIO.get() == aAIS.get()) {
365 aObj->setDisplayed(false);
366 //aDisp->erase(aObj, false);
369 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
371 myProxyViewer->activateViewer(true);
373 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
374 connect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
375 this, SLOT(onScriptLoaded()));
377 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
378 getApp(), SLOT(onSaveDoc()));
379 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
380 getApp(), SLOT(onSaveAsDoc()));
382 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
383 this, SLOT(onSaveDocByShaper()));
384 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
385 this, SLOT(onSaveAsDocByShaper()));
388 //connect(myWorkshop->operationMgr(), SIGNAL(operationResumed(ModuleBase_Operation*)),
389 // this, SLOT(onOperationResumed(ModuleBase_Operation*)));
390 //connect(myWorkshop->operationMgr(), SIGNAL(operationStopped(ModuleBase_Operation*)),
391 // this, SLOT(onOperationStopped(ModuleBase_Operation*)));
392 connect(myWorkshop->operationMgr(), SIGNAL(operationCommitted(ModuleBase_Operation*)),
393 this, SLOT(onOperationCommitted(ModuleBase_Operation*)));
394 connect(myWorkshop->operationMgr(), SIGNAL(operationAborted(ModuleBase_Operation*)),
395 this, SLOT(onOperationAborted(ModuleBase_Operation*)));
400 //******************************************************
401 void SHAPERGUI::hideInternalWindows()
403 myProxyViewer->activateViewer(false);
407 QObject* aObj = myWorkshop->objectBrowser()->parent();
408 QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
410 aObjDoc->setVisible(false);
411 myWorkshop->objectBrowser()->setVisible(false);
412 aObjDoc->toggleViewAction()->setVisible(false);
415 myInspectionPanel->hide();
416 myInspectionPanel->toggleViewAction()->setVisible(false);
418 myWorkshop->facesPanel()->hide();
419 myWorkshop->facesPanel()->toggleViewAction()->setVisible(false);
421 myWorkshop->propertyPanel()->hide();
422 myWorkshop->propertyPanel()->toggleViewAction()->setVisible(false);
424 myWorkshop->hidePanel(myWorkshop->facesPanel());
428 //******************************************************
429 bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy)
431 saveToolbarsConfig();
432 myWorkshop->deactivateModule();
434 myIsInspectionVisible = myInspectionPanel->isVisible();
435 myIsFacesPanelVisible = myWorkshop->facesPanel()->isVisible();
436 hideInternalWindows();
439 // the active operation should be stopped for the next activation.
440 // There should not be active operation and visualized preview.
441 // Abort operation should be performed before the selection's remove
442 // because the displayed objects should be removed from the viewer, but
443 // the AIS context is obtained from the selector.
444 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
445 while (anOperation) {
446 anOperation->abort();
447 anOperation = myWorkshop->operationMgr()->currentOperation();
449 // Delete selector because it has to be redefined on next activation
451 // Restore size of arrows of trihedron
452 if (myAxisArrowRate > 0) {
453 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
454 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
455 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
456 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
457 aContext->Redisplay(aTrihedron, false);
459 myWorkshop->displayer()->setSelectionColor(myOldSelectionColor);
460 myProxyViewer->setSelector(0);
462 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
463 QList<SUIT_Selector*> aList;
464 aMgr->selectors(aList);
465 foreach(SUIT_Selector* aSel, aList) {
466 aSel->setEnabled(aSel != mySelector);
473 //myWorkshop->contextMenuMgr()->disconnectViewer();
475 getApp()->setEditEnabled(myIsEditEnabled);
477 myOldSelectionColor.clear();
479 // Post-processing for LoadScriptId to remove created(if it was created) SALOME Object Browser
480 disconnect(getApp()->action(LightApp_Application::UserID+1), SIGNAL(triggered(bool)),
481 this, SLOT(onScriptLoaded()));
483 disconnect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
484 this, SLOT(onSaveDocByShaper()));
485 disconnect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
486 this, SLOT(onSaveAsDocByShaper()));
488 connect(getApp()->action(LightApp_Application::FileSaveId), SIGNAL(triggered(bool)),
489 getApp(), SLOT(onSaveDoc()));
490 connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)),
491 getApp(), SLOT(onSaveAsDoc()));
495 return LightApp_Module::deactivateModule(theStudy);
498 //******************************************************
499 void SHAPERGUI::logShaperGUIEvent()
501 QAction* anAction = static_cast<QAction*>(sender());
504 const QString anId = anAction->data().toString();
505 const QString section = anId.contains("Sketch") ? "sketcher" : "";
507 CAM_Application::logStructuredUserEvent( moduleName(),
513 //******************************************************
514 static void onOperationGeneric( ModuleBase_Operation* theOperation,
515 const QString moduleName,
516 const QString &event )
518 QString anId = theOperation->id();
519 QString section = "";
521 if (anId.contains("Sketch"))
523 section = "sketcher";
524 anId.remove("Sketch");
527 CAM_Application::logStructuredUserEvent( moduleName,
533 //******************************************************
534 void SHAPERGUI::onOperationCommitted(ModuleBase_Operation* theOperation)
536 onOperationGeneric(theOperation, moduleName(), "committed");
539 //******************************************************
540 void SHAPERGUI::onOperationAborted(ModuleBase_Operation* theOperation)
542 onOperationGeneric(theOperation, moduleName(), "aborted");
545 //******************************************************
546 void SHAPERGUI::onViewManagerAdded(SUIT_ViewManager* theMgr)
549 mySelector = createSelector(theMgr);
550 myWorkshop->selectionActivate()->updateSelectionFilters();
551 myWorkshop->selectionActivate()->updateSelectionModes();
552 myWorkshop->synchronizeViewer();
554 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
555 // Set the auto rotate flag in the new viewer based on the current preference
556 OCCViewer_ViewManager *aVM = (OCCViewer_ViewManager*)theMgr;
557 bool aAutoRotation = Config_PropManager::boolean("Visualization", "use_auto_rotation");
558 aVM->setAutoRotation(aAutoRotation);
560 connect(theMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
561 myProxyViewer, SLOT(onViewCreated(SUIT_ViewWindow*)));
565 //******************************************************
566 void SHAPERGUI::onViewManagerRemoved(SUIT_ViewManager* theMgr)
569 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
570 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
571 if (mySelector->viewer() == aViewer) {
572 XGUI_Displayer* aDisp = myWorkshop->displayer();
573 QObjectPtrList aObjects = aDisp->displayedObjects();
575 foreach(ObjectPtr aObj, aObjects) {
576 aObj->setDisplayed(false);
577 aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
579 while (aRes = ModelAPI_Tools::bodyOwner(aRes)) {
580 aRes->setDisplayed(false);
584 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
585 myProxyViewer->setSelector(0);
589 myWorkshop->module()->clearViewer();
595 //******************************************************
596 QtxPopupMgr* SHAPERGUI::popupMgr()
599 myPopupMgr = new QtxPopupMgr( 0, this );
603 //******************************************************
604 void SHAPERGUI::onDefaultPreferences()
606 // reset main resources
607 ModuleBase_Preferences::resetResourcePreferences(preferences());
608 // reset plugin's resources
609 ModuleBase_Preferences::resetConfigPropPreferences(preferences());
611 myWorkshop->displayer()->redisplayObjects();
614 //******************************************************
615 void SHAPERGUI::onScriptLoaded()
617 // this slot is called after processing of the LoadScriptId action of SalomeApp Application
618 // Each dumped script contains updateObjBrowser() that creates a new instance of Object
619 // Browser. When SHAPER module is active, this browser should not be used. It might be removed
620 // as hidden by means of updateWindows() of SalomeApp_Application or to remove
621 // it manually (because this method of application is protected)
622 SUIT_DataBrowser* aBrowser = getApp()->objectBrowser();
625 myWorkshop->displayer()->updateViewer();
626 myWorkshop->updateCommandStatus();
629 //******************************************************
630 void SHAPERGUI::onSaveDocByShaper()
632 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
635 getApp()->onSaveDoc();
638 //******************************************************
639 void SHAPERGUI::onSaveAsDocByShaper()
641 if(!workshop()->operationMgr()->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage))
644 getApp()->onSaveAsDoc();
647 //******************************************************
648 void SHAPERGUI::onUpdateCommandStatus()
650 getApp()->updateActions();
652 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
653 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
654 if (aInfoPanel->isVisible())
658 //******************************************************
659 SHAPERGUI_OCCSelector* SHAPERGUI::createSelector(SUIT_ViewManager* theMgr)
661 if (theMgr->getType() == OCCViewer_Viewer::Type()) {
662 OCCViewer_Viewer* aViewer = static_cast<OCCViewer_Viewer*>(theMgr->getViewModel());
664 // Remember current length of arrow of axis
665 Handle(AIS_Trihedron) aTrihedron = aViewer->getTrihedron();
666 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
667 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
669 SHAPERGUI_OCCSelector* aSelector = new SHAPERGUI_OCCSelector(aViewer,
670 getApp()->selectionMgr());
671 #ifdef SALOME_PATCH_FOR_CTRL_WHEEL
672 aViewer->setUseLocalSelection(true);
674 LightApp_SelectionMgr* aMgr = getApp()->selectionMgr();
675 QList<SUIT_Selector*> aList;
676 aMgr->selectors(aList);
677 foreach(SUIT_Selector* aSel, aList)
679 aSel->setEnabled(aSel == aSelector);
681 myProxyViewer->setSelector(aSelector);
683 if (myOldSelectionColor.size() == 0)
684 myOldSelectionColor = myWorkshop->displayer()->selectionColor();
686 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
687 myWorkshop->displayer()->setSelectionColor(aColor);
689 // Cause scaling of arrows of axis and dimensions
690 myWorkshop->module()->onViewTransformed();
697 //******************************************************
698 CAM_DataModel* SHAPERGUI::createDataModel()
700 return new SHAPERGUI_DataModel(this);
703 QAction* SHAPERGUI::addFeature(const QString& theWBName, const ActionInfo& theInfo,
704 const bool isAddSeparator)
706 return addFeature(theWBName,
710 //Issue #650: in the SALOME mode the tooltip should be same as text
719 //******************************************************
720 QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBName,
721 const QString& theId, const QString& theTitle, const QString& theTip,
722 const QIcon& theIcon, const QKeySequence& theKeys,
723 bool isCheckable, const bool isAddSeparator,
724 const QString& theStatusTip)
726 static QString aLastTool = "";
728 if (aLastTool.isEmpty())
729 aLastTool = theWBName;
730 else if (theWBName != aLastTool) {
731 aLastTool = theWBName;
733 desktop()->addToolBarBreak();
739 int aId = getNextCommandId();
740 myActionsList.append(aId);
741 SUIT_Desktop* aDesk = application()->desktop();
743 for (int i = 0; i < theKeys.count(); i++)
745 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
747 aAction->setStatusTip(theStatusTip);
749 aAction->setData(theId);
751 int aWBMenu = createMenu(theWBName, -1, -1, 30/*10-Window, 1000 - Help*/);
753 if( theId == "PointCoordinates" )
754 createMenu(separator(), aWBMenu);
759 createMenu(aId, aWBMenu);
762 createMenu(separator(), aWBMenu);
764 int aWBTool = createTool(theTBName, theTBName);
768 createTool(aId, aWBTool);
769 registerCommandToolbar(theTBName, aId);
770 if (isAddSeparator) {
771 createTool(separator(), aWBTool);
772 registerCommandToolbar(theTBName, -1);
774 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(logShaperGUIEvent()));
778 bool SHAPERGUI::isFeatureOfNested(const QAction* theAction)
780 return dynamic_cast<const SHAPERGUI_NestedButton*>(theAction);
783 QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName,
784 const ActionInfo& theInfo,
785 const QList<QAction*>& theNestedActions)
787 SUIT_Desktop* aDesk = application()->desktop();
788 SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions);
789 anAction->setData(theInfo.id);
790 anAction->setCheckable(theInfo.checkable);
791 anAction->setChecked(theInfo.checked);
792 anAction->setEnabled(theInfo.enabled);
793 anAction->setVisible(theInfo.visible);
794 anAction->setIcon(theInfo.icon);
795 anAction->setText(theInfo.text);
796 anAction->setToolTip(theInfo.toolTip);
797 anAction->setShortcut(theInfo.shortcut);
798 anAction->setFont(theInfo.font);
800 int aWBMenu = createMenu(theWBName, -1, -1, 30);
801 int aItemId = createMenu(anAction, aWBMenu);
802 myActionsList.append(aItemId);
803 createMenu(separator(), aWBMenu); /// nested action is always separated of others
805 int aWBTool = createTool(theWBName, theWBName);
809 createTool(anAction, aWBTool);
810 registerCommandToolbar(theWBName, aItemId);
811 createTool(separator(), aWBTool); /// nested action is always separated of others
812 registerCommandToolbar(theWBName, -1);
814 connect(anAction, SIGNAL(triggered(bool)), this, SLOT(logShaperGUIEvent()));
820 //******************************************************
821 QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTitle,
822 const QString& theTip, const QIcon& theIcon,
823 const QKeySequence& theKeys, bool isCheckable,
824 const char* theMenuSourceText,
825 const QString& theSubMenu,
826 const int theMenuPosition,
827 const int theSuibMenuPosition)
829 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
830 if (!theSubMenu.isNull())
831 aMenu = createMenu(theSubMenu, aMenu, -1, theSuibMenuPosition);
833 int aId = getNextCommandId();
834 myActionsList.append(aId);
835 SUIT_Desktop* aDesk = application()->desktop();
837 for (int i = 0; i < theKeys.count(); i++)
839 QAction* aAction = createAction(aId, theTip, theIcon, theTitle, theTip, aKeys, aDesk,
841 aAction->setStatusTip(theTip);
842 aAction->setData(theId);
843 createMenu(aId, aMenu, theMenuPosition);
845 connect(aAction, SIGNAL(triggered(bool)), this, SLOT(logShaperGUIEvent()));
850 //******************************************************
851 void SHAPERGUI::addDesktopMenuSeparator(const char* theMenuSourceText, const int theMenuPosition)
853 int aMenu = createMenu(tr(theMenuSourceText), -1, -1);
854 createMenu(separator(), aMenu, -1, theMenuPosition);
857 //******************************************************
858 bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
863 SUIT_Desktop* aDesktop = application()->desktop();
867 QtxActionToolMgr* aToolMgr = aDesktop->toolMgr();
871 aToolMgr->append( theAction, theToolBarTitle );
875 //******************************************************
876 QList<QAction*> SHAPERGUI::commandList() const
878 QList<QAction*> aActions;
879 foreach (int aId, myActionsList) {
880 QAction* aCmd = action(aId);
882 aActions.append(aCmd);
888 //******************************************************
889 QMainWindow* SHAPERGUI::desktop() const
891 return application()->desktop();
894 void SHAPERGUI::setFeatureInfo(const QString& theFeatureId,
895 const std::shared_ptr<Config_FeatureMessage>& theMessage)
897 myFeaturesInfo.insert(theFeatureId, theMessage);
900 std::shared_ptr<Config_FeatureMessage> SHAPERGUI::featureInfo(const QString& theFeatureId)
902 std::shared_ptr<Config_FeatureMessage> aMessage;
903 if (myFeaturesInfo.contains(theFeatureId))
904 aMessage = myFeaturesInfo[theFeatureId];
908 //******************************************************
909 void SHAPERGUI::selectionChanged()
911 LightApp_Module::selectionChanged();
912 myWorkshop->salomeViewerSelectionChanged();
915 //******************************************************
916 void SHAPERGUI::contextMenuPopup(const QString& theClient, QMenu* theMenu, QString& theTitle)
918 myWorkshop->contextMenuMgr()->updateViewerMenu();
919 myWorkshop->contextMenuMgr()->addViewerMenu(theMenu);
920 LightApp_Module::contextMenuPopup(theClient, theMenu, theTitle);
924 //******************************************************
925 void SHAPERGUI::createPreferences()
927 LightApp_Preferences* aPref = preferences();
930 ModuleBase_Preferences::updateConfigByResources();
931 QString aModName = moduleName();
933 QtxPreferenceItem* item = aPref->findItem(aModName, true );
934 if ( item && (!item->isEmpty() )) {
935 item->parentItem()->removeItem(item);
939 int catId = aPref->addPreference(aModName, -1 );
942 SHAPERGUI_PrefMgr aMgr(aPref, aModName);
943 ModuleBase_Preferences::createEditContent(&aMgr, catId);
945 int viewTab = aPref->addItem(tr("Viewer"), catId);
946 // Create other parameters group in viewer tab
947 int otherGroup = aPref->addItem(tr("Default selection"), viewTab);
948 aPref->setItemProperty("columns", 3, otherGroup);
949 aPref->addItem(tr("Faces"), otherGroup,
950 SUIT_PreferenceMgr::Bool,
951 ModuleBase_Preferences::VIEWER_SECTION, "face-selection");
952 aPref->addItem(tr("Edges"), otherGroup,
953 SUIT_PreferenceMgr::Bool,
954 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection");
955 aPref->addItem(tr("Vertices"), otherGroup,
956 SUIT_PreferenceMgr::Bool,
957 ModuleBase_Preferences::VIEWER_SECTION, "vertex-selection");
959 int sensitivityGroup = aPref->addItem(tr("Selection sensitivity"), viewTab);
960 aPref->setItemProperty("columns", 2, sensitivityGroup);
961 aPref->addItem(tr("Vertex"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
962 ModuleBase_Preferences::VIEWER_SECTION, "point-selection-sensitivity");
963 aPref->addItem(tr("Edge"), sensitivityGroup, SUIT_PreferenceMgr::DblSpin,
964 ModuleBase_Preferences::VIEWER_SECTION, "edge-selection-sensitivity");
966 int highlightGroup = aPref->addItem(tr("Additional highlighting"), viewTab);
967 aPref->setItemProperty("columns", 2, highlightGroup);
968 aPref->addItem(tr("In 3d mode"), highlightGroup,
969 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-3d");
970 aPref->addItem(tr("In 2d mode"), highlightGroup,
971 SUIT_PreferenceMgr::Bool, ModuleBase_Preferences::VIEWER_SECTION, "highlighting-2d");
973 int colorScaleGroup = aPref->addItem(tr("Color scale"), viewTab);
974 aPref->setItemProperty("columns", 4, colorScaleGroup);
975 int aItem = aMgr.addPreference(tr("X position"), colorScaleGroup,
976 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_x_position");
977 aPref->setItemProperty("min", 0, aItem);
978 aPref->setItemProperty("max", 1, aItem);
979 aItem = aMgr.addPreference(tr("Y position"), colorScaleGroup,
980 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_y_position");
981 aPref->setItemProperty("min", 0, aItem);
982 aPref->setItemProperty("max", 1, aItem);
983 aItem = aMgr.addPreference(tr("Width"), colorScaleGroup,
984 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_width");
985 aPref->setItemProperty("min", 0, aItem);
986 aPref->setItemProperty("max", 1, aItem);
987 aItem = aMgr.addPreference(tr("Height"), colorScaleGroup,
988 SUIT_PreferenceMgr::Double, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_height");
989 aPref->setItemProperty("min", 0, aItem);
990 aPref->setItemProperty("max", 1, aItem);
991 aItem = aMgr.addPreference(tr("Intervals number"), colorScaleGroup,
992 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_nb_intervals");
993 aPref->setItemProperty("min", 0, aItem);
994 aPref->setItemProperty("max", 100, aItem);
995 aItem = aMgr.addPreference(tr("Text height"), colorScaleGroup,
996 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_height");
997 aPref->setItemProperty("min", 0, aItem);
998 aPref->setItemProperty("max", 100, aItem);
999 aItem = aMgr.addPreference(tr("Text color"), colorScaleGroup,
1000 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "scalar_bar_text_color");
1002 int aGroupNamesGroup = aMgr.addPreference(tr("Group names display"), viewTab,
1003 SUIT_PreferenceMgr::GroupBox , ModuleBase_Preferences::VIEWER_SECTION, "group_names_display");
1004 aPref->setItemProperty("columns", 3, aGroupNamesGroup);
1005 aMgr.addPreference(tr("Text font"), aGroupNamesGroup,
1006 SUIT_PreferenceMgr::String, ModuleBase_Preferences::VIEWER_SECTION, "group_names_font");
1007 aItem = aMgr.addPreference(tr("Text size"), aGroupNamesGroup,
1008 SUIT_PreferenceMgr::Integer, ModuleBase_Preferences::VIEWER_SECTION, "group_names_size");
1009 aPref->setItemProperty("min", 8, aItem);
1010 aPref->setItemProperty("max", 100, aItem);
1011 aItem = aMgr.addPreference(tr("Text color"), aGroupNamesGroup,
1012 SUIT_PreferenceMgr::Color, ModuleBase_Preferences::VIEWER_SECTION, "group_names_color");
1017 //******************************************************
1018 void SHAPERGUI::preferencesChanged(const QString& theSection, const QString& theParam)
1020 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1021 QString aVal = aResMgr->stringValue(theSection, theParam);
1022 Config_Prop* aProp = Config_PropManager::findProp(theSection.toStdString(),
1023 theParam.toStdString());
1025 return; // invalid case, the property default value must be registered in XML file
1026 std::string aValue = aVal.toStdString();
1027 if (aValue.empty()) {
1028 aValue = aProp->defaultValue();
1029 aResMgr->setValue(theSection, theParam, QString(aValue.c_str()));
1031 LightApp_Preferences* aPref = preferences();
1035 aProp->setValue(aValue);
1037 if (theSection == "Visualization") {
1038 if (theParam == "selection_color") {
1039 std::vector<int> aColor = Config_PropManager::color("Visualization", "selection_color");
1040 myWorkshop->displayer()->setSelectionColor(aColor);
1042 if ((theParam == "zoom_trihedron_arrows") || (theParam == "axis_arrow_size")) {
1044 Handle(AIS_Trihedron) aTrihedron = mySelector->viewer()->getTrihedron();
1045 if (!aTrihedron.IsNull()) {
1046 bool aZoom = Config_PropManager::boolean("Visualization", "zoom_trihedron_arrows");
1047 Handle(AIS_InteractiveContext) aContext = mySelector->viewer()->getAISContext();
1049 ModuleBase_IViewer* aViewer = myWorkshop->viewer();
1050 Handle(V3d_View) aView = aViewer->activeView();
1053 aView->Convert(Config_PropManager::integer("Visualization", "axis_arrow_size"));
1054 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1055 double aAxisLen = aDatumAspect->AxisLength(Prs3d_DP_XAxis);
1056 myAxisArrowRate = aDatumAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
1057 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, aAxLen / aAxisLen);
1058 aTrihedron->Attributes()->SetDatumAspect(aDatumAspect);
1059 aContext->Redisplay(aTrihedron, true);
1062 else if (myAxisArrowRate > 0) {
1063 Handle(Prs3d_DatumAspect) aDatumAspect = aTrihedron->Attributes()->DatumAspect();
1064 aDatumAspect->SetAttribute(Prs3d_DP_ShadingConeLengthPercent, myAxisArrowRate);
1065 aContext->Redisplay(aTrihedron, true);
1070 if (theParam == "use_auto_rotation") {
1071 bool aAutoRotation = Config_PropManager::boolean("Visualization", "use_auto_rotation");
1072 // Update the auto rotation flag in all OCC 3D view windows
1073 ViewManagerList lst;
1074 getApp()->viewManagers(OCCViewer_Viewer::Type(), lst);
1075 for ( auto it = lst.begin(); it != lst.end(); ++it )
1077 OCCViewer_ViewManager *aVMgr = dynamic_cast<OCCViewer_ViewManager*>(*it);
1079 aVMgr->setAutoRotation(aAutoRotation);
1084 else if (theSection == ModuleBase_Preferences::GENERAL_SECTION && theParam == "create_init_part") {
1085 bool aCreate = ModuleBase_Preferences::resourceMgr()->booleanValue(
1086 ModuleBase_Preferences::GENERAL_SECTION, "create_init_part", true);
1087 Events_MessageBool aCreateMsg(Events_Loop::eventByName(EVENT_CREATE_PART_ON_START), aCreate);
1090 else if (theSection == ModuleBase_Preferences::VIEWER_SECTION &&
1091 theParam.startsWith("group_names_"))
1092 { // one of the group names parameter changed, so, update the groups names vizualization
1093 myWorkshop->updateGroupsText();
1094 myWorkshop->displayer()->updateViewer();
1096 myWorkshop->displayer()->redisplayObjects();
1099 void SHAPERGUI::putInfo(const QString& theInfo, const int theMSecs)
1101 application()->putInfo(theInfo, theMSecs);
1104 bool SHAPERGUI::abortAllOperations()
1106 return workshop()->operationMgr()->abortAllOperations();
1109 void SHAPERGUI::createFeatureActions()
1111 myWorkshop->menuMgr()->createFeatureActions();
1114 void SHAPERGUI::onWhatIs(bool isToggled)
1116 if (sender() == myWhatIsAction) {
1117 QAction* aViewAct = myInspectionPanel->toggleViewAction();
1118 aViewAct->blockSignals(true);
1119 aViewAct->setChecked(isToggled);
1120 aViewAct->blockSignals(false);
1121 myInspectionPanel->setVisible(isToggled);
1124 myWhatIsAction->blockSignals(true);
1125 myWhatIsAction->setChecked(isToggled);
1126 myWhatIsAction->blockSignals(false);
1127 myInspectionPanel->setVisible(isToggled);
1131 void SHAPERGUI::updateModuleVisibilityState()
1133 LightApp_Module::updateModuleVisibilityState();
1134 onWhatIs(myIsInspectionVisible);
1136 // the following code is caused by #187 bug.
1137 // SALOME saves the dock widget positions before deactivateModule() and
1138 // load it after the module activation. So, if the panel is visible before
1139 // deactivate, it becomes visible after activate.
1140 // In order to avoid the visible property panel, we hide it here
1141 ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation();
1143 myWorkshop->hidePanel(myWorkshop->propertyPanel());
1147 void SHAPERGUI::onEditToolbars()
1149 SHAPERGUI_ToolbarsDlg aDlg(this);
1150 if (aDlg.exec() == QDialog::Accepted) {
1154 updateToolbars(aDlg.result());
1158 void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
1160 if (!myToolbars.contains(theToolName))
1161 myToolbars[theToolName] = QList<int>();
1162 myToolbars[theToolName].append(theCommandId);
1165 int SHAPERGUI::getNextCommandId() const
1167 QtxActionMenuMgr* aMenuMgr = menuMgr();
1168 QIntList aIds = aMenuMgr->idList();
1169 int aId = aIds.count();
1170 while (action(aId) || myActionsList.contains(aId))
1175 void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
1177 // Store default toolbars
1178 if (myDefaultToolbars.size() == 0)
1179 myDefaultToolbars = myToolbars;
1181 QtxActionToolMgr* aMgr = toolMgr();
1182 QStringList aToolbars = theNewToolbars.keys();
1183 QIntList aCommands, aOldCmd;
1187 foreach(QString aName, aToolbars) {
1188 aCommands = theNewToolbars[aName];
1189 // Find or create toolbar
1190 if (aMgr->hasToolBar(aName)) {
1191 aToolbarId = aMgr->find(aMgr->toolBar(aName));
1192 aOldCmd = myToolbars[aName];
1195 aToolbarId = aMgr->createToolBar(aName);
1198 foreach(int aCmd, aCommands) {
1201 aAction = separator();
1203 aAction = action(aCmd);
1204 aActionId = aMgr->actionId(aAction);
1205 if (aActionId == -1) {
1207 aMgr->insert(aAction, aToolbarId, aPos);
1210 // Change position of action
1211 if (aMgr->index(aActionId, aToolbarId) != aPos) {
1212 if (aMgr->containsAction(aActionId, aToolbarId))
1213 aMgr->remove(aActionId, aToolbarId);
1214 aMgr->insert(aActionId, aToolbarId, aPos);
1217 aOldCmd.removeAll(aCmd);
1220 // remove extra actions
1221 foreach(int aCmd, aOldCmd) {
1222 aAction = action(aCmd);
1223 aActionId = aMgr->actionId(aAction);
1224 aMgr->remove(aActionId, aToolbarId);
1226 myToolbars.remove(aName);
1228 // Remove extra toolbars
1229 aToolbars = myToolbars.keys();
1230 foreach(QString aName, aToolbars) {
1231 aMgr->removeToolBar(aName);
1233 // Set new toolbars structure
1234 myToolbars = theNewToolbars;
1235 myIsToolbarsModified = true;
1238 void SHAPERGUI::saveToolbarsConfig()
1240 if (!myIsToolbarsModified)
1242 // Save toolbars configuration into map
1243 QMap<QString, QStringList> aToolbarsConfig;
1245 QtxActionToolMgr* aMgr =
1248 QStringList aToolbars = myToolbars.keys();
1249 QIntList aActionsIds;
1250 foreach(QString aName, aToolbars) {
1251 aActionsIds = myToolbars[aName];
1252 QStringList aContent;
1253 foreach(int aId, aActionsIds) {
1255 aContent.append("");
1257 aContent.append(action(aId)->data().toString());
1259 aToolbarsConfig[aName] = aContent;
1261 // Store the configuration into resources
1262 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1263 QStringList aNames = aToolbarsConfig.keys();
1264 QStringList aValues;
1265 foreach(QString aToolbar, aNames) {
1266 aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
1268 // Remove obsolete parameters from resources
1269 QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
1270 foreach(QString aName, aOldParams) {
1271 if (!aToolbars.contains(aName))
1272 aResMgr->remove(ToolbarsSection, aName);
1274 // Store current list of free commands
1275 QIntList aFreeCommands = getFreeCommands();
1276 QStringList aFreeList;
1277 foreach(int aId, aFreeCommands) {
1278 aFreeList.append(action(aId)->data().toString());
1280 if (aFreeList.size() > 0)
1281 aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
1283 myIsToolbarsModified = false;
1286 void SHAPERGUI::loadToolbarsConfig()
1288 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1289 QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
1290 if (aToolbarNames.size() == 0)
1293 // Create commands map
1294 QMap<QString, int> aCommandsMap;
1296 foreach(int aId, myActionsList) {
1297 aCmdIdStr = action(aId)->data().toString();
1298 aCommandsMap[aCmdIdStr] = aId;
1301 // Create new toolbars structure
1302 QMap<QString, QIntList> aToolbars;
1303 QStringList aCommands;
1304 QIntList aKnownCommands;
1305 QList<QAction*> aActions;
1306 foreach(QString aName, aToolbarNames) {
1307 aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
1308 if (aName == FreeCommandsParam) {
1309 // The value is a list of free commands
1310 foreach(QString aCommand, aCommands) {
1311 aKnownCommands.append(aCommandsMap[aCommand]);
1315 aToolbars[aName] = QIntList();
1316 if (aCommands.size() > 0) {
1317 foreach(QString aCommand, aCommands) {
1318 if (aCommand.isEmpty())
1319 aToolbars[aName].append(-1);
1320 else if (aCommandsMap.contains(aCommand)) {
1321 int aId = aCommandsMap[aCommand];
1322 aToolbars[aName].append(aId);
1323 aKnownCommands.append(aId);
1329 // Find new and obsolete commands
1330 QIntList aNewCommands = myActionsList;
1331 foreach(int aId, myActionsList) {
1332 if (aKnownCommands.contains(aId)) {
1333 aKnownCommands.removeAll(aId);
1334 aNewCommands.removeAll(aId);
1337 if (aNewCommands.size() > 0) {
1338 // Add new commands to toolbars structure
1339 QStringList aKeys = myToolbars.keys();
1340 foreach(int aNewId, aNewCommands) {
1341 foreach(QString aName, aKeys) {
1342 if (myToolbars[aName].contains(aNewId)) {
1343 if (!aToolbars.contains(aName)) {
1344 aToolbars[aName] = QIntList();
1346 aToolbars[aName].append(aNewId);
1351 if (aKnownCommands.size() > 0) {
1352 // Remove obsolete commands from the toolbars structure
1353 QStringList aKeys = aToolbars.keys();
1354 foreach(int aOldId, aKnownCommands) {
1355 foreach(QString aName, aKeys) {
1356 if (aToolbars[aName].contains(aOldId)) {
1357 aToolbars[aName].removeAll(aOldId);
1358 if (aToolbars[aName].size() == 0)
1359 aToolbars.remove(aName);
1364 updateToolbars(aToolbars);
1365 myIsToolbarsModified = false;
1369 QIntList SHAPERGUI::getFreeCommands() const
1371 QIntList aFreeCommands;
1372 QtxActionToolMgr* aMgr = toolMgr();
1375 QMap<QString, QIntList>::const_iterator aIt;
1376 QIntList aShaperActions = shaperActions();
1377 foreach(int aCmd, aShaperActions) {
1378 anAction = action(aCmd);
1379 aId = aMgr->actionId(anAction);
1380 if (!aMgr->containsAction(aId))
1381 aFreeCommands.append(aCmd);
1383 return aFreeCommands;
1386 void SHAPERGUI::resetToolbars()
1388 if (!myDefaultToolbars.isEmpty())
1389 updateToolbars(myDefaultToolbars);
1390 myIsToolbarsModified = false;
1391 SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
1392 aResMgr->remove(ToolbarsSection);
1395 void SHAPERGUI::publishToStudy()
1397 if (isActiveModule() && ModelAPI_Session::get()->hasModuleDocument()) {
1398 myWorkshop->module()->launchOperation("PublishToStudy", false);
1400 // update SHAPERSTUDY objects in OCC and VTK viewers
1401 QStringList aVMList;
1402 aVMList << "OCCViewer" << "VTKViewer";
1403 getApp()->updatePresentations("SHAPERSTUDY", aVMList);
1407 void SHAPERGUI::fillPartSetInfoPanel(QtxInfoPanel* theInfoPanel)
1409 QIntList aShaperActions = shaperActions();
1410 theInfoPanel->addLabel(tr("Current mode: Part set mode"));
1412 addActionsToInfoGroup(theInfoPanel, tr("Parts management"),
1413 { "Part", "Duplicate", "Remove" });
1414 addActionsToInfoGroup(theInfoPanel, tr("Import operations"),
1415 { "OPEN_CMD", "IMPORT_PART_CMD", "IMPORT_SHAPE_CMD" });
1416 addActionsToInfoGroup(theInfoPanel, tr("Export operations"),
1417 { "SAVEAS_CMD", "EXPORT_PART_CMD", "EXPORT_SHAPE_CMD" });
1418 addActionsToInfoGroup(theInfoPanel, tr("Arrangement of parts"),
1419 { "Placement", "Translation", "Rotation" });
1422 void SHAPERGUI::fillPartInfoPanel(QtxInfoPanel* theInfoPanel)
1424 QIntList aShaperActions = shaperActions();
1425 theInfoPanel->addLabel(tr("Current mode: Part mode"));
1427 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1428 { "Box", "Cylinder", "Sphere" });
1429 addActionsToInfoGroup(theInfoPanel, tr("Geometry"),
1430 { "Vertex", "Edge", "Wire", "Face" });
1431 addActionsToInfoGroup(theInfoPanel, tr("Features"),
1432 { "Extrusion", "Revolution", "Cut", "Fuse", "Fillet" });
1435 void SHAPERGUI::fillSketcherInfoPanel(QtxInfoPanel* theInfoPanel)
1437 QIntList aShaperActions = shaperActions();
1438 theInfoPanel->addLabel(tr("Current mode: Sketcher mode"));
1440 addActionsToInfoGroup(theInfoPanel, tr("Primitives"),
1441 { "SketchPoint", "SketchLine", "SketchCircle", "SketchRectangle" });
1442 addActionsToInfoGroup(theInfoPanel, tr("Dimensions"),
1443 { "SketchConstraintLength", "SketchConstraintRadius", "SketchConstraintAngle" });
1444 addActionsToInfoGroup(theInfoPanel, tr("Constraints"),
1445 { "SketchConstraintParallel", "SketchConstraintPerpendicular",
1446 "SketchConstraintEqual", "SketchConstraintCoincidence" });
1449 void SHAPERGUI::addActionsToInfoGroup(QtxInfoPanel* theInfoPanel,
1450 const QString& theGroup, const QSet<QString>& theActions)
1452 QIntList aShaperActions = shaperActions();
1454 int aGroup = theInfoPanel->addGroup(theGroup);
1456 foreach(int aCmd, aShaperActions) {
1457 QAction* aAction = action(aCmd);
1458 if (theActions.contains(aAction->data().toString()))
1460 theInfoPanel->addAction(aAction, aGroup);
1463 if (aCount >= theActions.size())
1468 void SHAPERGUI::updateInfoPanel()
1470 LightApp_Application* aApp = dynamic_cast<LightApp_Application*>(application());
1471 QtxInfoPanel* aInfoPanel = aApp->infoPanel();
1472 aInfoPanel->clear();
1473 aInfoPanel->setTitle(tr("Welcome to SHAPER"));
1475 SessionPtr aMgr = ModelAPI_Session::get();
1476 QList<DocumentPtr> aDocs;
1477 DocumentPtr aActiveDoc = aMgr->activeDocument();
1478 DocumentPtr aModuleDoc = aMgr->moduleDocument();
1480 XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
1481 QStringList aOpList = aOpMgr->operationList();
1482 bool isSketcher = false;
1483 if (aOpList.size() > 0)
1484 isSketcher = (aOpList.first() == "Sketch");
1486 if (isSketcher) // Sketcher mode
1487 fillSketcherInfoPanel(aInfoPanel);
1488 else if (aActiveDoc == aModuleDoc) // Part set mode
1489 fillPartSetInfoPanel(aInfoPanel);
1491 fillPartInfoPanel(aInfoPanel);