Skip to content

Commit

Permalink
ShapeColor to ShapeMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
davesrocketshop committed Mar 16, 2024
1 parent f86dcde commit 8bbc04e
Show file tree
Hide file tree
Showing 25 changed files with 9 additions and 67 deletions.
10 changes: 0 additions & 10 deletions src/Mod/Arch/ArchBuildingPart.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ def __init__(self,vobj):
#vobj.addExtension("Gui::ViewProviderGeoFeatureGroupExtensionPython")
vobj.Proxy = self
self.setProperties(vobj)
# vobj.ShapeColor = ArchCommands.getDefaultColor("Helpers")
vobj.ShapeAppearance.DiffuseColor = ArchCommands.getDefaultColor("Helpers")

def setProperties(self,vobj):
Expand Down Expand Up @@ -689,7 +688,6 @@ def attach(self,vobj):
self.txt.string.setValue("level")
self.sep.addChild(self.txt)
vobj.addDisplayMode(self.sep,"Default")
# self.onChanged(vobj,"ShapeColor")
self.onChanged(vobj,"ShapeAppearance")
self.onChanged(vobj,"FontName")
self.onChanged(vobj,"ShowLevel")
Expand Down Expand Up @@ -736,12 +734,10 @@ def getColors(self,obj):
colors = []
for child in Draft.get_group_contents(obj, walls=True):
if not Draft.get_type(child) in ["Space"]:
# if hasattr(child,'Shape') and (hasattr(child.ViewObject,"DiffuseColor") or hasattr(child.ViewObject,"ShapeColor")):
if hasattr(child,'Shape') and (hasattr(child.ViewObject,"DiffuseColor") or hasattr(child.ViewObject,"ShapeAppearance")):
if hasattr(child.ViewObject,"DiffuseColor") and len(child.ViewObject.DiffuseColor) == len(child.Shape.Faces):
colors.extend(child.ViewObject.DiffuseColor)
else:
# c = child.ViewObject.ShapeColor[:3]+(child.ViewObject.Transparency/100.0,)
c = child.ViewObject.ShapeAppearance.DiffuseColor[:3]+(child.ViewObject.Transparency/100.0,)
for i in range(len(child.Shape.Faces)):
colors.append(c)
Expand All @@ -751,10 +747,6 @@ def onChanged(self,vobj,prop):

#print(vobj.Object.Label," - ",prop)

# if prop == "ShapeColor":
# if hasattr(vobj,"ShapeColor"):
# l = vobj.ShapeColor
# self.mat.diffuseColor.setValue([l[0],l[1],l[2]])
if prop == "ShapeAppearance":
if hasattr(vobj,"ShapeAppearance"):
l = vobj.ShapeAppearance.DiffuseColor
Expand Down Expand Up @@ -809,10 +801,8 @@ def onChanged(self,vobj,prop):
if isinstance(txt,unicode):
txt = txt.encode("utf8")
self.txt.string.setValue(txt)
# elif prop in ["ChildrenOverride","ChildenLineWidth","ChildrenLineColor","ChildrenShapeColor","ChildrenTransparency"]:
elif prop in ["ChildrenOverride","ChildenLineWidth","ChildrenLineColor","ChildrenShapeAppearance","ChildrenTransparency"]:
if hasattr(vobj,"ChildrenOverride") and vobj.ChildrenOverride:
# props = ["ChildenLineWidth","ChildrenLineColor","ChildrenShapeColor","ChildrenTransparency"]
props = ["ChildenLineWidth","ChildrenLineColor","ChildrenShapeAppearance","ChildrenTransparency"]
for child in vobj.Object.Group:
for prop in props:
Expand Down
5 changes: 0 additions & 5 deletions src/Mod/Arch/ArchCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ def setAsSubcomponent(obj):
obj.ViewObject.LineColor = color
if hasattr(obj.ViewObject, "PointColor"):
obj.ViewObject.PointColor = color
# if hasattr(obj.ViewObject,"ShapeColor"):
# obj.ViewObject.ShapeColor = color
if hasattr(obj.ViewObject,"ShapeAppearance"):
obj.ViewObject.ShapeAppearance.DiffuseColor = color
if hasattr(obj.ViewObject,"Transparency"):
Expand Down Expand Up @@ -292,7 +290,6 @@ def splitMesh(obj,mark=True):
newobj = FreeCAD.ActiveDocument.addObject("Mesh::Feature",basename)
newobj.Mesh = c
if mark and (not(c.isSolid()) or c.hasNonManifolds()):
# newobj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0)
newobj.ViewObject.ShapeAppearance.DiffuseColor = (1.0,0.0,0.0,1.0)
nlist.append(newobj)
return nlist
Expand Down Expand Up @@ -576,7 +573,6 @@ def meshToShape(obj,mark=True,fast=True,tol=0.001,flat=False,cut=True):
#newobj.Placement = plac #the placement is already computed in the mesh
if (not solid.isClosed()) or (not solid.isValid()):
if mark:
# newobj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0)
newobj.ViewObject.ShapeAppearance.DiffuseColor = (1.0,0.0,0.0,1.0)
return newobj
return None
Expand Down Expand Up @@ -625,7 +621,6 @@ def removeShape(objs,mark=True):
ArchWall.makeWall(line,width=width,height=dims[3],name=name)
else:
if mark:
# obj.ViewObject.ShapeColor = (1.0,0.0,0.0,1.0)
obj.ViewObject.ShapeAppearance.DiffuseColor = (1.0,0.0,0.0,1.0)

def mergeCells(objectslist):
Expand Down
14 changes: 3 additions & 11 deletions src/Mod/Arch/ArchComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ def updateData(self,obj,prop):
"""Method called when the host object has a property changed.
If the object has a Material associated with it, match the view
object's ShapeColor and Transparency to match the Material.
object's ShapeAppearance and Transparency to match the Material.
If the object is now cloned, or is part of a compound, have the view
object inherit the DiffuseColor.
Expand All @@ -1203,8 +1203,6 @@ def updateData(self,obj,prop):
if "(" in obj.Material.Material['DiffuseColor']:
c = tuple([float(f) for f in obj.Material.Material['DiffuseColor'].strip("()").split(",")])
if obj.ViewObject:
# if obj.ViewObject.ShapeColor != c:
# obj.ViewObject.ShapeColor = c
if obj.ViewObject.ShapeAppearance.DiffuseColor != c:
obj.ViewObject.ShapeAppearance.DiffuseColor = c
if 'Transparency' in obj.Material.Material:
Expand Down Expand Up @@ -1257,7 +1255,7 @@ def onChanged(self,vobj,prop):
If DiffuseColor changes, change DiffuseColor to copy the host object's
clone, if it exists.
If ShapeColor changes, overwrite it with DiffuseColor.
If ShapeAppearance changes, overwrite it with DiffuseColor.
If Visibility changes, propagate the change to all view objects that
are also hosted by this view object's host.
Expand All @@ -1283,14 +1281,8 @@ def onChanged(self,vobj,prop):
if vobj.DiffuseColor != vobj.Object.CloneOf.ViewObject.DiffuseColor:
vobj.DiffuseColor = vobj.Object.CloneOf.ViewObject.DiffuseColor
vobj.update()
# elif prop == "ShapeColor":
# # restore DiffuseColor after overridden by ShapeColor
# if hasattr(vobj,"DiffuseColor"):
# if len(vobj.DiffuseColor) > 1:
# d = vobj.DiffuseColor
# vobj.DiffuseColor = d
elif prop == "ShapeAppearance":
# restore DiffuseColor after overridden by ShapeColor
# restore DiffuseColor after overridden by ShapeAppearance
if hasattr(vobj,"DiffuseColor"):
if len(vobj.DiffuseColor) > 1:
d = vobj.DiffuseColor
Expand Down
3 changes: 0 additions & 3 deletions src/Mod/Arch/ArchCurtainWall.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,6 @@ def onChanged(self,vobj,prop):

if (prop in ["DiffuseColor","Transparency"]) and vobj.Object:
self.colorize(vobj.Object)
# elif prop == "ShapeColor":
# self.colorize(vobj.Object,force=True)
elif prop == "ShapeAppearance":
self.colorize(vobj.Object,force=True)
ArchComponent.ViewProviderComponent.onChanged(self,vobj,prop)
Expand All @@ -578,7 +576,6 @@ def colorize(self,obj,force=False):

if not obj.Shape or not obj.Shape.Solids:
return
# basecolor = obj.ViewObject.ShapeColor
basecolor = obj.ViewObject.ShapeAppearance.DiffuseColor
basetransparency = obj.ViewObject.Transparency/100.0
panelcolor = ArchCommands.getDefaultColor("WindowGlass")
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchCutPlane.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def __init__(self):
_, self.base, self.cutter = _getShapes(FreeCADGui.Selection.getSelectionEx("", 0))

self.previewObj = FreeCAD.ActiveDocument.addObject("Part::Feature", "PreviewCutVolume")
# self.previewObj.ViewObject.ShapeColor = (1.00, 0.00, 0.00)
self.previewObj.ViewObject.ShapeAppearance.DiffuseColor = (1.00, 0.00, 0.00)
self.previewObj.ViewObject.Transparency = 75

Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def execute(self,obj):
for p in obj.InList:
if hasattr(p,"Material") and ( (not hasattr(p.ViewObject,"UseMaterialColor")) or p.ViewObject.UseMaterialColor):
if p.Material.Name == obj.Name:
# p.ViewObject.ShapeColor = c
p.ViewObject.ShapeAppearance.DiffuseColor = c
return

Expand Down
2 changes: 0 additions & 2 deletions src/Mod/Arch/ArchPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ class _ViewProviderPanel(ArchComponent.ViewProviderComponent):
def __init__(self,vobj):

ArchComponent.ViewProviderComponent.__init__(self,vobj)
# vobj.ShapeColor = ArchCommands.getDefaultColor("Panel")
vobj.ShapeAppearance.DiffuseColor = ArchCommands.getDefaultColor("Panel")

def getIcon(self):
Expand All @@ -790,7 +789,6 @@ def updateData(self,obj,prop):
if len(activematerials) == len(obj.Shape.Solids):
cols = []
for i,mat in enumerate(activematerials):
# c = obj.ViewObject.ShapeColor
c = obj.ViewObject.ShapeAppearance.DiffuseColor
c = (c[0],c[1],c[2],obj.ViewObject.Transparency/100.0)
if 'DiffuseColor' in mat.Material:
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchPrecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,6 @@ class _ViewProviderPrecast(ArchComponent.ViewProviderComponent):
def __init__(self,vobj):

ArchComponent.ViewProviderComponent.__init__(self,vobj)
# vobj.ShapeColor = ArchCommands.getDefaultColor("Structure")
vobj.ShapeAppearance.DiffuseColor = ArchCommands.getDefaultColor("Structure")

def getIcon(self):
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchRebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ def __init__(self,vobj):

ArchComponent.ViewProviderComponent.__init__(self,vobj)
self.setProperties(vobj)
# vobj.ShapeColor = ArchCommands.getDefaultColor("Rebar")
vobj.ShapeAppearance.DiffuseColor = ArchCommands.getDefaultColor("Rebar")

def setProperties(self,vobj):
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/Arch/ArchSectionPlane.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ def getFillForObject(o, defaultFill, source):
return material.SectionColor
elif hasattr(material, 'Color') and material.Color:
return material.Color
# elif hasattr(o,"ViewObject") and hasattr(o.ViewObject,"ShapeColor"):
# return o.ViewObject.ShapeColor
elif hasattr(o,"ViewObject") and hasattr(o.ViewObject,"ShapeAppearance"):
return o.ViewObject.ShapeAppearance.DiffuseColor
return defaultFill
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchStructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,6 @@ def __init__(self,vobj):
ArchComponent.ViewProviderComponent.setProperties(self, vobj)

self.setProperties(vobj)
# vobj.ShapeColor = ArchCommands.getDefaultColor("Structure")
vobj.ShapeAppearance.DiffuseColor = ArchCommands.getDefaultColor("Structure")

def setProperties(self,vobj):
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchVRM.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def addObjects(self,objs):
for o in objs:
if o.isDerivedFrom("Part::Feature"):
self.objects.append(o)
# color = o.ViewObject.ShapeColor
color = o.ViewObject.ShapeAppearance.DiffuseColor
if o.Shape.Faces:
self.shapes.append([o.Shape,color])
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/Arch/ArchWall.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,6 @@ class _ViewProviderWall(ArchComponent.ViewProviderComponent):

def __init__(self,vobj):
ArchComponent.ViewProviderComponent.__init__(self,vobj)
# vobj.ShapeColor = ArchCommands.getDefaultColor("Wall")
vobj.ShapeAppearance.DiffuseColor = ArchCommands.getDefaultColor("Wall")

def getIcon(self):
Expand Down Expand Up @@ -1673,7 +1672,6 @@ def updateData(self,obj,prop):
if len(activematerials) == len(obj.Shape.Solids):
cols = []
for i,mat in enumerate(activematerials):
# c = obj.ViewObject.ShapeColor
c = obj.ViewObject.ShapeAppearance.DiffuseColor
c = (c[0],c[1],c[2],obj.ViewObject.Transparency/100.0)
if 'DiffuseColor' in mat.Material:
Expand Down
3 changes: 0 additions & 3 deletions src/Mod/Arch/ArchWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,6 @@ def onChanged(self,vobj,prop):

if (prop in ["DiffuseColor","Transparency"]) and vobj.Object:
self.colorize(vobj.Object)
# elif prop == "ShapeColor":
# self.colorize(vobj.Object,force=True)
elif prop == "ShapeAppearance":
self.colorize(vobj.Object,force=True)
ArchComponent.ViewProviderComponent.onChanged(self,vobj,prop)
Expand All @@ -1155,7 +1153,6 @@ def colorize(self,obj,force=False):
solids = obj.Shape.copy().Solids
#print("Colorizing ", solids)
colors = []
# base = obj.ViewObject.ShapeColor
base = obj.ViewObject.ShapeAppearance.DiffuseColor
for i in range(len(solids)):
ccol = None
Expand Down
4 changes: 1 addition & 3 deletions src/Mod/Arch/OfflineRenderingUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def getColors(filename,nodiffuse=False):
of tuples if per-face colors are available. In case of DiffuseColors,
tuples can have 4 values (RGBT) (T = transparency, inverse of alpha)
This is a reduced version of getGuiData(), which returns more information.
If nodiffuse = True, DiffuseColor info is discarded, only ShapeColor is read."""
If nodiffuse = True, DiffuseColor info is discarded, only ShapeAppearance is read."""

guidata = getGuiData(filename)
colors = {}
Expand All @@ -288,8 +288,6 @@ def getColors(filename,nodiffuse=False):
colors[k] = v["DiffuseColor"]["value"][0]
else:
colors[k] = v["DiffuseColor"]["value"]
# elif "ShapeColor" in v:
# colors[k] = v["ShapeColor"]["value"]
elif "ShapeAppearance" in v:
colors[k] = v["ShapeAppearance"]["value"]
return colors
Expand Down
3 changes: 0 additions & 3 deletions src/Mod/Arch/exportIFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,6 @@ def export(exportList, filename, colors=None, preferences=None):
print("Unable to handle object",anno.Label)
continue

# for coldef in ["LineColor","TextColor","ShapeColor"]:
for coldef in ["LineColor","TextColor","ShapeAppearance"]:
if hasattr(obj.ViewObject,coldef):
rgb = getattr(obj.ViewObject,coldef)[:3]
Expand Down Expand Up @@ -2327,12 +2326,10 @@ def getRepresentation(
# this is a diffusecolor. For now, use the first color - #TODO: Support per-face colors
diffusecolor = color
shapecolor = color[0]
# elif FreeCAD.GuiUp and (not subtraction) and hasattr(obj.ViewObject,"ShapeColor"):
elif FreeCAD.GuiUp and (not subtraction) and hasattr(obj.ViewObject,"ShapeAppearance"):
# every object gets a surface style. If the obj has a material, the surfstyle
# is named after it. Revit will treat surfacestyles as materials (and discard
# actual ifcmaterial)
# shapecolor = obj.ViewObject.ShapeColor[:3]
shapecolor = obj.ViewObject.ShapeAppearance.DiffuseColor[:3]
transparency = obj.ViewObject.Transparency/100.0
if hasattr(obj.ViewObject,"DiffuseColor"):
Expand Down
4 changes: 1 addition & 3 deletions src/Mod/Arch/importDAE.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def read(filename):
obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature","Mesh")
obj.Mesh = newmesh
if color and FreeCAD.GuiUp:
obj.ViewObject.ShapeColor = color
obj.ViewObject.ShapeAppearance.DiffuseColor = color


def export(exportList,filename,tessellation=1,colors=None):
Expand Down Expand Up @@ -282,9 +282,7 @@ def export(exportList,filename,tessellation=1,colors=None):
matref = "ref_"+obj.Name
matnode = collada.scene.MaterialNode(matref, mat, inputs=[])
elif FreeCAD.GuiUp:
# if hasattr(obj.ViewObject,"ShapeColor"):
if hasattr(obj.ViewObject,"ShapeAppearance"):
# kd = obj.ViewObject.ShapeColor[:3]
kd = obj.ViewObject.ShapeAppearance.DiffuseColor[:3]
effect = collada.material.Effect("effect_"+obj.Name, [], "phong", diffuse=kd, specular=(1,1,1))
mat = collada.material.Material("mat_"+obj.Name, obj.Name, effect)
Expand Down
8 changes: 3 additions & 5 deletions src/Mod/Arch/importIFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,6 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
if FreeCAD.GuiUp:
# if preferences['DEBUG']:
# print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255))
# if hasattr(obj.ViewObject,"ShapeColor"):
# obj.ViewObject.ShapeColor = tuple(colors[pid][0:3])
if hasattr(obj.ViewObject,"ShapeAppearance"):
obj.ViewObject.ShapeAppearance.DiffuseColor = tuple(colors[pid][0:3])
if hasattr(obj.ViewObject,"Transparency"):
Expand Down Expand Up @@ -1234,7 +1232,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
# overwritten by the material color (if there is a material with a color).
# In such a case FreeCAD shows a different color than all common ifc viewers
# https://forum.freecad.org/viewtopic.php?f=39&t=38440
col = objects[o].ViewObject.ShapeColor[:3]
col = objects[o].ViewObject.ShapeAppearance.DiffuseColor[:3]
dig = 5
ma_color = sh_color = round(col[0], dig), round(col[1], dig), round(col[2], dig)
if "DiffuseColor" in objects[o].Material.Material:
Expand Down Expand Up @@ -1277,8 +1275,8 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
continue
# the method make_layer does some nasty debug prints
lay = Draft.make_layer(layer_name)
# ShapeColor and LineColor are not set, thus some some default values are used
# do not override the imported ShapeColor and LineColor with default layer values
# ShapeAppearance and LineColor are not set, thus some some default values are used
# do not override the imported ShapeAppearance and LineColor with default layer values
if FreeCAD.GuiUp:
lay.ViewObject.OverrideLineColorChildren = False
lay.ViewObject.OverrideShapeAppearanceChildren = False
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/Arch/importIFCHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,6 @@ def applyColorDict(doc,colordict=None):
for obj in doc.Objects:
if obj.Name in colordict:
color = colordict[obj.Name]
# if hasattr(obj.ViewObject,"ShapeColor"):
# obj.ViewObject.ShapeColor = tuple(color[0:3])
if hasattr(obj.ViewObject,"ShapeAppearance"):
obj.ViewObject.ShapeAppearance.DiffuseColor = tuple(color[0:3])
if hasattr(obj.ViewObject,"Transparency") and (len(color) >= 4):
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/importIFClegacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ def export(exportList,filename):

# get color
if FreeCAD.GuiUp:
# color = obj.ViewObject.ShapeColor[:3]
color = obj.ViewObject.ShapeAppearance.DiffuseColor[:3]

# get parent floor
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/importIFCmulticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ def setColor(obj,ifcproduct):
color = importIFCHelper.getColorFromProduct(ifcproduct)
colors[obj.Name] = color
if FreeCAD.GuiUp and color:
# obj.ViewObject.ShapeColor = color[:3]
obj.ViewObject.ShapeAppearance.DiffuseColor = color[:3]


Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/importJSON.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def getObjectData(obj):
if FreeCADGui:
result['color'] = \
Draft.getrgb(obj.ViewObject.ShapeAppearance.DiffuseColor, testbw = False)
# Draft.getrgb(obj.ViewObject.ShapeColor, testbw = False)

if obj.isDerivedFrom("Part::Feature"):
mesh = Mesh.Mesh(obj.Shape.tessellate(0.1))
Expand Down
Loading

0 comments on commit 8bbc04e

Please sign in to comment.