Salome HOME
sources v1.2
[modules/geom.git] / GEOM_SWIG / GEOM_usinggeom.py
1 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
2 #
3 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5
6 #  This library is free software; you can redistribute it and/or 
7 #  modify it under the terms of the GNU Lesser General Public 
8 #  License as published by the Free Software Foundation; either 
9 #  version 2.1 of the License. 
10
11 #  This library is distributed in the hope that it will be useful, 
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 #  Lesser General Public License for more details. 
15
16 #  You should have received a copy of the GNU Lesser General Public 
17 #  License along with this library; if not, write to the Free Software 
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19
20 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 #
22 #
23 #
24 #  File   : GEOM_usinggeom.py
25 #  Author : Damien COQUERET, Open CASCADE
26 #  Module : GEOM
27 #  $Header$
28
29 import salome
30 import geompy
31 import math
32
33 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "Geometry")
34 myBuilder = salome.myStudy.NewBuilder()
35
36 from geompy import gg
37
38 #Create base Variables
39 nbtimes1  = 5      #Short
40 nbtimes2  = 5
41 mindeg = 2
42 maxdeg = 5
43 nbiter = 5
44 ShapeTypeFace = 4
45 ShapeTypeEdge = 6
46 WantPlanarFace = 1 #True
47
48 radius    = 10.     #Double
49 radius1   = 100.
50 radius2   = 200.
51 height    = 200.
52 d1        = 10.
53 d2        = 10.
54 step1     = 250.
55 step2     = 250.
56 angle     = 45.
57 angle1    = angle * math.pi / 180
58 angle2    = 2 * angle1
59 factor    = 2.
60 tol3d = 0.0001
61 tol2d = 0.0001
62 weight = 1000000.
63 waterdensity = 1.
64 meshingdeflection = 0.01
65 trimsize  = 1000.
66 precision = 0.00001
67
68 #Create base points
69 p0 = geom.MakePointStruct(0., 0., 0.) #(Double, Double, Double)->PointStruct
70 px = geom.MakePointStruct(100., 0., 0.)
71 py = geom.MakePointStruct(0., 100., 0.)
72 pz = geom.MakePointStruct(0., 0., 100.)
73 pxyz = geom.MakePointStruct(100., 100., 100.)
74
75 #Create base directions
76 vx = geom.MakeDirection(px)                      #(PointStruct)->DirStruct
77 vy = geom.MakeDirection(py)
78 vz = geom.MakeDirection(pz)
79 vxyz = geom.MakeDirection(pxyz)
80 ax = geom.MakeAxisStruct(0., 0., 0., 100., 0., 0.) #(Double, Double, Double, Double, Double, Double)->AxisStruct
81 axy = geom.MakeAxisStruct(100., 0., 0., -100., 100., 0.)
82 ay = geom.MakeAxisStruct(0., 0., 0., 0., 100., 0.)
83 az = geom.MakeAxisStruct(0., 0., 0., 0., 0., 100.)
84
85 #Create base geometry 2D
86 Vertex = geom.MakeVertex(100., 50., 200.) #(Double, Double, Double)->GEOM_Shape_ptr
87 Vector = geom.MakeVector(px, py)          #(PointStruct, PointStruct)->GEOM_Shape_ptr
88 Line   = geom.MakeLine(p0, vxyz)            #(PointStruct, DirStruct)->GEOM_Shape_ptr
89 Arc    = geom.MakeArc(py, pz, px)         #(PointStruct, PointStruct, PointStruct)->GEOM_Shape_ptr
90 Circle = geom.MakeCircle(p0, vz, radius1) #(PointStruct, DirStruct, Double)->GEOM_Shape_ptr
91 Plane  = geom.MakePlane(pz, vxyz, trimsize) #(PointStruct, DirStruct, Double)->GEOM_Shape_ptr
92
93 #Create base geometry 3D
94 Box      = geompy.MakeBox(0., 0., 0., 200., 200., 200.)      #(Double, Double, Double)->GEOM_Shape_ptr
95 Cylinder = geompy.MakeCylinder(p0, vz, radius1, height)      #(Double, Double, Double)->GEOM_Shape_ptr
96 Sphere   = geompy.MakeSphere(0., 0., 0., radius1)            #(Double, Double, Double)->GEOM_Shape_ptr
97 Cone     = geompy.MakeCone(p0, vz, radius2, radius, height) #(PointStruct)->DirStruct
98 Torus    = geompy.MakeTorus(p0, vz, radius2, radius)         #(Double, Double, Double)->GEOM_Shape_ptr
99
100 #Boolean (Common, Cut, Fuse, Section)
101 Common  = geompy.MakeBoolean(Box, Sphere, 1) #(GEOM_Shape_ptr, GEOM_Shape_ptr, Short)->GEOM_Shape_ptr
102 Cut     = geompy.MakeBoolean(Box, Sphere, 2)
103 Fuse    = geompy.MakeBoolean(Box, Sphere, 3)
104 Section = geompy.MakeBoolean(Box, Sphere, 4)
105
106 #IORList for Wire
107 ShapeListWire = []
108 IORListWire   = []
109 ShapeListWire.append(Vector)
110 ShapeListWire.append(Arc)
111 for Shape in ShapeListWire :
112     IORListWire.append(Shape._get_Name())
113
114 #IORList for Compound
115 ShapeListCompound = []
116 IORListCompound   = []
117 i = 0
118 while i <= 3 :
119       S = geompy.MakeTranslation(Arc, i * 100., i * 100., i * 100.)
120       ShapeListCompound.append(S)
121       i = i + 1
122 for Shape in ShapeListCompound :
123     IORListCompound.append(Shape._get_Name())
124
125 #Create base objects
126 Edge     = geompy.MakeEdge(p0, pxyz)             #(PointStruct, PointStruct)->GEOM_Shape_ptr
127 Wire     = geompy.MakeWire(IORListWire)          #(ListOfIOR)->GEOM_Shape_ptr
128 Face     = geompy.MakeFace(Wire, WantPlanarFace) #(GEOM_Shape_ptr, Boolean)->GEOM_Shape_ptr
129 Compound = geompy.MakeCompound(IORListCompound)  #(ListOfIOR)->GEOM_Shape_ptr
130
131 #IORList for Sewing
132 ShapeListSewing = []
133 IORListSewing   = []
134 ShapeListSewing.append(Face)
135 S = geompy.MakeRotation(Face, axy, angle1)
136 ShapeListSewing.append(S)
137 for Shape in ShapeListSewing :
138     IORListSewing.append(Shape._get_Name())
139
140 #Create advanced objects
141 Copy       = geompy.MakeCopy(Box)                                               #(GEOM_Shape_ptr)->GEOM_Shape_ptr
142 Prism      = geompy.MakePrism(Face, p0, pz)                                     #(GEOM_Shape_ptr, PointStruct, PointStruct)->GEOM_Shape_ptr
143 #Revolution = geompy.MakeRevolution(Face, az, angle2)                            #(GEOM_Shape_ptr, AxisStruct, Double)->GEOM_Shape_ptr
144 Filling    = geompy.MakeFilling(Compound, mindeg, maxdeg, tol3d, tol2d, nbiter) #(GEOM_Shape_ptr, Short, Short, Double, Double, Short)->GEOM_Shape_ptr
145 Pipe       = geompy.MakePipe(Edge, Wire)                                        #(GEOM_Shape_ptr, GEOM_Shape_ptr)->GEOM_Shape_ptr
146 Sewing     = geompy.MakeSewing(IORListSewing, precision)                        #(ListOfIOR, Double)->GEOM_Shape_ptr
147
148 #IDList for Fillet/Chamfer
149 IDlist = []
150 i = 1
151 while i <= 3 :
152       IDlist.append(i)
153       i = i + 1
154
155 #Transform objects
156 Translation = geompy.MakeTranslation(Box, 300., 300., 300.)            #(GEOM_Shape_ptr, Double, Double, Double)->GEOM_Shape_ptr
157 Rotation    = geompy.MakeRotation(Box, az, angle1)                     #(GEOM_Shape_ptr, AxisStruct, Double)->GEOM_Shape_ptr
158 Scale       = geompy.MakeScaleTransform(Box, p0, factor)               #(GEOM_Shape_ptr, PointStruct, Double)->GEOM_Shape_ptr
159 Mirror      = geompy.MakeMirrorByPlane(Box, Plane)                     #(GEOM_Shape_ptr, GEOM_Shape_ptr)->GEOM_Shape_ptr
160 Orientation = geompy.OrientationChange(Box)                            #(GEOM_Shape_ptr)->GEOM_Shape_ptr
161 Fillet      = geompy.MakeFillet (Prism, radius, ShapeTypeEdge, IDlist) #(GEOM_Shape_ptr, Double, Short, ListOfSubShapeID)->GEOM_Shape_ptr
162 Chamfer     = geompy.MakeChamfer(Prism, d1, d2, ShapeTypeEdge, IDlist) #(GEOM_Shape_ptr, Double, Double, Short, ListOfSubShapeID)->GEOM_Shape_ptr
163
164 #Create Patterns
165 MultiTrans1D = geompy.MakeMultiTranslation1D(Fillet, vz, step1, nbtimes1)                      #(GEOM_Shape_ptr, DirStruct, Double, Short)->GEOM_Shape_ptr
166 MultiTrans2D = geompy.MakeMultiTranslation2D(Fillet, vz, step1, nbtimes1, vy, step2, nbtimes2) #(GEOM_Shape_ptr, DirStruct, Double, Short, DirStruct, Double, Short)->GEOM_Shape_ptr
167 #!!!!Angle In Degree!!!!
168 MultiRot1D   = geompy.MakeMultiRotation1D(Chamfer, vx, px, nbtimes1)                           #(GEOM_Shape_ptr, DirStruct, PointStruct, Short)->GEOM_Shape_ptr
169 MultiRot2D   = geompy.MakeMultiRotation2D(Chamfer, vx, px, angle, nbtimes1, step1, nbtimes2)   #(GEOM_Shape_ptr, DirStruct, PointStruct, Double, Short, Double, Short)->GEOM_Shape_ptr
170
171 #IDList for Partition
172 ShapeListPartition1 = []
173 ShapeListPartition1.append(Box)
174 IORListPartition1   = []
175 for Shape in ShapeListPartition1 :
176     IORListPartition1.append(Shape._get_Name())
177 ShapeListPartition2 = []
178 ShapeListPartition2.append(Plane)
179 IORListPartition2   = []
180 for Shape in ShapeListPartition2 :
181     IORListPartition2.append(Shape._get_Name())
182
183 #IDList for SubShape
184 IDlistSubShape = []
185 IDlistSubShape.append(3)
186
187 #Create Informations objects
188 CDG        = geompy.MakeCDG(Prism)                                          #(GEOM_Shape_ptr)->GEOM_Shape_ptr
189 Archimede  = geompy.Archimede(Box, weight, waterdensity, meshingdeflection) #(GEOM_Shape_ptr, Double, Double, Double)->GEOM_Shape_ptr
190 CheckShape = geompy.CheckShape(Prism)                                       #(GEOM_Shape_ptr)->Boolean
191
192 #Partition objects
193 Partition       = geompy.Partition(IORListPartition1, IORListPartition2) #(ListOfIOR, ListOfIOR)->GEOM_Shape_ptr
194
195 #Add In Study
196 id_Vertex       = geompy.addToStudy(Vertex,       "Vertex")
197 id_Vector       = geompy.addToStudy(Vector,       "Vector")
198 id_Line         = geompy.addToStudy(Line,         "Line")
199 id_Arc          = geompy.addToStudy(Arc,          "Arc")
200 id_Circle       = geompy.addToStudy(Circle,       "Circle")
201 id_Plane        = geompy.addToStudy(Plane,        "Plane")
202
203 id_Box          = geompy.addToStudy(Box,          "Box")
204 id_Cylinder     = geompy.addToStudy(Cylinder,     "Cylinder")
205 id_Sphere       = geompy.addToStudy(Sphere,       "Sphere")
206 id_Cone         = geompy.addToStudy(Cone,         "Cone")
207 id_Torus        = geompy.addToStudy(Torus,        "Torus")
208
209 id_Edge         = geompy.addToStudy(Edge,         "Edge")
210 id_Wire         = geompy.addToStudy(Wire,         "Wire")
211 id_Face         = geompy.addToStudy(Face,         "Face")
212 id_Compound     = geompy.addToStudy(Compound,     "Compound")
213
214 id_Common       = geompy.addToStudy(Common,       "Common")
215 id_Cut          = geompy.addToStudy(Cut,          "Cut")
216 id_Fuse         = geompy.addToStudy(Fuse,         "Fuse")
217 id_Section      = geompy.addToStudy(Section,      "Section")
218
219 id_Copy         = geompy.addToStudy(Copy,         "Copy")
220 id_Prism        = geompy.addToStudy(Prism,        "Prism")
221 #id_Revolution   = geompy.addToStudy(Revolution,   "Revolution")
222 id_Filling      = geompy.addToStudy(Filling,      "Filling")
223 id_Pipe         = geompy.addToStudy(Pipe,         "Pipe")
224 id_Sewing       = geompy.addToStudy(Sewing,       "Sewing")
225
226 Id_Translation  = geompy.addToStudy(Translation,  "Translation")
227 Id_Rotation     = geompy.addToStudy(Rotation,     "Rotation")
228 Id_Scale        = geompy.addToStudy(Scale,        "Scale")
229 Id_Mirror       = geompy.addToStudy(Mirror,       "Mirror")
230 Id_Orientation  = geompy.addToStudy(Orientation,  "Orientation")
231 Id_Fillet       = geompy.addToStudy(Fillet,       "Fillet")
232 Id_Chamfer      = geompy.addToStudy(Chamfer,      "Chamfer")
233
234 Id_MultiTrans1D = geompy.addToStudy(MultiTrans1D, "MultiTrans1D")
235 Id_MultiTrans2D = geompy.addToStudy(MultiTrans2D, "MultiTrans2D")
236 Id_MultiRot1D   = geompy.addToStudy(MultiRot1D,   "MultiRot1D")
237 Id_MultiRot2D   = geompy.addToStudy(MultiRot2D,   "MultiRot2D")
238
239 Id_Partition    = geompy.addToStudy(Partition,  "Partition")
240 Id_CDG          = geompy.addToStudy(CDG,          "CDG")
241 Id_Archimede    = geompy.addToStudy(Archimede,    "Archimede")
242
243 #Decompose objects
244 SubShape        = geompy.SubShape(Box, ShapeTypeFace, IDlistSubShape)    #(GEOM_Shape_ptr, Short, ListOfSubShapeID)->GEOM_Shape_ptr
245 name            = geompy.SubShapeName( SubShape._get_Name(), Box._get_Name() )
246 Id_SubShape     = geompy.addToStudyInFather(Box, SubShape, name)
247
248 SubShapeAllList = []
249 SubShapeAllList = geompy.SubShapeAll(SubShape, ShapeTypeEdge)            #(GEOM_Shape_ptr, Short)->ListOfGeomShapes
250 for Shape in SubShapeAllList :
251     name = geompy.SubShapeName( Shape._get_Name(), Box._get_Name() )
252     Id_SubShapeAll  = geompy.addToStudyInFather(SubShape, Shape, name)