1 # Copyright (C) 2021 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
20 from salome.shaper import model
23 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 l = model.addParameter(Part_1_doc, "l", "50")
29 h = model.addParameter(Part_1_doc, "h", "20")
32 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
34 ### Create SketchProjection
35 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
36 SketchPoint_1 = SketchProjection_1.createdFeature()
39 SketchLine_1 = Sketch_1.addLine(-25, -10, 25, -10)
42 SketchLine_2 = Sketch_1.addLine(-25, -10, 25, 10)
43 SketchLine_2.setAuxiliary(True)
46 SketchLine_3 = Sketch_1.addLine(25, -10, -25, 10)
47 SketchLine_3.setAuxiliary(True)
50 SketchLine_4 = Sketch_1.addLine(25, -10, 25, 10)
53 SketchLine_5 = Sketch_1.addLine(25, 10, -25, 10)
56 SketchLine_6 = Sketch_1.addLine(-25, 10, -25, -10)
58 ### Create SketchPoint
59 SketchPoint_2 = Sketch_1.addPoint(0, 0)
60 SketchPoint_2.setAuxiliary(True)
61 Sketch_1.setCoincident(SketchPoint_2.coordinates(), SketchLine_2.result())
62 Sketch_1.setCoincident(SketchPoint_2.coordinates(), SketchLine_3.result())
63 Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_1.startPoint())
64 Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchLine_1.startPoint())
65 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_4.startPoint())
66 Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_4.startPoint())
67 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
68 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_5.startPoint())
69 Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
70 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_6.startPoint())
71 Sketch_1.setCoincident(SketchPoint_1.result(), SketchPoint_2.result())
72 Sketch_1.setHorizontal(SketchLine_1.result())
73 Sketch_1.setVertical(SketchLine_4.result())
74 Sketch_1.setHorizontal(SketchLine_5.result())
75 Sketch_1.setVertical(SketchLine_6.result())
76 Sketch_1.setLength(SketchLine_5.result(), "l")
77 Sketch_1.setLength(SketchLine_6.result(), "h")
81 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_4f-SketchLine_5f-SketchLine_6f")], model.selection(), 40, 0, "Faces|Wires")
85 #=============================================================================================
87 #=============================================================================================
88 from GeomDataAPI import *
89 from ModelAPI import *
91 from SketchAPI import SketchAPI_Sketch, SketchAPI_SketchEntity
93 def isSymetricX(line):
94 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
95 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
96 return aStart.x() == -aEnd.x()
98 def isSymetricY(line):
99 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
100 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
101 return aStart.y() == -aEnd.y()
103 def isSymetricXY(line):
104 aStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
105 aEnd = geomDataAPI_Point2D(line.attribute("EndPoint"))
106 return (aStart.x() == -aEnd.x()) and (aStart.y() == -aEnd.y())
108 #=========================================================================
109 def checkLinesSymetry(aSketchFeature):
110 #=========================================================================
111 # Checks the lines of rectangle are symetric around the origin
112 aNbSubs = aSketchFeature.numberOfSubs()
115 for i in range (0, aNbSubs):
116 aFeature = objectToFeature(aSketchFeature.subFeature(i))
117 if aFeature.getKind() == "SketchLine":
119 entity = SketchAPI_SketchEntity(aLastLine)
120 if entity.auxiliary().value(): # auxiliary line
121 assert isSymetricXY(aLastLine)
124 assert (isSymetricX(aLastLine) or isSymetricY(aLastLine))
125 aNbLines = aNbLines + 1
127 assert (aNbLines == 4)
128 assert (model.dof(aSketchFeature) == 0)
130 Part_doc = model.activeDocument()
131 for feat in Part_doc.allFeatures():
132 if feat.getKind() == "Sketch":
135 aSketchFeature = featureToCompositeFeature(sketch)
136 #=========================================================================
137 # Check the lines of rectangle are symetric around the origin
138 #=========================================================================
139 checkLinesSymetry(aSketchFeature)
140 #=========================================================================
141 # Change the dimensions of the rectangle
142 #=========================================================================
143 aSession = ModelAPI_Session.get()
144 aSession.startOperation()
147 aSession.finishOperation()
148 #=========================================================================
149 # Check the lines of rectangle are symetric around the origin
150 #=========================================================================
151 checkLinesSymetry(aSketchFeature)
153 assert(model.checkPythonDump())