From 29ec98df8d2e06f1af19167fc03e0eb5bd7baa64 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Thu, 15 Jul 2021 08:30:12 +0200 Subject: [PATCH] Material, workaround for precision problem --- src/Mod/Material/MaterialEditor.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Mod/Material/MaterialEditor.py b/src/Mod/Material/MaterialEditor.py index c3db367b64..51cf4ab14c 100644 --- a/src/Mod/Material/MaterialEditor.py +++ b/src/Mod/Material/MaterialEditor.py @@ -649,17 +649,23 @@ class MaterialsDelegate(QtGui.QStyledItemDelegate): else: super(MaterialsDelegate, self).setEditorData(editor, index) - print("item2={}".format(item.text())) + # print("item2={}".format(item.text())) ui = FreeCADGui.UiLoader() def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, - minimum=None, maximum=None, stepsize=None, precision=None): + minimum=None, maximum=None, stepsize=None, precision=12): '''customs widgets for the material stuff.''' + # FIXME + # Workaround for problem from here: + # https://forum.freecadweb.org/viewtopic.php?f=18&t=56912&start=20#p516811 + # set precision to 12 + # it is strange, but for the user defined values everything works fine + if Type == "String": widget = ui.createWidget("Gui::PrefLineEdit") @@ -675,23 +681,31 @@ def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, lineEdit = widget.children()[1] lineEdit.setText(Value) - elif Type == "Quantity": + elif Type == "Quantity" or Type == "Float": widget = ui.createWidget("Gui::InputField") + # print(matproperty) if hasattr(FreeCAD.Units, matproperty): unit = getattr(FreeCAD.Units, matproperty) quantity = FreeCAD.Units.Quantity(1, unit) widget.setProperty('unit', quantity.getUserPreferred()[2]) else: - FreeCAD.Console.PrintError('Not known unit for property: {}\n'.format(matproperty)) + FreeCAD.Console.PrintWarning( + "Not known unit for property: {}. Probably the Quantity does not have a unit.\n" + .format(matproperty) + ) + # the Gui::InputField is used for Floats too, because of the diggits elif Type == "Integer": widget = ui.createWidget("Gui::UIntSpinBox") - elif Type == "Float": + # elif Type == "Float": - widget = ui.createWidget("Gui::PrefDoubleSpinBox") + # widget = ui.createWidget("Gui::PrefDoubleSpinBox") + # has only 2 diggits precision, but for example RelativePermittivity needs much more + # see material card for Air, thus Workaround + # a "Gui::InputField" without unit is used elif Type == "Enumerator":