Salome HOME
PAL8375 improvement solving.
[modules/geom.git] / src / GEOM_SWIG / GEOM_TestOthers.py
1 #  GEOM GEOM_SWIG : binding of C++ implementaion with Python
2 #
3 #  Copyright (C) 2003  CEA
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 #  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 #
21 #
22 #  File   : GEOM_TestOthers.py
23 #  Author : Julia DOROVSKIKH
24 #  Module : GEOM
25 #  $Header$
26
27 def TestOtherOperations (geompy, math):
28
29   # MakeFaces
30   p11 = geompy.MakeVertex( 0,  0, 0)
31   p12 = geompy.MakeVertex(30,  0, 0)
32   p13 = geompy.MakeVertex(30, 30, 0)
33   p14 = geompy.MakeVertex( 0, 30, 0)
34
35   p21 = geompy.MakeVertex(10, 10, 0)
36   p22 = geompy.MakeVertex(20, 10, 0)
37   p23 = geompy.MakeVertex(20, 20, 0)
38   p24 = geompy.MakeVertex(10, 20, 0)
39
40   e11 = geompy.MakeEdge(p11, p12)
41   e12 = geompy.MakeEdge(p12, p13)
42   e13 = geompy.MakeEdge(p13, p14)
43   e14 = geompy.MakeEdge(p14, p11)
44
45   e21 = geompy.MakeEdge(p21, p22)
46   e22 = geompy.MakeEdge(p22, p23)
47   e23 = geompy.MakeEdge(p23, p24)
48   e24 = geompy.MakeEdge(p24, p21)
49
50   w1 = geompy.MakeWire([e11, e12, e13, e14])
51   w2 = geompy.MakeWire([e21, e22, e23, e24])
52   w3 = geompy.MakeTranslation(w2, 0, 0, 10)
53
54   id_w1 = geompy.addToStudy(w1, "Outside Wire")
55   id_w2 = geompy.addToStudy(w2, "Inside Wire")
56   id_w3 = geompy.addToStudy(w3, "Inside Wire, translated along OZ")
57
58   f12 = geompy.MakeFaces([w1, w2], 0)
59   id_f12 = geompy.addToStudy(f12, "MakeFaces WO + WI")
60
61   # OrientationChange
62   Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
63   Orientation = geompy.OrientationChange(Box)
64   id_Orientation = geompy.addToStudy(Orientation, "OrientationChange")
65
66   # MakeCommon, MakeCut, MakeFuse, MakeSection
67   Sphere = geompy.MakeSphereR(100)
68
69   Common  = geompy.MakeCommon (Box, Sphere)
70   Cut     = geompy.MakeCut    (Box, Sphere)
71   Fuse    = geompy.MakeFuse   (Box, Sphere)
72   Section = geompy.MakeSection(Box, Sphere)
73
74   id_Common  = geompy.addToStudy(Common,  "Common")
75   id_Cut     = geompy.addToStudy(Cut,     "Cut")
76   id_Fuse    = geompy.addToStudy(Fuse,    "Fuse")
77   id_Section = geompy.addToStudy(Section, "Section")
78
79   # Partition
80   p100 = geompy.MakeVertex(100, 100, 100)
81   p300 = geompy.MakeVertex(300, 300, 300)
82   Box1 = geompy.MakeBoxTwoPnt(p100, p300)
83   Partition = geompy.Partition([Box], [Box1], [], [Box])
84   id_Partition = geompy.addToStudy(Partition, "Partition of Box by Box1")
85
86   # MakeMultiRotation1D, MakeMultiRotation2D
87   pz = geompy.MakeVertex(0, 0, 100)
88   vy = geompy.MakeVectorDXDYDZ(0, 100, 0)
89
90   MultiRot1D = geompy.MakeMultiRotation1D(f12, vy, pz, 6)
91   MultiRot2D = geompy.MakeMultiRotation2D(f12, vy, pz, 45, 6, 30, 3)
92
93   id_MultiRot1D = geompy.addToStudy(MultiRot1D, "MakeMultiRotation1D")
94   id_MultiRot2D = geompy.addToStudy(MultiRot2D, "MakeMultiRotation2D")
95
96   # MakeFilletAll
97   radius_fillet = 10.
98   face5 = geompy.SubShapeSorted(Box, geompy.ShapeType["FACE"], [5])
99   f_glob_id = geompy.GetSubShapeID(Box, face5)
100   SuppFace = geompy.SuppressFaces(Box, [f_glob_id])
101
102   MakeFilletAll = geompy.MakeFilletAll(SuppFace, radius_fillet)
103   id_MakeFilletAll = geompy.addToStudy(MakeFilletAll, "MakeFilletAll")
104
105   # MakeChamferAll
106   dimension_chamfer = 10.
107   MakeChamferAll = geompy.MakeChamferAll(SuppFace, dimension_chamfer)
108   id_MakeChamferAll = geompy.addToStudy(MakeChamferAll, "MakeChamferAll")
109
110   # MakeChamfer
111   d1 = 13.
112   d2 = 7.
113   box_faces = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
114   f_ind_1 = geompy.GetSubShapeID(Box, box_faces[0])
115   f_ind_2 = geompy.GetSubShapeID(Box, box_faces[1])
116   f_ind_3 = geompy.GetSubShapeID(Box, box_faces[2])
117
118   MakeChamfer = geompy.MakeChamfer(Box, d1, d2, geompy.ShapeType["FACE"],
119                                    [f_ind_1, f_ind_2, f_ind_3])
120   id_MakeChamfer = geompy.addToStudy(MakeChamfer, "MakeChamfer")
121
122   # Export
123   geompy.Export(f12, "/tmp/testExportImport.brep", "BREP")
124
125   # ExportBREP, ExportIGES, ExportSTEP
126   geompy.ExportBREP(f12, "/tmp/testExportImportBREP.brep")
127   geompy.ExportIGES(f12, "/tmp/testExportImportIGES.iges")
128   geompy.ExportSTEP(f12, "/tmp/testExportImportSTEP.step")
129
130   # Import
131   Import = geompy.Import("/tmp/testExportImport.brep", "BREP")
132
133   id_Import = geompy.addToStudy(Import, "Import")
134
135   # ImportBREP, ImportIGES, ImportSTEP
136   ImportBREP = geompy.ImportBREP("/tmp/testExportImportBREP.brep")
137   ImportIGES = geompy.ImportIGES("/tmp/testExportImportIGES.iges")
138   ImportSTEP = geompy.ImportSTEP("/tmp/testExportImportSTEP.step")
139
140   id_ImportBREP = geompy.addToStudy(ImportBREP, "ImportBREP")
141   id_ImportIGES = geompy.addToStudy(ImportIGES, "ImportIGES")
142   id_ImportSTEP = geompy.addToStudy(ImportSTEP, "ImportSTEP")
143
144   # NumberOfFaces
145   NumberOfFaces = geompy.NumberOfFaces(Box)
146   if NumberOfFaces != 6:
147     print "Bad number of faces in BOX!"
148
149   # NumberOfEdges
150   NumberOfEdges = geompy.NumberOfEdges(Box)
151   if NumberOfEdges != 12:
152     print "Bad number of edges in BOX!"
153
154   # MakeBlockExplode
155   Compound = geompy.MakeCompound([Box, Sphere])
156   MakeBlockExplode = geompy.MakeBlockExplode(Compound, 6, 6)
157
158   id_MakeBlockExplode = geompy.addToStudy(MakeBlockExplode[0], "MakeBlockExplode")
159
160   # CheckCompoundOfBlocks
161   p1 = geompy.MakeVertex(200, 0, 0)
162   p2 = geompy.MakeVertex(400, 200, 200)
163   p3 = geompy.MakeVertex(400, 50, 50)
164   p4 = geompy.MakeVertex(600, 250, 250)
165
166   Box2 = geompy.MakeBoxTwoPnt(p1, p2)
167   Box3 = geompy.MakeBoxTwoPnt(p3, p4)
168   Cyl  = geompy.MakeCylinderRH(50, 300)
169   Cone = geompy.MakeConeR1R2H(150, 10, 400)
170
171   Compound1 = geompy.MakeCompound([Box, Cyl, Cone, Box3, Box2])
172
173   IsValid = geompy.CheckCompoundOfBlocks(Compound1)
174   if IsValid == 0:
175     print "The Blocks Compound is NOT VALID"
176   else:
177     print "The Blocks Compound is VALID"
178
179   IsValid = geompy.CheckCompoundOfBlocks(Box)
180   if IsValid == 0:
181     print "The Box is NOT VALID"
182   else:
183     print "The Box is VALID"
184
185   # test geometrical groups
186
187   # CreateGroup
188   CreateGroup = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])
189
190   id_CreateGroup = geompy.addToStudy(CreateGroup, "CreateGroup")
191
192   # AddObject
193   f_ind_4 = geompy.GetSubShapeID(Box, box_faces[3])
194   f_ind_5 = geompy.GetSubShapeID(Box, box_faces[4])
195   f_ind_6 = geompy.GetSubShapeID(Box, box_faces[5])
196
197   geompy.AddObject(CreateGroup, f_ind_6) # box_faces[5]
198   geompy.AddObject(CreateGroup, f_ind_1) # box_faces[0]
199   geompy.AddObject(CreateGroup, f_ind_4) # box_faces[3]
200
201   # UnionList
202   geompy.UnionList(CreateGroup, [box_faces[2], box_faces[4], box_faces[5]])
203
204   # RemoveObject(theGroup, theSubShapeID)
205   geompy.RemoveObject(CreateGroup, f_ind_1) # box_faces[0]
206
207   # DifferenceList
208   geompy.DifferenceList(CreateGroup, [box_faces[1], box_faces[0], box_faces[3]])
209
210   # GetObjectIDs
211   GetObjectIDs = geompy.GetObjectIDs(CreateGroup)
212
213   print "Group of Box's faces includes the following IDs:"
214   print "(must be ", f_ind_6, ", ", f_ind_3, " and ", f_ind_5, ")"
215   for ObjectID in GetObjectIDs:
216     print " ", ObjectID
217
218   BoxCopy = geompy.GetMainShape(CreateGroup)
219
220   # -----------------------------------------------------------------------------
221   # enumeration ShapeTypeString as a dictionary
222   # -----------------------------------------------------------------------------
223   ShapeTypeString = {'0':"COMPOUND", '1':"COMPSOLID", '2':"SOLID", '3':"SHELL", '4':"FACE", '5':"WIRE", '6':"EDGE", '7':"VERTEX", '8':"SHAPE"}
224
225   GroupType = geompy.GetType(CreateGroup)
226   print "Type of elements of the created group is ", ShapeTypeString[`GroupType`]
227
228   # Prepare data for the following operations
229   p0 = geompy.MakeVertex(0, 0, 0)
230   b0 = geompy.MakeBox(-50, -50, -50, 50, 50, 50)
231   s0 = geompy.MakeSphereR(100)
232
233   id_b0 = geompy.addToStudy(b0, "b0")
234   id_s0 = geompy.addToStudy(s0, "s0")
235
236   v_0pp = geompy.MakeVectorDXDYDZ( 0,  1,  1)
237   v_0np = geompy.MakeVectorDXDYDZ( 0, -1,  1)
238   v_p0p = geompy.MakeVectorDXDYDZ( 1,  0,  1)
239   v_n0p = geompy.MakeVectorDXDYDZ(-1,  0,  1)
240   v_pp0 = geompy.MakeVectorDXDYDZ( 1,  1,  0)
241   v_np0 = geompy.MakeVectorDXDYDZ(-1,  1,  0)
242
243   pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
244   pln_0np = geompy.MakePlane(p0, v_0np, 300)
245   pln_p0p = geompy.MakePlane(p0, v_p0p, 300)
246   pln_n0p = geompy.MakePlane(p0, v_n0p, 300)
247   pln_pp0 = geompy.MakePlane(p0, v_pp0, 300)
248   pln_np0 = geompy.MakePlane(p0, v_np0, 300)
249
250   part_tool_1 = geompy.MakePartition([b0, pln_0pp, pln_0np, pln_p0p, pln_n0p, pln_pp0, pln_np0],
251                                      [],
252                                      [],
253                                      [b0])
254
255   pt_pnt_1  = geompy.MakeVertex( 55,   0,  55)
256   pt_pnt_2  = geompy.MakeVertex(  0,  55,  55)
257   pt_pnt_3  = geompy.MakeVertex(-55,   0,  55)
258   pt_pnt_4  = geompy.MakeVertex(  0, -55,  55)
259   pt_pnt_5  = geompy.MakeVertex( 55,  55,   0)
260   pt_pnt_6  = geompy.MakeVertex( 55, -55,   0)
261   pt_pnt_7  = geompy.MakeVertex(-55,  55,   0)
262   pt_pnt_8  = geompy.MakeVertex(-55, -55,   0)
263   pt_pnt_9  = geompy.MakeVertex( 55,   0, -55)
264   pt_pnt_10 = geompy.MakeVertex(  0,  55, -55)
265   pt_pnt_11 = geompy.MakeVertex(-55,   0, -55)
266   pt_pnt_12 = geompy.MakeVertex(  0, -55, -55)
267
268   pt_face_1  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_1)
269   pt_face_2  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_2)
270   pt_face_3  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_3)
271   pt_face_4  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_4)
272   pt_face_5  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_5)
273   pt_face_6  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_6)
274   pt_face_7  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_7)
275   pt_face_8  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_8)
276   pt_face_9  = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_9)
277   pt_face_10 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_10)
278   pt_face_11 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_11)
279   pt_face_12 = geompy.GetFaceNearPoint(part_tool_1, pt_pnt_12)
280
281   pt_box = geompy.GetBlockNearPoint(part_tool_1, p0)
282
283   part_tool = geompy.MakeCompound([pt_face_1, pt_face_4, pt_face_7, pt_face_10,
284                                    pt_face_2, pt_face_5, pt_face_8, pt_face_11,
285                                    pt_face_3, pt_face_6, pt_face_9, pt_face_12, pt_box])
286   id_part_tool = geompy.addToStudy(part_tool, "part_tool")
287
288   part = geompy.MakePartition([s0], [part_tool])
289   geompy.addToStudy(part, "part")
290
291   # GetFreeFacesIDs
292   anIDs = geompy.GetFreeFacesIDs(part)
293   freeFaces = geompy.GetSubShape(part, anIDs)
294
295   geompy.addToStudy(freeFaces, "freeFaces")
296
297   # RemoveExtraEdges
298   freeFacesWithoutExtra = geompy.RemoveExtraEdges(freeFaces)
299
300   geompy.addToStudy(freeFacesWithoutExtra, "freeFacesWithoutExtra")
301
302   # GetSharedShapes
303   sharedFaces = geompy.GetSharedShapes(part, freeFacesWithoutExtra, geompy.ShapeType["FACE"])
304
305   for shFace in sharedFaces:
306     geompy.addToStudy(shFace, "sharedFace")
307
308   # CheckAndImprove
309   blocksComp = geompy.CheckAndImprove(part)
310
311   geompy.addToStudy(blocksComp, "blocksComp")
312
313   # Propagate
314   listChains = geompy.Propagate(blocksComp)
315
316   for chain in listChains:
317     geompy.addToStudyInFather(blocksComp, chain, "propagation chain")
318
319   # GetPoint(theShape, theX, theY, theZ, theEpsilon)
320   # 
321   # (-50,  50, 50) .-----. (50,  50, 50)
322   #      pb0_top_1 |     | 
323   #                |     . pmidle
324   #                |     | 
325   # (-50, -50, 50) '-----' (50, -50, 50)
326   #
327   pb0_top_1 = geompy.GetPoint(blocksComp, -50,  50,  50, 0.01)
328   pb0_bot_1 = geompy.GetPoint(blocksComp, -50, -50, -50, 0.01)
329
330   geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50,  50,  50)")
331   geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)")
332
333   # GetEdgeNearPoint(theShape, thePoint)
334   pmidle = geompy.MakeVertex(50, 0, 50)
335   edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle)
336
337   geompy.addToStudyInFather(blocksComp, edge1, "edge near point (50, 0, 50)")
338
339   # GetBlockByParts(theCompound, theParts)
340   b0_image = geompy.GetBlockByParts(blocksComp, [pb0_top_1, pb0_bot_1, edge1])
341
342   geompy.addToStudyInFather(blocksComp, b0_image, "b0 image")
343
344   # GetShapesOnPlane
345   faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"],
346                                          v_0pp, geompy.GEOM.ST_ONIN)
347   for face_i in faces_on_pln:
348     geompy.addToStudy(face_i, "Face on Plane (N = (0, 1, 1)) or below it")
349
350   # GetShapesOnCylinder
351   edges_on_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
352                                             vy, 55, geompy.GEOM.ST_OUT)
353   for edge_i in edges_on_cyl:
354     geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)")
355
356   # GetShapesOnSphere
357   vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"],
358                                              p0, 100, geompy.GEOM.ST_ON)
359   for vertex_i in vertices_on_sph:
360     geompy.addToStudy(vertex_i, "Vertex on Sphere (center = (0, 0, 0), r = 100)")
361
362   # GetInPlace(theShapeWhere, theShapeWhat)
363   box5 = geompy.MakeBoxDXDYDZ(100, 100, 100)
364   box6 = geompy.MakeTranslation(box5, 50, 50, 0)
365
366   part = geompy.MakePartition([box5], [box6])
367   geompy.addToStudy(part, "Partitioned")
368
369   ibb = 5
370   box_list = [box5, box6]
371   for abox in box_list:
372     geompy.addToStudy(abox, "Box " + `ibb`)
373     box_faces = geompy.SubShapeAll(abox, geompy.ShapeType["FACE"])
374     ifa = 1
375     for aface in box_faces:
376       geompy.addToStudyInFather(abox, aface, "Face" + `ifa`)
377       refl_box_face = geompy.GetInPlace(part, aface)
378       if refl_box_face is not None:
379         geompy.addToStudyInFather(part, refl_box_face,
380                                   "Reflection of Face " + `ifa` + " of box " + `ibb`)
381       ifa = ifa + 1
382     ibb = ibb + 1