Commit Graph

361 Commits

Author SHA1 Message Date
Kacper Donat
77e40b9747 Base: Use explicit pointer syntax for freecad_cast (#20694)
* Base: Use explicit pointer syntax for freecad_cast

This aligns our custom cast with other casts

* All: Use explicit pointer syntax for freecad_cast
2025-04-11 14:11:33 +00:00
PaddleStroke
2f479e3c95 PartDesign: Fix use of App::Planes to create sketches (#20453) 2025-04-07 17:34:13 +02:00
Kacper Donat
9d97d1c895 Base: Rename Base::freecad_dynamic_cast into freecad_cast
This is to make it shorter and easier to use. QT does the same thing
with their qobject_cast.
2025-04-07 10:32:28 -05:00
Pieter Hijma
032cb79301 [Doc] Improve topics within App
- The location of the documentation is improved (not in the cpp file
  anymore but in core-app.dox).  This prevents cluttering source with
  high-level overviews typical of topic documentation.
- The formatting has been made consistent.
2025-03-29 15:11:01 -05:00
Florian Foinant-Willig
756e3789ce Fix FreeCAD#19588 2025-03-20 20:14:50 +01:00
Chris Hennes
09cdcee1bb App: Coverity fixes 2025-03-18 15:59:22 +01:00
Chris Hennes
9a77120e82 Merge pull request #20142 from bofdahof/ranges
Apply C++20 std::ranges (mainly to std::find)
2025-03-17 03:08:27 -05:00
Chris Hennes
e0aa5f3c30 Merge pull request #19917 from tritao/refactor-document-recompute
Core: Refactor code around document and feature recompute
2025-03-16 23:59:12 -05:00
bofdahof
59c3bbe5c2 App: apply std::ranges 2025-03-16 17:14:38 -05:00
Chris Hennes
44908ad721 Merge pull request #19428 from tritao/base-tracy-profiler
Base: Add Tracy frame profiling support.
2025-03-14 04:12:05 +00:00
Joao Matos
0feab195ac Base: Add build support and instrumentation for the Tracy profiler. 2025-03-14 03:41:30 +00:00
Kevin Martin
3b87c991cb Deregister DocumentObject's Label before deleting the object
Under certain circumstances the existing code would try to obtain the Label of a DocumentObject after that object had been deleted, causing an access to freed memory and failing to deregister the Label. The latter would lead to phanton Label collisions and unexpected generation of unique labels.
2025-03-05 22:23:42 -05:00
Joao Matos
ec2a281d66 App: Capitalize exception message in Document.cpp. 2025-03-03 21:22:22 +00:00
Joao Matos
60605cc2db App: Refactor with early exit in Document::recomputeFeature. 2025-03-03 21:22:22 +00:00
Joao Matos
6797cfdfbe App: Remove old DAG implementation. 2025-02-28 14:32:32 +00:00
Kevin Martin
edb8e4c937 Address performance of existing unique-name generation (Part 2) (#18676)
As described in Issue 16849, the existing Tools::getUniqueName method
requires calling code to form a vector of existing names to be avoided.

This leads to poor performance both in the O(n) cost of building such a
vector and also getUniqueName's O(n) algorithm for actually generating
the unique name (where 'n' is the number of pre-existing names).

This has  particularly noticeable cost in documents with large numbers
of DocumentObjects because generating both Names and Labels for each new
object incurs this cost. During an operation such as importing this
results in an O(n^2) time spent generating names.

The other major cost is in the saving of the temporary backup file,
which uses name generation for the "files" embedded in the Zip file.
Documents can easily need several such "files" for each object in the
document.

This update includes the following changes to use the newly-added
UniqueNameManager as a replacement for the old Tools::getUniqueName
method and deletes the latter to remove any temptation to use it as
its usage model breeds inefficiency:

Eliminate Tools::getUniqueName, its local functions, and its unit tests.

Make DocumentObject naming use the new UniqueNameManager class.

Make DocumentObject Label naming use the new UniqueNameManager class.
This needs to monitor DocumentObject Labels for changes since this
property is not read-only. The special handling for the Label
property, which includes optionally forcing uniqueness and updating
links in referencing objects, has been mostly moved from
PropertyString to DocumentObject.

Add Document::containsObject(DocumentObject*) for a definitive
test of an object being in a Document. This is needed because
DocumentObjects can be in a sort of limbo (e.g. when they are in the
Undo/Redo lists) where they have a parent linkage to the Document but
should not participate in Label collision checks.

Rename Document.getStandardObjectName to getStandardObjectLabel
to better represent what it does.

Use new UniqueNameManager for Writer internal filenames within the zip
file.

Eliminate unneeded Reader::FileNames collection. The file names
already exist in the FileList collection elements. The only existing
use for the FileNames collection was to determine if there were any
files at all, and with FileList and FileNames being parallel
vectors, they both had the same length so FileList could be used
for this test..

Use UniqueNameManager for document names and labels. This uses ad hoc
UniqueNameManager objects created on the spot on the assumption that
document creation is relatively rare and there are few documents, so
although the cost is O(n), n itself is small.

Use an ad hoc UniqueNameManager to name new DymanicProperty entries.
This is only done if a property of the proposed name already exists,
since such a check is more-or-less O(log(n)), almost never finds a
collision, and avoids the O(n) building of the UniqueNameManager.
If there is a collision an ad-hoc UniqueNameManager is built
and discarded after use.
The property management classes have a bit of a mess of methods
including several to populate various collection types with all
existing properties. Rather than introducing yet another such
collection-specific method to fill a UniqueNameManager, a
visitProperties method was added which calls a passed function for
each property. The existing code (e.g. getPropertyMap) would be
simpler if they all used this but the cost of calling a lambda
for each property must be considered. It would clarify the semantics
of these methods, which have a bit of variance in which properties
populate the passed collection, e.g. when there are duplicate names..
Ideally the PropertyContainer class would keep a central directory of
all properties ("static", Dynamic, and exposed by ExtensionContainer and
other derivations) and a permanent UniqueNameManager. However the
Property management is a bit of a mess making such a change a project
unto itself.
2025-02-24 10:23:53 -06:00
Kacper Donat
cc2efa90f8 Base: Add isNullOrEmpty string helper
This adds isNullOrEmpty string helper that cheks if string is... well
null or empty. It is done to improve readability of the code and better
express intent.
2025-02-21 15:04:43 +01:00
Benjamin Nauck
6d28a19a3e App: Add Document::addObject<T>(...) to simplify code 2025-02-10 18:33:00 +01:00
tritao
f7a0cece08 Base: Remove Boost-based filesystem and switch to standard <filesystem> 2025-02-10 10:48:54 -06:00
Benjamin Nauck
6f535f19fb Prefer to use BaseClass's isDerivedFrom<T> over non template or Base::Type's
Regex based changes, manually verified
2025-01-27 16:08:18 +01:00
Benjamin Nauck
085c5e67cd Modernizing countObjectsOfType functions 2025-01-14 14:23:46 +01:00
Benjamin Nauck
08fe94ef25 Add template based Document::countObjectsOfType
Also convert code to use this new method
2025-01-14 14:23:46 +01:00
Benjamin Nauck
39402e2083 Revert "Address the poor performance of the existing unique-name generation (#17944)"
This reverts commit 83202d8ad6.

# Conflicts:
#	src/Base/Tools.cpp
#	src/Base/Tools.h
2024-12-16 17:31:43 +01:00
Kevin Martin
5696c9add3 Address the poor performance of the existing unique-name generation (#17944)
* Address the poor performance of the existing unique-name generation

As described in Issue 16849, the existing Tools::getUniqueName method
requires calling code to form a vector of existing names to be avoided.

This leads to poor performance both in the O(n) cost of building such a
vector and also getUniqueName's O(n) algorithm for actually generating
the unique name (where 'n' is the number of pre-existing names).

This has  particularly noticeable cost in documents with large numbers
of DocumentObjects because generating both Names and Labels for each new
object incurs this cost. During an operation such as importing this
results in an O(n^2) time spent generating names.

The other major cost is in the saving of the temporary backup file,
which uses name generation for the "files" embedded in the Zip file.
Documents can easily need several such "files" for each object in the
document.

This update includes the following changes:

Create UniqueNameManager to keep a list of existing names organized in
a manner that eases unique-name generation. This class essentially acts
as a set of names, with the ability to add and remove names and check if
a name is already there, with the added ability to take a prototype name
and generate a unique form for it which is not already in the set.

Eliminate Tools::getUniqueName

Make DocumentObject naming use the new UniqueNameManager class

Make DocumentObject Label naming use the new UniqueNameManager class.
Labels are not always unique; unique labels are generated if the
settings at the time request it (and other conditions). Because of this
the Label management requires additionally keeping a map of counts
for labels which already exist more than once.
These collections are maintained via notifications of value changes on
the Label properties of the objects in the document.

Add Document::containsObject(DocumentObject*) for a definitive
test of an object being in a Document. This is needed because
DocumentObjects can be in a sort of limbo (e.g. when they are in the
Undo/Redo lists) where they have a parent linkage to the Document but
should not participate in Label collision checks.

Rename Document.getStandardObjectName to getStandardObjectLabel
to better represent what it does.

Use new UniqueNameManager for Writer internal filenames within the zip
file.

Eliminate unneeded Reader::FileNames collection. The file names
already exist in the FileList collection elements. The only existing
use for the FileNames collection was to determine if there were any
files at all, and with FileList and FileNames being parallel
vectors, they both had the same length so FileList could be used
for this test..

Use UniqueNameManager for document names and labels. This uses ad hoc
UniqueNameManager objects created on the spot on the assumption that
document creation is relatively rare and there are few documents, so
although the cost is O(n), n itself is small.

Use an ad hoc UniqueNameManager to name new DymanicProperty entries.
This is only done if a property of the proposed name already exists,
since such a check is more-or-less O(log(n)), almost never finds a
collision, and avoids the O(n) building of the UniqueNameManager.
If there is a collision an ad-hoc UniqueNameManager is built
and discarded after use.
The property management classes have a bit of a mess of methods
including several to populate various collection types with all
existing properties. Rather than introducing yet another such
collection-specific method to fill a UniqueNameManager, a
visitProperties method was added which calls a passed function for
each property. The existing code would be simpler if existing
fill-container methods all used this.
Ideally the PropertyContainer class would keep a central directory of
all properties ("static", Dynamic, and exposed by ExtensionContainer and
other derivations) and a permanent UniqueNameManager. However the
Property management is a bit of a mess making such a change a project
unto itself.

The unit tests for Tools:getUniqueName have been changed to test
UniqueNameManager.makeUniqueName instead.
This revealed a small regression insofar as passing a prototype name
like "xyz1234" to the old code would yield "xyz1235" whether or
not "xyz1234" already existed, while the new code will return the next
name above the currently-highest name on the "xyz" model, which could
be "xyz" or "xyz1".

* Correct wrong case on include path

* Implement suggested code changes
Also change the semantics of visitProperties to not have any short-circuit return

* Remove reference through undefined iterator

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

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

* Fix up some comments for DOxygen

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-12-13 10:54:46 -06:00
wmayer
fa5a171e9a Core: Do not detach object from document before the call of breakDependency
This fixes #17900
2024-11-25 18:25:17 +01:00
wmayer
fadfc7e270 App: Apply clang format (part 2) 2024-11-21 21:17:42 +01:00
wmayer
6e1e832039 Core: Fix flaw in XMLReader class
Remove implementation details of the Document class from the XMLReader class.
Instead keep an array of failed files and check them in the calling instance.
2024-11-17 08:34:03 +01:00
Yorik van Havre
054205d8c6 Merge pull request #17632 from wwmayer/issue_17553
Fixes #17553
2024-11-04 18:14:18 +01:00
wmayer
97ce877883 Core: Fixes #17553 2024-11-03 00:05:49 +01:00
wmayer
de18adba03 Core: Add wrapper function Application::applicationPid() 2024-11-01 15:48:01 +01:00
Zheng, Lei
c4d5cc5967 Transfer in LS3 code 2024-09-16 17:49:35 +02:00
bgbsww
27423dbb39 Toponaming: Support disabling hashing; getting element history 2024-08-22 11:24:09 -05:00
bgbsww
e425f2367f Toponaming: make sure toposhapes have hashers 2024-08-02 21:42:16 -04:00
Pieter Hijma
851f72ee72 Core: Add missing Python interpreter locks 2024-07-16 11:57:36 +02:00
PaddleStroke
5f4dd814ea Core: Add getRootObjectsIgnoreLinks and fix bugs in tree.cpp and AssemblyObject.cpp, CommandInsertLink.py, UtilsAssembly.py 2024-05-13 17:58:34 +02:00
Ladislav Michl
a691d6fcdc Base: Use std::chrono for time handling
Replace platform specific implementations with standard C++ std::chrono.
As time_t is now 64-bit on all supported systems, use it to set the clock.
2024-03-05 12:22:40 +01:00
Ladislav Michl
7b70d3fc6f Base: Move currentDateTimeString out of TimeInfo
currentDateTimeString does not have anything in common
with TimeInfo class, move it into Tools.
2024-03-05 12:22:40 +01:00
André Caldas
89dbab9b0e Avoids using getNameInDocument() to test if DocumentObject is attached to a Document.
This patch substitutes by isAttachedToDocument() (almost) everywhere where
getNameInDocument() is used for this purpose.

The very few places not touched by this patch demand a (just a little) less trivial change.
When we change the returning type of getNameInDocument() to std::string,
those places will be easily found, because they shall generate a compiler error
(converting std::string to bool).

Rationale:
The fact that getNameInDocument() return nullptr to indicate
that the object is not attached to a document is responsible for lots of bugs
where the developer does not check for "nullptr".

The idea is to eliminate all those uses of getNameInDocument() and, in the near future,
make getNameInDocument() return always a valid std::string.
2023-12-11 17:37:58 +01:00
bgbsww
c2bab7a2fa Move the unit schema into Project Information and remove all Project Unit System code (#11266)
* Add unit system to Project Information and store with document.

* Remove the project unit system

* Restore correct document activation signalling to fix test fail

* Remove commented out dead lines

* Restore ignore option for project unit schemas

* Whitespace fix

* Refresh after changing units

* Remove field label

* Property editor changes applied to unit system
2023-12-04 13:04:53 -06:00
wmayer
0c21c6298c Base: fix google-explicit-constructor 2023-11-22 23:47:29 +01:00
Florian Foinant-Willig
dbe1c6135a Fix #10910 2023-10-09 22:54:12 +02:00
wmayer
d305f306df Core: Revert superfluous changes made with PR #9521 2023-10-09 15:06:45 +02:00
AgCaliva
3ac69993c0 merge master via cli 2023-10-04 13:28:48 -03:00
dyylanhammond
3b44bba8ac Change default file saving preferences (#10781)
* Change default compression level from 3 to 7
* increase default thumbnail size to 256
2023-09-27 16:08:43 -05:00
AgCaliva
a4e90b2609 Merge branch 'master' into User/Document/Feature_level_units_selection_#7746 2023-09-25 22:58:23 -03:00
Chris Hennes
564f829e5c App/Toponaming: Minor code cleanup 2023-09-17 13:13:37 -05:00
Chris Hennes
9b55b3a70b App/Toponaming: Add StringHasher to Document 2023-09-17 13:13:37 -05:00
AgCaliva
3da00e36a3 Merge Master 2023-08-30 16:24:16 -03:00
wmayer
af8c05c507 App: modernize C++: return braced init list 2023-08-18 00:36:24 +02:00
wmayer
4991475341 App: modernize C++: use range-based for loop 2023-08-14 16:40:25 +02:00