From fc0f3ee4fb4ea96ae268652e692a2504392e1b92 Mon Sep 17 00:00:00 2001 From: gdd Date: Tue, 6 Mar 2012 15:12:11 +0000 Subject: [PATCH] Add missing files for previous commit --- src/SalomeApp/pluginsdemo/minmax.ui | 148 ++++++++++++++++++ src/SalomeApp/pluginsdemo/minmax_dialog.py | 73 +++++++++ src/SalomeApp/pluginsdemo/minmax_plugin.py | 165 +++++++++++++++++++++ src/SalomeApp/pluginsdemo/smesh_plugins.py | 14 ++ 4 files changed, 400 insertions(+) create mode 100644 src/SalomeApp/pluginsdemo/minmax.ui create mode 100644 src/SalomeApp/pluginsdemo/minmax_dialog.py create mode 100644 src/SalomeApp/pluginsdemo/minmax_plugin.py create mode 100644 src/SalomeApp/pluginsdemo/smesh_plugins.py diff --git a/src/SalomeApp/pluginsdemo/minmax.ui b/src/SalomeApp/pluginsdemo/minmax.ui new file mode 100644 index 000000000..3c9eafd98 --- /dev/null +++ b/src/SalomeApp/pluginsdemo/minmax.ui @@ -0,0 +1,148 @@ + + + Dialog + + + + 0 + 0 + 178 + 156 + + + + Get min and max value of control + + + true + + + + + + Mesh + + + + + + + true + + + + + + + Control + + + + + + + + + + Min + + + + + + + true + + + + + + + Max + + + + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Help + + + + + + + mesh + control + minvalue + maxvalue + buttonBox + + + + + buttonBox + rejected() + Dialog + OnCancel() + + + 253 + 371 + + + 262 + 101 + + + + + buttonBox + helpRequested() + Dialog + helpMessage() + + + 131 + 373 + + + 131 + 64 + + + + + control + activated(QString) + Dialog + compute_minmax() + + + 250 + 137 + + + 131 + 81 + + + + + + compute_minmax() + helpMessage() + OnCancel() + OnOk() + + diff --git a/src/SalomeApp/pluginsdemo/minmax_dialog.py b/src/SalomeApp/pluginsdemo/minmax_dialog.py new file mode 100644 index 000000000..c7d310e9f --- /dev/null +++ b/src/SalomeApp/pluginsdemo/minmax_dialog.py @@ -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 index 000000000..14be18312 --- /dev/null +++ b/src/SalomeApp/pluginsdemo/minmax_plugin.py @@ -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 index 000000000..5515ffc95 --- /dev/null +++ b/src/SalomeApp/pluginsdemo/smesh_plugins.py @@ -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) -- 2.39.2