Salome HOME
97674648ee52109c99e0c29c9d040e5d51e29a23
[modules/geom.git] / src / GEOM_SWIG / GEOM_usinggeom.py
1 #==============================================================================
2 #  File      : GEOM_usinggeom.py
3 #  Created   : mon apr 22 11:55:00 CET 2002
4 #  Author    : Damien COQUERET, Open CASCADE
5 #  Project   : SALOME
6 #  Copyright : Open CASCADE, 2002
7 #  $Header$
8 #==============================================================================
9
10 import salome
11 import geompy
12 import math
13
14 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
15 myBuilder = salome.myStudy.NewBuilder()
16
17 from geompy import gg
18
19 #Create base Variables
20 nbtimes1  = 5      #Short
21 nbtimes2  = 5
22 mindeg = 2
23 maxdeg = 5
24 nbiter = 5
25 ShapeTypeFace = 4
26 ShapeTypeEdge = 6
27 WantPlanarFace = 1 #True
28
29 radius    = 10.     #Double
30 radius1   = 100.
31 radius2   = 200.
32 height    = 200.
33 d1        = 10.
34 d2        = 10.
35 step1     = 250.
36 step2     = 250.
37 angle     = 45.
38 angle1    = angle * math.pi / 180
39 angle2    = 2 * angle1
40 factor    = 2.
41 tol3d = 0.0001
42 tol2d = 0.0001
43 weight = 1000000.
44 waterdensity = 1.
45 meshingdeflection = 0.01
46 trimsize  = 1000.
47 precision = 0.00001
48
49 #Create base points
50 p0 = geom.MakePointStruct(0., 0., 0.) #(Double, Double, Double)->PointStruct
51 px = geom.MakePointStruct(100., 0., 0.)
52 py = geom.MakePointStruct(0., 100., 0.)
53 pz = geom.MakePointStruct(0., 0., 100.)
54 pxyz = geom.MakePointStruct(100., 100., 100.)
55
56 #Create base directions
57 vx = geom.MakeDirection(px)                      #(PointStruct)->DirStruct
58 vy = geom.MakeDirection(py)
59 vz = geom.MakeDirection(pz)
60 vxyz = geom.MakeDirection(pxyz)
61 ax = geom.MakeAxisStruct(0., 0., 0., 100., 0., 0.) #(Double, Double, Double, Double, Double, Double)->AxisStruct
62 axy = geom.MakeAxisStruct(100., 0., 0., -100., 100., 0.)
63 ay = geom.MakeAxisStruct(0., 0., 0., 0., 100., 0.)
64 az = geom.MakeAxisStruct(0., 0., 0., 0., 0., 100.)
65
66 #Create base geometry 2D
67 Vertex = geom.MakeVertex(100., 50., 200.) #(Double, Double, Double)->GEOM_Shape_ptr
68 Vector = geom.MakeVector(px, py)          #(PointStruct, PointStruct)->GEOM_Shape_ptr
69 Line   = geom.MakeLine(p0, vxyz)            #(PointStruct, DirStruct)->GEOM_Shape_ptr
70 Arc    = geom.MakeArc(py, pz, px)         #(PointStruct, PointStruct, PointStruct)->GEOM_Shape_ptr
71 Circle = geom.MakeCircle(p0, vz, radius1) #(PointStruct, DirStruct, Double)->GEOM_Shape_ptr
72 Plane  = geom.MakePlane(pz, vxyz, trimsize) #(PointStruct, DirStruct, Double)->GEOM_Shape_ptr
73
74 #Create base geometry 3D
75 Box      = geompy.MakeBox(0., 0., 0., 200., 200., 200.)      #(Double, Double, Double)->GEOM_Shape_ptr
76 Cylinder = geompy.MakeCylinder(p0, vz, radius1, height)      #(Double, Double, Double)->GEOM_Shape_ptr
77 Sphere   = geompy.MakeSphere(0., 0., 0., radius1)            #(Double, Double, Double)->GEOM_Shape_ptr
78 Cone     = geompy.MakeCone(p0, vz, radius2, radius, height) #(PointStruct)->DirStruct
79 Torus    = geompy.MakeTorus(p0, vz, radius2, radius)         #(Double, Double, Double)->GEOM_Shape_ptr
80
81 #Boolean (Common, Cut, Fuse, Section)
82 Common  = geompy.MakeBoolean(Box, Sphere, 1) #(GEOM_Shape_ptr, GEOM_Shape_ptr, Short)->GEOM_Shape_ptr
83 Cut     = geompy.MakeBoolean(Box, Sphere, 2)
84 Fuse    = geompy.MakeBoolean(Box, Sphere, 3)
85 Section = geompy.MakeBoolean(Box, Sphere, 4)
86
87 #IORList for Wire
88 ShapeListWire = []
89 IORListWire   = []
90 ShapeListWire.append(Vector)
91 ShapeListWire.append(Arc)
92 for Shape in ShapeListWire :
93     IORListWire.append(Shape._get_Name())
94
95 #IORList for Compound
96 ShapeListCompound = []
97 IORListCompound   = []
98 i = 0
99 while i <= 3 :
100       S = geompy.MakeTranslation(Arc, i * 100., i * 100., i * 100.)
101       ShapeListCompound.append(S)
102       i = i + 1
103 for Shape in ShapeListCompound :
104     IORListCompound.append(Shape._get_Name())
105
106 #Create base objects
107 Edge     = geompy.MakeEdge(p0, pxyz)             #(PointStruct, PointStruct)->GEOM_Shape_ptr
108 Wire     = geompy.MakeWire(IORListWire)          #(ListOfIOR)->GEOM_Shape_ptr
109 Face     = geompy.MakeFace(Wire, WantPlanarFace) #(GEOM_Shape_ptr, Boolean)->GEOM_Shape_ptr
110 Compound = geompy.MakeCompound(IORListCompound)  #(ListOfIOR)->GEOM_Shape_ptr
111
112 #IORList for Sewing
113 ShapeListSewing = []
114 IORListSewing   = []
115 ShapeListSewing.append(Face)
116 S = geompy.MakeRotation(Face, axy, angle1)
117 ShapeListSewing.append(S)
118 for Shape in ShapeListSewing :
119     IORListSewing.append(Shape._get_Name())
120
121 #Create advanced objects
122 Copy       = geompy.MakeCopy(Box)                                               #(GEOM_Shape_ptr)->GEOM_Shape_ptr
123 Prism      = geompy.MakePrism(Face, p0, pz)                                     #(GEOM_Shape_ptr, PointStruct, PointStruct)->GEOM_Shape_ptr
124 Revolution = geompy.MakeRevolution(Face, az, angle2)                            #(GEOM_Shape_ptr, AxisStruct, Double)->GEOM_Shape_ptr
125 Filling    = geompy.MakeFilling(Compound, mindeg, maxdeg, tol3d, tol2d, nbiter) #(GEOM_Shape_ptr, Short, Short, Double, Double, Short)->GEOM_Shape_ptr
126 Pipe       = geompy.MakePipe(Edge, Wire)                                        #(GEOM_Shape_ptr, GEOM_Shape_ptr)->GEOM_Shape_ptr
127 Sewing     = geompy.MakeSewing(IORListSewing, precision)                        #(ListOfIOR, Double)->GEOM_Shape_ptr
128
129 #IDList for Fillet/Chamfer
130 IDlist = []
131 i = 1
132 while i <= 3 :
133       IDlist.append(i)
134       i = i + 1
135
136 #Transform objects
137 Translation = geompy.MakeTranslation(Box, 300., 300., 300.)            #(GEOM_Shape_ptr, Double, Double, Double)->GEOM_Shape_ptr
138 Rotation    = geompy.MakeRotation(Box, az, angle1)                     #(GEOM_Shape_ptr, AxisStruct, Double)->GEOM_Shape_ptr
139 Scale       = geompy.MakeScaleTransform(Box, p0, factor)               #(GEOM_Shape_ptr, PointStruct, Double)->GEOM_Shape_ptr
140 Mirror      = geompy.MakeMirrorByPlane(Box, Plane)                     #(GEOM_Shape_ptr, GEOM_Shape_ptr)->GEOM_Shape_ptr
141 Orientation = geompy.OrientationChange(Box)                            #(GEOM_Shape_ptr)->GEOM_Shape_ptr
142 Fillet      = geompy.MakeFillet (Prism, radius, ShapeTypeEdge, IDlist) #(GEOM_Shape_ptr, Double, Short, ListOfSubShapeID)->GEOM_Shape_ptr
143 Chamfer     = geompy.MakeChamfer(Prism, d1, d2, ShapeTypeEdge, IDlist) #(GEOM_Shape_ptr, Double, Double, Short, ListOfSubShapeID)->GEOM_Shape_ptr
144
145 #Create Patterns
146 MultiTrans1D = geompy.MakeMultiTranslation1D(Fillet, vz, step1, nbtimes1)                      #(GEOM_Shape_ptr, DirStruct, Double, Short)->GEOM_Shape_ptr
147 MultiTrans2D = geompy.MakeMultiTranslation2D(Fillet, vz, step1, nbtimes1, vy, step2, nbtimes2) #(GEOM_Shape_ptr, DirStruct, Double, Short, DirStruct, Double, Short)->GEOM_Shape_ptr
148 #!!!!Angle In Degree!!!!
149 MultiRot1D   = geompy.MakeMultiRotation1D(Chamfer, vx, px, nbtimes1)                           #(GEOM_Shape_ptr, DirStruct, PointStruct, Short)->GEOM_Shape_ptr
150 MultiRot2D   = geompy.MakeMultiRotation2D(Chamfer, vx, px, angle, nbtimes1, step1, nbtimes2)   #(GEOM_Shape_ptr, DirStruct, PointStruct, Double, Short, Double, Short)->GEOM_Shape_ptr
151
152 #IDList for Partition
153 ShapeListPartition1 = []
154 ShapeListPartition1.append(Box)
155 IORListPartition1   = []
156 for Shape in ShapeListPartition1 :
157     IORListPartition1.append(Shape._get_Name())
158 ShapeListPartition2 = []
159 ShapeListPartition2.append(Plane)
160 IORListPartition2   = []
161 for Shape in ShapeListPartition2 :
162     IORListPartition2.append(Shape._get_Name())
163
164 #IDList for SubShape
165 IDlistSubShape = []
166 IDlistSubShape.append(3)
167
168 #Create Informations objects
169 CDG        = geompy.MakeCDG(Prism)                                          #(GEOM_Shape_ptr)->GEOM_Shape_ptr
170 Archimede  = geompy.Archimede(Box, weight, waterdensity, meshingdeflection) #(GEOM_Shape_ptr, Double, Double, Double)->GEOM_Shape_ptr
171 CheckShape = geompy.CheckShape(Prism)                                       #(GEOM_Shape_ptr)->Boolean
172
173 #Partition objects
174 Partition       = geompy.Partition(IORListPartition1, IORListPartition2) #(ListOfIOR, ListOfIOR)->GEOM_Shape_ptr
175
176 #Add In Study
177 id_Vertex       = geompy.addToStudy(Vertex,       "Vertex")
178 id_Vector       = geompy.addToStudy(Vector,       "Vector")
179 id_Line         = geompy.addToStudy(Line,         "Line")
180 id_Arc          = geompy.addToStudy(Arc,          "Arc")
181 id_Circle       = geompy.addToStudy(Circle,       "Circle")
182 id_Plane        = geompy.addToStudy(Plane,        "Plane")
183
184 id_Box          = geompy.addToStudy(Box,          "Box")
185 id_Cylinder     = geompy.addToStudy(Cylinder,     "Cylinder")
186 id_Sphere       = geompy.addToStudy(Sphere,       "Sphere")
187 id_Cone         = geompy.addToStudy(Cone,         "Cone")
188 id_Torus        = geompy.addToStudy(Torus,        "Torus")
189
190 id_Edge         = geompy.addToStudy(Edge,         "Edge")
191 id_Wire         = geompy.addToStudy(Wire,         "Wire")
192 id_Face         = geompy.addToStudy(Face,         "Face")
193 id_Compound     = geompy.addToStudy(Compound,     "Compound")
194
195 id_Common       = geompy.addToStudy(Common,       "Common")
196 id_Cut          = geompy.addToStudy(Cut,          "Cut")
197 id_Fuse         = geompy.addToStudy(Fuse,         "Fuse")
198 id_Section      = geompy.addToStudy(Section,      "Section")
199
200 id_Copy         = geompy.addToStudy(Copy,         "Copy")
201 id_Prism        = geompy.addToStudy(Prism,        "Prism")
202 id_Revolution   = geompy.addToStudy(Revolution,   "Revolution")
203 id_Filling      = geompy.addToStudy(Filling,      "Filling")
204 id_Pipe         = geompy.addToStudy(Pipe,         "Pipe")
205 id_Sewing       = geompy.addToStudy(Sewing,       "Sewing")
206
207 Id_Translation  = geompy.addToStudy(Translation,  "Translation")
208 Id_Rotation     = geompy.addToStudy(Rotation,     "Rotation")
209 Id_Scale        = geompy.addToStudy(Scale,        "Scale")
210 Id_Mirror       = geompy.addToStudy(Mirror,       "Mirror")
211 Id_Orientation  = geompy.addToStudy(Orientation,  "Orientation")
212 Id_Fillet       = geompy.addToStudy(Fillet,       "Fillet")
213 Id_Chamfer      = geompy.addToStudy(Chamfer,      "Chamfer")
214
215 Id_MultiTrans1D = geompy.addToStudy(MultiTrans1D, "MultiTrans1D")
216 Id_MultiTrans2D = geompy.addToStudy(MultiTrans2D, "MultiTrans2D")
217 Id_MultiRot1D   = geompy.addToStudy(MultiRot1D,   "MultiRot1D")
218 Id_MultiRot2D   = geompy.addToStudy(MultiRot2D,   "MultiRot2D")
219
220 Id_Partition    = geompy.addToStudy(Partition,  "Partition")
221 Id_CDG          = geompy.addToStudy(CDG,          "CDG")
222 Id_Archimede    = geompy.addToStudy(Archimede,    "Archimede")
223
224 #Decompose objects
225 SubShape        = geompy.SubShape(Box, ShapeTypeFace, IDlistSubShape)    #(GEOM_Shape_ptr, Short, ListOfSubShapeID)->GEOM_Shape_ptr
226 name            = geompy.SubShapeName( SubShape._get_Name(), Box._get_Name() )
227 Id_SubShape     = geompy.addToStudyInFather(Box, SubShape, name)
228
229 SubShapeAllList = []
230 SubShapeAllList = geompy.SubShapeAll(SubShape, ShapeTypeEdge)            #(GEOM_Shape_ptr, Short)->ListOfGeomShapes
231 for Shape in SubShapeAllList :
232     name = geompy.SubShapeName( Shape._get_Name(), Box._get_Name() )
233     Id_SubShapeAll  = geompy.addToStudyInFather(SubShape, Shape, name)