Merge pull request #7885 from Roy-043/Draft-fix-clone-DiffuseColor
Draft: fix clone DiffuseColor
This commit is contained in:
@@ -78,7 +78,7 @@ def make_clone(obj, delta=None, forcedraft=False):
|
||||
if utils.get_type(obj[0]) == "BuildingPart":
|
||||
cl = Arch.makeComponent()
|
||||
else:
|
||||
try: # new-style maek function
|
||||
try: # new-style make function
|
||||
cl = getattr(Arch, "make_" + obj[0].Proxy.Type.lower())()
|
||||
except Exception:
|
||||
try: # old-style make function
|
||||
@@ -100,11 +100,11 @@ def make_clone(obj, delta=None, forcedraft=False):
|
||||
except Exception:
|
||||
pass
|
||||
if App.GuiUp:
|
||||
gui_utils.format_object(cl,base)
|
||||
cl.ViewObject.DiffuseColor = base.ViewObject.DiffuseColor
|
||||
if utils.get_type(obj[0]) in ["Window","BuildingPart"]:
|
||||
ToDo.delay(Arch.recolorize,cl)
|
||||
gui_utils.select(cl)
|
||||
gui_utils.format_object(cl, base)
|
||||
# Workaround to trigger update of DiffuseColor:
|
||||
ToDo.delay(lambda col: setattr(cl.ViewObject, "DiffuseColor", col),
|
||||
cl.ViewObject.DiffuseColor)
|
||||
gui_utils.select(cl)
|
||||
return cl
|
||||
# fall back to Draft clone mode
|
||||
if not cl:
|
||||
@@ -112,19 +112,23 @@ def make_clone(obj, delta=None, forcedraft=False):
|
||||
cl.addExtension("Part::AttachExtensionPython")
|
||||
cl.Label = prefix + obj[0].Label
|
||||
Clone(cl)
|
||||
if App.GuiUp:
|
||||
ViewProviderClone(cl.ViewObject)
|
||||
cl.Objects = obj
|
||||
if delta:
|
||||
cl.Placement.move(delta)
|
||||
elif (len(obj) == 1) and hasattr(obj[0],"Placement"):
|
||||
cl.Placement = obj[0].Placement
|
||||
gui_utils.format_object(cl,obj[0])
|
||||
if hasattr(cl,"LongName") and hasattr(obj[0],"LongName"):
|
||||
cl.LongName = obj[0].LongName
|
||||
if App.GuiUp and (len(obj) > 1):
|
||||
cl.ViewObject.Proxy.resetColors(cl.ViewObject)
|
||||
gui_utils.select(cl)
|
||||
if App.GuiUp:
|
||||
ViewProviderClone(cl.ViewObject)
|
||||
gui_utils.format_object(cl, obj[0])
|
||||
if len(obj) > 1 or hasattr(obj[0], "Group"):
|
||||
cl.ViewObject.Proxy.resetColors(cl.ViewObject)
|
||||
# Workaround to trigger update of DiffuseColor:
|
||||
# Note: only works if obj contains 1 object.
|
||||
ToDo.delay(lambda col: setattr(cl.ViewObject, "DiffuseColor", col),
|
||||
cl.ViewObject.DiffuseColor)
|
||||
gui_utils.select(cl)
|
||||
return cl
|
||||
|
||||
|
||||
|
||||
@@ -56,22 +56,28 @@ class ViewProviderClone:
|
||||
colors = []
|
||||
for o in groups.get_group_contents(vobj.Object.Objects):
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
if len(o.ViewObject.DiffuseColor) > 1:
|
||||
if len(o.ViewObject.DiffuseColor) == len(o.Shape.Faces):
|
||||
colors.extend(o.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = o.ViewObject.ShapeColor
|
||||
c = (c[0],c[1],c[2],o.ViewObject.Transparency/100.0)
|
||||
colors += [c] * len(o.Shape.Faces) # TODO: verify this line
|
||||
c = (c[0], c[1], c[2], o.ViewObject.Transparency / 100.0)
|
||||
colors += [c] * len(o.Shape.Faces)
|
||||
elif o.hasExtension("App::GeoFeatureGroupExtension"):
|
||||
for so in vobj.Object.Group:
|
||||
for so in o.Group:
|
||||
if so.isDerivedFrom("Part::Feature"):
|
||||
if len(so.ViewObject.DiffuseColor) > 1:
|
||||
if len(so.ViewObject.DiffuseColor) == len(so.Shape.Faces):
|
||||
colors.extend(so.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = so.ViewObject.ShapeColor
|
||||
c = (c[0],c[1],c[2],so.ViewObject.Transparency/100.0)
|
||||
c = (c[0], c[1], c[2], so.ViewObject.Transparency / 100.0)
|
||||
colors += [c] * len(so.Shape.Faces)
|
||||
if colors:
|
||||
first_color = colors[0]
|
||||
for next_color in colors[1:]:
|
||||
if next_color != first_color:
|
||||
break
|
||||
else:
|
||||
colors = [first_color]
|
||||
vobj.DiffuseColor = colors
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user