Skip to content

Commit a871bcf

Browse files
committed
Valid types
1 parent e35e988 commit a871bcf

8 files changed

Lines changed: 78 additions & 81 deletions

File tree

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType
1717
use crate::messages::portfolio::document::properties_panel::properties_panel_message_handler::PropertiesPanelMessageContext;
1818
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
1919
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
20-
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, NodeTemplate, OutputConnector};
20+
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, NodeTemplate};
2121
use crate::messages::portfolio::document::utility_types::nodes::RawBuffer;
2222
use crate::messages::portfolio::utility_types::PanelType;
2323
use crate::messages::portfolio::utility_types::PersistentData;

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use crate::messages::portfolio::document::node_graph::utility_types::{ContextMen
1010
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
1111
use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
1212
use crate::messages::portfolio::document::utility_types::network_interface::{
13-
self, FlowType, InputConnector, NodeNetworkInterface, NodeTemplate, NodeTypePersistentMetadata, OutputConnector, Previewing, TypeSource,
13+
self, FlowType, InputConnector, NodeNetworkInterface, NodeTemplate, NodeTypePersistentMetadata, OutputConnector, Previewing,
1414
};
1515
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, LayerPanelEntry};
1616
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
1717
use crate::messages::prelude::*;
1818
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
19-
use crate::messages::tool::common_functionality::graph_modification_utils::{self, get_clip_mode};
19+
use crate::messages::tool::common_functionality::graph_modification_utils::get_clip_mode;
2020
use crate::messages::tool::common_functionality::utility_functions::make_path_editable_is_allowed;
2121
use crate::messages::tool::tool_messages::tool_prelude::{Key, MouseMotion};
2222
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
@@ -1206,14 +1206,14 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
12061206
return;
12071207
}
12081208

1209+
let compatible_type = network_interface.output_type(&output_connector, selection_network_path).add_node_string();
1210+
12091211
// Get the output types from the network interface
12101212
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
12111213
warn!("No network_metadata");
12121214
return;
12131215
};
12141216

1215-
let compatible_type = network_interface.output_type(&output_connector.unwrap(), selection_network_path).add_node_string();
1216-
12171217
let appear_right_of_mouse = if ipp.mouse.position.x > ipp.viewport_bounds.size().x - 173. { -173. } else { 0. };
12181218
let appear_above_mouse = if ipp.mouse.position.y > ipp.viewport_bounds.size().y - 34. { -34. } else { 0. };
12191219
let node_graph_shift = DVec2::new(appear_right_of_mouse, appear_above_mouse) / network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.matrix2.x_axis.x;
@@ -1648,6 +1648,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
16481648
has_left_input_wire,
16491649
});
16501650
responses.add(NodeGraphMessage::SendSelectedNodes);
1651+
responses.add(NodeGraphMessage::SendWires);
16511652
self.update_node_graph_hints(responses);
16521653
}
16531654
}
@@ -2100,7 +2101,7 @@ impl NodeGraphMessageHandler {
21002101
.popover_layout({
21012102
// Showing only compatible types
21022103
let compatible_type = match (selection_includes_layers, has_multiple_selection, selected_layer) {
2103-
(true, false, Some(layer)) => network_interface.output_type(&OutputConnector::node(node_id, 0), &[]).add_node_string(),
2104+
(true, false, Some(layer)) => network_interface.output_type(&OutputConnector::node(layer.to_node(), 1), &[]).add_node_string(),
21042105
_ => None,
21052106
};
21062107

editor/src/messages/portfolio/document/node_graph/node_properties.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::messages::prelude::*;
88
use choice::enum_choice;
99
use dyn_any::DynAny;
1010
use glam::{DAffine2, DVec2};
11-
use graph_craft::Type;
1211
use graph_craft::document::value::TaggedValue;
1312
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
13+
use graph_craft::{Type, concrete};
1414
use graphene_std::NodeInputDecleration;
1515
use graphene_std::animation::RealTimeMode;
1616
use graphene_std::extract_xy::XY;
@@ -1996,7 +1996,7 @@ pub struct ParameterWidgetsInfo<'a> {
19961996
impl<'a> ParameterWidgetsInfo<'a> {
19971997
pub fn new(node_id: NodeId, index: usize, blank_assist: bool, context: &'a mut NodePropertiesContext) -> ParameterWidgetsInfo<'a> {
19981998
let (name, description) = context.network_interface.displayed_input_name_and_description(&node_id, index, context.selection_network_path);
1999-
let input_type = FrontendGraphDataType::from_type(&context.network_interface.input_type(&InputConnector::node(node_id, index), context.selection_network_path));
1999+
let input_type = FrontendGraphDataType::displayed_type(&context.network_interface.input_type(&InputConnector::node(node_id, index), context.selection_network_path));
20002000
let document_node = context.network_interface.document_node(&node_id, context.selection_network_path);
20012001

20022002
ParameterWidgetsInfo {

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::messages::portfolio::document::utility_types::network_interface::TypeSource;
21
use glam::IVec2;
32
use graph_craft::document::NodeId;
43
use graph_craft::document::value::TaggedValue;
54
use graphene_std::Type;
65
use std::borrow::Cow;
76

7+
use crate::messages::portfolio::document::utility_types::network_interface::resolved_types::TypeSource;
8+
89
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize, specta::Type)]
910
pub enum FrontendGraphDataType {
1011
#[default]
@@ -42,7 +43,7 @@ impl FrontendGraphDataType {
4243
}
4344
}
4445

45-
pub fn displayed_type(type_source: TypeSource) -> Self {
46+
pub fn displayed_type(type_source: &TypeSource) -> Self {
4647
match type_source.compiled_nested_type() {
4748
Some(nested_type) => Self::from_type(&nested_type),
4849
None => Self::General,

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
mod deserialization;
2-
31
use super::document_metadata::{DocumentMetadata, LayerNodeIdentifier, NodeRelations};
42
use super::misc::PTZ;
53
use super::nodes::SelectedNodes;
@@ -13,25 +11,23 @@ use crate::messages::tool::common_functionality::graph_modification_utils;
1311
use crate::messages::tool::tool_messages::tool_prelude::NumberInputMode;
1412
use deserialization::deserialize_node_persistent_metadata;
1513
use glam::{DAffine2, DVec2, IVec2};
14+
use graph_craft::Type;
1615
use graph_craft::document::value::TaggedValue;
17-
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, InlineRust, NodeId, NodeInput, NodeNetwork, OldDocumentNodeImplementation, OldNodeNetwork};
18-
use graph_craft::{ProtoNodeIdentifier, Type, concrete};
16+
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput, NodeNetwork, OldDocumentNodeImplementation, OldNodeNetwork};
1917
use graphene_std::ContextDependencies;
2018
use graphene_std::math::quad::Quad;
2119
use graphene_std::subpath::Subpath;
2220
use graphene_std::transform::Footprint;
2321
use graphene_std::vector::click_target::{ClickTarget, ClickTargetType};
2422
use graphene_std::vector::{PointId, Vector, VectorModificationType};
25-
use interpreted_executor::node_registry::NODE_REGISTRY;
2623
use kurbo::BezPath;
2724
use serde_json::{Value, json};
2825
use std::collections::{HashMap, HashSet, VecDeque};
29-
use std::hash::{DefaultHasher, Hash, Hasher};
26+
use std::hash::Hash;
27+
use std::ops::Deref;
3028

3129
mod deserialization;
32-
mod resolved_types;
33-
use deserialization::deserialize_node_persistent_metadata;
34-
use std::ops::Deref;
30+
pub mod resolved_types;
3531

3632
/// All network modifications should be done through this API, so the fields cannot be public. However, all fields within this struct can be public since it it not possible to have a public mutable reference.
3733
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
@@ -670,7 +666,7 @@ impl NodeNetworkInterface {
670666
let valid_types = match self.valid_input_types(&input_connector, network_path) {
671667
Ok(input_types) => input_types.iter().map(|ty| ty.to_string()).collect(),
672668
Err(e) => {
673-
log::error!("Error getting valid types for input {input_connector}: {e}");
669+
log::error!("Error getting valid types for input {input_connector:?}: {e}");
674670
Vec::new()
675671
}
676672
};
@@ -719,7 +715,7 @@ impl NodeNetworkInterface {
719715
} else if let Some(import_type_name) = output_type.compiled_nested_type_name() {
720716
import_type_name
721717
} else {
722-
format!("Import index {}", export_index)
718+
format!("Import index {}", *import_index)
723719
};
724720

725721
(import_name, description)
@@ -1061,7 +1057,10 @@ impl NodeNetworkInterface {
10611057
log::error!("Could not get downstream_connectors in primary_output_connected_to_layer");
10621058
return false;
10631059
};
1064-
let downstream_nodes = downstream_connectors.iter().filter_map(|connector| connector.node_id()).collect::<Vec<_>>();
1060+
let downstream_nodes = downstream_connectors
1061+
.iter()
1062+
.filter_map(|connector| if connector.input_index() == 0 { connector.node_id() } else { None })
1063+
.collect::<Vec<_>>();
10651064
downstream_nodes.iter().any(|node_id| self.is_layer(node_id, network_path))
10661065
}
10671066

@@ -1444,30 +1443,6 @@ impl NodeNetworkInterface {
14441443
}
14451444
}
14461445

1447-
/// Gets the type for a random protonode implementation (used if there is no type from the compiled network)
1448-
fn random_protonode_implementation(protonode: &graph_craft::ProtoNodeIdentifier) -> Option<&graphene_std::NodeIOTypes> {
1449-
let mut protonode = protonode.clone();
1450-
// TODO: Remove
1451-
if let Some((path, _generics)) = protonode.name.split_once('<') {
1452-
protonode = path.to_string().to_string().into();
1453-
}
1454-
let Some(node_io_hashmap) = NODE_REGISTRY.get(&protonode) else {
1455-
log::error!("Could not get hashmap for proto node: {protonode:?}");
1456-
return None;
1457-
};
1458-
1459-
let node_types = node_io_hashmap.keys().min_by_key(|node_io_types| {
1460-
let mut hasher = DefaultHasher::new();
1461-
node_io_types.hash(&mut hasher);
1462-
hasher.finish()
1463-
});
1464-
1465-
if node_types.is_none() {
1466-
log::error!("Could not get node_types from hashmap");
1467-
};
1468-
node_types
1469-
}
1470-
14711446
// Private mutable getters for use within the network interface
14721447
impl NodeNetworkInterface {
14731448
fn network_mut(&mut self, network_path: &[NodeId]) -> Option<&mut NodeNetwork> {

editor/src/messages/portfolio/document/utility_types/network_interface/resolved_types.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
use std::collections::HashMap;
1+
use std::collections::{HashMap, HashSet};
22

3-
use graph_craft::Type;
3+
use graph_craft::{
4+
ProtoNodeIdentifier, Type, concrete,
5+
document::{DocumentNodeImplementation, InlineRust, NodeInput, value::TaggedValue},
6+
};
47
use graphene_std::uuid::NodeId;
5-
use interpreted_executor::dynamic_executor::ResolvedDocumentNodeTypesDelta;
8+
use interpreted_executor::{
9+
dynamic_executor::{NodeTypes, ResolvedDocumentNodeTypesDelta},
10+
node_registry::NODE_REGISTRY,
11+
};
612

713
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface, OutputConnector};
814

@@ -12,13 +18,6 @@ pub struct ResolvedDocumentNodeTypes {
1218
pub types: HashMap<Vec<NodeId>, NodeTypes>,
1319
}
1420

15-
#[derive(Debug, Default)]
16-
pub struct NodeTypes {
17-
// TODO: This is currently unused. Only the output is used
18-
pub inputs: Vec<Type>,
19-
pub output: Type,
20-
}
21-
2221
impl ResolvedDocumentNodeTypes {
2322
pub fn update(&mut self, delta: ResolvedDocumentNodeTypesDelta) {
2423
for (path, node_type) in delta.add {
@@ -56,20 +55,20 @@ impl TypeSource {
5655

5756
pub fn compiled_nested_type(&self) -> Option<&Type> {
5857
match self {
59-
TypeSource::Compiled(compiled_type) => Some(compiled_type.compiled_nested_type()),
60-
TypeSource::TaggedValue(value_type) => Some(value_type.compiled_nested_type()),
58+
TypeSource::Compiled(compiled_type) => Some(compiled_type.nested_type()),
59+
TypeSource::TaggedValue(value_type) => Some(value_type.nested_type()),
6160
_ => None,
6261
}
6362
}
6463

6564
// If Some, the type should be displayed in the imports/exports, if None it should be replaced with "import/export index _"
66-
pub fn compiled_nested_type_name(self) -> Option<String> {
67-
self.into_compiled_nested_type().map(|ty| ty.to_string())
65+
pub fn compiled_nested_type_name(&self) -> Option<String> {
66+
self.compiled_nested_type().map(|ty| ty.to_string())
6867
}
6968

7069
// Used when searching for nodes in the add Node popup
71-
pub fn add_node_string(self) -> Option<String> {
72-
self.into_compiled_nested_type().map(|ty| format!("type:{}", ty.to_string()))
70+
pub fn add_node_string(&self) -> Option<String> {
71+
self.compiled_nested_type().map(|ty| format!("type:{}", ty.to_string()))
7372
}
7473

7574
// The type to display in the tooltip
@@ -99,8 +98,15 @@ impl NodeNetworkInterface {
9998
// If we are trying to get the input type of an unknown node, check if it has a reference to its definition and use that input type
10099
if let InputConnector::Node { node_id, input_index } = input_connector {
101100
if let Some(definition) = self.get_node_definition(node_id, network_path) {
102-
if let Some(value) = definition.node_template.document_node.inputs.get(*input_index).cloned().and_then(|input| input.as_value()) {
103-
return TypeSource::DocumentNodeDefinition(value.ty());
101+
if let Some(ty) = definition
102+
.node_template
103+
.document_node
104+
.inputs
105+
.get(*input_index)
106+
.cloned()
107+
.and_then(|input| input.as_value().map(|value| value.ty()))
108+
{
109+
return TypeSource::DocumentNodeDefinition(ty);
104110
}
105111
}
106112
}
@@ -174,13 +180,14 @@ impl NodeNetworkInterface {
174180
let valid_types = implementations
175181
.iter()
176182
.filter_map(|(node_io, _)| {
177-
if !valid_output_types.contains(&node_io.return_value) {
183+
if !valid_output_types.iter().any(|output_type| output_type.nested_type() == node_io.return_value.nested_type()) {
178184
return None;
179185
}
186+
180187
let valid_inputs = (0..node_io.inputs.len()).filter(|iterator_index| iterator_index != input_index).all(|iterator_index| {
181188
let input_type = self.input_type(&InputConnector::node(*node_id, iterator_index), network_path);
182189
match input_type.into_compiled_nested_type() {
183-
Some(input_type) => node_io.inputs.get(iterator_index) == Some(&input_type),
190+
Some(input_type) => node_io.inputs.get(iterator_index).map(|input_type| input_type.nested_type()) == Some(&input_type),
184191
None => true,
185192
}
186193
});
@@ -205,7 +212,7 @@ impl NodeNetworkInterface {
205212
let Some(implementations) = NODE_REGISTRY.get(&ProtoNodeIdentifier::new(render_node)) else {
206213
return Err(format!("Protonode {render_node:?} not found in registry"));
207214
};
208-
Ok(implementations.iter().map(|(types, _)| types.inputs[1]).collect())
215+
Ok(implementations.iter().map(|(types, _)| types.inputs[1].clone()).collect())
209216
}
210217
}
211218
}
@@ -293,7 +300,7 @@ impl NodeNetworkInterface {
293300
return None;
294301
};
295302
match implementation {
296-
DocumentNodeImplementation::Network(node_network) => {
303+
DocumentNodeImplementation::Network(_) => {
297304
let Some(outward_wires) = self.outward_wires(&network_path) else {
298305
log::error!("Could not get outward wires in random_downstream_protonode_from_connector");
299306
return None;
@@ -305,7 +312,7 @@ impl NodeNetworkInterface {
305312
let Some(first_input) = inputs_from_import.first().cloned() else {
306313
return None;
307314
};
308-
self.random_downstream_type_from_connector(&first_input, &[network_path, &[node_id]].concat())
315+
self.random_downstream_type_from_connector(&first_input, &[network_path, &[*node_id]].concat())
309316
}
310317
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
311318
let Some(implementations) = NODE_REGISTRY.get(proto_node_identifier) else {

0 commit comments

Comments
 (0)