* 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>
A frozen object prevents the document to be saved
The frozen status propagates into object inheritance
A frozen sketch is no more editable
Transform and Placement can't be changed for a frozen object
The freeze icon is reduced
* Fixed a mistake made in getSubObjectListFlatten()
* Applied modifications according to review comments
Signed-off-by: CalligaroV <vincenzo.calligaro@gmail.com>
* Formatted and refactored code imported for the DocumentObject class
* Formatted and refactored code imported for the SubObjectT class
Signed-off-by: CalligaroV <vincenzo.calligaro@gmail.com>
* Added SubObjectT methods normalize(), normalized(), hasSubObject() and hasSubElement()
* Updated DocumentObject::getSubObjectList()
* Applied modifications to make the code compile
In order to make getNameInDocument() always return a valid string,
we implement a getDagKey() method that shall be used instead of getNameInDocument()
when we want to use the pointer value as a "key" to identify the DocumentObject.
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.
====================================================
Before this commit there is a function getFullName(), which
produces a string in the form document#objectname. For "document"
the real name of the document is taken, whereas for objectname it
is the initial name (Sketch, Sketch001), not the label.
The new function fo this commit, getFullLabel(), provides a string
documentlabel#documentobjectlabel, that are
probably easier to identify for end users.
* Part: fix Placement/Shape onChanged() handling
* App: fix property ordering problem when undo/redo
See https://tracker.freecadweb.org/view.php?id=4265#c14271
* Gui: fix undo/redo signaling
Make sure to signal after all properties has been restored
Found via `codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,anormal,apoints,ba,beginn,behaviour,bloaded,bottome,byteorder,calculater,cancelled,cancelling,cas,cascade,centimetre,childrens,childs,colour,colours,commen,connexion,currenty,dof,doubleclick,dum,eiter,elemente,ende,feld,finde,findf,freez,hist,iff,indicies,initialisation,initialise,initialised,initialises,initialisiert,inout,ist,itsel,kilometre,lod,mantatory,methode,metres,millimetre,modell,nd,noe,normale,normaly,nto,numer,oce,oder,ontop,orgin,orginx,orginy,ot,pard,parm,parms,pres,programm,que,rady,recurrance,ro,rougly,seperator,serie,sinc,strack,substraction,te,technic,thist,thru,tread,uint,unter,vertexes,wallthickness,whitespaces -S ./.git,*.po,*.ts,./ChangeLog.txt,./src/3rdParty,./src/Mod/Assembly/App/opendcm,./src/CXX,./src/zipios++,./src/Base/swig*,./src/Mod/Robot/App/kdl_cp,./src/Mod/Import/App/SCL,./src/WindowsInstaller,./src/Doc/FreeCAD.uml,./build/doc/SourceDocu`
* [App] DocumentObject.cpp: Add more information to the error message printed to the console when links go out of allowed scope, namely linked object name(s), allowed scope name, invalid scope name(s).
=============================================
New mechanism for on-demand signaling of undo/redo transaction finalisation.
The mechanism consists of:
1) A status bit that is set, when an object should receive this signaling (e.g. because changes during transaction have been inhibited)
2) The new function to be called by the Document undo/redo actions when the transaction is over (for those objects having the status bit set).
Note 1: The undo/redo signals are now outside the undoing FlagToggler, this means that:
1) a call to isPerformingTransaction will return false.
2) a recompute the slot of such a signal will not be inhibited.
Note 2: The undo/redo signals are called once the documentobjects that requested to be notified after the trasaction is over have been notified.
The consequence is that the viewprovider can rely on the documentobject having a correct status.
I think that the behaviour of Note and Note 2 is the wanted behaviour of this signals, I cannot rule out that other parts of FC rely on the old
implementation.
Found via `codespell -q 3 -L aci,ake,aline,alle,alledges,alocation,als,ang,anid,ba,beginn,behaviour,bloaded,byteorder,calculater,cancelled,cancelling,cas,cascade,centimetre,childs,colour,colours,commen,currenty,dof,doubleclick,dum,eiter,elemente,feld,freez,hist,iff,indicies,initialisation,initialise,initialised,initialises,initialisiert,ist,kilometre,lod,mantatory,methode,metres,millimetre,modell,nd,noe,normale,normaly,nto,numer,oder,orgin,orginx,orginy,ot,pard,pres,programm,que,recurrance,rougly,seperator,serie,sinc,strack,substraction,te,thist,thru,tread,uint,unter,vertexes,wallthickness,whitespaces -S ./.git,*.po,*.ts,./ChangeLog.txt,./src/3rdParty,./src/Mod/Assembly/App/opendcm,./src/CXX,./src/zipios++,./src/Base/swig*,./src/Mod/Robot/App/kdl_cp,./src/Mod/Import/App/SCL,./src/WindowsInstaller,./src/Doc/FreeCAD.uml`
This patch adds support of recomputation with external linked object,
as well as external document auto loading and partial loading.
Application:
* Modified new/openDocument()/signalNewDocument to choose whether to
signal GUI for creating a view for the document. This makes it possible
to suppress view creation when opening external documents.
* New API openDocuments() which does the actual job of loading the
document together with any external dependencies. There are afew
extra arguments to allow setting FileName property differently from
the actual file path, which are required when auto loading
dependencies during document recovery (with future patch to
Gui::DocumentRecovery)
* openDocumentPrivate() is an internal helper for opening individual
document.
* New signalStart/FinishOpenDocument to be signaled before and after
opening a document. There may be multiple depending documents actually
opened in between these two signals.
* New signalBeforeRecomputeDocument signaled before recompute a
document.
* New API addPendingDocument() for use by external capable link
properties' to queue up external documents.
* isRestoring/isClosingAll(), for convenience status reporting.
Document:
* signalFinishImport/RestoreObjects, new signal triggered after imported
or restored all input objects
* signalBeforeRecompute, signaled before start recomputing this document
* Modified signalRecomputed with additional recomputed objects, this is
to make it more efficient for Gui::TreeWidget to check recomputation
result.
* signalSkipRecompute, signal to inform which objects are skipped
during recomputation because of their owner document SkipRecompute
setting.
* restore/save/read/writeObjects() modified to suport partial
loading. See [here](https://git.io/fj6PY) for more information.
* afterRestore(), internal function called to finish restore. The
function is separated from restore() because there is quite a few
critical steps needed to fully restore a document with external
linking. See [here](https://git.io/fj6P4) for more information.
* DocumentP::_RecomputeLog is modified to store more accurate object
recomputation error, including those happened during restore/import.
* isExporting(), new API for checking if an object is exporting.
External linking properties will use this function to decide how to
export.
* copyObject(), modified to support external linking objects, and
accepts multiple input objects.
* moveObject(), modified to support arbitary object moves. The original
implementation may cause crash if undo/redo is enabled. Furthermore,
because the original information fakes the object's deletion to break
its dependency, it does not work for objects that may auto delete their
children when being deleted. The new implementation copy the object,
and than paste it to the other document. It then deletes the input
objects from the original document. In case of recursive move, it only
deletes the depending object if it has an empty in list.
* importLinks(), new API to import any external object linked by the
input objects into this document. It will auto correct all link
references after importing.
* getDependencyList/_rebuildDependencyList(), these two APIs are unified
and implemented by an internal function _buildDependencyList() with a
new algorithm to handle external objects. The returned dependency list
will now include objects from external documents. In case of cyclic
dependencies, getDpendencyList() will report the actual objects
involved in dependency loops.
* mustExecute(), new API to check if there are any object requires
recomputation. This function will call _buildDependencyList() and
check for external objects as well.
* addRecomputeObject(), new API for marking changes during document
restore. It only marks the object but does not actually recompute
them for performance reason. One use case is for geo feature to
request for recomputation to generate geometry topological names.
* recompute(), support partial, external, and inverse dependency
recomputation. Improve error handling during recomputation.
See [here](https://git.io/fj6PO) for more information.
* _recomputeFeature(), suppoert user abort.
* getDependentDocuments/getInList(), new API to obtain an optional
dependency sorted list of depending documents.
DocumentObject:
* Add various ObjectStatus flags
* isExporting/getExportName(), return a safe name for exporting, in the
form of <ObjName>@<DocName>, which is guarrenteed to be unique.
Various link property will save linked object using this name if the
the linked object is exported together with the owner object, see
[PropertyLinkBase::restoreLabelReference()](https://git.io/fj6XO)
for more information.
* recomputeFeature(), add option to recompute this object together with
all its dependent objects.
* canLoadPartial(), new API for [partial document loading](https://git.io/fj6PY).
MergeDocuments:
* Move object name mapping logic to various link properties. See
Base::Sequencer:
* Add new API checkAbort() for checking user abort.