From b22f8bc2d6f96b466583d21445d5c5c719f4c724 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 28 Feb 2019 14:06:13 +0300 Subject: [PATCH] Issue #2879: "What is" does not work Take into account trimmed curves while verifying a wire is a rectangle. --- src/GeomAPI/CMakeLists.txt | 1 + src/GeomAPI/GeomAPI_Wire.cpp | 4 +++ src/GeomAPI/Test/Test2879.py | 52 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/GeomAPI/Test/Test2879.py diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 5bdfb2135..a95efe2ce 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -171,4 +171,5 @@ ADD_UNIT_TESTS( TestSphere.py TestTorus.py Test2675.py + Test2879.py ) diff --git a/src/GeomAPI/GeomAPI_Wire.cpp b/src/GeomAPI/GeomAPI_Wire.cpp index 9cd4c0012..c1124a353 100644 --- a/src/GeomAPI/GeomAPI_Wire.cpp +++ b/src/GeomAPI/GeomAPI_Wire.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,7 @@ bool GeomAPI_Wire::isRectangle(std::list& thePoints) const const TopoDS_Wire& aWire = TopoDS::Wire(impl()); const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line); + const Handle(Standard_Type)& aTrimmedCurveType = STANDARD_TYPE(Geom_TrimmedCurve); gp_XYZ aPrevDir(0, 0, 0); @@ -91,6 +93,8 @@ bool GeomAPI_Wire::isRectangle(std::list& thePoints) const const TopoDS_Edge& anEdge = anExp.Current(); double aT1, aT2; Handle(Geom_Curve) aC3D = BRep_Tool::Curve(anEdge, aT1, aT2); + while (aC3D->IsKind(aTrimmedCurveType)) + aC3D = Handle(Geom_TrimmedCurve)::DownCast(aC3D)->BasisCurve(); if (!aC3D.IsNull() && aC3D->IsKind(aLineType)) { gp_Pnt aCorner = BRep_Tool::Pnt(anExp.CurrentVertex()); thePoints.push_back(GeomPointPtr(new GeomAPI_Pnt(aCorner.X(), aCorner.Y(), aCorner.Z()))); diff --git a/src/GeomAPI/Test/Test2879.py b/src/GeomAPI/Test/Test2879.py new file mode 100644 index 000000000..cb7c500b2 --- /dev/null +++ b/src/GeomAPI/Test/Test2879.py @@ -0,0 +1,52 @@ +# Copyright (C) 2019-20xx CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model +from GeomAPI import * +import math + +TOLERANCE = 1.e-7 + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_2_1")], model.selection("EDGE", "PartSet/OX"), 10) +Fuse_1 = model.addFuse(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Translation_1_1")], True) +model.do() +model.end() + +aShape = Fuse_1.result().resultSubShapePair()[0].shape() +assert(aShape.isSolid()) +aBox = aShape.solid().getParallelepiped() +assert(aBox is not None) +assert(aBox.isAxesAligned()) + +CORNER = GeomAPI_Pnt(0, 0, 0) +WIDTH = 20 +HEIGHT = 10 +DEPTH = 10 + +aCorner = aBox.corner() +assert(aCorner.distance(CORNER) < TOLERANCE), "({}, {}, {}) != expected ({}, {}, {})".format(aCorner.x(), aCorner.y(), aCorner.z(), CORNER.x(), CORNER.y(), CORNER.z()) +assert(math.fabs(aBox.width() - WIDTH) < TOLERANCE), "Width {} != {}".format(aBox.width(), WIDTH) +assert(math.fabs(aBox.depth() - DEPTH) < TOLERANCE), "Depth {} != {}".format(aBox.depth(), DEPTH) +assert(math.fabs(aBox.height() - HEIGHT) < TOLERANCE), "Height {} != {}".format(aBox.height(), HEIGHT) -- 2.39.2