Skip to content

Commit 31eba84

Browse files
committed
Add invalid type
1 parent 19ac9c5 commit 31eba84

File tree

11 files changed

+146
-139
lines changed

11 files changed

+146
-139
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,37 @@ 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+
// Link the protonodes with custom networks to their reference
36+
for node in custom.iter_mut() {
37+
traverse_node(&node.node_template.document_node, &mut node.node_template.persistent_node_metadata);
38+
}
39+
1040
// Remove struct generics
1141
for DocumentNodeDefinition { node_template, .. } in custom.iter_mut() {
1242
let NodeTemplate {

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/node_properties.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,6 @@ 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-
15781577
let input_type = match implementation {
15791578
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => 'early_return: {
15801579
if let Some(field) = graphene_std::registry::NODE_METADATA

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: 12 additions & 10 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)
@@ -679,7 +679,6 @@ impl NodeNetworkInterface {
679679
/// Returns None if there is an error, it is the document network, a hidden primary output or import
680680
pub fn frontend_output_from_connector(&mut self, output_connector: &OutputConnector, network_path: &[NodeId]) -> Option<FrontendGraphOutput> {
681681
let output_type = self.output_type(output_connector, network_path);
682-
683682
let (name, description) = match output_connector {
684683
OutputConnector::Node { node_id, output_index } => {
685684
// Do not display the primary output port for a node if it is a network node with a hidden primary export
@@ -690,7 +689,7 @@ impl NodeNetworkInterface {
690689
let node_metadata = self.node_metadata(node_id, network_path)?;
691690
let output_name = node_metadata.persistent_metadata.output_names.get(*output_index).cloned().unwrap_or_default();
692691

693-
let output_name = if !output_name.is_empty() { output_name } else { output_type.resolved_type_name() };
692+
let output_name = if !output_name.is_empty() { output_name } else { output_type.resolved_type_node_string() };
694693
(output_name, String::new())
695694
}
696695
OutputConnector::Import(import_index) => {
@@ -707,7 +706,7 @@ impl NodeNetworkInterface {
707706

708707
let import_name = if !import_name.is_empty() {
709708
import_name
710-
} else if let Some(import_type_name) = output_type.compiled_nested_type_name() {
709+
} else if let Some(import_type_name) = output_type.compiled_nested_type().map(|nested| nested.to_string()) {
711710
import_type_name
712711
} else {
713712
format!("Import index {}", import_index)
@@ -717,7 +716,7 @@ impl NodeNetworkInterface {
717716
}
718717
};
719718
let data_type = output_type.displayed_type();
720-
let resolved_type = output_type.resolved_type_name();
719+
let resolved_type = output_type.resolved_type_node_string();
721720
let mut connected_to = self
722721
.outward_wires(network_path)
723722
.and_then(|outward_wires| outward_wires.get(output_connector))
@@ -977,7 +976,7 @@ impl NodeNetworkInterface {
977976
};
978977
let description = input_metadata.input_description.to_string();
979978
let name = if input_metadata.input_name.is_empty() {
980-
self.input_type(&InputConnector::node(*node_id, input_index), network_path).resolved_type_name()
979+
self.input_type(&InputConnector::node(*node_id, input_index), network_path).resolved_type_node_string()
981980
} else {
982981
input_metadata.input_name.to_string()
983982
};
@@ -1015,7 +1014,7 @@ impl NodeNetworkInterface {
10151014
pub fn description(&self, node_id: &NodeId, network_path: &[NodeId]) -> String {
10161015
self.get_node_definition(node_id, network_path)
10171016
.map(|node_definition| node_definition.description.to_string())
1018-
.filter(|description: &String| description != "TODO")
1017+
.filter(|description| description != "TODO")
10191018
.unwrap_or_default()
10201019
}
10211020

@@ -2455,7 +2454,10 @@ impl NodeNetworkInterface {
24552454
pub fn wire_path_from_input(&mut self, input: &InputConnector, graph_wire_style: GraphWireStyle, dashed: bool, network_path: &[NodeId]) -> Option<WirePath> {
24562455
let (vector_wire, thick) = self.vector_wire_from_input(input, graph_wire_style, network_path)?;
24572456
let path_string = vector_wire.to_svg();
2458-
let data_type = self.input_type(input, network_path).displayed_type();
2457+
let data_type = self
2458+
.upstream_output_connector(input, network_path)
2459+
.map(|output| self.output_type(&output, network_path).displayed_type())
2460+
.unwrap_or(FrontendGraphDataType::General);
24592461
Some(WirePath {
24602462
path_string,
24612463
data_type,

0 commit comments

Comments
 (0)