Back to index

salome-geom  6.5.0
Classes | Functions | Variables
GEOM_PY.geomtools Namespace Reference

Classes

class  GeomStudyTools

Functions

def getGeompy
def TEST_createBox
def TEST_getGeomObjectSelected
def TEST_createAndDeleteShape

Variables

 GEOM = None
tuple logger = Logger("salome.geom.geomtools", color = termcolor.RED)
dictionary _geompys = {}
int ModeWireFrame = 0
int ModeShading = 1
 DisplayMode = ModeShading
list PreviewColor = [236,163,255]

Function Documentation

def GEOM_PY.geomtools.getGeompy (   studyId = None)
Return an object behaving exactly like geompy module, except that it is
associated with the study `studyId`. If `studyId` is :const:`None`, return
a pseudo geompy object for the current study.

Definition at line 42 of file geomtools.py.

00042 
00043 def getGeompy(studyId = None):
00044     """
00045     Return an object behaving exactly like geompy module, except that it is
00046     associated with the study `studyId`. If `studyId` is :const:`None`, return
00047     a pseudo geompy object for the current study.
00048     """
00049     # We can't use geompy module because it initializes GEOM with
00050     # salome.myStudy, which may not exist. So we use this trick to create
00051     # a pseudo geompy module. 
00052     salome.salome_init()
00053     if studyId is None:
00054         studyId = getActiveStudyId()
00055     if not _geompys.has_key(studyId):
00056         import geompyDC
00057         _geompys[studyId] = salome.lcc.FindOrLoadComponent("FactoryServer",
00058                                                            "GEOM")
00059         _geompys[studyId].ShapeType = geompyDC.ShapeType
00060         _geompys[studyId].GEOM = geompyDC.GEOM
00061         _geompys[studyId].kind = geompyDC.kind
00062         _geompys[studyId].info = geompyDC.info
00063         _geompys[studyId].PackData = geompyDC.PackData
00064         _geompys[studyId].ReadTexture = geompyDC.ReadTexture
00065         study = salome.myStudyManager.GetStudyByID(studyId)
00066         _geompys[studyId].init_geom(study)
00067     return _geompys[studyId]
00068 

Here is the caller graph for this function:

This test is a simple use case that illustrates how to create a
GEOM shape in a SALOME session (create the GEOM object, put in in
the study, and display the shape in a viewer) and delete a shape
from a SALOME session (erase the shape from the viewer, delete the
entry from the study, and finally destroy the underlying GEOM
object).

Definition at line 292 of file geomtools.py.

00292 
00293 def TEST_createAndDeleteShape():
00294     """
00295     This test is a simple use case that illustrates how to create a
00296     GEOM shape in a SALOME session (create the GEOM object, put in in
00297     the study, and display the shape in a viewer) and delete a shape
00298     from a SALOME session (erase the shape from the viewer, delete the
00299     entry from the study, and finally destroy the underlying GEOM
00300     object).
00301     """
00302     import salome
00303     salome.salome_init()
00304     study   = salome.myStudy
00305     studyId = salome.myStudyId
00306 
00307     from salome.geom import geomtools
00308     geompy = geomtools.getGeompy(studyId)
00309     
00310     from salome.kernel.studyedit import getStudyEditor
00311     studyEditor = getStudyEditor(studyId)
00312 
00313     gst = geomtools.GeomStudyTools(studyEditor)
00314 
00315     # --------------------------------------------------
00316     # Create a first shape (GEOM object)
00317     radius = 5
00318     length = 100
00319     cylinder = geompy.MakeCylinderRH(radius, length)
00320 
00321     # Register the shape in the study, at the root of the GEOM
00322     # folder. A name must be specified. The register operation
00323     # (addShapeToStudy) returns an identifier of the entry in the study.
00324     cylinderName = "cyl.r%s.l%s"%(radius,length)
00325     cylinderStudyEntry = gst.addShapeToStudy(cylinder, cylinderName)
00326 
00327     # Display the registered shape in a viewer
00328     gst.displayShapeByEntry(cylinderStudyEntry)
00329 
00330     # --------------------------------------------------
00331     # A second shape
00332     radius = 10
00333     sphere = geompy.MakeSphereR(radius)
00334     sphereName = "sph.r%s"%radius
00335     sphereStudyEntry = gst.addShapeToStudy(sphere, sphereName)
00336     gst.displayShapeByEntry(sphereStudyEntry)
00337 
00338     # --------------------------------------------------
00339     # This new shape is stored in the study, but in a specific
00340     # sub-folder, and is displayed in the viewer with a specific
00341     # color.
00342     length = 20
00343     box = geompy.MakeBoxDXDYDZ(length,length,length)
00344     boxName = "box.l%s"%length
00345     folderName = "boxset" 
00346     boxStudyEntry = gst.addShapeToStudy(box, boxName, folderName)
00347     gst.displayShapeByEntry(boxStudyEntry,PreviewColor)
00348 
00349     # --------------------------------------------------
00350     # In this example, we illustrate how to erase a shape (the sphere)
00351     # from the viewer. After this operation, the sphere is no longer
00352     # displayed but still exists in the study. You can then redisplay
00353     # it using the context menu of the SALOME object browser.
00354     gst.eraseShapeByEntry(sphereStudyEntry)
00355 
00356     # --------------------------------------------------
00357     # In this last example, we completly delete an object from the
00358     # SALOME session (erase from viewer, remove from study and finnaly
00359     # destroy the object). This is done by a simple call to
00360     # deleteShape().
00361     gst.deleteShape(cylinderStudyEntry)
00362 
00363     # --------------------------------------------------
00364     # At the end of the executioon of this test, you should have in
00365     # the SALOME session:
00366     # - the box, in a dedicated folder of the study, and displayed in the viewer
00367     # - the sphere, in the standard place of the study, and not displayed 
00368 
00369     # If you comment the deleteShape line, you should see the cylinder
00370     # in the study and displayed in the viewer. 

Definition at line 279 of file geomtools.py.

00279 
00280 def TEST_createBox():
00281     geompy = getGeompy()
00282     box = geompy.MakeBoxDXDYDZ(200, 200, 200)
00283     geompy.addToStudy( box, 'box' )    
00284     if salome.sg.hasDesktop():
00285         salome.sg.updateObjBrowser(1)
00286 

Here is the call graph for this function:

Definition at line 287 of file geomtools.py.

00287 
00288 def TEST_getGeomObjectSelected():
00289     tool = GeomStudyTools()
00290     myGeomObject = tool.getGeomObjectSelected()
00291     print myGeomObject


Variable Documentation

dictionary GEOM_PY.geomtools._geompys = {}

Definition at line 40 of file geomtools.py.

Definition at line 71 of file geomtools.py.

Definition at line 27 of file geomtools.py.

tuple GEOM_PY.geomtools.logger = Logger("salome.geom.geomtools", color = termcolor.RED)

Definition at line 31 of file geomtools.py.

Definition at line 70 of file geomtools.py.

Definition at line 69 of file geomtools.py.

list GEOM_PY.geomtools.PreviewColor = [236,163,255]

Definition at line 72 of file geomtools.py.