Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/geom.git] / 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", "Geometry")
36 geom.GetCurrentStudy(salome.myStudyId)
37 myBuilder = salome.myStudy.NewBuilder()
38
39 gg = salome.ImportComponentGUI("Geometry")
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("Geometry")
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 MakeCompound(ListShape):
244     anObj = geom.MakeCompound(ListShape)
245     ior = salome.orb.object_to_string(anObj)
246     anObj._set_Name(ior)
247     return anObj
248
249 # -----------------------------------------------------------------------------
250 # Create advanced objects
251 # -----------------------------------------------------------------------------
252
253 def MakeCopy(aShape):
254     anObj = geom.MakeCopy(aShape)       
255     ior = salome.orb.object_to_string(anObj)
256     anObj._set_Name(ior)
257     return anObj
258
259 def MakePrism(baseShape,p1,p2):
260     anObj = geom.MakePrism(baseShape,p1,p2)
261     ior = salome.orb.object_to_string(anObj)
262     anObj._set_Name(ior)
263     return anObj
264
265 def MakeRevolution(aShape,axis,angle):    
266     anObj = geom.MakeRevolution(aShape,axis,angle)
267     ior = salome.orb.object_to_string(anObj)
268     anObj._set_Name(ior)
269     return anObj
270
271 def MakeFilling(aShape,mindeg,maxdeg,tol3d,tol2d,nbiter):
272     anObj = geom.MakeFilling(aShape,mindeg,maxdeg,tol3d,tol2d,nbiter)
273     ior = salome.orb.object_to_string(anObj)
274     anObj._set_Name(ior)
275     return anObj
276
277 def MakePipe(pathShape,baseShape):
278     anObj = geom.MakePipe(pathShape,baseShape)
279     ior = salome.orb.object_to_string(anObj)
280     anObj._set_Name(ior)
281     return anObj
282
283 def MakeSewing(ListShape,precision):
284     anObj = geom.MakeSewing(ListShape,precision)
285     ior = salome.orb.object_to_string(anObj)
286     anObj._set_Name(ior)
287     return anObj
288
289 # -----------------------------------------------------------------------------
290 # Boolean (Common, Cut, Fuse, Section)
291 # -----------------------------------------------------------------------------
292
293 def MakeBoolean(shape1,shape2,operation):
294     anObj = geom.MakeBoolean(shape1,shape2,operation)
295     ior = salome.orb.object_to_string(anObj)
296     anObj._set_Name(ior)
297     return anObj
298
299 # -----------------------------------------------------------------------------
300 # Transform objects
301 # -----------------------------------------------------------------------------
302
303 def MakeTranslation(aShape,x,y,z):
304     anObj = geom.MakeTranslation(aShape,x,y,z)  
305     ior = salome.orb.object_to_string(anObj)
306     anObj._set_Name(ior)
307     return anObj
308
309 def MakeRotation(aShape,axis,angle):
310     anObj = geom.MakeRotation(aShape,axis,angle)
311     ior = salome.orb.object_to_string(anObj)
312     anObj._set_Name(ior)
313     return anObj
314
315 def MakeScaleTransform(aShape,theCenterofScale,factor): 
316     anObj = geom.MakeScaleTransform(aShape,theCenterofScale,factor)
317     ior = salome.orb.object_to_string(anObj)
318     anObj._set_Name(ior)
319     return anObj
320
321 def MakeMirrorByPlane(aShape,aPlane):
322     anObj = geom.MakeMirrorByPlane(aShape,aPlane)
323     ior = salome.orb.object_to_string(anObj)
324     anObj._set_Name(ior)
325     return anObj
326
327 def OrientationChange(aShape):
328     anObj = geom.OrientationChange(aShape)
329     ior = salome.orb.object_to_string(anObj)
330     anObj._set_Name(ior)
331     return anObj
332
333 def MakeFillet(aShape,radius,ShapeType,ListShape):
334     anObj = geom.MakeFillet(aShape,radius,ShapeType,ListShape)
335     ior = salome.orb.object_to_string(anObj)
336     anObj._set_Name(ior)
337     return anObj
338
339 def MakeChamfer(aShape,d1,d2,ShapeType,ListShape):
340     anObj = geom.MakeChamfer(aShape,d1,d2,ShapeType,ListShape)
341     ior = salome.orb.object_to_string(anObj)
342     anObj._set_Name(ior)
343     return anObj
344
345 # -----------------------------------------------------------------------------
346 # Decompose objects
347 # -----------------------------------------------------------------------------
348
349 def SubShape(aShape,type,ListOfId):
350     anObj = geom.SubShape(aShape,type, ListOfId)        
351     ior = salome.orb.object_to_string(anObj)
352     anObj._set_Name(ior)
353     return anObj
354
355 def SubShapeAll(aShape,type):
356     ListObj = geom.SubShapeAll(aShape,type)
357     for anObj in ListObj :
358             ior = salome.orb.object_to_string(anObj)
359             anObj._set_Name(ior)
360     return ListObj
361
362 def SubShapeSorted(aShape,type,ListOfId):
363     anObj = geom.SubShapeSorted(aShape,type, ListOfId)  
364     ior = salome.orb.object_to_string(anObj)
365     anObj._set_Name(ior)
366     return anObj
367
368 def SubShapeAllSorted(aShape,type):
369     ListObj = geom.SubShapeAllSorted(aShape,type)
370     for anObj in ListObj :
371             ior = salome.orb.object_to_string(anObj)
372             anObj._set_Name(ior)
373     return ListObj
374
375 # -- enumeration ShapeType as a dictionary --
376 ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
377
378 def Partition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[], Limit=ShapeType["SHAPE"]):
379     anObj = geom.Partition(ListShapes, ListTools, ListKeepInside, ListRemoveInside, Limit);
380     ior = salome.orb.object_to_string(anObj)
381     anObj._set_Name(ior)
382     return anObj
383
384 def SuppressFaces(aShape,ListOfId):
385     anObj = geom.SuppressFaces(aShape,ListOfId)
386     ior = salome.orb.object_to_string(anObj)
387     anObj._set_Name(ior)
388     return anObj
389
390 def SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace):
391     anObj = geom.SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace)
392     ior = salome.orb.object_to_string(anObj)
393     anObj._set_Name(ior)
394     return anObj
395
396 # -----------------------------------------------------------------------------
397 # Patterns
398 # -----------------------------------------------------------------------------
399
400 def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
401     anObj = geom.MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes)
402     ior = salome.orb.object_to_string(anObj)
403     anObj._set_Name(ior)
404     return anObj
405
406 def MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2):
407     anObj = geom.MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2)
408     ior = salome.orb.object_to_string(anObj)
409     anObj._set_Name(ior)
410     return anObj
411
412 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
413     anObj = geom.MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes)
414     ior = salome.orb.object_to_string(anObj)
415     anObj._set_Name(ior)
416     return anObj
417
418 def MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2):
419     anObj = geom.MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2)
420     ior = salome.orb.object_to_string(anObj)
421     anObj._set_Name(ior)
422     return anObj
423
424 # -----------------------------------------------------------------------------
425 # Import objects
426 # -----------------------------------------------------------------------------
427
428 def ImportBREP(filename):
429     anObj = geom.ImportBREP(filename)
430     ior = salome.orb.object_to_string(anObj)
431     anObj._set_Name(ior)
432     return anObj
433
434 def ImportIGES(filename):
435     anObj = geom.ImportIGES(filename)
436     ior = salome.orb.object_to_string(anObj)
437     anObj._set_Name(ior)
438     return anObj
439
440 def ImportSTEP(filename):
441     anObj = geom.ImportSTEP(filename)
442     ior = salome.orb.object_to_string(anObj)
443     anObj._set_Name(ior)
444     return anObj
445
446 # -----------------------------------------------------------------------------
447 # Export objects
448 # -----------------------------------------------------------------------------
449 def ExportBREP(filename,aShape):
450     geom.ExportBREP(filename,aShape)
451
452 def ExportIGES(filename,aShape):
453     geom.ExportIGES(filename,aShape)
454
455 def ExportSTEP(filename,aShape):
456     geom.ExportSTEP(filename,aShape)
457
458 # -----------------------------------------------------------------------------
459 # Information objects
460 # -----------------------------------------------------------------------------
461
462 def MakeCDG(aShape):    
463     anObj = geom.MakeCDG(aShape)
464     ior = salome.orb.object_to_string(anObj)
465     anObj._set_Name(ior)
466     return anObj
467
468 def Archimede(aShape,weight,WaterDensity,MeshingDeflection):    
469     anObj = geom.Archimede(aShape,weight,WaterDensity,MeshingDeflection)
470     ior = salome.orb.object_to_string(anObj)
471     anObj._set_Name(ior)
472     return anObj
473
474 def CheckShape(aShape): 
475     Status = geom.CheckShape(aShape)
476     return Status