geom/test/test_wire_modes.py

139 lines
6.4 KiB
Python
Raw Normal View History

# -*- coding: iso-8859-1 -*-
# Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
#
# 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
#
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
import math
geompy = geomBuilder.New()
O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
Vertex_1 = geompy.MakeVertex(30, 70, 0)
Vertex_2 = geompy.MakeVertex(100, 0, 0)
Vertex_3 = geompy.MakeVertex(100, 70, 0)
Vertex_4 = geompy.MakeVertex(0, 70, 0)
Vertex_5 = geompy.MakeVertex(60, 60, 0)
Vertex_6 = geompy.MakeVertex(10, 50, 0)
Vertex_7 = geompy.MakeVertex(20, 0, 0)
Vertex_8 = geompy.MakeVertex(15, 80, 0)
Vertex_9 = geompy.MakeVertex(35, 60, 0)
Vertex_10 = geompy.MakeVertex(-20, 80, 0)
Vertex_11 = geompy.MakeVertex(10, -10, 0)
Vertex_12 = geompy.MakeVertex(10, 20, 0)
Vertex_13 = geompy.MakeVertex(-10, 30, 0)
Vertex_14 = geompy.MakeVertex(-20, 0, 0)
Vertex_15 = geompy.MakeVertex(-10, -10, 0)
# Linear segments
Curve_1 = geompy.MakePolyline([O, Vertex_2, Vertex_3, Vertex_4], True)
# Circles
Circle_1 = geompy.MakeCircle(Vertex_3, None, 10)
Circle_2 = geompy.MakeCircle(Vertex_5, None, 15)
# Ellipses
geomObj_1 = geompy.MakeEllipse(O, None, 30, 10)
geomObj_2 = geompy.MakeRotation(geomObj_1, OZ, 45*math.pi/180.0)
Translation_1 = geompy.MakeTranslation(geomObj_2, 100, 0, 0)
geomObj_3 = geompy.MakeEllipse(None, None, 20, 10)
geomObj_4 = geompy.MakeRotation(geomObj_3, OZ, 90*math.pi/180.0)
Translation_2 = geompy.MakeTranslation(geomObj_4, 50, 10, 0)
# B-Spline curve
Curve_2 = geompy.MakeInterpol([Vertex_1, Vertex_6, Vertex_10, Vertex_8], True, False)
# Bezier curve
Curve_4 = geompy.MakeBezier([Vertex_7, Vertex_12, Vertex_13, Vertex_14, Vertex_15, Vertex_11], True)
# Partition
Partition_1 = geompy.MakePartition([Circle_1, Circle_2, Curve_1, Curve_2, Translation_1, Translation_2, Curve_4], [], [], [], geompy.ShapeType["EDGE"], 0, [], 0)
[Edge_1,Edge_2,Edge_3,Edge_4,Edge_5,Edge_6,Edge_7,Edge_8,Edge_9,Edge_10,Edge_11,Edge_12,Edge_13,Edge_14,Edge_15,Edge_16,Edge_17,Edge_18,Edge_19,Edge_20,Edge_21,Edge_22,Edge_23,Edge_24,Edge_25,Edge_26,Edge_27,Edge_28,Edge_29,Edge_30,Edge_31,Edge_32] = geompy.ExtractShapes(Partition_1, geompy.ShapeType["FLAT"], True)
# FuseCollinearEdges
Wire_1 = geompy.MakeWire([Edge_16, Edge_20], 1e-07)
Wire_2 = geompy.MakeWire([Edge_30, Edge_32], 1e-07)
Wire_3 = geompy.MakeWire([Edge_24, Edge_31], 1e-07)
Wire_4 = geompy.MakeWire([Edge_11, Edge_15], 1e-07)
FuseEdges_1 = geompy.FuseCollinearEdgesWithinWire(Wire_1, [])
[Edge_33] = geompy.ExtractShapes(FuseEdges_1, geompy.ShapeType["EDGE"], True)
FuseEdges_2 = geompy.FuseCollinearEdgesWithinWire(Wire_2, [])
[Edge_34] = geompy.ExtractShapes(FuseEdges_2, geompy.ShapeType["EDGE"], True)
FuseEdges_3 = geompy.FuseCollinearEdgesWithinWire(Wire_3, [])
[Edge_35] = geompy.ExtractShapes(FuseEdges_3, geompy.ShapeType["EDGE"], True)
FuseEdges_4 = geompy.FuseCollinearEdgesWithinWire(Wire_4, [])
[Edge_36] = geompy.ExtractShapes(FuseEdges_4, geompy.ShapeType["EDGE"], True)
# Make gaps
Translation_3 = geompy.MakeTranslation(Edge_2, -1, -1, 0)
Translation_4 = geompy.MakeTranslation(Edge_5, -1, 1, 0)
Translation_5 = geompy.MakeTranslation(Edge_18, 0, 1, 0)
Translation_6 = geompy.MakeTranslation(Edge_34, 1, 1, 0)
Translation_7 = geompy.MakeTranslation(Edge_35, 1, -1, 0)
Translation_8 = geompy.MakeTranslation(Edge_13, 0, -1, 0)
Translation_9 = geompy.MakeTranslation(Edge_7, 1, 1, 0)
Translation_10 = geompy.MakeTranslation(Edge_9, 1, -1, 0)
Translation_11 = geompy.MakeTranslation(Edge_33, 0, -1, 0)
Translation_12 = geompy.MakeTranslation(Edge_25, -1, -1, 0)
Translation_13 = geompy.MakeTranslation(Edge_23, -1, 1, 0)
Translation_14 = geompy.MakeTranslation(Edge_36, 0, 1, 0)
# Make wires
# a. Old implementation (FixTolerance)
Wire_5 = geompy.MakeWire([Translation_3, Translation_4, Translation_5, Translation_6, Translation_7, Translation_8, Edge_3, Edge_10, Edge_12, Edge_19, Edge_21, Edge_28], 3, 'Wire_5')
Wire_6 = geompy.MakeWire([Translation_9, Translation_10, Translation_11, Translation_12, Translation_13, Translation_14, Edge_3, Edge_10, Edge_12, Edge_19, Edge_21, Edge_28], 3, 'Wire_6')
# b. New implementation (ConstCurveType)
Wire_7 = geompy.MakeWireConstCurveType([Translation_3, Translation_4, Translation_5, Translation_6, Translation_7, Translation_8, Edge_3, Edge_10, Edge_12, Edge_19, Edge_21, Edge_28], 3, 'Wire_7')
Wire_8 = geompy.MakeWireConstCurveType([Translation_9, Translation_10, Translation_11, Translation_12, Translation_13, Translation_14, Edge_3, Edge_10, Edge_12, Edge_19, Edge_21, Edge_28], 3, 'Wire_8')
# c. Approximation mode (in case of need canonical curves are approximated with b-splines)
Wire_9 = geompy.MakeWireWithMode([Translation_3, Translation_4, Translation_5, Translation_6, Translation_7, Translation_8, Edge_3, Edge_10, Edge_12, Edge_19, Edge_21, Edge_28], 3, GEOM.WBM_Approximation, 'Wire_9')
Wire_10 = geompy.MakeWireWithMode([Translation_9, Translation_10, Translation_11, Translation_12, Translation_13, Translation_14, Edge_3, Edge_10, Edge_12, Edge_19, Edge_21, Edge_28], 3, GEOM.WBM_Approximation, 'Wire_10')
### check wire length
Length5 = geompy.BasicProperties( Wire_5 )[0]
Length6 = geompy.BasicProperties( Wire_6 )[0]
Length7 = geompy.BasicProperties( Wire_7 )[0]
Length8 = geompy.BasicProperties( Wire_8 )[0]
Length9 = geompy.BasicProperties( Wire_9 )[0]
Length10 = geompy.BasicProperties( Wire_10 )[0]
assert(abs(Length5 - 530.130817) < 1e-05)
assert(abs(Length6 - 415.467625) < 1e-05)
assert(abs(Length7 - 534.130817) < 1e-05)
assert(abs(Length8 - 411.467625) < 1e-05)
# Here we have a problem with Approximation mode: "arcs" of bezier curve are wrongly treated
#assert(math.abs(Length9 - ) < 1e-05)
#assert(math.abs(Length10 - ) < 1e-05)