diff --git a/pane_layout.json b/pane_layout.json index 266bdc7..8fb7227 100644 --- a/pane_layout.json +++ b/pane_layout.json @@ -1,24 +1,10 @@ [ - { - "pane": { - "type": "BluePane" - }, - "id": "BLUE", - "mode": "Left" - }, - { - "pane": { - "type": "GreenPane" - }, - "id": "Green", - "mode": "Bottom" - }, { "pane": { "type": "PointRendererPane" }, "id": "Point Cloud", - "mode": "Center" + "mode": "Hidden" }, { "pane": { @@ -27,21 +13,55 @@ "nodes": { "0": { "value": { - "type": "Node1" + "type": "Node2" }, "pos": { - "x": -56.0, - "y": -52.5 + "x": -282.38733, + "y": -103.8249 }, "open": true }, "1": { + "value": { + "type": "Node3" + }, + "pos": { + "x": 101.502266, + "y": -93.96767 + }, + "open": true + }, + "2": { "value": { "type": "Node1" }, "pos": { - "x": -61.21814, - "y": 155.28181 + "x": -70.495674, + "y": -69.65721 + }, + "open": true + }, + "3": { + "value": { + "type": "Constants", + "vars": [], + "popup_open": false + }, + "pos": { + "x": -523.0798, + "y": -137.1891 + }, + "open": true + }, + "4": { + "value": { + "type": "Constants", + "vars": [], + "popup_open": false + }, + "pos": { + "x": -525.76666, + "y": -80.20156 }, "open": true } @@ -49,7 +69,27 @@ "wires": [ { "out_pin": { + "node": 2, + "output": 0 + }, + "in_pin": { "node": 1, + "input": 0 + } + }, + { + "out_pin": { + "node": 4, + "output": 0 + }, + "in_pin": { + "node": 0, + "input": 1 + } + }, + { + "out_pin": { + "node": 3, "output": 0 }, "in_pin": { @@ -63,7 +103,7 @@ "output": 0 }, "in_pin": { - "node": 1, + "node": 2, "input": 0 } } @@ -72,9 +112,9 @@ "style": { "select_rect_contained": null }, - "snarl_ui_id": 12028535709621507733 + "snarl_ui_id": 968669704945789632 }, "id": "Pipeline Pane", - "mode": "Right" + "mode": "Center" } ] \ No newline at end of file diff --git a/src/nodes/constants.rs b/src/nodes/constants.rs index e69de29..1ad2b0c 100644 --- a/src/nodes/constants.rs +++ b/src/nodes/constants.rs @@ -0,0 +1,85 @@ +use eframe::epaint::Color32; +use egui::Ui; +use egui_snarl::{InPin, OutPin}; +use egui_snarl::ui::{PinInfo, WireStyle}; +use crate::pane_manager::{Pane, PaneMode, PaneState, PsudoCreationContext}; +use crate::panes::pipeline_editor::Node; + + +#[derive(Clone, serde::Serialize, serde::Deserialize)] +pub struct Constants { + vars: Vec, + popup_open: bool, +} +#[typetag::serde] +impl Node for Constants { + fn new() -> Self { + Self { + vars: Vec::new(), + popup_open: false, + } + } + + fn get_name(&self) -> &str { + "Constants" + } + fn get_description(&self) -> &str {"Test Node"} + + fn duplicate(&self) -> Box { + Box::new(Self::new()) + } + + fn inputs(&self) -> usize { + 0 + } + fn outputs(&self) -> usize { + 1 + } + fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { + PinInfo::square() + } + fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { + PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) + } + fn can_rx(&self, _other: &Box) -> bool { + true + } + fn can_tx(&self, _other: &Box) -> bool { + true + } + fn context_menu(&self, ui: &mut Ui) { + egui::Window::new("TEST").show(ui.ctx(), |ui| { + ui.heading("EEEEE"); + }); + // if ui.button("Edit").clicked() { + // self.popup_open = !self.popup_open; + // } + } + fn update(&self, ui: &mut Ui) { + + } +} + +// #[derive(serde::Serialize, serde::Deserialize, Clone)] +// pub struct Constant_Edit_Popup { +// pub data: Vec, +// pub has_changed: bool, +// } +// #[typetag::serde] +// impl Pane for Constant_Edit_Popup { +// fn new() -> PaneState where Self: Sized { +// let mut s = Self { +// node: None, +// has_changed: false, +// }; +// PaneState { +// id: s.name().to_string(), +// mode: PaneMode::Popup, +// pane: Box::new(s), +// } +// } +// fn init(&mut self, _pcc: &PsudoCreationContext) {} +// fn name(&mut self) -> &str {"ERROR"} +// fn render(&mut self, _ui: &mut Ui){} +// fn context_menu(&mut self, _ui: &mut Ui) {} +// } diff --git a/src/pane_manager.rs b/src/pane_manager.rs index d140c71..231e507 100644 --- a/src/pane_manager.rs +++ b/src/pane_manager.rs @@ -12,6 +12,7 @@ pub enum PaneMode { Left, Bottom, Center, + Popup, } #[typetag::serde(tag = "type")] @@ -62,20 +63,6 @@ impl PaneState { } -// impl Default for dyn Pane { -// fn default() -> (impl Pane + 'static) { -// Box::new(NoPane {}) -// } -// } - -// pub struct PaneGroup { -// pub direction: TileDirection, -// pub panes: Vec, -// } - -// #[derive(serde::Deserialize, serde::Serialize)] -// #[derive(serde::Deserialize, serde::Serialize)] - pub struct PsudoCreationContext { pub gl: Option>, } @@ -130,7 +117,11 @@ impl PaneManager { ui.menu_button("View", |ui| { for i in 0..len { + if self.panes[i].mode == PaneMode::Popup { + continue; + } ui.menu_button(self.panes[i].id.clone(), |ui| { + if ui.button("Center").clicked() { for a in 0..len { let pane2: &mut PaneState = &mut self.panes[a]; @@ -168,7 +159,7 @@ impl PaneManager { ui.separator(); for i in 0..len { - if self.panes[i].mode != PaneMode::Hidden { + if self.panes[i].mode != PaneMode::Hidden && self.panes[i].mode != PaneMode::Popup { ui.menu_button(self.panes[i].id.clone(), |ui| { let _ = &mut self.panes[i].pane.context_menu(ui); }); @@ -203,7 +194,7 @@ impl PaneManager { pane.render(ui); }); }, - PaneMode::Windowed => { + PaneMode::Windowed | PaneMode::Popup => { egui::Window::new(pane.id.clone()) .resizable(true) .max_width(ui.clip_rect().width()).max_height(ui.clip_rect().height()) diff --git a/src/panes/pipeline_editor.rs b/src/panes/pipeline_editor.rs index 440647e..7578e00 100644 --- a/src/panes/pipeline_editor.rs +++ b/src/panes/pipeline_editor.rs @@ -2,11 +2,8 @@ use crate::pane_manager::{Pane, PaneMode, PaneState, PsudoCreationContext}; use egui::{Color32, Id, Pos2, Ui}; -use egui_snarl::{ - ui::{PinInfo, SnarlStyle, SnarlViewer}, - InPin, NodeId, OutPin, Snarl, -}; -use egui_snarl::ui::{PinShape, WireStyle}; +use egui_snarl::{ui::{PinInfo, SnarlStyle, SnarlViewer}, InPin, InPinId, NodeId, OutPin, OutPinId, Snarl}; +use egui_snarl::ui::{WireStyle}; #[derive(serde::Serialize, serde::Deserialize)] pub struct PipelinePane { @@ -64,8 +61,75 @@ impl Pane for PipelinePane { } impl PipelinePane { - pub fn run(&mut self) { - // Todo: + fn run(&mut self) { + if let Some(snarl) = &mut self.snarl { + fn remove_duplicates(nodes: Vec) -> Vec { + let mut new_vec : Vec = Vec::new(); + for node in nodes { + if !new_vec.contains(&node){ + new_vec.push(node); + } + } + new_vec + } + fn has_input_wire(snarl: &Snarl>, nodeid: NodeId) -> bool { + for wire in snarl.wires() { + if wire.1.node == nodeid { + return true; + } + } + false + } + fn get_output_wires(snarl: &Snarl>, nodeid: &NodeId) -> Vec { + let mut arr: Vec = Vec::new(); + for wire in snarl.wires() { + if &wire.0.node == nodeid { + arr.push(wire.0) + } + } + arr + } + + // let wires = snarl.wires().map(|| {}) + + let mut nodes: Vec> = Vec::new(); + let mut starting_nodes: Vec = Vec::new(); + for node in snarl.nodes_ids_data() { + if !has_input_wire(snarl, node.0) { + starting_nodes.push(node.0.clone()) + } + } + starting_nodes = remove_duplicates(starting_nodes); + nodes.push(starting_nodes); + + + for i in 1..50 { + if nodes.get(i-1).is_none() {break} + let mut prevarr = nodes.get(i-1).unwrap(); + if prevarr.len() == 0 {break} + + let mut newarr: Vec = Vec::new(); + + for node in prevarr { + for wire in get_output_wires(snarl, node) { + newarr.push(wire.node); + } + } + + newarr = remove_duplicates(newarr); + + nodes.push(newarr); + } + + for nodearr in nodes { + println!("Nodes: "); + for node in nodearr { + println!("{}", snarl.get_node(node).unwrap().get_name()); + } + } + + + } } } @@ -75,7 +139,7 @@ fn format_float(v: f64) -> String { } #[typetag::serde(tag = "type")] -trait Node { +pub trait Node { fn new() -> Self where Self: Sized; @@ -89,6 +153,7 @@ trait Node { fn can_rx(&self, other: &Box) -> bool; fn can_tx(&self, other: &Box) -> bool; fn context_menu(&self, ui: &mut Ui); + fn update(&self, ui: &mut Ui); } #[derive(Clone, serde::Serialize, serde::Deserialize)] @@ -98,39 +163,84 @@ impl Node for Node1 { fn new() -> Self { Self } - - fn get_name(&self) -> &str { - "Test" - } + fn get_name(&self) -> &str { "Test" } fn get_description(&self) -> &str {"Test Node"} - - fn duplicate(&self) -> Box { - Box::new(Self::new()) - } - + fn duplicate(&self) -> Box { Box::new(Self::new()) } fn inputs(&self) -> usize { 1 } fn outputs(&self) -> usize { 1 } - fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { - PinInfo::square() - } - fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { - PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) - } + fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() } + fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) } fn can_rx(&self, _other: &Box) -> bool { true } fn can_tx(&self, _other: &Box) -> bool { true } - fn context_menu(&self, ui: &mut Ui) { - ui.label("Test!"); - } + fn context_menu(&self, ui: &mut Ui) { ui.label("Test!"); } + fn update(&self, ui: &mut Ui) {} } +#[derive(Clone, serde::Serialize, serde::Deserialize)] +struct Node2; +#[typetag::serde] +impl Node for Node2 { + fn new() -> Self { + Self + } + fn get_name(&self) -> &str { "Test 2-1" } + fn get_description(&self) -> &str {"Test Node"} + fn duplicate(&self) -> Box { Box::new(Self::new()) } + fn inputs(&self) -> usize { + 2 + } + fn outputs(&self) -> usize { + 1 + } + fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() } + fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) } + fn can_rx(&self, _other: &Box) -> bool { + true + } + fn can_tx(&self, _other: &Box) -> bool { + true + } + fn context_menu(&self, ui: &mut Ui) { ui.label("Test!"); } + fn update(&self, ui: &mut Ui) {} +} + +#[derive(Clone, serde::Serialize, serde::Deserialize)] +struct Node3; +#[typetag::serde] +impl Node for crate::panes::pipeline_editor::Node3 { + fn new() -> Self { + Self + } + fn get_name(&self) -> &str { "Test 1-2" } + fn get_description(&self) -> &str {"Test Node"} + fn duplicate(&self) -> Box { Box::new(Self::new()) } + fn inputs(&self) -> usize { + 1 + } + fn outputs(&self) -> usize { + 2 + } + fn show_input(&self, _pin: &InPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square() } + fn show_output(&self, _pin: &OutPin, _ui: &mut Ui, _scale: f32) -> PinInfo { PinInfo::square().with_fill(Color32::RED).with_wire_style(WireStyle::Bezier3) } + fn can_rx(&self, _other: &Box) -> bool { + true + } + fn can_tx(&self, _other: &Box) -> bool { + true + } + fn context_menu(&self, ui: &mut Ui) { ui.label("Test!"); } + fn update(&self, ui: &mut Ui) {} +} + + #[derive(Clone, serde::Serialize, serde::Deserialize)] struct NodeViewer; @@ -150,6 +260,12 @@ impl SnarlViewer> for NodeViewer { } } + fn disconnect(&mut self, from: &OutPin, to: &InPin, snarl: &mut Snarl>) { + for &remote in &to.remotes { + snarl.disconnect(remote, to.id); + } + } + fn title(&mut self, node: &Box) -> String { node.get_name().to_string() } @@ -239,19 +355,39 @@ impl SnarlViewer> for NodeViewer { } else if ui.button("Duplicate").clicked() { snarl.insert_node(Pos2 {x:0.,y:0.}, snarl.get_node(nodeid).unwrap().duplicate()); ui.close_menu(); + // }// else if ui.button("Remove All Connections").clicked() { + // ui. + // ui.close_menu(); } else { snarl.get_node(nodeid).unwrap().context_menu(ui); } } + + fn show_body(&mut self, node: NodeId, inputs: &[InPin], outputs: &[OutPin], ui: &mut Ui, scale: f32, snarl: &mut Snarl>) { + snarl.get_node(node).unwrap().update(ui); + } } impl NodeViewer { pub fn add_node_menu(pos: Pos2, ui: &mut Ui, snarl: &mut Snarl>) { ui.label("Add node"); - let button = ui.button("Test1"); - if button.clicked() { + + + if ui.button("Test").clicked() { snarl.insert_node(pos, Box::new(Node1::new())); ui.close_menu(); + } else if ui.button("Constants").clicked() { + snarl.insert_node(pos, Box::new(crate::nodes::constants::Constants::new())); + ui.close_menu(); + } else if ui.button("Test 2-1").clicked() { + snarl.insert_node(pos, Box::new(Node2::new())); + ui.close_menu(); + } else if ui.button("Test 1-2").clicked() { + snarl.insert_node(pos, Box::new(Node3::new())); + ui.close_menu(); } + + + } } \ No newline at end of file