Skip to content

Commit

Permalink
Arch: Fixed window transparency bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Mar 22, 2018
1 parent fa26b06 commit c960e8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/Mod/Arch/ArchWindow.py
Expand Up @@ -73,7 +73,7 @@ def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"):
_Window(obj)
if FreeCAD.GuiUp:
_ViewProviderWindow(obj.ViewObject)
obj.ViewObject.Transparency=p.GetInt("WindowTransparency",85)
#obj.ViewObject.Transparency=p.GetInt("WindowTransparency",85)
if width:
obj.Width = width
if height:
Expand All @@ -98,8 +98,14 @@ def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"):
if obj.Base and FreeCAD.GuiUp:
obj.Base.ViewObject.DisplayMode = "Wireframe"
obj.Base.ViewObject.hide()
from DraftGui import todo
todo.delay(recolorize,obj)
return obj

def recolorize(obj):
if obj.ViewObject:
if obj.ViewObject.Proxy:
obj.ViewObject.Proxy.colorize(obj,force=True)

def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None):
"""makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,[placement]): makes a
Expand Down Expand Up @@ -1029,6 +1035,7 @@ def updateData(self,obj,prop):
if len(obj.Base.ViewObject.DiffuseColor) > 1:
obj.ViewObject.DiffuseColor = obj.Base.ViewObject.DiffuseColor
obj.ViewObject.update()
self.colorize(obj)
elif prop == "CloneOf":
if obj.CloneOf:
mat = None
Expand All @@ -1040,23 +1047,17 @@ def updateData(self,obj,prop):
if len(obj.CloneOf.ViewObject.DiffuseColor) > 1:
obj.ViewObject.DiffuseColor = obj.CloneOf.ViewObject.DiffuseColor
obj.ViewObject.update()
if (prop in ["WindowParts","Shape"]):
if obj.Shape:
if not obj.Shape.isNull():
self.colorize(obj)

def onDelete(self,vobj,subelements):
for o in vobj.Object.Hosts:
o.touch()
return True

def onChanged(self,vobj,prop):
if (prop in ["DiffuseColor","ShapeColor","Transparency"]) and vobj.Object:
if vobj.Object.Base:
if len(vobj.DiffuseColor) < 2:
if vobj.Object.Shape:
if not vobj.Object.Shape.isNull():
self.colorize(vobj.Object)
if (prop in ["DiffuseColor","Transparency"]) and vobj.Object:
self.colorize(vobj.Object)
elif prop == "ShapeColor":
self.colorize(vobj.Object,force=True)
ArchComponent.ViewProviderComponent.onChanged(self,vobj,prop)

def setEdit(self,vobj,mode):
Expand All @@ -1080,13 +1081,18 @@ def unsetEdit(self,vobj,mode):
FreeCADGui.Control.closeDialog()
return

def colorize(self,obj):
def colorize(self,obj,force=False):
"setting different part colors"
if obj.CloneOf:
obj.ViewObject.DiffuseColor = obj.CloneOf.ViewObject.DiffuseColor
if self.areDifferentColors(obj.ViewObject.DiffuseColor,obj.CloneOf.ViewObject.DiffuseColor) or force:
obj.ViewObject.DiffuseColor = obj.CloneOf.ViewObject.DiffuseColor
return
if not obj.WindowParts:
return
if not obj.Shape:
return
if not obj.Shape.Solids:
return
solids = obj.Shape.copy().Solids
#print("Colorizing ", solids)
colors = []
Expand Down Expand Up @@ -1121,9 +1127,16 @@ def colorize(self,obj):
ccol = base
colors.extend([ccol for f in solids[i].Faces])
#print("colors: ",colors)
if len(colors) > 1:
if colors != obj.ViewObject.DiffuseColor:
obj.ViewObject.DiffuseColor = colors
if self.areDifferentColors(colors,obj.ViewObject.DiffuseColor) or force:
obj.ViewObject.DiffuseColor = colors

def areDifferentColors(self,a,b):
if len(a) != len(b):
return True
for i in range(len(a)):
if abs(sum(a[i]) - sum(b[i])) > 0.00001:
return True
return False

class _ArchWindowTaskPanel:
'''The TaskPanel for Arch Windows'''
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Draft/Draft.py
Expand Up @@ -2980,6 +2980,9 @@ def clone(obj,delta=None,forcedraft=False):
pass
if gui:
cl.ViewObject.DiffuseColor = base.ViewObject.DiffuseColor
if obj[0].Proxy.Type == "Window":
from DraftGui import todo
todo.delay(Arch.recolorize,cl)
select(cl)
return cl
else:
Expand Down

0 comments on commit c960e8d

Please sign in to comment.