Commit Graph

339 Commits

Author SHA1 Message Date
Benjamin Nauck
a2c980f7d6 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
83202d8ad6 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
eb3ce44b58 Core: Do not detach object from document before the call of breakDependency
This fixes #17900
2024-11-25 18:25:17 +01:00
wmayer
5771c94523 App: Apply clang format (part 2) 2024-11-21 21:17:42 +01:00
wmayer
6f8abe880c 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
8ac217a7b0 Merge pull request #17632 from wwmayer/issue_17553
Fixes #17553
2024-11-04 18:14:18 +01:00
wmayer
400d5c49ab Core: Fixes #17553 2024-11-03 00:05:49 +01:00
wmayer
c6f083b3e7 Core: Add wrapper function Application::applicationPid() 2024-11-01 15:48:01 +01:00
Zheng, Lei
445a884682 Transfer in LS3 code 2024-09-16 17:49:35 +02:00
bgbsww
40d23c2639 Toponaming: Support disabling hashing; getting element history 2024-08-22 11:24:09 -05:00
bgbsww
cd128984e1 Toponaming: make sure toposhapes have hashers 2024-08-02 21:42:16 -04:00
Pieter Hijma
44387a793b Core: Add missing Python interpreter locks 2024-07-16 11:57:36 +02:00
PaddleStroke
344b125a07 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
159fe5c21f 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
de1305413e 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
560898907b 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
a1c08dbf43 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
dcd533af4b Base: fix google-explicit-constructor 2023-11-22 23:47:29 +01:00
Florian Foinant-Willig
191aee568f Fix #10910 2023-10-09 22:54:12 +02:00
wmayer
56820718c5 Core: Revert superfluous changes made with PR #9521 2023-10-09 15:06:45 +02:00
AgCaliva
2212e68a30 merge master via cli 2023-10-04 13:28:48 -03:00
dyylanhammond
f1a6a9e3a6 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
1f9bae0de7 Merge branch 'master' into User/Document/Feature_level_units_selection_#7746 2023-09-25 22:58:23 -03:00
Chris Hennes
b8055fa6f4 App/Toponaming: Minor code cleanup 2023-09-17 13:13:37 -05:00
Chris Hennes
2a386c9f6f App/Toponaming: Add StringHasher to Document 2023-09-17 13:13:37 -05:00
AgCaliva
39dcb1da7b Merge Master 2023-08-30 16:24:16 -03:00
wmayer
89bdd489b0 App: modernize C++: return braced init list 2023-08-18 00:36:24 +02:00
wmayer
26f16f7410 App: modernize C++: use range-based for loop 2023-08-14 16:40:25 +02:00
AgCaliva
0c4ef0e106 merge master 2023-08-08 23:29:40 -03:00
wmayer
0af4990817 modernize C++: make unique 2023-08-07 19:51:30 -06:00
wmayer
96aabe113e modernize C++: raw string literal 2023-08-07 19:51:15 -06:00
wmayer
5621a0089f Qt6 port:
Fix deprecation warnings with version 6.3 or 6.4
2023-08-04 21:23:14 -06:00
wmayer
6a726f6c88 Core: report the real error of a failed feature after a recompute 2023-08-04 18:47:44 -06:00
Zheng, Lei
a5e350ad46 App: fix removing object while recomputing
Fixes #9912
2023-07-23 19:40:01 +00:00
Ajinkya Dahale
c3e395f963 [Core] Use FCBak extension with timestamp by default 2023-07-23 19:37:10 +00:00
AgCaliva
816d4077df Implemented DocumentReader for GuiDocument.xml reading. Final 2023-06-30 20:50:36 -03:00
AgCaliva
0751770bc6 Revert "DocumentReader implemented for GuiDocument.xml reading."
This reverts commit 5f101af3e9.
2023-06-30 20:27:12 -03:00
AgCaliva
5f101af3e9 DocumentReader implemented for GuiDocument.xml reading. 2023-06-30 18:41:00 -03:00
Chris Hennes
a8f2a32397 GUI: Don't have report view message tell users to see report view 2023-05-06 18:19:08 +02:00
luzpaz
129d5882a7 Migrate domain name from freecadweb to freecad (#9352)
* Migrate domain name from freecadweb to freecad
* Migrate src/Mod/Material files
* Migrate Stylesheet related files
* Migrate *.svg files
* Migrate miscellaneous files
* Migrate some build files
* Migrate recently added TD AR_IRAM template files

Closes #6415
2023-04-24 15:19:20 -05:00
berniev
0a5e59adae an example of using constexpr array for data
simplifies code and removes the need for a class.
2023-03-07 23:22:44 +01:00
wmayer
d03f287cf4 App: using fmtlib causes a linking failure together with boost's graphviz classes
To fix this failure a workaround is move the graphviz handling from Document.cpp to a separate source file
See also: https://github.com/FreeCAD/FreeCAD/pull/8350
2023-03-04 19:08:11 +01:00
wmayer
4036613fd2 App: refactor license handling to reduce code duplication 2023-02-12 19:57:41 +01:00
alexneufeld
8f06403537 Gui: Add CERN OHL to default licenses list 2023-02-12 10:31:59 +01:00
wmayer
c3b38bda08 App: [skip ci] fix warnings reported by GH actions 2022-11-17 23:50:34 +01:00
wmayer
e10b23ca70 App: replace boolean with enum 2022-11-17 17:38:31 +01:00
wmayer
ea5a5ff363 App: [skip ci] for the dependency graph use orange color to indicate links that go out of scope 2022-10-08 16:29:36 +02:00
wmayer
5240a30431 App: modernize C++: replace 'typedef' with 'using' 2022-08-29 12:58:39 +02:00
wmayer
cf399afe87 App: minor improvements:
* use 'using' instead of 'typedef' [modernize-use-using]
* fix bugprone-reserved-identifier
* fix whitespace/comma
2022-08-28 16:15:57 +02:00
wmayer
e809295342 App: replace some while loops with range-based for loops to increase readability 2022-08-28 15:42:57 +02:00