Skip to content

Commit

Permalink
test for default color from preferences in OpenSCAD/Explode command
Browse files Browse the repository at this point in the history
  • Loading branch information
5263 authored and wwmayer committed Mar 21, 2015
1 parent 1846087 commit 089174c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Mod/OpenSCAD/OpenSCADCommands.py
Expand Up @@ -43,9 +43,23 @@ def IsActive(self):
return FreeCADGui.Selection.countObjectsOfType('Part::Feature') > 0

def Activated(self):
def isdefault(shapecolor):
def comparefloat(f1,f2):
if f1 == 0.0:
return f1 == f2
else:
return abs((f1-f2)/f1) < 2**-24
scol=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")\
.GetUnsigned('DefaultShapeColor',0xccccccff)
defaultcolor = (((scol >> 24) & 0xff) / 255.0,\
((scol >> 16) & 0xff) / 255.0,\
((scol >> 8) & 0xff) / 255.0, 0.0)
return all(all(comparefloat(fcc,dcc) for fcc,dcc in \
zip(facecolor,defaultcolor)) for facecolor in shapecolor)

def isgrey(shapecolor):
defaultcolor=(float.fromhex('0x1.99999ap-1'),float.fromhex('0x1.99999ap-1'),\
float.fromhex('0x1.99999ap-1'),0.0)
defaultcolor=(float.fromhex('0x1.99999ap-1'),float.fromhex(\
'0x1.99999ap-1'),float.fromhex('0x1.99999ap-1'),0.0)
return all(facecolor == defaultcolor for facecolor in shapecolor)

def randomcolor(transp=0.0):
Expand All @@ -68,7 +82,7 @@ def explode(obj,color=True):
if FreeCAD.GuiUp:
import FreeCADGui
oo.ViewObject.show()
if color and isgrey(oo.ViewObject.DiffuseColor):
if color and isdefault(oo.ViewObject.DiffuseColor):
if color == True:
oo.ViewObject.DiffuseColor=randomcolor()
else:
Expand Down

0 comments on commit 089174c

Please sign in to comment.