Commit Graph

262 Commits

Author SHA1 Message Date
forbes
9809ff852c feat: .kc file format — Layer 1 (format registration)
Cherry-picked from feat/kc-file-format-layer1 (723a8c98d5).
- Document.cpp: checkFileName() accepts .kc extension
- FreeCADInit.py: register .kc import type
- Dialog filters: Save As, Save Copy, Merge, Project Utility
- kc_format.py: DocumentObserver preserves silo/ entries across saves
- InitGui.py: register kc_format observer on startup
2026-02-13 14:10:36 -06:00
tritao
69058376e6 Base: Remove Boost-based signals and switch to FastSignals. 2026-01-07 21:16:16 +00:00
PaddleStroke
450789e77b Sketcher: Fix text sometimes reversed when switching from one sketch edit to another.
Sometimes when user would switch from editing one sketch to edit to another sketch by double clicking on the new sketch, without living the previous sketch, it would then render the text of constraints backward. This was happening because the unsetEdit of the previous sketch was clearing the selection and adding the old sketch as selected. Then the new setEdit was failing to find the correct editing placement resulting in backward text.
2026-01-05 16:17:04 +01:00
PaddleStroke
46a847c857 Gui: Do not lose thumbnail when saving partially loaded doc (#25458) 2025-11-26 13:53:11 -06:00
Syres916
83c01fae68 [Gui] Fix string encoding for document name 2025-11-20 20:02:21 +00:00
Chris Hennes
4d0c35dd2d Core: Convert transparency to alpha (#24891)
* Core: Convert transparency to alpha

Create new `Base::getVersion()` function for extracting a program
version enumeration given a version string.

Convert transparency to alpha value for old project files.

* Base/App: Address review comments

---------

Co-authored-by: wmayer <wmayer@freecad.org>
2025-11-17 17:15:19 +01:00
pre-commit-ci[bot]
25c3ba7338 All: Reformat according to new standard 2025-11-11 13:49:01 +01:00
Markus Reitböck
6ef07bb358 Gui: 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:03 +02:00
Max Wilfinger
ecf02b7878 Gui: Update UI strings for consistency
Closes: #22135
2025-08-04 20:14:45 +02:00
jffmichi
450846c4bc Gui: enable dock/undock/fullscreen for all MDI widgets 2025-07-21 00:44:18 +02:00
wmayer
ce6641cb81 Gui: Handle exception when trying to start editing an object 2025-05-30 18:04:33 +02:00
wmayer
8de63825cf Gui: Fix stackoverflow when loading corrupted file
If an object has a link to itself it may cause a stackoverflow
in several cases:
* If the method claimChildren3D() returns a list containing the
  object of the view provider then Document::handleChildren3D()
  will add a SoGroup to itself as a child. This will result into
  a stackoverflow as soon as an action traverses the scene.
* If the method claimChildren() returns a list containing the
  object of the view provider then DocumentItem::createNewItem()
  causes an infinite loop with DocumentItem::populateItem()

Solution:
* Inside Document::handleChildren3D() avoid to add a SoGroup to itself
* In this specific case fix ViewProviderCoordinateSystem::claimChildren()
  to avoid a cyclic dependency

Hint: Since PR 18126 FreeCAD is vulnerable for this problem.

This fixes issue 19682
2025-05-30 18:04:33 +02:00
Joao Matos
1f5e0f6494 App: Invoke signalBeforeRecompute() on the GUI thread
Historically, `App::Document::recompute()` ran entirely on the **main**
(GUI) thread and directly emitted `signalBeforeRecompute()`.

* Add-ons like **Assembly3** and others depend on that signal for
setup/teardown hooks before any recompute work begins.

* After offloading `recompute()` into a background worker thread to keep
the UI responsive, calling `signalBeforeRecompute()` directly from the
worker would break thread-affinity rules and silently break
compatibility with those add-ons.

**Solution**

1. **Introduce a generic hook** (`PreRecomputeHook`) in
**App::Document**:

* A `std::function<void()>` that, if set, is invoked at the very
start of `recompute()`.

* Core code stays Qt-free—only knows to call a callback if one
exists.

2. **Wire up the hook in `Gui::Document`**:

* In the GUI wrapper’s constructor, install a hook that calls
`callSignalBeforeRecompute()`.

* `callSignalBeforeRecompute()` uses `QMetaObject::invokeMethod(...,
Qt::BlockingQueuedConnection)` to enqueue `signalBeforeRecompute()` on
the GUI thread and **block** the worker until it completes.

    * If already on the GUI thread, it simply calls the signal directly.

3. **Maintain add-on compatibility**:

* From the add-on’s perspective nothing changes—they still receive
`signalBeforeRecompute()` on the main thread before any recompute work.

* Internally, the recompute body now runs on a worker thread,
improving UI responsiveness without breaking existing hooks.

**Result**

* **Recompute** remains fully backward-compatible for add-ons like
Assembly3.

* **UI thread** still handles all GUI-related signaling.

* **Worker thread** performs the actual heavy lifting, unblocked only
once the GUI is primed and all pre-recompute signals have been
delivered.
2025-05-19 18:30:56 +02:00
Chris Hennes
f5806841b6 Merge pull request #19907 from benj5378/getAttribute
Base: make getAttribute template
2025-05-12 10:39:55 -05:00
Benjamin Bræstrup Sayoc
6786af6ef9 Everywhere: clean up getAttribute conversions 2025-05-09 15:54:57 +02:00
Benjamin Bræstrup Sayoc
492b8312b3 Base: make getAttribute template 2025-05-09 15:54:57 +02:00
xtemp09
54fdd62fc7 Gui: Add switching to the document when closing FreeCAD (#21135)
* Add switching to the document when closing FreeCAD

Closes #20997

* Some update of language

* camelCase every variable name used
2025-05-08 23:59:11 +02:00
bofdahof
998f4e4d45 Console: rename PascalCase named methods to camelCase 2025-05-06 17:50:21 +02:00
Ladislav Michl
c293d74566 Base: rename Exception's PascalCase methods to camelCase 2025-05-05 23:50:01 +02:00
Benjamin Nauck
a882289995 Gui: use contains() and isEmpty() instead of count() where possible 2025-05-03 22:19:51 +02:00
Kacper Donat
6e2583cdcd Gui: Use freecad_cast whenever possible 2025-04-26 14:23:25 +02:00
Kacper Donat
b300c80b90 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
Kacper Donat
35a9673a75 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
João Martins
83c1c76b04 Assembly: Allow more than one assembly deactivation (#20461)
Fixes #18631.
2025-03-26 19:25:53 +01:00
bofdahof
e5b06ae736 Gui: apply std::ranges 2025-03-16 17:15:14 -05:00
Joao Matos
3b05b61de2 Gui: Remove QtOpenGL.h. 2025-02-25 23:03:51 +00:00
Joao Matos
91e94ba1dd Gui: Cleanup Qt OpenGL usings in QtOpenGL.h.
Previously the code defined compatiblity usings in `QtOpenGL.h` header,
which I think was added for backwards compatiblity with previous Qt
OpenGL widgets.

As far as I can tell, this is not necessary anymore, and can be cleaned
up.
2025-02-25 23:03:51 +00: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
Kacper Donat
12a69fe296 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 Bræstrup Sayoc
f647d4a1eb Gui: Use QStringLiteral 2025-02-10 18:34:57 +01:00
Benjamin Nauck
dd6aa9f3c7 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
tritao
08c1275ec4 Gui: Introduce Gui::Document::createView to Python. 2025-01-17 12:35:14 -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
PaddleStroke
ef3445e9e1 Core / Assembly: Add a way for vp edit modes to be restored. 2024-11-29 12:04:25 -05:00
wmayer
3db3f7546d Gui: Add overloaded function Document::openEditingView3D(const App::DocumentObject*) 2024-11-22 12:00:56 -05:00
wmayer
c5c64a9c70 Core: Refactor Document::setEdit 2024-10-27 13:13:11 -05:00
wmayer
6c0659711b Core: Do not save changes of a text object if the GUI document is about to be closed
This fixes #16873: Text document breaks some Analysis container objects
2024-10-02 20:42:00 -06:00
bgbsww
0f53f2195d Add override flag for recomputes; set it in relevant tests with old files. 2024-09-16 17:49:35 +02:00
bgbsww
a54f03f666 Move code for recompute dialog and disable warning 2024-09-16 17:49:35 +02:00
hlorus
16cfe2f499 [MeasureGui] Use temporary measure object creation (#15122)
* MeasureGui: Store measure type in TaskMeasure

* MeasureGui: Avoid adding measurement to document during command interaction

* [Gui] Add check for document in VPDocumentObject::getActiveView

* MeasureGui: Track the document when adding objects

* MeasureGui: Cleanup python measurement creation

* [Gui] Add isAnnotationViewProvider method

* [Gui] Check if viewprovider is added as an annotation in getActiveView

* [Gui] Add takeAnnotationViewprovider method to Gui::Document

* [Gui] Make addViewProvider public

* [MeasureGui] Add existing view provider to document when storing measurement

* [MeasureGui] Fix invocation of initial label placement

* [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-02 11:54:05 -04:00
Pieter Hijma
44387a793b Core: Add missing Python interpreter locks 2024-07-16 11:57:36 +02:00
PaddleStroke
974f57cf94 Core: Add Gui::Document::getTreeRootObjects() 2024-06-12 10:57:24 +02:00
Kuzma30
32b55a6c1c Fix potential problems. https://forum.freecad.org/viewtopic.php?t=70256#p762073 2024-05-27 11:57:26 -05:00
Kuzma30
bb4ef6dae2 Use for predefined filename string its Label value 2024-05-27 11:57:26 -05:00
wmayer
d89bece39a Gui: Replace TreeRank property with a simple int
This fixes that copied & pasted objects are not added at the end of the tree view.
See https://forum.freecad.org/viewtopic.php?p=755532#p755532
2024-05-06 18:24:20 +02: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
Chris Hennes
aaa0db3867 Merge pull request #11231 from DeflateAwning/http-cleanup
Find and replace http://freecad to https://freecad
2023-11-06 11:16:13 -06:00
DeflateAwning
8de6db3e97 Find and replace http://freecad.org to https://freecad.org
Find and replace:
http:\/\/(.{0,10})freecad
https://$1freecad
Done in all remaining files (after doing it in SVGs in the last commit)
2023-10-29 22:39:22 -06:00