X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_ResultPrs.cpp;h=d9460ce72b20da44fd6db842e46e20a2e42edddc;hb=5b4e69308550c299e14f336d489dc0aefbc5d6f4;hp=a298dd29723c13b92e42b45c7d781673d795f09c;hpb=f47b586aeeaa4a6cfe924e8a1c9663419f918907;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp old mode 100644 new mode 100755 index a298dd297..d9460ce72 --- a/src/ModuleBase/ModuleBase_ResultPrs.cpp +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -5,76 +5,207 @@ // Author: Vitaly SMETANNIKOV #include "ModuleBase_ResultPrs.h" +#include "ModuleBase_Tools.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_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); + + + -IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape); -IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape); ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) - : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false) + : ViewerData_AISShape(TopoDS_Shape()), myResult(theResult), myAdditionalSelectionPriority(0) { std::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); - std::shared_ptr aWirePtr = - std::dynamic_pointer_cast(aShapePtr); - if (aWirePtr) { - if (aWirePtr->hasPlane() ) { - // If this is a wire with plane defined thin it is a sketch-like object - // It must have invisible faces - myIsSketchMode = true; - } - } - Set(aShapePtr->impl()); + TopoDS_Shape aShape = aShapePtr->impl(); + Set(aShape); + Handle(Prs3d_Drawer) aDrawer = Attributes(); + if (aDrawer->HasOwnPointAspect()) + 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); + + ModuleBase_Tools::setPointBallHighlighting(this); } +void ModuleBase_ResultPrs::setAdditionalSelectionPriority(const int thePriority) +{ + myAdditionalSelectionPriority = thePriority; +} void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { std::shared_ptr aShapePtr = ModelAPI_Tools::shape(myResult); - if (!aShapePtr) - return; - if (myIsSketchMode) { - std::shared_ptr aWirePtr = - std::dynamic_pointer_cast(aShapePtr); - myFacesList.clear(); - GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(), - aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, myFacesList); + bool aReadyToDisplay = aShapePtr.get(); + if (aReadyToDisplay) { + myOriginalShape = aShapePtr->impl(); + if (!myOriginalShape.IsNull()) + Set(myOriginalShape); } - myOriginalShape = aShapePtr->impl(); - if (!myOriginalShape.IsNull()) { - Set(aShapePtr->impl()); - AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); + // change deviation coefficient to provide more precise circle + ModuleBase_Tools::setDefaultDeviationCoefficient(myResult, Attributes()); + AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); + + if (!aReadyToDisplay) { + Events_InfoMessage("ModuleBase_ResultPrs", "An empty AIS presentation: ModuleBase_ResultPrs").send(); + static const Events_ID anEvent = Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION); + ModelAPI_EventCreator::get()->sendUpdated(myResult, anEvent); } } - void ModuleBase_ResultPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { - if (myIsSketchMode) { - if (aMode == TopAbs_FACE) { - BRep_Builder aBuilder; - TopoDS_Compound aComp; - aBuilder.MakeCompound(aComp); - aBuilder.Add(aComp, myOriginalShape); - std::list>::const_iterator aIt; - for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) { - TopoDS_Shape aFace = (*aIt)->impl(); - aBuilder.Add(aComp, aFace); + if (aMode > 8) + // In order to avoid using custom selection modes + return; + + // 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)) { + const TopoDS_Shape& aShape = Shape(); + TopExp_Explorer aCompExp(aShape, TopAbs_COMPOUND); + // do not activate in compound mode shapes which do not contain compounds + if (!aCompExp.More()) + return; + } + + 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; } - Set(aComp); - } else { - Set(myOriginalShape); } - } + //AIS_Shape::ComputeSelection(aSelection, 0); + } AIS_Shape::ComputeSelection(aSelection, aMode); -} \ No newline at end of file + + if (myAdditionalSelectionPriority > 0) { + for (aSelection->Init(); aSelection->More(); aSelection->Next()) { + Handle(SelectBasics_EntityOwner) aBasicsOwner = aSelection->Sensitive()->BaseSensitive()->OwnerId(); + if (!aBasicsOwner.IsNull()) + aBasicsOwner->Set(aBasicsOwner->Priority() + myAdditionalSelectionPriority); + } + } +} + +void ModuleBase_ResultPrs::appendWiresSelection(const Handle(SelectMgr_Selection)& theSelection, + const TopoDS_Shape& theShape) +{ + 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 ) { + } +} + +void ModuleBase_ResultPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM, + const SelectMgr_SequenceOfOwner& theOwners) +{ + Handle(SelectMgr_EntityOwner) anOwner; + Handle(ModuleBase_BRepOwner) aCompOwner; + for (int i = 1; i <= theOwners.Length(); i++) { + anOwner = theOwners.Value(i); + aCompOwner = Handle(ModuleBase_BRepOwner)::DownCast(anOwner); + if (aCompOwner.IsNull()) + anOwner->Hilight(thePM); + else { + TopoDS_Shape aShape = aCompOwner->Shape(); + 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) +{ + Handle(StdSelect_BRepOwner) aOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if (aOwner.IsNull()) + return; + + TopoDS_Shape aShape = aOwner->Shape(); + 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); + } +}