Implement source maps between proto/document nodes

Add the node path to the document node and carry that over to the proto
nodes which are generated from that.
This pr also adds a compiler pass to assign the paths based on the
hierarchical structure of the nodegraph.

Test Plan: - Run units tests which check the path propagation works

Reviewers: Keavon

Reviewed By: Keavon

Pull Request: https://github.com/GraphiteEditor/Graphite/pull/1181
This commit is contained in:
Dennis Kobert
2023-04-27 11:02:04 +02:00
committed by Keavon Chambers
parent ef93f8442a
commit a4793fb284
8 changed files with 99 additions and 49 deletions
+13 -3
View File
@@ -120,6 +120,7 @@ pub struct ProtoNode {
pub construction_args: ConstructionArgs,
pub input: ProtoNodeInput,
pub identifier: NodeIdentifier,
pub document_node_path: Vec<NodeId>,
}
/// A ProtoNodeInput represents the input of a node in a ProtoNetwork.
@@ -170,11 +171,12 @@ impl ProtoNode {
Some(hasher.finish() as NodeId)
}
pub fn value(value: ConstructionArgs) -> Self {
pub fn value(value: ConstructionArgs, path: Vec<NodeId>) -> Self {
Self {
identifier: NodeIdentifier::new("graphene_core::value::ValueNode"),
construction_args: value,
input: ProtoNodeInput::None,
document_node_path: path,
}
}
@@ -270,13 +272,15 @@ impl ProtoNetwork {
let mut lookup = self.nodes.iter().map(|(id, _)| (*id, *id)).collect::<HashMap<_, _>>();
let compose_node_id = self.nodes.len() as NodeId;
let inputs = self.nodes.iter().map(|(_, node)| node.input.clone()).collect::<Vec<_>>();
let paths = self.nodes.iter().map(|(_, node)| node.document_node_path.clone()).collect::<Vec<_>>();
let resolved_lookup = resolved.clone();
if let Some((input_node, id, input)) = self.nodes.iter_mut().filter(|(id, _)| !resolved_lookup.contains(id)).find_map(|(id, node)| {
if let Some((input_node, id, input, path)) = self.nodes.iter_mut().filter(|(id, _)| !resolved_lookup.contains(id)).find_map(|(id, node)| {
if let ProtoNodeInput::Node(input_node, false) = node.input {
resolved.insert(*id);
let pre_node_input = inputs.get(input_node as usize).expect("input node should exist");
Some((input_node, *id, pre_node_input.clone()))
let pre_path = paths.get(input_node as usize).expect("input node should exist");
Some((input_node, *id, pre_node_input.clone(), pre_path.clone()))
} else {
resolved.insert(*id);
None
@@ -290,6 +294,7 @@ impl ProtoNetwork {
identifier: NodeIdentifier::new("graphene_core::structural::ComposeNode<_, _, _>"),
construction_args: ConstructionArgs::Nodes(vec![(input_node, false), (id, true)]),
input,
document_node_path: path,
},
));
return false;
@@ -644,6 +649,7 @@ mod test {
identifier: "id".into(),
input: ProtoNodeInput::Node(11, false),
construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![],
},
),
(
@@ -652,6 +658,7 @@ mod test {
identifier: "id".into(),
input: ProtoNodeInput::Node(11, false),
construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![],
},
),
(
@@ -660,6 +667,7 @@ mod test {
identifier: "cons".into(),
input: ProtoNodeInput::Network(concrete!(u32)),
construction_args: ConstructionArgs::Nodes(vec![(14, false)]),
document_node_path: vec![],
},
),
(
@@ -668,6 +676,7 @@ mod test {
identifier: "add".into(),
input: ProtoNodeInput::Node(10, false),
construction_args: ConstructionArgs::Nodes(vec![]),
document_node_path: vec![],
},
),
(
@@ -676,6 +685,7 @@ mod test {
identifier: "value".into(),
input: ProtoNodeInput::None,
construction_args: ConstructionArgs::Value(value::TaggedValue::U32(2)),
document_node_path: vec![],
},
),
]