]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Add missing files for previous commit
authorgdd <gdd>
Tue, 6 Mar 2012 15:12:11 +0000 (15:12 +0000)
committergdd <gdd>
Tue, 6 Mar 2012 15:12:11 +0000 (15:12 +0000)
src/SalomeApp/pluginsdemo/minmax.ui [new file with mode: 0644]
src/SalomeApp/pluginsdemo/minmax_dialog.py [new file with mode: 0644]
src/SalomeApp/pluginsdemo/minmax_plugin.py [new file with mode: 0644]
src/SalomeApp/pluginsdemo/smesh_plugins.py [new file with mode: 0644]

diff --git a/src/SalomeApp/pluginsdemo/minmax.ui b/src/SalomeApp/pluginsdemo/minmax.ui
new file mode 100644 (file)
index 0000000..3c9eafd
--- /dev/null
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>178</width>
+    <height>156</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Get min and max value of control</string>
+  </property>
+  <property name="sizeGripEnabled">
+   <bool>true</bool>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="label_2">
+     <property name="text">
+      <string>Mesh</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1" colspan="2">
+    <widget class="QLineEdit" name="mesh">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0">
+    <widget class="QLabel" name="label_3">
+     <property name="text">
+      <string>Control</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1" colspan="2">
+    <widget class="QComboBox" name="control"/>
+   </item>
+   <item row="2" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Min</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1" colspan="2">
+    <widget class="QLineEdit" name="minvalue">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <widget class="QLabel" name="label_4">
+     <property name="text">
+      <string>Max</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1" colspan="2">
+    <widget class="QLineEdit" name="maxvalue">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0" colspan="3">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <tabstops>
+  <tabstop>mesh</tabstop>
+  <tabstop>control</tabstop>
+  <tabstop>minvalue</tabstop>
+  <tabstop>maxvalue</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>Dialog</receiver>
+   <slot>OnCancel()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>253</x>
+     <y>371</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>262</x>
+     <y>101</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>helpRequested()</signal>
+   <receiver>Dialog</receiver>
+   <slot>helpMessage()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>131</x>
+     <y>373</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>131</x>
+     <y>64</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>control</sender>
+   <signal>activated(QString)</signal>
+   <receiver>Dialog</receiver>
+   <slot>compute_minmax()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>250</x>
+     <y>137</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>131</x>
+     <y>81</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+ <slots>
+  <slot>compute_minmax()</slot>
+  <slot>helpMessage()</slot>
+  <slot>OnCancel()</slot>
+  <slot>OnOk()</slot>
+ </slots>
+</ui>
diff --git a/src/SalomeApp/pluginsdemo/minmax_dialog.py b/src/SalomeApp/pluginsdemo/minmax_dialog.py
new file mode 100644 (file)
index 0000000..c7d310e
--- /dev/null
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'minmax.ui'
+#
+# Created: Thu Mar  1 15:23:57 2012
+#      by: PyQt4 UI code generator 4.8.1
+#
+# WARNING! All changes made in this file will be lost!
+
+from PyQt4 import QtCore, QtGui
+
+try:
+    _fromUtf8 = QtCore.QString.fromUtf8
+except AttributeError:
+    _fromUtf8 = lambda s: s
+
+class Ui_Dialog(object):
+    def setupUi(self, Dialog):
+        Dialog.setObjectName(_fromUtf8("Dialog"))
+        Dialog.resize(178, 156)
+        Dialog.setSizeGripEnabled(True)
+        self.gridLayout = QtGui.QGridLayout(Dialog)
+        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
+        self.label_2 = QtGui.QLabel(Dialog)
+        self.label_2.setObjectName(_fromUtf8("label_2"))
+        self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
+        self.mesh = QtGui.QLineEdit(Dialog)
+        self.mesh.setReadOnly(True)
+        self.mesh.setObjectName(_fromUtf8("mesh"))
+        self.gridLayout.addWidget(self.mesh, 0, 1, 1, 2)
+        self.label_3 = QtGui.QLabel(Dialog)
+        self.label_3.setObjectName(_fromUtf8("label_3"))
+        self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
+        self.control = QtGui.QComboBox(Dialog)
+        self.control.setObjectName(_fromUtf8("control"))
+        self.gridLayout.addWidget(self.control, 1, 1, 1, 2)
+        self.label = QtGui.QLabel(Dialog)
+        self.label.setObjectName(_fromUtf8("label"))
+        self.gridLayout.addWidget(self.label, 2, 0, 1, 1)
+        self.minvalue = QtGui.QLineEdit(Dialog)
+        self.minvalue.setReadOnly(True)
+        self.minvalue.setObjectName(_fromUtf8("minvalue"))
+        self.gridLayout.addWidget(self.minvalue, 2, 1, 1, 2)
+        self.label_4 = QtGui.QLabel(Dialog)
+        self.label_4.setObjectName(_fromUtf8("label_4"))
+        self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
+        self.maxvalue = QtGui.QLineEdit(Dialog)
+        self.maxvalue.setReadOnly(True)
+        self.maxvalue.setObjectName(_fromUtf8("maxvalue"))
+        self.gridLayout.addWidget(self.maxvalue, 3, 1, 1, 2)
+        self.buttonBox = QtGui.QDialogButtonBox(Dialog)
+        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
+        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Help)
+        self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
+        self.gridLayout.addWidget(self.buttonBox, 4, 0, 1, 3)
+
+        self.retranslateUi(Dialog)
+        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.OnCancel)
+        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("helpRequested()")), Dialog.helpMessage)
+        QtCore.QObject.connect(self.control, QtCore.SIGNAL(_fromUtf8("activated(QString)")), Dialog.compute_minmax)
+        QtCore.QMetaObject.connectSlotsByName(Dialog)
+        Dialog.setTabOrder(self.mesh, self.control)
+        Dialog.setTabOrder(self.control, self.minvalue)
+        Dialog.setTabOrder(self.minvalue, self.maxvalue)
+        Dialog.setTabOrder(self.maxvalue, self.buttonBox)
+
+    def retranslateUi(self, Dialog):
+        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Get min and max value of control", None, QtGui.QApplication.UnicodeUTF8))
+        self.label_2.setText(QtGui.QApplication.translate("Dialog", "Mesh", None, QtGui.QApplication.UnicodeUTF8))
+        self.label_3.setText(QtGui.QApplication.translate("Dialog", "Control", None, QtGui.QApplication.UnicodeUTF8))
+        self.label.setText(QtGui.QApplication.translate("Dialog", "Min", None, QtGui.QApplication.UnicodeUTF8))
+        self.label_4.setText(QtGui.QApplication.translate("Dialog", "Max", None, QtGui.QApplication.UnicodeUTF8))
+
diff --git a/src/SalomeApp/pluginsdemo/minmax_plugin.py b/src/SalomeApp/pluginsdemo/minmax_plugin.py
new file mode 100644 (file)
index 0000000..14be183
--- /dev/null
@@ -0,0 +1,165 @@
+# -*- coding: utf-8 -*-
+
+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
+
+  import salome
+  import smesh
+
+  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,
+    }
+
+  controls_3d = [
+    "Aspect Ratio 3D",
+    "Volume",
+    "Element Diameter 3D",
+    ]
+  controls_2d = [
+    "Length 2D",
+    "MultiConnection 2D",
+    "Area",
+    "Taper",
+    "Aspect Ratio",
+    "Minimum Angle",
+    "Warping",
+    "Skew",
+    "Element Diameter 2D"
+    ]
+  controls_1d = [
+    "Length",
+    "MultiConnection",
+    ]
+
+  class MinmaxDialog(QDialog):
+    def __init__(self):
+      QDialog.__init__(self, None, Qt.Tool)
+      # Set up the user interface from Designer.
+      self.ui = Ui_Dialog()
+      self.ui.setupUi(self)
+      self.show()
+
+      self.clearLineEdit()
+
+      # Connect up the selectionChanged() event of the object browser.
+      self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+
+      self.mm = None
+      self.ui.control.setFocus()
+      self.select()
+
+      pass
+
+    def OnCancel(self):
+      self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      self.reject()
+      pass
+
+    def clearLineEdit(self):
+      self.ui.mesh.setText("Select a Mesh")
+      self.ui.mesh.setStyleSheet("QLineEdit { color: grey }")
+      self.ui.minvalue.setText("")
+      self.ui.maxvalue.setText("")
+
+    def select(self):
+      self.disconnect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      self.ui.control.clear()
+      self.ui.minvalue.setText("")
+      self.ui.maxvalue.setText("")
+      objId = salome.sg.getSelected(0)
+      if objId:
+        mm = study.FindObjectID(objId).GetObject()
+        mesh = None
+        try:
+          mesh = mm.GetMEDMesh()
+        except:
+          #print "No mesh selected"
+          self.clearLineEdit()
+          mesh = None
+          pass
+        if mesh:
+          self.ui.mesh.setStyleSheet("")
+          self.ui.mesh.setText(mesh.getName())
+          #print "Mesh selected: ", mesh.getName()
+          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
+            pass
+          if f:
+            controls += controls_2d
+            pass
+          if v:
+            controls += controls_3d
+            pass
+          self.ui.control.addItems(controls)
+          self.compute_minmax()
+      self.connect(sg.getObjectBrowser(), SIGNAL("selectionChanged()"), self.select)
+      pass
+
+    def helpMessage(self):
+      QMessageBox.about(None, "About Min/Max value of control",
+      """
+      Displays the min/max value of a control
+      ---------------------------------
+
+This plugin displays the min and max value of a control
+on a mesh.
+Inputs:
+  - The mesh to analyse
+  - The control to compute
+      """)
+      pass
+
+    def compute_minmax(self):
+      if self.mm:
+        control = self.ui.control.currentText()
+        #print "Compute control: ",control
+        fun = smesh.GetFunctor(controls_dict[str(control)])
+        fun.SetMesh(self.mm.GetMesh())
+        hist = fun.GetHistogram(1)
+        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
+
+  window = MinmaxDialog()
+  window.exec_()
+  pass
+
diff --git a/src/SalomeApp/pluginsdemo/smesh_plugins.py b/src/SalomeApp/pluginsdemo/smesh_plugins.py
new file mode 100644 (file)
index 0000000..5515ffc
--- /dev/null
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+#!/usr/bin/env python
+
+import salome_pluginsmanager
+
+DEMO_IS_ACTIVATED = True
+
+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',
+      minmax)