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