Skip to content

Commit e3073bf

Browse files
committed
Refactor TypeSource
1 parent 94414ad commit e3073bf

12 files changed

Lines changed: 390 additions & 425 deletions

File tree

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

Lines changed: 5 additions & 10 deletions
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;
@@ -2820,16 +2820,11 @@ impl DocumentMessageHandler {
28202820
.tooltip("Add an operation to the end of this layer's chain of nodes")
28212821
.disabled(!has_selection || has_multiple_selection)
28222822
.popover_layout({
2823-
// Showing only compatible types
2823+
// Showing only compatible types for the layer based on the output type of the node upstream from its horizontal input
28242824
let compatible_type = selected_layer.and_then(|layer| {
2825-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, &self.network_interface);
2826-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2827-
if let Some(node_id) = node_type {
2828-
let (output_type, _) = self.network_interface.output_type(&OutputConnector::node(node_id, 0), &self.selection_network_path);
2829-
Some(format!("type:{}", output_type.nested_type()))
2830-
} else {
2831-
None
2832-
}
2825+
self.network_interface
2826+
.upstream_output_connector(&InputConnector::node(layer.to_node(), 1), &[])
2827+
.and_then(|upstream_output| self.network_interface.output_type(&upstream_output, &[]).add_node_string())
28332828
});
28342829

28352830
let mut node_chooser = NodeCatalog::new();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ impl<'a> ModifyInputsContext<'a> {
303303
// If inserting a 'Path' node, insert a 'Flatten Path' node if the type is `Graphic`.
304304
// TODO: Allow the 'Path' node to operate on table data by utilizing the reference (index or ID?) for each row.
305305
if node_definition.identifier == "Path" {
306-
let layer_input_type = self.network_interface.input_type(&InputConnector::node(output_layer.to_node(), 1), &[]).0.nested_type().clone();
307-
if layer_input_type == concrete!(Table<Graphic>) {
306+
let layer_input_type = self.network_interface.input_type(&InputConnector::node(output_layer.to_node(), 1), &[]);
307+
if layer_input_type.compiled_nested_type() == Some(&concrete!(Table<Graphic>)) {
308308
let Some(flatten_path_definition) = resolve_document_node_type("Flatten Path") else {
309309
log::error!("Flatten Path does not exist in ModifyInputsContext::existing_node_id");
310310
return None;

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

Lines changed: 13 additions & 38 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};
@@ -881,7 +881,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
881881
};
882882
let Some(output_connector) = output_connector else { return };
883883
self.wire_in_progress_from_connector = network_interface.output_position(&output_connector, selection_network_path);
884-
self.wire_in_progress_type = FrontendGraphDataType::from_type(&network_interface.input_type(clicked_input, breadcrumb_network_path).0);
884+
self.wire_in_progress_type = network_interface.input_type(clicked_input, breadcrumb_network_path).displayed_type();
885885
return;
886886
}
887887

@@ -891,8 +891,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
891891
self.initial_disconnecting = false;
892892

893893
self.wire_in_progress_from_connector = network_interface.output_position(&clicked_output, selection_network_path);
894-
let (output_type, source) = &network_interface.output_type(&clicked_output, breadcrumb_network_path);
895-
self.wire_in_progress_type = FrontendGraphDataType::displayed_type(output_type, source);
894+
let output_type = network_interface.output_type(&clicked_output, breadcrumb_network_path);
895+
self.wire_in_progress_type = output_type.displayed_type();
896896

897897
self.update_node_graph_hints(responses);
898898
return;
@@ -1210,21 +1210,17 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
12101210
}
12111211

12121212
// Get the output types from the network interface
1213-
let (output_type, type_source) = network_interface.output_type(&output_connector, selection_network_path);
12141213
let Some(network_metadata) = network_interface.network_metadata(selection_network_path) else {
12151214
warn!("No network_metadata");
12161215
return;
12171216
};
12181217

1219-
let compatible_type = match type_source {
1220-
TypeSource::RandomProtonodeImplementation | TypeSource::Error(_) => None,
1221-
_ => Some(format!("type:{}", output_type.nested_type())),
1222-
};
1223-
12241218
let appear_right_of_mouse = if ipp.mouse.position.x > viewport.size().y() - 173. { -173. } else { 0. };
12251219
let appear_above_mouse = if ipp.mouse.position.y > viewport.size().y() - 34. { -34. } else { 0. };
12261220
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;
12271221

1222+
let compatible_type = network_interface.output_type(&output_connector, selection_network_path).add_node_string();
1223+
12281224
self.context_menu = Some(ContextMenuInformation {
12291225
context_menu_coordinates: ((point.x + node_graph_shift.x) as i32, (point.y + node_graph_shift.y) as i32),
12301226
context_menu_data: ContextMenuData::CreateNode { compatible_type },
@@ -1999,12 +1995,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
19991995
responses.add(NodeGraphMessage::SendGraph);
20001996
}
20011997
NodeGraphMessage::UpdateTypes { resolved_types, node_graph_errors } => {
2002-
for (path, node_type) in resolved_types.add {
2003-
network_interface.resolved_types.types.insert(path.to_vec(), node_type);
2004-
}
2005-
for path in resolved_types.remove {
2006-
network_interface.resolved_types.types.remove(&path.to_vec());
2007-
}
1998+
network_interface.resolved_types.update(resolved_types);
20081999
self.node_graph_errors = node_graph_errors;
20092000
}
20102001
NodeGraphMessage::UpdateActionButtons => {
@@ -2118,16 +2109,7 @@ impl NodeGraphMessageHandler {
21182109
.popover_layout({
21192110
// Showing only compatible types
21202111
let compatible_type = match (selection_includes_layers, has_multiple_selection, selected_layer) {
2121-
(true, false, Some(layer)) => {
2122-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network_interface);
2123-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2124-
if let Some(node_id) = node_type {
2125-
let (output_type, _) = network_interface.output_type(&OutputConnector::node(node_id, 0), &[]);
2126-
Some(format!("type:{}", output_type.nested_type()))
2127-
} else {
2128-
None
2129-
}
2130-
}
2112+
(true, false, Some(layer)) => network_interface.output_type(&OutputConnector::node(layer.to_node(), 1), &[]).add_node_string(),
21312113
_ => None,
21322114
};
21332115

@@ -2440,17 +2422,10 @@ impl NodeGraphMessageHandler {
24402422
.icon(Some("Node".to_string()))
24412423
.tooltip("Add an operation to the end of this layer's chain of nodes")
24422424
.popover_layout({
2443-
let layer_identifier = LayerNodeIdentifier::new(layer, context.network_interface);
2444-
let compatible_type = {
2445-
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer_identifier, context.network_interface);
2446-
let node_type = graph_layer.horizontal_layer_flow().nth(1);
2447-
if let Some(node_id) = node_type {
2448-
let (output_type, _) = context.network_interface.output_type(&OutputConnector::node(node_id, 0), &[]);
2449-
Some(format!("type:{}", output_type.nested_type()))
2450-
} else {
2451-
None
2452-
}
2453-
};
2425+
let compatible_type = context
2426+
.network_interface
2427+
.upstream_output_connector(&InputConnector::node(layer, 1), &[])
2428+
.and_then(|upstream_output| context.network_interface.output_type(&upstream_output, &[]).add_node_string());
24542429

24552430
let mut node_chooser = NodeCatalog::new();
24562431
node_chooser.intial_search = compatible_type.unwrap_or("".to_string());

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

Lines changed: 18 additions & 9 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;
@@ -85,7 +85,7 @@ pub fn start_widgets(parameter_widgets_info: ParameterWidgetsInfo) -> Vec<Widget
8585
description,
8686
input_type,
8787
blank_assist,
88-
exposeable,
88+
exposable,
8989
} = parameter_widgets_info;
9090

9191
let Some(document_node) = document_node else {
@@ -99,7 +99,7 @@ pub fn start_widgets(parameter_widgets_info: ParameterWidgetsInfo) -> Vec<Widget
9999
};
100100
let description = if description != "TODO" { description } else { String::new() };
101101
let mut widgets = Vec::with_capacity(6);
102-
if exposeable {
102+
if exposable {
103103
widgets.push(expose_widget(node_id, index, input_type, input.is_exposed()));
104104
}
105105
widgets.push(TextLabel::new(name).tooltip(description).widget_holder());
@@ -1128,7 +1128,7 @@ pub(crate) fn channel_mixer_properties(node_id: NodeId, context: &mut NodeProper
11281128

11291129
let is_monochrome = bool_widget(ParameterWidgetsInfo::new(node_id, MonochromeInput::INDEX, true, context), CheckboxInput::default());
11301130
let mut parameter_info = ParameterWidgetsInfo::new(node_id, OutputChannelInput::INDEX, true, context);
1131-
parameter_info.exposeable = false;
1131+
parameter_info.exposable = false;
11321132
let output_channel = enum_choice::<RedGreenBlue>().for_socket(parameter_info).property_row();
11331133

11341134
let document_node = match get_document_node(node_id, context) {
@@ -1185,7 +1185,7 @@ pub(crate) fn selective_color_properties(node_id: NodeId, context: &mut NodeProp
11851185
use graphene_std::raster::selective_color::*;
11861186

11871187
let mut default_info = ParameterWidgetsInfo::new(node_id, ColorsInput::INDEX, true, context);
1188-
default_info.exposeable = false;
1188+
default_info.exposable = false;
11891189
let colors = enum_choice::<SelectiveColorChoice>().for_socket(default_info).property_row();
11901190

11911191
let document_node = match get_document_node(node_id, context) {
@@ -1574,6 +1574,7 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
15741574
let mut display_decimal_places = None;
15751575
let mut step = None;
15761576
let mut unit_suffix = None;
1577+
15771578
let input_type = match implementation {
15781579
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => 'early_return: {
15791580
if let Some(field) = graphene_std::registry::NODE_METADATA
@@ -1610,7 +1611,12 @@ pub(crate) fn generate_node_properties(node_id: NodeId, context: &mut NodeProper
16101611

16111612
input_type.clone()
16121613
}
1613-
_ => context.network_interface.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path).0,
1614+
_ => context
1615+
.network_interface
1616+
.input_type(&InputConnector::node(node_id, input_index), context.selection_network_path)
1617+
.compiled_nested_type()
1618+
.cloned()
1619+
.unwrap_or(concrete!(())),
16141620
};
16151621

16161622
property_from_type(node_id, input_index, &input_type, number_options, unit_suffix, display_decimal_places, step, context).unwrap_or_else(|value| value)
@@ -1989,13 +1995,16 @@ pub struct ParameterWidgetsInfo<'a> {
19891995
description: String,
19901996
input_type: FrontendGraphDataType,
19911997
blank_assist: bool,
1992-
exposeable: bool,
1998+
exposable: bool,
19931999
}
19942000

19952001
impl<'a> ParameterWidgetsInfo<'a> {
19962002
pub fn new(node_id: NodeId, index: usize, blank_assist: bool, context: &'a mut NodePropertiesContext) -> ParameterWidgetsInfo<'a> {
19972003
let (name, description) = context.network_interface.displayed_input_name_and_description(&node_id, index, context.selection_network_path);
1998-
let input_type = FrontendGraphDataType::from_type(&context.network_interface.input_type(&InputConnector::node(node_id, index), context.selection_network_path).0);
2004+
let input_type = context
2005+
.network_interface
2006+
.input_type(&InputConnector::node(node_id, index), context.selection_network_path)
2007+
.displayed_type();
19992008
let document_node = context.network_interface.document_node(&node_id, context.selection_network_path);
20002009

20012010
ParameterWidgetsInfo {
@@ -2006,7 +2015,7 @@ impl<'a> ParameterWidgetsInfo<'a> {
20062015
description,
20072016
input_type,
20082017
blank_assist,
2009-
exposeable: true,
2018+
exposable: true,
20102019
}
20112020
}
20122021
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
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;
@@ -41,13 +40,6 @@ impl FrontendGraphDataType {
4140
_ => Self::General,
4241
}
4342
}
44-
45-
pub fn displayed_type(input: &Type, type_source: &TypeSource) -> Self {
46-
match type_source {
47-
TypeSource::Error(_) | TypeSource::RandomProtonodeImplementation => Self::General,
48-
_ => Self::from_type(input),
49-
}
50-
}
5143
}
5244

5345
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]

0 commit comments

Comments
 (0)