Skip to content

Commit

Permalink
Add merging nodes into a subgraph with Ctrl+M and basic subgraph sign…
Browse files Browse the repository at this point in the history
…ature customization (#2097)

* Merge nodes

* Fix bugs/crashes

* WIP: Debugging

* Fix bugs, add button

* Add imports/exports

* Improve button

* Fix breadcrumbs

* Fix lints and change shortcut key

---------

Co-authored-by: Keavon Chambers <[email protected]>
  • Loading branch information
adamgerhant and Keavon authored Nov 12, 2024
1 parent 4c4d559 commit 4250f29
Show file tree
Hide file tree
Showing 13 changed files with 735 additions and 238 deletions.
4 changes: 4 additions & 0 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ pub enum FrontendMessage {
UpdateImportsExports {
imports: Vec<(FrontendGraphOutput, i32, i32)>,
exports: Vec<(FrontendGraphInput, i32, i32)>,
#[serde(rename = "addImport")]
add_import: Option<(i32, i32)>,
#[serde(rename = "addExport")]
add_export: Option<(i32, i32)>,
},
UpdateInSelectedNetwork {
#[serde(rename = "inSelectedNetwork")]
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub fn input_mappings() -> Mapping {
entry!(KeyDown(KeyL); modifiers=[Alt], action_dispatch=NodeGraphMessage::ToggleSelectedAsLayersOrNodes),
entry!(KeyDown(KeyC); modifiers=[Shift], action_dispatch=NodeGraphMessage::PrintSelectedNodeCoordinates),
entry!(KeyDown(KeyC); modifiers=[Alt], action_dispatch=NodeGraphMessage::SendClickTargets),
entry!(KeyDown(KeyM); modifiers=[Accel], action_dispatch=NodeGraphMessage::MergeSelectedNodes),
entry!(KeyUp(KeyC); action_dispatch=NodeGraphMessage::EndSendClickTargets),
entry!(KeyDown(ArrowUp); action_dispatch=NodeGraphMessage::ShiftSelectedNodes { direction: Direction::Up, rubber_band: false }),
entry!(KeyDown(ArrowRight); action_dispatch=NodeGraphMessage::ShiftSelectedNodes { direction: Direction::Right, rubber_band: false }),
Expand Down
15 changes: 13 additions & 2 deletions editor/src/messages/portfolio/document/document_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
}
DocumentMessage::DebugPrintDocument => {
info!("{:#?}", self.network_interface);
info!("{:?}", self.network_interface);
}
DocumentMessage::DeleteNode { node_id } => {
responses.add(DocumentMessage::StartTransaction);
Expand Down Expand Up @@ -1128,6 +1128,9 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
// TODO: Allow non layer nodes to have click targets
let layer_click_targets = click_targets
.into_iter()
.filter(|(node_id, _)|
// Ensure that the layer is in the document network to prevent logging an error
self.network_interface.network(&[]).unwrap().nodes.contains_key(node_id))
.filter_map(|(node_id, click_targets)| {
self.network_interface.is_layer(&node_id, &[]).then(|| {
let layer = LayerNodeIdentifier::new(node_id, &self.network_interface, &[]);
Expand Down Expand Up @@ -1223,11 +1226,19 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
self.network_interface.set_transform(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();
let add_import = self.network_interface.frontend_import_modify(&self.breadcrumb_network_path);
let add_export = self.network_interface.frontend_export_modify(&self.breadcrumb_network_path);

responses.add(DocumentMessage::RenderRulers);
responses.add(DocumentMessage::RenderScrollbars);
responses.add(NodeGraphMessage::UpdateEdges);
responses.add(NodeGraphMessage::UpdateBoxSelection);
responses.add(FrontendMessage::UpdateImportsExports { imports, exports });
responses.add(FrontendMessage::UpdateImportsExports {
imports,
exports,
add_import,
add_export,
});
responses.add(FrontendMessage::UpdateNodeGraphTransform {
transform: Transform {
scale: transform.matrix2.x_axis.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ static DOCUMENT_NODE_TYPES: once_cell::sync::Lazy<Vec<DocumentNodeDefinition>> =
/// The [`DocumentNode`] is the instance while these [`DocumentNodeDefinition`]s are the "classes" or "blueprints" from which the instances are built.
fn static_nodes() -> Vec<DocumentNodeDefinition> {
let mut custom = vec![
// TODO: Auto-generate this from its proto node macro
DocumentNodeDefinition {
identifier: "Default Network",
category: "General",
node_template: NodeTemplate {
document_node: DocumentNode {
implementation: DocumentNodeImplementation::Network(NodeNetwork::default()),
..Default::default()
},
persistent_node_metadata: DocumentNodePersistentMetadata {
network_metadata: Some(NodeNetworkMetadata::default()),
..Default::default()
},
},
description: Cow::Borrowed("A default node network you can use to create your own custom nodes."),
properties: &node_properties::node_no_properties,
},
// TODO: Auto-generate this from its proto node macro
DocumentNodeDefinition {
identifier: "Identity",
Expand All @@ -80,7 +97,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
},
description: Cow::Borrowed("The identity node simply passes its data through. You can use this to organize your node graph if you want."),
description: Cow::Borrowed("The identity node passes its data through. You can use this to organize your node graph."),
properties: &|_document_node, _node_id, _context| node_properties::string_properties("The identity node simply passes its data through"),
},
// TODO: Auto-generate this from its proto node macro
Expand All @@ -101,7 +118,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
},
description: Cow::Borrowed("The Monitor node is used by the editor to access the data flowing through it"),
description: Cow::Borrowed("The Monitor node is used by the editor to access the data flowing through it."),
properties: &|_document_node, _node_id, _context| node_properties::string_properties("The Monitor node is used by the editor to access the data flowing through it"),
},
DocumentNodeDefinition {
Expand Down Expand Up @@ -208,7 +225,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
},
description: Cow::Borrowed("The Merge node combines graphical data through composition"),
description: Cow::Borrowed("The Merge node combines graphical data through composition."),
properties: &node_properties::node_no_properties,
},
DocumentNodeDefinition {
Expand Down Expand Up @@ -319,7 +336,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
},
description: Cow::Borrowed("Creates a new Artboard which can be used as a working surface"),
description: Cow::Borrowed("Creates a new Artboard which can be used as a working surface."),
properties: &node_properties::artboard_properties,
},
DocumentNodeDefinition {
Expand Down Expand Up @@ -719,7 +736,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
},
description: Cow::Borrowed("Creates an embedded image with the given transform"),
description: Cow::Borrowed("Creates an embedded image with the given transform."),
properties: &|_document_node, _node_id, _context| node_properties::string_properties("Creates an embedded image with the given transform"),
},
DocumentNodeDefinition {
Expand Down Expand Up @@ -798,7 +815,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
..Default::default()
},
},
description: Cow::Borrowed("Generates different noise patters"),
description: Cow::Borrowed("Generates different noise patterns."),
properties: &node_properties::noise_pattern_properties,
},
// TODO: This needs to work with resolution-aware (raster with footprint, post-Cull node) data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeTemplate, OutputConnector};
use crate::messages::prelude::*;

use glam::IVec2;
use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeInput};
use graph_craft::proto::GraphErrors;
Expand All @@ -16,6 +17,8 @@ pub enum NodeGraphMessage {
nodes: Vec<(NodeId, NodeTemplate)>,
new_ids: HashMap<NodeId, NodeId>,
},
AddImport,
AddExport,
Init,
SelectedNodesUpdated,
Copy,
Expand Down Expand Up @@ -68,6 +71,7 @@ pub enum NodeGraphMessage {
input_connector: InputConnector,
insert_node_input_index: usize,
},
MergeSelectedNodes,
MoveLayerToStack {
layer: LayerNodeIdentifier,
parent: LayerNodeIdentifier,
Expand Down Expand Up @@ -126,19 +130,23 @@ pub enum NodeGraphMessage {
node_id: NodeId,
alias: String,
},
SetToNodeOrLayer {
node_id: NodeId,
is_layer: bool,
},
ShiftNodePosition {
node_id: NodeId,
x: i32,
y: i32,
},
SetToNodeOrLayer {
node_id: NodeId,
is_layer: bool,
},
ShiftSelectedNodes {
direction: Direction,
rubber_band: bool,
},
ShiftSelectedNodesByAmount {
graph_delta: IVec2,
rubber_band: bool,
},
TogglePreview {
node_id: NodeId,
},
Expand Down
Loading

0 comments on commit 4250f29

Please sign in to comment.