Commit Graph

51 Commits

Author SHA1 Message Date
ᴩʜᴏɴᴇᴅʀᴏɪᴅ
0df300cee6 [ Import ]: Update SPDX License Identifiers (#24976) 2025-11-03 11:57:57 -06:00
tetektoza
0cfa5ba5fe Fix: Closed polylines import duplicate vertices
Similar case to the previous commit related to closed polylines having
coincident vertices, but this time for import. Basically if importing
DXF files containing closed polylines, FC would throw an exception.

This was because `BuildWireFromPolyline()` function in the DXF importer
attempted to create a closing edge for closed polylines by connecting
the last vertex back to first vertex.

So, this patch adds a skip for the closing edge if the vertices are
coincident.
2025-10-26 15:17:00 +01:00
tetektoza
01777cb320 Fix: Closed polylines export duplicate vertices
AS the title says - when exporting closed curves (ellipses for example)
as polylines with the "Treat ellipses and splines as polylines" option,
the generated DXF file contained duplicate vertices. For example, an
ellipse polyline would have vertex1 and vertex40 which are identical in
terms of coordinates. This has caused exception upon importing.

Cause of that was that discretizer was blindly iterating through all
discretized points without checking if the first and last points are
coincident.

So, this patch adds a check for that to detect and skip the last
coincident point if it is in fact coincident during Export.
2025-10-26 14:45:10 +01:00
tetektoza
34eafe127e Import: Use proper location for DXF prefs
Currently if users enabled the "Treat ellipses and splines as polylines"
option in DXF export preferences and exported them, they were still
being exported as native primitives.

This was because we were reading from a wrong preferences location, UI
stored it in `BaseApp/Preferences/Mod/Draft`, but it was read from
`BaseApp/Preferences/Mod/Import`. Since the pref didn't exist, we were
taking default value which was set to `false`.

So the solution is obvious - just set it to the correct path.
2025-10-26 14:26:02 +01:00
Markus Reitböck
7051848d10 Import: use CMake to generate precompiled headers on all platforms
"Professional CMake" book suggest the following:

"Targets should build successfully with or without compiler support for precompiled headers. It
 should be considered an optimization, not a requirement. In particular, do not explicitly include a
 precompile header (e.g. stdafx.h) in the source code, let CMake force-include an automatically
 generated precompile header on the compiler command line instead. This is more portable across
 the major compilers and is likely to be easier to maintain. It will also avoid warnings being
 generated from certain code checking tools like iwyu (include what you use)."

Therefore, removed the "#include <PreCompiled.h>" from sources, also
there is no need for the "#ifdef _PreComp_" anymore
2025-09-23 22:39:35 +02:00
Furgo
8054042a9a Import: DXF, fix typo in individual shapes import mode 2025-07-14 10:18:04 +02:00
Furgo
808526e8b8 Import: DXF, deduplicate Part primitives creation
Create helpers that can be reused when importing entities as top-level
geometry and as part of blocks
2025-07-14 10:18:04 +02:00
Furgo
cb64caf283 Import: DXF, first working version of dimensions import 2025-07-14 10:18:04 +02:00
Furgo
5243501638 Import: DXF, make ellipses parametric 2025-07-14 10:18:04 +02:00
Furgo
fa4d8247bc Import: DXF, first working version of Draft objects import 2025-07-14 10:18:04 +02:00
Furgo
a7f8fd29bb Import: DXF, first working version for import as Part primitives 2025-07-14 10:18:04 +02:00
Furgo
071bdcc579 Import: DXF, add dedicated import dialog 2025-07-14 10:18:04 +02:00
Furgo
1b2246c5db Import: DXF importer, refactor preferences UI 2025-07-14 10:18:04 +02:00
Furgo
3b3d19c56b Import: improve DXF C++ importer support for BLOCK and INSERT entities (#22045)
* Import: DXF importer, block and inserts overhaul

Implement support for blocks as definitions and inserts
as instances.

A BLOCK definition becomes a hidden master object in a
_BlockDefinitions group (currently a Part::Compound).
An INSERT becomes a visible App::Link that points to
that master definition.

* Import: DXF parser/importer add debug print statements

* Import: DXF importer, various improvements

- Add more code comments
- Correctly increase object count
- Improve readability of anonymous block checks

* Import: DXF (all) report anonymous blocks separately

* Import: DXF importer (App + GUI) add nested inserts support

* Import: DXF importer (GUI) fix preserving colors for inserts

* Import: DXF importer, make primitives naming more specific

* Import: DXF parser/importer remove debug print statements

* Import: DXF parser, work around DXF color index 7

* Import: DXF importer GUI, temporary debug print to show layer color data

* Import: DXF importer, fix nested inserts hierarchy

* Import: DXF importer, prefix and suffix underscores to names

To work around mangling from FreeCAD's unique name generator.

* Import: DXF importer, implement flattening blocks on import

* Revert "Import: DXF importer GUI, temporary debug print to show layer color data"

This reverts commit b6ece395c9d2b8a1e0796d6f7b0d58842a2f3686.

* Import: DXF importer, fix imported text orientation

The DXF file provides the text rotation angle in degrees.
The used rotZ function expects the angle in radians,
thus the conversion needs to be made.

Fixes: #21548

* Import: DXF importer, honour the preference to not import layouts

* Import: DXF importer, move unreferenced blocks to separate group

This provides better classification, but it has a performance hit:
we import all blocks as before, we sort them and we reparent them
to the correct group. The reparentipart with Grou.setValues()
appears to be an expensive call. Probably because internally the
FreeCAD dependency graph is modified.

* Import: DXF importer, count compound children in the report

* Import: DXF importer, cleanup defined blocks group if empty
2025-07-12 13:38:13 +02:00
Furgo
7764ed5173 Import: DXF backend/frontend, report more unsupported features info
Now for unsupported features we report on line numbers and on the entity
handle, in case that unsupported feature is a DXF entity. To avoid
flooding the output, only a maximum of 5 instances are reported with
details. The rest simply add up to the global count and are ellipsized
in the report.

Report output is now in sentence case.
2025-06-25 07:41:03 +02:00
Furgo
c10a945fad Import: DXF importer, add code comments to C++ to Python stats passing function 2025-06-25 07:41:03 +02:00
Furgo
bf0c8f24fa Import: DXF parser/imported improve unsupported features count
Classify unsupported features by type, and report on
the breakdown.
2025-06-25 07:41:03 +02:00
Furgo
ef0dd661a3 Import: DXF parser/importer, improve scale reporting
Report additional information about user scaling
value, scaling info source and resulting scale,
including units.
2025-06-25 07:41:03 +02:00
Furgo
321c5b692b Import: DXF importer, add Python bindings 2025-06-25 07:41:03 +02:00
Furgo
9775aafc32 Import: DXF importer, populate stats reporting structure 2025-06-25 07:41:03 +02:00
Furgo
f3a4b9de78 DXF: do not ignore the setting that controls importing paper layouts 2025-06-23 14:06:02 +02:00
bofdahof
998f4e4d45 Console: rename PascalCase named methods to camelCase 2025-05-06 17:50:21 +02:00
Benjamin Nauck
4bf7048534 Import: use contains() instead of count() where possible 2025-05-03 22:19:51 +02:00
Kevin Martin
0986dadb2f Correct non-gui DXF C++ importer to not generate pending python exceptions (#20328)
* Add a test case for DXF import

* Test gui flag rather than look for import error to make gui decision

The new code is cleaner and faster and avoids any exception stuff

* Properly avoid trying to use Layer's View object in non-GUI

The code was trying to avoid this but had a Python None object rather than a null C++ pointer and so tried setting a property on None. This left an unhandled exception state which acted as a booby trap that caused the later failure of some unrelated code.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* De-lint, remove wong "unsupported" message
Hidden layers have been supported for a while but still generated an import note about this being unsupported.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-31 11:20:37 -05:00
Benjamin Nauck
821327b4cd Import: Use std::numeric_limits and std::numbers instead of defines 2025-03-29 13:32:38 +01:00
Kacper Donat
a72a63232a Base: Move App::Color to Base
Every basic data type is stored in Base module, color is standing out as
one that does not. Moving it to Base opens possibilities to integrate it
better with the rest of FreeCAD.
2025-02-17 21:10:26 +01:00
Benjamin Nauck
a1c5767643 Mod: Use new addObject<T>(...) using regex 2025-02-10 18:35:38 +01:00
wmayer
ca7b7fe5a0 Fix compiler warning 2024-09-25 18:46:55 +02:00
Kevin Martin
5bed9bf53f DXF: Fix Import related behavior reported in issues #13597 and #16068 (#16511)
* Fix double-import on exception in ImportGUI.readDXF
The python code has a try/catch block intended to detect if the ImportGUI module is present and if so use its readDXF method, otherwise use Import.readDXF.
The block was incorrectly structured so that Import.readDXF would also be called if ImportGUI.readDXF raised an exception, causing the DXF file contents to be loaded twice into the drawing (at least, up to the point where the exception occurred)

* Make ImpExpDxfRead::MakeLayer use centralized accessor for Draft module
The importer class already had a method to find the python Draft module, but MakeLayer was doing the work itself. Now it uses the centralized accessor, which has also been improved to generate a message if the module can't be loaded.

* Give compounded objects names related to the containing layer name
If "Use Layers" is set and also "Group layers into blocks" the names of the generated compound objects will be based on the name of the containing layer.
If "Use Layers" is not set this will not occur because in general objects from several layers would be compounded together.
Fixes (partially) #16068, the remaining fix is likely just an explanation of the interaction of the options.
closes #13597

* Use correct (new) property name OverrideShapeAppearanceChildren
This corrects a bug created by commit 495a96a which renamed the layer property "OverrideShapeColorChildren" to "OverrideShapeAppearanceChildren" but missed this particular reference to the property by its old name.

The code here called PyObject_SetAttrString which, due to the wrong attribute name, set an expection state in the Python engine, ultimately causing the next attempt at importing a module to fail, with various consequences depending on why the module is being imported.

* Wrap PyObject_SetAttrString and PyObject_GetAttrString with error-checkers
In DEBUG compiles these methods are wrapped to report errors which can occur if the property cannot be referenced.

* Make some error-printers static instead of const
They don't need the CDxfRead object to work

* Display exceptions raised by ReadEntity
Although the DXF reader has an ignore-errors flag, it should still report any errors it encounters. The flag is deemed to mean that, after an error, the reader should continue to try to read the file rather than quitting on the first error.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-09-23 17:28:00 +02:00
Kevin Martin
c9887d9400 DXF: Place objects in layer all at once rather than one at a time to improve DXF import speed dramatically. (#16596)
* Place objects in layer all at once rather than one at a time.
This reduces (by a factor of the number of objects in the layer) the number of times that the layer contents are traversed to set the properties of the contained objects.
This means the layer insertion of O(n) rather then O(n^2) on the number of objects.
Also remove a loop invariant in view_layer so the chidren are not traversed if colours or appearnces are not inherited from the layer.
Fixes #15732

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-09-23 11:39:02 +02:00
wmayer
f6e67a009d Fix several compiler warnings
* -Wmaybe-uninitialized
* -Wunused-parameter
* -Wunused-variable
* -Wnonnull
* -Wstringop-truncation
* -Wstringop-overflow
2024-06-19 21:14:23 -05:00
pre-commit-ci[bot]
b5fa008272 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-03-31 10:47:32 +02:00
ppphp
da7ee06d67 fix: c++20 deprecate [=] 2024-03-31 10:47:32 +02:00
Kevin Martin
0dcfe94505 Handle all combos of "group into blocks" "use DXF colors" "use layers"
Fixes #11873 this was the primary goal of these changes

Fixes (partially) #11874 the parts of a polyline are combined as a
compound object (shape) but it would be preferable for them to be made
into a wire (if possible)

Fixes #11872 Objects in a block definition are now kept separately
until the block is inserted, in which case the inserted objects are
subject to all the other options regarding combining.

Fixes (partially, review required) #11871 Text and dimensions are now
kept as part of the block definition and are placed in the drawing when
the block is inserted but this code has not been extensively tested.

Affects #11875, custom types are not made, but the labels now reflect
the object types rather than all being "Shapennn"

This leaves the importer options handling in a bit of a mess that needs
cleanup eventually, but this can be a new issue.
This includes some importer flags that have no corresponding options
(e.g. import frozen layers), some flags not yet implemented, some
flags not yet even declared in the code because their implementation
is further off (import hatch outlines), and some suggested future
options (import SOLIDs as faces)

Centralize the calculation of the OCS for entities as they're read
from the DXF. Most of the entities don't use this yet, but some of
them roll their own crude Normal Vector handling. Because the new
code takes priority over the old for reading the normal vector, such
code will always see (0, 0, 1) as the extrusion direction.
2024-02-06 12:50:30 +01:00
Kevin Martin
2c0bc89f62 Streamline scaling for DXF import
Eliminate m_measurement_inch to clean up logic for priority of MEASUREMENT and INSUNITS.
Save the actual scaling factor rather than the scaling enum so a switch statement is not executed for each call to mm()
Add to CDxfRead the work to handle dxfScaling option, ImpExpDxfRead just has to set it up now.
Get the scaling factor from a lookup table rather than a switch statement
Display a message explaining what the scaling factor is and where it comes from
Remove large amount of Lint.
2024-01-08 18:01:21 +01:00
Kevin Martin
abd411f934 Add color on DXF import, refactor code
Colors as assigned to imported drawing entities if they are not merged
with other entities.
The code has been refactored to remove much duplication in reading of
attributes.
The code gives brief messages on the Python console about unsupported
DXF festures and also issues some new errors.
There is no support yet for making colors 1-9 and 250-255 contrast with
the creeen background color. Colors are generated by code rather than a
lookup table; this code can eventually modify the colors it generates to
contrast with a specific background color.
2023-12-14 10:15:17 +01:00
pre-commit-ci[bot]
91dc7285e1 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2023-11-20 18:25:29 +01:00
Kevin Martin
4e12621954 Use PyObject_CallObject rather than interpreting generated code
Rather than generating Python code and interpreting it, which, in C++, is fraught with issues of creating the correct syntax for a str token when the text contains certain special characters like double-quote and backslash, the modified code makes call(s) to PyObject_CallObject which takes the C++ string and makes the appropriate conversion itself. The steps in building the Position passed to make_text are also done using c++ objects until the final Python Placement object is needed.
2023-11-20 18:25:29 +01:00
Yorik van Havre
55292e9041 Import: Support DXF text rotation (#11001)
* Import: Support DXF text rotation - fixes #10882

- Reads and supports text rotation in builtin DXF import
- Makes the builtin DXF import produce Draft texts instead of App::Annotations
- Extends the arguments of Draft make_text()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-10-11 17:05:31 +02:00
pre-commit-ci[bot]
222a2520b1 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2023-09-12 13:02:35 -04:00
wmayer
b5d0950211 Import: Apply clang format 2023-09-10 19:23:47 +02:00
wmayer
a3057e946b Mod: modernize C++: use equals default 2023-08-22 11:16:49 +02:00
wmayer
7402ac7a26 Import: modernize C++: return braced init list 2023-08-19 11:35:41 +02:00
Abdullah Tahiri
c604d1741d Console/ILogger: Refactor and extension
=======================================

Refactor:
 - Substitute the use of variadic templates with parameter packs.
 - Use recently incorporated external library "fmt" to handle printf like formating.
 - Extensive cleaning of pragmas and unnecessary forward declarations.
 - Parameter packs and libfmt provide a much stronger type checking now, so
   conversions that are by standard implicit as bool to int need an explicit static_cast
   to avoid compilation warnings.

Extension:
 - Include a notifier field, so that the originator of the message can be provided. E.g. Document#DocumentObject
 - Include a new type of message called CriticalMessage, this message is intended to have
   special behaviour in the future. Namely, it will be used to notify forward compatilibity issues.
   It will be used to substitute the current signal/slot mechanism.
 - Include two new types of messages for user notifications (Notification and TranslatedNotification). This messages
   will be use to convey UI notifications intended for the user (such as non-intrusive message about the usage of a tool). There
   are two versions to mark whether the string provided as a message is already translated or not. When using the console system for
   notifications, these notifications may originate from the App or the Gui. In the former, it is generally the case that the strings
   of messages are not (yet) translated (but they can be marked with QT_TRANSLATE_NOOP). In the latter, often the messages to be provided
   are already translated.

Python support for CriticalMessage, Notification and TranslatedNofification, including shortcuts:

    Crt = FreeCAD.Console.PrintCritical
    Ntf = FreeCAD.Console.PrintNotification
    Tnf = FreeCAD.Console.PrintTranslatedNotification
2023-03-07 16:13:23 +01:00
luzpaz
c14f58d6f3 Fix various trailing whitespace issues and typos 2023-02-19 10:59:14 -06:00
wmayer
b44d70f646 Import: [skip ci] fix warning about trailing whitespaces, fix parsing errors 2022-11-25 11:55:51 +01:00
Uwe
838d99636b [Import] remove unused includes
- also some sorting
2022-11-25 04:34:44 +01:00
marioalexis
816ce9063d Import: Replace C cast 2022-09-18 11:06:51 -05:00
berniev
da9ebc572f Mod: redundant void 2 2022-08-08 10:27:50 +02:00
Benjamin Alterauge
d15da0ef96 PreCompiled fix
Preventive action to avoid problems with MSVC.
2022-07-16 10:55:24 +02:00