From 4c2507fbb01f3b1c716f77ec5663043652313079 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 18 Jan 2022 18:38:09 +0300 Subject: [PATCH] Show an average value of control in the demo plugin --- src/SalomeApp/pluginsdemo/minmax.ui | 16 +++++++++++++++- src/SalomeApp/pluginsdemo/minmax_plugin.py | 21 +++++++++++++++------ src/SalomeApp/pluginsdemo/smesh_plugins.py | 4 ++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/SalomeApp/pluginsdemo/minmax.ui b/src/SalomeApp/pluginsdemo/minmax.ui index 3c9eafd98..f1b31cfe4 100644 --- a/src/SalomeApp/pluginsdemo/minmax.ui +++ b/src/SalomeApp/pluginsdemo/minmax.ui @@ -69,7 +69,21 @@ - + + + + Average + + + + + + + true + + + + Qt::Horizontal diff --git a/src/SalomeApp/pluginsdemo/minmax_plugin.py b/src/SalomeApp/pluginsdemo/minmax_plugin.py index 8642628ad..ec7523418 100644 --- a/src/SalomeApp/pluginsdemo/minmax_plugin.py +++ b/src/SalomeApp/pluginsdemo/minmax_plugin.py @@ -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 diff --git a/src/SalomeApp/pluginsdemo/smesh_plugins.py b/src/SalomeApp/pluginsdemo/smesh_plugins.py index a0c196e2b..b56ca2d2e 100644 --- a/src/SalomeApp/pluginsdemo/smesh_plugins.py +++ b/src/SalomeApp/pluginsdemo/smesh_plugins.py @@ -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) -- 2.39.2