Back to index

salome-gui  6.5.0
Functions | Variables
minmax_plugin Namespace Reference

Functions

def minmax

Variables

 ui
 mm

Function Documentation

def minmax_plugin.minmax (   context)

Definition at line 22 of file minmax_plugin.py.

00022 
00023 def minmax(context):
00024   # get context study, studyId, salomeGui
00025   study = context.study
00026   studyId = context.studyId
00027   sg = context.sg
00028 
00029   from PyQt4.QtGui import QDialog
00030   from PyQt4.QtGui import QMessageBox
00031   from PyQt4.QtCore import Qt
00032   from PyQt4.QtCore import SIGNAL
00033 
00034   from minmax_dialog import Ui_Dialog
00035 
00036   import salome
00037   import smesh
00038 
00039   controls_dict = {
00040     "Aspect Ratio 3D" :     smesh.FT_AspectRatio3D,
00041     "Volume" :              smesh.FT_Volume3D,
00042     "Element Diameter 3D" : smesh.FT_MaxElementLength3D,
00043     "Length 2D" :           smesh.FT_Length2D,
00044     "MultiConnection 2D" :  smesh.FT_MultiConnection2D,
00045     "Area" :                smesh.FT_Area,
00046     "Taper" :               smesh.FT_Taper,
00047     "Aspect Ratio" :        smesh.FT_AspectRatio,
00048     "Minimum Angle" :       smesh.FT_MinimumAngle,
00049     "Warping" :             smesh.FT_Warping,
00050     "Skew" :                smesh.FT_Skew,
00051     "Element Diameter 2D" : smesh.FT_MaxElementLength2D,
00052     "Length" :              smesh.FT_Length,
00053     "MultiConnection" :     smesh.FT_MultiConnection,
00054     }
00055 
00056   controls_3d = [
00057     "Aspect Ratio 3D",
00058     "Volume",
00059     "Element Diameter 3D",
00060     ]
00061   controls_2d = [
00062     "Length 2D",
00063     "MultiConnection 2D",
00064     "Area",
00065     "Taper",
00066     "Aspect Ratio",
00067     "Minimum Angle",
00068     "Warping",
00069     "Skew",
00070     "Element Diameter 2D"
00071     ]
00072   controls_1d = [
00073     "Length",
00074     "MultiConnection",
00075     ]
00076 
00077   class MinmaxDialog(QDialog):
00078     def __init__(self):
00079       QDialog.__init__(self, None, Qt.Tool)
00080       # Set up the user interface from Designer.
00081       self.ui = Ui_Dialog()
00082       self.ui.setupUi(self)
00083       self.show()
00084 
00085       self.clearLineEdit()
00086 
00087       # Connect up the selectionChanged() event of the object browser.
00088       self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00089 
00090       self.mm = None
00091       self.ui.control.setFocus()
00092       self.select()
00093 
00094       pass
00095 
00096     def OnCancel(self):
00097       self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00098       self.reject()
00099       pass
00100 
00101     def clearLineEdit(self):
00102       self.ui.mesh.setText("Select a Mesh")
00103       self.ui.mesh.setStyleSheet("QLineEdit { color: grey }")
00104       self.ui.minvalue.setText("")
00105       self.ui.maxvalue.setText("")
00106 
00107     def select(self):
00108       self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00109       self.ui.control.clear()
00110       self.ui.minvalue.setText("")
00111       self.ui.maxvalue.setText("")
00112       objId = salome.sg.getSelected(0)
00113       if objId:
00114         mm = study.FindObjectID(objId).GetObject()
00115         mesh = None
00116         try:
00117           mesh = mm.GetMEDMesh()
00118         except:
00119           #print "No mesh selected"
00120           self.clearLineEdit()
00121           mesh = None
00122           pass
00123         if mesh:
00124           self.ui.mesh.setStyleSheet("")
00125           self.ui.mesh.setText(mesh.getName())
00126           #print "Mesh selected: ", mesh.getName()
00127           self.mm = mm
00128           e = self.mm.NbEdges()
00129           f = self.mm.NbFaces()
00130           v = self.mm.NbVolumes()
00131           #print "NbEdges: ",e
00132           #print "NbFaces: ",f
00133           #print "NbVolumes: ",v
00134           controls = []
00135           if e:
00136             controls += controls_1d
00137             pass
00138           if f:
00139             controls += controls_2d
00140             pass
00141           if v:
00142             controls += controls_3d
00143             pass
00144           self.ui.control.addItems(controls)
00145           self.compute_minmax()
00146       self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00147       pass
00148 
00149     def helpMessage(self):
00150       QMessageBox.about(None, "About Min/Max value of control",
00151       """
00152       Displays the min/max value of a control
00153       ---------------------------------
00154 
00155 This plugin displays the min and max value of a control
00156 on a mesh.
00157 Inputs:
00158   - The mesh to analyse
00159   - The control to compute
00160       """)
00161       pass
00162 
00163     def compute_minmax(self):
00164       if self.mm:
00165         control = self.ui.control.currentText()
00166         #print "Compute control: ",control
00167         fun = smesh.GetFunctor(controls_dict[str(control)])
00168         fun.SetMesh(self.mm.GetMesh())
00169         hist = fun.GetHistogram(1)
00170         maxVal = hist[0].max
00171         minVal = hist[0].min
00172         #print "Max value for %s: %f"%(control, maxVal)
00173         #print "Min value for %s: %f"%(control, minVal)
00174         self.ui.maxvalue.setText("%f"%(maxVal))
00175         self.ui.minvalue.setText("%f"%(minVal))
00176       else:
00177         print "Pas de maillage"
00178         pass
00179       pass
00180     pass
00181 
00182   window = MinmaxDialog()
00183   window.exec_()
00184   pass
00185 

Variable Documentation

Definition at line 89 of file minmax_plugin.py.

Definition at line 80 of file minmax_plugin.py.