]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Show an average value of control in the demo plugin
authoreap <eap@opencascade.com>
Tue, 18 Jan 2022 15:38:09 +0000 (18:38 +0300)
committereap <eap@opencascade.com>
Tue, 18 Jan 2022 15:38:09 +0000 (18:38 +0300)
src/SalomeApp/pluginsdemo/minmax.ui
src/SalomeApp/pluginsdemo/minmax_plugin.py
src/SalomeApp/pluginsdemo/smesh_plugins.py

index 3c9eafd98f70a9d3dc0ee10a1b2a5c63448b3c57..f1b31cfe4768a9ed1eebb8502151117b824e063d 100644 (file)
      </property>
     </widget>
    </item>
-   <item row="4" column="0" colspan="3">
+   <item row="4" column="0">
+    <widget class="QLabel" name="label_5">
+     <property name="text">
+      <string>Average</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1" colspan="2">
+    <widget class="QLineEdit" name="avgvalue">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="0" colspan="3">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
index 8642628ad3cfc50791ec967b086119d527ad6222..ec7523418fa8a7f62066662bba52cccb5007b639 100644 (file)
@@ -142,12 +142,12 @@ def minmax(context):
       pass
 
     def helpMessage(self):
-      QMessageBox.about(None, "About Min/Max value of control",
+      QMessageBox.about(None, "About Min/Max and Average value of control",
       """
-      Displays the min/max value of a control
-      ---------------------------------
+      Displays the min/max and average value of a control
+      ---------------------------------------------------
 
-This plugin displays the min and max value of a control
+      This plugin displays the min, max and average value of a control
 on a mesh.
 Inputs:
   - The mesh to analyse
@@ -160,11 +160,20 @@ Inputs:
       if self.mm and control:
         fun = smesh.GetFunctor(controls_dict[str(control)])
         fun.SetMesh(self.mm)
-        hist = fun.GetHistogram(1,False)
-        maxVal = hist[0].max
+        nbRectangles = int(max(100, self.mm.NbElements() / 100 ))
+        hist = fun.GetHistogram(nbRectangles,False)
+        maxVal = hist[-1].max
         minVal = hist[0].min
+        avgVal = 0
+        nbElems = 0
+        for rect in hist:
+          avgVal += 0.5 * ( hist[0].max + hist[0].min ) * rect.nbEvents
+          nbElems += rect.nbEvents
+        if nbElems > 0:
+          avgVal /= nbElems
         self.ui.maxvalue.setText("%f"%(maxVal))
         self.ui.minvalue.setText("%f"%(minVal))
+        self.ui.avgvalue.setText("%f"%(avgVal))
       else:
         pass
       pass
index a0c196e2b63ea4287e8d97ba8250b822b77bb20b..b56ca2d2ec754f5e1bc2c2d97fefea660784d268 100644 (file)
@@ -27,6 +27,6 @@ from minmax_plugin import *
  
 # register the function in the plugin manager
 if DEMO_IS_ACTIVATED:
-  salome_pluginsmanager.AddFunction('Get min or max value of control',
-      'Get min or max value of control',
+  salome_pluginsmanager.AddFunction('Get min, max and average value of control',
+      'Get min, max and average value of control',
       minmax)