Draft: Support of layers in DXF import

This commit is contained in:
Yorik van Havre
2019-07-03 21:49:50 -03:00
parent b0be0f9ce3
commit 0b38daa862
2 changed files with 25 additions and 6 deletions

View File

@@ -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")
@@ -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
@@ -121,6 +130,13 @@ class Layer:
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:
@@ -207,7 +223,7 @@ class ViewProviderLayer:
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
@@ -285,7 +301,7 @@ class ViewProviderLayer:
menu.addAction(action1)
def activate(self):
if hasattr(self,"Object"):
FreeCADGui.Selection.clearSelection()
FreeCADGui.Selection.addSelection(self.Object)

View File

@@ -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
@@ -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