From: boulant Date: Thu, 27 Oct 2011 15:56:38 +0000 (+0000) Subject: IMP: extends the class GeomStudyTools with function to retrieve geom objects selected... X-Git-Tag: V6_4_0a1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=502948884b74e4a70b60633a21311466bd8d8614;p=modules%2Fgeom.git IMP: extends the class GeomStudyTools with function to retrieve geom objects selected in the browser (Note that the equivalent exists for SMESH objects in the SMESH module, see salome.smesh.guihelper.py) --- diff --git a/src/GEOM_PY/geomtools.py b/src/GEOM_PY/geomtools.py index 23642ced0..9f10c4c26 100644 --- a/src/GEOM_PY/geomtools.py +++ b/src/GEOM_PY/geomtools.py @@ -31,6 +31,8 @@ from salome.kernel import termcolor logger = Logger("salome.geom.geomtools", color = termcolor.RED) from salome.kernel.studyedit import getActiveStudyId, getStudyEditor +from salome.gui.helper import getSObjectSelected +from salome.kernel.services import IDToObject _geompys = {} @@ -61,6 +63,10 @@ def getGeompy(studyId = None): return _geompys[studyId] +ModeWireFrame = 0 +ModeShading = 1 +DisplayMode=ModeShading + class GeomStudyTools: """ This class provides several methods to manipulate geom objects in Salome @@ -108,8 +114,60 @@ class GeomStudyTools: if shape: geomgui = salome.ImportComponentGUI("GEOM") geomgui.createAndDisplayGO(entry) - geomgui.setDisplayMode(entry, 1) + geomgui.setDisplayMode(entry, DisplayMode) if color is not None: geomgui.setColor(entry, color[0], color[1], color[2]) return True return False + + def getGeomObjectSelected(self): + ''' + Returns the GEOM object currently selected in the objects browser. + ''' + sobject, entry = getSObjectSelected() + geomObject = self.getGeomObjectFromEntry(entry) + return geomObject + + def getGeomObjectFromEntry(self,entry): + ''' + Returns the GEOM object associated to the specified entry, + (the entry is the identifier of an item in the active study) + ''' + if entry is None: + return None + geomObject=IDToObject(entry, self.editor.study) + return geomObject._narrow(GEOM.GEOM_Object) + +# +# ================================================================== +# Use cases and demo functions +# ================================================================== +# + +# How to test? +# 1. Run a SALOME application including GEOM, and create a new study +# 2. In the console, enter: +# >>> from salome.geom import geomtools +# >>> geomtools.TEST_createBox() +# 3. Select the object named "box" in the browser +# 4. In the console, enter: +# >>> geomtools.TEST_getGeomObjectSelected() + +def TEST_createBox(): + geompy = getGeompy() + box = geompy.MakeBoxDXDYDZ(200, 200, 200) + geompy.addToStudy( box, 'box' ) + if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(1) + + +def TEST_getGeomObjectSelected(): + tool = GeomStudyTools() + myGeomObject = tool.getGeomObjectSelected() + print myGeomObject + +if __name__ == "__main__": + TEST_getGeomObjectSelected() + + +