1 # Copyright (C) 2018-2019 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from SketchAPI import *
23 from salome.shaper import model
29 def assertRectangle(theWire):
30 assert(theWire is not None)
31 aCorners = [GeomAPI.GeomAPI_Pnt(0, 0, 0)]
32 assert(theWire.isRectangle(aCorners))
34 def checkRectangleFace(theDocument, theFaceName):
35 aFace = model.addFace(theDocument, [model.selection("FACE", theFaceName)])
36 aShape = aFace.result().resultSubShapePair()[0].shape()
37 assert(aShape.isFace())
38 aSubs = aShape.subShapes(GeomAPI.GeomAPI_Shape.WIRE)
39 assert(aSubs.size() == 1)
40 assertRectangle(aSubs[0].wire())
41 theDocument.removeFeature(aFace.feature())
43 def checkRectangleWire(theDocument, theEdgeNames):
45 for name in theEdgeNames:
46 aSelection.append(model.selection("EDGE", name))
47 aWire = model.addWire(theDocument, aSelection)
48 aShape = aWire.result().resultSubShapePair()[0].shape()
49 assert(aShape.isWire())
50 assert(aShape.wire().isClosed())
51 assertRectangle(aShape.wire())
52 theDocument.removeFeature(aWire.feature())
55 def assertPolygon(theWire):
56 assert(theWire is not None)
57 aCorners = [GeomAPI.GeomAPI_Pnt(0, 0, 0)]
58 assert(theWire.isPolygon(aCorners))
60 def checkPolygonWire(theDocument, theEdgeNames):
62 for name in theEdgeNames:
63 aSelection.append(model.selection("EDGE", name))
64 aWire = model.addWire(theDocument, aSelection)
65 aShape = aWire.result().resultSubShapePair()[0].shape()
66 assert(aShape.isWire())
67 assertPolygon(aShape.wire())
68 theDocument.removeFeature(aWire.feature())
70 def checkPolyline(theDocument, theVertexNames):
72 for name in theVertexNames:
73 aSelection.append(model.selection("VERTEX", name))
74 aWire = model.addPolyline3D(Part_1_doc, aSelection, False)
75 aShape = aWire.result().resultSubShapePair()[0].shape()
76 assert(aShape.isWire())
77 assertPolygon(aShape.wire())
78 theDocument.removeFeature(aWire.feature())
83 partSet = model.moduleDocument()
84 Part_1 = model.addPart(partSet)
85 Part_1_doc = Part_1.document()
86 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
89 # Test 1. Check face/wire of box is a rectangle
90 checkRectangleFace(Part_1_doc, "Box_1_1/Top")
91 Wire_edges = ["[Box_1_1/Left][Box_1_1/Top]", "[Box_1_1/Front][Box_1_1/Top]", "[Box_1_1/Right][Box_1_1/Top]", "[Box_1_1/Back][Box_1_1/Top]"]
92 checkRectangleWire(Part_1_doc, Wire_edges)
94 # Test 2. Build a polygon from edges
95 Wire_edges = ["[Box_1_1/Left][Box_1_1/Bottom]", "[Box_1_1/Front][Box_1_1/Left]", "[Box_1_1/Left][Box_1_1/Top]", "[Box_1_1/Back][Box_1_1/Top]", "[Box_1_1/Right][Box_1_1/Top]"]
96 checkPolygonWire(Part_1_doc, Wire_edges)
98 # Test 3. Build a polygon from vertices
99 Poly_vertices = ["[Box_1_1/Back][Box_1_1/Left][Box_1_1/Bottom]", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Bottom]", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Top]", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Top]", "[Box_1_1/Back][Box_1_1/Right][Box_1_1/Top]"]
100 checkPolyline(Part_1_doc, Poly_vertices)