Commit Graph

51 Commits

Author SHA1 Message Date
wmayer
2c3d9e2bb7 Base: Add C++ iostate methods to Writer class 2026-02-05 10:58:12 +01:00
Stephan T. Lavavej
9e6509a3a4 Avoid using non-Standard std::locale::empty() for MSVC 2025-11-14 00:22:18 -06:00
PhoneDroid
2a56489feb [ Base ]: Updated SPDX 2025-10-14 10:00:04 -05:00
Markus Reitböck
f0eca551b3 Base: 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-14 09:47:01 +02:00
Florian Foinant-Willig
7bf1b5d787 Fix FreeCAD#19588 2025-03-20 20:14:50 +01:00
Kevin Martin
41f09db9e1 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
Benjamin Bræstrup Sayoc
dda05369c4 Base: remove unneeded includes 2025-02-18 11:07:57 -06:00
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
pre-commit-ci[bot]
ef6cd173eb [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-06-24 03:34:21 +00:00
bgbsww
3c3709cb5d Toponaming: Fix save and restore of elementmaps 2024-06-23 23:33:12 -04:00
wmayer
85ead154c4 fix readability-make-member-function-const 2023-11-16 01:22:09 +01:00
wmayer
5c306f6e2a fix readability-*:
* readability-uppercase-literal-suffix
* readability-named-parameter
2023-11-16 01:22:08 +01:00
wmayer
f539138dd9 fix readability-*:
* readability-const-return-type
* readability-container-data-pointer
* readability-container-size-empty
* readability-delete-null-pointer
* readability-else-after-return
* readability-inconsistent-declaration-parameter-name
* readability-redundant-member-init
* readability-redundant-smartptr-get
* readability-redundant-string-cstr
* readability-use-anyofallof
* readability-static-definition-in-anonymous-namespace
* readability-static-accessed-through-instance
* readability-simplify-boolean-expr
2023-11-16 01:22:08 +01:00
wmayer
73a1e90e45 fix readability-identifier-length 2023-11-16 01:22:08 +01:00
wmayer
e85c383bff Base: apply clang format 2023-11-13 12:01:26 -05:00
Chris Hennes
9b11c36708 Base/Toponaming: Refactor to extract filters to new file 2023-10-10 11:28:30 -05:00
Chris Hennes
5b30bdc2f0 App/Toponaming: Linter cleanup of Base64 code
Does not address pointer arithmetic or array indexing complaints.
2023-10-10 10:19:44 -05:00
Chris Hennes
5975e3d51e App/Toponaming: Add base64 encoding to XML 2023-10-10 10:19:43 -05:00
wmayer
010dca8303 Base: C++ core guidelines: init variables 2023-08-24 18:48:52 +02:00
wmayer
4fb07bcfd6 Base: modernize C++: use default member init 2023-08-23 19:51:44 +02:00
wmayer
89d529ab7b modernize C++: use using 2023-08-06 23:17:10 +02:00
marioalexis
f1af39725a Base: Include needed header file 2023-05-16 12:46:34 -03:00
Chris Hennes
2e5f43e69b App/Toponaming: Add missing include to Writer 2023-05-11 14:34:35 -05:00
Chris Hennes
0a2eacade2 App/Toponaming: Lint and compilation cleanup 2023-05-11 14:34:35 -05:00
Chris Hennes
1c0cf32b22 App/Toponaming: Add supporting code
Support for reading and writing binary data, and a small tweak to bitmask.
2023-05-11 14:34:35 -05:00
berniev
8aff4a7503 Base: Modernise ctors dtors defs etc 2022-08-02 12:37:46 +02:00
wmayer
6b6df27df8 C++ core guidelines:
* ES.87: Don’t add redundant == or != to conditions
2022-06-25 17:38:57 +02:00
wmayer
cbc0bfc24d Base: cosmetic changes 2022-05-12 17:49:55 +02:00
wmayer
2465840791 Base: fix warnings from code analysers:
* replace some C-style casts with static_cast
* remove unneeded destructors
* define default copy-constructor and assignment operator
2022-03-05 19:03:21 +01:00
Uwe
7b14b3b02e [Base] Reader and Writer: remove unused includes 2022-02-27 23:54:00 +01:00
Uwe
6a606783d6 [Base] remove unused code 2022-02-27 19:30:09 +01:00
wmayer
4d87039635 Base: modernize C++11
* remove redundant void-arg
* use nullptr
* replace deprecated headers
2022-01-25 20:21:30 +01:00
luz paz
d5f6c096b8 Base: Fix header uniformity, whitespace, and doxygen
[skip ci]
2020-11-22 18:12:16 +01:00
wmayer
767b2787c1 LGTM: [skip ci] remove some obsolete FIXME comments from source code 2020-07-28 09:49:20 +02:00
luz.paz
6f11ed298a src/Base: [skip ci] fix header uniformity
This PR fixes header uniformity across all `src/Base` files
2019-12-25 11:38:58 +01:00
asapelkin
8bc5b585c8 Used single quotes for single character in string::find algorithm, more efficient 2019-11-21 18:59:43 +01:00
wmayer
bd89326d06 avoid using hard-code precision when writing double to streams 2019-02-23 14:58:41 +01:00
Abdullah Tahiri
714604e58f ZipStream: Change precision from 12 to 16 decimals
==================================================

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=3&t=32212&start=10#p269080
2018-11-19 11:31:08 +01:00
wmayer
1673ab801e use specialized exception classes 2017-04-28 18:49:11 +02:00
wmayer
7d09444dd9 + fixes #0001237: the project file is not saved when the /tmp directory is full, but the user is not aware of it 2015-09-19 18:59:22 +02:00
wmayer
e5c3a09502 + for file-based recovery write the data files in worker threads 2015-09-19 13:12:59 +02:00
wmayer
8db1280a4d + make RecoveryWriter more robust 2015-09-18 15:32:33 +02:00
wmayer
bb05d17596 + implement FileWriter class based on files and a specialized sub-class for recovery purposes 2015-09-17 21:37:47 +02:00
wmayer
32367b1744 + save Brep in binary format for recovery files 2015-09-16 22:58:47 +02:00
Sebastian Hoogen
fc14611c93 use 4 spaces to indent XML output 2014-12-10 01:33:51 +01:00
wmayer
f69b57459b Support to write vector list and float lists in old format, fix issues in property editor, move back to float for curvature type 2013-03-30 12:32:53 +01:00
wmayer
ef24e4d2e6 Implement CDATA reader, fix bugs in Writer::insertBinFile 2012-05-31 11:50:25 +02:00
wmayer
435d4f82d7 fix some issues when writing binary data into an XML file 2012-05-10 12:07:37 +02:00
wmayer
a65d4fdda6 + implement global draw styles
+ use double precision in XML file
+ fix crash with in SoBrepFaceSet

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5083 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
2011-11-01 13:52:38 +00:00