From d81101039fb361a402d28f738a8fe0be3f9e6ac5 Mon Sep 17 00:00:00 2001 From: duv Date: Wed, 8 Oct 2014 13:01:51 +0400 Subject: [PATCH] 0025335: Visualization - method ::SelectedShape() in AIS_LocalContext and AIS_InteractiveContext overrides shape transformation Shape location overriding fixed by combining AIS object transformation and shape location. Also incorrect highlight presentation (and sensitive) placement was possible. --- src/AIS/AIS_InteractiveContext_1.cxx | 12 ++++--- src/AIS/AIS_LocalContext_1.cxx | 13 ++++--- src/AIS/AIS_Shape.cxx | 4 --- src/ViewerTest/ViewerTest.cxx | 51 ++++++++++++++++++++++++++++ tests/bugs/vis/bug25335 | 24 +++++++++++++ 5 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 tests/bugs/vis/bug25335 diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 9d041b0297..90168e831f 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -1122,10 +1122,14 @@ TopoDS_Shape AIS_InteractiveContext::SelectedShape() const { if (!HasOpenedContext()) { - TopoDS_Shape sh; - Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(SelectedInteractive()); - if (!shape.IsNull()) sh = shape->Shape().Located (SelectedInteractive()->Transformation()); - return sh; + TopoDS_Shape aResShape; + Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive()); + if (!aShape.IsNull()) + { + aResShape = aShape->Shape().Located (TopLoc_Location (SelectedInteractive()->Transformation()) * aShape->Shape().Location()); + } + + return aResShape; } else { diff --git a/src/AIS/AIS_LocalContext_1.cxx b/src/AIS/AIS_LocalContext_1.cxx index 280c1c0210..6ef3585610 100644 --- a/src/AIS/AIS_LocalContext_1.cxx +++ b/src/AIS/AIS_LocalContext_1.cxx @@ -776,15 +776,14 @@ HasShape() const //================================================== TopoDS_Shape AIS_LocalContext::SelectedShape() const { - static TopoDS_Shape aSh; - Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); - Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); - Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); - if( BRO.IsNull() ) + Handle(Standard_Transient) aTr = AIS_Selection::CurrentSelection()->Value(); + Handle(SelectMgr_EntityOwner) anEO = *((Handle(SelectMgr_EntityOwner)*)&aTr); + Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(anEO); + if( aBRO.IsNull() ) { - return aSh; + return TopoDS_Shape(); } - return BRO->Shape().Located (BRO->Location()); + return aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location()); } //================================================== diff --git a/src/AIS/AIS_Shape.cxx b/src/AIS/AIS_Shape.cxx index 468b684de0..780349ee3f 100644 --- a/src/AIS/AIS_Shape.cxx +++ b/src/AIS/AIS_Shape.cxx @@ -379,10 +379,6 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, static TopAbs_ShapeEnum TypOfSel; TypOfSel = AIS_Shape::SelectionType(aMode); TopoDS_Shape shape = myshape; - if( HasTransformation() ) { - gp_Trsf trsf = Transformation(); - shape = shape.Located(TopLoc_Location(trsf)*shape.Location()); - } // POP protection against crash in low layers diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index a1597da1da..9ef3bce06f 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -4079,6 +4079,54 @@ static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** return 0; } +//======================================================================= +//function : VPickSelected +//purpose : +//======================================================================= +static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs) +{ + static Standard_Integer aCount = 0; + TCollection_AsciiString aName = "PickedShape_"; + + if (theArgNb > 1) + { + aName = theArgs[1]; + } + else + { + aName = aName + aCount++ + "_"; + } + + Standard_Integer anIdx = 0; + for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx) + { + TopoDS_Shape aShape; + if (TheAISContext()->HasSelectedShape()) + { + aShape = TheAISContext()->SelectedShape(); + } + else + { + Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); + aShape = (*((Handle(AIS_Shape)*) &IO))->Shape(); + } + + TCollection_AsciiString aCurrentName = aName; + if (anIdx > 0) + { + aCurrentName += anIdx; + } + + DBRep::Set ((aCurrentName).ToCString(), aShape); + + Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape); + GetMapOfAIS().Bind (aNewShape, aCurrentName); + TheAISContext()->Display (aNewShape); + } + + return 0; +} + //======================================================================= //function : list of known objects //purpose : @@ -4636,6 +4684,9 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) theCommands.Add("vr", "vr : reading of the shape", __FILE__,vr, group); + theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.", + __FILE__, VPickSelected, group); + } //===================================================================== diff --git a/tests/bugs/vis/bug25335 b/tests/bugs/vis/bug25335 new file mode 100644 index 0000000000..f8835cf4e1 --- /dev/null +++ b/tests/bugs/vis/bug25335 @@ -0,0 +1,24 @@ +puts "================" +puts "OCC25335" +puts "================" +puts "" +####################################################################################### +# Visualization - method ::SelectedShape() in AIS_LocalContext and AIS_InteractiveContext overrides shape transformation +####################################################################################### + +vinit + +box b 1 1 1 +vdisplay b +btranslate b 1 0 0 +vselmode 2 1 +vfit +vselect 299 352 +vpickselected +vsetlocation b 0 1 0 +vzfit +vselect 233 188 +vpickselected +vsetlocation b -2 2 0 +vfit +