Commit graph

282 commits

Author SHA1 Message Date
Yann Lanthony
6f0542c07e [core] Simplify handling of link assignment by value on Attribute
Centralize the handling of link assigment by value in a dedicated
private method.
Store link assignment by value in a separate member variable
`_linkExpression`, to avoid manipulating a internal `_value` that
can represent different concepts (value VS serialized edge expression).
2025-02-21 18:56:45 +01:00
Yann Lanthony
90acb93ea8 [core] Trigger node desc creation callback only for explicit node creation
The desc.Node.onCreated callback is a hook in the Node API for developers to
write custom behavior on a node first initialization.
By being called in the core.Node constructor, this was triggered in several situations
that don't match this idea and with unpredictable side effects (graph loading, node re-creation on undo...).

* Make `onNodeCreated` callback an explicit method on desc.Node.
* Remove the call to node descriptor's `onNodeCreated` callback outside core.Node constructor.
* Trigger this callback on explicit node creation (adding new node to graph, init a graph from a template).
2025-02-14 11:42:22 +01:00
Yann Lanthony
724e7fb387 [core] Graph: add missing GraphModification
In `initFromTemplate`, ensure that Publish nodes removal are grouped
under the same graph modification to trigger updates only once.
2025-02-06 16:46:05 +01:00
Yann Lanthony
87fbcee06d [core][graphIO] Improve node type version handling
* Deserialization: Replace the logic that defaulted the node type version to "0.0" when unspecified,
and assume that unspecified version on a node is targetting current node type version.
* Serialization: Only serialize node type versions for which a version info is available.

* Test suites:
  * Add helper context manager to manually override the version of a given node type.
  * Add new unit tests to cover version conflicts handling is various scenarios.
2025-02-06 16:46:05 +01:00
Yann Lanthony
e430368f15 [core] Graph: improve internal function naming 2025-02-06 16:46:05 +01:00
Yann Lanthony
9794f43ed1 [core] Graph: improved uid conflicts evaluation on deserialization
At the end of the deserialization process, solve node uid conflicts iteratively by node depths,
and only replace the conflicting nodes with a CompatibilityNode.

Add new test suite for testing uid conflict handling.
2025-02-06 16:46:04 +01:00
Yann Lanthony
45ef4b592d [core] Graph: add replaceNode method
Factorize the logic of replacing a node with another one and re-creating
output edges into `Graph.replaceNode`  and `Graph._restoreOutEdges`.
2025-02-06 16:46:04 +01:00
Yann Lanthony
1cf0fc95ba [core][graphIO] Add "template" as an explicit key 2025-02-06 16:46:04 +01:00
Yann Lanthony
b07dd64c11 [core] Graph: cleanup unused methods 2025-02-06 16:46:04 +01:00
Yann Lanthony
bfc642e2dc [core] Add Graph.copy method
Add a new method to create a copy of a graph instance, relying on
chaining serialization and deserialization operations.
Add test suite to validate its behavior, and the underlying serialization processes.
2025-02-06 16:46:04 +01:00
Yann Lanthony
d54ba012a0 [ui] Refactor node pasting using graph partial serialization
Re-implement node pasting by relying on the graph partial serializer,
to serialize only the subset of selected nodes.
On pasting, use standard graph deserialization and import the content
of the serialized graph in the active graph instance.

Simplify the positioning of pasted nodes to only consider mouse position
or center of the graph, which works well for the major variety of use-cases.
Compute the offset to apply to imported nodes by using the de-serialized
graph content's bounding box.
2025-02-06 16:46:04 +01:00
Yann Lanthony
f8f03b0bd5 [core] Graph: improve uid conflicts check on deserialization
Only perform uid check when we have both a serialized and a computed
UID.
If the node has not been serialized with a UID, it means that it does not
expect to match a specific value on deserialization.
2025-02-06 16:46:04 +01:00
Yann Lanthony
6b75dcb356 [core][graphIO] Introduce PartialGraphSerializer
Add a new serializer class to manage partial graph serialization logic,
ensuring to remove link expressions on attributes refering to nodes
that are not in the subset of nodes to serialize.
2025-02-06 16:46:04 +01:00
Yann Lanthony
01d67eb33d [graphIO] Introduce graph serializer classes
Move the serialization logic to dedicated serializer classes.
Implement both `GraphSerializer` and `TemplateGraphSerializer`
to cover for the existing serialization use-cases.
2025-02-06 16:46:04 +01:00
Yann Lanthony
a665200c38 [core] Introducing new graphIO module
Move Graph.IO internal class to its own module, and rename it to `GraphIO`.
This avoid nested classes within the core Graph class, and starts decoupling
the management of graph's IO from the logic of the graph itself.
2025-02-06 16:46:04 +01:00
Yann Lanthony
4aec741a89 [core] Graph: add importGraphContent API
Extract the logic of importing the content of a graph within a graph instance from
the graph loading logic.
Add `Graph.importGraphContent` and `Graph.importGraphContentFromFile`
methods.
Use the deserialization API to load the content in another temporary graph instance,
to handle the renaming of nodes using the Graph API, rather than manipulating
entries in a raw dictionnary.
2025-02-06 16:46:04 +01:00
Yann Lanthony
7eab289d30 [core] Graph: initial refactoring of graph loading API and logic
* API
Instead of having a single `load` function that exposes in its API
some elements only applicable to initializing a graph from a templates,
split it into 2 distinct functions: `load` and `initFromTemplate`.
Apply those changes to users of the API (UI, CLI), and simplify Graph
wrapper classes to better align with those concepts.

* Deserialization
Reduce the cognitive complexity of the deserizalization process
by splitting it into more atomic functions, while maintaining the
current behavior.
2025-02-06 16:46:04 +01:00
Yann Lanthony
c883c53397 [core] Refactor nodeFactory function
Rewrite `nodeFactory` to reduce cognitive complexity,
while preserving the current behavior.
2025-02-06 16:46:04 +01:00
Yann Lanthony
025e0e3322 [core] Move nodeFactory to its own module 2025-02-06 16:46:04 +01:00
waaake
3f47c54595 [ui] Application: Changing the current project refreshes the NodeEditor to reset the current Tab index 2024-12-31 09:56:48 +05:30
waaake
535f2f06b3 [core] Graph: Introduced 'isSaving' flag
The 'isSaving' flag is a way to identify if the project is currently being saved and serves as a way to correctly distinguish whether the current filepath change is due to a save or a new scene or a load operation
2024-12-30 10:25:56 +05:30
Yann Lanthony
a0398c45c0
[core] Graph: fix Graph.load missing return value
Add missing return statement for the load function, used by the UI to determine whether the load was successful.
2024-12-11 14:10:43 +01:00
Yann Lanthony
b0808f9040
[core] Fix errorneous docstring
Co-authored-by: Vivek <vivek_ve@outlook.com>
2024-11-18 10:07:02 +01:00
Yann Lanthony
61d35904ba [core] Discard attribute callbacks during graph loading 2024-11-14 19:11:08 +01:00
Yann Lanthony
c09a0d2327 [core] Add 'strictCompatibility' mode for loadGraph function
Provide a way to control how to handle node compatibility issues
when loading a Graph with the `strictCompatibility` parameter.
Introduce a new error type, GraphCompatibilityError, to be raised
when loading a Graph with compatibility issues with strictCompatibility enabled.
2024-11-14 19:11:08 +01:00
Aurore LAFAURIE
b6df2852e7 [ui] Recompute and Re-submit not allowed with Compatibility Nodes
Renaming of canCompute to canComputeTopologically to understand the static aspect of the function
2024-09-13 18:32:46 +02:00
Candice Bentéjac
41e885d9ff Linting: Clean-up files 2024-09-12 10:50:13 +02:00
Candice Bentéjac
b726387534 [core] Graph: Support loading files with previous UID system
The file version is updated and support for files with an older version
is added: upon detecting that the file version is old, the old UID
keys will be detected and reformatted with new ones so the file can
be properly loaded.
2024-09-12 10:41:53 +02:00
Candice Bentéjac
9973298746 [core] Simplify invalidation status for all the attributes
The UID system based on a UID index is removed and replaced by a single
UID per node.

Attributes will be included in the UID computation if the `invalidate`
is set to `True` in their description. This replaces the `uid=[]` /
`uid=[0]` element of the description.
2024-09-12 10:41:53 +02:00
Aurore LAFAURIE
5b92df328f Implementation of Homepage 2024-08-26 16:21:26 +02:00
Candice Bentéjac
5b07f9a393 [core] Exclude edges from InputNode nodes in dfsToProcess
If the edges of a node to submit include an `InputNode` (which cannot
be computed), then that node should be excluded from the list of edges
to process as if that node had already been computed.

This allows to submit any type of graph involving `InputNode` to the farm.
2024-07-02 12:18:35 +02:00
Candice Bentéjac
2bcf9d432c [core] Graph: Remove selectedViewpoint property
The information that this property conveys will be accessible at an upper
level and is thus redundant here.
2024-06-27 15:04:53 +02:00
Candice Bentéjac
d585b053a5 [core] Graph: Add a selectedViewpoint property
The `selectedViewpoint` property will store the attribute corresponding to
the actively selected viewpoint, if it exists. Otherwise, it will be set
to None.
2024-06-20 15:47:04 +02:00
Candice Bentéjac
154babbf5c
Merge pull request #2440 from alicevision/dev/sortToSave
File export ordering
2024-06-17 11:35:55 +02:00
Fabien Castan
8451f299ab Remove extra logging 2024-06-17 09:36:37 +02:00
Fabien Castan
620ba0c2cf [core] sort nodes by name in file export
Avoid randomness in the ordering during file export to facilitate
comparison of scene files.
2024-06-16 21:31:54 +02:00
Fabien Castan
3c4ebd9b25 [core] sort node types versions in file export 2024-06-16 21:29:23 +02:00
Fabien Castan
77571dca38 [core] init nodes uids from project file 2024-06-16 18:54:37 +02:00
Fabien Castan
d5e356c0aa [core] New dynamic output attributes 2024-06-15 19:47:29 +02:00
Fabien Castan
020dbecc68 [core] attribute: new initValue, independant from the resetToDefaultValue
Avoid to evaluate the default value if we don't need to.
2024-06-15 18:05:24 +02:00
Aurore LAFAURIE
0fc1c2f625 [core] Fix assign file date when saving file
When saving file we need to assign the new file date to prevent modified file popup
2024-06-03 15:28:23 +02:00
Fabien Castan
45fd86e51b
Merge pull request #2396 from alicevision/fix/getLatestSfMNode
[ui/core] Fix get latest SfM node for previz
2024-06-01 11:37:21 +02:00
Aurore LAFAURIE
e63c2df2a8 Compare last saved date before saving to prevent overwrite 2024-05-27 16:43:00 +02:00
Aurore LAFAURIE
663b6b66d4 [ui/core] Order last node of type according to node's depth and name 2024-05-17 10:27:32 +02:00
Aurore LAFAURIE
4e8c0c2cf8 [ui/core] Fix get latest SfM node for previz 2024-04-30 15:42:08 +02:00
Aurore LAFAURIE
5d70a51285 [core] Set internal attributes when copy/pasting nodes 2024-04-26 15:56:26 +02:00
Candice Bentéjac
e9ee9f2315 Update ListAttributes identically when removing edges or nodes
The behaviour regarding `ListAttributes` was different depending on
whether an edge or a node was removed:
- if an edge was removed, the `ListAttribute` that was the destination
of that edge had its corresponding element completely removed;
- if a node was removed, the `ListAttribute` that was the destination
of one of the node's edges had its corresponding element reset, but not
removed.

With this behaviour, a user had different UIDs depending on whether
a single edge or the whole node had been removed where the UID should
always be identical.
2024-02-02 15:23:44 +01:00
Candice Bentéjac
610ac36376 [core] Preserve edges by recreating all the nodes during UID evaluation
Up until this commit, compatibility nodes (which necessarily had a version
or description issue) were ignored during the evaluation of UID conflicts,
as they had no UID.

This however created a bug, where already existing compatibility nodes
with inputs from nodes that triggered UID conflicts were losing their
input connections: when the node with the UID conflict was replaced with
a new compatibility node (with a UID conflict issue), the link was broken
and could not be resolved anymore as it lost any mention of the input
node's name. This was also valid for nodes without any compatibility issue
which had UID conflicted-nodes as their inputs.

Processing all the nodes in addition to those with a UID conflict issue
prevents this from happening: edges are correctly preserved.

This also fixes an issue that occurred when opening a project file that
contained nodes whose type was not recognized. Instead of raising an
"unknown node type" compatibility issue, "attribute is already connected"
errors were raised for the unrecognized nodes.
2023-07-24 15:26:37 +02:00
Candice Bentéjac
cdf5c6746f [core] Graph: Detect UID conflicts when loading a graph
When loading the graph, once all the nodes have been created and the
links resolved, the computed nodes' UID can be compared with those
stored in the graph.

If a mismatch is detected, the node that presents the UID conflict is
removed from the graph and replaced with a CompatibilityNode, set with
`UidConflict`.

Nodes that come from templates are ignored as no UID is stored in
templates. Similarly, nodes that are already Compatibility nodes are left
out as they do not have a UID.
2023-06-16 09:02:59 +02:00
Loïc Vital
750d2d9b34 [core] graph: propagate dependenciesOnly through flowEdges args 2023-06-15 02:10:18 -07:00