From 6b8c715fb1dd0c821ba1b898b0533ace4f85698a Mon Sep 17 00:00:00 2001 From: mzn Date: Tue, 4 Sep 2018 17:52:09 +0300 Subject: [PATCH] Issue #1467: pipe problem. --- src/FeaturesPlugin/CMakeLists.txt | 1 + src/FeaturesPlugin/Test/Test1467.py | 111 +++++++++++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp | 38 ++++++++- 3 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 src/FeaturesPlugin/Test/Test1467.py diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index ccc359c3c..bf278d767 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -332,4 +332,5 @@ ADD_UNIT_TESTS(TestExtrusion.py Test2596.py Test2592.py Test2588.py + Test1467.py ) diff --git a/src/FeaturesPlugin/Test/Test1467.py b/src/FeaturesPlugin/Test/Test1467.py new file mode 100644 index 000000000..929c9f10a --- /dev/null +++ b/src/FeaturesPlugin/Test/Test1467.py @@ -0,0 +1,111 @@ +## Copyright (C) 2014-2017 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 + +# Create document +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +# Create base and path for pipe +Point_2 = model.addPoint(Part_1_doc, 5, 20, 0) +Point_3 = model.addPoint(Part_1_doc, 0, 40, 30) +Point_4 = model.addPoint(Part_1_doc, 10, 50, 70) +Vertex_1 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Point_1")]) +Vertex_2 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "PartSet/Origin")]) +Vertex_3 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Point_2")]) +Vertex_4 = model.addVertex(Part_1_doc, [model.selection("VERTEX", "Point_3")]) +Sketch_1 = model.addSketch(Part_1_doc, model.standardPlane("YOZ")) +SketchLine_1 = Sketch_1.addLine(14.65001594578831, -16.75950688440132, 21.53989436538019, 4.084511469683225) +SketchLine_1.setName("SketchLine_2") +SketchLine_1.result().setName("SketchLine_1") +SketchLine_1.result().setColor(225, 0, 0) +SketchLine_2 = Sketch_1.addLine(21.53989436538019, 4.084511469683225, 17.92440575878417, 20.67042582762886) +SketchLine_2.setName("SketchLine_3") +SketchLine_2.result().setName("SketchLine_3") +SketchLine_2.result().setColor(225, 0, 0) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2") +SketchLine_3 = Sketch_1.addLine(17.92440575878417, 20.67042582762886, 6.041293582700577, 31.26820121140768) +SketchLine_3.setName("SketchLine_4") +SketchLine_3.result().setName("SketchLine_4") +SketchLine_3.result().setColor(225, 0, 0) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_3") +SketchArc_1 = Sketch_1.addArc(15.73021805614924, 42.13223372900752, 6.041293582700577, 31.26820121140768, 1.302016307518145, 40.2010542198842, True) +SketchArc_1.result().setColor(225, 0, 0) +SketchArc_1.results()[1].setColor(225, 0, 0) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_3.endPoint()) +SketchConstraintCoincidence_3.setName("SketchConstraintCoincidence_4") +SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_3.result()) +SketchArc_2 = Sketch_1.addArc(5.884297127208473, -13.86204556507233, 14.65001594578831, -16.75950688440132, -3.31891814825968, -14.59275556007859, True) +SketchArc_2.result().setColor(225, 0, 0) +SketchArc_2.results()[1].setColor(225, 0, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_2.startPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_9") +SketchConstraintTangent_2 = Sketch_1.setTangent(SketchArc_2.results()[1], SketchLine_1.result()) +SketchConstraintRigid_1 = Sketch_1.setFixed(SketchArc_1.startPoint()) +SketchConstraintRigid_2 = Sketch_1.setFixed(SketchLine_2.endPoint()) +model.do() +Wire_1_objects = [model.selection("EDGE", "Sketch_1/Edge-SketchArc_2_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_3"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_4"), model.selection("EDGE", "Sketch_1/Edge-SketchArc_1_2")] +Wire_1 = model.addWire(Part_1_doc, Wire_1_objects) +Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY")) +SketchLine_4 = Sketch_2.addLine(9.525599451781, 2.539525405208, -21.231656152164, 2.539525405208) +SketchLine_4.setName("SketchLine_5") +SketchLine_4.result().setName("SketchLine_5") +SketchLine_5 = Sketch_2.addLine(-21.231656152164, 2.539525405208, -21.231656152164, -7.57049842757) +SketchLine_5.setName("SketchLine_6") +SketchLine_5.result().setName("SketchLine_6") +SketchLine_6 = Sketch_2.addLine(-21.231656152164, -7.57049842757, 9.525599451781, -7.57049842757) +SketchLine_6.setName("SketchLine_7") +SketchLine_6.result().setName("SketchLine_7") +SketchLine_7 = Sketch_2.addLine(9.525599451781, -7.57049842757, 9.525599451781, 2.539525405208) +SketchLine_7.setName("SketchLine_8") +SketchLine_7.result().setName("SketchLine_8") +SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_5") +SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_6") +SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_7") +SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_8") +SketchConstraintHorizontal_1 = Sketch_2.setHorizontal(SketchLine_4.result()) +SketchConstraintVertical_1 = Sketch_2.setVertical(SketchLine_5.result()) +SketchConstraintHorizontal_2 = Sketch_2.setHorizontal(SketchLine_6.result()) +SketchConstraintVertical_2 = Sketch_2.setVertical(SketchLine_7.result()) +model.do() + +# Create pipe on the entire path (big pipe) +Pipe_1 = model.addPipe(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection("WIRE", "Wire_1_1")) + +# Create pipe on the fisrt segment of the path (small pipe) +Pipe_2 = model.addPipe(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection("EDGE", "Sketch_1/Edge-SketchArc_2_2")) + +# Cut big pipe from the small pipe +Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Pipe_2_1")], [model.selection("SOLID", "Pipe_1_1")]) +model.do() + +# Check that the small pipe is a part of the big one +assert(len(Cut_1.results()) == 0) + +model.end() diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp index 236f8e944..84a09ea10 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Pipe.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -37,12 +38,15 @@ #include #include #include +#include static bool getBase(TopoDS_Shape& theBaseOut, TopAbs_ShapeEnum& theBaseTypeOut, const GeomShapePtr theBaseShape); static bool getPath(TopoDS_Wire& thePathOut, const GeomShapePtr thePathShape); +static gp_Trsf getPathToBaseTranslation(const TopoDS_Shape& theBase, + const TopoDS_Shape& thePath); static bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder); static ListOfShape getListFromShape(const TopoDS_Shape& theShape); @@ -93,6 +97,7 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, if(!getPath(aPathWire, thePathShape)) { return; } + aPathWire.Move(getPathToBaseTranslation(aBaseShape, aPathWire)); // Making pipe. BRepOffsetAPI_MakePipe* aPipeBuilder = new BRepOffsetAPI_MakePipe(aPathWire, aBaseShape); @@ -139,6 +144,8 @@ void GeomAlgoAPI_Pipe::build(const GeomShapePtr theBaseShape, return; } + aPathWire.Move(getPathToBaseTranslation(aBaseShape, aPathWire)); + // Getting Bi-Normal. if(!theBiNormal.get()) { return; @@ -208,11 +215,20 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, } // Getting path. + TopoDS_Shape aBaseShape; + TopAbs_ShapeEnum aBaseShapeType; + if (!getBase(aBaseShape, aBaseShapeType, theBaseShapes.front())) { + return; + } + TopoDS_Wire aPathWire; if(!getPath(aPathWire, thePathShape)) { return; } + gp_Trsf aTrsf = getPathToBaseTranslation(aBaseShape, aPathWire); + aPathWire.Move(aTrsf); + // Making pipe. Standard_Boolean isDone = Standard_False; bool anIsSolidNeeded = false; @@ -226,8 +242,6 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, ListOfShape::const_iterator aLocIt = theLocations.cbegin(); while(aBaseIt != theBaseShapes.cend()) { GeomShapePtr aBase = *aBaseIt; - TopoDS_Shape aBaseShape; - TopAbs_ShapeEnum aBaseShapeType; if(!getBase(aBaseShape, aBaseShapeType, aBase)) { delete aPipeBuilder; return; @@ -244,6 +258,7 @@ void GeomAlgoAPI_Pipe::build(const ListOfShape& theBaseShapes, return; } TopoDS_Vertex aLocationVertex = aLocation->impl(); + aLocationVertex.Move(aTrsf); ++aLocIt; aPipeBuilder->Add(aBaseShape, aLocationVertex); } else { @@ -341,8 +356,7 @@ bool getBase(TopoDS_Shape& theBaseOut, } //================================================================================================== -bool getPath(TopoDS_Wire& thePathOut, - const GeomShapePtr thePathShape) +bool getPath(TopoDS_Wire& thePathOut, const GeomShapePtr thePathShape) { if(!thePathShape.get()) { return false; @@ -365,6 +379,22 @@ bool getPath(TopoDS_Wire& thePathOut, return true; } +//================================================================================================== +gp_Trsf getPathToBaseTranslation(const TopoDS_Shape& theBase, const TopoDS_Shape& thePath) +{ + gp_Trsf aTranslation; + + BRepExtrema_DistShapeShape aDist(theBase, thePath); + aDist.Perform(); + if (aDist.IsDone() && aDist.Value() > Precision::Confusion()) { + gp_Pnt aPntBase = aDist.PointOnShape1(1); + gp_Pnt aPntPath = aDist.PointOnShape2(1); + aTranslation.SetTranslation(aPntPath, aPntBase); + } + + return aTranslation; +} + //================================================================================================== bool buildPipe(BRepOffsetAPI_MakePipeShell* thePipeBuilder) { -- 2.39.2