From 0f6ef7c56be3322d832376ed464dee4e13d44dbf Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 1 Apr 2015 14:44:27 +0300 Subject: [PATCH] Improve sketcher popup menu processing --- src/ModuleBase/ModuleBase_IModule.h | 5 +- src/PartSet/PartSet_Module.cpp | 10 ++- src/PartSet/PartSet_Module.h | 4 +- src/SketcherPrs/SketcherPrs_Coincident.cpp | 21 ++++-- src/SketcherPrs/SketcherPrs_Coincident.h | 1 + src/XGUI/XGUI_ContextMenuMgr.cpp | 76 ++++++++++++---------- 6 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index c7cd377cc..1d6837205 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -75,7 +76,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Add menu atems for viewer into the given menu /// \param theMenu a popup menu to be shown in the viewer - virtual void addViewerItems(QMenu* theMenu) const {} + /// \param theStdActions a map of standard actions + /// \return true if items are added and there is no necessity to provide standard menu + virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const { return false; } /// Add menu atems for object browser into the given menu /// \param theMenu a popup menu to be shown in the object browser diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 841387209..4c6856835 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -288,12 +288,12 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const return aCanDisplay; } -void PartSet_Module::addViewerItems(QMenu* theMenu) const +bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMap& theStdActions) const { ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); if (!PartSet_SketcherMgr::isSketchOperation(anOperation) && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - return; + return false; ModuleBase_ISelection* aSelection = myWorkshop->selection(); QObjectPtrList aObjects = aSelection->selectedPresentations(); @@ -307,10 +307,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const } } if (hasFeature) { - XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD"); - theMenu->addAction(anAction); + theMenu->addAction(theStdActions["DELETE_CMD"]); } } bool isAuxiliary; @@ -319,6 +316,7 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const theMenu->addAction(anAction); anAction->setChecked(isAuxiliary); } + return true; } void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 891759c36..5264352dc 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -103,7 +103,9 @@ public: /// Add menu atems for viewer into the given menu /// \param theMenu a popup menu to be shown in the viewer - virtual void addViewerItems(QMenu* theMenu) const; + /// \param theStdActions a map of standard actions + /// \return true if items are added and there is no necessity to provide standard menu + virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const; public slots: /// SLOT, that is called by no more widget signal emitted by property panel diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 60c2e451a..86f1a1f3e 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Coincident, AIS_InteractiveObject); @@ -34,6 +37,7 @@ SketcherPrs_Coincident::SketcherPrs_Coincident(SketchPlugin_Constraint* theConst const std::shared_ptr& thePlane) : AIS_InteractiveObject(), myConstraint(theConstraint), myPlane(thePlane) { + } @@ -48,11 +52,15 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& return; std::shared_ptr aPoint = myPlane->to3D(aPnt->x(), aPnt->y()); - - static Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d (); - aPtA->SetType(Aspect_TOM_RING1); - aPtA->SetScale(2.); - aPtA->SetColor(myOwnColor); + myPoint = aPoint->impl(); + + static Handle(Graphic3d_AspectMarker3d) aPtA; + if (aPtA.IsNull()) { + aPtA = new Graphic3d_AspectMarker3d (); + aPtA->SetType(Aspect_TOM_RING1); + aPtA->SetScale(2.); + aPtA->SetColor(myOwnColor); + } Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); aGroup->SetPrimitivesAspect(aPtA); Handle(Graphic3d_ArrayOfPoints) aPntArray = new Graphic3d_ArrayOfPoints(1); @@ -64,6 +72,9 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { + Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10); + Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint); + aSelection->Add(aSp); } void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol) diff --git a/src/SketcherPrs/SketcherPrs_Coincident.h b/src/SketcherPrs/SketcherPrs_Coincident.h index 9b9c4cd8a..72c7ec5d0 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.h +++ b/src/SketcherPrs/SketcherPrs_Coincident.h @@ -47,6 +47,7 @@ protected: private: SketchPlugin_Constraint* myConstraint; std::shared_ptr myPlane; + gp_Pnt myPoint; }; diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 282b1a31c..91d5c2f7c 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -227,40 +227,49 @@ QMenu* XGUI_ContextMenuMgr::viewerMenu() const void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const { - XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); - QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); - if (aObjects.size() > 0) { - //if (aObjects.size() == 1) - // theMenu->addAction(action("EDIT_CMD")); - bool isVisible = false; - bool isShading = false; - bool canBeShaded = false; - foreach(ObjectPtr aObject, aObjects) - { - ResultPtr aRes = std::dynamic_pointer_cast(aObject); - if (aRes && myWorkshop->displayer()->isVisible(aRes)) { - isVisible = true; - canBeShaded = myWorkshop->displayer()->canBeShaded(aObject); - isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); - break; + bool aIsDone = false; + ModuleBase_IModule* aModule = myWorkshop->module(); + if (aModule) + aIsDone = aModule->addViewerItems(theMenu, myActions); + + if (!aIsDone) { + XGUI_SelectionMgr* aSelMgr = myWorkshop->selector(); + QObjectPtrList aObjects = aSelMgr->selection()->selectedObjects(); + if (aObjects.size() > 0) { + //if (aObjects.size() == 1) + // theMenu->addAction(action("EDIT_CMD")); + bool isVisible = false; + bool isShading = false; + bool canBeShaded = false; + foreach(ObjectPtr aObject, aObjects) + { + ResultPtr aRes = std::dynamic_pointer_cast(aObject); + if (aRes && myWorkshop->displayer()->isVisible(aRes)) { + isVisible = true; + canBeShaded = myWorkshop->displayer()->canBeShaded(aObject); + isShading = (myWorkshop->displayer()->displayMode(aObject) == XGUI_Displayer::Shading); + break; + } } + if (isVisible) { + if (canBeShaded) { + if (isShading) + theMenu->addAction(action("WIREFRAME_CMD")); + else + theMenu->addAction(action("SHADING_CMD")); + } + theMenu->addSeparator(); + theMenu->addAction(action("SHOW_ONLY_CMD")); + theMenu->addAction(action("HIDE_CMD")); + } else + theMenu->addAction(action("SHOW_CMD")); + //theMenu->addAction(action("DELETE_CMD")); } - if (isVisible) { - if (canBeShaded) { - if (isShading) - theMenu->addAction(action("WIREFRAME_CMD")); - else - theMenu->addAction(action("SHADING_CMD")); - } - theMenu->addSeparator(); - theMenu->addAction(action("SHOW_ONLY_CMD")); - theMenu->addAction(action("HIDE_CMD")); - } else - theMenu->addAction(action("SHOW_CMD")); - //theMenu->addAction(action("DELETE_CMD")); + if (myWorkshop->canChangeColor()) + theMenu->addAction(action("COLOR_CMD")); + if (myWorkshop->displayer()->objectsCount() > 0) + theMenu->addAction(action("HIDEALL_CMD")); } - if (myWorkshop->displayer()->objectsCount() > 0) - theMenu->addAction(action("HIDEALL_CMD")); if (!myWorkshop->isSalomeMode()) { theMenu->addSeparator(); QMdiArea* aMDI = myWorkshop->mainWindow()->mdiArea(); @@ -269,12 +278,7 @@ void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const aSubMenu->addActions(aMDI->actions()); } } - if (myWorkshop->canChangeColor()) - theMenu->addAction(action("COLOR_CMD")); - ModuleBase_IModule* aModule = myWorkshop->module(); - if (aModule) - aModule->addViewerItems(theMenu); } void XGUI_ContextMenuMgr::connectObjectBrowser() const -- 2.30.2