Skip to content

Commit

Permalink
[Arch] ArchMaterial 0.18 Fix Crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Syres916 authored and yorikvanhavre committed Nov 5, 2019
1 parent 980bf90 commit 44f6e86
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Mod/Arch/ArchMaterial.py
Expand Up @@ -259,14 +259,23 @@ def __init__(self,obj):
obj.addProperty("App::PropertyPercent","Transparency","Arch",QT_TRANSLATE_NOOP("App::Property","The transparency value of this material"))
obj.addProperty("App::PropertyColor","Color","Arch",QT_TRANSLATE_NOOP("App::Property","The color of this material"))

def isSameColor(self,c1,c2):

r = 4
if round(c1[0],r) == round(c2[0],r):
if round(c1[1],r) == round(c2[1],r):
if round(c1[2],r) == round(c2[2],r):
return True
return False

def onChanged(self,obj,prop):

d = obj.Material
if prop == "Material":
if "DiffuseColor" in obj.Material:
c = tuple([float(f) for f in obj.Material['DiffuseColor'].strip("()").split(",")])
if hasattr(obj,"Color"):
if obj.Color != c:
if not self.isSameColor(obj.Color,c):
obj.Color = c
if "Transparency" in obj.Material:
t = int(obj.Material['Transparency'])
Expand Down Expand Up @@ -296,11 +305,10 @@ def onChanged(self,obj,prop):
d["Name"] = obj.Label
elif prop == "Color":
if hasattr(obj,"Color"):
val = str(obj.Color[:3])
if "DiffuseColor" in d:
if d["DiffuseColor"] == val:
if self.isSameColor(tuple([float(f) for f in d['DiffuseColor'].strip("()").split(",")]),obj.Color[:3]):
return
d["DiffuseColor"] = val
d["DiffuseColor"] = str(obj.Color[:3])
elif prop == "Transparency":
if hasattr(obj,"Transparency"):
val = str(obj.Transparency)
Expand Down Expand Up @@ -517,6 +525,11 @@ def accept(self):
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()

def reject(self):
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Control.closeDialog()
FreeCAD.ActiveDocument.recompute()

def chooseMat(self, card):
"sets self.material from a card"
if card in self.cards:
Expand Down

0 comments on commit 44f6e86

Please sign in to comment.