--- /dev/null
+# -*- coding: iso-8859-1 -*-
+
+import salome
+from salome.geom import geomtools
+
+def addToStudy(study,shape,name):
+ '''
+ Helper function to add an object in the study. It returns the
+ associated entry so that this study could be manipulated using
+ study object functions.
+ '''
+ studyId = study._get_StudyId()
+ geompy = geomtools.getGeompy(studyId)
+ entry = geompy.addToStudy( shape, "Tube" )
+ return entry
+
+# Available in SALOME 6.5 only
+def displayShape_version65(shapeStudyEntry):
+ gst = geomtools.GeomStudyTools()
+ gst.displayShapeByEntry(shapeStudyEntry)
+
+def eraseShape_version65(shapeStudyEntry):
+ gst = geomtools.GeomStudyTools()
+ gst.eraseShapeByEntry(shapeStudyEntry)
+
+ModeShading = 1
+DisplayMode=ModeShading
+def displayShape(shapeStudyEntry):
+ """This displays the shape specified by its entry in the study"""
+ geomgui = salome.ImportComponentGUI("GEOM")
+ geomgui.createAndDisplayFitAllGO(shapeStudyEntry)
+ geomgui.setDisplayMode(shapeStudyEntry, DisplayMode)
+
+def eraseShape(shapeStudyEntry):
+ """
+ This erases from the viewers the shape specified by its entry
+ in the study.
+ """
+ geomgui = salome.ImportComponentGUI("GEOM")
+ eraseFromAllWindows=True
+ geomgui.eraseGO(shapeStudyEntry,eraseFromAllWindows)
# dedicated imported modules (tube.py and tubedialog.py).
#
import tube
+import myhelper
# A single dialog box is defined and recycled for every call. The
# fields are initialized with default values given by the tube factory
dialog.setData(tube.DEFAULT_RADIUS, tube.DEFAULT_LENGTH, tube.DEFAULT_WIDTH)
def tube_shapewithgui(context):
- global tube, dialog
+ global tube, myhelper, dialog
activeStudy = context.study
# Get the parameter values from a gui dialog box. If the dialog is
if dialog.wasOk():
radius, length, width = dialog.getData()
shape = tube.createGeometry(activeStudy, radius, length, width)
+ entry = myhelper.addToStudy(activeStudy, shape, "Tube" )
+ myhelper.displayShape(entry)
if DEMO_IS_ACTIVATED:
salome_pluginsmanager.AddFunction('Tube shape 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 named the "callback" functions.
+#
+import tubedialogWithApply
+dialogWithApply = tubedialogWithApply.TubeDialogWithApply()
+dialogWithApply.setData(tube.DEFAULT_RADIUS, tube.DEFAULT_LENGTH, tube.DEFAULT_WIDTH)
+activeStudy = None
+previewShapeEntry = None
+
+def acceptCallback():
+ """Action to do when click on Ok"""
+ global tube, dialogWithApply, activeStudy, previewShapeEntry, deletePreviewShape
+ dialogWithApply.accept()
+
+ if previewShapeEntry is not None:
+ deletePreviewShape()
+
+ radius, length, width = dialogWithApply.getData()
+ shape = tube.createGeometry(activeStudy, radius, length, width)
+ entry = myhelper.addToStudy(activeStudy, shape, "Tube" )
+ myhelper.displayShape(entry)
+
+
+def rejectCallback():
+ """Action to do when click on Cancel"""
+ global tube, dialogWithApply, activeStudy, previewShapeEntry, deletePreviewShape
+ dialogWithApply.reject()
+
+ if previewShapeEntry is not None:
+ deletePreviewShape()
+
+def applyCallback():
+ """Action to do when click on Apply"""
+ global tube, dialogWithApply, activeStudy, previewShapeEntry, deletePreviewShape
+ # 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 = tube.createGeometry(activeStudy, radius, length, width)
+ previewShapeEntry = myhelper.addToStudy(activeStudy, shape, "Tube" )
+ myhelper.displayShape(previewShapeEntry)
+
+def deletePreviewShape():
+ global activeStudy, previewShapeEntry
+
+ from salome.kernel.studyedit import getStudyEditor, getStudyIdFromStudy
+ from salome.kernel.services import IDToSObject, IDToObject
+
+ # WARN: please be aware that to delete a geom object, you have
+ # three operations to perform:
+ # 1. erase the shape from the viewer
+ # 2. delete the entry in the study
+ # 3. destroy the geom object
+ myhelper.eraseShape(previewShapeEntry)
+ item = IDToSObject(previewShapeEntry)
+ geomObj = IDToObject(previewShapeEntry)
+ ste = getStudyEditor(getStudyIdFromStudy(activeStudy))
+ ste.removeItem(item,True)
+ geomObj.Destroy()
+ previewShapeEntry = None
+
+dialogWithApply.handleAcceptWith(acceptCallback)
+dialogWithApply.handleRejectWith(rejectCallback)
+dialogWithApply.handleApplyWith(applyCallback)
+
+def tube_shapewithguiAndPreview(context):
+ global tube, dialogWithApply, activeStudy
+ activeStudy = context.study
+ dialogWithApply.open()
+
+if DEMO_IS_ACTIVATED:
+ salome_pluginsmanager.AddFunction('Tube geometry from parameters with preview',
+ 'Creates a tube object from specified parameters',
+ tube_shapewithguiAndPreview)
+
+
+
# -------------------------------------------------------------------------
# Example 3: run a shell session in a xterm to get a SALOME python console
def runSalomeShellSession(context):
DEFAULT_LENGTH = 300
DEFAULT_WIDTH = 20
+from salome.geom import geomtools
+
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)
+ studyId = study._get_StudyId()
+ geompy = geomtools.getGeompy(studyId)
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.
+ studyId = study._get_StudyId()
+ geompy = geomtools.getGeompy(studyId)
+
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)
--- /dev/null
+import sys
+from PyQt4 import QtGui
+from PyQt4 import QtCore
+
+
+from tubedialog import TubeDialog
+class TubeDialogWithApply(TubeDialog):
+ def setupUi(self):
+ """
+ This setupUi adds a button Apply to execute tasks as preview
+ """
+ TubeDialog.setupUi(self)
+ self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|
+ QtGui.QDialogButtonBox.Apply|
+ QtGui.QDialogButtonBox.Ok)
+
+ self.setWindowFlags(self.windowFlags() |
+ QtCore.Qt.WindowStaysOnTopHint)
+
+
+ def handleAcceptWith(self,callbackFunction):
+ QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), callbackFunction)
+
+ def handleRejectWith(self,callbackFunction):
+ QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), callbackFunction)
+
+ def handleApplyWith(self,callbackFunction):
+ button = self.buttonBox.button(QtGui.QDialogButtonBox.Apply)
+ QtCore.QObject.connect(button, QtCore.SIGNAL("clicked()"), callbackFunction);
+