1 # GEOM GEOM_SWIG : binding of C++ omplementaion with Python
3 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
25 # Author : Paul RASCLE, EDF
31 #import SALOMEDS_Attributes_idl
33 #NRI : BugID 1682 : from libSALOME_Swig import *
35 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
36 geom.GetCurrentStudy(salome.myStudyId)
37 myBuilder = salome.myStudy.NewBuilder()
39 gg = salome.ImportComponentGUI("GEOM")
41 father = salome.myStudy.FindComponent("GEOM")
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)
53 # -----------------------------------------------------------------------------
55 # -----------------------------------------------------------------------------
57 def SubShapeName(aSubId, aMainId):
58 index = gg.getIndexTopology(aSubId, aMainId)
59 name = gg.getShapeTypeString(aSubId) + "_%d"%(index)
62 def addArguments(aShape):
64 ListIOR = geom.GetReferencedObjects(aShape)
66 if aShape._get_StudyShapeId()!="":
67 father = salome.IDToSObject(aShape._get_StudyShapeId())
69 myBuilder.NewCommand()
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);
81 Shape = salome.orb.string_to_object(anIOR)
83 if Shape._get_StudyShapeId()!="":
84 Obj = salome.IDToSObject(Shape._get_StudyShapeId())
86 Obj1 = myBuilder.NewObject(Arg)
87 myBuilder.Addreference(Obj1,Obj)
91 myBuilder.RemoveObject(Arg)
93 myBuilder.CommitCommand()
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)
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)
111 aShape._set_StudyShapeId(id)
112 myBuilder.CommitCommand()
114 addArguments( aShape )
116 #NRI : BugID 1682 : sg = SALOMEGUI_Swig()
117 #NRI : BugID 1682 : sg.updateObjBrowser(0)
118 # salome.sg.updateObjBrowser(0)
121 def addToStudyInFather(aFather, aShape, aName):
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)
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)
138 aShape._set_StudyShapeId(id)
139 myBuilder.CommitCommand()
141 addArguments( aShape )
143 #NRI : BugID 1682 : sg.updateObjBrowser(0)
144 # salome.sg.updateObjBrowser(0)
147 # -----------------------------------------------------------------------------
149 # -----------------------------------------------------------------------------
151 def MakeVertex(x,y,z):
152 anObj = geom.MakeVertex(x,y,z)
153 ior = salome.orb.object_to_string(anObj)
157 def MakeVector(p1,p2):
158 anObj = geom.MakeVector(p1,p2)
159 ior = salome.orb.object_to_string(anObj)
164 anObj = geom.MakeLine(p1,d1)
165 ior = salome.orb.object_to_string(anObj)
169 def MakeArc(p1,p2,p3):
170 anObj = geom.MakeArc(p1,p2,p3)
171 ior = salome.orb.object_to_string(anObj)
175 def MakeCircle(p1,d1,radius):
176 anObj = geom.MakeCircle(p1,d1,radius)
177 ior = salome.orb.object_to_string(anObj)
181 def MakePlane(p1,d1,trimsize):
182 anObj = geom.MakePlane(p1,d1,trimsize)
183 ior = salome.orb.object_to_string(anObj)
187 # -----------------------------------------------------------------------------
189 # -----------------------------------------------------------------------------
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)
197 def MakeCylinder(p1,d1,radius,height):
198 anObj = geom.MakeCylinder(p1,d1,radius,height)
199 ior = salome.orb.object_to_string(anObj)
203 def MakeSphere(x,y,z,radius):
204 anObj = geom.MakeSphere(x,y,z,radius)
205 ior = salome.orb.object_to_string(anObj)
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)
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)
221 # -----------------------------------------------------------------------------
222 # Create base objects
223 # -----------------------------------------------------------------------------
226 anObj = geom.MakeEdge(p1,p2)
227 ior = salome.orb.object_to_string(anObj)
231 def MakeWire(ListShape):
232 anObj = geom.MakeWire(ListShape)
233 ior = salome.orb.object_to_string(anObj)
237 def MakeFace(aShapeWire,WantPlanarFace):
238 anObj = geom.MakeFace(aShapeWire,WantPlanarFace)
239 ior = salome.orb.object_to_string(anObj)
243 def MakeCompound(ListShape):
244 anObj = geom.MakeCompound(ListShape)
245 ior = salome.orb.object_to_string(anObj)
249 # -----------------------------------------------------------------------------
250 # Create advanced objects
251 # -----------------------------------------------------------------------------
253 def MakeCopy(aShape):
254 anObj = geom.MakeCopy(aShape)
255 ior = salome.orb.object_to_string(anObj)
259 def MakePrism(baseShape,p1,p2):
260 anObj = geom.MakePrism(baseShape,p1,p2)
261 ior = salome.orb.object_to_string(anObj)
265 def MakeRevolution(aShape,axis,angle):
266 anObj = geom.MakeRevolution(aShape,axis,angle)
267 ior = salome.orb.object_to_string(anObj)
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)
277 def MakePipe(pathShape,baseShape):
278 anObj = geom.MakePipe(pathShape,baseShape)
279 ior = salome.orb.object_to_string(anObj)
283 def MakeSewing(ListShape,precision):
284 anObj = geom.MakeSewing(ListShape,precision)
285 ior = salome.orb.object_to_string(anObj)
289 # -----------------------------------------------------------------------------
290 # Boolean (Common, Cut, Fuse, Section)
291 # -----------------------------------------------------------------------------
293 def MakeBoolean(shape1,shape2,operation):
294 anObj = geom.MakeBoolean(shape1,shape2,operation)
295 ior = salome.orb.object_to_string(anObj)
299 # -----------------------------------------------------------------------------
301 # -----------------------------------------------------------------------------
303 def MakeTranslation(aShape,x,y,z):
304 anObj = geom.MakeTranslation(aShape,x,y,z)
305 ior = salome.orb.object_to_string(anObj)
309 def MakeRotation(aShape,axis,angle):
310 anObj = geom.MakeRotation(aShape,axis,angle)
311 ior = salome.orb.object_to_string(anObj)
315 def MakeScaleTransform(aShape,theCenterofScale,factor):
316 anObj = geom.MakeScaleTransform(aShape,theCenterofScale,factor)
317 ior = salome.orb.object_to_string(anObj)
321 def MakeMirrorByPlane(aShape,aPlane):
322 anObj = geom.MakeMirrorByPlane(aShape,aPlane)
323 ior = salome.orb.object_to_string(anObj)
327 def OrientationChange(aShape):
328 anObj = geom.OrientationChange(aShape)
329 ior = salome.orb.object_to_string(anObj)
333 def MakeFillet(aShape,radius,ShapeType,ListShape):
334 anObj = geom.MakeFillet(aShape,radius,ShapeType,ListShape)
335 ior = salome.orb.object_to_string(anObj)
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)
345 # -----------------------------------------------------------------------------
347 # -----------------------------------------------------------------------------
349 def SubShape(aShape,type,ListOfId):
350 anObj = geom.SubShape(aShape,type, ListOfId)
351 ior = salome.orb.object_to_string(anObj)
355 def SubShapeAll(aShape,type):
356 ListObj = geom.SubShapeAll(aShape,type)
357 for anObj in ListObj :
358 ior = salome.orb.object_to_string(anObj)
362 def SubShapeSorted(aShape,type,ListOfId):
363 anObj = geom.SubShapeSorted(aShape,type, ListOfId)
364 ior = salome.orb.object_to_string(anObj)
368 def SubShapeAllSorted(aShape,type):
369 ListObj = geom.SubShapeAllSorted(aShape,type)
370 for anObj in ListObj :
371 ior = salome.orb.object_to_string(anObj)
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}
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)
384 def SuppressFaces(aShape,ListOfId):
385 anObj = geom.SuppressFaces(aShape,ListOfId)
386 ior = salome.orb.object_to_string(anObj)
390 def SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace):
391 anObj = geom.SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace)
392 ior = salome.orb.object_to_string(anObj)
396 # -----------------------------------------------------------------------------
398 # -----------------------------------------------------------------------------
400 def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
401 anObj = geom.MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes)
402 ior = salome.orb.object_to_string(anObj)
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)
412 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
413 anObj = geom.MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes)
414 ior = salome.orb.object_to_string(anObj)
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)
424 # -----------------------------------------------------------------------------
426 # -----------------------------------------------------------------------------
428 def ImportBREP(filename):
429 anObj = geom.ImportBREP(filename)
430 ior = salome.orb.object_to_string(anObj)
434 def ImportIGES(filename):
435 anObj = geom.ImportIGES(filename)
436 ior = salome.orb.object_to_string(anObj)
440 def ImportSTEP(filename):
441 anObj = geom.ImportSTEP(filename)
442 ior = salome.orb.object_to_string(anObj)
446 # -----------------------------------------------------------------------------
448 # -----------------------------------------------------------------------------
449 def ExportBREP(filename,aShape):
450 geom.ExportBREP(filename,aShape)
452 def ExportIGES(filename,aShape):
453 geom.ExportIGES(filename,aShape)
455 def ExportSTEP(filename,aShape):
456 geom.ExportSTEP(filename,aShape)
458 # -----------------------------------------------------------------------------
459 # Information objects
460 # -----------------------------------------------------------------------------
463 anObj = geom.MakeCDG(aShape)
464 ior = salome.orb.object_to_string(anObj)
468 def Archimede(aShape,weight,WaterDensity,MeshingDeflection):
469 anObj = geom.Archimede(aShape,weight,WaterDensity,MeshingDeflection)
470 ior = salome.orb.object_to_string(anObj)
474 def CheckShape(aShape):
475 Status = geom.CheckShape(aShape)