Need help understanding DXF import and export prefs

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!
Post Reply
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Need help understanding DXF import and export prefs

Post by Roy_043 »

I am trying to understand the 'Treat ellipses and splines as polylines' option.

In my tests this setting has no effect on imported ellipses and splines.
It does not matter if the legacy importer or the new importer is used.
Note that the new importer does not import splines.

The 'Max Spline Segment' setting which seems related to the 'Treat ellipses and splines as polylines' option, does not have an impact on imports (see above).
But bizarrely does have an impact when the legacy exporter is used to export ellipses and splines.

Code: Select all

DXF Import test:

[NO] Use legacy python importer + [NO] Treat ellipses and splines as polylines
[NO] Use legacy python importer + [YES] Treat ellipses and splines as polylines
  Ellipse is imported as ellipse (verified by creating sketch from object).
  Spline is not imported.

[YES] Use legacy python importer + [NO] Treat ellipses and splines as polylines
[YES] Use legacy python importer + [YES] Treat ellipses and splines as polylines
  Ellipse is imported as elliptical arc (verified by creating sketch from object).
  Spline is imported as spline.

Code: Select all

DXF Export test:

[NO] Use legacy python exporter + [NO] Treat ellipses and splines as polylines + Max Spline Segment [10]
[NO] Use legacy python exporter + [YES] Treat ellipses and splines as polylines + Max Spline Segment [10]
[NO] Use legacy python exporter + [NO] Treat ellipses and splines as polylines + Max Spline Segment [1]
[NO] Use legacy python exporter + [YES] Treat ellipses and splines as polylines + Max Spline Segment [1]
  Ellipse is imported as ellipse
  Spline is imported as spline.

[YES] Use legacy python exporter + [NO] Treat ellipses and splines as polylines + Max Spline Segment [10]
[YES] Use legacy python exporter + [YES] Treat ellipses and splines as polylines + Max Spline Segment [10]
[YES] Use legacy python exporter + [NO] Treat ellipses and splines as polylines + Max Spline Segment [1]
[YES] Use legacy python exporter + [YES] Treat ellipses and splines as polylines + Max Spline Segment [1]
  Ellipse is imported as polyline. Max Spline Segment has effect on number of points.
  Spline is imported as polyline. Max Spline Segment has effect on number of points.
Related topic: https://forum.freecadweb.org/viewtopic.php?f=3&t=41437

Test files attached.

Code: Select all

OS: Windows 8.1 (6.3)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19591 (Git)
Build type: Release
Branch: master
Hash: 27771fc6ee93170b6ecb978ff4da438a5b9cfe97
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Dutch/Netherlands (nl_NL)
Attachments
Spline_Ellipse.FCStd
(5.07 KiB) Downloaded 13 times
Spline_Ellipse.dxf
(13.39 KiB) Downloaded 14 times
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Need help understanding DXF import and export prefs

Post by Roy_043 »

The 'Group layers into blocks' option does not appear to be very useful. It conflicts with the 'Use layers option.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Need help understanding DXF import and export prefs

Post by vocx »

Roy_043 wrote: Mon Feb 24, 2020 6:51 pm I am trying to understand the 'Treat ellipses and splines as polylines' option.
...
I'm afraid the situation is a bit messy, and requires significant re-factoring of the DXF importer.

The "new" importer is defined in C++ files located in src/Mod/Draft/App

It seems the function to import Splines is there but empty. So, somebody needs to add the implementation for it.

Code: Select all

void DraftDxfRead::OnReadSpline(struct SplineData& /*sd*/)
{
    // not yet implemented
}
On the other hand, the "legacy" importer is defined entirely in Python. It is the file src/Mod/Draft/ImportDXF.py.

This file requires that you first install the "dxf_library" that you can download from the Addon Manager. This is actually a collection of three files that get installed in the .FreeCAD/Macro directory of your installation.

The dxf_library parses the DXF, gets the data, and the importDXF functions are responsible for creating the actual FreeCAD objects in your document.

I cleaned up, and added a ton of comments to importDXF.py a while ago, but it is still pretty complex. I added this comment it seems.

Code: Select all

def drawSpline(spline, forceShape=False):
    ...
    To do
    ----
    As there is currently no Draft primitive to handle splines
    the result is a non-parametric curve.

    **2019:** There is a `Draft BSpline` now, but it's not used.
    """
It seems you may be able to import splines as long as you don't use Draft objects, just primitive Part objects. Or somebody should extend the code to use Draft_BSpline where it makes sense.

Honestly, this code could use a good refactoring, but it is a hard task. It requires a person to be committed for a straight month, testing many cases, and avoiding regressions. I was thinking of doing it, but I got into something else, so basically, time is never enough.

What could be helpful is having a standardized DXF file that we can use as reference to test our code. Basically, a file with a single line, a single wire, a single spline, a single circle, etc., with all shapes that make sense to import and export. Something similar to this. We could essentially use this Draft test script to produce a DXF and read it back, although it would be nice to get a DXF file from another program as well.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Roy_043
Veteran
Posts: 8552
Joined: Thu Dec 27, 2018 12:28 pm

Re: Need help understanding DXF import and export prefs

Post by Roy_043 »

Maybe I need to clarify. I expect the 'Treat ellipses and splines as polylines' option to create faceted objects from DXF ellipses and splines. But in my tests I get curved objects. This can be demonstrated by converting these 'Edge' objects to sketches.

If I understand correctly manually installing the DXF libraries is not necessary if the 'Allow FreeCAD to automatically download and update the DXF libraries' option is checked.
User avatar
wandererfan
Veteran
Posts: 6321
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Need help understanding DXF import and export prefs

Post by wandererfan »

vocx wrote: Mon Feb 24, 2020 7:40 pm The "new" importer is defined in C++ files located in src/Mod/Draft/App
Pretty sure the real source for the "new" importer in in Mod/Import/App. It has been maintained more recently than the one in Draft. Also there's a message in AppDraftUtilsPy saying not to use DraftUtils.readDxf, but to use Import.readDxf instead.

I've only worked on the export side so I could be all wet about import.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Need help understanding DXF import and export prefs

Post by vocx »

wandererfan wrote: Mon Feb 24, 2020 8:11 pm Pretty sure the real source for the "new" importer in in Mod/Import/App....
Yes, you are right. Then the Draft C++ code is not used any more and should be removed probably. Otherwise it just creates more confusion.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Need help understanding DXF import and export prefs

Post by vocx »

Roy_043 wrote: Mon Feb 24, 2020 7:59 pm ...
If I understand correctly manually installing the DXF libraries is not necessary if the 'Allow FreeCAD to automatically download and update the DXF libraries' option is checked.
Correct, but that's a bit of a hack. I think it makes more sense to remove that option from the preferences, and instruct the user to the Addon Manager instead. That option to automatically install the DXF libraries was written at a time when the Addon Manager didn't exist.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply