From d17fb3aa5d120217491ceba159dcc667a0da6452 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sun, 9 Feb 2014 20:50:07 +0100 Subject: [PATCH] First tests of using InputField via Python --- src/Gui/InputField.cpp | 11 ++++++ src/Gui/InputField.h | 6 +++- src/Mod/Fem/MechanicalMaterial.py | 48 ++++++++++++------------- src/Mod/Fem/MechanicalMaterial.ui | 59 ++++++++++++++----------------- 4 files changed, 64 insertions(+), 60 deletions(-) diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 34ae8b0fb..7c5545a89 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -329,6 +329,17 @@ void InputField::setMinimum(double m) Minimum = m; } +void InputField::setUnitText(QString str) +{ + Base::Quantity quant = Base::Quantity::parse(str); + setUnit(quant.getUnit()); +} + +QString InputField::getUnitText(void) +{ + return actUnitStr; +} + // get the value of the minimum property int InputField::historySize(void)const { diff --git a/src/Gui/InputField.h b/src/Gui/InputField.h index 3c31be05f..e0fd46aa2 100644 --- a/src/Gui/InputField.h +++ b/src/Gui/InputField.h @@ -52,6 +52,7 @@ class GuiExport InputField : public QLineEdit Q_PROPERTY(double maximum READ maximum WRITE setMaximum ) Q_PROPERTY(double minimum READ minimum WRITE setMinimum ) Q_PROPERTY(int historySize READ historySize WRITE setHistorySize ) + Q_PROPERTY(QString unit READ getUnitText WRITE setUnitText ) public: @@ -88,7 +89,10 @@ public: int historySize(void)const; /// set the value of the minimum property void setHistorySize(int); - + /// set the unit by a string (can be used in the *.ui file) + void setUnitText(QString); + /// get the unit as a string (can be used in the *.ui file) + QString getUnitText(void); /// set the number portion selected (use after setValue()) void selectNumber(void); diff --git a/src/Mod/Fem/MechanicalMaterial.py b/src/Mod/Fem/MechanicalMaterial.py index 2d7a1290d..b13672840 100644 --- a/src/Mod/Fem/MechanicalMaterial.py +++ b/src/Mod/Fem/MechanicalMaterial.py @@ -128,20 +128,13 @@ class _ViewProviderMechanicalMaterial: class _MechanicalMaterialTaskPanel: '''The editmode TaskPanel for MechanicalMaterial objects''' def __init__(self,obj): - # the panel has a tree widget that contains categories - # for the subcomponents, such as additions, subtractions. - # the categories are shown only if they are not empty. - form_class, base_class = uic.loadUiType(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui") - self.obj = obj - self.formUi = form_class() - self.form = QtGui.QWidget() - self.formUi.setupUi(self.form) + + self.form=FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/MechanicalMaterial.ui") self.params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Fem") - - QtCore.QObject.connect(self.formUi.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb) - QtCore.QObject.connect(self.formUi.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat) + QtCore.QObject.connect(self.form.pushButton_MatWeb, QtCore.SIGNAL("clicked()"), self.goMatWeb) + QtCore.QObject.connect(self.form.comboBox_MaterialsInDir, QtCore.SIGNAL("currentIndexChanged(int)"), self.chooseMat) self.update() @@ -150,10 +143,11 @@ class _MechanicalMaterialTaskPanel: matmap = self.obj.Material - matmap['Mechanical_youngsmodulus'] = str(self.formUi.spinBox_young_modulus.value() * 1e+6) - matmap['FEM_poissonratio'] = str(self.formUi.spinBox_poisson_ratio.value()) + matmap['Mechanical_youngsmodulus'] = self.form.spinBox_young_modulus.text() + matmap['FEM_poissonratio'] = str(self.form.spinBox_poisson_ratio.value()) self.obj.Material = matmap + print matmap def transferFrom(self): @@ -161,11 +155,11 @@ class _MechanicalMaterialTaskPanel: matmap = self.obj.Material if matmap.has_key('Mechanical_youngsmodulus'): - print float(matmap['Mechanical_youngsmodulus']) - self.formUi.spinBox_young_modulus.setValue(float(matmap['Mechanical_youngsmodulus'])/1e+6) + print matmap['Mechanical_youngsmodulus'] + self.form.spinBox_young_modulus.setText(matmap['Mechanical_youngsmodulus']) if matmap.has_key('FEM_poissonratio'): - print float(matmap['FEM_poissonratio']) - self.formUi.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio'])) + #print float(matmap['FEM_poissonratio']) + self.form.spinBox_poisson_ratio.setValue(float(matmap['FEM_poissonratio'])) def isAllowedAlterSelection(self): return False @@ -178,8 +172,8 @@ class _MechanicalMaterialTaskPanel: def update(self): 'fills the widgets' - self.formUi.spinBox_young_modulus.setValue(0.0) - self.formUi.spinBox_poisson_ratio.setValue(0.0) + #self.form.spinBox_young_modulus.setValue(0.0) + #self.form.spinBox_poisson_ratio.setValue(0.0) self.transferFrom() self.fillMaterialCombo() @@ -187,10 +181,12 @@ class _MechanicalMaterialTaskPanel: return def accept(self): + print 'accept(self)' self.transferTo() FreeCADGui.ActiveDocument.resetEdit() def reject(self): + print 'reject(self)' FreeCADGui.ActiveDocument.resetEdit() def saveMat(self): @@ -207,12 +203,12 @@ class _MechanicalMaterialTaskPanel: def chooseMat(self,index): if index == 0:return import Material - print index + #print index name = self.pathList[index-1] - print 'Import ', str(name) + #print 'Import ', str(name) self.obj.Material = Material.importFCMat(str(name)) - print self.obj.Material + #print self.obj.Material self.transferFrom() @@ -221,13 +217,13 @@ class _MechanicalMaterialTaskPanel: matmap = self.obj.Material dirname = FreeCAD.ConfigGet("AppHomePath")+"data/Mod/Material/StandardMaterial" self.pathList = glob.glob(dirname + '/*.FCMat') - self.formUi.comboBox_MaterialsInDir.clear() + self.form.comboBox_MaterialsInDir.clear() if(matmap.has_key('General_name')): - self.formUi.comboBox_MaterialsInDir.addItem(matmap['General_name']) + self.form.comboBox_MaterialsInDir.addItem(matmap['General_name']) else: - self.formUi.comboBox_MaterialsInDir.addItem('-> choose Material') + self.form.comboBox_MaterialsInDir.addItem('-> choose Material') for i in self.pathList: - self.formUi.comboBox_MaterialsInDir.addItem(os.path.basename(i) ) + self.form.comboBox_MaterialsInDir.addItem(os.path.basename(i) ) diff --git a/src/Mod/Fem/MechanicalMaterial.ui b/src/Mod/Fem/MechanicalMaterial.ui index 120266931..48cebddb5 100644 --- a/src/Mod/Fem/MechanicalMaterial.ui +++ b/src/Mod/Fem/MechanicalMaterial.ui @@ -6,8 +6,8 @@ 0 0 - 196 - 142 + 188 + 124 @@ -34,27 +34,17 @@ - - - - Qt::Horizontal - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Qt::Horizontal + + + + Young's Modulus: - - + + 0 @@ -70,28 +60,31 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + Pa + + 3 - + 2000.000000000000000 - + 2.000000000000000 - + 0.000000000000000 - - + + - Young's Mod.(GPa) + Poisson Ratio: - + @@ -122,17 +115,17 @@ - - - - Poisson Ratio - - - + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+