Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store network metadata information in the Node Network #1957

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 0 additions & 2 deletions editor/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pub const IMPORTS_TO_LEFT_EDGE_PIXEL_GAP: u32 = 120;
// Viewport
pub const VIEWPORT_ZOOM_WHEEL_RATE: f64 = (1. / 600.) * 3.;
pub const VIEWPORT_ZOOM_MOUSE_RATE: f64 = 1. / 400.;
pub const VIEWPORT_ZOOM_SCALE_MIN: f64 = 0.000_000_1;
pub const VIEWPORT_ZOOM_SCALE_MAX: f64 = 10_000.;
pub const VIEWPORT_ZOOM_MIN_FRACTION_COVER: f64 = 0.01;
pub const VIEWPORT_ZOOM_LEVELS: [f64; 74] = [
0.0001, 0.000125, 0.00016, 0.0002, 0.00025, 0.00032, 0.0004, 0.0005, 0.00064, 0.0008, 0.001, 0.0016, 0.002, 0.0025, 0.0032, 0.004, 0.005, 0.0064, 0.008, 0.01, 0.01125, 0.015, 0.02, 0.025, 0.03,
Expand Down
12 changes: 6 additions & 6 deletions editor/src/messages/dialog/dialog_message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::simple_dialogs::{self, AboutGraphiteDialog, ComingSoonDialog, DemoArtworkDialog, LicensesDialog};
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
use crate::messages::prelude::*;

pub struct DialogMessageData<'a> {
Expand Down Expand Up @@ -74,12 +75,11 @@ impl MessageHandler<DialogMessage, DialogMessageData<'_>> for DialogMessageHandl
.all_layers()
.filter(|&layer| document.network_interface.is_artboard(&layer.to_node(), &[]))
.map(|layer| {
let name = document
.network_interface
.node_metadata(&layer.to_node(), &[])
.map(|node| node.persistent_metadata.display_name.clone())
.and_then(|name| if name.is_empty() { None } else { Some(name) })
.unwrap_or_else(|| "Artboard".to_string());
let display_name = document.network_interface.display_name(&layer.to_node(), &[]).cloned().unwrap_or_else(|| {
log::error!("Artboard has no display name: {:?}", layer);
"".to_string()
});
let name = if display_name.is_empty() { "Artboard".to_string() } else { display_name };
(layer, name)
})
.collect();
Expand Down
40 changes: 21 additions & 19 deletions editor/src/messages/portfolio/document/document_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::node_graph::utility_types::Transform;
use super::utility_types::clipboards::Clipboard;
use super::utility_types::error::EditorError;
use super::utility_types::misc::{SnappingOptions, SnappingState, GET_SNAP_BOX_FUNCTIONS, GET_SNAP_GEOMETRY_FUNCTIONS};
use super::utility_types::network_interface::{NodeNetworkInterface, TransactionStatus};
use super::utility_types::nodes::{CollapsedLayers, SelectedNodes};
use super::utility_types::network_interface::{NodeNetworkInterface, NodeNetworkPersistentMetadata, TransactionStatus};
use super::utility_types::nodes::{CollapsedLayers, OldSelectedNodes, SelectedNodes};
use crate::application::{generate_uuid, GRAPHITE_GIT_COMMIT_HASH};
use crate::consts::{ASYMPTOTIC_EFFECT, DEFAULT_DOCUMENT_NAME, FILE_SAVE_SUFFIX, SCALE_EFFECT, SCROLLBAR_SPACING, VIEWPORT_ROTATE_SNAP_INTERVAL};
use crate::messages::input_mapper::utility_types::macros::action_keys;
Expand All @@ -13,7 +13,7 @@ use crate::messages::portfolio::document::node_graph::NodeGraphHandlerData;
use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay, overlay_options};
use crate::messages::portfolio::document::properties_panel::utility_types::PropertiesPanelMessageHandlerData;
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis};
use crate::messages::portfolio::document::utility_types::nodes::RawBuffer;
use crate::messages::portfolio::utility_types::PersistentData;
use crate::messages::prelude::*;
Expand All @@ -24,7 +24,7 @@ use crate::messages::tool::utility_types::ToolType;
use crate::node_graph_executor::NodeGraphExecutor;

use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeNetwork, OldNodeNetwork};
use graph_craft::document::{NodeId, NodeNetwork, OldNodeNetwork, PTZ};
use graphene_core::raster::BlendMode;
use graphene_core::raster::ImageFrame;
use graphene_core::vector::style::ViewMode;
Expand All @@ -48,7 +48,7 @@ pub struct OldDocumentMessageHandler {
/// It recursively stores its sub-graphs, so this root graph is the whole snapshot of the document content.
pub network: OldNodeNetwork,
/// List of the [`NodeId`]s that are currently selected by the user.
pub selected_nodes: SelectedNodes,
pub selected_nodes: OldSelectedNodes,
/// List of the [`LayerNodeIdentifier`]s that are currently collapsed by the user in the Layers panel.
/// Collapsed means that the expansion arrow isn't set to show the children of these layers.
pub collapsed: CollapsedLayers,
Expand All @@ -70,7 +70,7 @@ pub struct OldDocumentMessageHandler {
/// Sets whether or not the rulers should be drawn along the top and left edges of the viewport area.
pub rulers_visible: bool,
/// Sets whether or not the node graph is drawn (as an overlay) on top of the viewport area, or otherwise if it's hidden.
pub graph_view_overlay_open: bool,
pub graph_ui_open: bool,
/// The current user choices for snapping behavior, including whether snapping is enabled at all.
pub snapping_state: SnappingState,
}
Expand Down Expand Up @@ -299,6 +299,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
}
DocumentMessage::ClearLayersPanel => {
// Send an empty layer list
// TODO: Dont create a new document message handler just to get the default data buffer for an empty layer structure
let data_buffer: RawBuffer = Self::default().serialize_root();
responses.add(FrontendMessage::UpdateDocumentLayerStructure { data_buffer });

Expand Down Expand Up @@ -779,10 +780,8 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
}
DocumentMessage::RenderRulers => {
let current_ptz = if self.graph_view_overlay_open {
let Some(network_metadata) = self.network_interface.network_metadata(&self.breadcrumb_network_path) else {
return;
};
&network_metadata.persistent_metadata.navigation_metadata.node_graph_ptz
let Some(ptz) = self.network_interface.ptz(&self.breadcrumb_network_path) else { return };
ptz
} else {
&self.document_ptz
};
Expand Down Expand Up @@ -1106,14 +1105,14 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
}));
responses.add(NodeGraphMessage::RunDocumentGraph);
} else {
let Some(network_metadata) = self.network_interface.network_metadata(&self.breadcrumb_network_path) else {
let Some(ptz) = self.network_interface.ptz(&self.breadcrumb_network_path) else {
return;
};

let transform = self
.navigation_handler
.calculate_offset_transform(ipp.viewport_bounds.center(), &network_metadata.persistent_metadata.navigation_metadata.node_graph_ptz);
self.network_interface.set_transform(transform, &self.breadcrumb_network_path);
let transform = self.navigation_handler.calculate_offset_transform(ipp.viewport_bounds.center(), ptz);

self.network_interface.set_node_graph_to_viewport(transform, &self.breadcrumb_network_path);

let imports = self.network_interface.frontend_imports(&self.breadcrumb_network_path).unwrap_or_default();
let exports = self.network_interface.frontend_exports(&self.breadcrumb_network_path).unwrap_or_default();
responses.add(DocumentMessage::RenderRulers);
Expand Down Expand Up @@ -1328,7 +1327,7 @@ impl DocumentMessageHandler {
view_mode: old_message_handler.view_mode,
overlays_visible: old_message_handler.overlays_visible,
rulers_visible: old_message_handler.rulers_visible,
graph_view_overlay_open: old_message_handler.graph_view_overlay_open,
graph_view_overlay_open: old_message_handler.graph_ui_open,
snapping_state: old_message_handler.snapping_state,
..Default::default()
};
Expand Down Expand Up @@ -1435,7 +1434,8 @@ impl DocumentMessageHandler {
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
responses.add(NodeGraphMessage::SelectedNodesUpdated);
responses.add(NodeGraphMessage::ForceRunDocumentGraph);

// TODO: Remove once the footprint is used to load the imports/export distances from the edge
responses.add(NodeGraphMessage::SetGridAlignedEdges);
Some(previous_network)
}
pub fn redo_with_history(&mut self, ipp: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) {
Expand Down Expand Up @@ -1464,7 +1464,8 @@ impl DocumentMessageHandler {
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
responses.add(NodeGraphMessage::SelectedNodesUpdated);
responses.add(NodeGraphMessage::ForceRunDocumentGraph);

// TODO: Remove once the footprint is used to load the imports/export distances from the edge
responses.add(NodeGraphMessage::SetGridAlignedEdges);
Some(previous_network)
}

Expand Down Expand Up @@ -1507,7 +1508,7 @@ impl DocumentMessageHandler {
.unwrap_or_else(|| self.network_interface.all_artboards().iter().next().copied().unwrap_or(LayerNodeIdentifier::ROOT_PARENT))
}

pub fn get_calculated_insert_index(metadata: &DocumentMetadata, selected_nodes: SelectedNodes, parent: LayerNodeIdentifier) -> usize {
pub fn get_calculated_insert_index(metadata: &DocumentMetadata, selected_nodes: impl SelectedNodes, parent: LayerNodeIdentifier) -> usize {
parent
.children(metadata)
.enumerate()
Expand Down Expand Up @@ -1979,6 +1980,7 @@ impl DocumentMessageHandler {
/// Create a network interface with a single export
fn default_document_network_interface() -> NodeNetworkInterface {
let mut network_interface = NodeNetworkInterface::default();
network_interface.insert_network_metadata(NodeNetworkPersistentMetadata::default(), &[]);
network_interface.add_export(TaggedValue::ArtboardGroup(graphene_core::ArtboardGroup::EMPTY), -1, "".to_string(), &[]);
network_interface
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::transform_utils;
use super::utility_types::ModifyInputsContext;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface};
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
use crate::messages::portfolio::document::utility_types::nodes::CollapsedLayers;
use crate::messages::prelude::*;

use graph_craft::document::{generate_uuid, NodeId, NodeInput};
use graph_craft::document::{generate_uuid, NodeId, NodeInput, InputConnector};
use graphene_core::renderer::Quad;
use graphene_core::text::Font;
use graphene_core::vector::style::{Fill, Gradient, GradientStops, GradientType, LineCap, LineJoin, Stroke};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface};
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;

use bezier_rs::Subpath;
use graph_craft::document::{value::TaggedValue, NodeId, NodeInput};
use graph_craft::document::{value::TaggedValue, InputConnector, NodeId, NodeInput};
use graphene_core::vector::PointId;

use glam::{DAffine2, DVec2};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::transform_utils;
use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_document_node_type;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::network_interface::{self, InputConnector, NodeNetworkInterface, OutputConnector};
use crate::messages::portfolio::document::utility_types::network_interface::{self, NodeNetworkInterface};
use crate::messages::prelude::*;

use bezier_rs::Subpath;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{generate_uuid, NodeId, NodeInput};
use graph_craft::document::{generate_uuid, InputConnector, NodeId, NodeInput, OutputConnector};
use graphene_core::raster::{BlendMode, ImageFrame};
use graphene_core::text::Font;
use graphene_core::vector::brush_stroke::BrushStroke;
Expand Down Expand Up @@ -242,7 +242,12 @@ impl<'a> ModifyInputsContext<'a> {
// Take until another layer node is found (but not the first layer node)
let existing_node_id = upstream
.take_while(|node_id| is_traversal_start(*node_id) || !self.network_interface.is_layer(node_id, &[]))
.find(|node_id| self.network_interface.reference(node_id, &[]).is_some_and(|node_reference| node_reference == reference));
.find(|node_id| {
let Some(node_reference) = self.network_interface.reference(node_id, &[]) else {
log::error!("Node reference does not exist in ModifyInputsContext::existing_node_id");
return false;
};
node_reference.as_ref().is_some_and(|node_reference| node_reference == reference)});

// Create a new node if the node does not exist and update its inputs
existing_node_id.or_else(|| {
Expand Down
Loading