Import transparent and IFC4 colours
This commit is contained in:
committed by
Yorik van Havre
parent
647f3c0f4b
commit
5da9197bc5
@@ -799,9 +799,12 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
|||||||
|
|
||||||
# color
|
# color
|
||||||
|
|
||||||
if FreeCAD.GuiUp and (pid in colors) and hasattr(obj.ViewObject,"ShapeColor"):
|
if FreeCAD.GuiUp and (pid in colors) and colors[pid]:
|
||||||
# if preferences['DEBUG']: print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255))
|
# if preferences['DEBUG']: print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255))
|
||||||
obj.ViewObject.ShapeColor = colors[pid]
|
if hasattr(obj.ViewObject,"ShapeColor"):
|
||||||
|
obj.ViewObject.ShapeColor = tuple(colors[pid][0:3])
|
||||||
|
if hasattr(obj.ViewObject,"Transparency"):
|
||||||
|
obj.ViewObject.Transparency = colors[pid][3]
|
||||||
|
|
||||||
# if preferences['DEBUG'] is on, recompute after each shape
|
# if preferences['DEBUG'] is on, recompute after each shape
|
||||||
if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute()
|
if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute()
|
||||||
|
|||||||
@@ -347,6 +347,7 @@ def getColorFromStyledItem(styled_item):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
rgb_color = None
|
rgb_color = None
|
||||||
|
transparency = None
|
||||||
|
|
||||||
# print(styled_item)
|
# print(styled_item)
|
||||||
# The IfcStyledItem holds presentation style information for products,
|
# The IfcStyledItem holds presentation style information for products,
|
||||||
@@ -370,7 +371,11 @@ def getColorFromStyledItem(styled_item):
|
|||||||
# never seen an ifc with more than one Styles in IfcStyledItem
|
# never seen an ifc with more than one Styles in IfcStyledItem
|
||||||
else:
|
else:
|
||||||
# get the IfcPresentationStyleAssignment, there should only be one, see above
|
# get the IfcPresentationStyleAssignment, there should only be one, see above
|
||||||
assign_style = styled_item.Styles[0]
|
if styled_item.Styles[0].is_a('IfcPresentationStyleAssignment'):
|
||||||
|
assign_style = styled_item.Styles[0]
|
||||||
|
else:
|
||||||
|
# IfcPresentationStyleAssignment is deprecated in IFC4.
|
||||||
|
assign_style = styled_item
|
||||||
# print(assign_style) # IfcPresentationStyleAssignment
|
# print(assign_style) # IfcPresentationStyleAssignment
|
||||||
|
|
||||||
# IfcPresentationStyleAssignment can hold various kinde and count of styles
|
# IfcPresentationStyleAssignment can hold various kinde and count of styles
|
||||||
@@ -380,6 +385,10 @@ def getColorFromStyledItem(styled_item):
|
|||||||
# print(assign_style.Styles[0].Styles[0]) # IfcSurfaceStyleRendering
|
# print(assign_style.Styles[0].Styles[0]) # IfcSurfaceStyleRendering
|
||||||
rgb_color = assign_style.Styles[0].Styles[0].SurfaceColour # IfcColourRgb
|
rgb_color = assign_style.Styles[0].Styles[0].SurfaceColour # IfcColourRgb
|
||||||
# print(rgb_color)
|
# print(rgb_color)
|
||||||
|
if assign_style.Styles[0].Styles[0].is_a('IfcSurfaceStyleShading') \
|
||||||
|
and hasattr(assign_style.Styles[0].Styles[0], 'Transparency') \
|
||||||
|
and assign_style.Styles[0].Styles[0].Transparency:
|
||||||
|
transparency = assign_style.Styles[0].Styles[0].Transparency * 100
|
||||||
elif assign_style.Styles[0].is_a("IfcCurveStyle"):
|
elif assign_style.Styles[0].is_a("IfcCurveStyle"):
|
||||||
if (
|
if (
|
||||||
len(assign_style.Styles) == 2
|
len(assign_style.Styles) == 2
|
||||||
@@ -398,7 +407,8 @@ def getColorFromStyledItem(styled_item):
|
|||||||
rgb_color = assign_style.Styles[0].CurveColour
|
rgb_color = assign_style.Styles[0].CurveColour
|
||||||
|
|
||||||
if rgb_color is not None:
|
if rgb_color is not None:
|
||||||
col = rgb_color.Red, rgb_color.Green, rgb_color.Blue
|
col = [rgb_color.Red, rgb_color.Green, rgb_color.Blue]
|
||||||
|
col.append(int(transparency) if transparency else 0)
|
||||||
# print(col)
|
# print(col)
|
||||||
else:
|
else:
|
||||||
col = None
|
col = None
|
||||||
|
|||||||
Reference in New Issue
Block a user