--- /dev/null
+## 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<mailto: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())
#include <BRepExtrema_ExtCF.hxx>
#include <BRepGProp.hxx>
#include <BRepTools.hxx>
+#include <BRepTools_WireExplorer.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
#include <BRepClass_FaceClassifier.hxx>
#include <Geom2d_Curve.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
+#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
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();
}
}
//==================================================================================================
+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<GeomAPI_Edge> GeomAlgoAPI_ShapeTools::wireToEdge(
const std::shared_ptr<GeomAPI_Wire>& theWire)
{
GeomEdgePtr anEdge;
if (theWire) {
- const TopoDS_Wire& aWire = theWire->impl<TopoDS_Wire>();
+ TopoDS_Wire aWire = theWire->impl<TopoDS_Wire>();
+ // 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));