1 ## Copyright (C) 2014-2017 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>
21 # Initialization of the test
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from GeomAlgoAPI import *
29 def createPoint(theSketchFeature):
30 aSketchPointFeature = theSketchFeature.addFeature("SketchPoint")
31 aPointCoordinates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordinates"))
32 aPointCoordinates.setValue(random.uniform(0, 50), random.uniform(0, 50))
33 return aSketchPointFeature
35 def createLine(theSketchFeature):
36 aSketchLineFeature = theSketchFeature.addFeature("SketchLine")
37 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
38 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
39 aSketchLineStartPoint.setValue(random.uniform(0, 50), random.uniform(0, 50))
40 aSketchLineEndPoint.setValue(random.uniform(0, 50), random.uniform(0, 50))
41 return aSketchLineFeature
44 aSession = ModelAPI_Session.get()
45 aDocument = aSession.moduleDocument()
48 aSession.startOperation()
49 aPartFeature = aDocument.addFeature("Part")
50 aSession.finishOperation()
51 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
52 aPart = aPartResult.partDoc()
55 aSession.startOperation()
56 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
57 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
58 anOrigin.setValue(0, 0, 0)
59 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
60 aDirX.setValue(1, 0, 0)
61 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
62 aNorm.setValue(0, 0, 1)
65 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
66 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
67 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
68 aSketchLineStartPoint.setValue(0, 0)
69 aSketchLineEndPoint.setValue(0, 50)
70 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
71 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
72 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
73 aSketchLineStartPoint.setValue(0, 50)
74 aSketchLineEndPoint.setValue(50, 50)
75 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
76 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
77 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
78 aSketchLineStartPoint.setValue(50, 50)
79 aSketchLineEndPoint.setValue(50, 0)
80 aSketchLineFeature = aSketchFeature.addFeature("SketchLine")
81 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
82 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
83 aSketchLineStartPoint.setValue(50, 0)
84 aSketchLineEndPoint.setValue(0, 0)
86 aSession.finishOperation()
87 aSketchResult = aSketchFeature.firstResult()
88 aSketchShape = aSketchResult.shape()
91 aSession.startOperation()
92 aFaceFeature = aPart.addFeature("Face")
93 aBaseObjectsList = aFaceFeature.selectionList("base_objects")
94 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
95 while aShapeExplorer.more():
96 aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
98 aSession.finishOperation()
99 aFaceResult = aFaceFeature.firstResult()
101 # Create a sketch with points and lines
102 aSession.startOperation()
103 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
104 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
105 anOrigin.setValue(0, 0, 0)
106 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
107 aDirX.setValue(1, 0, 0)
108 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
109 aNorm.setValue(0, 0, 1)
114 for i in range(aNumOfPoints):
115 aSession.startOperation()
116 aSketchPointFeature = createPoint(aSketchFeature)
117 aSession.finishOperation()
118 aPoints.append(aSketchPointFeature.firstResult().shape())
123 for i in range(aNumOfLines):
124 aSession.startOperation()
125 aSketchLineFeature = createLine(aSketchFeature)
126 aSession.finishOperation()
127 aLines.append(aSketchLineFeature.firstResult().shape())
129 aSession.finishOperation()
130 aSketchResult = aSketchFeature.firstResult()
131 aSketchShape = aSketchResult.shape()
134 aSession.startOperation()
135 aSubShapesFeature = aPart.addFeature("SubShapes")
136 aBaseShapeSelection = aSubShapesFeature.selection("base_shape")
137 aBaseShapeSelection.setValue(aFaceResult, None)
138 aSubShapesList = aSubShapesFeature.selectionList("subshapes")
139 for aPoint in aPoints:
140 aSubShapesList.append(aSketchResult, aPoint)
141 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
142 while aShapeExplorer.more():
143 aSubShapesList.append(aSketchResult, aShapeExplorer.current())
144 aShapeExplorer.next()
145 aSession.finishOperation()
148 assert (len(aSubShapesFeature.results()) > 0)
150 from salome.shaper import model
153 partSet = model.moduleDocument()
154 Part_1 = model.addPart(partSet)
155 Part_1_doc = Part_1.document()
156 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
157 SketchCircle_1 = Sketch_1.addCircle(-454.545454545455, 50.600343053173, 137.95899463189)
158 SketchCircle_2 = Sketch_1.addCircle(-454.545454545455, 50.600343053173, 62.129572131303)
159 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchCircle_2.center())
160 SketchPoint_1 = Sketch_1.addPoint(-490.566037735849, 50.600343053173)
161 SketchPoint_2 = Sketch_1.addPoint(-423.670668953688, 50.600343053173)
163 Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchCircle_1_2f")])
164 Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchCircle_2_2r")])
165 SubShapes_1 = model.addSubShapes(Part_1_doc, model.selection("FACE", "Face_1_1"), [model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_2")])
166 SubShapes_1.setBaseShape(model.selection("FACE", "Face_2_1"))
169 assert(model.checkPythonDump())