Back to index

salome-gui  6.5.0
minmax_plugin.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 # Author : Guillaume Boulant (EDF)
00021 
00022 def minmax(context):
00023   # get context study, studyId, salomeGui
00024   study = context.study
00025   studyId = context.studyId
00026   sg = context.sg
00027 
00028   from PyQt4.QtGui import QDialog
00029   from PyQt4.QtGui import QMessageBox
00030   from PyQt4.QtCore import Qt
00031   from PyQt4.QtCore import SIGNAL
00032 
00033   from minmax_dialog import Ui_Dialog
00034 
00035   import salome
00036   import smesh
00037 
00038   controls_dict = {
00039     "Aspect Ratio 3D" :     smesh.FT_AspectRatio3D,
00040     "Volume" :              smesh.FT_Volume3D,
00041     "Element Diameter 3D" : smesh.FT_MaxElementLength3D,
00042     "Length 2D" :           smesh.FT_Length2D,
00043     "MultiConnection 2D" :  smesh.FT_MultiConnection2D,
00044     "Area" :                smesh.FT_Area,
00045     "Taper" :               smesh.FT_Taper,
00046     "Aspect Ratio" :        smesh.FT_AspectRatio,
00047     "Minimum Angle" :       smesh.FT_MinimumAngle,
00048     "Warping" :             smesh.FT_Warping,
00049     "Skew" :                smesh.FT_Skew,
00050     "Element Diameter 2D" : smesh.FT_MaxElementLength2D,
00051     "Length" :              smesh.FT_Length,
00052     "MultiConnection" :     smesh.FT_MultiConnection,
00053     }
00054 
00055   controls_3d = [
00056     "Aspect Ratio 3D",
00057     "Volume",
00058     "Element Diameter 3D",
00059     ]
00060   controls_2d = [
00061     "Length 2D",
00062     "MultiConnection 2D",
00063     "Area",
00064     "Taper",
00065     "Aspect Ratio",
00066     "Minimum Angle",
00067     "Warping",
00068     "Skew",
00069     "Element Diameter 2D"
00070     ]
00071   controls_1d = [
00072     "Length",
00073     "MultiConnection",
00074     ]
00075 
00076   class MinmaxDialog(QDialog):
00077     def __init__(self):
00078       QDialog.__init__(self, None, Qt.Tool)
00079       # Set up the user interface from Designer.
00080       self.ui = Ui_Dialog()
00081       self.ui.setupUi(self)
00082       self.show()
00083 
00084       self.clearLineEdit()
00085 
00086       # Connect up the selectionChanged() event of the object browser.
00087       self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00088 
00089       self.mm = None
00090       self.ui.control.setFocus()
00091       self.select()
00092 
00093       pass
00094 
00095     def OnCancel(self):
00096       self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00097       self.reject()
00098       pass
00099 
00100     def clearLineEdit(self):
00101       self.ui.mesh.setText("Select a Mesh")
00102       self.ui.mesh.setStyleSheet("QLineEdit { color: grey }")
00103       self.ui.minvalue.setText("")
00104       self.ui.maxvalue.setText("")
00105 
00106     def select(self):
00107       self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00108       self.ui.control.clear()
00109       self.ui.minvalue.setText("")
00110       self.ui.maxvalue.setText("")
00111       objId = salome.sg.getSelected(0)
00112       if objId:
00113         mm = study.FindObjectID(objId).GetObject()
00114         mesh = None
00115         try:
00116           mesh = mm.GetMEDMesh()
00117         except:
00118           #print "No mesh selected"
00119           self.clearLineEdit()
00120           mesh = None
00121           pass
00122         if mesh:
00123           self.ui.mesh.setStyleSheet("")
00124           self.ui.mesh.setText(mesh.getName())
00125           #print "Mesh selected: ", mesh.getName()
00126           self.mm = mm
00127           e = self.mm.NbEdges()
00128           f = self.mm.NbFaces()
00129           v = self.mm.NbVolumes()
00130           #print "NbEdges: ",e
00131           #print "NbFaces: ",f
00132           #print "NbVolumes: ",v
00133           controls = []
00134           if e:
00135             controls += controls_1d
00136             pass
00137           if f:
00138             controls += controls_2d
00139             pass
00140           if v:
00141             controls += controls_3d
00142             pass
00143           self.ui.control.addItems(controls)
00144           self.compute_minmax()
00145       self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
00146       pass
00147 
00148     def helpMessage(self):
00149       QMessageBox.about(None, "About Min/Max value of control",
00150       """
00151       Displays the min/max value of a control
00152       ---------------------------------
00153 
00154 This plugin displays the min and max value of a control
00155 on a mesh.
00156 Inputs:
00157   - The mesh to analyse
00158   - The control to compute
00159       """)
00160       pass
00161 
00162     def compute_minmax(self):
00163       if self.mm:
00164         control = self.ui.control.currentText()
00165         #print "Compute control: ",control
00166         fun = smesh.GetFunctor(controls_dict[str(control)])
00167         fun.SetMesh(self.mm.GetMesh())
00168         hist = fun.GetHistogram(1)
00169         maxVal = hist[0].max
00170         minVal = hist[0].min
00171         #print "Max value for %s: %f"%(control, maxVal)
00172         #print "Min value for %s: %f"%(control, minVal)
00173         self.ui.maxvalue.setText("%f"%(maxVal))
00174         self.ui.minvalue.setText("%f"%(minVal))
00175       else:
00176         print "Pas de maillage"
00177         pass
00178       pass
00179     pass
00180 
00181   window = MinmaxDialog()
00182   window.exec_()
00183   pass
00184