Draft: Added preference setting to use the new C++ dxf importer

This commit is contained in:
Yorik van Havre 2015-09-07 16:46:08 -03:00
parent b4e3fcb428
commit 6b792952c3
2 changed files with 59 additions and 19 deletions

View File

@ -61,6 +61,29 @@
<property name="margin"> <property name="margin">
<number>9</number> <number>9</number>
</property> </property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_4">
<property name="toolTip">
<string>If this is checked, the old python importer is used, otherwise the new C++ one (faster, but not as many features yet)</string>
</property>
<property name="text">
<string>Use legacy python importer</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>dxfUseLegacyImporter</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <item>

View File

@ -1467,6 +1467,7 @@ def warn(dxfobject,num=None):
def open(filename): def open(filename):
"called when freecad opens a file." "called when freecad opens a file."
readPreferences() readPreferences()
if dxfUseLegacyImporter:
if dxfReader: if dxfReader:
docname = os.path.splitext(os.path.basename(filename))[0] docname = os.path.splitext(os.path.basename(filename))[0]
if isinstance(docname,unicode): if isinstance(docname,unicode):
@ -1478,10 +1479,21 @@ def open(filename):
return doc return doc
else: else:
errorDXFLib(gui) errorDXFLib(gui)
else:
docname = os.path.splitext(os.path.basename(filename))[0]
if isinstance(docname,unicode):
import sys #workaround since newDocument currently can't handle unicode filenames
docname = docname.encode(sys.getfilesystemencoding())
doc = FreeCAD.newDocument(docname)
doc.Label = decodeName(docname)
FreeCAD.setActiveDocument(docname)
import DraftUtils
DraftUtils.readDXF(filename)
def insert(filename,docname): def insert(filename,docname):
"called when freecad imports a file" "called when freecad imports a file"
readPreferences() readPreferences()
if dxfUseLegacyImporter:
if dxfReader: if dxfReader:
groupname = os.path.splitext(os.path.basename(filename))[0] groupname = os.path.splitext(os.path.basename(filename))[0]
try: try:
@ -1496,6 +1508,10 @@ def insert(filename,docname):
importgroup.addObject(l) importgroup.addObject(l)
else: else:
errorDXFLib(gui) errorDXFLib(gui)
else:
FreeCAD.setActiveDocument(docname)
import DraftUtils
DraftUtils.readDXF(filename)
def getShapes(filename): def getShapes(filename):
"reads a dxf file and returns a list of shapes from its contents" "reads a dxf file and returns a list of shapes from its contents"
@ -1944,7 +1960,7 @@ def readPreferences():
global dxfCreatePart, dxfCreateDraft, dxfCreateSketch, dxfDiscretizeCurves, dxfStarBlocks global dxfCreatePart, dxfCreateDraft, dxfCreateSketch, dxfDiscretizeCurves, dxfStarBlocks
global dxfMakeBlocks, dxfJoin, dxfRenderPolylineWidth, dxfImportTexts, dxfImportLayouts global dxfMakeBlocks, dxfJoin, dxfRenderPolylineWidth, dxfImportTexts, dxfImportLayouts
global dxfImportPoints, dxfImportHatches, dxfUseStandardSize, dxfGetColors, dxfUseDraftVisGroups global dxfImportPoints, dxfImportHatches, dxfUseStandardSize, dxfGetColors, dxfUseDraftVisGroups
global dxfFillMode, dxfBrightBackground, dxfDefaultColor global dxfFillMode, dxfBrightBackground, dxfDefaultColor, dxfUseLegacyImporter
dxfCreatePart = p.GetBool("dxfCreatePart",True) dxfCreatePart = p.GetBool("dxfCreatePart",True)
dxfCreateDraft = p.GetBool("dxfCreateDraft",False) dxfCreateDraft = p.GetBool("dxfCreateDraft",False)
dxfCreateSketch = p.GetBool("dxfCreateSketch",False) dxfCreateSketch = p.GetBool("dxfCreateSketch",False)
@ -1961,5 +1977,6 @@ def readPreferences():
dxfGetColors = p.GetBool("dxfGetOriginalColors",False) dxfGetColors = p.GetBool("dxfGetOriginalColors",False)
dxfUseDraftVisGroups = p.GetBool("dxfUseDraftVisGroups",False) dxfUseDraftVisGroups = p.GetBool("dxfUseDraftVisGroups",False)
dxfFillMode = p.GetBool("fillmode",True) dxfFillMode = p.GetBool("fillmode",True)
dxfUseLegacyImporter = p.GetBool("dxfUseLegacyImporter",True)
dxfBrightBackground = isBrightBackground() dxfBrightBackground = isBrightBackground()
dxfDefaultColor = getColor() dxfDefaultColor = getColor()