Material improvements

A forum to discuss the implementation of a good Materials system in FreeCAD
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Material improvements

Postby ian.rees » Tue Sep 25, 2018 4:53 am

Apologies for the delay - I've rebased Eivind's work on to the latest master at https://github.com/ianrrees/FreeCAD_tin ... al2-rebase . Haven't been able to compile it yet, as my machine is only setup for building against Python 3 at the moment, which wasn't supported by the old branch.
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: Material improvements

Postby ian.rees » Tue Sep 25, 2018 5:47 am

OK, I've got a compile (pushed a few fixes to my branch), but am running in to a crash on startup, which seems to relate to initialising Python types. I'm really rusty in this area, and can't see an easy solution:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff54eab38 in PyUnicode_InternInPlace () from /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
(gdb) bt
#0  0x00007ffff54eab38 in PyUnicode_InternInPlace () from /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#1  0x00007ffff54eac0d in PyUnicode_InternFromString () from /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#2  0x00007ffff5595545 in PyType_Ready () from /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#3  0x00007ffff5597408 in PyType_Ready () from /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
#4  0x00007ffff5b0fac2 in Py::PythonType::readyType (this=0x5555557b60f0)
    at /home/irees/Projects/freecad-code/src/CXX/Python3/cxx_extensions.cxx:283
#5  0x00007ffff64866e3 in Py::SolidMaterialArray::init_type ()
    at /home/irees/Projects/freecad-code/src/App/PropertyPartMaterial.cpp:321
#6  0x00007ffff64860f4 in Py::PropertyPartMaterial::init_type ()
    at /home/irees/Projects/freecad-code/src/App/PropertyPartMaterial.cpp:423
#7  0x00007ffff64d4615 in App::Application::initTypes ()
    at /home/irees/Projects/freecad-code/src/App/Application.cpp:1359
#8  0x00007ffff64d4421 in App::Application::init (argc=1, argv=0x7fffffffdbe8)
    at /home/irees/Projects/freecad-code/src/App/Application.cpp:1253
#9  0x000055555555c38e in main (argc=1, argv=0x7fffffffdbe8)
    at /home/irees/Projects/freecad-code/src/Main/MainGui.cpp:192
User avatar
bernd
Posts: 7341
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Material improvements

Postby bernd » Tue Sep 25, 2018 3:22 pm

Great :D compiles and starts for me on Python2 . It even rebases on the latest commits from master

OS: Debian GNU/Linux 9.5 (stretch)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14805 (Git)
Build type: Unknown
Branch: materialian2
Hash: e16950459ae4e9c8e9ffd3852f8ccbe017443d01
Python version: 2.7.13
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.0.0
Locale: German/Switzerland (de_CH)


first find ... it is not possible to load a saved file. Not one saved with master not one saved with this branch.
User avatar
bernd
Posts: 7341
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Material improvements

Postby bernd » Tue Oct 23, 2018 9:34 pm

It still rebases on master https://github.com/berndhahnebach/FreeC ... aterialian

but still the problems resist ...
first find ... it is not possible to load a saved file. Not one saved with master not one saved with this branch.
User avatar
bernd
Posts: 7341
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Material improvements

Postby bernd » Wed Feb 27, 2019 5:17 pm

https://github.com/berndhahnebach/FreeC ... rialeivind

still rebases, but not the material editor ui, but this is no that important. C++ code is still not finished. It would be a pitty if this development would be for trash eventually.

eivindkvedalen wrote: ping
eivindkvedalen
Posts: 591
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Postby eivindkvedalen » Sun Mar 31, 2019 10:53 pm

bernd wrote:
Wed Feb 27, 2019 5:17 pm
https://github.com/berndhahnebach/FreeC ... rialeivind

still rebases, but not the material editor ui, but this is no that important. C++ code is still not finished. It would be a pitty if this development would be for trash eventually.
Rebased on current master: https://github.com/eivindkv/FreeCAD/tree/Material2

It compiles, and it didn't crash when I opened a file :)

Eivind
User avatar
bernd
Posts: 7341
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Material improvements

Postby bernd » Tue Apr 02, 2019 9:30 am

Great! it is compiling ... Seams yor are still on Python2 At the moment I switched back to Py2 too because I had some compile error on Py3. I well report back.
User avatar
bernd
Posts: 7341
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Material improvements

Postby bernd » Tue Apr 02, 2019 4:57 pm

Just a quote from eivind an ealier post to know what is this branch about:


eivindkvedalen wrote:
Sun Aug 21, 2016 8:19 am
Things more or less done:
- Added a MaterialDatabase class. This is the collection of various sources described below. Material queries happens from this database.
- Added a DefaultMaterialSource class. This source is read-only and contains the original pre-defined materials that could be selected in FreeCAD. It also contains a DEFAULT material, that all other materials can inherit from, to ensure that visual properties are defined.
- Added a DocumentMaterialSource class. Per-document materials are stored here. If visualization materials are changed, a copy is stored here.
- Added a FileMaterialSource class. FCMat materials cards are provided by this source. Multiple sources may be added (system/user).
- Added a PropertyPartMaterial class. This class and its helper classes encapsulates materials for solids and surfaces.
- Added a PropertyPartMaterial member Material to Part::Feature, along with its Shape.

I've been focusing on the data structure part now; almost nothing is done on the Gui part, except propagating material colors from the Material property to the view provider, so the colors of the parts change.

I have also added a Python interface (this is what I actually use for testing), and a typical use-case could be:

Code: Select all

App.ActiveDocument.Box.Material.setSolidMaterial(0, "PLA");
This will assign the PLA material to solid 0 of Box. Properties can then be queried, e.g

Code: Select all

App.ActiveDocument.Box.Material.Solid[0].YoungsModulus
Surface materials are accessed as e.g

Code: Select all

App.ActiveDocument.Box.Material.Solid[0].setSurfaceMaterial(0, "GOLD")
(provided that Solid[0] has been set first).

The material databases are accessed either at

Code: Select all

App.getMaterialDatabase()
or

Code: Select all

doc.MaterialDatabase 
(ideally they should have the same syntax; something for later). The material database in App is the application-wide database, so adding/removing/editing materials should be possible to do without an open document. The material database in the document links to the application-wide one, but also provides a private material source for materials specific for the document.

The file-based materials are supposed to be in either

Code: Select all

getResourceDir() + "/Mod/Material/StandardMaterial"
or

Code: Select all

getUserAppDataDir() + "Materials"
User avatar
bernd
Posts: 7341
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: Material improvements

Postby bernd » Tue Apr 02, 2019 5:16 pm

with Python2 and Qt5 I am able to compile this branch. But as soon as an object which has a Shape property is created FreeCAD crashes. Files with meshes or for example an FEM file without the shape saves and reopens fine.

OS: Debian GNU/Linux buster/sid (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16369 (Git)
Build type: Unknown
Branch: materialeivind
Hash: 159b004261e6fc932af376978710911aee26fc4e
Python version: 2.7.16rc1
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Switzerland (de_CH)
eivindkvedalen
Posts: 591
Joined: Tue Jan 29, 2013 10:35 pm

Re: Material improvements

Postby eivindkvedalen » Tue Apr 02, 2019 6:54 pm

bernd wrote:
Tue Apr 02, 2019 5:16 pm
with Python2 and Qt5 I am able to compile this branch. But as soon as an object which has a Shape property is created FreeCAD crashes. Files with meshes or for example an FEM file without the shape saves and reopens fine.
I discovered that as well, and I'm looking into it now...

Eivind