Currently it exits two solution to import a dxf file. The legacy python importer provide more comfort. But this will not be developed further because the performance. The C++ importer unfortunately supports significantly fewer functions and still seems vulnerable. What is confusing is that the documentation (feature matrix [1]) in draft suggests otherwise. Having embarrassingly learned the next release will be a big jump, the goal should be to replace the two solutions. This also includes cleaning up the source code, since the implementation can be found in several places.
Basic principle
At startup it is checked if an ASCII file is present. The reader (ReadFile()) captures each pair of lines and converts the group code into int. Supported values are also converted and stored in a map. CreateObjects() creates the corresponding objects. The two functions (ReadFile=producer, CreatObject=consumer) can be executed parallel in Part mode. At the end, the rendering is done and the user sees the result. The concept fix this.
Currently, the CAD kernel is still used directly in part mode. For maintainable source code, the functions offered by the FreeCAD base should also be used. An example can be found at the splines.
Code style
Even though not everything is prefect yet, I used cpplint
Comments / improvements are welcome.
Feature matrix
Lines
Part & Draft are supported
Polylines (and lwpolylines)
Part & Draft are supported. Polylines are split in the Part module to lines. If someone knows how to use a spline (one degree) here, please let me know.
Arcs
Part & Draft are supported
Circles
Part & Draft are supported
ellipses
Part & Draft are supported
Splines
Part & Draft are supported.
Some parts are under construction. A test file with a spline though fit points is needed.
PR needed #6914
Bezier Curves
Part & Draft are supported, but should validate. Close #6008
Points
Part & Draft are supported
Texts and mtexts
Supported, but there is still room for improvement here. E.g. Rotation.
Dimensions
Part & Draft are supported. But there is still room for improvement here.
Leaders
Is this really supported? Any kind of information is welcome.
blocks (only geometry, texts, dimensions and attributes inside blocks are skipped)
Not yet. But they're no reason that texts or dims are skipped.
Layers
Currently only the color of the layers are supported. The color map is not completed.
It's not a pretty job.
Paper space objects
Any kind of information is welcome.
3D faces
I mean in the past only faces with 3 points are supported. This restriction no longer exists.
Testing
The current work you will find here. No panic, for a PR I will create a new branch. To test it, use please this script:
Code: Select all
from PySide import QtGui
# open dxf file
path = FreeCAD.ConfigGet('UserAppData')
fname, filter = QtGui.QFileDialog.getOpenFileName(None, 'Read DXF file', path, '*.dxf')
if fname:
# set flag to use the new Library to test
grp = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
grp.SetInt("nativLibraryVersion", 2)
# load the dxf
import Import
Import.readDXF(fname)
# set the standard library
grp.SetInt("nativLibraryVersion", 1)