From 6745a491d370afafd5a741877e7931e0c60beef2 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 16 Dec 2015 12:00:06 +0300 Subject: [PATCH] Issue #1019: Provide CompSolid selection mode for composite results --- src/FeaturesPlugin/rotation_widget.xml | 2 +- src/FeaturesPlugin/translation_widget.xml | 2 +- src/ModuleBase/ModuleBase_ISelection.cpp | 7 +- src/ModuleBase/ModuleBase_ResultPrs.cpp | 128 +++++++++++++++++++++- src/ModuleBase/ModuleBase_ResultPrs.h | 42 +++++++ src/XGUI/XGUI_Selection.cpp | 23 ++++ 6 files changed, 193 insertions(+), 11 deletions(-) diff --git a/src/FeaturesPlugin/rotation_widget.xml b/src/FeaturesPlugin/rotation_widget.xml index d715df152..f483a7403 100755 --- a/src/FeaturesPlugin/rotation_widget.xml +++ b/src/FeaturesPlugin/rotation_widget.xml @@ -5,7 +5,7 @@ label="Main objects" icon=":icons/cut_shape.png" tooltip="Select a solid objects" - type_choice="" + type_choice="solid" use_choice="false" concealment="true"> diff --git a/src/FeaturesPlugin/translation_widget.xml b/src/FeaturesPlugin/translation_widget.xml index c9261206b..41e53b002 100644 --- a/src/FeaturesPlugin/translation_widget.xml +++ b/src/FeaturesPlugin/translation_widget.xml @@ -5,7 +5,7 @@ label="Main objects" icon=":icons/cut_shape.png" tooltip="Select a solid objects" - type_choice="" + type_choice="solid" concealment="true"> diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp index 72f1e4df8..d5c325558 100644 --- a/src/ModuleBase/ModuleBase_ISelection.cpp +++ b/src/ModuleBase/ModuleBase_ISelection.cpp @@ -38,13 +38,12 @@ ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs) { ResultPtr aResult; - if (!thePrs.owner().IsNull()) { + if (thePrs.object().get()) + aResult = std::dynamic_pointer_cast(thePrs.object()); + else if (!thePrs.owner().IsNull()) { ObjectPtr anObject = getSelectableObject(thePrs.owner()); aResult = std::dynamic_pointer_cast(anObject); } - else { - aResult = std::dynamic_pointer_cast(thePrs.object()); - } return aResult; } diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 73a492df9..f7f360422 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -13,13 +13,32 @@ #include #include +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include + + + +IMPLEMENT_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner); +IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner); + +//******************************************************************************************* IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape); IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape); + + + + ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false) { @@ -40,6 +59,10 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_PLUS); else aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_PLUS, Quantity_NOC_YELLOW, 1.)); + + // Activate individual repaintng if this is a part of compsolid + ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); + SetAutoHilight(aCompSolid.get() == NULL); } @@ -50,6 +73,7 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t std::shared_ptr aShapePtr = ModelAPI_Tools::shape(myResult); if (!aShapePtr) return; + if (myIsSketchMode) { myFacesList.clear(); ResultConstructionPtr aConstruction = @@ -75,12 +99,13 @@ void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& t void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { - if (aMode > TopAbs_SHAPE) + if (aMode > 8) // In order to avoid using custom selection modes return; + if (myIsSketchMode) { - if (aMode == TopAbs_FACE) { + if (aMode == AIS_Shape::SelectionMode(TopAbs_FACE)) { BRep_Builder aBuilder; TopoDS_Compound aComp; aBuilder.MakeCompound(aComp); @@ -91,9 +116,102 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a aBuilder.Add(aComp, aFace); } Set(aComp); - } else { + } else Set(myOriginalShape); + } + if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) { + // Limit selection area only by actual object (Shape) + ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); + if (aCompSolid.get()) { + std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aCompSolid); + if (aShapePtr.get()) { + TopoDS_Shape aShape = aShapePtr->impl(); + int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_SHAPE); + double aDeflection = Prs3d::GetDeflection(aShape, myDrawer); + + Handle(ModuleBase_BRepOwner) aOwner = new ModuleBase_BRepOwner(aShape, aPriority); + StdSelect_BRepSelectionTool::ComputeSensitive(aShape, aOwner, aSelection, + aDeflection, myDrawer->HLRAngle(), 9, 500); + + for (aSelection->Init(); aSelection->More(); aSelection->Next()) { + Handle(SelectMgr_EntityOwner) anOwner + = Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Sensitive()->BaseSensitive()->OwnerId()); + anOwner->Set(this); + } + return; + } } - } + //AIS_Shape::ComputeSelection(aSelection, 0); + } AIS_Shape::ComputeSelection(aSelection, aMode); -} \ No newline at end of file +} + + +bool ModuleBase_ResultPrs::hasCompSolidSelectionMode() const +{ + if (!HasInteractiveContext()) + return false; + + Handle(AIS_InteractiveContext) aContext = GetContext(); + TColStd_ListOfInteger aModes; + aContext->ActivatedModes(this, aModes); + + TColStd_ListIteratorOfListOfInteger aIt(aModes); + for (; aIt.More(); aIt.Next()) { + if (aIt.Value() == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) + return true; + } + return false; +} + + +TopoDS_Shape ModuleBase_ResultPrs::getSelectionShape() const +{ + if (hasCompSolidSelectionMode()) { + // In case of CompSolid mode use shape from Parent for highlighting + ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); + if (aCompSolid.get()) { + std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aCompSolid); + if (aShapePtr.get()) + return aShapePtr->impl(); + } + } + return myOriginalShape; +} + + +void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, + const SelectMgr_SequenceOfOwner& theOwners) +{ + TopoDS_Shape aShape = getSelectionShape(); + if (!aShape.IsNull()) { + Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM ); + aSelectionPrs->Clear(); + + StdPrs_WFDeflectionShape::Add(aSelectionPrs, aShape, myDrawer); + + aSelectionPrs->SetDisplayPriority(9); + aSelectionPrs->Highlight(Aspect_TOHM_COLOR, aSelectionPrs->HighlightColor()); + aSelectionPrs->Display(); + thePM->Highlight(this); + } +} + +void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, + const Quantity_NameOfColor theColor, + const Handle(SelectMgr_EntityOwner)& theOwner) +{ + TopoDS_Shape aShape = getSelectionShape(); + if (!aShape.IsNull()) { + thePM->Color(this, theColor); + + Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM ); + aHilightPrs->Clear(); + + StdPrs_WFDeflectionShape::Add(aHilightPrs, aShape, myDrawer); + aHilightPrs->Highlight(Aspect_TOHM_COLOR, theColor); + + if (thePM->IsImmediateModeOn()) + thePM->AddToImmediateList(aHilightPrs); + } +} diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h index 0389241a0..056d757e1 100644 --- a/src/ModuleBase/ModuleBase_ResultPrs.h +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -13,6 +13,31 @@ #include #include +#include + +DEFINE_STANDARD_HANDLE(ModuleBase_BRepOwner, StdSelect_BRepOwner) + +/** +* \ingroup GUI +* A redefinition of standard BRep Owner in order to provide specific selection +* of CompSolid objects. This owner is created only for selection mode TopAbs_COMPSOLID +*/ +class ModuleBase_BRepOwner: public StdSelect_BRepOwner +{ +public: + ModuleBase_BRepOwner(const TopoDS_Shape& aShape, + const Standard_Integer aPriority = 0, + const Standard_Boolean ComesFromDecomposition = Standard_False) + : StdSelect_BRepOwner(aShape, aPriority, ComesFromDecomposition) {} + + virtual void HilightWithColor (const Handle(PrsMgr_PresentationManager3d)& aPM, + const Quantity_NameOfColor aCol, const Standard_Integer aMode = 0) + { Selectable()->HilightOwnerWithColor(aPM, aCol, this); } + + DEFINE_STANDARD_RTTI(ModuleBase_BRepOwner) +}; + + DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, ViewerData_AISShape) @@ -28,6 +53,16 @@ public: /// \param theResult a result object Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult); + + //! Method which draws selected owners ( for fast presentation draw ) + Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, + const SelectMgr_SequenceOfOwner& theOwners); + + //! Method which hilight an owner belonging to + //! this selectable object ( for fast presentation draw ) + Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, + const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner); + /// Returns result object Standard_EXPORT ResultPtr getResult() const { return myResult; } @@ -37,6 +72,9 @@ public: /// Returns a list of faces Standard_EXPORT const std::list >& facesList() { return myFacesList; } + /// Returns true if the object is used in CompSolid selection mode + Standard_EXPORT bool hasCompSolidSelectionMode() const; + DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs) protected: /// Redefinition of virtual function @@ -48,6 +86,10 @@ protected: const Standard_Integer aMode) ; private: + /// Returns shape dependent on CompSolid selection mode + /// In case CompSolid selection mode it returns parent's compsolid shape + TopoDS_Shape getSelectionShape() const; + /// Reference to result object ResultPtr myResult; diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 1b6f86542..079c30cba 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -10,7 +10,10 @@ #include "XGUI_ViewerProxy.h" #include "XGUI_ObjectsBrowser.h" +#include "ModuleBase_ResultPrs.h" + #include +#include #include #include @@ -166,6 +169,26 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrs& thePrs, XGUI_Displayer* aDisplayer = myWorkshop->displayer(); ObjectPtr aFeature = aDisplayer->getObject(anIO); + + Handle(ModuleBase_BRepOwner) aCompSolidBRO = Handle(ModuleBase_BRepOwner)::DownCast(theOwner); + if (!aCompSolidBRO.IsNull()) { + // If ModuleBase_BRepOwner object is created then it means that TopAbs_COMPSOLID selection mode + // is On and we have to use parent result which corresponds to the CompSolid shape + ResultPtr aResult = std::dynamic_pointer_cast(aFeature); + if (aResult.get()) { + ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(aResult); + if (aCompSolid.get()) { + GeomShapePtr aShapePtr = aCompSolid->shape(); + if (aShapePtr.get()) { + TopoDS_Shape aShape = aShapePtr->impl(); + if (aShape.IsEqual(thePrs.shape())) { + thePrs.setObject(aCompSolid); + return; + } + } + } + } + } thePrs.setObject(aFeature); } -- 2.39.2