Fix for creating/changing colors in material card

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!
Nocturnial

Fix for creating/changing colors in material card

Post by Nocturnial »

Changing the diffuse color and creating specular, emissive,... colors didn't work in the material card dialog. The patch below should fix that. If those changes are ok do I issue a PR or should I create a tracking issue first?

https://github.com/FreeCAD/FreeCAD/comp ... e:matcolor
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Fix for creating/changing colors in material card

Post by Kunda1 »

Nocturnial wrote: Mon Sep 02, 2019 10:29 am Changing the diffuse color and creating specular, emissive,... colors didn't work in the material card dialog. The patch below should fix that. If those changes are ok do I issue a PR or should I create a tracking issue first?

https://github.com/FreeCAD/FreeCAD/comp ... e:matcolor
Lets ping some of the Material folks to review your code.
yorik wrote:
moult wrote:
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fix for creating/changing colors in material card

Post by bernd »

No need to make a PR. I will have a look and merge if it is ok
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fix for creating/changing colors in material card

Post by bernd »

What exactly does not work with the integer color representation? I could not find anything wrong. Would it be possible to give some step by step example.
Nocturnial

Re: Fix for creating/changing colors in material card

Post by Nocturnial »

These steps are for the 0.19 pre-release (exact details below) but they are also present in the master branch (HEAD github)

Can't edit diffuse color:
1) Run freecad
2) (menu) File->New
3) Switch to arch workbench
4) (menu) Arch->Material tools->Material
5) in combo view in the tab tasks, you see the where you can enter things like name, Description, color, etc.. of the material
6) Next to name click the clipboard icon to bring up the material card editor
7) Scroll to diffuse color and double click the value to edit
=> Nothing happens but in report view I see:

Code: Select all

Traceback (most recent call last):
  File "E:\work\programs\FreeCAD_0.19.17515_x64_Conda_Py3QT5-WinVS2015\Mod\Material\MaterialEditor.py", line 526, in createEditor
    editor = matProperWidget(parent, matproperty, Type, Value)
  File "E:\work\programs\FreeCAD_0.19.17515_x64_Conda_Py3QT5-WinVS2015\Mod\Material\MaterialEditor.py", line 624, in matProperWidget
    value = string2tuple(Value)
  File "E:\work\programs\FreeCAD_0.19.17515_x64_Conda_Py3QT5-WinVS2015\Mod\Material\MaterialEditor.py", line 653, in string2tuple
    value = [int(v) for v in value]
  File "E:\work\programs\FreeCAD_0.19.17515_x64_Conda_Py3QT5-WinVS2015\Mod\Material\MaterialEditor.py", line 653, in <listcomp>
    value = [int(v) for v in value]
ValueError: invalid literal for int() with base 10: '0.5019607843137255'
I can't seem to reproduce the exact steps that caused me troubles for the other colors (emissive,...). Maybe it was caused because at the time I was experimenting with mixed c++, python debugging. I don't know.

In any case, the diffuse color is stored as three floats and it would make things easier if the other colors for rendering in the material card are stored in the same format. If you're worried about compatibility issues let me know.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17505 (Git)
Build type: Release
Branch: master
Hash: 755536e9df94d2d39da1468420f1fd333c35da7a
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Fix for creating/changing colors in material card

Post by yorik »

Indeed inside FreeCAD float-based colors are used everywhere and if I'm not mistaken, int-based (1->255) colors are never used anywhere except inside FCStd files, but that is invisible to the user. For me the patch looks good
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fix for creating/changing colors in material card

Post by bernd »

yorik wrote: Thu Sep 05, 2019 8:55 pm Indeed inside FreeCAD float-based colors are used everywhere and if I'm not mistaken, int-based (1->255) colors are never used anywhere except inside FCStd files, but that is invisible to the user. For me the patch looks good
But editing the mat files by "Hand" is nearly impossible. Since the color has lots of diggits with the float it is not easy to use exact the same color. IT might be a different because of the last diggit to be different because of numerical problems.

It is difficault to describe my concerns about the use of floats in the mat cards.

Ahh the int based colors are used in the gui! This is what the user sees. And the color numbers in the mat files ist what the user sees too.

Means any no code API, no matter if it is the GUI, the FCStd file or the mat cards uses the int based system.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Fix for creating/changing colors in material card

Post by bernd »

Nocturnial

Re: Fix for creating/changing colors in material card

Post by Nocturnial »

bernd wrote: Thu Oct 03, 2019 1:30 pm may be related https://forum.freecadweb.org/viewtopic.php?f=23&t=39802
I really doubt it, but I could be wrong. The infinite loop and stack overflow problem sounds like a 0.18 problem which was fixed in 0.19(pre). I had the same problem and either searched the forum or github, but in any case IIRC someone reported this and it was fixed. Let them try master or a 0.19(pre) package for their distro. I'm using 0.19(pre) for windows for this specific reason.

The problem of floats vs ints is rather benign. As far as I know it only results in not displaying the qt color picker instead of crashing.
User avatar
petit_chat_noir
Posts: 87
Joined: Wed Oct 02, 2019 6:45 pm

Re: Fix for creating/changing colors in material card

Post by petit_chat_noir »

bernd wrote: Thu Oct 03, 2019 1:30 pm may be related https://forum.freecadweb.org/viewtopic.php?f=23&t=39802
Yes, I've compiled 0.19pre and the problem is solved. So this bug is 0.18.3 related...
Post Reply