Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::utility_types::{Direction, NodeEvaluationError};
use crate::messages::input_mapper::utility_types::keyboard::Key;
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
use crate::messages::portfolio::document::utility_types::network_interface::{ChainInsertionPoint, ChainNodeCopy, ImportOrExport, InputConnector, NodeTemplate, OutputConnector, RootNode};
use crate::messages::portfolio::document::utility_types::network_interface::{ChainInsertionPoint, ChainNodeCopy, ImportOrExport, InputConnector, NodeTemplate, OutputConnector};
use crate::messages::prelude::*;
use glam::IVec2;
use graph_craft::document::value::TaggedValue;
Expand Down Expand Up @@ -75,10 +75,6 @@ pub enum NodeGraphMessage {
DisconnectImportExport {
index: ImportOrExport,
},
DisconnectRootNode,
SetRootNodeToRestore {
root_node_to_restore: RootNode,
},
EnterNestedNetwork,
DuplicateSelectedNodes,
ExposeInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
use crate::messages::portfolio::document::utility_types::layers_in_view::LayersInView;
use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
use crate::messages::portfolio::document::utility_types::network_interface::{
self, FlowType, GlideOffsets, ImportOrExport, InputConnector, NodeNetworkInterface, NodeTypePersistentMetadata, OutputConnector, Previewing, RootNode, TransactionCheckpoint,
self, FlowType, GlideOffsets, ImportOrExport, InputConnector, NodeNetworkInterface, NodeTypePersistentMetadata, OutputConnector, TransactionCheckpoint,
};
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, LayerPanelChainInsertion, LayerPanelChainNode, LayerPanelEntry};
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
Expand Down Expand Up @@ -471,23 +471,13 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
ImportOrExport::Import(import_index) => {
network_interface.disconnect_import_wires(import_index, breadcrumb_network_path);
}
// While previewing, drop the wire the preview would restore, as dragging it off does
ImportOrExport::Export(0) if matches!(network_interface.previewing(breadcrumb_network_path), Previewing::Yes { root_node_to_restore: Some(_) }) => {
network_interface.start_previewing_without_restore(breadcrumb_network_path);
}
ImportOrExport::Export(export_index) => network_interface.disconnect_input(&InputConnector::Export(export_index), breadcrumb_network_path),
}
network_interface.remove_orphaned_dots(breadcrumb_network_path);

responses.add(NodeGraphMessage::SendGraph);
responses.add(NodeGraphMessage::RunDocumentGraph);
}
NodeGraphMessage::DisconnectRootNode => {
network_interface.start_previewing_without_restore(selection_network_path);
}
NodeGraphMessage::SetRootNodeToRestore { root_node_to_restore } => {
network_interface.set_root_node_to_restore(root_node_to_restore, selection_network_path);
}
// Duplicates in the flow like everywhere else
NodeGraphMessage::DuplicateSelectedNodes => responses.add(DocumentMessage::DuplicateSelectedLayers),
NodeGraphMessage::EnterNestedNetwork => {
Expand Down Expand Up @@ -1396,18 +1386,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
self.wire_in_progress_to_connector = Some(point);
// Disconnect if the wire was previously connected to an input
if let Some(disconnecting) = &self.disconnecting {
let mut disconnect_root_node = false;
if let Previewing::Yes { root_node_to_restore } = network_interface.previewing(selection_network_path)
&& root_node_to_restore.is_some()
&& *disconnecting == InputConnector::Export(0)
{
disconnect_root_node = true;
}
if disconnect_root_node {
responses.add(NodeGraphMessage::DisconnectRootNode);
} else {
responses.add(NodeGraphMessage::DisconnectInput { input_connector: *disconnecting });
}
responses.add(NodeGraphMessage::DisconnectInput { input_connector: *disconnecting });
// Picking up a wire from the end of a dot leaves that dot with nothing to redirect
responses.add(NodeGraphMessage::RemoveOrphanedDots);
// Update the frontend that the node is disconnected
Expand Down Expand Up @@ -1823,7 +1802,6 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
.into_iter()
.collect::<HashSet<_>>();

let previewing = network_interface.previewing(selection_network_path);
for selected_node in &all_selected_nodes {
// Handle inputs of selected node
for input_index in 0..network_interface.number_of_inputs(selected_node, selection_network_path) {
Expand All @@ -1850,17 +1828,6 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
first_deselected_upstream_output = upstream_of(&node_id);
}

// While previewing, the export's eventual return to this node is a connection too, so it moves upstream as well
if let Some(OutputConnector::Node { node_id, output_index }) = first_deselected_upstream_output
&& let Previewing::Yes {
root_node_to_restore: Some(root_node_to_restore),
} = previewing && root_node_to_restore.to_connector() == OutputConnector::primary_output(*selected_node)
{
responses.add(NodeGraphMessage::SetRootNodeToRestore {
root_node_to_restore: RootNode { node_id, output_index },
});
}

let number_of_outputs = network_interface.number_of_outputs(selected_node, selection_network_path);
let Some(outward_wires) = network_interface.outward_wires(selection_network_path) else {
log::error!("Could not get output wires in shake input");
Expand Down Expand Up @@ -3095,7 +3062,7 @@ impl NodeGraphMessageHandler {
.filter(|input| network_interface.input_from_connector(input, network_path).is_some_and(|input| input.is_exposed()))
.filter_map(|input| network_interface.wire_update_from_input(input, wire_style, glide_offsets, network_path))
.collect::<Vec<_>>();
wires.extend(network_interface.wire_to_root(wire_style, glide_offsets, network_path));
wires.extend(network_interface.wire_to_preview(wire_style, glide_offsets, network_path));
wires
}

Expand Down Expand Up @@ -3415,14 +3382,7 @@ impl NodeGraphMessageHandler {
warn!("No network in update_selection_action_buttons");
return;
};
let previewing = if matches!(network_interface.previewing(breadcrumb_network_path), Previewing::Yes { .. }) {
network.exports.iter().find_map(|export| {
let NodeInput::Node { node_id, .. } = export else { return None };
Some(*node_id)
})
} else {
None
};
let previewing = network_interface.previewing(breadcrumb_network_path).previewed().map(|previewed| previewed.node_id);

// If only one node is selected then show the preview or stop previewing button
if let Some(node_id) = previewing {
Expand Down Expand Up @@ -3710,8 +3670,8 @@ impl NodeGraphMessageHandler {
wire_path_update: None,
}));

if let Some(wire_to_root) = network_interface.wire_to_root(graph_wire_style, &GlideOffsets::default(), breadcrumb_network_path) {
added_wires.push(wire_to_root);
if let Some(wire_to_preview) = network_interface.wire_to_preview(graph_wire_style, &GlideOffsets::default(), breadcrumb_network_path) {
added_wires.push(wire_to_preview);
} else {
added_wires.push(WirePathUpdate {
id: NodeId(u64::MAX),
Expand Down Expand Up @@ -3762,11 +3722,7 @@ impl NodeGraphMessageHandler {
log::error!("Could not get position for node: {node_id}");
continue;
};
let is_export = network_interface
.input_from_connector(&InputConnector::Export(0), breadcrumb_network_path)
.is_some_and(|export| export.as_node().is_some_and(|export_node_id| node_id == export_node_id));
let is_root_node = network_interface.root_node(breadcrumb_network_path).is_some_and(|root_node| root_node.node_id == node_id);
let previewed = is_export && !is_root_node;
let previewed = network_interface.previewing(breadcrumb_network_path).previews(node_id);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl Default for PathSnapping {

#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize, PartialEq)]
pub enum GridType {
// TODO: Eventually remove this alias document upgrade code
#[serde(alias = "Rectangle")]
Rectangular {
spacing: DVec2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ impl PartialEq for NodeNetworkInterface {
}

impl NodeNetworkInterface {
// TODO: Eventually remove this document upgrade code
/// Normalizes the stored types of every node at every nesting level, for an older document whose stored types predate the current form.
pub fn normalize_stored_types(&mut self) {
self.migrate_graph(NodeNetwork::normalize_stored_types);
}

// TODO: Eventually remove this document upgrade code
/// Add DocumentNodePath input to the PathModifyNode protonode
pub fn migrate_path_modify_node(&mut self) {
self.migrate_graph(fix_network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,7 @@ impl NodeNetworkInterface {

/// The wire into the input as the frontend draws it, with its ends following anything drawn gliding into place.
pub fn wire_update_from_input(&self, input: &InputConnector, graph_wire_style: GraphWireStyle, glide_offsets: &GlideOffsets, network_path: &[NodeId]) -> Option<WirePathUpdate> {
// While previewing, the export's wire leads to the temporarily previewed node
let dashed = *input == InputConnector::Export(0) && matches!(self.previewing(network_path), Previewing::Yes { .. });
let wire = self.wire_path_from_input(input, graph_wire_style, dashed, glide_offsets, network_path)?;
let wire = self.wire_path_from_input(input, graph_wire_style, false, glide_offsets, network_path)?;
let (id, input_index) = match input {
InputConnector::Node { node_id, input_index } => (*node_id, *input_index),
InputConnector::Export(export_index) => (NodeId(u64::MAX), *export_index),
Expand Down Expand Up @@ -755,27 +753,23 @@ impl NodeNetworkInterface {
network_metadata.transient_metadata.wires.borrow_mut().remove(input);
}

/// When previewing, there may be a second path to the root node.
pub fn wire_to_root(&self, graph_wire_style: GraphWireStyle, glide_offsets: &GlideOffsets, network_path: &[NodeId]) -> Option<WirePathUpdate> {
/// The dashed wire from the previewed node to the export, drawn alongside the export's own wire.
pub fn wire_to_preview(&self, graph_wire_style: GraphWireStyle, glide_offsets: &GlideOffsets, network_path: &[NodeId]) -> Option<WirePathUpdate> {
let input = InputConnector::Export(0);
let current_export = self.upstream_output_connector(&input, network_path)?;

let root_node = match self.previewing(network_path) {
Previewing::Yes { root_node_to_restore } => root_node_to_restore,
Previewing::No => None,
}?;
let Previewing::Yes { previewed } = self.previewing(network_path) else { return None };

if Some(root_node.node_id) == current_export.node_id() {
if self.upstream_output_connector(&input, network_path) == Some(previewed.to_connector()) {
return None;
}
let Some(input_position) = self.get_input_center(&input, network_path) else {
log::error!("Could not get input position for wire end in root node: {input:?}");
log::error!("Could not get input position for wire end in preview: {input:?}");
return None;
};
let input_position = input_position + glide_offsets.input(&input);
let upstream_output = OutputConnector::node(root_node.node_id, root_node.output_index);
let upstream_output = OutputConnector::node(previewed.node_id, previewed.output_index);
let Some(output_position) = self.get_output_center(&upstream_output, network_path) else {
log::error!("Could not get output position for wire start in root node: {upstream_output:?}");
log::error!("Could not get output position for wire start in preview: {upstream_output:?}");
return None;
};
let output_position = output_position + glide_offsets.output(&upstream_output);
Expand All @@ -787,15 +781,14 @@ impl NodeNetworkInterface {

let path_string = vector_wire.to_svg();
let center_path_string = center_line.to_svg();
// Styled by the root node's own output, since the export it leads to is connected to the previewed node instead
let output_type = self.output_type(&upstream_output, network_path);
let data_type = output_type.displayed_type();
let is_list = output_type.is_list();
let wire_path_update = Some(WirePath {
path_string,
data_type,
thick,
dashed: false,
dashed: true,
is_list,
center_path_string,
});
Expand Down
Loading
Loading