mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2024-11-22 17:11:05 +00:00
app: load/save node position
Able to load and save the node position in the XML file. Autosave/autoload the current graph in the settings folder.
This commit is contained in:
parent
e9b905230a
commit
1a8e893169
4 changed files with 60 additions and 20 deletions
4
TODO.md
4
TODO.md
|
@ -40,8 +40,8 @@
|
||||||
- [ ] Remove a pad from a node
|
- [ ] Remove a pad from a node
|
||||||
- [ ] Implement graphview unit test
|
- [ ] Implement graphview unit test
|
||||||
- [ ] Implement pipeline unit test
|
- [ ] Implement pipeline unit test
|
||||||
- [ ] Save node position in XML
|
- [x] Save node position in XML
|
||||||
- [ ] Autosave the graph
|
- [x] Autosave the graph
|
||||||
- [ ] Check the pîpeline live
|
- [ ] Check the pîpeline live
|
||||||
- [ ] Display pad properties with tooltip hover
|
- [ ] Display pad properties with tooltip hover
|
||||||
- [ ] Render a media file
|
- [ ] Render a media file
|
||||||
|
|
63
src/app.rs
63
src/app.rs
|
@ -38,7 +38,7 @@ use crate::logger;
|
||||||
use crate::pipeline::{Pipeline, PipelineState};
|
use crate::pipeline::{Pipeline, PipelineState};
|
||||||
use crate::plugindialogs;
|
use crate::plugindialogs;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use crate::{GPS_DEBUG, GPS_ERROR};
|
use crate::{GPS_DEBUG, GPS_ERROR, GPS_WARN};
|
||||||
|
|
||||||
use crate::graphmanager::{GraphView, Node, PortDirection};
|
use crate::graphmanager::{GraphView, Node, PortDirection};
|
||||||
|
|
||||||
|
@ -110,6 +110,7 @@ impl GPSApp {
|
||||||
plugin_list_initialized: OnceCell::new(),
|
plugin_list_initialized: OnceCell::new(),
|
||||||
menu_signal_handlers: RefCell::new(HashMap::new()),
|
menu_signal_handlers: RefCell::new(HashMap::new()),
|
||||||
}));
|
}));
|
||||||
|
app.graphview.borrow_mut().set_id(0);
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,6 +477,17 @@ impl GPSApp {
|
||||||
|
|
||||||
drawing_area_window.set_child(Some(&*self.graphview.borrow()));
|
drawing_area_window.set_child(Some(&*self.graphview.borrow()));
|
||||||
|
|
||||||
|
// Setup the logger to get messages into the TreeView
|
||||||
|
let (ready_tx, ready_rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||||
|
let app_weak = self.downgrade();
|
||||||
|
logger::init_logger(ready_tx, logger::LogLevel::Debug);
|
||||||
|
self.setup_logger_list();
|
||||||
|
let _ = ready_rx.attach(None, move |msg: String| {
|
||||||
|
let app = upgrade_weak!(app_weak, glib::Continue(false));
|
||||||
|
app.add_to_logger_list(msg);
|
||||||
|
glib::Continue(true)
|
||||||
|
});
|
||||||
|
|
||||||
let window = &self.window;
|
let window = &self.window;
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
|
@ -575,9 +587,29 @@ impl GPSApp {
|
||||||
self.connect_button_action("button-clear", move |_| {
|
self.connect_button_action("button-clear", move |_| {
|
||||||
let app = upgrade_weak!(app_weak);
|
let app = upgrade_weak!(app_weak);
|
||||||
app.clear_graph();
|
app.clear_graph();
|
||||||
//app.load_graph("graphs/compositor.xml").expect("Unable to open file");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let app_weak = self.downgrade();
|
||||||
|
self.graphview
|
||||||
|
.borrow()
|
||||||
|
.connect_local(
|
||||||
|
"graph-updated",
|
||||||
|
false,
|
||||||
|
glib::clone!(@weak application => @default-return None, move |values: &[Value]| {
|
||||||
|
let app = upgrade_weak!(app_weak, None);
|
||||||
|
let id = values[1].get::<u32>().expect("id in args[1]");
|
||||||
|
GPS_DEBUG!("Graph updated id={}", id);
|
||||||
|
let _ = app
|
||||||
|
.save_graph(
|
||||||
|
Settings::default_graph_file_path()
|
||||||
|
.to_str()
|
||||||
|
.expect("Unable to convert to string"),
|
||||||
|
)
|
||||||
|
.map_err(|e| GPS_WARN!("Unable to save file {}", e));
|
||||||
|
None
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.expect("Failed to register graph-updated signal of graphview");
|
||||||
// When user clicks on port with right button
|
// When user clicks on port with right button
|
||||||
let app_weak = self.downgrade();
|
let app_weak = self.downgrade();
|
||||||
self.graphview
|
self.graphview
|
||||||
|
@ -722,15 +754,14 @@ impl GPSApp {
|
||||||
// Setup the favorite list
|
// Setup the favorite list
|
||||||
self.setup_favorite_list(application);
|
self.setup_favorite_list(application);
|
||||||
|
|
||||||
// Setup the logger to get messages into the TreeView
|
let _ = self
|
||||||
let (ready_tx, ready_rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
.load_graph(
|
||||||
let app_weak = self.downgrade();
|
Settings::default_graph_file_path()
|
||||||
logger::init_logger(ready_tx, logger::LogLevel::Debug);
|
.to_str()
|
||||||
self.setup_logger_list();
|
.expect("Unable to convert to string"),
|
||||||
let _ = ready_rx.attach(None, move |msg: String| {
|
)
|
||||||
let app = upgrade_weak!(app_weak, glib::Continue(false));
|
.map_err(|_e| {
|
||||||
app.add_to_logger_list(msg);
|
GPS_WARN!("Unable to load default graph");
|
||||||
glib::Continue(true)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +774,7 @@ impl GPSApp {
|
||||||
fn drop(self) {}
|
fn drop(self) {}
|
||||||
|
|
||||||
pub fn add_new_element(&self, element_name: &str) {
|
pub fn add_new_element(&self, element_name: &str) {
|
||||||
let graph_view = self.graphview.borrow_mut();
|
let graph_view = self.graphview.borrow();
|
||||||
let node_id = graph_view.next_node_id();
|
let node_id = graph_view.next_node_id();
|
||||||
let pads = Pipeline::pads(element_name, false);
|
let pads = Pipeline::pads(element_name, false);
|
||||||
if Pipeline::element_is_uri_src_handler(element_name) {
|
if Pipeline::element_is_uri_src_handler(element_name) {
|
||||||
|
@ -752,7 +783,7 @@ impl GPSApp {
|
||||||
let node = app.graphview.borrow().node(&node_id).unwrap();
|
let node = app.graphview.borrow().node(&node_id).unwrap();
|
||||||
let mut properties: HashMap<String, String> = HashMap::new();
|
let mut properties: HashMap<String, String> = HashMap::new();
|
||||||
properties.insert(String::from("location"), filename);
|
properties.insert(String::from("location"), filename);
|
||||||
node.update_node_properties(&properties);
|
node.update_properties(&properties);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
graph_view.add_node_with_port(
|
graph_view.add_node_with_port(
|
||||||
|
@ -765,7 +796,7 @@ impl GPSApp {
|
||||||
|
|
||||||
pub fn update_element_properties(&self, node_id: u32, properties: &HashMap<String, String>) {
|
pub fn update_element_properties(&self, node_id: u32, properties: &HashMap<String, String>) {
|
||||||
let node = self.graphview.borrow().node(&node_id).unwrap();
|
let node = self.graphview.borrow().node(&node_id).unwrap();
|
||||||
node.update_node_properties(properties);
|
node.update_properties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_graph(&self) {
|
fn clear_graph(&self) {
|
||||||
|
@ -774,14 +805,14 @@ impl GPSApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_graph(&self, filename: &str) -> anyhow::Result<()> {
|
fn save_graph(&self, filename: &str) -> anyhow::Result<()> {
|
||||||
let graph_view = self.graphview.borrow_mut();
|
let graph_view = self.graphview.borrow();
|
||||||
graph_view.render_xml(filename)?;
|
graph_view.render_xml(filename)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_graph(&self, filename: &str) -> anyhow::Result<()> {
|
fn load_graph(&self, filename: &str) -> anyhow::Result<()> {
|
||||||
self.clear_graph();
|
self.clear_graph();
|
||||||
let graph_view = self.graphview.borrow_mut();
|
let graph_view = self.graphview.borrow();
|
||||||
graph_view.load_xml(filename)?;
|
graph_view.load_xml(filename)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,8 +396,10 @@ impl Pipeline {
|
||||||
description.push_str(&format!("{} name={} ", node.name(), unique_name));
|
description.push_str(&format!("{} name={} ", node.name(), unique_name));
|
||||||
elements.insert(unique_name.clone(), unique_name.clone());
|
elements.insert(unique_name.clone(), unique_name.clone());
|
||||||
for (name, value) in node.properties().iter() {
|
for (name, value) in node.properties().iter() {
|
||||||
|
if !node.hidden_property(name) {
|
||||||
description.push_str(&format!("{}={}", name, value));
|
description.push_str(&format!("{}={}", name, value));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let ports = node.all_ports(PortDirection::Output);
|
let ports = node.all_ports(PortDirection::Output);
|
||||||
let n_ports = ports.len();
|
let n_ports = ports.len();
|
||||||
|
|
|
@ -42,6 +42,13 @@ impl Settings {
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_graph_file_path() -> PathBuf {
|
||||||
|
let mut path = glib::user_config_dir();
|
||||||
|
path.push(config::APP_ID);
|
||||||
|
path.push("default_graph.toml");
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
// Public methods
|
// Public methods
|
||||||
pub fn add_favorite(favorite: &str) {
|
pub fn add_favorite(favorite: &str) {
|
||||||
let mut settings = Settings::load_settings();
|
let mut settings = Settings::load_settings();
|
||||||
|
|
Loading…
Reference in a new issue