In this example, the end user has to write:
-# the python script that creates the mesh from the parameters, using
- the GEOM and SMESH python interface, as in a clasic use case.
--# the dialog box in PyQt to input the parameters
--# the file salome_plugins.py that declares the plugins
+ the GEOM and SMESH python interface, as in a classic use case,
+-# the dialog box in PyQt to input the parameters,
+-# the file salome_plugins.py that declares the plugins.
This page explains only the last point.
salome_pluginsmanager.AddFunction('My plugin n°1', 'This action runs the plugin n°1', myplugin1)
salome_pluginsmanager.AddFunction('My plugin n°2', 'This action runs the plugin n°2', myplugin2)
...
-\endcode
+\endcode
The procedure is to define a function that implements the plugin, and
to declare this function to the plugins manager. The implementation
In this code, the variable "context" is automatically transmitted by
the pluginmanager when you request the plugin. This context provides
-you with at at least the following attributes:
+you with at least the following attributes:
\code
activeStudy = context.study
<module_name> is the name of the module in low letters).
-# The directory ~/.config/salome/Plugins for personnal end user
plugins.
--# Any path in the shell variable SALOME_PLUGIN_PATH (each path must be
+-# Any path in the shell variable SALOME_PLUGINS_PATH (each path must be
separated by a comma ":" for unix and ";" for windows). This
- variable should be set and exported before running the SALOME application.
+ variable should be set and exported before running the SALOME application.
\section S3_SALOMEPLUGINS A complete example
is capable to write if he reads the documentation and follows the
training course):
-\code
+\code
# Intialize the geompy factory with the active study
import salome
import GEOM
an action on it, for example, to select a mesh and display some information related to it.
Some important methods and objects to use are as follows:
--# context.sg.getObjectBrowser(): to connect the signal event
- `selectionChanged()` to a custom slot
+-# context.sg.getObjectBrowser(): to connect the signal event
+ `selectionChanged()` to a custom slot
-# context.salome.sg.getAllSelected(): to get the list of selected object
- in the object browser
--# objId = context.salome.sg.getSelected(0):
+ in the object browser
+-# objId = context.salome.sg.getSelected(0):
to get the first selected object in the object browser
-# salomeObj = context.salome.study.FindObjectID(objId).GetObject():
to retrieve the salome object from selection. It can be a GEOM, SMESH, or any
- other module object.
+ other module object.
- If it is a mesh, then it is possible to call GetMEDMesh() on the object.
- If it is not a mesh, this call will raise an exception.
- So it is possible to write the mesh retrieval in the following way:
+ If it is a mesh, then it is possible to call methods of the SMESH::SMESH_Mesh interface
+ on the object, for example GetShapeToMesh().
+ If it is not a mesh, this call will raise an exception.
+ So it is possible to write the code retrieving the shape a mesh is built on in the following way:
\code
mesh = None
try:
- mesh = salomeObj.GetMEDMesh()
+ shape = salomeObj.GetShapeToMesh()
except:
print "The selection is not a mesh"
\endcode
-A example of those methods is available with the demo examples.
+An example of those methods is available with the demo examples.
See the next chapter \ref S5_SALOMEPLUGINS.
\section S5_SALOMEPLUGINS Other examples
variable DEMO_IS_ACTIVATED to True.
The demo examples are:
--# \b trihedron: create a trihedron and display it with fit on the size
+-# \b trihedron: create a trihedron and display it with fit on the size
-# \b tube_shapewithgui: create a geom object from parameters given by a
dialog box.
-# \b tube_meshwithgui: create a mesh object from parameters given by a
-# \b runSalomeShellSession: run a SALOME prepared shell session in a
xterm.
-# \b minmax: computes the min and max values of a control on a selected mesh.
- \note This plugin is available in the SMESH module only. To activate it, edit
+ \note This plugin is available in the SMESH module only. To activate it, edit
the file $GUI_ROOT_DIR/share/salome/plugins/gui/demo/smesh_plugins.py and turn the variable
DEMO_IS_ACTIVATED to True.