Rename `NodeInput::Network` to `NodeInput::Import` (#3163)

This commit is contained in:
Keavon Chambers 2025-09-10 20:50:15 -07:00 committed by GitHub
parent 332088bce1
commit 9a32e79853
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 102 additions and 122 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -169,30 +169,26 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
nodes: [
// Primary (bottom) input type coercion
DocumentNode {
inputs: vec![NodeInput::network(generic!(T), 0)],
inputs: vec![NodeInput::import(generic!(T), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphic::to_graphic::IDENTIFIER),
call_argument: concrete!(Context),
..Default::default()
},
// Secondary (left) input type coercion
DocumentNode {
inputs: vec![NodeInput::network(generic!(T), 1)],
inputs: vec![NodeInput::import(generic!(T), 1)],
implementation: DocumentNodeImplementation::ProtoNode(graphic::wrap_graphic::IDENTIFIER),
call_argument: concrete!(Context),
..Default::default()
},
// Store the ID of the parent node (which encapsulates this sub-network) in each row we are extending the table with.
DocumentNode {
inputs: vec![NodeInput::node(NodeId(1), 0), NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::DocumentNodePath)],
implementation: DocumentNodeImplementation::ProtoNode(graphic::source_node_id::IDENTIFIER),
call_argument: concrete!(Context),
..Default::default()
},
// The monitor node is used to display a thumbnail in the UI
DocumentNode {
inputs: vec![NodeInput::node(NodeId(2), 0)],
implementation: DocumentNodeImplementation::ProtoNode(memo::monitor::IDENTIFIER),
call_argument: concrete!(Context),
skip_deduplication: true,
..Default::default()
},
@ -290,12 +286,12 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
call_argument: generic!(T),
implementation: DocumentNodeImplementation::ProtoNode(artboard::create_artboard::IDENTIFIER),
inputs: vec![
NodeInput::network(concrete!(TaggedValue), 1),
NodeInput::import(concrete!(TaggedValue), 1),
NodeInput::value(TaggedValue::String(String::from("Artboard")), false),
NodeInput::network(concrete!(TaggedValue), 2),
NodeInput::network(concrete!(TaggedValue), 3),
NodeInput::network(concrete!(TaggedValue), 4),
NodeInput::network(concrete!(TaggedValue), 5),
NodeInput::import(concrete!(TaggedValue), 2),
NodeInput::import(concrete!(TaggedValue), 3),
NodeInput::import(concrete!(TaggedValue), 4),
NodeInput::import(concrete!(TaggedValue), 5),
],
..Default::default()
},
@ -303,7 +299,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
inputs: vec![NodeInput::node(NodeId(0), 0), NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::DocumentNodePath)],
implementation: DocumentNodeImplementation::ProtoNode(graphic::source_node_id::IDENTIFIER),
call_argument: concrete!(Context),
..Default::default()
},
// The monitor node is used to display a thumbnail in the UI.
@ -316,9 +311,8 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![
NodeInput::network(graphene_std::Type::Fn(Box::new(concrete!(Context)), Box::new(concrete!(Table<Artboard>))), 0),
NodeInput::import(graphene_std::Type::Fn(Box::new(concrete!(Context)), Box::new(concrete!(Table<Artboard>))), 0),
NodeInput::node(NodeId(2), 0),
],
implementation: DocumentNodeImplementation::ProtoNode(graphic::extend::IDENTIFIER),
@ -431,14 +425,12 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::node(NodeId(1), 0)],
nodes: [
DocumentNode {
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::scope("editor-api"), NodeInput::network(concrete!(String), 1)],
call_argument: concrete!(Context),
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::scope("editor-api"), NodeInput::import(concrete!(String), 1)],
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::load_resource::IDENTIFIER),
..Default::default()
},
DocumentNode {
inputs: vec![NodeInput::node(NodeId(0), 0)],
call_argument: concrete!(Context),
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::decode_image::IDENTIFIER),
..Default::default()
},
@ -505,7 +497,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::ProtoNode(memo::memo::IDENTIFIER),
..Default::default()
@ -567,20 +558,17 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
inputs: vec![NodeInput::scope("editor-api")],
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::create_surface::IDENTIFIER),
call_argument: concrete!(Context),
skip_deduplication: true,
..Default::default()
},
DocumentNode {
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::ProtoNode(memo::memo::IDENTIFIER),
call_argument: concrete!(Context),
..Default::default()
},
DocumentNode {
inputs: vec![NodeInput::network(generic!(T), 0), NodeInput::network(concrete!(Footprint), 1), NodeInput::node(NodeId(1), 0)],
inputs: vec![NodeInput::import(generic!(T), 0), NodeInput::import(concrete!(Footprint), 1), NodeInput::node(NodeId(1), 0)],
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::rasterize::IDENTIFIER),
call_argument: concrete!(Context),
..Default::default()
},
]
@ -653,7 +641,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
category: "Raster: Pattern",
node_template: NodeTemplate {
document_node: DocumentNode {
call_argument: concrete!(Context),
implementation: DocumentNodeImplementation::ProtoNode(raster_nodes::std_nodes::noise_pattern::IDENTIFIER),
inputs: vec![
NodeInput::value(TaggedValue::None, false),
@ -717,7 +704,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
nodes: [
DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Raster<CPU>>), 0),
NodeInput::import(concrete!(Table<Raster<CPU>>), 0),
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Red), false),
],
implementation: DocumentNodeImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
@ -726,7 +713,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Raster<CPU>>), 0),
NodeInput::import(concrete!(Table<Raster<CPU>>), 0),
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Green), false),
],
implementation: DocumentNodeImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
@ -735,7 +722,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Raster<CPU>>), 0),
NodeInput::import(concrete!(Table<Raster<CPU>>), 0),
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Blue), false),
],
implementation: DocumentNodeImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
@ -744,7 +731,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
},
DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Raster<CPU>>), 0),
NodeInput::import(concrete!(Table<Raster<CPU>>), 0),
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Alpha), false),
],
implementation: DocumentNodeImplementation::ProtoNode(raster_nodes::adjustments::extract_channel::IDENTIFIER),
@ -823,13 +810,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::value(TaggedValue::None, false), NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(1), 0)],
nodes: [
DocumentNode {
inputs: vec![NodeInput::network(concrete!(Table<Raster<CPU>>), 0), NodeInput::value(TaggedValue::XY(XY::X), false)],
inputs: vec![NodeInput::import(concrete!(Table<Raster<CPU>>), 0), NodeInput::value(TaggedValue::XY(XY::X), false)],
implementation: DocumentNodeImplementation::ProtoNode(extract_xy::extract_xy::IDENTIFIER),
call_argument: generic!(T),
..Default::default()
},
DocumentNode {
inputs: vec![NodeInput::network(concrete!(Table<Raster<CPU>>), 0), NodeInput::value(TaggedValue::XY(XY::Y), false)],
inputs: vec![NodeInput::import(concrete!(Table<Raster<CPU>>), 0), NodeInput::value(TaggedValue::XY(XY::Y), false)],
implementation: DocumentNodeImplementation::ProtoNode(extract_xy::extract_xy::IDENTIFIER),
call_argument: generic!(T),
..Default::default()
@ -894,11 +881,10 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::node(NodeId(0), 0)],
nodes: vec![DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Raster<CPU>>), 0),
NodeInput::network(concrete!(Vec<brush::brush_stroke::BrushStroke>), 1),
NodeInput::network(concrete!(BrushCache), 2),
NodeInput::import(concrete!(Table<Raster<CPU>>), 0),
NodeInput::import(concrete!(Vec<brush::brush_stroke::BrushStroke>), 1),
NodeInput::import(concrete!(BrushCache), 2),
],
call_argument: concrete!(Context),
implementation: DocumentNodeImplementation::ProtoNode(brush::brush::brush::IDENTIFIER),
..Default::default()
}]
@ -949,7 +935,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
document_node: DocumentNode {
implementation: DocumentNodeImplementation::ProtoNode(memo::memo::IDENTIFIER),
inputs: vec![NodeInput::value(TaggedValue::Raster(Default::default()), true)],
call_argument: concrete!(Context),
..Default::default()
},
persistent_node_metadata: DocumentNodePersistentMetadata {
@ -968,7 +953,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
document_node: DocumentNode {
implementation: DocumentNodeImplementation::ProtoNode(memo::impure_memo::IDENTIFIER),
inputs: vec![NodeInput::value(TaggedValue::Raster(Default::default()), true)],
call_argument: concrete!(Context),
..Default::default()
},
persistent_node_metadata: DocumentNodePersistentMetadata {
@ -990,13 +974,11 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::node(NodeId(1), 0)],
nodes: [
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![NodeInput::scope("editor-api")],
implementation: DocumentNodeImplementation::ProtoNode(wgpu_executor::create_gpu_surface::IDENTIFIER),
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::ProtoNode(memo::impure_memo::IDENTIFIER),
..Default::default()
@ -1061,7 +1043,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
DocumentNode {
inputs: vec![NodeInput::network(concrete!(Table<Raster<CPU>>), 0), NodeInput::node(NodeId(0), 0)],
inputs: vec![NodeInput::import(concrete!(Table<Raster<CPU>>), 0), NodeInput::node(NodeId(0), 0)],
call_argument: generic!(T),
implementation: DocumentNodeImplementation::ProtoNode(wgpu_executor::texture_upload::upload_texture::IDENTIFIER),
..Default::default()
@ -1181,7 +1163,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::node(NodeId(1), 0)],
nodes: vec![
DocumentNode {
inputs: vec![NodeInput::network(concrete!(Table<Vector>), 0)],
inputs: vec![NodeInput::import(concrete!(Table<Vector>), 0)],
implementation: DocumentNodeImplementation::ProtoNode(memo::monitor::IDENTIFIER),
call_argument: generic!(T),
skip_deduplication: true,
@ -1190,7 +1172,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
inputs: vec![
NodeInput::node(NodeId(0), 0),
NodeInput::network(concrete!(graphene_std::vector::VectorModification), 1),
NodeInput::import(concrete!(graphene_std::vector::VectorModification), 1),
NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::DocumentNodePath),
],
call_argument: generic!(T),
@ -1253,7 +1235,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
node_template: NodeTemplate {
document_node: DocumentNode {
implementation: DocumentNodeImplementation::ProtoNode(text::text::IDENTIFIER),
call_argument: concrete!(Context),
inputs: vec![
NodeInput::scope("editor-api"),
NodeInput::value(TaggedValue::String("Lorem ipsum".to_string()), false),
@ -1376,7 +1357,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
DocumentNode {
inputs: vec![
// From the Value import
NodeInput::network(generic!(T), 0),
NodeInput::import(generic!(T), 0),
],
implementation: DocumentNodeImplementation::ProtoNode(memo::monitor::IDENTIFIER),
call_argument: generic!(T),
@ -1389,13 +1370,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
// From the Monitor node
NodeInput::node(NodeId(0), 0),
// From the Translation import
NodeInput::network(concrete!(DVec2), 1),
NodeInput::import(concrete!(DVec2), 1),
// From the Rotation import
NodeInput::network(concrete!(f64), 2),
NodeInput::import(concrete!(f64), 2),
// From the Scale import
NodeInput::network(concrete!(DVec2), 3),
NodeInput::import(concrete!(DVec2), 3),
// From the Skew import
NodeInput::network(concrete!(DVec2), 4),
NodeInput::import(concrete!(DVec2), 4),
],
implementation: DocumentNodeImplementation::ProtoNode(transform_nodes::transform::IDENTIFIER),
..Default::default()
@ -1481,7 +1462,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::node(NodeId(1), 0)],
nodes: vec![
DocumentNode {
inputs: vec![NodeInput::network(concrete!(Table<Vector>), 0), NodeInput::network(concrete!(vector::style::Fill), 1)],
inputs: vec![NodeInput::import(concrete!(Table<Vector>), 0), NodeInput::import(concrete!(vector::style::Fill), 1)],
implementation: DocumentNodeImplementation::ProtoNode(path_bool::boolean_operation::IDENTIFIER),
call_argument: generic!(T),
..Default::default()
@ -1551,20 +1532,20 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
exports: vec![NodeInput::node(NodeId(2), 0)],
nodes: [
DocumentNode {
inputs: vec![NodeInput::network(concrete!(Table<Vector>), 0)],
inputs: vec![NodeInput::import(concrete!(Table<Vector>), 0)],
implementation: DocumentNodeImplementation::ProtoNode(vector::subpath_segment_lengths::IDENTIFIER),
call_argument: generic!(T),
..Default::default()
},
DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Vector>), 0),
NodeInput::network(concrete!(vector::misc::PointSpacingType), 1),
NodeInput::network(concrete!(f64), 2),
NodeInput::network(concrete!(u32), 3),
NodeInput::network(concrete!(f64), 4),
NodeInput::network(concrete!(f64), 5),
NodeInput::network(concrete!(bool), 6),
NodeInput::import(concrete!(Table<Vector>), 0),
NodeInput::import(concrete!(vector::misc::PointSpacingType), 1),
NodeInput::import(concrete!(f64), 2),
NodeInput::import(concrete!(u32), 3),
NodeInput::import(concrete!(f64), 4),
NodeInput::import(concrete!(f64), 5),
NodeInput::import(concrete!(bool), 6),
NodeInput::node(NodeId(0), 0),
],
implementation: DocumentNodeImplementation::ProtoNode(vector::sample_polyline::IDENTIFIER),
@ -1690,9 +1671,9 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
nodes: [
DocumentNode {
inputs: vec![
NodeInput::network(concrete!(Table<Vector>), 0),
NodeInput::network(concrete!(f64), 1),
NodeInput::network(concrete!(u32), 2),
NodeInput::import(concrete!(Table<Vector>), 0),
NodeInput::import(concrete!(f64), 1),
NodeInput::import(concrete!(u32), 2),
],
call_argument: generic!(T),
implementation: DocumentNodeImplementation::ProtoNode(vector::poisson_disk_points::IDENTIFIER),

View File

@ -200,7 +200,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
responses.add(PortfolioMessage::SubmitActiveGraphRender);
}
NodeGraphMessage::CreateWire { output_connector, input_connector } => {
// TODO: Add support for flattening NodeInput::Network exports in flatten_with_fns https://github.com/GraphiteEditor/Graphite/issues/1762
// TODO: Add support for flattening NodeInput::Import exports in flatten_with_fns https://github.com/GraphiteEditor/Graphite/issues/1762
if matches!(input_connector, InputConnector::Export(_)) && matches!(output_connector, OutputConnector::Import { .. }) {
responses.add(DialogMessage::RequestComingSoonDialog { issue: Some(1762) });
return;

View File

@ -457,7 +457,7 @@ impl NodeNetworkInterface {
let tagged_value = TaggedValue::from_type_or_none(&self.input_type(&InputConnector::node(*node_id, input_index), network_path).0);
*input = NodeInput::value(tagged_value, true);
}
} else if let &mut NodeInput::Network { .. } = input {
} else if let &mut NodeInput::Import { .. } = input {
// Always disconnect network node input
let tagged_value = TaggedValue::from_type_or_none(&self.input_type(&InputConnector::node(*node_id, input_index), network_path).0);
*input = NodeInput::value(tagged_value, true);
@ -725,7 +725,7 @@ impl NodeNetworkInterface {
..
} => self.output_type(&OutputConnector::node(*nested_node_id, *output_index), &[network_path, &[*node_id]].concat()),
NodeInput::Value { tagged_value, .. } => (tagged_value.ty(), TypeSource::TaggedValue),
NodeInput::Network { .. } => {
NodeInput::Import { .. } => {
// let mut encapsulating_path = network_path.to_vec();
// let encapsulating_node = encapsulating_path.pop().expect("No imports exist in document network");
// self.input_type(&InputConnector::node(encapsulating_node, *import_index), network_path)
@ -1586,7 +1586,7 @@ impl NodeNetworkInterface {
let input = self.input_from_connector(input_connector, network_path);
input.and_then(|input| match input {
NodeInput::Node { node_id, output_index, .. } => Some(OutputConnector::node(*node_id, *output_index)),
NodeInput::Network { import_index, .. } => Some(OutputConnector::Import(*import_index)),
NodeInput::Import { import_index, .. } => Some(OutputConnector::Import(*import_index)),
_ => None,
})
}
@ -2419,7 +2419,7 @@ impl NodeNetworkInterface {
)
});
outward_wires_entry.push(InputConnector::node(*current_node_id, input_index));
} else if let NodeInput::Network { import_index, .. } = input {
} else if let NodeInput::Import { import_index, .. } = input {
let outward_wires_entry = outward_wires
.get_mut(&OutputConnector::Import(*import_index))
.unwrap_or_else(|| panic!("Output connector {:?} should be initialized for each import from a node", OutputConnector::Import(*import_index)));
@ -2436,7 +2436,7 @@ impl NodeNetworkInterface {
)
});
outward_wires_entry.push(InputConnector::Export(export_index));
} else if let NodeInput::Network { import_index, .. } = export {
} else if let NodeInput::Import { import_index, .. } = export {
let outward_wires_entry = outward_wires
.get_mut(&OutputConnector::Import(*import_index))
.unwrap_or_else(|| panic!("Output connector {:?} should be initialized between imports and exports", OutputConnector::Import(*import_index)));
@ -4226,8 +4226,8 @@ impl NodeNetworkInterface {
}
pub fn set_input(&mut self, input_connector: &InputConnector, new_input: NodeInput, network_path: &[NodeId]) {
if matches!(input_connector, InputConnector::Export(_)) && matches!(new_input, NodeInput::Network { .. }) {
// TODO: Add support for flattening NodeInput::Network exports in flatten_with_fns https://github.com/GraphiteEditor/Graphite/issues/1762
if matches!(input_connector, InputConnector::Export(_)) && matches!(new_input, NodeInput::Import { .. }) {
// TODO: Add support for flattening NodeInput::Import exports in flatten_with_fns https://github.com/GraphiteEditor/Graphite/issues/1762
log::error!("Cannot connect a network to an export, see https://github.com/GraphiteEditor/Graphite/issues/1762");
return;
}
@ -4397,12 +4397,12 @@ impl NodeNetworkInterface {
self.try_set_upstream_to_chain(input_connector, network_path);
}
// If a connection is made to the imports
(NodeInput::Value { .. } | NodeInput::Scope { .. } | NodeInput::Inline { .. }, NodeInput::Network { .. }) => {
(NodeInput::Value { .. } | NodeInput::Scope { .. } | NodeInput::Inline { .. }, NodeInput::Import { .. }) => {
self.unload_outward_wires(network_path);
self.unload_wire(input_connector, network_path);
}
// If a connection to the imports is disconnected
(NodeInput::Network { .. }, NodeInput::Value { .. } | NodeInput::Scope { .. } | NodeInput::Inline { .. }) => {
(NodeInput::Import { .. }, NodeInput::Value { .. } | NodeInput::Scope { .. } | NodeInput::Inline { .. }) => {
self.unload_outward_wires(network_path);
self.unload_wire(input_connector, network_path);
}
@ -4512,7 +4512,7 @@ impl NodeNetworkInterface {
pub fn create_wire(&mut self, output_connector: &OutputConnector, input_connector: &InputConnector, network_path: &[NodeId]) {
let input = match output_connector {
OutputConnector::Node { node_id, output_index } => NodeInput::node(*node_id, *output_index),
OutputConnector::Import(import_index) => NodeInput::Network {
OutputConnector::Import(import_index) => NodeInput::Import {
import_type: graph_craft::generic!(T),
import_index: *import_index,
},
@ -4559,7 +4559,7 @@ impl NodeNetworkInterface {
.document_node
.inputs
.iter()
.all(|input| !(matches!(input, NodeInput::Node { .. }) || matches!(input, NodeInput::Network { .. })));
.all(|input| !(matches!(input, NodeInput::Node { .. }) || matches!(input, NodeInput::Import { .. })));
assert!(has_node_or_network_input, "Cannot insert node with node or network inputs. Use insert_node_group instead");
let Some(network) = self.network_mut(network_path) else {
log::error!("Network not found in insert_node");
@ -4696,7 +4696,7 @@ impl NodeNetworkInterface {
node.inputs
.iter()
.find(|input| input.is_exposed())
.filter(|input| matches!(input, NodeInput::Node { .. } | NodeInput::Network { .. }))
.filter(|input| matches!(input, NodeInput::Node { .. } | NodeInput::Import { .. }))
.cloned()
});
// Get all upstream references
@ -4717,7 +4717,7 @@ impl NodeNetworkInterface {
for downstream_input in &downstream_inputs_to_disconnect {
self.disconnect_input(downstream_input, network_path);
// Prevent reconnecting export to import until https://github.com/GraphiteEditor/Graphite/issues/1762 is solved
if !(matches!(reconnect_to_input, Some(NodeInput::Network { .. })) && matches!(downstream_input, InputConnector::Export(_))) {
if !(matches!(reconnect_to_input, Some(NodeInput::Import { .. })) && matches!(downstream_input, InputConnector::Export(_))) {
if let Some(reconnect_input) = &reconnect_to_input {
reconnect_node = reconnect_input.as_node().and_then(|node_id| if self.is_stack(&node_id, network_path) { Some(node_id) } else { None });
self.disconnect_input(&InputConnector::node(*node_id, 0), network_path);
@ -6003,7 +6003,7 @@ impl NodeNetworkInterface {
self.shift_absolute_node_position(&layer.to_node(), shift, network_path);
self.insert_node_between(&layer.to_node(), &post_node, 0, network_path);
}
NodeInput::Network { .. } => {
NodeInput::Import { .. } => {
log::error!("Cannot move post node to parent which connects to the imports")
}
}
@ -6022,7 +6022,7 @@ impl NodeNetworkInterface {
self.shift_absolute_node_position(&layer.to_node(), shift, network_path);
self.insert_node_between(&layer.to_node(), &post_node, 0, network_path);
}
NodeInput::Network { .. } => {
NodeInput::Import { .. } => {
log::error!("Cannot move post node to parent which connects to the imports")
}
}
@ -6225,7 +6225,7 @@ impl OutputConnector {
pub fn from_input(input: &NodeInput) -> Option<Self> {
match input {
NodeInput::Network { import_index, .. } => Some(Self::Import(*import_index)),
NodeInput::Import { import_index, .. } => Some(Self::Import(*import_index)),
NodeInput::Node { node_id, output_index, .. } => Some(Self::node(*node_id, *output_index)),
_ => None,
}

View File

@ -37,7 +37,7 @@ pub struct DocumentNode {
/// The inputs to a node, which are either:
/// - From other nodes within this graph [`NodeInput::Node`],
/// - A constant value [`NodeInput::Value`],
/// - A [`NodeInput::Network`] which specifies that this input is from outside the graph, which is resolved in the graph flattening step in the case of nested networks.
/// - A [`NodeInput::Import`] which specifies that this input comes from outside the graph, which is resolved in the graph flattening step in the case of nested networks.
///
/// In the root network, it is resolved when evaluating the borrow tree.
/// Ensure the click target in the encapsulating network is updated when the inputs cause the node shape to change (currently only when exposing/hiding an input)
@ -119,7 +119,7 @@ impl OriginalLocation {
}
}
impl DocumentNode {
/// Locate the input that is a [`NodeInput::Network`] at index `offset` and replace it with a [`NodeInput::Node`].
/// Locate the input that is a [`NodeInput::Import`] at index `offset` and replace it with a [`NodeInput::Node`].
pub fn populate_first_network_input(&mut self, node_id: NodeId, output_index: usize, offset: usize, source: impl Iterator<Item = Source>, skip: usize) {
let (index, _) = self
.inputs
@ -139,28 +139,29 @@ impl DocumentNode {
let DocumentNodeImplementation::ProtoNode(identifier) = self.implementation else {
unreachable!("tried to resolve not flattened node on resolved node {self:?}");
};
assert!(!self.inputs.iter().any(|input| matches!(input, NodeInput::Import { .. })), "received non-resolved input");
let (input, mut args) = (self.call_argument, ConstructionArgs::Nodes(vec![]));
assert!(!self.inputs.iter().any(|input| matches!(input, NodeInput::Network { .. })), "received non-resolved input");
let mut construction_args = ConstructionArgs::Nodes(vec![]);
// If we have one input of the type inline, set it as the construction args
if let &[NodeInput::Inline(ref inline)] = self.inputs.as_slice() {
args = ConstructionArgs::Inline(inline.clone());
construction_args = ConstructionArgs::Inline(inline.clone());
}
// If we have one input of the type inline, set it as the construction args
if let &[NodeInput::Value { ref tagged_value, .. }] = self.inputs.as_slice() {
args = ConstructionArgs::Value(tagged_value.clone());
construction_args = ConstructionArgs::Value(tagged_value.clone());
}
if let ConstructionArgs::Nodes(nodes) = &mut args {
if let ConstructionArgs::Nodes(nodes) = &mut construction_args {
nodes.extend(self.inputs.iter().map(|input| match input {
NodeInput::Node { node_id, .. } => *node_id,
_ => unreachable!(),
}));
}
ProtoNode {
identifier,
call_argument: input,
construction_args: args,
call_argument: self.call_argument,
construction_args,
original_location: self.original_location,
skip_deduplication: self.skip_deduplication,
context_features: self.context_features,
@ -178,8 +179,9 @@ pub enum NodeInput {
Value { tagged_value: MemoHash<TaggedValue>, exposed: bool },
// TODO: Remove import_type and get type from parent node input
/// Input that is provided by the parent network to this document node, instead of from a hardcoded value or another node within the same network.
Network { import_type: Type, import_index: usize },
/// Input that is provided by the import from the parent network to this document node network.
#[serde(alias = "Network")]
Import { import_type: Type, import_index: usize },
/// Input that is extracted from the parent scopes the node resides in. The string argument is the key.
Scope(Cow<'static, str>),
@ -219,8 +221,8 @@ impl NodeInput {
Self::Value { tagged_value, exposed }
}
pub const fn network(import_type: Type, import_index: usize) -> Self {
Self::Network { import_type, import_index }
pub const fn import(import_type: Type, import_index: usize) -> Self {
Self::Import { import_type, import_index }
}
pub fn scope(key: impl Into<Cow<'static, str>>) -> Self {
@ -237,7 +239,7 @@ impl NodeInput {
match self {
NodeInput::Node { .. } => true,
NodeInput::Value { exposed, .. } => *exposed,
NodeInput::Network { .. } => true,
NodeInput::Import { .. } => true,
NodeInput::Inline(_) => false,
NodeInput::Scope(_) => false,
NodeInput::Reflection(_) => false,
@ -248,9 +250,9 @@ impl NodeInput {
match self {
NodeInput::Node { .. } => unreachable!("ty() called on NodeInput::Node"),
NodeInput::Value { tagged_value, .. } => tagged_value.ty(),
NodeInput::Network { import_type, .. } => import_type.clone(),
NodeInput::Import { import_type, .. } => import_type.clone(),
NodeInput::Inline(_) => panic!("ty() called on NodeInput::Inline"),
NodeInput::Scope(_) => unreachable!("ty() called on NodeInput::Scope"),
NodeInput::Scope(_) => panic!("ty() called on NodeInput::Scope"),
NodeInput::Reflection(_) => concrete!(Metadata),
}
}
@ -292,7 +294,7 @@ pub enum DocumentNodeImplementation {
/// A proto node identifier which can be found in `node_registry.rs`.
#[serde(alias = "Unresolved")] // TODO: Eventually remove this alias document upgrade code
ProtoNode(ProtoNodeIdentifier),
/// The Extract variant is a tag which tells the compilation process to do something special. It invokes language-level functionality built for use by the ExtractNode to enable metaprogramming.
/// The Extract variant is a tag which tells the compilation process to do something special: it invokes language-level functionality built for use by the ExtractNode to enable metaprogramming.
/// When the ExtractNode is compiled, it gets replaced by a value node containing a representation of the source code for the function/lambda of the document node that's fed into the ExtractNode
/// (but only that one document node, not upstream nodes).
///
@ -404,7 +406,7 @@ pub struct OldDocumentNode {
/// The inputs to a node, which are either:
/// - From other nodes within this graph [`NodeInput::Node`],
/// - A constant value [`NodeInput::Value`],
/// - A [`NodeInput::Network`] which specifies that this input is from outside the graph, which is resolved in the graph flattening step in the case of nested networks.
/// - A [`NodeInput::Import`] which specifies that this input is from outside the graph, which is resolved in the graph flattening step in the case of nested networks.
///
/// In the root network, it is resolved when evaluating the borrow tree.
/// Ensure the click target in the encapsulating network is updated when the inputs cause the node shape to change (currently only when exposing/hiding an input) by using network.update_click_target(node_id).
@ -515,7 +517,7 @@ pub struct NodeNetwork {
// TODO: Eventually remove this alias document upgrade code
#[cfg_attr(target_family = "wasm", serde(alias = "outputs", deserialize_with = "deserialize_exports"))]
pub exports: Vec<NodeInput>,
// TODO: Instead of storing import types in each NodeInput::Network connection, the types are stored here. This is similar to how types need to be defined for parameters when creating a function in Rust.
// TODO: Instead of storing import types in each NodeInput::Import connection, the types are stored here. This is similar to how types need to be defined for parameters when creating a function in Rust.
// pub import_types: Vec<Type>,
/// The list of all nodes in this network.
#[serde(serialize_with = "graphene_core::vector::serialize_hashmap", deserialize_with = "graphene_core::vector::deserialize_hashmap")]
@ -737,7 +739,7 @@ impl NodeNetwork {
let mut are_inputs_used = vec![false; number_of_inputs];
for node in &self.nodes {
for node_input in &node.1.inputs {
if let NodeInput::Network { import_index, .. } = node_input {
if let NodeInput::Import { import_index, .. } = node_input {
if let Some(is_used) = are_inputs_used.get_mut(*import_index) {
*is_used = true;
}
@ -827,7 +829,7 @@ impl NodeNetwork {
// Match the document node input and the inputs of the inner network
for (nested_node_id, mut nested_node) in inner_network.nodes.into_iter() {
for (nested_input_index, nested_input) in nested_node.clone().inputs.iter().enumerate() {
if let NodeInput::Network { import_index, .. } = nested_input {
if let NodeInput::Import { import_index, .. } = nested_input {
let parent_input = node.inputs.get(*import_index).unwrap_or_else(|| panic!("Import index {import_index} should always exist"));
match *parent_input {
// If the input to self is a node, connect the corresponding output of the inner network to it
@ -836,9 +838,9 @@ impl NodeNetwork {
let input_node = self.nodes.get_mut(&node_id).unwrap_or_else(|| panic!("unable find input node {node_id:?}"));
input_node.original_location.dependants[output_index].push(nested_node_id);
}
NodeInput::Network { import_index, .. } => {
NodeInput::Import { import_index, .. } => {
let parent_input_index = import_index;
let Some(NodeInput::Network { import_index, .. }) = nested_node.inputs.get_mut(nested_input_index) else {
let Some(NodeInput::Import { import_index, .. }) = nested_node.inputs.get_mut(nested_input_index) else {
log::error!("Nested node should have a network input");
continue;
};
@ -857,7 +859,7 @@ impl NodeNetwork {
}
self.nodes.insert(nested_node_id, nested_node);
}
// TODO: Add support for flattening exports that are NodeInput::Network (https://github.com/GraphiteEditor/Graphite/issues/1762)
// TODO: Add support for flattening exports that are NodeInput::Import (https://github.com/GraphiteEditor/Graphite/issues/1762)
// Connect all nodes that were previously connected to this node to the nodes of the inner network
for (i, export) in inner_network.exports.into_iter().enumerate() {
@ -895,7 +897,7 @@ impl NodeNetwork {
// Replace value exports and imports with value nodes, added inside the nested network
for export in inputs {
let export: &mut NodeInput = export;
let previous_export = std::mem::replace(export, NodeInput::network(concrete!(()), 0));
let previous_export = std::mem::replace(export, NodeInput::import(concrete!(()), 0));
let (tagged_value, exposed) = match previous_export {
NodeInput::Value { tagged_value, exposed } => (tagged_value, exposed),
@ -1026,14 +1028,14 @@ impl NodeNetwork {
node.implementation = DocumentNodeImplementation::ProtoNode("graphene_core::value::ClonedNode".into());
if let Some(input) = input_node.inputs.get_mut(0) {
*input = match &input {
NodeInput::Node { .. } => NodeInput::network(generic!(T), 0),
ni => NodeInput::network(ni.ty(), 0),
NodeInput::Node { .. } => NodeInput::import(generic!(T), 0),
ni => NodeInput::import(ni.ty(), 0),
};
}
for input in input_node.inputs.iter_mut() {
if let NodeInput::Node { .. } = input {
*input = NodeInput::network(generic!(T), 0)
*input = NodeInput::import(generic!(T), 0)
}
}
node.inputs = vec![NodeInput::value(TaggedValue::DocumentNode(input_node), false)];
@ -1139,7 +1141,7 @@ mod test {
(
NodeId(0),
DocumentNode {
inputs: vec![NodeInput::network(concrete!(u32), 0), NodeInput::network(concrete!(u32), 1)],
inputs: vec![NodeInput::import(concrete!(u32), 0), NodeInput::import(concrete!(u32), 1)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::structural::ConsNode".into()),
..Default::default()
},
@ -1169,7 +1171,7 @@ mod test {
(
NodeId(1),
DocumentNode {
inputs: vec![NodeInput::network(concrete!(u32), 0), NodeInput::network(concrete!(u32), 1)],
inputs: vec![NodeInput::import(concrete!(u32), 0), NodeInput::import(concrete!(u32), 1)],
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::structural::ConsNode".into()),
..Default::default()
},
@ -1228,7 +1230,7 @@ mod test {
nodes: [(
NodeId(1),
DocumentNode {
inputs: vec![NodeInput::network(concrete!(u32), 0), NodeInput::value(TaggedValue::U32(2), false)],
inputs: vec![NodeInput::import(concrete!(u32), 0), NodeInput::value(TaggedValue::U32(2), false)],
implementation: DocumentNodeImplementation::Network(add_network()),
..Default::default()
},
@ -1391,7 +1393,7 @@ mod test {
(
NodeId(1),
DocumentNode {
inputs: vec![NodeInput::network(concrete!(u32), 0)],
inputs: vec![NodeInput::import(concrete!(u32), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
..Default::default()
},
@ -1399,7 +1401,7 @@ mod test {
(
NodeId(2),
DocumentNode {
inputs: vec![NodeInput::network(concrete!(u32), 1)],
inputs: vec![NodeInput::import(concrete!(u32), 1)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::ops::identity::IDENTIFIER),
..Default::default()
},

View File

@ -32,13 +32,11 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
nodes: [
DocumentNode {
inputs: vec![NodeInput::scope("editor-api")],
call_argument: concrete!(Context),
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("wgpu_executor::CreateGpuSurfaceNode")),
skip_deduplication: true,
..Default::default()
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![NodeInput::node(NodeId(0), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_core::memo::memo::IDENTIFIER),
..Default::default()
@ -48,7 +46,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
call_argument: concrete!(graphene_std::application_io::RenderConfig),
inputs: vec![
NodeInput::scope("editor-api"),
NodeInput::network(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0),
NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0),
NodeInput::node(NodeId(1), 0),
],
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::RenderNode")),

View File

@ -86,15 +86,14 @@ pub fn generate_node_substitutions() -> HashMap<ProtoNodeIdentifier, DocumentNod
};
DocumentNode {
inputs: vec![NodeInput::network(input.clone(), i)],
inputs: vec![NodeInput::import(input.clone(), i)],
implementation: DocumentNodeImplementation::ProtoNode(proto_node),
visible: true,
call_argument: concrete!(Context),
..Default::default()
}
}
_ => DocumentNode {
inputs: vec![NodeInput::network(generic!(X), i)],
inputs: vec![NodeInput::import(generic!(X), i)],
implementation: DocumentNodeImplementation::ProtoNode(identity_node.clone()),
visible: false,
..Default::default()