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 MakeFaces(ListShape,WantPlanarFace):
244 anObj = geom.MakeFaces(ListShape,WantPlanarFace)
245 ior = salome.orb.object_to_string(anObj)
249 def MakeCompound(ListShape):
250 anObj = geom.MakeCompound(ListShape)
251 ior = salome.orb.object_to_string(anObj)
255 # -----------------------------------------------------------------------------
256 # Create advanced objects
257 # -----------------------------------------------------------------------------
259 def MakeCopy(aShape):
260 anObj = geom.MakeCopy(aShape)
261 ior = salome.orb.object_to_string(anObj)
265 def MakePrism(baseShape,p1,p2):
266 anObj = geom.MakePrism(baseShape,p1,p2)
267 ior = salome.orb.object_to_string(anObj)
271 def MakeRevolution(aShape,axis,angle):
272 anObj = geom.MakeRevolution(aShape,axis,angle)
273 ior = salome.orb.object_to_string(anObj)
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)
283 def MakePipe(pathShape,baseShape):
284 anObj = geom.MakePipe(pathShape,baseShape)
285 ior = salome.orb.object_to_string(anObj)
289 def MakeSewing(ListShape,precision):
290 anObj = geom.MakeSewing(ListShape,precision)
291 ior = salome.orb.object_to_string(anObj)
295 # -----------------------------------------------------------------------------
296 # Boolean (Common, Cut, Fuse, Section)
297 # -----------------------------------------------------------------------------
299 def MakeBoolean(shape1,shape2,operation):
300 anObj = geom.MakeBoolean(shape1,shape2,operation)
301 ior = salome.orb.object_to_string(anObj)
305 # -----------------------------------------------------------------------------
307 # -----------------------------------------------------------------------------
309 def MakeTranslation(aShape,x,y,z):
310 anObj = geom.MakeTranslation(aShape,x,y,z)
311 ior = salome.orb.object_to_string(anObj)
315 def MakeRotation(aShape,axis,angle):
316 anObj = geom.MakeRotation(aShape,axis,angle)
317 ior = salome.orb.object_to_string(anObj)
321 def MakeScaleTransform(aShape,theCenterofScale,factor):
322 anObj = geom.MakeScaleTransform(aShape,theCenterofScale,factor)
323 ior = salome.orb.object_to_string(anObj)
327 def MakeMirrorByPlane(aShape,aPlane):
328 anObj = geom.MakeMirrorByPlane(aShape,aPlane)
329 ior = salome.orb.object_to_string(anObj)
333 def OrientationChange(aShape):
334 anObj = geom.OrientationChange(aShape)
335 ior = salome.orb.object_to_string(anObj)
339 def MakeFillet(aShape,radius,ShapeType,ListShape):
340 anObj = geom.MakeFillet(aShape,radius,ShapeType,ListShape)
341 ior = salome.orb.object_to_string(anObj)
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)
351 # -----------------------------------------------------------------------------
353 # -----------------------------------------------------------------------------
355 def SubShape(aShape,type,ListOfId):
356 anObj = geom.SubShape(aShape,type, ListOfId)
357 ior = salome.orb.object_to_string(anObj)
361 def SubShapeAll(aShape,type):
362 ListObj = geom.SubShapeAll(aShape,type)
363 for anObj in ListObj :
364 ior = salome.orb.object_to_string(anObj)
368 def SubShapeSorted(aShape,type,ListOfId):
369 anObj = geom.SubShapeSorted(aShape,type, ListOfId)
370 ior = salome.orb.object_to_string(anObj)
374 def SubShapeAllSorted(aShape,type):
375 ListObj = geom.SubShapeAllSorted(aShape,type)
376 for anObj in ListObj :
377 ior = salome.orb.object_to_string(anObj)
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}
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)
390 def SuppressFaces(aShape,ListOfId):
391 anObj = geom.SuppressFaces(aShape,ListOfId)
392 ior = salome.orb.object_to_string(anObj)
396 def SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace):
397 anObj = geom.SuppressHole(aShape,ListOfFace,ListOfWire,ListOfEndFace)
398 ior = salome.orb.object_to_string(anObj)
402 # -----------------------------------------------------------------------------
404 # -----------------------------------------------------------------------------
406 def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
407 anObj = geom.MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes)
408 ior = salome.orb.object_to_string(anObj)
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)
418 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
419 anObj = geom.MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes)
420 ior = salome.orb.object_to_string(anObj)
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)
430 # -----------------------------------------------------------------------------
432 # -----------------------------------------------------------------------------
434 def ImportBREP(filename):
435 anObj = geom.ImportBREP(filename)
436 ior = salome.orb.object_to_string(anObj)
440 def ImportIGES(filename):
441 anObj = geom.ImportIGES(filename)
442 ior = salome.orb.object_to_string(anObj)
446 def ImportSTEP(filename):
447 anObj = geom.ImportSTEP(filename)
448 ior = salome.orb.object_to_string(anObj)
452 # -----------------------------------------------------------------------------
454 # -----------------------------------------------------------------------------
455 def ExportBREP(filename,aShape):
456 geom.ExportBREP(filename,aShape)
458 def ExportIGES(filename,aShape):
459 geom.ExportIGES(filename,aShape)
461 def ExportSTEP(filename,aShape):
462 geom.ExportSTEP(filename,aShape)
464 # -----------------------------------------------------------------------------
465 # Information objects
466 # -----------------------------------------------------------------------------
469 anObj = geom.MakeCDG(aShape)
470 ior = salome.orb.object_to_string(anObj)
474 def Archimede(aShape,weight,WaterDensity,MeshingDeflection):
475 anObj = geom.Archimede(aShape,weight,WaterDensity,MeshingDeflection)
476 ior = salome.orb.object_to_string(anObj)
480 def CheckShape(aShape):
481 Status = geom.CheckShape(aShape)