Skip to content
Permalink
Browse files

First tests of using InputField via Python

  • Loading branch information...
jriegel committed Feb 9, 2014
1 parent 58fda26 commit d17fb3aa5d120217491ceba159dcc667a0da6452
Showing with 64 additions and 60 deletions.
  1. +11 −0 src/Gui/InputField.cpp
  2. +5 −1 src/Gui/InputField.h
  3. +22 −26 src/Mod/Fem/MechanicalMaterial.py
  4. +26 −33 src/Mod/Fem/MechanicalMaterial.ui
@@ -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
{
@@ -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 @@ class GuiExport InputField : public QLineEdit
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);

@@ -128,20 +128,13 @@ def __setstate__(self,state):
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,22 +143,23 @@ def transferTo(self):

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):
"Transfer from the object to the dialog"
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,19 +172,21 @@ def getStandardButtons(self):

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()


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 @@ def goMatWeb(self):
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 @@ def fillMaterialCombo(self):
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) )



@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>196</width>
<height>142</height>
<width>188</width>
<height>124</height>
</rect>
</property>
<property name="windowTitle">
@@ -34,27 +34,17 @@
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Young's Modulus:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QDoubleSpinBox" name="spinBox_young_modulus">
<item row="0" column="1">
<widget class="Gui::InputField" name="spinBox_young_modulus">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -70,28 +60,31 @@
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="decimals">
<property name="unit" stdset="0">
<string>Pa</string>
</property>
<property name="decimals" stdset="0">
<number>3</number>
</property>
<property name="maximum">
<property name="maximum" stdset="0">
<double>2000.000000000000000</double>
</property>
<property name="singleStep">
<property name="singleStep" stdset="0">
<double>2.000000000000000</double>
</property>
<property name="value">
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_6">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Young's Mod.(GPa)</string>
<string>Poisson Ratio:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinBox_poisson_ratio">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -122,17 +115,17 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Poisson Ratio</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit d17fb3a

Please sign in to comment.
You can’t perform that action at this time.