material editor

A forum to discuss the implementation of a good Materials system in FreeCAD
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

bernd wrote: Wed Jul 04, 2018 4:41 am we do not have this problem in FEM material task panel ...
Yes. Because of the unit acceptance is coded.
https://github.com/FreeCAD/FreeCAD/blob ... aterial.py
That's exactly what I want for the MaterialEditor. A little bit different coded but the same result.
bernd wrote: Wed Jul 04, 2018 4:41 am What do you mean by this?
For example this
unit_constraints.png
unit_constraints.png (7.41 KiB) Viewed 16360 times
The density accepts a negative value. Why do I want to limit the values? Because of my custom workbench. I need to constrain the values that I feed to the processor. The majority of properties are constrained with a schema [<=, <, >, >=]. For the density should be [None, 0, None, None] always bigger than zero.
EDIT: [>=, >, <, <=]
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

Okay. Let's go with a proposal in a few hours ...
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

Firstly, we don't overwrite the method 'setModelData'

Code: Select all


from PySide import QtCore, QtGui
import FreeCADGui
ui = FreeCADGui.UiLoader()


class MaterialDelegate(QtGui.QStyledItemDelegate):

    def createEditor(self, parent, option, index):
        if index.column() == 1:
            # editor = QtGui.QLineEdit()
            editor = ui.createWidget("Gui::InputField")
            editor.setParent(parent)
            return editor

    def setEditorData(self, editor, index):
        print('setEditorData')
        data = index.data()
        editor.setText(data)

    '''def setModelData(self, editor, model, index):
        data = editor.text()
        model.setData(index, data)'''

    def showData(self, model):
        print('showData')
        item = model.item(0, 1)
        print(item.text())


model = QtGui.QStandardItemModel()
tableView = QtGui.QTableView()
tableView.setModel(model)
delegate = MaterialDelegate()
tableView.setItemDelegate(delegate)
item = QtGui.QStandardItem("MyProperty")
it = QtGui.QStandardItem()
it.setText("10 m")
model.appendRow([item, it])
tableView.setWindowTitle("MaterialDelegate")
tableView.show()  

Later on, the model's source of data could be updated with a new function

Code: Select all

delegate.showData(model)
showData
11,00 m
This could be manually (Apply or Save button) or automatically capturing the editor signal.
EDIT: this avoids the problem we're having with Gui::InputField and the class Delegate
Last edited by damian on Wed Jul 04, 2018 4:59 pm, edited 1 time in total.
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

Secondly, a set of custom editors. One editor for every Type of property. For instance: string, float, integer, enumeration, vector ...
The editors must be coded outside the class Delegate, and could be used for all views and widgets everywhere.
The editor must accept a 'units' specification and take care of maintaining it, like in the FEM code.
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

Thirdly, to finish the material's attributes structure. I would like something like (property, type, value, units, ...)
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

The alternative could be don't use Gui::InputField and make a highly customized QLineEdit with the same services as Gui::InputField

EDIT: the points two (custom editors) and three (attributes structure) remain identical
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

https://stackoverflow.com/questions/254 ... gate-in-qt
https://stackoverflow.com/questions/254 ... 0_25427425
P.S. You use a custom delegate for wrong purpose. A custom delegate is needed when you need to paint something which cannot be painted with a standard QStyledItemDelegate. But it can draw icons.
To draw an icon you need to process Qt::DecorationRole in your model like this:

virtual QVariant data (const QModelIndex& index, int role) const
{
...
if (role == Qt::DecorationRole)
return someIcon;
...
}

QStyledItemDelegate draws an icons in the left by default. Here in my comment I suggested to you how to make it paint it in the right side of a row: Delegate erasing text in QTreeView using QStandardItemModel
QAction *QLineEdit::addAction(const QIcon &icon, QLineEdit::ActionPosition position)

This is an overloaded function.

Creates a new action with the given icon at the position.

This function was introduced in Qt 5.2.
https://stackoverflow.com/questions/279 ... -qlineedit
damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

Code: Select all

ui = FreeCADGui.UiLoader()
editor = ui.createWidget("Gui::InputField")
editor.property('text')
editor.property('unit')
editor.property('minimum')
editor.property('maximum')
editor.property('singleStep')
editor.setProperty('unit', 'kg')
editor.property('unit')

damian
Posts: 583
Joined: Sun May 31, 2015 6:16 pm

Re: material editor

Post by damian »

Hello:

Material: MaterialEditor implement model/view
https://github.com/caceres/FreeCAD/comm ... 1a99506ba5

It includes a new file MatPropDict.xml, as the proposal in https://www.freecadweb.org/wiki/Material_data_model
The file's build is not solved ...
Please, if this is a convenient solution, could someone to write a recipe for the installation of the file MatPropDict.xml?

The next months I will be very busy, and I can't follow a complete development, but I could support little corrections, or explanations, of the proposed commit.

Thank everyone.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: material editor

Post by yorik »

Great! Curious to see.
You can have a look at the CMake file in Arch, it installs a couple of .csv files. You could do the same with your xml file. Or simply copy it over together with the .py files...
Post Reply