FreeCAD / FreeCAD

This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.
https://www.freecad.org
Other
19.11k stars 3.97k forks source link

DXF importer (Python): blocks are imported outside their layers #16552

Open furgo16 opened 3 days ago

furgo16 commented 3 days ago

Is there an existing issue for this?

Problem description

Steps to reproduce:

  1. Download the sample DXF file
  2. Start FreeCAD
  3. Create a new document
  4. File > Import
  5. Open the DXF sample file from step 1.
  6. In the preferences dialog, use the import preferences from the screenshot below. Most importantly, tick Use legacy python importer, Use layers, Create Part shapes and Group layers into blocks .
  7. Expected: DXF entities are imported as a block by layer
  8. Actual: DXF entities are imported as a block by layer, but the blocks are outside of the layers (see screenshot)

Also note the naming of the blocks: the block that should be under the 0 layer is named _. I believe this is because there is already an object with the "0" label (the layer), so when the importer creates the child block with the same "0" label, FreeCAD renames it. The renaming logic seems to be to replace the first digit of the label by an underscore, if the label starts with a digit. A workaround is to prepend a letter to the label. Looking at the output of #16550, it seems that the legacy importer works around this by prepending block to the created block, but for some reason that is not happening here.

image

image

Full version info

OS: Ubuntu 22.04.4 LTS (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 1.0.0RC1.38720 +8 (Git)
Build type: Unknown
Branch: Issue16068
Hash: 6149c0c015fab15ad6996d3060c6af103de59337
Python 3.10.12, Qt 5.15.3, Coin 4.0.0, Vtk 9.1.0, OCC 7.8.1
Stylesheet/Theme/QtStyle: unset/Classic/Qt default

Subproject(s) affected?

File formats

Anything else?

No response

Code of Conduct

maxwxyz commented 3 days ago

@kpemartin @Roy-043 FYI

kpemartin commented 3 days ago

This seems to be asking for the Legacy importer to back-implement behaviour of the C++ importer, which leaves the compound objects within the layers since there can be several such compound objects (if, say, the colours are different), and there can be non-compoundable objects (like dimensions).

I do not believe that the legacy importer checks attributes and always merges all the shapes of the layer into a single compound, so it is a bit more justified to just place this compound at top level instead of in the layer. I'm not sure what it does if there are also dimensions or annotations in the layer.

furgo16 commented 3 days ago

so it is a bit more justified to just place this compound at top level instead of in the layer.

Thanks for the detailed analysis. I'm not familiar with the implementation details, but from the user perspective, I would think the expectation would be to have the blocks under the layers.

The workaround is to move the blocks manually under the layers after the import, but I feel a more optimal experience would be for this to happen automatically like in the C++ importer.

I'm not sure what it does if there are also dimensions or annotations in the layer.

I can test this soon and report back.

furgo16 commented 2 days ago

I added a text line and a dimension to the sample file with QCAD. I then imported it with the legacy importer and settings in the screensheet at the bottom

Result:

image

image