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 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)