X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ResultPrs.cpp;h=b988f7fec2677ba5a3e8e8c56fe17bea3a8de05c;hb=4b7e6acd7e2430b11a86eeb9867ea54396c05f08;hp=0dd37b3550efc2c532da7bdea5a515390075ffdf;hpb=5c59bf6725e7e4855b5ca956475d705e2d5b014c;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp index 0dd37b355..b988f7fec 100755 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -19,36 +19,40 @@ // #include "ModuleBase_ResultPrs.h" -#include "ModuleBase_Tools.h" + +#include #include #include #include #include -#include + +#include "ModuleBase_Tools.h" +#include "ModuleBase_BRepOwner.h" #include #include +#include +#include +#include #include +#include #include #include #include #include -#include -#include +#include #include #include #include #include +#include #include -#include -#include #include -#include #include - -IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_BRepOwner, StdSelect_BRepOwner); +#include +#include //******************************************************************************************* @@ -56,8 +60,10 @@ IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, ViewerData_AISShape); +//******************************************************************** ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) - : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0) + : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0), + myTransparency(1) { std::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); TopoDS_Shape aShape = aShapePtr->impl(); @@ -72,14 +78,98 @@ ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); SetAutoHilight(aCompSolid.get() == NULL); + myHiddenSubShapesDrawer = new AIS_ColoredDrawer (myDrawer); + Handle(Prs3d_ShadingAspect) aShadingAspect = new Prs3d_ShadingAspect(); + aShadingAspect->SetMaterial(Graphic3d_NOM_BRASS); //default value of context material + myHiddenSubShapesDrawer->SetShadingAspect(aShadingAspect); + ModuleBase_Tools::setPointBallHighlighting(this); } +//******************************************************************** void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority) { myAdditionalSelectionPriority = thePriority; } +//******************************************************************** +void ModuleBase_ResultPrs::SetColor (const Quantity_Color& theColor) +{ + ViewerData_AISShape::SetColor(theColor); + myHiddenSubShapesDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel); +} + +//******************************************************************** +bool ModuleBase_ResultPrs::setSubShapeHidden(const NCollection_List& theShapes) +{ + bool isModified = false; + + TopoDS_Compound aCompound; + BRep_Builder aBBuilder; + aBBuilder.MakeCompound (aCompound); + // restore hidden shapes if there are not the shapes in parameter container + NCollection_List aVisibleSubShapes; + for (NCollection_List::Iterator aHiddenIt(myHiddenSubShapes); aHiddenIt.More(); + aHiddenIt.Next()) { + if (!theShapes.Contains(aHiddenIt.Value())) + aVisibleSubShapes.Append(aHiddenIt.Value()); + else + aBBuilder.Add (aCompound, aHiddenIt.Value()); + } + isModified = !aVisibleSubShapes.IsEmpty(); + for (NCollection_List::Iterator aVisibleIt(aVisibleSubShapes); aVisibleIt.More(); + aVisibleIt.Next()) + myHiddenSubShapes.Remove(aVisibleIt.Value()); + + // append hidden shapes into internal container if there are not these shapes + for (NCollection_List::Iterator aShapeIt(theShapes); aShapeIt.More(); + aShapeIt.Next()) + { + if (aShapeIt.Value().ShapeType() != TopAbs_FACE) // only face shape can be hidden + continue; + + if (!myHiddenSubShapes.Contains(aShapeIt.Value())) { + myHiddenSubShapes.Append(aShapeIt.Value()); + aBBuilder.Add (aCompound, aShapeIt.Value()); + isModified = true; + } + } + myHiddenCompound = aCompound; + return isModified; +} + +//******************************************************************** +bool ModuleBase_ResultPrs::hasSubShapeVisible(const TopoDS_Shape& theShape) +{ + int aNbOfHiddenSubShapes = myHiddenSubShapes.Size(); + + if (!myHiddenSubShapes.Contains(theShape)) + aNbOfHiddenSubShapes++; // the shape to be hidden later + + TopExp_Explorer anExp(myOriginalShape, TopAbs_FACE); + bool aHasVisibleShape = false; + for(TopExp_Explorer anExp(myOriginalShape, TopAbs_FACE); anExp.More() && !aHasVisibleShape; + anExp.Next()) + { + aNbOfHiddenSubShapes--; + if (aNbOfHiddenSubShapes < 0) + aHasVisibleShape = true; + } + return aHasVisibleShape; +} + +//******************************************************************** +bool ModuleBase_ResultPrs::setHiddenSubShapeTransparency(double theTransparency) +{ + if (theTransparency > 1 || theTransparency < 0) + return false; + + myTransparency = theTransparency; + myHiddenSubShapesDrawer->ShadingAspect()->SetTransparency (theTransparency, myCurrentFacingModel); + return true; +} + +//******************************************************************** void ModuleBase_ResultPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, @@ -89,13 +179,36 @@ void ModuleBase_ResultPrs::Compute( bool aReadyToDisplay = aShapePtr.get(); if (aReadyToDisplay) { myOriginalShape = aShapePtr->impl(); - if (!myOriginalShape.IsNull()) - Set(myOriginalShape); + if (myHiddenSubShapes.IsEmpty() || myOriginalShape.ShapeType() > TopAbs_FACE ) { + if (!myOriginalShape.IsNull()) + Set(myOriginalShape); + } + else { // convert shape into SHELL + TopoDS_Shell aShell; + BRep_Builder aShellBuilder; + aShellBuilder.MakeShell(aShell); + bool isEmptyShape = true; + for(TopExp_Explorer anExp(myOriginalShape, TopAbs_FACE); anExp.More(); anExp.Next()) { + if (myHiddenSubShapes.Contains(anExp.Current())) + continue; + aShellBuilder.Add(aShell, anExp.Current()); + isEmptyShape = false; + } + Set(aShell); + if (isEmptyShape) + aReadyToDisplay = false; + } } // change deviation coefficient to provide more precise circle //ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); + // visualize hidden sub-shapes transparent + if (myTransparency < 1 && !myHiddenSubShapes.IsEmpty()) + { + StdPrs_ShadedShape::Add (thePresentation, myHiddenCompound, myHiddenSubShapesDrawer); + } + if (!aReadyToDisplay) { Events_InfoMessage("ModuleBase_ResultPrs", "An empty AIS presentation: ModuleBase_ResultPrs").send(); @@ -104,12 +217,16 @@ void ModuleBase_ResultPrs::Compute( } } +//******************************************************************** void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, - const Standard_Integer aMode) + const Standard_Integer theMode) { - if (aMode > TopAbs_SHAPE) { + if (appendVertexSelection(aSelection, theMode)) + return; + + if (theMode > TopAbs_SHAPE) { // In order to avoid using custom selection modes - if (aMode == ModuleBase_ResultPrs::Sel_Result) { + if (theMode == ModuleBase_ResultPrs::Sel_Result) { AIS_Shape::ComputeSelection(aSelection, TopAbs_COMPOUND); } return; @@ -117,7 +234,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a // TODO: OCCT issue should be created for the COMPOUND processing // before it is fixed, the next workaround in necessary - if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) { + if (theMode == AIS_Shape::SelectionMode(TopAbs_COMPOUND)) { const TopoDS_Shape& aShape = Shape(); TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND); // do not activate in compound mode shapes which do not contain compounds @@ -125,7 +242,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a return; } - if (aMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) { + if (theMode == AIS_Shape::SelectionMode(TopAbs_COMPSOLID)) { // Limit selection area only by actual object (Shape) ResultCompSolidPtr aCompSolid = ModelAPI_Tools::compSolidOwner(myResult); if (aCompSolid.get()) { @@ -154,7 +271,7 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a } //AIS_Shape::ComputeSelection(aSelection, 0); } - AIS_Shape::ComputeSelection(aSelection, aMode); + AIS_Shape::ComputeSelection(aSelection, theMode); if (myAdditionalSelectionPriority > 0) { for (aSelection->Init(); aSelection->More(); aSelection->Next()) { @@ -166,25 +283,35 @@ void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& a } } -void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection, - const TopoDS_Shape& theShape) +//******************************************************************** +bool ModuleBase_ResultPrs::appendVertexSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer theMode) { - static TopAbs_ShapeEnum TypOfSel - = AIS_Shape::SelectionType(AIS_Shape::SelectionMode(TopAbs_WIRE)); - // POP protection against crash in low layers - Standard_Real aDeflection = Prs3d::GetDeflection(theShape, myDrawer); - try { - StdSelect_BRepSelectionTool::Load(theSelection, - this, - theShape, - TypOfSel, - aDeflection, - myDrawer->HLRAngle(), - myDrawer->IsAutoTriangulation()); - } catch ( Standard_Failure ) { + if (Shape().ShapeType() == TopAbs_VERTEX) { + const TopoDS_Shape& aShape = Shape(); + + int aPriority = StdSelect_BRepSelectionTool::GetStandardPriority(aShape, TopAbs_VERTEX); + double aDeflection = Prs3d::GetDeflection(aShape, myDrawer); + + /// The cause of this method is the last parameter of BRep owner setting into True. + /// That means that owner should behave like it comes from decomposition. (In this case, OCCT + /// visualizes it in Ring style) OCCT version is 7.0.0 with path for SHAPER module. + Handle(StdSelect_BRepOwner) aOwner = new StdSelect_BRepOwner(aShape, aPriority, Standard_True); + 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 true; } + return false; } +//******************************************************************** void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, const SelectMgr_SequenceOfOwner& theOwners) { @@ -211,6 +338,7 @@ void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManag } } +//******************************************************************** void ModuleBase_ResultPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM, const Handle(Graphic3d_HighlightStyle)& theStyle, const Handle(SelectMgr_EntityOwner)& theOwner)