Back to index

salome-geom  6.5.0
Public Member Functions | Public Attributes
GEOM_PY.geomtools.GeomStudyTools Class Reference

List of all members.

Public Member Functions

def __init__
def addShapeToStudy
def removeFromStudy
def displayShapeByName
def displayShapeByEntry
def eraseShapeByEntry
def deleteShape
def getGeomObjectSelected
def getGeomObjectFromEntry

Public Attributes

 editor

Detailed Description

This class provides several methods to manipulate geom objects in Salome
study. The parameter `studyEditor` defines a
:class:`~salome.kernel.studyedit.StudyEditor` object used to access the study. If
:const:`None`, the method returns a :class:`~salome.kernel.studyedit.StudyEditor`
object on the current study.

.. attribute:: editor

   This instance attribute contains the underlying
   :class:`~salome.kernel.studyedit.StudyEditor` object. It can be used to access
   the study but the attribute itself should not be modified.

Definition at line 74 of file geomtools.py.


Constructor & Destructor Documentation

def GEOM_PY.geomtools.GeomStudyTools.__init__ (   self,
  studyEditor = None 
)

Definition at line 90 of file geomtools.py.

00090 
00091     def __init__(self, studyEditor = None):
00092         global GEOM
00093         if GEOM is None:
00094             GEOM = __import__("GEOM")
00095         if studyEditor is None:
00096             studyEditor = getStudyEditor()
00097         self.editor = studyEditor


Member Function Documentation

def GEOM_PY.geomtools.GeomStudyTools.addShapeToStudy (   self,
  shape,
  shapeName,
  folderName = None 
)
Add a GEOM shape in the study. It returns the associated entry
that corresponds to the identifier of the entry in the study. This
entry can be used to retrieve an object in the study. A folderName
can be specified. In this case, a folder with this name is first
created in the Geometry part of the study, and the shape study
object is stored in this folder of the study. 

:type   shape: GEOM object
:param  shape: the GEOM object defining the shape

:type   shapeName: string
:param  shapeName: the name for this shape in the study 

:type   folderName: string
:param  folderName: the name of a folder in the GEOM part of the study

Definition at line 101 of file geomtools.py.

00101 
00102     def addShapeToStudy(self, shape,shapeName,folderName=None):
00103         """
00104         Add a GEOM shape in the study. It returns the associated entry
00105         that corresponds to the identifier of the entry in the study. This
00106         entry can be used to retrieve an object in the study. A folderName
00107         can be specified. In this case, a folder with this name is first
00108         created in the Geometry part of the study, and the shape study
00109         object is stored in this folder of the study. 
00110 
00111         :type   shape: GEOM object
00112         :param  shape: the GEOM object defining the shape
00113 
00114         :type   shapeName: string
00115         :param  shapeName: the name for this shape in the study 
00116 
00117         :type   folderName: string
00118         :param  folderName: the name of a folder in the GEOM part of the study
00119         """
00120         study   = self.editor.study
00121         studyId = study._get_StudyId()
00122         geompy  = getGeompy(studyId)
00123 
00124         if folderName is None:
00125             # Insert the shape in the study by the standard way
00126             entry = geompy.addToStudy( shape, shapeName )
00127         else:
00128             # A folder name has been specified to embed this shape. Find
00129             # or create a folder with this name in the Geometry study, and
00130             # then store the shape in this folder.
00131             geomStudyFolder = self.editor.findOrCreateComponent("GEOM")
00132             shapeStudyFolder = self.editor.findOrCreateItem(geomStudyFolder,folderName)
00133             
00134             shapeIor = salome.orb.object_to_string(shape)
00135             geomgui = salome.ImportComponentGUI("GEOM")
00136             shapeIcon = geomgui.getShapeTypeIcon(shapeIor)
00137             
00138             shapeStudyObject = self.editor.createItem(shapeStudyFolder,
00139                                                       name=shapeName,
00140                                                       IOR=shapeIor,
00141                                                       icon=shapeIcon)
00142             entry = shapeStudyObject.GetID()
00143 
00144         return entry

Here is the call graph for this function:

def GEOM_PY.geomtools.GeomStudyTools.deleteShape (   self,
  shapeStudyEntry 
)
This completly deletes a geom shape.

WARNING: please be aware that to delete a geom object, you have
three operations to perform:

1. erase the shape from the viewers
2. remove the entry from the study
3. destroy the underlying geom object

Definition at line 228 of file geomtools.py.

00228 
00229     def deleteShape(self,shapeStudyEntry):
00230         """
00231         This completly deletes a geom shape.
00232         
00233         WARNING: please be aware that to delete a geom object, you have
00234         three operations to perform:
00235         
00236         1. erase the shape from the viewers
00237         2. remove the entry from the study
00238         3. destroy the underlying geom object
00239         """
00240         self.eraseShapeByEntry(shapeStudyEntry)
00241         shape = self.removeFromStudy(shapeStudyEntry)
00242         shape.Destroy()

Here is the call graph for this function:

def GEOM_PY.geomtools.GeomStudyTools.displayShapeByEntry (   self,
  shapeStudyEntry,
  color = None,
  fit = True 
)
Display the geometrical shape whose entry is given by
`entry`. You should prefer use this function instead of the
displayShapeByName which can have an unpredictible behavior in
the case where several objects exist with the same name in the
study.

Definition at line 193 of file geomtools.py.

00193 
00194     def displayShapeByEntry(self, shapeStudyEntry, color = None, fit=True):
00195         """
00196         Display the geometrical shape whose entry is given by
00197         `entry`. You should prefer use this function instead of the
00198         displayShapeByName which can have an unpredictible behavior in
00199         the case where several objects exist with the same name in the
00200         study.
00201         """
00202         geomgui = salome.ImportComponentGUI("GEOM")
00203         if fit:
00204             geomgui.createAndDisplayFitAllGO(shapeStudyEntry)
00205         else:
00206             geomgui.createAndDisplayGO(shapeStudyEntry)
00207         geomgui.setDisplayMode(shapeStudyEntry, DisplayMode)
00208         if color is not None:
00209             geomgui.setColor(shapeStudyEntry, color[0], color[1], color[2])
00210         return True

Here is the caller graph for this function:

def GEOM_PY.geomtools.GeomStudyTools.displayShapeByName (   self,
  shapeName,
  color = None,
  fit = True 
)
Display the geometrical shape whose name in the study is `shapeName`.

:type   shapeName: string
:param  shapeName: name of the geometrical shape

:type   color: tuple (triplet)
:param  color: RGB components of the color of the shape

:return: True if the shape was found, False otherwise

Definition at line 169 of file geomtools.py.

00169 
00170     def displayShapeByName(self, shapeName, color = None, fit=True):
00171         """
00172         Display the geometrical shape whose name in the study is `shapeName`.
00173         
00174         :type   shapeName: string
00175         :param  shapeName: name of the geometrical shape
00176         
00177         :type   color: tuple (triplet)
00178         :param  color: RGB components of the color of the shape
00179         
00180         :return: True if the shape was found, False otherwise
00181         """
00182         logger.debug("displayShapeByName in PAL: %s with color %s" %
00183                      (shapeName, color))
00184         listSO = self.editor.study.FindObjectByName(shapeName, "GEOM")
00185         for sObj in listSO:
00186             entry = sObj.GetID()
00187             geomObj = self.editor.getOrLoadObject(sObj)
00188             if geomObj:
00189                 shape = geomObj._narrow(GEOM.GEOM_Object)
00190                 if shape:
00191                     return self.displayShapeByEntry(entry,color,fit)
00192         return False

Here is the call graph for this function:

def GEOM_PY.geomtools.GeomStudyTools.eraseShapeByEntry (   self,
  shapeStudyEntry 
)
Erase the geometrical shape whose entry is given by
`entry`. Please note that the shape is just erased from the
viewer. The associated study object still exists in the study,
and the geom object still exists in the GEOM engine.

Definition at line 211 of file geomtools.py.

00211 
00212     def eraseShapeByEntry(self, shapeStudyEntry):
00213         """
00214         Erase the geometrical shape whose entry is given by
00215         `entry`. Please note that the shape is just erased from the
00216         viewer. The associated study object still exists in the study,
00217         and the geom object still exists in the GEOM engine.
00218         """
00219         geomgui = salome.ImportComponentGUI("GEOM")
00220         eraseFromAllWindows=True
00221         geomgui.eraseGO(shapeStudyEntry,eraseFromAllWindows)
00222         return True
00223 

Here is the caller graph for this function:

Returns the GEOM object associated to the specified entry,
(the entry is the identifier of an item in the active study)

Definition at line 254 of file geomtools.py.

00254 
00255     def getGeomObjectFromEntry(self,entry):
00256         '''
00257         Returns the GEOM object associated to the specified entry,
00258         (the entry is the identifier of an item in the active study)
00259         '''
00260         if entry is None:
00261             return None
00262         geomObject=IDToObject(entry, self.editor.study)
00263         return geomObject._narrow(GEOM.GEOM_Object)
00264 
00265 #
00266 # ==================================================================
00267 # Use cases and demo functions
00268 # ==================================================================
00269 #
00270 
00271 # How to test?
00272 # 1. Run a SALOME application including GEOM, and create a new study
00273 # 2. In the console, enter:
00274 #    >>> from salome.geom import geomtools
00275 #    >>> geomtools.TEST_createBox()
00276 # 3. Select the object named "box" in the browser
00277 # 4. In the console, enter:
00278 #    >>> geomtools.TEST_getGeomObjectSelected()

Here is the caller graph for this function:

Returns the GEOM object currently selected in the objects browser.

Definition at line 246 of file geomtools.py.

00246 
00247     def getGeomObjectSelected(self):
00248         '''
00249         Returns the GEOM object currently selected in the objects browser.
00250         '''
00251         sobject, entry = guihelper.getSObjectSelected()
00252         geomObject = self.getGeomObjectFromEntry(entry)
00253         return geomObject

Here is the call graph for this function:

def GEOM_PY.geomtools.GeomStudyTools.removeFromStudy (   self,
  shapeStudyEntry 
)
This removes the specified entry from the study. Note that this
operation does not destroy the underlying GEOM object, neither
erase the drawing in the viewer.
The underlying GEOM object is returned (so that it can be destroyed)

Definition at line 145 of file geomtools.py.

00145 
00146     def removeFromStudy(self, shapeStudyEntry):
00147         """
00148         This removes the specified entry from the study. Note that this
00149         operation does not destroy the underlying GEOM object, neither
00150         erase the drawing in the viewer.
00151         The underlying GEOM object is returned (so that it can be destroyed)
00152         """
00153         study = self.editor.study
00154         studyId = study._get_StudyId()
00155         shape = self.getGeomObjectFromEntry(shapeStudyEntry)    
00156         studyObject = IDToSObject(shapeStudyEntry)
00157         self.editor.removeItem(studyObject,True)
00158         return shape

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 96 of file geomtools.py.


The documentation for this class was generated from the following file: