Draft: fixes to dxf & svg exporters to work in console mode

This commit is contained in:
Yorik van Havre 2013-06-28 14:13:35 -03:00
parent b2c635e40c
commit c6d512ccab
2 changed files with 40 additions and 25 deletions

View File

@ -1284,6 +1284,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
def getLineStyle(obj): def getLineStyle(obj):
"returns a linestyle pattern for a given object" "returns a linestyle pattern for a given object"
if gui:
if obj.ViewObject: if obj.ViewObject:
if hasattr(obj.ViewObject,"DrawStyle"): if hasattr(obj.ViewObject,"DrawStyle"):
ds = obj.ViewObject.DrawStyle ds = obj.ViewObject.DrawStyle
@ -1485,23 +1486,36 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
n += 1 n += 1
elif obj.isDerivedFrom('Part::Feature'): elif obj.isDerivedFrom('Part::Feature'):
if obj.Shape.isNull(): return '' if obj.Shape.isNull():
return ''
if gui:
color = getrgb(obj.ViewObject.LineColor) color = getrgb(obj.ViewObject.LineColor)
else:
color = "#000000"
# setting fill # setting fill
if obj.Shape.Faces and (obj.ViewObject.DisplayMode != "Wireframe"): if obj.Shape.Faces:
if gui:
if (obj.ViewObject.DisplayMode != "Wireframe"):
if fillstyle == "shape color": if fillstyle == "shape color":
fill = getrgb(obj.ViewObject.ShapeColor) fill = getrgb(obj.ViewObject.ShapeColor)
else: else:
fill = 'url(#'+fillstyle+')' fill = 'url(#'+fillstyle+')'
svg += getPattern(fillstyle) svg += getPattern(fillstyle)
else:
fill = "none"
else:
fill = "#888888"
else: else:
fill = 'none' fill = 'none'
lstyle = getLineStyle(obj) lstyle = getLineStyle(obj)
name = obj.Name name = obj.Name
if gui:
if obj.ViewObject.DisplayMode == "Shaded": if obj.ViewObject.DisplayMode == "Shaded":
stroke = "none" stroke = "none"
else: else:
stroke = getrgb(obj.ViewObject.LineColor) stroke = getrgb(obj.ViewObject.LineColor)
else:
stroke = "#000000"
if len(obj.Shape.Vertexes) > 1: if len(obj.Shape.Vertexes) > 1:
wiredEdges = [] wiredEdges = []

View File

@ -43,11 +43,11 @@ import sys, FreeCAD, os, Part, math, re, string, Mesh, Draft, DraftVecUtils, Dra
from Draft import _Dimension, _ViewProviderDimension from Draft import _Dimension, _ViewProviderDimension
from FreeCAD import Vector from FreeCAD import Vector
try: import FreeCADGui gui = FreeCAD.GuiUp
except: gui = False try:
else: gui = True draftui = FreeCADGui.draftToolBar
try: draftui = FreeCADGui.draftToolBar except:
except: draftui = None draftui = None
files = ['dxfColorMap.py','dxfImportObjects.py','dxfLibrary.py','dxfReader.py'] files = ['dxfColorMap.py','dxfImportObjects.py','dxfLibrary.py','dxfReader.py']
baseurl = 'https://raw.github.com/yorikvanhavre/Draft-dxf-importer/master/' baseurl = 'https://raw.github.com/yorikvanhavre/Draft-dxf-importer/master/'
@ -162,7 +162,8 @@ def getGroup(ob):
def getACI(ob,text=False): def getACI(ob,text=False):
"gets the ACI color closest to the objects color" "gets the ACI color closest to the objects color"
if not gui: return 0 if not gui:
return 0
else: else:
if text: if text:
col=ob.ViewObject.TextColor col=ob.ViewObject.TextColor