# Directory for installing resource files
salomeresdir = $(prefix)/share/salome/resources/@MODULE_NAME@
+# Directory for installing plugins files
+salomepluginsdir = $(prefix)/share/salome/plugins/@MODULE_NAME@
+
# Directories for installing admin files
admlocaldir = $(prefix)/adm_local
admlocalunixdir = $(admlocaldir)/unix
src/Session/Makefile \
src/SalomeApp/Makefile \
src/SalomeApp/Test/Makefile \
+ src/SalomeApp/pluginsdemo/Makefile \
src/GuiHelpers/Makefile \
src/TreeData/Makefile \
src/TreeData/Test/Makefile \
include $(top_srcdir)/adm_local/unix/make_common_starter.am
+SUBDIRS=pluginsdemo
+
if CPPUNIT_IS_OK
if GUI_ENABLE_CORBA
- SUBDIRS = Test
+ SUBDIRS += Test
endif
endif
--- /dev/null
+# Copyright (C) 2010 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# -* Makefile *-
+#
+# Author : Guillaume Boulant (EDF)
+#
+
+include $(top_srcdir)/adm_local/unix/make_common_starter.am
+
+#
+# Note that the plugins files should be installed in the directory
+# <salomepluginsdir> (ROOT_DIR/share/salome/plugins) or one of this
+# sub-directories (the search of plugins by the plugin manager is
+# recurcive from this folder, in each SALOME module, i.e. each
+# variable *_ROOT_DIR).
+#
+pluginsdir =$(salomepluginsdir)/demo
+plugins_PYTHON = \
+ salome_plugins.py \
+ trihedron.py \
+ tubedialog.py \
+ tube.py
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+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 tube
+
+# 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(tube.DEFAULT_RADIUS, tube.DEFAULT_LENGTH, tube.DEFAULT_WIDTH)
+
+def tube_shapewithgui(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()
+ shape = tube.createGeometry(activeStudy, radius, length, width)
+
+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 (tube.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 = tube.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 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)&"
+ os.system(command)
+
+if DEMO_IS_ACTIVATED:
+ salome_pluginsmanager.AddFunction('SALOME shell session',
+ 'Execute a SALOME shell session in an external xterm',
+ runSalomeShellSession)
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Example 1: creation of basic objects (O, Vx, Vy, Vz)
+#
+
+# Intialize the geompy factory with the active study
+import geompy
+import salome
+geompy.init_geom(salome.myStudy)
+
+# 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" )
+
+
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+
+import salome
+
+DEFAULT_RADIUS = 100
+DEFAULT_LENGTH = 300
+DEFAULT_WIDTH = 20
+
+def createGeometry(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
+ '''
+ This function creates the geometry on the specified study and with
+ given parameters.
+ '''
+ print "TUBE: creating the geometry ..."
+ import geompy
+ geompy.init_geom(study)
+
+ radius_ext = radius
+ radius_int = radius_ext - width
+
+ CylinderExt = geompy.MakeCylinderRH(radius_ext, length)
+ CylinderInt = geompy.MakeCylinderRH(radius_int, length)
+ Tube = geompy.MakeCut(CylinderExt, CylinderInt)
+ entry = geompy.addToStudy( Tube, "Tube" )
+ return Tube
+
+def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
+ '''
+ This function create the geometrical shape with a partition so
+ that the hexaedric algorithm could be used for meshing.
+ '''
+ import geompy
+ shape = createGeometry(study,radius,length,width)
+
+ # We have to create a partition so that we can use an hexaedric
+ # meshing algorithm.
+ print "TUBE: creating a partition ..."
+ toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3)
+ partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
+ entry = geompy.addToStudy( partition, "TubeWithPartition" )
+ return partition
+
+def createMesh(study, shape):
+ '''This function creates the mesh of the specified shape on the specified study'''
+ print "TUBE: creating the mesh ..."
+ import smesh
+
+ smesh.SetCurrentStudy(study)
+ mesh = smesh.Mesh(shape)
+ Regular_1D = mesh.Segment()
+ Nb_Segments = Regular_1D.NumberOfSegments(10)
+ Nb_Segments.SetDistrType( 0 )
+ Quadrangle_2D = mesh.Quadrangle()
+ Hexa_3D = mesh.Hexahedron()
+
+ isDone = mesh.Compute()
+
+ if salome.sg.hasDesktop():
+ smesh.SetName(mesh.GetMesh(), 'TubeMesh')
+ smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
+ smesh.SetName(Nb_Segments, 'Nb. Segments_1')
+ smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
+ smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
+ salome.sg.updateObjBrowser(0)
+
+ return mesh
+
+
+def createModel(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH,width=DEFAULT_WIDTH):
+ '''
+ This function create the geomtrical shape AND the associated mesh.
+ '''
+ # We first create a shape with a partition so that the hexaedric
+ # algorithm could be used.
+ shape = createGeometryWithPartition(study,radius,length,width)
+
+ # Then the mesh can be defined and computed
+ mesh = createMesh(study,shape)
+
+def exportModel(mesh, filename):
+ '''
+ This exports the mesh to the specified filename in the med format
+ '''
+ print "TUBE: exporting mesh to file %s ..."%filename
+ import SMESH
+ mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 )
+
+
+#
+# ===================================================================
+# Use cases and test functions
+# ===================================================================
+#
+def TEST_createGeometry():
+ salome.salome_init()
+ theStudy=salome.myStudy
+ createGeometry(theStudy)
+
+def TEST_createMesh():
+ salome.salome_init()
+ theStudy=salome.myStudy
+ shape = createGeometryWithPartition(theStudy)
+ mesh = createMesh(theStudy, shape)
+
+def TEST_createModel():
+ salome.salome_init()
+ theStudy=salome.myStudy
+ createModel(theStudy)
+
+def TEST_exportModel():
+ salome.salome_init()
+ theStudy=salome.myStudy
+ shape = createGeometryWithPartition(theStudy)
+ mesh = createMesh(theStudy, shape)
+ exportModel(mesh,"tubemesh.med")
+
+if __name__ == "__main__":
+ #TEST_createGeometry()
+ #TEST_createMesh()
+ TEST_createModel()
+ #TEST_exportModel()
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+import sys
+from PyQt4 import QtGui
+from PyQt4 import QtCore
+
+
+class TubeDialog(QtGui.QDialog):
+ def __init__(self, parent=None):
+ QtGui.QDialog.__init__(self, parent)
+ self.setupUi()
+
+ def setupUi(self):
+ self.setObjectName("Dialog")
+ self.resize(400, 300)
+ self.hboxlayout = QtGui.QHBoxLayout(self)
+ self.hboxlayout.setMargin(9)
+ self.hboxlayout.setSpacing(6)
+ self.hboxlayout.setObjectName("hboxlayout")
+ self.vboxlayout = QtGui.QVBoxLayout()
+ self.vboxlayout.setMargin(0)
+ self.vboxlayout.setSpacing(6)
+ self.vboxlayout.setObjectName("vboxlayout")
+ self.hboxlayout1 = QtGui.QHBoxLayout()
+ self.hboxlayout1.setMargin(0)
+ self.hboxlayout1.setSpacing(6)
+ self.hboxlayout1.setObjectName("hboxlayout1")
+ self.vboxlayout1 = QtGui.QVBoxLayout()
+ self.vboxlayout1.setMargin(0)
+ self.vboxlayout1.setSpacing(6)
+ self.vboxlayout1.setObjectName("vboxlayout1")
+ self.lblRadius = QtGui.QLabel(self)
+ self.lblRadius.setObjectName("lblRadius")
+ self.vboxlayout1.addWidget(self.lblRadius)
+ self.lblLength = QtGui.QLabel(self)
+ self.lblLength.setObjectName("lblLength")
+ self.vboxlayout1.addWidget(self.lblLength)
+ self.lblWidth = QtGui.QLabel(self)
+ self.lblWidth.setObjectName("lblWidth")
+ self.vboxlayout1.addWidget(self.lblWidth)
+ self.hboxlayout1.addLayout(self.vboxlayout1)
+ self.vboxlayout2 = QtGui.QVBoxLayout()
+ self.vboxlayout2.setMargin(0)
+ self.vboxlayout2.setSpacing(6)
+ self.vboxlayout2.setObjectName("vboxlayout2")
+ self.txtRadius = QtGui.QLineEdit(self)
+ self.txtRadius.setObjectName("txtRadius")
+ self.vboxlayout2.addWidget(self.txtRadius)
+ self.txtLength = QtGui.QLineEdit(self)
+ self.txtLength.setObjectName("txtLength")
+ self.vboxlayout2.addWidget(self.txtLength)
+ self.txtWidth = QtGui.QLineEdit(self)
+ self.txtWidth.setObjectName("txtWidth")
+ self.vboxlayout2.addWidget(self.txtWidth)
+ self.hboxlayout1.addLayout(self.vboxlayout2)
+ self.vboxlayout.addLayout(self.hboxlayout1)
+ spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
+ self.vboxlayout.addItem(spacerItem)
+ self.buttonBox = QtGui.QDialogButtonBox(self)
+ self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
+ self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok)
+ self.buttonBox.setObjectName("buttonBox")
+ self.vboxlayout.addWidget(self.buttonBox)
+ self.hboxlayout.addLayout(self.vboxlayout)
+
+ self.setWindowTitle("Tube construction")
+ self.lblRadius.setText("Rayon")
+ self.lblLength.setText("Longueur")
+ self.lblWidth.setText("Epaisseur")
+
+ QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.accept)
+ QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.reject)
+
+ def accept(self):
+ '''Callback function when dialog is accepted (click Ok)'''
+ self._wasOk = True
+ QtGui.QDialog.accept(self)
+
+ def reject(self):
+ '''Callback function when dialog is rejected (click Cancel)'''
+ self._wasOk = False
+ QtGui.QDialog.reject(self)
+
+ def wasOk(self):
+ return self._wasOk
+
+ def setData(self, radius, length, width):
+ self.txtRadius.setText(str(radius))
+ self.txtLength.setText(str(length))
+ self.txtWidth.setText(str(width))
+
+ def getData(self):
+ try:
+ radius=eval(str(self.txtRadius.text()))
+ length=eval(str(self.txtLength.text()))
+ width=eval(str(self.txtWidth.text()))
+ except:
+ print "pb a la saisie"
+
+ return radius, length, width
+
+
+def TEST_getData():
+ # This use case illustrates the MVC pattern on this simple dialog example.
+ a = QtGui.QApplication(sys.argv)
+
+ tubedialog = TubeDialog()
+ tubedialog.setData(10,50,3)
+ tubedialog.exec_()
+ if tubedialog.wasOk():
+ radius, length, width = tubedialog.getData()
+ print radius, length, width
+
+ sys.exit(0)
+
+def main( args ):
+ a = QtGui.QApplication(sys.argv)
+
+ tubedialog = TubeDialog()
+ tubedialog.setData(10,50,3)
+ sys.exit(tubedialog.exec_())
+
+if __name__=="__main__":
+ #main(sys.argv)
+ TEST_getData()
+