Skip to content

Commit 812f768

Browse files
committed
insert passthrough
1 parent f11bd50 commit 812f768

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,30 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
203203
}
204204
NodeGraphMessage::CreateWire { output_connector, input_connector } => {
205205
// TODO: Add support for flattening NodeInput::Import exports in flatten_with_fns https://github.com/GraphiteEditor/Graphite/issues/1762
206-
if matches!(input_connector, InputConnector::Export(_)) && matches!(output_connector, OutputConnector::Import { .. }) {
207-
// We return early for now until this case becomes supported, then we can remove this
206+
if let (InputConnector::Export(_), OutputConnector::Import(_)) = (input_connector, output_connector) {
207+
let mid_point = (network_interface.get_output_center(&output_connector, breadcrumb_network_path).unwrap()
208+
+ network_interface.get_input_center(&input_connector, breadcrumb_network_path).unwrap())
209+
/ 2.;
210+
let node_template = Box::new(document_node_definitions::resolve_document_node_type("Passthrough").unwrap().default_node_template());
211+
212+
let node_id = NodeId::new();
213+
responses.add(NodeGraphMessage::InsertNode { node_id, node_template });
214+
responses.add(NodeGraphMessage::ShiftNodePosition {
215+
node_id,
216+
x: (mid_point.x / 24.) as i32,
217+
y: (mid_point.y / 24.) as i32,
218+
});
219+
let node_input_connector = InputConnector::node(node_id, 0);
220+
let node_output_connector = OutputConnector::node(node_id, 0);
221+
responses.add(NodeGraphMessage::CreateWire {
222+
output_connector,
223+
input_connector: node_input_connector,
224+
});
225+
responses.add(NodeGraphMessage::CreateWire {
226+
output_connector: node_output_connector,
227+
input_connector,
228+
});
229+
208230
return;
209231
}
210232
network_interface.create_wire(&output_connector, &input_connector, selection_network_path);
@@ -745,7 +767,6 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
745767
let clicked_input = network_interface.input_connector_from_click(click, selection_network_path);
746768
let clicked_output = network_interface.output_connector_from_click(click, selection_network_path);
747769
let network_metadata = network_interface.network_metadata(selection_network_path).unwrap();
748-
749770
// Create the add node popup on right click, then exit
750771
if right_click {
751772
// Abort dragging a node

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,15 +2750,23 @@ impl NodeNetworkInterface {
27502750
log::error!("Could not get nested network_metadata in collect_frontend_click_targets");
27512751
return FrontendClickTargets::default();
27522752
};
2753-
network_metadata.persistent_metadata.node_metadata.keys().copied().collect::<Vec<_>>().into_iter().for_each(|node_id| {
2754-
if let (Some(import_export_click_targets), Some(node_click_targets)) = (self.import_export_ports(network_path).cloned(), self.node_click_targets(&node_id, network_path)) {
2753+
let nodes = network_metadata.persistent_metadata.node_metadata.keys().copied().collect::<Vec<_>>();
2754+
if let Some(import_export_click_targets) = self.import_export_ports(network_path).cloned() {
2755+
for port in import_export_click_targets.click_targets() {
2756+
if let ClickTargetType::Subpath(subpath) = port.target_type() {
2757+
connector_click_targets.push(subpath.to_bezpath().to_svg());
2758+
}
2759+
}
2760+
}
2761+
nodes.into_iter().for_each(|node_id| {
2762+
if let Some(node_click_targets) = self.node_click_targets(&node_id, network_path) {
27552763
let mut node_path = String::new();
27562764

27572765
if let ClickTargetType::Subpath(subpath) = node_click_targets.node_click_target.target_type() {
27582766
node_path.push_str(subpath.to_bezpath().to_svg().as_str())
27592767
}
27602768
all_node_click_targets.push((node_id, node_path));
2761-
for port in node_click_targets.port_click_targets.click_targets().chain(import_export_click_targets.click_targets()) {
2769+
for port in node_click_targets.port_click_targets.click_targets() {
27622770
if let ClickTargetType::Subpath(subpath) = port.target_type() {
27632771
connector_click_targets.push(subpath.to_bezpath().to_svg());
27642772
}
@@ -2925,19 +2933,18 @@ impl NodeNetworkInterface {
29252933
.collect::<Vec<_>>()
29262934
.iter()
29272935
.filter_map(|node_id| {
2928-
self.node_click_targets(node_id, network_path)
2929-
.and_then(|transient_node_metadata| {
2930-
transient_node_metadata
2931-
.port_click_targets
2932-
.clicked_input_port_from_point(point)
2933-
.map(|port| InputConnector::node(*node_id, port))
2934-
})
2935-
.or_else(|| {
2936-
self.import_export_ports(network_path)
2937-
.and_then(|import_export_ports| import_export_ports.clicked_input_port_from_point(point).map(InputConnector::Export))
2938-
})
2936+
self.node_click_targets(node_id, network_path).and_then(|transient_node_metadata| {
2937+
transient_node_metadata
2938+
.port_click_targets
2939+
.clicked_input_port_from_point(point)
2940+
.map(|port| InputConnector::node(*node_id, port))
2941+
})
29392942
})
29402943
.next()
2944+
.or_else(|| {
2945+
self.import_export_ports(network_path)
2946+
.and_then(|import_export_ports| import_export_ports.clicked_input_port_from_point(point).map(InputConnector::Export))
2947+
})
29412948
}
29422949

29432950
pub fn output_connector_from_click(&mut self, click: DVec2, network_path: &[NodeId]) -> Option<OutputConnector> {
@@ -2955,19 +2962,18 @@ impl NodeNetworkInterface {
29552962
nodes
29562963
.iter()
29572964
.filter_map(|node_id| {
2958-
self.node_click_targets(node_id, network_path)
2959-
.and_then(|transient_node_metadata| {
2960-
transient_node_metadata
2961-
.port_click_targets
2962-
.clicked_output_port_from_point(point)
2963-
.map(|output_index| OutputConnector::node(*node_id, output_index))
2964-
})
2965-
.or_else(|| {
2966-
self.import_export_ports(network_path)
2967-
.and_then(|import_export_ports| import_export_ports.clicked_output_port_from_point(point).map(OutputConnector::Import))
2968-
})
2965+
self.node_click_targets(node_id, network_path).and_then(|transient_node_metadata| {
2966+
transient_node_metadata
2967+
.port_click_targets
2968+
.clicked_output_port_from_point(point)
2969+
.map(|output_index| OutputConnector::node(*node_id, output_index))
2970+
})
29692971
})
29702972
.next()
2973+
.or_else(|| {
2974+
self.import_export_ports(network_path)
2975+
.and_then(|import_export_ports| import_export_ports.clicked_output_port_from_point(point).map(OutputConnector::Import))
2976+
})
29712977
}
29722978

29732979
pub fn input_position(&mut self, input_connector: &InputConnector, network_path: &[NodeId]) -> Option<DVec2> {

0 commit comments

Comments
 (0)