Skip to content

Commit ebbafaa

Browse files
committed
Add invalid type
1 parent 6a2c0a6 commit ebbafaa

File tree

10 files changed

+165
-140
lines changed

10 files changed

+165
-140
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ use crate::messages::portfolio::document::utility_types::nodes::CollapsedLayers;
77
use crate::messages::prelude::*;
88
use crate::messages::tool::common_functionality::graph_modification_utils::get_clip_mode;
99
use glam::{DAffine2, DVec2, IVec2};
10+
use graph_craft::document::value::TaggedValue;
1011
use graph_craft::document::{NodeId, NodeInput};
1112
use graphene_std::Color;
1213
use graphene_std::renderer::Quad;
1314
use graphene_std::renderer::convert_usvg_path::convert_usvg_path;
15+
use graphene_std::table::Table;
1416
use graphene_std::text::{Font, TypesettingConfig};
1517
use graphene_std::vector::style::{Fill, Gradient, GradientStops, GradientType, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
1618

@@ -140,10 +142,16 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
140142
skip_rerender: true,
141143
});
142144
}
145+
// Set the bottom input of the artboard back to artboard
146+
let bottom_input = NodeInput::value(TaggedValue::Artboard(Table::new()), true);
147+
network_interface.set_input(&InputConnector::node(artboard_layer.to_node(), 0), bottom_input, &[]);
143148
} else {
144149
// We have some non layers (e.g. just a rectangle node). We disconnect the bottom input and connect it to the left input.
145150
network_interface.disconnect_input(&InputConnector::node(artboard_layer.to_node(), 0), &[]);
146151
network_interface.set_input(&InputConnector::node(artboard_layer.to_node(), 1), primary_input, &[]);
152+
// Set the bottom input of the artboard back to artboard
153+
let bottom_input = NodeInput::value(TaggedValue::Artboard(Table::new()), true);
154+
network_interface.set_input(&InputConnector::node(artboard_layer.to_node(), 0), bottom_input, &[]);
147155
}
148156
}
149157
responses.add_front(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });

editor/src/messages/portfolio/document/node_graph/document_node_definitions/document_node_derive.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,39 @@ use graphene_std::registry::*;
66
use graphene_std::*;
77
use std::collections::HashSet;
88

9+
/// Traverses a document node template and metadata in parallel to link the protonodes to their reference
10+
fn traverse_node(node: &DocumentNode, node_metadata: &mut DocumentNodePersistentMetadata) {
11+
match &node.implementation {
12+
DocumentNodeImplementation::Network(node_network) => {
13+
for (nested_node_id, nested_node) in node_network.nodes.iter() {
14+
let nested_metadata = node_metadata
15+
.network_metadata
16+
.as_mut()
17+
.expect("Network node must have network metadata")
18+
.persistent_metadata
19+
.node_metadata
20+
.get_mut(nested_node_id)
21+
.expect("Network metadata must have corresponding node id");
22+
traverse_node(nested_node, &mut nested_metadata.persistent_metadata);
23+
}
24+
}
25+
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
26+
if let Some(metadata) = NODE_METADATA.lock().unwrap().get(&proto_node_identifier) {
27+
node_metadata.reference = Some(metadata.display_name.to_string());
28+
}
29+
}
30+
DocumentNodeImplementation::Extract => {}
31+
}
32+
}
33+
934
pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec<DocumentNodeDefinition> {
35+
NODE_METADATA.lock().unwrap().keys().for_each(|key| log::debug!("{key:?}"));
36+
37+
// Link the protonodes with custom networks to their reference
38+
for node in custom.iter_mut() {
39+
traverse_node(&node.node_template.document_node, &mut node.node_template.persistent_node_metadata);
40+
}
41+
1042
// Remove struct generics
1143
for DocumentNodeDefinition { node_template, .. } in custom.iter_mut() {
1244
let NodeTemplate {
@@ -20,7 +52,6 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
2052
*name = Cow::Owned(new_name.to_string())
2153
};
2254
}
23-
2455
let node_registry = NODE_REGISTRY.lock().unwrap();
2556
'outer: for (id, metadata) in NODE_METADATA.lock().unwrap().iter() {
2657
for node in custom.iter() {
@@ -32,7 +63,10 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
3263
..
3364
} = node;
3465
match implementation {
35-
DocumentNodeImplementation::ProtoNode(name) if name == id => continue 'outer,
66+
DocumentNodeImplementation::ProtoNode(name) if name == id => {
67+
log::debug!("skipping defintion {name}");
68+
continue 'outer;
69+
}
3670
_ => (),
3771
}
3872
}
@@ -55,6 +89,8 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
5589
let output_type = &first_node_io.return_value;
5690

5791
let inputs = preprocessor::node_inputs(fields, first_node_io);
92+
log::debug!("generating definition for {display_name:?}");
93+
5894
let node = DocumentNodeDefinition {
5995
identifier: display_name,
6096
node_template: NodeTemplate {
@@ -91,5 +127,6 @@ pub(super) fn post_process_nodes(mut custom: Vec<DocumentNodeDefinition>) -> Vec
91127
custom.push(node);
92128
}
93129

130+
custom.iter().for_each(|def| log::debug!("{:?}", def.identifier));
94131
custom
95132
}

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
2323
use crate::messages::viewport::Position;
2424
use glam::{DAffine2, DVec2, IVec2};
2525
use graph_craft::document::{DocumentNodeImplementation, NodeId, NodeInput};
26-
use graph_craft::proto::GraphErrors;
2726
use graphene_std::math::math_ext::QuadExt;
2827
use graphene_std::vector::algorithms::bezpath_algorithms::bezpath_is_inside_bezpath;
2928
use graphene_std::*;
@@ -51,7 +50,6 @@ pub struct NodeGraphMessageContext<'a> {
5150
pub struct NodeGraphMessageHandler {
5251
// TODO: Remove network and move to NodeNetworkInterface
5352
pub network: Vec<NodeId>,
54-
pub node_graph_errors: GraphErrors,
5553
has_selection: bool,
5654
widgets: [LayoutGroup; 2],
5755
/// Used to add a transaction for the first node move when dragging.
@@ -1628,7 +1626,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
16281626
if node_bbox[1].x >= document_bbox[0].x && node_bbox[0].x <= document_bbox[1].x && node_bbox[1].y >= document_bbox[0].y && node_bbox[0].y <= document_bbox[1].y {
16291627
nodes.push(*node_id);
16301628
}
1631-
for error in &self.node_graph_errors {
1629+
for error in &network_interface.resolved_types.node_graph_errors {
16321630
if error.node_path.contains(node_id) {
16331631
nodes.push(*node_id);
16341632
}
@@ -1992,8 +1990,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
19921990
responses.add(NodeGraphMessage::SendGraph);
19931991
}
19941992
NodeGraphMessage::UpdateTypes { resolved_types, node_graph_errors } => {
1995-
network_interface.resolved_types.update(resolved_types);
1996-
self.node_graph_errors = node_graph_errors;
1993+
network_interface.resolved_types.update(resolved_types, node_graph_errors);
19971994
}
19981995
NodeGraphMessage::UpdateActionButtons => {
19991996
if selection_network_path == breadcrumb_network_path {
@@ -2554,13 +2551,14 @@ impl NodeGraphMessageHandler {
25542551

25552552
let locked = network_interface.is_locked(&node_id, breadcrumb_network_path);
25562553

2557-
let errors = self
2554+
let errors = network_interface
2555+
.resolved_types
25582556
.node_graph_errors
25592557
.iter()
25602558
.find(|error| error.node_path == node_id_path)
25612559
.map(|error| format!("{:?}", error.error.clone()))
25622560
.or_else(|| {
2563-
if self.node_graph_errors.iter().any(|error| error.node_path.starts_with(&node_id_path)) {
2561+
if network_interface.resolved_types.node_graph_errors.iter().any(|error| error.node_path.starts_with(&node_id_path)) {
25642562
Some("Node graph type error within this node".to_string())
25652563
} else {
25662564
None
@@ -2743,7 +2741,6 @@ impl Default for NodeGraphMessageHandler {
27432741
fn default() -> Self {
27442742
Self {
27452743
network: Vec::new(),
2746-
node_graph_errors: Vec::new(),
27472744
has_selection: false,
27482745
widgets: [LayoutGroup::Row { widgets: Vec::new() }, LayoutGroup::Row { widgets: Vec::new() }],
27492746
drag_start: None,
@@ -2775,7 +2772,6 @@ impl Default for NodeGraphMessageHandler {
27752772
impl PartialEq for NodeGraphMessageHandler {
27762773
fn eq(&self, other: &Self) -> bool {
27772774
self.network == other.network
2778-
&& self.node_graph_errors == other.node_graph_errors
27792775
&& self.has_selection == other.has_selection
27802776
&& self.widgets == other.widgets
27812777
&& self.drag_start == other.drag_start

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum FrontendGraphDataType {
1616
Color,
1717
Gradient,
1818
Typography,
19+
Invalid,
1920
}
2021

2122
impl FrontendGraphDataType {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::nodes::SelectedNodes;
88
use crate::consts::{EXPORTS_TO_RIGHT_EDGE_PIXEL_GAP, EXPORTS_TO_TOP_EDGE_PIXEL_GAP, GRID_SIZE, IMPORTS_TO_LEFT_EDGE_PIXEL_GAP, IMPORTS_TO_TOP_EDGE_PIXEL_GAP};
99
use crate::messages::portfolio::document::graph_operation::utility_types::ModifyInputsContext;
1010
use crate::messages::portfolio::document::node_graph::document_node_definitions::{DocumentNodeDefinition, resolve_document_node_type};
11-
use crate::messages::portfolio::document::node_graph::utility_types::{Direction, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput};
11+
use crate::messages::portfolio::document::node_graph::utility_types::{Direction, FrontendClickTargets, FrontendGraphDataType, FrontendGraphInput, FrontendGraphOutput};
1212
use crate::messages::portfolio::document::utility_types::network_interface::resolved_types::ResolvedDocumentNodeTypes;
1313
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
1414
use crate::messages::tool::common_functionality::graph_modification_utils;
@@ -625,7 +625,7 @@ impl NodeNetworkInterface {
625625
}
626626
let input_type = self.input_type(input_connector, network_path);
627627
let data_type = input_type.displayed_type();
628-
let resolved_type = input_type.resolved_type_name();
628+
let resolved_type = input_type.resolved_type_node_string();
629629

630630
let connected_to = self
631631
.upstream_output_connector(input_connector, network_path)
@@ -656,7 +656,7 @@ impl NodeNetworkInterface {
656656

657657
let export_name = if !export_name.is_empty() {
658658
export_name
659-
} else if let Some(export_type_name) = input_type.compiled_nested_type_name() {
659+
} else if let Some(export_type_name) = input_type.compiled_nested_type().map(|nested| nested.to_string()) {
660660
export_type_name
661661
} else {
662662
format!("Export index {}", export_index)
@@ -690,7 +690,7 @@ impl NodeNetworkInterface {
690690
let node_metadata = self.node_metadata(node_id, network_path)?;
691691
let output_name = node_metadata.persistent_metadata.output_names.get(*output_index).cloned().unwrap_or_default();
692692

693-
let output_name = if !output_name.is_empty() { output_name } else { output_type.resolved_type_name() };
693+
let output_name = if !output_name.is_empty() { output_name } else { output_type.resolved_type_node_string() };
694694
(output_name, String::new())
695695
}
696696
OutputConnector::Import(import_index) => {
@@ -707,7 +707,7 @@ impl NodeNetworkInterface {
707707

708708
let import_name = if !import_name.is_empty() {
709709
import_name
710-
} else if let Some(import_type_name) = output_type.compiled_nested_type_name() {
710+
} else if let Some(import_type_name) = output_type.compiled_nested_type().map(|nested| nested.to_string()) {
711711
import_type_name
712712
} else {
713713
format!("Import index {}", import_index)
@@ -717,7 +717,7 @@ impl NodeNetworkInterface {
717717
}
718718
};
719719
let data_type = output_type.displayed_type();
720-
let resolved_type = output_type.resolved_type_name();
720+
let resolved_type = output_type.resolved_type_node_string();
721721
let mut connected_to = self
722722
.outward_wires(network_path)
723723
.and_then(|outward_wires| outward_wires.get(output_connector))
@@ -977,7 +977,7 @@ impl NodeNetworkInterface {
977977
};
978978
let description = input_metadata.input_description.to_string();
979979
let name = if input_metadata.input_name.is_empty() {
980-
self.input_type(&InputConnector::node(*node_id, input_index), network_path).resolved_type_name()
980+
self.input_type(&InputConnector::node(*node_id, input_index), network_path).resolved_type_node_string()
981981
} else {
982982
input_metadata.input_name.to_string()
983983
};
@@ -2455,7 +2455,10 @@ impl NodeNetworkInterface {
24552455
pub fn wire_path_from_input(&mut self, input: &InputConnector, graph_wire_style: GraphWireStyle, dashed: bool, network_path: &[NodeId]) -> Option<WirePath> {
24562456
let (vector_wire, thick) = self.vector_wire_from_input(input, graph_wire_style, network_path)?;
24572457
let path_string = vector_wire.to_svg();
2458-
let data_type = self.input_type(input, network_path).displayed_type();
2458+
let data_type = self
2459+
.upstream_output_connector(input, network_path)
2460+
.map(|output| self.output_type(&output, network_path).displayed_type())
2461+
.unwrap_or(FrontendGraphDataType::General);
24592462
Some(WirePath {
24602463
path_string,
24612464
data_type,

0 commit comments

Comments
 (0)