Skip to content

Commit cf9dca4

Browse files
4adexKeavon
authored andcommitted
Add graph message for adding a path
1 parent 561b671 commit cf9dca4

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub enum NodeGraphMessage {
1616
nodes: Vec<(NodeId, NodeTemplate)>,
1717
new_ids: HashMap<NodeId, NodeId>,
1818
},
19+
AddPathNode,
1920
AddImport,
2021
AddExport,
2122
Init,

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers
1616
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
1717
use crate::messages::prelude::*;
1818
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
19-
use crate::messages::tool::common_functionality::graph_modification_utils::get_clip_mode;
19+
use crate::messages::tool::common_functionality::graph_modification_utils::{self, get_clip_mode};
2020
use crate::messages::tool::tool_messages::tool_prelude::{Key, MouseMotion};
2121
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
2222
use glam::{DAffine2, DVec2, IVec2};
23+
use graph_craft::document::value::TaggedValue;
2324
use graph_craft::document::{DocumentNodeImplementation, NodeId, NodeInput};
2425
use graph_craft::proto::GraphErrors;
2526
use graphene_std::math::math_ext::QuadExt;
@@ -119,6 +120,41 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
119120

120121
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![new_layer_id] });
121122
}
123+
NodeGraphMessage::AddPathNode => {
124+
let selected_nodes = network_interface.selected_nodes();
125+
let mut selected_layers = selected_nodes.selected_layers(network_interface.document_metadata());
126+
let selected_layer = selected_layers.next();
127+
let has_selection = selected_layer.is_some();
128+
let has_multiple_selection = selected_layers.next().is_some();
129+
130+
let compatible_type = selected_layer.and_then(|layer| {
131+
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, network_interface);
132+
let node_type = graph_layer.horizontal_layer_flow().nth(1);
133+
if let Some(node_id) = node_type {
134+
let (output_type, _) = network_interface.output_type(&node_id, 0, &[]);
135+
Some(format!("type:{}", output_type.nested_type()))
136+
} else {
137+
None
138+
}
139+
});
140+
141+
let compatible = compatible_type.unwrap_or("".to_string()) == "type:Instances<VectorData>";
142+
let single_layer_selected = has_selection && !has_multiple_selection;
143+
144+
if compatible && single_layer_selected {
145+
if let Some(layer) = selected_layer {
146+
let node_type = "Path".to_string();
147+
let graph_layer = graph_modification_utils::NodeGraphLayer::new(layer, &network_interface);
148+
let modifiable = matches!(graph_layer.find_input("Path", 1), Some(TaggedValue::VectorModification(_)));
149+
if !modifiable {
150+
responses.add(NodeGraphMessage::CreateNodeInLayerWithTransaction {
151+
node_type: node_type.clone(),
152+
layer: LayerNodeIdentifier::new_unchecked(layer.to_node()),
153+
});
154+
}
155+
}
156+
}
157+
}
122158
NodeGraphMessage::AddImport => {
123159
network_interface.add_import(graph_craft::document::value::TaggedValue::None, true, -1, "", "", breadcrumb_network_path);
124160
responses.add(NodeGraphMessage::SendGraph);

editor/src/messages/portfolio/menu_bar/menu_bar_message_handler.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ impl LayoutHolder for MenuBarMessageHandler {
260260
},
261261
],
262262
vec![
263+
MenuBarEntry {
264+
label: "Make Path Editable".into(),
265+
icon: Some("NodeShape".into()),
266+
shortcut: None,
267+
action: MenuBarEntry::create_action(|_| NodeGraphMessage::AddPathNode.into()),
268+
disabled: false,
269+
..MenuBarEntry::default()
270+
},
263271
MenuBarEntry {
264272
label: "Grab".into(),
265273
icon: Some("TransformationGrab".into()),

editor/src/messages/tool/tool_messages/path_tool.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ impl LayoutHolder for PathTool {
264264
.selected_index(Some(self.options.path_overlay_mode as u32))
265265
.widget_holder();
266266

267+
// Works only if a single layer is selected and its type is vectordata
268+
let path_node_button = TextButton::new("Make Path Editable")
269+
.icon(Some("NodeShape".into()))
270+
.tooltip("Make Path Editable")
271+
.on_update(|_| NodeGraphMessage::AddPathNode.into())
272+
.widget_holder();
273+
267274
let [_checkbox, _dropdown] = {
268275
let pivot_gizmo_type_widget = pivot_gizmo_type_widget(self.tool_data.pivot_gizmo.state, PivotToolSource::Path);
269276
[pivot_gizmo_type_widget[0].clone(), pivot_gizmo_type_widget[2].clone()]
@@ -294,6 +301,7 @@ impl LayoutHolder for PathTool {
294301
unrelated_seperator.clone(),
295302
path_overlay_mode_widget,
296303
unrelated_seperator.clone(),
304+
path_node_button,
297305
// checkbox.clone(),
298306
// related_seperator.clone(),
299307
// dropdown.clone(),

0 commit comments

Comments
 (0)