From 1c078d3b39ba785b7f369f4a361f9d3a2a213959 Mon Sep 17 00:00:00 2001 From: aba Date: Wed, 11 Nov 2015 13:41:59 +0300 Subject: [PATCH] 0026056: AIS_LengthDimension can not build dimension for face-edge or edge-face - Correct AIS_LengthDimension::InitEdgeFaceLength() method to support face-edge and edge-face cases - Correct test command to support face-edge and edge-face input geomerty without custom plane --- src/AIS/AIS_LengthDimension.cxx | 58 ++++--- src/AIS/AIS_LengthDimension.hxx | 4 +- .../ViewerTest_RelationCommands.cxx | 144 +++++++----------- tests/bugs/vis/bug26056 | 25 +++ 4 files changed, 118 insertions(+), 113 deletions(-) create mode 100644 tests/bugs/vis/bug26056 diff --git a/src/AIS/AIS_LengthDimension.cxx b/src/AIS/AIS_LengthDimension.cxx index ebbba29fe8..f941818883 100755 --- a/src/AIS/AIS_LengthDimension.cxx +++ b/src/AIS/AIS_LengthDimension.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -26,8 +27,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -433,28 +434,32 @@ Standard_Boolean AIS_LengthDimension::InitEdgeFaceLength (const TopoDS_Edge& the const TopoDS_Face& theFace, gp_Dir& theEdgeDir) { - Handle(Geom_Curve) aCurve; - gp_Pnt aFirstPoint, aSecondPoint; - Standard_Boolean isInfinite = Standard_False; - - if (!AIS::ComputeGeometry (theEdge, aCurve, aFirstPoint, aSecondPoint, isInfinite)) + // Compute edge direction + BRepAdaptor_Curve aCurveAdaptor (theEdge); + Handle(Geom_Curve) aCurve = Handle(Geom_Curve)::DownCast (aCurveAdaptor.Curve().Curve()->Transformed (aCurveAdaptor.Trsf())); + if (aCurve.IsNull()) { return Standard_False; } - theEdgeDir = gce_MakeDir (aFirstPoint, aSecondPoint); - gp_Pln aPlane; - Handle(Geom_Surface) aSurface; - AIS_KindOfSurface aSurfType; - Standard_Real anOffset; - - if (!AIS::GetPlaneFromFace (theFace, aPlane, aSurface, aSurfType, anOffset)) + Standard_Real aFirst = aCurveAdaptor.FirstParameter(); + Standard_Real aLast = aCurveAdaptor.LastParameter(); + gp_Pnt aFirstPoint = !Precision::IsInfinite (aFirst) ? aCurve->Value (aFirst) : gp::Origin(); + gp_Pnt aSecondPoint = !Precision::IsInfinite (aLast) ? aCurve->Value (aLast) : gp::Origin(); + gce_MakeDir aMakeDir (aFirstPoint, aSecondPoint); + if (!aMakeDir.IsDone()) { return Standard_False; } + theEdgeDir = aMakeDir.Value(); - GeomAPI_ExtremaCurveSurface aDistAdaptor (aCurve, aSurface); - - aDistAdaptor.NearestPoints (myFirstPoint, mySecondPoint); + // Find attachment points + BRepExtrema_DistShapeShape aDistAdaptor (theEdge, theFace, Extrema_ExtFlag_MIN); + if (!aDistAdaptor.IsDone()) + { + return Standard_False; + } + myFirstPoint = aDistAdaptor.PointOnShape1 (1); + mySecondPoint = aDistAdaptor.PointOnShape2 (1); return IsValidPoints (myFirstPoint, mySecondPoint); } @@ -578,11 +583,11 @@ Standard_Boolean AIS_LengthDimension::InitTwoShapesPoints (const TopoDS_Shape& t return isSuccess && IsValidPoints (myFirstPoint, mySecondPoint); } - else if (theFirstShape.ShapeType() == TopAbs_EDGE) + else if (theSecondShape.ShapeType() == TopAbs_EDGE) { myGeometryType = GeometryType_EdgeFace; - isSuccess = InitEdgeFaceLength (TopoDS::Edge (theFirstShape), - TopoDS::Face (theSecondShape), + isSuccess = InitEdgeFaceLength (TopoDS::Edge (theSecondShape), + TopoDS::Face (theFirstShape), aDirAttach); if (isSuccess) @@ -627,6 +632,21 @@ Standard_Boolean AIS_LengthDimension::InitTwoShapesPoints (const TopoDS_Shape& t theIsPlaneComputed = Standard_True; } + return isSuccess; + } + else if (theSecondShape.ShapeType() == TopAbs_FACE) + { + myGeometryType = GeometryType_EdgeFace; + isSuccess = InitEdgeFaceLength (TopoDS::Edge (theFirstShape), + TopoDS::Face (theSecondShape), + aDirAttach); + + if (isSuccess) + { + theComputedPlane = ComputePlane (aDirAttach); + theIsPlaneComputed = Standard_True; + } + return isSuccess; } } diff --git a/src/AIS/AIS_LengthDimension.hxx b/src/AIS/AIS_LengthDimension.hxx index 206904ad89..01ae8fa37c 100755 --- a/src/AIS/AIS_LengthDimension.hxx +++ b/src/AIS/AIS_LengthDimension.hxx @@ -65,7 +65,7 @@ DEFINE_STANDARD_HANDLE (AIS_LengthDimension, AIS_Dimension) //! In case of face-edge, edge-vertex or face-face lengthes the automatic plane //! computing is allowed. For this plane the third point is found on the //! edge or on the face. -//! +//! //! Please note that if the inappropriate geometry is defined //! or the distance between measured points is less than //! Precision::Confusion(), the dimension is invalid and its @@ -81,8 +81,6 @@ public: Standard_EXPORT AIS_LengthDimension (const TopoDS_Face& theFace, const TopoDS_Edge& theEdge); -public: - //! Construct length dimension between two faces. //! @param theFirstFace [in] the first face (first shape). //! @param theSecondFace [in] the second face (second shape). diff --git a/src/ViewerTest/ViewerTest_RelationCommands.cxx b/src/ViewerTest/ViewerTest_RelationCommands.cxx index f49c62c16a..140ef984ab 100644 --- a/src/ViewerTest/ViewerTest_RelationCommands.cxx +++ b/src/ViewerTest/ViewerTest_RelationCommands.cxx @@ -18,20 +18,36 @@ #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 #include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -60,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -537,11 +554,6 @@ static int VDimBuilder (Draw_Interpretor& /*theDi*/, { case AIS_KOD_LENGTH: { - if (!isPlaneCustom) - { - std::cerr << theArgs[0] << ": can not build dimension without working plane.\n"; - return 1; - } if (aShapes.Extent() == 1) { if (aShapes.First()->Type() == AIS_KOI_Shape @@ -550,6 +562,12 @@ static int VDimBuilder (Draw_Interpretor& /*theDi*/, std::cerr << theArgs[0] << ": wrong shape type.\n"; return 1; } + if (!isPlaneCustom) + { + std::cerr << theArgs[0] << ": can not build dimension without working plane.\n"; + return 1; + } + // Adjust working plane TopoDS_Edge anEdge = TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape()); TopoDS_Vertex aFirst, aSecond; @@ -566,8 +584,7 @@ static int VDimBuilder (Draw_Interpretor& /*theDi*/, // Getting shapes if (aShapes.First()->DynamicType() == STANDARD_TYPE (AIS_Point)) { - Handle(AIS_Point) aPoint1 = Handle(AIS_Point)::DownCast (aShapes.First ()); - aShape1 = aPoint1->Vertex(); + aShape1 = Handle(AIS_Point)::DownCast (aShapes.First ())->Vertex(); } else if (aShapes.First()->Type() == AIS_KOI_Shape) { @@ -576,8 +593,7 @@ static int VDimBuilder (Draw_Interpretor& /*theDi*/, if (aShapes.Last()->DynamicType() == STANDARD_TYPE (AIS_Point)) { - Handle(AIS_Point) aPoint2 = Handle(AIS_Point)::DownCast (aShapes.Last ()); - aShape2 = aPoint2->Vertex(); + aShape2 = Handle(AIS_Point)::DownCast (aShapes.Last ())->Vertex(); } else if (aShapes.Last()->Type() == AIS_KOI_Shape) { @@ -590,17 +606,38 @@ static int VDimBuilder (Draw_Interpretor& /*theDi*/, return 1; } - // Adjust working plane - if (aShape1.ShapeType() == TopAbs_VERTEX) + // Face-Face case + if (aShape1.ShapeType() == TopAbs_FACE && aShape2.ShapeType() == TopAbs_FACE) + { + aDim = new AIS_LengthDimension (TopoDS::Face (aShape1), TopoDS::Face (aShape2)); + } + else if (aShape1.ShapeType() == TopAbs_FACE && aShape2.ShapeType() == TopAbs_EDGE) { - aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape1))); + aDim = new AIS_LengthDimension (TopoDS::Face (aShape1), TopoDS::Edge (aShape2)); } - else if (aShape2.ShapeType() == TopAbs_VERTEX) + else if (aShape1.ShapeType() == TopAbs_EDGE && aShape2.ShapeType() == TopAbs_FACE) { - aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape2))); + aDim = new AIS_LengthDimension (TopoDS::Face (aShape2), TopoDS::Edge (aShape1)); } + else + { + if (!isPlaneCustom) + { + std::cerr << theArgs[0] << ": can not build dimension without working plane.\n"; + return 1; + } + // Vertex-Vertex case + if (aShape1.ShapeType() == TopAbs_VERTEX) + { + aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape1))); + } + else if (aShape2.ShapeType() == TopAbs_VERTEX) + { + aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape2))); + } - aDim = new AIS_LengthDimension (aShape1, aShape2, aWorkingPlane); + aDim = new AIS_LengthDimension (aShape1, aShape2, aWorkingPlane); + } } else { @@ -896,14 +933,6 @@ static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, cons //purpose : Display the concentric relation between two surfaces. //Draw arg : vconcentric Name //============================================================================== -#include -#include -#include -#include -#include -#include - - static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -990,11 +1019,6 @@ static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const //purpose : //Draw arg : vdiameterdim Name DiameterValue //============================================================================== -#include -#include -#include - - static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1152,11 +1176,6 @@ static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const //purpose : //Draw arg : vdiameterdim Name DiameterValue //============================================================================== -#include -#include -#include - - static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1230,10 +1249,6 @@ static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, con //purpose : //Draw arg : vdiameterdim Name DiameterValue //============================================================================== -#include -#include -#include - static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1295,11 +1310,6 @@ static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char* //purpose : //Draw arg : vdiameterdim Name DiameterValue //============================================================================== -#include -#include -#include - - static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1436,18 +1446,6 @@ static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const c //purpose : Display the diameter dimension of a face or an edge. //Draw arg : vdiameterdim Name DiameterValue //============================================================================== -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1738,12 +1736,6 @@ static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const c //purpose : Display the radius dimension of a face or an edge. //Draw arg : vradiusdim Name //============================================================================== -#include -#include -#include -#include - - static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1831,11 +1823,6 @@ static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const //purpose : Display the offset dimension //Draw arg : voffsetdim Name //============================================================================== -#include -#include -#include - - static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -1924,15 +1911,6 @@ static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const //purpose : Display the parallel relation //Draw arg : vparallel Name //============================================================================== -#include -#include -#include -#include -#include -#include -#include - - static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -2081,14 +2059,6 @@ static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const c //purpose : Display the Perpendicular Relation //Draw arg : vperpendicular Name //============================================================================== -#include -#include -#include -#include -#include - - - static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -2231,9 +2201,6 @@ static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, co //purpose : Display the tangent Relation //Draw arg : vtangent Name //============================================================================== -#include - - static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations @@ -2372,11 +2339,6 @@ static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const ch //purpose : Display the Symetrical Relation //Draw arg : vsymetric Name //============================================================================== -#include -#include -#include - - static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // Declarations diff --git a/tests/bugs/vis/bug26056 b/tests/bugs/vis/bug26056 new file mode 100644 index 0000000000..56242d86b2 --- /dev/null +++ b/tests/bugs/vis/bug26056 @@ -0,0 +1,25 @@ +puts "============" +puts "CR26056" +puts "AIS_LengthDimension can not build dimension for face-edge or edge-face" +puts "============" +puts "" +puts "Tests case of edge-face and face-edge input geometry for dimension" +pload MODELING VISUALIZATION +line aLine 0 -100 0 1 0 0 +mkedge anEdge aLine -100 100 + +plane aPlane 0 0 50 0 0 1 +mkface aFace aPlane -100 100 -100 100 + +line aLine2 0 0 100 1 1 0 +mkedge anEdge2 aLine2 -150 150 + +vinit View1 +vclear +vaxo +vdisplay anEdge anEdge2 aFace +vdimension aDim1 -length -shapes anEdge aFace -text 15 3d sh +vdimension aDim2 -length -shapes aFace anEdge2 -text 15 3d sh +vfit + +set only_screen 1 -- 2.39.5