Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fem: Save and restore custom colors of elements in mesh - fixes #6131 #13698

Merged
merged 1 commit into from May 6, 2024

Conversation

marioalexis84
Copy link
Member

@marioalexis84 marioalexis84 commented Apr 28, 2024

This fixes #6131 FemMesh coloring issue (fix #5815 requires one more step, since currently only first-order meshes are colored correctly).
With this pull request it is possible to save and restore custom colors on meshes, including transparency.
An enumeration property ColorMode is added to select the color mode. There are three options:

  • Overall: The color of the object is determined entirely by ShapeAppearance property.
  • ByElement: The mesh is colored by element based on the values of the ElementColorArray property.
  • ByNode: The mesh is colored by node based on the values of the NodeColorArray property.

Properties NodeColorArray and ElementColorArray are added to set custom diffuse colors on meshes.
They behave as is next below:

  • The array contains a single color: This color is used for all elements.
  • Less values than geometry elements: for the remaining values ShapeAppearance diffuse color is used.
  • More values than geometry elements: excedent values are ignored.

Python ElementColor and NodeColor attributes of the view provider receive a dictionary with ID-color as key-value pair. The ID can be indicated individually or as tuple of ID's associated with a color.
For example:

import Fem
a = Fem.FemMesh()

a.addNode(0,    0,    0,    1)
a.addNode(10,    0,    0,    2)
a.addNode(5,    10,    0,    3)
a.addNode(15,    15,    0,    4)

a.addFace([1,2,3], 1)
a.addFace([2,4,3], 2)
obj = FreeCAD.ActiveDocument.addObject("Fem::FemMeshObject")
#obj.Placement.Base = FreeCAD.Vector(2, 0, 0)
obj.FemMesh = a

obj.ViewObject.ElementColor = {1:(1,0,0)}     # set element ID=1 to red, remaining items are filled with ShapeAppearance diffuse color

obj.ViewObject.ElementColor = {(1,2):(0,0,1)}     # set element ID=1,2 to blue

@FEA-eng , @maxwxyz

@github-actions github-actions bot added the WB FEM Related to the FEM Workbench label Apr 28, 2024
@FEA-eng
Copy link
Contributor

FEA-eng commented Apr 29, 2024

I’ll try to test it next week, probably on Monday.

@yorikvanhavre yorikvanhavre merged commit 1b6fa97 into FreeCAD:main May 6, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WB FEM Related to the FEM Workbench
Projects
None yet
3 participants