DXF Import C++ version fail to load

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
JulianTodd
Posts: 51
Joined: Tue Oct 23, 2018 3:35 pm

DXF Import C++ version fail to load

Postby JulianTodd » Wed Nov 28, 2018 6:33 pm

The FC bug tracker says to post questions to the forum before filing a bug. So that's what I am doing. However I'm going to make it a bigger question.

I have a small DXF file (attached) that I have edited down in Librecad that loads correctly using the "legacy python importer" that I was able to select using a checkbox in a dialog box found here:

Code: Select all

Drafts workbench, Menu: Edit -> Preferences, Import-Export, DXF: [ ] Use legacy python importer
However, the C++-implemented DXF importer doesn't work at all and just gives me four straight lines.

This is nearly the latest version, which I built from source last week.

I've had a look at the history of the two versions where it seems they are both under development:

https://github.com/FreeCAD/FreeCAD/comm ... portDXF.py

https://github.com/FreeCAD/FreeCAD/comm ... ExpDxf.cpp

This looks like unnecessary duplication of work, even though there is a presumption that C++ one is more up to date.

Personally, I don't think C++ is the right language to implement any import/export file features. It's really bad at handling the parsing of strings and there's very little speed advantage because the converter is not the bottleneck. If there is a bottleneck, it's because of a single linear file, or the callbacks to the main system where the internal entities are allocated and constructed.

It is in the nature of import/exporters to be generally buggy. The data is not simple and well-defined, and is often written and read by other buggy programs. A C++ implementation creates a much higher barrier to getting these superficial but serious bugs fixed than a Python implementation -- where you can debug make minor modifications and quickly try them out in real time in the middle of a job.

I searched and I cannot find any discussions about this sort of thing anywhere. It would be good to know what people are thinking about this when they are doing their development.

DXF parsing has a lot of use outside of FC, so it would be even more productive to use an outside library that's going to get much better maintained, because it's done in isolation. When I was working with DXF parsers last year I had a lot of joy with https://github.com/mozman/dxfgrabber

Now I've looked, it seems that the author of that package has superseded it with https://github.com/mozman/ezdxf which is under active development and can both read and write DXFs. What about basing all the DXF conversions his lovely-looking library?
Attachments
simplelibrecadsaved.dxf
(21.95 KiB) Downloaded 14 times
wandererfan
Posts: 2779
Joined: Tue Nov 06, 2012 5:42 pm

Re: DXF Import C++ version fail to load

Postby wandererfan » Thu Nov 29, 2018 1:24 am

JulianTodd wrote:
Wed Nov 28, 2018 6:33 pm
However, the C++-implemented DXF importer doesn't work at all and just gives me four straight lines.
AFAIK, the C++ import functions haven't been touched for 2 years. The export functions are recent and work well. Maybe we should split the code.
JulianTodd
Posts: 51
Joined: Tue Oct 23, 2018 3:35 pm

Re: DXF Import C++ version fail to load

Postby JulianTodd » Thu Nov 29, 2018 9:54 am

It sounds like deprecating the C++ import implementation and always calling the Python version (regardless of that checkbox) is a one-line fix.

Should we file this as an urgent top-priority bug?

It's very important that DXF loading works out of the box, because this is one of the first features a new user might do.
User avatar
yorik
Site Admin
Posts: 11377
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DXF Import C++ version fail to load

Postby yorik » Thu Nov 29, 2018 1:15 pm

Those two importers have very different uses. I don't think any of them should be discarded.

The C++ importer will painlessly swallow 50Mb+ dxf files. However, not all DXF entities are supported (yet).
The py importer supports many more entities, but becomes unbearably slow after a couple of Mb.

In this dxf file what is missing is splines support apparently.
JulianTodd
Posts: 51
Joined: Tue Oct 23, 2018 3:35 pm

Re: DXF Import C++ version fail to load

Postby JulianTodd » Fri Nov 30, 2018 2:01 pm

It's not my experience that a Python importer/translator will be slower than a C++ one, especially for large files. In fact it should be faster, because the programmer can consider implementingf many more suitable algorithms in the same number of days as he could do in C++, where he normally gets one shot to write it from scratch. This effect is evidenced by there being more features in the Python implementation than the C++ one.

Is there a resource containing example 50Mb files that the Python interpreter chokes on where this can be tested? Even the most informed opinions get out of date very quickly with the progress of each version of the interpreter and changes in the algorithm. These things need to be double-checked. I was employed as a C++ coder for 20 years, and have had a lot of battles on this subject -- usually with managers whose opinions are seriously out of date and would have us coding in Fortran if they got their way.

Once you challenge the theoretical speed advantage of C++ (which you can only get with double the coding time), there's very little justification for using it.
User avatar
yorik
Site Admin
Posts: 11377
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DXF Import C++ version fail to load

Postby yorik » Fri Nov 30, 2018 8:22 pm

If you manage our py importer to get as fast as the C++ one, I'd be forever grateful :D It would likely be because of my feeble programming talents of course, but try opening any dxf file with both, you'll see the difference...
keithsloan52
Posts: 881
Joined: Mon Feb 27, 2012 5:31 pm

Re: DXF Import C++ version fail to load

Postby keithsloan52 » Fri Nov 30, 2018 9:10 pm

Just a heads up that the OpenSCAD workbench uses the legacy python DXF library, especially for 2D hull & minkowski requests so in case you are thinking of dropping it. PLEASE DON'T
User avatar
kkremitzki
Posts: 1647
Joined: Thu Mar 03, 2016 9:52 pm
Location: Texas

Re: DXF Import C++ version fail to load

Postby kkremitzki » Fri Nov 30, 2018 9:56 pm

keithsloan52 wrote:
Fri Nov 30, 2018 9:10 pm
Just a heads up that the OpenSCAD workbench uses the legacy python DXF library, especially for 2D hull & minkowski requests so in case you are thinking of dropping it. PLEASE DON'T
Can you try to reduce your usage of ALL CAPS? It gives the impression you're trying to yell at us, and I've seen several posts recently where you've been doing this.
Like my FreeCAD work? I'd appreciate any level of support via Patreon, Liberapay, or PayPal! Read more about what I do at my blog.
User avatar
yorik
Site Admin
Posts: 11377
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: DXF Import C++ version fail to load

Postby yorik » Sat Dec 01, 2018 1:29 pm

keithsloan52 wrote:
Fri Nov 30, 2018 9:10 pm
in case you are thinking of dropping it. PLEASE DON'T
Nobody is thinking of dropping it.
keithsloan52
Posts: 881
Joined: Mon Feb 27, 2012 5:31 pm

Re: DXF Import C++ version fail to load

Postby keithsloan52 » Sat Dec 01, 2018 6:10 pm

yorik wrote:
Sat Dec 01, 2018 1:29 pm
keithsloan52 wrote:
Fri Nov 30, 2018 9:10 pm
in case you are thinking of dropping it. PLEASE DON'T
Nobody is thinking of dropping it.
Good to know