Skip to content

Commit

Permalink
Draft: Support of layers in DXF import
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jul 4, 2019
1 parent 2d8f7ef commit 5bc05c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src/Mod/Draft/DraftLayer.py
Expand Up @@ -34,9 +34,10 @@ def QT_TRANSLATE_NOOP(ctx,txt):
"This module contains everything related to Draft Layers"


def makeLayer(name=None):
def makeLayer(name=None,linecolor=None,drawstyle=None,shapecolor=None,transparency=None):

'''makeLayer([name]): creates a Layer object in the active document'''
'''makeLayer([name,linecolor,drawstyle,shapecolor,transparency]):
creates a Layer object in the active document'''

if not FreeCAD.ActiveDocument:
FreeCAD.Console.PrintError(translate("draft","No active document. Aborting")+"\n")
Expand All @@ -49,6 +50,14 @@ def makeLayer(name=None):
obj.Label = translate("draft","Layer")
if FreeCAD.GuiUp:
ViewProviderLayer(obj.ViewObject)
if linecolor:
obj.ViewObject.LineColor = linecolor
if drawstyle:
obj.ViewObject.DrawStyle = drawstyle
if shapecolor:
obj.ViewObject.ShapeColor = shapecolor
if transparency:
obj.ViewObject.Transparency = transparency
getLayerContainer().addObject(obj)
return obj

Expand Down Expand Up @@ -121,6 +130,13 @@ def __setstate__(self,state):
def execute(self,obj):
pass

def addObject(self,obj,child):

g = obj.Group
if not child in g:
g.append(child)
obj.Group = g


class ViewProviderLayer:

Expand Down Expand Up @@ -207,7 +223,7 @@ def onChanged(self,vobj,prop):
for o in vobj.Object.Group:
if o.ViewObject and hasattr(o.ViewObject,"Visibility"):
o.ViewObject.Visibility = vobj.Visibility

if (prop in ["LineColor","ShapeColor"]) and hasattr(vobj,"LineColor") and hasattr(vobj,"ShapeColor"):
from PySide import QtCore,QtGui
lc = vobj.LineColor
Expand Down Expand Up @@ -285,7 +301,7 @@ def setupContextMenu(self,vobj,menu):
menu.addAction(action1)

def activate(self):

if hasattr(self,"Object"):
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(self.Object)
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/Draft/importDXF.py
Expand Up @@ -222,7 +222,7 @@ def locateLayer(wantedLayer,color=None):
if wantedLayerName==l.Label:
return l
if dxfUseDraftVisGroups:
newLayer = Draft.makeVisGroup(name=wantedLayer)
newLayer = Draft.makeLayer(name=wantedLayer,linecolor=color)
else:
newLayer = doc.addObject("App::DocumentObjectGroup",wantedLayer)
newLayer.Label = wantedLayerName
Expand Down Expand Up @@ -982,7 +982,10 @@ def addObject(shape,name="Shape",layer=None):
newob = shape
if layer:
lay=locateLayer(layer)
lay.addObject(newob)
if hasattr(lay,"addObject"):
lay.addObject(newob)
elif hasattr(lay,"Proxy") and hasattr(lay.Proxy,"addObject"):
lay.Proxy.addObject(lay,newob)
formatObject(newob)
return newob

Expand Down

0 comments on commit 5bc05c2

Please sign in to comment.