From: gdd Date: Thu, 7 Jun 2012 11:22:17 +0000 (+0000) Subject: Demo plugins are activated only if GEOM and SMESH module are present X-Git-Tag: B4WheelZoom~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6b0ebf5a8f2894a9f0f496849fb9e0e309495b60;p=modules%2Fgui.git Demo plugins are activated only if GEOM and SMESH module are present --- diff --git a/src/SalomeApp/pluginsdemo/salome_plugins.py b/src/SalomeApp/pluginsdemo/salome_plugins.py index bf8563599..57a94fef0 100755 --- a/src/SalomeApp/pluginsdemo/salome_plugins.py +++ b/src/SalomeApp/pluginsdemo/salome_plugins.py @@ -22,226 +22,232 @@ import salome_pluginsmanager DEMO_IS_ACTIVATED=True - -# ------------------------------------------------------------------------- -# Example 1: creation of basic objects. -# The plugin function is implemented here and declared in the pluginsmanager. -# -import salome - -def trihedron(context): - import geompy - - # Intialize the geompy factory with the active study - activeStudy = context.study - geompy.init_geom(activeStudy) - - # Create the objects - Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) - Vy = geompy.MakeVectorDXDYDZ(0, 10, 0) - Vz = geompy.MakeVectorDXDYDZ(0, 0, 10) - origin = geompy.MakeVertex(0, 0, 0) - - # Register the objects in the active study - geompy.addToStudy( Vx, "Vx" ) - geompy.addToStudy( Vy, "Vy" ) - geompy.addToStudy( Vz, "Vz" ) - geompy.addToStudy( origin, "origin" ) - -if DEMO_IS_ACTIVATED: - salome_pluginsmanager.AddFunction('O,Vx,Vy,Vz', - 'Creates the trihedron', - trihedron) - - -# ------------------------------------------------------------------------- -# Example 1 bis: creation of basic objects and automatic display -def trihedron_withdisplay(context): - import geompy - - # Intialize the geompy factory with the active study - activeStudy = context.study - geompy.init_geom(activeStudy) - - # Create the objects - Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) - Vy = geompy.MakeVectorDXDYDZ(0, 10, 0) - Vz = geompy.MakeVectorDXDYDZ(0, 0, 10) - origin = geompy.MakeVertex(0, 0, 0) - - # Register the objects in the active study - entries=[] - entries.append(geompy.addToStudy( Vx, "Vx" )) - entries.append(geompy.addToStudy( Vy, "Vy" )) - entries.append(geompy.addToStudy( Vz, "Vz" )) - entries.append(geompy.addToStudy( origin, "origin" )) - - # This part is to automatically display the objects in the active viewer. - gcomp = salome.ImportComponentGUI("GEOM") - for entry in entries: - gcomp.createAndDisplayFitAllGO(entry) - -if DEMO_IS_ACTIVATED: - salome_pluginsmanager.AddFunction('O,Vx,Vy,Vz (2)', - 'Creates Basic GEOM objects', - trihedron_withdisplay) - -# ------------------------------------------------------------------------- -# Example 2: creation of a shape with parameters that can be read from a GUI. -# The plugin function (tube_shapewithgui) delegates some action to -# dedicated imported modules (tube.py and tubedialog.py). -# -import tubebuilder -import xalome - -# A single dialog box is defined and recycled for every call. The -# fields are initialized with default values given by the tube factory -# tube.py. -import tubedialog -dialog = tubedialog.TubeDialog() -dialog.setData(tubebuilder.DEFAULT_RADIUS, - tubebuilder.DEFAULT_LENGTH, - tubebuilder.DEFAULT_WIDTH) - -def tube_shapewithgui(context): - global tubebuilder, xalome, dialog - activeStudy = context.study - - # Get the parameter values from a gui dialog box. If the dialog is - # closed using the Ok button, then the data are requested from the - # gui and used to create the shape of the tube. - dialog.exec_() - if dialog.wasOk(): - radius, length, width = dialog.getData() - shape = tubebuilder.createGeometry(activeStudy, radius, length, width) - entry = xalome.addToStudy(activeStudy, shape, "Tube" ) - xalome.displayShape(entry) - -if DEMO_IS_ACTIVATED: - salome_pluginsmanager.AddFunction('Tube shape from parameters', - 'Creates a tube object from specified parameters', - tube_shapewithgui) - - -# ------------------------------------------------------------------------- -# Example 2 bis: creation of a mesh with parameters that can be read from a GUI. -# The plugin function (tube_meshwithgui) delegates some action to -# dedicated imported modules (tubebuilder.py and tubedialog.py). -# -def tube_meshwithgui(context): - global tube, dialog - activeStudy = context.study - - # Get the parameter values from a gui dialog box. If the dialog is - # closed using the Ok button, then the data are requested from the - # gui and used to create the shape of the tube. - dialog.exec_() - if dialog.wasOk(): - radius, length, width = dialog.getData() - mesh = tubebuilder.createModel(activeStudy, radius, length, width) - -if DEMO_IS_ACTIVATED: - salome_pluginsmanager.AddFunction('Tube mesh from parameters', - 'Creates a tube object from specified parameters', - tube_meshwithgui) - - -# ------------------------------------------------------------------------- -# Example 2 ter: creation of a geom object with a preview function in -# the dialog box. This use case is more complex from the gui point of -# view because the dialog box is a not modal so that we can have -# interaction with the complete SALOME application. This modal -# situation requires to connect button click signal on global -# functions as a "callback" mechanism. -# -# TODO: -# - coloring the preview in pink -# - store the tmp study objects in a "preview" folder -# -dialogWithApply = tubedialog.TubeDialogOnTopWithApply() -dialogWithApply.setData(tubebuilder.DEFAULT_RADIUS, - tubebuilder.DEFAULT_LENGTH, - tubebuilder.DEFAULT_WIDTH) -activeStudy = None -previewShapeEntry = None - -DEFAULT_FOLDER_NAME="TubeList" -DEFAULT_SHAPE_NAME="tube" -PREVIEW_SHAPE_NAME="preview" - -def acceptCallback(): - """Action to be done when click on Ok""" - global tubebuilder, xalome - global dialogWithApply, activeStudy - global previewShapeEntry, deletePreviewShape - global DEFAULT_FOLDER_NAME,DEFAULT_SHAPE_NAME - - dialogWithApply.accept() - - if previewShapeEntry is not None: - deletePreviewShape() - - radius, length, width = dialogWithApply.getData() - shape = tubebuilder.createGeometry(activeStudy, radius, length, width) - entry = xalome.addToStudy(activeStudy, shape, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME) - xalome.displayShape(entry) - -def rejectCallback(): - """Action to be done when click on Cancel""" - global dialogWithApply, previewShapeEntry, deletePreviewShape - - dialogWithApply.reject() - - if previewShapeEntry is not None: - deletePreviewShape() - -import SALOMEDS -PREVIEW_COLOR=SALOMEDS.Color(1,0.6,1) # pink - -def applyCallback(): - """Action to be done when click on Apply""" - global tubebuilder, xalome - global dialogWithApply, activeStudy - global previewShapeEntry, deletePreviewShape - global PREVIEW_COLOR, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME, PREVIEW_SHAPE_NAME - - # We first have to destroy the currently displayed preview shape. - if previewShapeEntry is not None: - deletePreviewShape() - - # Then we can create the new shape with the new parameter values - radius, length, width = dialogWithApply.getData() - shape = tubebuilder.createGeometry(activeStudy, radius, length, width) - # We apply a specific color on the shape for the preview state - shape.SetColor(PREVIEW_COLOR) - previewShapeEntry = xalome.addToStudy(activeStudy, shape, PREVIEW_SHAPE_NAME, DEFAULT_FOLDER_NAME ) - xalome.displayShape(previewShapeEntry) - -def deletePreviewShape(): - """This delete the shape currently being displayed as a preview""" - global activeStudy, previewShapeEntry, xsalome - xalome.deleteShape(activeStudy,previewShapeEntry) - previewShapeEntry = None - -# Connection of callback functions to the dialog butoon click signals -dialogWithApply.handleAcceptWith(acceptCallback) -dialogWithApply.handleRejectWith(rejectCallback) -dialogWithApply.handleApplyWith(applyCallback) - -def tube_shapewithguiAndPreview(context): - """ - This plugin open a dialog in an asynchronous mode. Then it - required callback functions to be associated to the button - signals. - """ - global dialogWithApply, activeStudy - activeStudy = context.study - dialogWithApply.open() +try: + import geompy, smesh +except: + DEMO_IS_ACTIVATED=False if DEMO_IS_ACTIVATED: - salome_pluginsmanager.AddFunction('Tube geometry from parameters with preview', - 'Creates a tube object from specified parameters', - tube_shapewithguiAndPreview) + # ------------------------------------------------------------------------- + # Example 1: creation of basic objects. + # The plugin function is implemented here and declared in the pluginsmanager. + # + import salome + + def trihedron(context): + import geompy + + # Intialize the geompy factory with the active study + activeStudy = context.study + geompy.init_geom(activeStudy) + + # Create the objects + Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) + Vy = geompy.MakeVectorDXDYDZ(0, 10, 0) + Vz = geompy.MakeVectorDXDYDZ(0, 0, 10) + origin = geompy.MakeVertex(0, 0, 0) + + # Register the objects in the active study + geompy.addToStudy( Vx, "Vx" ) + geompy.addToStudy( Vy, "Vy" ) + geompy.addToStudy( Vz, "Vz" ) + geompy.addToStudy( origin, "origin" ) + + + salome_pluginsmanager.AddFunction('DEMO/O,Vx,Vy,Vz', + 'Creates the trihedron', + trihedron) + + + # ------------------------------------------------------------------------- + # Example 1 bis: creation of basic objects and automatic display + def trihedron_withdisplay(context): + import geompy + + # Intialize the geompy factory with the active study + activeStudy = context.study + geompy.init_geom(activeStudy) + + # Create the objects + Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) + Vy = geompy.MakeVectorDXDYDZ(0, 10, 0) + Vz = geompy.MakeVectorDXDYDZ(0, 0, 10) + origin = geompy.MakeVertex(0, 0, 0) + + # Register the objects in the active study + entries=[] + entries.append(geompy.addToStudy( Vx, "Vx" )) + entries.append(geompy.addToStudy( Vy, "Vy" )) + entries.append(geompy.addToStudy( Vz, "Vz" )) + entries.append(geompy.addToStudy( origin, "origin" )) + + # This part is to automatically display the objects in the active viewer. + gcomp = salome.ImportComponentGUI("GEOM") + for entry in entries: + gcomp.createAndDisplayFitAllGO(entry) + + + salome_pluginsmanager.AddFunction('DEMO/O,Vx,Vy,Vz (2)', + 'Creates Basic GEOM objects', + trihedron_withdisplay) + + # ------------------------------------------------------------------------- + # Example 2: creation of a shape with parameters that can be read from a GUI. + # The plugin function (tube_shapewithgui) delegates some action to + # dedicated imported modules (tube.py and tubedialog.py). + # + + import tubebuilder + import xalome + + # A single dialog box is defined and recycled for every call. The + # fields are initialized with default values given by the tube factory + # tube.py. + import tubedialog + dialog = tubedialog.TubeDialog() + dialog.setData(tubebuilder.DEFAULT_RADIUS, + tubebuilder.DEFAULT_LENGTH, + tubebuilder.DEFAULT_WIDTH) + + def tube_shapewithgui(context): + global tubebuilder, xalome, dialog + activeStudy = context.study + + # Get the parameter values from a gui dialog box. If the dialog is + # closed using the Ok button, then the data are requested from the + # gui and used to create the shape of the tube. + dialog.exec_() + if dialog.wasOk(): + radius, length, width = dialog.getData() + shape = tubebuilder.createGeometry(activeStudy, radius, length, width) + entry = xalome.addToStudy(activeStudy, shape, "Tube" ) + xalome.displayShape(entry) + + + salome_pluginsmanager.AddFunction('DEMO/Tube shape from parameters', + 'Creates a tube object from specified parameters', + tube_shapewithgui) + + + # ------------------------------------------------------------------------- + # Example 2 bis: creation of a mesh with parameters that can be read from a GUI. + # The plugin function (tube_meshwithgui) delegates some action to + # dedicated imported modules (tubebuilder.py and tubedialog.py). + # + def tube_meshwithgui(context): + global tube, dialog + activeStudy = context.study + + # Get the parameter values from a gui dialog box. If the dialog is + # closed using the Ok button, then the data are requested from the + # gui and used to create the shape of the tube. + dialog.exec_() + if dialog.wasOk(): + radius, length, width = dialog.getData() + mesh = tubebuilder.createModel(activeStudy, radius, length, width) + + + salome_pluginsmanager.AddFunction('DEMO/Tube mesh from parameters', + 'Creates a tube object from specified parameters', + tube_meshwithgui) + + + # ------------------------------------------------------------------------- + # Example 2 ter: creation of a geom object with a preview function in + # the dialog box. This use case is more complex from the gui point of + # view because the dialog box is a not modal so that we can have + # interaction with the complete SALOME application. This modal + # situation requires to connect button click signal on global + # functions as a "callback" mechanism. + # + # TODO: + # - coloring the preview in pink + # - store the tmp study objects in a "preview" folder + # + dialogWithApply = tubedialog.TubeDialogOnTopWithApply() + dialogWithApply.setData(tubebuilder.DEFAULT_RADIUS, + tubebuilder.DEFAULT_LENGTH, + tubebuilder.DEFAULT_WIDTH) + activeStudy = None + previewShapeEntry = None + + DEFAULT_FOLDER_NAME="TubeList" + DEFAULT_SHAPE_NAME="tube" + PREVIEW_SHAPE_NAME="preview" + + def acceptCallback(): + """Action to be done when click on Ok""" + global tubebuilder, xalome + global dialogWithApply, activeStudy + global previewShapeEntry, deletePreviewShape + global DEFAULT_FOLDER_NAME,DEFAULT_SHAPE_NAME + + dialogWithApply.accept() + + if previewShapeEntry is not None: + deletePreviewShape() + + radius, length, width = dialogWithApply.getData() + shape = tubebuilder.createGeometry(activeStudy, radius, length, width) + entry = xalome.addToStudy(activeStudy, shape, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME) + xalome.displayShape(entry) + + def rejectCallback(): + """Action to be done when click on Cancel""" + global dialogWithApply, previewShapeEntry, deletePreviewShape + + dialogWithApply.reject() + + if previewShapeEntry is not None: + deletePreviewShape() + + import SALOMEDS + PREVIEW_COLOR=SALOMEDS.Color(1,0.6,1) # pink + + def applyCallback(): + """Action to be done when click on Apply""" + global tubebuilder, xalome + global dialogWithApply, activeStudy + global previewShapeEntry, deletePreviewShape + global PREVIEW_COLOR, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME, PREVIEW_SHAPE_NAME + + # We first have to destroy the currently displayed preview shape. + if previewShapeEntry is not None: + deletePreviewShape() + + # Then we can create the new shape with the new parameter values + radius, length, width = dialogWithApply.getData() + shape = tubebuilder.createGeometry(activeStudy, radius, length, width) + # We apply a specific color on the shape for the preview state + shape.SetColor(PREVIEW_COLOR) + previewShapeEntry = xalome.addToStudy(activeStudy, shape, PREVIEW_SHAPE_NAME, DEFAULT_FOLDER_NAME ) + xalome.displayShape(previewShapeEntry) + + def deletePreviewShape(): + """This delete the shape currently being displayed as a preview""" + global activeStudy, previewShapeEntry, xsalome + xalome.deleteShape(activeStudy,previewShapeEntry) + previewShapeEntry = None + + # Connection of callback functions to the dialog butoon click signals + dialogWithApply.handleAcceptWith(acceptCallback) + dialogWithApply.handleRejectWith(rejectCallback) + dialogWithApply.handleApplyWith(applyCallback) + + def tube_shapewithguiAndPreview(context): + """ + This plugin open a dialog in an asynchronous mode. Then it + required callback functions to be associated to the button + signals. + """ + global dialogWithApply, activeStudy + activeStudy = context.study + dialogWithApply.open() + + + salome_pluginsmanager.AddFunction('DEMO/Tube geometry from parameters with preview', + 'Creates a tube object from specified parameters', + tube_shapewithguiAndPreview) @@ -249,10 +255,12 @@ if DEMO_IS_ACTIVATED: # Example 3: run a shell session in a xterm to get a SALOME python console def runSalomeShellSession(context): import os - command="(xterm -e "+os.environ['KERNEL_ROOT_DIR']+"/runSession)&" + import salome_version + ld_library_path= os.getenv("LD_LIBRARY_PATH") + command = 'xterm -T "SALOME %s - Shell session" -e env LD_LIBRARY_PATH=%s %s/runSession&'%(salome_version.getVersion(full=True),ld_library_path,os.environ['KERNEL_ROOT_DIR']) os.system(command) -if DEMO_IS_ACTIVATED: - salome_pluginsmanager.AddFunction('SALOME shell session', - 'Execute a SALOME shell session in an external xterm', - runSalomeShellSession) + +salome_pluginsmanager.AddFunction('SALOME shell session', + 'Execute a SALOME shell session in an external xterm', + runSalomeShellSession)