Material improvements

Thanks :smiley:

1º) will the MaterialComposition have layers?

No, the matter in a solid consists of a single material. However, this is described by a list of materials. The difference between the composition and the stack is the way how the look-up of its properties is done.

For a composition, the look-up is started at the top of the stack, and the first match is returned. This makes it possible to override sub-sets of a material by stacking another on top. E.g if you read the post by bernd, he would like to have concrete with different values for YoungsModulus. This is possible by having a “standard” concrete at the bottom of the stack, and then different materials with only one property (or a few), YoungsModulus, that differentiates one type of concrete from another.

For surfaces, think of the stack as a bunch of physical layers. When searching for a property, you must first specify the layer in which to do the look-up. As an example, think of an object with a background color and a silk-print on top. One layer would then specify the background color, and the second one could specify a transparent texture that would be put on top. This is how I envision it; it is not implemented yet :slight_smile:

2º) could a solid have a MaterialComposition? The question is with a single solid, no with a compsolids.

Each solid is a MaterialComposition object, and the Material property contains an array of solids to cover compsolids.

3º) how will the thickness of every layer be specified?

This could be specified as a property, but would not easily be reflected in the geometric model.

Eivind

Yes, I know this structure will face the same problems wrt topological naming. I can add string based look-up to the API for completeness; the implementation will most likely change a lot when topological naming is sorted out.

Eivind

Hi Eivind!

I was thinking about this for a while and this weekend i will finally have some time to test it. Is this still the latest branch to test?

https://github.com/eivindkv/free-cad-code/tree/Material

Yes, I have had too little time for FreeCAD lately, so it is still the latest branch…

Eivind

No problem i just wanted to make sure i will try out the latest code. I tried to compile the code today and it looks like 2 files are missing. In src/App/Application.cpp (line 115 and 116):

#include "MaterialDatabasePy.h"
#include "FileMaterialSourcePy.h"

It doesn’t look like this is available ATM.

hmm.. Just try to remove them from Application.cpp. I changed the way I do the Python integration, so I don’t think they are needed anymore.

Eivind

Yes i did that but it didn’t help. I got a lot of errors after for example:

error: ‘FileMaterialSource’ was not declared in this scope
         _pMaterialDatbase->addMaterialSource(std::make_shared<FileMaterialSource>("System", system_dir.c_str()));



note: forward declaration of ‘class App::MaterialDatabase’
 class MaterialDatabase;

About 30 lines of errors and notes.

I recreated the problem here after I removed some old auto-generated files were still in my build directory. I’ve fixed, rebased, and pushed a new branch: https://github.com/eivindkv/free-cad-code/tree/Material2

Eivind

I can confirm this branch compiles now. There are still some (very likely not your changes related) issues involved and i needed to disable few modules to successfully compile your branch. Likely related to this:

http://forum.freecadweb.org/viewtopic.php?f=10&t=16021&start=30#p140382

Therefore you might want to provide a branch containing the latest changes in the future for other testers compiling without issues. I tested as described:

http://forum.freecadweb.org/viewtopic.php?f=10&t=16714&start=10#p134905

It seems to work OK but if i try to:

App.ActiveDocument.Box.Material.Solid[0].YoungsModulus

I get:

RuntimeError: Unable to resolve property YoungsModulus (missing material?)

Therefore i am guessing you just added sample code and PLA material isn’t available yet in the database?

I think that the PLA material definition isn’t in the right location; I think I had to copy the files manually when testing. The file-based materials are supposed to be in either

getResourceDir() + “/Mod/Material/StandardMaterial”

or

getUserAppDataDir() + “Materials”

Eivind

Hi Eivind.

I tested this by moving materials in all mentioned locations and tested a few more. The same issue was always produced. Therefore best to leave it as it is for now and in the future when you will start working on it again we can test further.

I think i got the general idea. Your work will very likely enable FreeCAD and all its modules to use materials in straightforward fashion in the future.

I’ve rebased this to the current master: https://github.com/ianrrees/FreeCAD_tinkering/tree/20170226-material2-rebase Looks cool! -Ian-

Thank you for taking to do the rebasing, iirc I got some conflicts last time I looked into this. Currently I’m super busy, so I’m not sure when I can work more on this. Also, I’d like to finish the hole-feature first, as that is closer to completion…

Eivind

I know a few guys who will be happy to read that…

IMHO geometry creation should always come first.

:mrgreen:

No worries! I’ll try to keep my branch rebased occasionally. Might even try to do a bit of work on it once a few other things are popped off the TODO stack.

Parallelism is where it’s at! :slight_smile:

which branch has the latest development?

Lately I did some development on Material module of FreeCAD. I started to sort out some devs but stopped because einvind did all the work already. He even did it ten times better than just some better Python devs for material handling. OK, I gave it a try and started to rebase eivinds branch https://github.com/eivindkv/free-cad-code/tree/Material2 but had to give up. To much conflicts on FreeCADs insides on C++ I do not have a glue how to solve. It would be really cool if we could give this great development new live and somehow could rebase it on master …

bernd

It’s good to see attention in this area bernd. I think it will be easier for you to update from the branch on my github mentioned a few posts back here, rather than eivind’s original work. I’ll try to update that branch sometime soon - not likely to be in the next week as I have some work to get done on the car which has a hard deadline…

oh yeah your branch has much more less conflicts … I gave a rebase a try but eventually run into trouble on compiling …

[ 10%] Built target FreeCADBase
[ 10%] Building CXX object src/App/CMakeFiles/FreeCADApp.dir/MaterialComposition.cpp.o
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/App/MaterialComposition.cpp: In constructor ‘App::MaterialComposition::MaterialComposition(App::PropertyPartMaterial*, int)’:
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/App/MaterialComposition.cpp:73:76: warning: unused parameter ‘_solid’ [-Wunused-parameter]
 MaterialComposition::MaterialComposition(PropertyPartMaterial *_owner, int _solid)
                                                                            ^~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/App/MaterialComposition.cpp: In member function ‘virtual Py::Object Py::MaterialCompositionPy::getattr(const char*)’:
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/App/MaterialComposition.cpp:204:123: error: no matching function for call to ‘Py::Exception::Exception(std::__cxx11::basic_string<char>)’
                 throw Py::Exception(boost::str(boost::format("Unable to resolve property %1% (missing material?)") % name));
                                                                                                                           ^
In file included from /home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Exception.hxx:40:0,
                 from /home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Objects.hxx:44,
                 from /home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Extensions.hxx:52,
                 from /home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Extensions.hxx:40,
                 from /home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/App/MaterialComposition.h:29,
                 from /home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/App/MaterialComposition.cpp:31:
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:76:9: note: candidate: Py::Exception::Exception(PyObject*, Py::Object&)
         Exception (PyObject* exception, Object &reason);
         ^~~~~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:76:9: note:   candidate expects 2 arguments, 1 provided
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:71:9: note: candidate: Py::Exception::Exception(PyObject*, const string&)
         Exception (PyObject* exception, const std::string& reason)
         ^~~~~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:71:9: note:   candidate expects 2 arguments, 1 provided
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:62:18: note: candidate: Py::Exception::Exception()
         explicit Exception ()
                  ^~~~~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:62:18: note:   candidate expects 0 arguments, 1 provided
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:60:9: note: candidate: Py::Exception::Exception(Py::ExtensionExceptionType&, Py::Object&)
         Exception( ExtensionExceptionType &exception, Object &reason );
         ^~~~~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:60:9: note:   candidate expects 2 arguments, 1 provided
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:59:9: note: candidate: Py::Exception::Exception(Py::ExtensionExceptionType&, const string&)
         Exception( ExtensionExceptionType &exception, const std::string& reason );
         ^~~~~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:59:9: note:   candidate expects 2 arguments, 1 provided
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:56:24: note: candidate: constexpr Py::Exception::Exception(const Py::Exception&)
     class PYCXX_EXPORT Exception
                        ^~~~~~~~~
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:56:24: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘const Py::Exception&’
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:56:24: note: candidate: constexpr Py::Exception::Exception(Py::Exception&&)
/home/hugo/Documents/dev/freecad/freecadbhb_dev/freecad/src/CXX/Python2/Exception.hxx:56:24: note:   no known conversion for argument 1 from ‘std::__cxx11::basic_string<char>’ to ‘Py::Exception&&’
src/App/CMakeFiles/FreeCADApp.dir/build.make:1382: die Regel für Ziel „src/App/CMakeFiles/FreeCADApp.dir/MaterialComposition.cpp.o“ scheiterte
make[2]: *** [src/App/CMakeFiles/FreeCADApp.dir/MaterialComposition.cpp.o] Fehler 1
CMakeFiles/Makefile2:776: die Regel für Ziel „src/App/CMakeFiles/FreeCADApp.dir/all“ scheiterte
make[1]: *** [src/App/CMakeFiles/FreeCADApp.dir/all] Fehler 2
Makefile:127: die Regel für Ziel „all“ scheiterte
make: *** [all] Fehler 2
hugo@ahorn:~/Documents/dev/freecad/freecadbhb_dev/build$

Seams I need to wait for you ian.

BTW you will get some problems with material-editor.ui This is something I changed lately and I would fix if all the other would compile and run. Just checkout one of the ui files.