Salome HOME
Merge branch 'V8_0_0_BR'
[modules/gui.git] / src / SalomeApp / pluginsdemo / minmax_plugin.py
index c743e5279f1e4c992ef00433b10138a7e63f550c..b6470ff32bbee3b4ec2eecf13b18da4be6ef2c72 100644 (file)
@@ -1,10 +1,10 @@
 # -*- coding: utf-8 -*-
-# Copyright (C) 2010-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2010-2015  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.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 #
 # Author : Guillaume Boulant (EDF)
 
+from qtsalome import *
+
 def minmax(context):
   # get context study, studyId, salomeGui
   study = context.study
   studyId = context.studyId
   sg = context.sg
 
-  from PyQt4.QtGui import QDialog
-  from PyQt4.QtGui import QMessageBox
-  from PyQt4.QtCore import Qt
-  from PyQt4.QtCore import SIGNAL
-
-  from minmax_dialog import Ui_Dialog
+  from minmax_ui import Ui_Dialog
 
   import salome
-  import smesh
+  import SMESH
+  from salome.smesh import smeshBuilder
+  smesh = smeshBuilder.New(salome.myStudy)
 
   controls_dict = {
-    "Aspect Ratio 3D" :     smesh.FT_AspectRatio3D,
-    "Volume" :              smesh.FT_Volume3D,
-    "Element Diameter 3D" : smesh.FT_MaxElementLength3D,
-    "Length 2D" :           smesh.FT_Length2D,
-    "MultiConnection 2D" :  smesh.FT_MultiConnection2D,
-    "Area" :                smesh.FT_Area,
-    "Taper" :               smesh.FT_Taper,
-    "Aspect Ratio" :        smesh.FT_AspectRatio,
-    "Minimum Angle" :       smesh.FT_MinimumAngle,
-    "Warping" :             smesh.FT_Warping,
-    "Skew" :                smesh.FT_Skew,
-    "Element Diameter 2D" : smesh.FT_MaxElementLength2D,
-    "Length" :              smesh.FT_Length,
-    "MultiConnection" :     smesh.FT_MultiConnection,
+    "Aspect Ratio 3D" :     SMESH.FT_AspectRatio3D,
+    "Volume" :              SMESH.FT_Volume3D,
+    "Element Diameter 3D" : SMESH.FT_MaxElementLength3D,
+    "Length 2D" :           SMESH.FT_Length2D,
+    "MultiConnection 2D" :  SMESH.FT_MultiConnection2D,
+    "Area" :                SMESH.FT_Area,
+    "Taper" :               SMESH.FT_Taper,
+    "Aspect Ratio" :        SMESH.FT_AspectRatio,
+    "Minimum Angle" :       SMESH.FT_MinimumAngle,
+    "Warping" :             SMESH.FT_Warping,
+    "Skew" :                SMESH.FT_Skew,
+    "Element Diameter 2D" : SMESH.FT_MaxElementLength2D,
+    "Length" :              SMESH.FT_Length,
+    "MultiConnection" :     SMESH.FT_MultiConnection,
     }
 
   controls_3d = [
@@ -84,7 +83,7 @@ def minmax(context):
       self.clearLineEdit()
 
       # Connect up the selectionChanged() event of the object browser.
-      self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      sg.getObjectBrowser().selectionChanged.connect(self.select)
 
       self.mm = None
       self.ui.control.setFocus()
@@ -93,7 +92,7 @@ def minmax(context):
       pass
 
     def OnCancel(self):
-      self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      sg.getObjectBrowser().selectionChanged.disconnect(self.select)
       self.reject()
       pass
 
@@ -104,7 +103,7 @@ def minmax(context):
       self.ui.maxvalue.setText("")
 
     def select(self):
-      self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      sg.getObjectBrowser().selectionChanged.disconnect(self.select)
       self.ui.control.clear()
       self.ui.minvalue.setText("")
       self.ui.maxvalue.setText("")
@@ -113,23 +112,20 @@ def minmax(context):
         mm = study.FindObjectID(objId).GetObject()
         mesh = None
         try:
-          mesh = mm.GetMEDMesh()
+          mm.Load()
+          mesh = mm
         except:
-          #print "No mesh selected"
           self.clearLineEdit()
           mesh = None
           pass
         if mesh:
+          name = smeshBuilder.GetName( mm )
           self.ui.mesh.setStyleSheet("")
-          self.ui.mesh.setText(mesh.getName())
-          #print "Mesh selected: ", mesh.getName()
+          self.ui.mesh.setText( name )
           self.mm = mm
           e = self.mm.NbEdges()
           f = self.mm.NbFaces()
           v = self.mm.NbVolumes()
-          #print "NbEdges: ",e
-          #print "NbFaces: ",f
-          #print "NbVolumes: ",v
           controls = []
           if e:
             controls += controls_1d
@@ -142,7 +138,7 @@ def minmax(context):
             pass
           self.ui.control.addItems(controls)
           self.compute_minmax()
-      self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      sg.getObjectBrowser().selectionChanged.connect(self.select)
       pass
 
     def helpMessage(self):
@@ -160,20 +156,16 @@ Inputs:
       pass
 
     def compute_minmax(self):
-      if self.mm:
-        control = self.ui.control.currentText()
-        #print "Compute control: ",control
+      control = self.ui.control.currentText()
+      if self.mm and control:
         fun = smesh.GetFunctor(controls_dict[str(control)])
-        fun.SetMesh(self.mm.GetMesh())
-        hist = fun.GetHistogram(1)
+        fun.SetMesh(self.mm)
+        hist = fun.GetHistogram(1,False)
         maxVal = hist[0].max
         minVal = hist[0].min
-        #print "Max value for %s: %f"%(control, maxVal)
-        #print "Min value for %s: %f"%(control, minVal)
         self.ui.maxvalue.setText("%f"%(maxVal))
         self.ui.minvalue.setText("%f"%(minVal))
       else:
-        print "Pas de maillage"
         pass
       pass
     pass