]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_SWIG/geompy.py
Salome HOME
4746e7d62039381e3d9e76879018d26b7d545ba3
[modules/geom.git] / src / GEOM_SWIG / geompy.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   : geompy.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : GEOM
27 #  $Header$
28
29 import salome
30 import SALOMEDS
31 #import SALOMEDS_Attributes_idl
32
33 #NRI : BugID 1682 : from libSALOME_Swig import *
34
35 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
36 geom.GetCurrentStudy(salome.myStudyId)
37 myBuilder = salome.myStudy.NewBuilder()
38
39 gg = salome.ImportComponentGUI("GEOM")
40
41 father = salome.myStudy.FindComponent("GEOM")
42 if father is None:
43         father = myBuilder.NewComponent("GEOM")
44         A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName");
45         FName = A1._narrow(SALOMEDS.AttributeName)
46         FName.SetValue( salome.sg.getComponentUserName("GEOM") )
47         A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap");
48         aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
49         aPixmap.SetPixMap( "ICON_OBJBROWSER_Geometry" );
50         myBuilder.DefineComponentInstance(father,geom)
51
52
53 # -----------------------------------------------------------------------------
54 # add To Study  
55 # -----------------------------------------------------------------------------
56
57 def SubShapeName(aSubId, aMainId):
58     index = gg.getIndexTopology(aSubId, aMainId)
59     name = gg.getShapeTypeString(aSubId) + "_%d"%(index)
60     return name
61
62 def addArguments(aShape):
63     ListIOR = []
64     ListIOR = geom.GetReferencedObjects(aShape)
65
66     if aShape._get_StudyShapeId()!="":
67         father = salome.IDToSObject(aShape._get_StudyShapeId())
68
69         myBuilder.NewCommand()
70         if len(ListIOR) > 0:
71           Arg = myBuilder.NewObject(father)
72           A1 = myBuilder.FindOrCreateAttribute(Arg, "AttributeName");
73           ArgName = A1._narrow(SALOMEDS.AttributeName)
74           ArgName.SetValue("Arguments")
75           A2 = myBuilder.FindOrCreateAttribute(Arg, "AttributeSelectable");
76           SelAttr = A2._narrow(SALOMEDS.AttributeSelectable);
77           SelAttr.SetSelectable(0);
78         
79           OneObject = 0
80           for anIOR in ListIOR:
81              Shape = salome.orb.string_to_object(anIOR)
82              if Shape is not None:
83                 if Shape._get_StudyShapeId()!="":
84                    Obj = salome.IDToSObject(Shape._get_StudyShapeId())
85                    if Obj is not None:
86                            Obj1 = myBuilder.NewObject(Arg)
87                            myBuilder.Addreference(Obj1,Obj)
88                            OneObject = 1
89
90           if OneObject == 0:
91              myBuilder.RemoveObject(Arg)
92
93     myBuilder.CommitCommand()
94     return 1    
95
96 def addToStudy(aShape, aName):
97     myBuilder.NewCommand()
98     newObj = myBuilder.NewObject(father)
99     ior = salome.orb.object_to_string(aShape)
100     A1 = myBuilder.FindOrCreateAttribute(newObj, "AttributeIOR");
101     ObjIOR = A1._narrow(SALOMEDS.AttributeIOR)
102     ObjIOR.SetValue(ior)
103     A2 = myBuilder.FindOrCreateAttribute(newObj, "AttributeName");
104     ObjName = A2._narrow(SALOMEDS.AttributeName)
105     ObjName.SetValue(aName)
106     A3 = myBuilder.FindOrCreateAttribute(newObj, "AttributePixMap");
107     ObjPixmap = A3._narrow(SALOMEDS.AttributePixMap)
108     anIcon = gg.getShapeTypeIcon(ior);
109     ObjPixmap.SetPixMap(anIcon)
110     id = newObj.GetID()
111     aShape._set_StudyShapeId(id)
112     myBuilder.CommitCommand()
113
114     addArguments( aShape )
115
116 #NRI : BugID 1682 :     sg = SALOMEGUI_Swig()
117 #NRI : BugID 1682 :     sg.updateObjBrowser(0)
118 #    salome.sg.updateObjBrowser(0)
119     return id
120
121 def addToStudyInFather(aFather, aShape, aName):
122
123 #NRI : BugID 1682 :     sg = SALOMEGUI_Swig()
124     myBuilder.NewCommand()
125     newObj = myBuilder.NewObject( salome.IDToSObject(aFather._get_StudyShapeId()) )
126     ior = salome.orb.object_to_string(aShape)
127     A1 = myBuilder.FindOrCreateAttribute(newObj, "AttributeIOR");
128     ObjIOR = A1._narrow(SALOMEDS.AttributeIOR)
129     ObjIOR.SetValue(ior)
130     A2 = myBuilder.FindOrCreateAttribute(newObj, "AttributeName");
131     ObjName = A2._narrow(SALOMEDS.AttributeName)
132     ObjName.SetValue(aName)
133     A3 = myBuilder.FindOrCreateAttribute(newObj, "AttributePixMap");
134     ObjPixmap = A3._narrow(SALOMEDS.AttributePixMap)
135     anIcon = gg.getShapeTypeIcon(ior);
136     ObjPixmap.SetPixMap(anIcon)
137     id = newObj.GetID()
138     aShape._set_StudyShapeId(id)
139     myBuilder.CommitCommand()
140
141     addArguments( aShape )
142
143 #NRI : BugID 1682 :     sg.updateObjBrowser(0)
144 #    salome.sg.updateObjBrowser(0)
145     return id
146
147 # -----------------------------------------------------------------------------
148 # Create Geometry 2D
149 # -----------------------------------------------------------------------------
150
151 def MakeVertex(x,y,z):
152     anObj = geom.MakeVertex(x,y,z)
153     ior = salome.orb.object_to_string(anObj)
154     anObj._set_Name(ior)
155     return anObj
156
157 def MakeVector(p1,p2):
158     anObj = geom.MakeVector(p1,p2)
159     ior = salome.orb.object_to_string(anObj)
160     anObj._set_Name(ior)
161     return anObj
162
163 def MakeLine(p1,d1):
164     anObj = geom.MakeLine(p1,d1)
165     ior = salome.orb.object_to_string(anObj)
166     anObj._set_Name(ior)
167     return anObj
168
169 def MakeArc(p1,p2,p3):
170     anObj = geom.MakeArc(p1,p2,p3)
171     ior = salome.orb.object_to_string(anObj)
172     anObj._set_Name(ior)
173     return anObj
174
175 def MakeCircle(p1,d1,radius):  
176     anObj = geom.MakeCircle(p1,d1,radius)
177     ior = salome.orb.object_to_string(anObj)
178     anObj._set_Name(ior)
179     return anObj
180
181 def MakePlane(p1,d1,trimsize): 
182     anObj = geom.MakePlane(p1,d1,trimsize)
183     ior = salome.orb.object_to_string(anObj)
184     anObj._set_Name(ior)
185     return anObj
186
187 # -----------------------------------------------------------------------------
188 # Create Geometry 3D
189 # -----------------------------------------------------------------------------
190
191 def MakeBox(x1,y1,z1,x2,y2,z2):
192     anObj = geom.MakeBox(x1,y1,z1,x2,y2,z2)
193     ior = salome.orb.object_to_string(anObj)
194     anObj._set_Name(ior)
195     return anObj
196
197 def MakeCylinder(p1,d1,radius,height):
198     anObj = geom.MakeCylinder(p1,d1,radius,height)
199     ior = salome.orb.object_to_string(anObj)
200     anObj._set_Name(ior)
201     return anObj
202
203 def MakeSphere(x,y,z,radius):
204     anObj = geom.MakeSphere(x,y,z,radius)       
205     ior = salome.orb.object_to_string(anObj)
206     anObj._set_Name(ior)
207     return anObj
208
209 def MakeCone(p1,d1,radius1,radius2,height):
210     anObj = geom.MakeCone(p1,d1,radius1,radius2,height) 
211     ior = salome.orb.object_to_string(anObj)
212     anObj._set_Name(ior)
213     return anObj
214
215 def MakeTorus(p1,d1,major_radius,minor_radius):
216     anObj = geom.MakeTorus(p1,d1,major_radius,minor_radius)
217     ior = salome.orb.object_to_string(anObj)
218     anObj._set_Name(ior)
219     return anObj
220
221 # -----------------------------------------------------------------------------
222 # Create base objects
223 # -----------------------------------------------------------------------------
224
225 def MakeEdge(p1,p2):
226     anObj = geom.MakeEdge(p1,p2)
227     ior = salome.orb.object_to_string(anObj)
228     anObj._set_Name(ior)
229     return anObj
230
231 def MakeWire(ListShape):
232     anObj = geom.MakeWire(ListShape)
233     ior = salome.orb.object_to_string(anObj)
234     anObj._set_Name(ior)
235     return anObj
236
237 def MakeFace(aShapeWire,WantPlanarFace):
238     anObj = geom.MakeFace(aShapeWire,WantPlanarFace)
239     ior = salome.orb.object_to_string(anObj)
240     anObj._set_Name(ior)
241     return anObj
242
243 def MakeFaces(ListShape,WantPlanarFace):
244     anObj = geom.MakeFaces(ListShape,WantPlanarFace)
245     ior = salome.orb.object_to_string(anObj)
246     anObj._set_Name(ior)
247     return anObj
248
249 def MakeCompound(ListShape):
250     anObj = geom.MakeCompound(ListShape)
251     ior = salome.orb.object_to_string(anObj)
252     anObj._set_Name(ior)
253     return anObj
254
255 # -----------------------------------------------------------------------------
256 # Create advanced objects
257 # -----------------------------------------------------------------------------
258
259 def MakeCopy(aShape):
260     anObj = geom.MakeCopy(aShape)       
261     ior = salome.orb.object_to_string(anObj)
262     anObj._set_Name(ior)
263     return anObj
264
265 def MakePrism(baseShape,p1,p2):
266     anObj = geom.MakePrism(baseShape,p1,p2)
267     ior = salome.orb.object_to_string(anObj)
268     anObj._set_Name(ior)
269     return anObj
270
271 def MakeRevolution(aShape,axis,angle):    
272     anObj = geom.MakeRevolution(aShape,axis,angle)
273     ior = salome.orb.object_to_string(anObj)
274     anObj._set_Name(ior)
275     return anObj
276
277 def MakeFilling(aShape,mindeg,maxdeg,tol3d,tol2d,nbiter):
278     anObj = geom.MakeFilling(aShape,mindeg,maxdeg,tol3d,tol2d,nbiter)
279     ior = salome.orb.object_to_string(anObj)
280     anObj._set_Name(ior)
281     return anObj
282
283 def MakePipe(pathShape,baseShape):
284     anObj = geom.MakePipe(pathShape,baseShape)
285     ior = salome.orb.object_to_string(anObj)
286     anObj._set_Name(ior)
287     return anObj
288
289 def MakeSewing(ListShape,precision):
290     anObj = geom.MakeSewing(ListShape,precision)
291     ior = salome.orb.object_to_string(anObj)
292     anObj._set_Name(ior)
293     return anObj
294
295 # -----------------------------------------------------------------------------
296 # Boolean (Common, Cut, Fuse, Section)
297 # -----------------------------------------------------------------------------
298
299 def MakeBoolean(shape1,shape2,operation):
300     anObj = geom.MakeBoolean(shape1,shape2,operation)
301     ior = salome.orb.object_to_string(anObj)
302     anObj._set_Name(ior)
303     return anObj
304
305 # -----------------------------------------------------------------------------
306 # Transform objects
307 # -----------------------------------------------------------------------------
308
309 def MakeTranslation(aShape,x,y,z):
310     anObj = geom.MakeTranslation(aShape,x,y,z)  
311     ior = salome.orb.object_to_string(anObj)
312     anObj._set_Name(ior)
313     return anObj
314
315 def MakeRotation(aShape,axis,angle):
316     anObj = geom.MakeRotation(aShape,axis,angle)
317     ior = salome.orb.object_to_string(anObj)
318     anObj._set_Name(ior)
319     return anObj
320
321 def MakeScaleTransform(aShape,theCenterofScale,factor): 
322     anObj = geom.MakeScaleTransform(aShape,theCenterofScale,factor)
323     ior = salome.orb.object_to_string(anObj)
324     anObj._set_Name(ior)
325     return anObj
326
327 def MakeMirrorByPlane(aShape,aPlane):
328     anObj = geom.MakeMirrorByPlane(aShape,aPlane)
329     ior = salome.orb.object_to_string(anObj)
330     anObj._set_Name(ior)
331     return anObj
332
333 def OrientationChange(aShape):
334     anObj = geom.OrientationChange(aShape)
335     ior = salome.orb.object_to_string(anObj)
336     anObj._set_Name(ior)
337     return anObj
338
339 def MakeFillet(aShape,radius,ShapeType,ListShape):
340     anObj = geom.MakeFillet(aShape,radius,ShapeType,ListShape)
341     ior = salome.orb.object_to_string(anObj)
342     anObj._set_Name(ior)
343     return anObj
344
345 def MakeChamfer(aShape,d1,d2,ShapeType,ListShape):
346     anObj = geom.MakeChamfer(aShape,d1,d2,ShapeType,ListShape)
347     ior = salome.orb.object_to_string(anObj)
348     anObj._set_Name(ior)
349     return anObj
350
351 # -----------------------------------------------------------------------------
352 # Decompose objects
353 # -----------------------------------------------------------------------------
354
355 def SubShape(aShape,type,ListOfId):
356     anObj = geom.SubShape(aShape,type, ListOfId)        
357     ior = salome.orb.object_to_string(anObj)
358     anObj._set_Name(ior)
359     return anObj
360
361 def SubShapeAll(aShape,type):
362     ListObj = geom.SubShapeAll(aShape,type)
363     for anObj in ListObj :
364             ior = salome.orb.object_to_string(anObj)
365             anObj._set_Name(ior)
366     return ListObj
367
368 def SubShapeSorted(aShape,type,ListOfId):
369     anObj = geom.SubShapeSorted(aShape,type, ListOfId)  
370     ior = salome.orb.object_to_string(anObj)
371     anObj._set_Name(ior)
372     return anObj
373
374 def SubShapeAllSorted(aShape,type):
375     ListObj = geom.SubShapeAllSorted(aShape,type)
376     for anObj in ListObj :
377             ior = salome.orb.object_to_string(anObj)
378             anObj._set_Name(ior)
379     return ListObj
380
381 # -- enumeration ShapeType as a dictionary --
382 ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
383
384 def Partition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[], Limit=ShapeType["SHAPE"]):
385     anObj = geom.Partition(ListShapes, ListTools, ListKeepInside, ListRemoveInside, Limit);
386     ior = salome.orb.object_to_string(anObj)
387     anObj._set_Name(ior)
388     return anObj
389
390 def SuppressFaces(aShape,ListOfId):
391     anObj = geom.SuppressFaces(aShape,ListOfId)
392     ior = salome.orb.object_to_string(anObj)
393     anObj._set_Name(ior)
394     return anObj
395
396 def SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace):
397     anObj = geom.SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace)
398     ior = salome.orb.object_to_string(anObj)
399     anObj._set_Name(ior)
400     return anObj
401
402 # -----------------------------------------------------------------------------
403 # Patterns
404 # -----------------------------------------------------------------------------
405
406 def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
407     anObj = geom.MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes)
408     ior = salome.orb.object_to_string(anObj)
409     anObj._set_Name(ior)
410     return anObj
411
412 def MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2):
413     anObj = geom.MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2)
414     ior = salome.orb.object_to_string(anObj)
415     anObj._set_Name(ior)
416     return anObj
417
418 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
419     anObj = geom.MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes)
420     ior = salome.orb.object_to_string(anObj)
421     anObj._set_Name(ior)
422     return anObj
423
424 def MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2):
425     anObj = geom.MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2)
426     ior = salome.orb.object_to_string(anObj)
427     anObj._set_Name(ior)
428     return anObj
429
430 # -----------------------------------------------------------------------------
431 # Import objects
432 # -----------------------------------------------------------------------------
433
434 def ImportBREP(filename):
435     anObj = geom.ImportBREP(filename)
436     ior = salome.orb.object_to_string(anObj)
437     anObj._set_Name(ior)
438     return anObj
439
440 def ImportIGES(filename):
441     anObj = geom.ImportIGES(filename)
442     ior = salome.orb.object_to_string(anObj)
443     anObj._set_Name(ior)
444     return anObj
445
446 def ImportSTEP(filename):
447     anObj = geom.ImportSTEP(filename)
448     ior = salome.orb.object_to_string(anObj)
449     anObj._set_Name(ior)
450     return anObj
451
452 # -----------------------------------------------------------------------------
453 # Export objects
454 # -----------------------------------------------------------------------------
455 def ExportBREP(filename,aShape):
456     geom.ExportBREP(filename,aShape)
457
458 def ExportIGES(filename,aShape):
459     geom.ExportIGES(filename,aShape)
460
461 def ExportSTEP(filename,aShape):
462     geom.ExportSTEP(filename,aShape)
463
464 # -----------------------------------------------------------------------------
465 # Information objects
466 # -----------------------------------------------------------------------------
467
468 def MakeCDG(aShape):    
469     anObj = geom.MakeCDG(aShape)
470     ior = salome.orb.object_to_string(anObj)
471     anObj._set_Name(ior)
472     return anObj
473
474 def Archimede(aShape,weight,WaterDensity,MeshingDeflection):    
475     anObj = geom.Archimede(aShape,weight,WaterDensity,MeshingDeflection)
476     ior = salome.orb.object_to_string(anObj)
477     anObj._set_Name(ior)
478     return anObj
479
480 def CheckShape(aShape): 
481     Status = geom.CheckShape(aShape)
482     return Status