From 41171d48cbcae06727fc7f93c043600cf4caebb8 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 12 Jan 2018 14:28:09 +0300 Subject: [PATCH] Issue #2398: Filling : incorrect result Workaround for OCCT problem which appears when concatenating a wire consists of two edges placed at the ending and the beginning of the same closed curve. --- src/BuildPlugin/CMakeLists.txt | 4 +- src/BuildPlugin/Test/Test2398.py | 110 +++++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 48 ++++++++- 3 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 src/BuildPlugin/Test/Test2398.py diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index 61497aa7c..afa4e6c00 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -110,4 +110,6 @@ ADD_UNIT_TESTS(TestVertex.py TestFilling_ByEdges.py TestFilling_ByWires.py TestFilling_Mixed.py - Test1920.py) + Test1920.py + Test2398.py +) diff --git a/src/BuildPlugin/Test/Test2398.py b/src/BuildPlugin/Test/Test2398.py new file mode 100644 index 000000000..14f101769 --- /dev/null +++ b/src/BuildPlugin/Test/Test2398.py @@ -0,0 +1,110 @@ +## Copyright (C) 2018-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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(0, 0, 30.79356776198042) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center()) +model.do() + +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchCircle_1_2f")], model.selection(), 100, 100) + +Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY")) +SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_2 = SketchProjection_2.createdFeature() +SketchCircle_2 = Sketch_2.addCircle(0, 0, 25.19116787687743) +SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchPoint_2.result(), SketchCircle_2.center()) +model.do() + +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 100, 0) +Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OX"), 90) + +Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Rotation_1_1")], [model.selection("SOLID", "Extrusion_2_1")]) + +Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_3.addLine(7.903534676574237, 7.903534676574236, -7.903534676574236, 7.903534676574236) +SketchLine_2 = Sketch_3.addLine(-7.903534676574236, 7.903534676574236, -7.903534676574236, -7.903534676574237) +SketchLine_3 = Sketch_3.addLine(-7.903534676574236, -7.903534676574237, 7.903534676574237, -7.903534676574237) +SketchLine_4 = Sketch_3.addLine(7.903534676574237, -7.903534676574237, 7.903534676574237, 7.903534676574236) +SketchConstraintCoincidence_3 = Sketch_3.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_4 = Sketch_3.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_5 = Sketch_3.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_6 = Sketch_3.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_3.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_3.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_3.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_3.setVertical(SketchLine_4.result()) +SketchConstraintEqual_1 = Sketch_3.setEqual(SketchLine_4.result(), SketchLine_1.result()) +SketchLine_5 = Sketch_3.addLine(-7.903534676574236, 7.903534676574236, 7.903534676574237, -7.903534676574237) +SketchLine_5.setAuxiliary(True) +SketchConstraintCoincidence_7 = Sketch_3.setCoincident(SketchLine_1.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_8 = Sketch_3.setCoincident(SketchLine_3.endPoint(), SketchLine_5.endPoint()) +SketchProjection_3 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_3 = SketchProjection_3.createdFeature() +SketchConstraintCoincidence_9 = Sketch_3.setCoincident(SketchLine_5.result(), SketchAPI_Point(SketchPoint_3).coordinates()) +SketchConstraintMiddle_1 = Sketch_3.setMiddlePoint(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_5.result()) +model.do() + +Edge_1_objects = [model.selection("EDGE", "Sketch_3/Edge-SketchLine_2"), model.selection("EDGE", "Sketch_3/Edge-SketchLine_1"), model.selection("EDGE", "Sketch_3/Edge-SketchLine_4"), model.selection("EDGE", "Sketch_3/Edge-SketchLine_3")] +Edge_1 = model.addEdge(Part_1_doc, Edge_1_objects) + +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOZ"), model.selection("EDGE", "PartSet/OZ"), 135) +Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Plane_1"), model.selection("EDGE", "PartSet/OZ"), 90) + +Partition_1_objects = [model.selection("EDGE", "Intersection_1_1"), model.selection("FACE", "Plane_2"), model.selection("FACE", "Plane_1")] +Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects) + +Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Partition_1_1_4"), model.selection("EDGE", "Edge_1_2")]) +Filling_2 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Partition_1_1_5"), model.selection("EDGE", "Edge_1_1")]) +Filling_3 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Partition_1_1_3"), model.selection("EDGE", "Edge_1_4")]) + +Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Partition_1_1_1"), model.selection("EDGE", "Partition_1_1_2")]) +Filling_4 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Edge_1_3"), model.selection("WIRE", "Wire_1_1")]) +model.do() + +from GeomAPI import * + +# check fillings +REF_DATA = [(Filling_1, 718.953160474090168463590089232), + (Filling_2, 910.697240711571453175565693527), + (Filling_3, 718.950138772744594461983069777), + (Filling_4, 910.697500240109889091399963945)] +for ref in REF_DATA: + model.testNbResults(ref[0], 1) + model.testNbSubResults(ref[0], [0]) + model.testNbSubShapes(ref[0], GeomAPI_Shape.SOLID, [0]) + model.testNbSubShapes(ref[0], GeomAPI_Shape.FACE, [1]) + model.testNbSubShapes(ref[0], GeomAPI_Shape.EDGE, [4]) + model.testNbSubShapes(ref[0], GeomAPI_Shape.VERTEX, [8]) + model.testResultsVolumes(ref[0], [ref[1]]) + +model.end() + +assert(model.checkPythonDump()) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index c5bf76802..5dc12d2ed 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ #include #include #include +#include #include #include @@ -91,7 +93,10 @@ double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr theSh return 0.0; } const Standard_Real anEps = 1.e-6; - BRepGProp::VolumeProperties(aShape, aGProps, anEps); + if (aShape.ShapeType() <= TopAbs_SOLID) + BRepGProp::VolumeProperties(aShape, aGProps, anEps); + else + BRepGProp::SurfaceProperties(aShape, aGProps, anEps); return aGProps.Mass(); } @@ -958,12 +963,51 @@ std::shared_ptr GeomAlgoAPI_ShapeTools::buildDirFromAxisAndShape( } //================================================================================================== +static TopoDS_Wire fixParametricGaps(const TopoDS_Wire& theWire) +{ + TopoDS_Wire aFixedWire; + Handle(Geom_Curve) aPrevCurve; + double aPrevLastParam = 0.0; + + BRep_Builder aBuilder; + aBuilder.MakeWire(aFixedWire); + + BRepTools_WireExplorer aWExp(theWire); + for (; aWExp.More(); aWExp.Next()) { + TopoDS_Edge anEdge = aWExp.Current(); + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast); + if (aCurve == aPrevCurve) { + // if parametric gap occurs, create new edge based on the copied curve + aCurve = Handle(Geom_Curve)::DownCast(aCurve->Copy()); + TopoDS_Vertex aV1, aV2; + TopExp::Vertices(anEdge, aV1, aV2); + anEdge = TopoDS::Edge(anEdge.EmptyCopied()); + aBuilder.UpdateEdge(anEdge, aCurve, BRep_Tool::Tolerance(anEdge)); + aBuilder.Add(anEdge, aV1); + aBuilder.Add(anEdge, aV2); + } + + aBuilder.Add(aFixedWire, anEdge); + + aPrevCurve = aCurve; + aPrevLastParam = aLast; + } + + return aFixedWire; +} + std::shared_ptr GeomAlgoAPI_ShapeTools::wireToEdge( const std::shared_ptr& theWire) { GeomEdgePtr anEdge; if (theWire) { - const TopoDS_Wire& aWire = theWire->impl(); + TopoDS_Wire aWire = theWire->impl(); + // Workaround: when concatenate a wire consisting of two edges based on the same B-spline curve + // (non-periodic, but having equal start and end points), first of which is placed at the end + // on the curve and second is placed at the start, this workaround copies second curve to avoid + // treating these edges as a single curve by setting trim parameters. + aWire = fixParametricGaps(aWire); TopoDS_Edge aNewEdge = BRepAlgo::ConcatenateWireC0(aWire); anEdge = GeomEdgePtr(new GeomAPI_Edge); anEdge->setImpl(new TopoDS_Edge(aNewEdge)); -- 2.39.2