Skip to content

Commit

Permalink
Draft: Introduced Layers system (former VisGroup)
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jun 5, 2019
1 parent 9161a87 commit 5ee99ca
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 121 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Arch/InitGui.py
Expand Up @@ -79,7 +79,7 @@ def IsActive(self):
"Draft_SelectGroup","Draft_SelectPlane",
"Draft_ShowSnapBar","Draft_ToggleGrid","Draft_UndoLine",
"Draft_FinishLine","Draft_CloseLine"]
self.draftutils = ["Draft_VisGroup","Draft_Heal","Draft_FlipDimension",
self.draftutils = ["Draft_Layer","Draft_Heal","Draft_FlipDimension",
"Draft_ToggleConstructionMode","Draft_ToggleContinueMode","Draft_Edit",
"Draft_Slope","Draft_SetWorkingPlaneProxy","Draft_AddConstruction"]
self.snapList = ['Draft_Snap_Lock','Draft_Snap_Midpoint','Draft_Snap_Perpendicular',
Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ SET(Draft_SRCS
DraftTrackers.py
DraftVecUtils.py
DraftGeomUtils.py
DraftLayer.py
WorkingPlane.py
getSVG.py
importDXF.py
Expand Down
107 changes: 15 additions & 92 deletions src/Mod/Draft/Draft.py
Expand Up @@ -67,6 +67,15 @@ def translate(ctx,txt):

arrowtypes = ["Dot","Circle","Arrow","Tick","Tick-2"]

#---------------------------------------------------------------------------
# Backwards compatibility
#---------------------------------------------------------------------------

import DraftLayer
_VisGroup = DraftLayer.Layer
_ViewProviderVisGroup = DraftLayer.ViewProviderLayer
makeLayer = DraftLayer.makeLayer

#---------------------------------------------------------------------------
# General functions
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -123,6 +132,8 @@ def getParam(param,default=None):
if t == "int":
if default == None:
default = 0
if param == "linewidth":
return FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetInt("DefaultShapeLineWidth",default)
return p.GetInt(param,default)
elif t == "string":
if default == None:
Expand Down Expand Up @@ -150,7 +161,10 @@ def setParam(param,value):
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
t = getParamType(param)
if t == "int":
p.SetInt(param,value)
if param == "linewidth":
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").SetInt("DefaultShapeLineWidth",value)
else:
p.SetInt(param,value)
elif t == "string":
p.SetString(param,value)
elif t == "float":
Expand Down Expand Up @@ -1338,21 +1352,6 @@ def makeEllipse(majradius,minradius,placement=None,face=True,support=None):

return obj

def makeVisGroup(group=None,name="VisGroup"):
'''makeVisGroup([group]): creates a VisGroup object in the given group, or in the
active document if no group is given'''
if not FreeCAD.ActiveDocument:
FreeCAD.Console.PrintError("No active document. Aborting\n")
return
obj = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",name)
_VisGroup(obj)
if FreeCAD.GuiUp:
_ViewProviderVisGroup(obj.ViewObject)
formatObject(obj)
if group:
group.addObject(obj)
return obj

def extrude(obj,vector,solid=False):
'''makeExtrusion(object,vector): extrudes the given object
in the direction given by the vector. The original object
Expand Down Expand Up @@ -6275,82 +6274,6 @@ def unsetEdit(self,vobj,mode):
return False


class _VisGroup:
"The VisGroup object"
def __init__(self,obj):
self.Type = "VisGroup"
obj.Proxy = self
self.Object = obj

def __getstate__(self):
return self.Type

def __setstate__(self,state):
if state:
self.Type = state

def execute(self,obj):
pass

class _ViewProviderVisGroup:
"A View Provider for the VisGroup object"
def __init__(self,vobj):
vobj.addProperty("App::PropertyColor","LineColor","Base","")
vobj.addProperty("App::PropertyColor","ShapeColor","Base","")
vobj.addProperty("App::PropertyFloat","LineWidth","Base","")
vobj.addProperty("App::PropertyEnumeration","DrawStyle","Base","")
vobj.addProperty("App::PropertyInteger","Transparency","Base","")
vobj.DrawStyle = ["Solid","Dashed","Dotted","Dashdot"]
vobj.LineWidth = 1
vobj.LineColor = (0.13,0.15,0.37)
vobj.DrawStyle = "Solid"
vobj.Proxy = self

def getIcon(self):
import Arch_rc
return ":/icons/Draft_VisGroup.svg"

def attach(self,vobj):
self.Object = vobj.Object
return

def claimChildren(self):
return self.Object.Group

def __getstate__(self):
return None

def __setstate__(self,state):
return None

def updateData(self,obj,prop):
if prop == "Group":
if obj.ViewObject:
obj.ViewObject.Proxy.onChanged(obj.ViewObject,"LineColor")

def onChanged(self,vobj,prop):
if hasattr(vobj,"Object"):
if vobj.Object:
if hasattr(vobj.Object,"Group"):
if vobj.Object.Group:
for o in vobj.Object.Group:
if o.ViewObject:
for p in ["LineColor","ShapeColor","LineWidth","DrawStyle","Transparency"]:
if hasattr(vobj,p):
if hasattr(o.ViewObject,p):
setattr(o.ViewObject,p,getattr(vobj,p))
elif hasattr(o,p):
# for Drawing views
setattr(o,p,getattr(vobj,p))
elif (p == "DrawStyle") and hasattr(o,"LineStyle"):
# Special case in Drawing views
setattr(o,"LineStyle",getattr(vobj,p))
if vobj.Object.InList:
# touch the page if something was changed
if vobj.Object.InList[0].isDerivedFrom("Drawing::FeaturePage"):
vobj.Object.InList[0].touch()


class WorkingPlaneProxy:

"The Draft working plane proxy object"
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/DraftGui.py
Expand Up @@ -1958,7 +1958,7 @@ def getDefaultColor(self,type,rgb=False):
g = float(self.color.green()/255.0)
b = float(self.color.blue()/255.0)
elif type == "face":
color = facecolor = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)
color = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View").GetUnsigned("DefaultShapeColor",4294967295)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
Expand Down

0 comments on commit 5ee99ca

Please sign in to comment.