DXFNext

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

DXFNext

Post by Gift »

Introduction

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)
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: DXFNext

Post by Gift »

Gift wrote: Thu Jun 16, 2022 11:33 am ...
PR needed #6914
...
@uwestoehr Thanks for merge.

Now I need an example dxf file with a spline on basis of fit points. :D
User avatar
NewJoker
Veteran
Posts: 3017
Joined: Sun Oct 11, 2020 7:49 pm

Re: DXFNext

Post by NewJoker »

Will it also handle export to DXF ? It would be great to have a reliable solution for import and export (especially from TechDraw) of DXF files. Recently, there were several forum threads about issues with the current state of DXF handling.
User avatar
wandererfan
Veteran
Posts: 6267
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: DXFNext

Post by wandererfan »

Shouldn't we be thinking of a dedicated dxf library like libdxfrw, dxflib, etc? I would be good to offload the actual dxf creation. We'd still need a FC to dxfLibrary layer.
Workshop_Notes
Posts: 590
Joined: Wed Sep 29, 2021 8:35 am

Re: DXFNext

Post by Workshop_Notes »

Gift wrote: Fri Jun 24, 2022 10:58 am Now I need an example dxf file with a spline on basis of fit points.
This is a reply to both you and wanderfan's later post:

Are you aware of the very good dxf module for Python, Ezdxf (https://pypi.org/project/ezdxf/)?

It might be useful to create your spline test/example dxf in it. It also has good dxf reading/understanding in the other direction.
User avatar
wandererfan
Veteran
Posts: 6267
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: DXFNext

Post by wandererfan »

Workshop_Notes wrote: Fri Jun 24, 2022 5:51 pm Are you aware of the very good dxf module for Python, Ezdxf (https://pypi.org/project/ezdxf/)?
Ezdxf looks promising. MIT license which is compatible with LGPL. We'd need a replacement for Import/App/ImpExpDxf.cpp and mods to functions that use it.
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: DXFNext

Post by Gift »

NewJoker wrote: Fri Jun 24, 2022 11:06 am Will it also handle export to DXF ? It would be great to have a reliable solution for import and export (especially from TechDraw) of DXF files. Recently, there were several forum threads about issues with the current state of DXF handling.
Currently only the reading of dxf files is support. But writing and testing will flow.
wandererfan wrote: Fri Jun 24, 2022 2:45 pm Shouldn't we be thinking of a dedicated dxf library like libdxfrw, dxflib, etc? I would be good to offload the actual dxf creation. We'd still need a FC to dxfLibrary layer.
Where do you see the advantage in a library? To prase or write a file is very easy. The work is to create the interface. We should inspect all the libs. If we find a good concept (classes), we should put it over FreeCAD with own C++ source code.
Workshop_Notes wrote: Fri Jun 24, 2022 5:51 pm
This is a reply to both you and wanderfan's later post:

Are you aware of the very good dxf module for Python, Ezdxf (https://pypi.org/project/ezdxf/)?

It might be useful to create your spline test/example dxf in it. It also has good dxf reading/understanding in the other direction.
My favorite is a c++ solution. For testing it should be possible. See here
User avatar
sliptonic
Veteran
Posts: 3457
Joined: Tue Oct 25, 2011 10:46 pm
Location: Columbia, Missouri
Contact:

Re: DXFNext

Post by sliptonic »

Gift wrote: Sun Jun 26, 2022 2:43 pm
Where do you see the advantage in a library?
One advantage is that support and maintenance gets shared by many projects. Mozman has been working on ezdxf for at least four years. He has a wealth of information on dxf standards and implementation and he's been actively resolving bugs the whole time.

If we can take advantage of a library rather than 'rolling our own', why wouldn't we?
User avatar
wandererfan
Veteran
Posts: 6267
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: DXFNext

Post by wandererfan »

Gift wrote: Sun Jun 26, 2022 2:43 pm Where do you see the advantage in a library?
Because making Dxf files sucks. Especially for anything newer than R12 with all the tables, dictionary entries, handles, etc.

I'd rather delegate the headache of supporting new Dxf versions to somebody else. :)
User avatar
Gift
Posts: 769
Joined: Tue Aug 18, 2015 10:08 am
Location: Germany, Sauerland

Re: DXFNext

Post by Gift »

Hello @wandererfan, Hello @sliptonic,

I had written a longer reply. Unfortunately, it is deleted. :cry: In short, I have tested the Ezdxf library. Which needs only to read the following file 80 seconds. My solution needs 33 seconds to read, create the objects and render. The first two steps run parallel. I think performance is an important feature. If you see other aspects in the foreground, we should create a morphological analysis.
Post Reply