1 ## Copyright (C) 2018-20xx 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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 from SketchAPI import *
24 from salome.shaper import model
30 def assertRectangle(theWire):
31 assert(theWire is not None)
32 aCorners = [GeomAPI.GeomAPI_Pnt(0, 0, 0)]
33 assert(theWire.isRectangle(aCorners))
35 def checkRectangleFace(theDocument, theFaceName):
36 aFace = model.addFace(theDocument, [model.selection("FACE", theFaceName)])
37 aShape = aFace.result().resultSubShapePair()[0].shape()
38 assert(aShape.isFace())
39 aSubs = aShape.subShapes(GeomAPI.GeomAPI_Shape.WIRE)
40 assert(aSubs.size() == 1)
41 assertRectangle(aSubs[0].wire())
42 theDocument.removeFeature(aFace.feature())
44 def checkRectangleWire(theDocument, theEdgeNames):
46 for name in theEdgeNames:
47 aSelection.append(model.selection("EDGE", name))
48 aWire = model.addWire(theDocument, aSelection)
49 aShape = aWire.result().resultSubShapePair()[0].shape()
50 assert(aShape.isWire())
51 assert(aShape.wire().isClosed())
52 assertRectangle(aShape.wire())
53 theDocument.removeFeature(aWire.feature())
56 def assertPolygon(theWire):
57 assert(theWire is not None)
58 aCorners = [GeomAPI.GeomAPI_Pnt(0, 0, 0)]
59 assert(theWire.isPolygon(aCorners))
61 def checkPolygonWire(theDocument, theEdgeNames):
63 for name in theEdgeNames:
64 aSelection.append(model.selection("EDGE", name))
65 aWire = model.addWire(theDocument, aSelection)
66 aShape = aWire.result().resultSubShapePair()[0].shape()
67 assert(aShape.isWire())
68 assertPolygon(aShape.wire())
69 theDocument.removeFeature(aWire.feature())
71 def checkPolyline(theDocument, theVertexNames):
73 for name in theVertexNames:
74 aSelection.append(model.selection("VERTEX", name))
75 aWire = model.addPolyline3D(Part_1_doc, aSelection, False)
76 aShape = aWire.result().resultSubShapePair()[0].shape()
77 assert(aShape.isWire())
78 assertPolygon(aShape.wire())
79 theDocument.removeFeature(aWire.feature())
84 partSet = model.moduleDocument()
85 Part_1 = model.addPart(partSet)
86 Part_1_doc = Part_1.document()
87 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
90 # Test 1. Check face/wire of box is a rectangle
91 checkRectangleFace(Part_1_doc, "Box_1_1/Top")
92 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]"]
93 checkRectangleWire(Part_1_doc, Wire_edges)
95 # Test 2. Build a polygon from edges
96 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]"]
97 checkPolygonWire(Part_1_doc, Wire_edges)
99 # Test 3. Build a polygon from vertices
100 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]"]
101 checkPolyline(Part_1_doc, Poly_vertices)