//! Editing the metadata, the style, the structure and the waypoints of the files, and the tools: //! reversing, cropping, reducing, timestamps, merging, cleaning... use gpx_engine::{CleanType, FileId, MergeType, Selection, SplitType, api}; use tauri::State; use uuid::Uuid; use crate::state::{AppState, Core}; /// Names and describes the selected files or tracks. A file on the disk is renamed with it (and back /// when it is undone): its name is one that a file can have, and not the one of another file. #[tauri::command(async)] pub fn metadata(state: State, name: String, desc: String) -> api::Outcome { state.core(move |core| rename_selection(core, name, desc)) } /// See `metadata`. pub fn rename_selection(core: &mut Core, name: String, desc: String) -> api::Outcome { let mut name = name; if let Selection::File { file_ids } = core.engine.selection() { for FileId(id) in file_ids.clone() { name = core.workspace.valid_name(id, &name); if let Err(error) = core.workspace.renamed_path(id, &name) { return api::Outcome::failed(error); } } } core.edit(move |e| api::metadata(e, &name, &desc)) } #[tauri::command(async)] pub fn style( state: State, color: Option, opacity: Option, width: Option, ) -> api::Outcome { state.run(move |e| api::style(e, color.as_deref(), opacity, width)) } #[tauri::command(async)] pub fn new_track(state: State) -> api::Outcome { state.run(api::new_track) } #[tauri::command(async)] pub fn new_track_segment(state: State) -> api::Outcome { state.run(api::new_track_segment) } // Waypoints #[tauri::command(async)] #[allow(clippy::too_many_arguments)] pub fn new_waypoint( state: State, lng: f64, lat: f64, ele: f64, name: String, desc: String, icon: String, link: String, ) -> api::Outcome { state.run(move |e| api::new_waypoint(e, lng, lat, ele, &name, &desc, &icon, &link)) } #[tauri::command(async)] pub fn move_waypoint( state: State, file_id: Uuid, waypoint_id: Uuid, lng: f64, lat: f64, ele: f64, ) -> api::Outcome { state.run(move |e| api::move_waypoint(e, file_id, waypoint_id, lng, lat, ele)) } #[tauri::command(async)] pub fn delete_waypoint(state: State, file_id: Uuid, waypoint_id: Uuid) -> api::Outcome { state.run(move |e| api::delete_waypoint(e, file_id, waypoint_id)) } #[tauri::command(async)] #[allow(clippy::too_many_arguments)] pub fn update_waypoint( state: State, file_id: Uuid, waypoint_id: Uuid, lng: f64, lat: f64, ele: f64, name: String, desc: String, icon: String, link: String, ) -> api::Outcome { state.run(move |e| { api::update_waypoint( e, file_id, waypoint_id, lng, lat, ele, &name, &desc, &icon, &link, ) }) } // Tools #[tauri::command(async)] pub fn reverse(state: State) -> api::Outcome { state.run(api::reverse) } #[tauri::command(async)] pub fn round_trip(state: State) -> api::Outcome { state.run(api::round_trip) } #[tauri::command(async)] pub fn crop(state: State, start: u32, end: u32) -> api::Outcome { state.run(move |e| api::crop(e, start, end)) } #[tauri::command(async)] pub fn reduce(state: State, tolerance: f64) -> api::Outcome { state.run(move |e| api::reduce(e, tolerance)) } #[tauri::command(async)] pub fn change_timestamps( state: State, start_time: f64, speed: f64, ratio: f64, ) -> api::Outcome { state.run(move |e| api::change_timestamps(e, start_time, speed, ratio)) } #[tauri::command(async)] pub fn create_artificial_timestamps( state: State, start_time: f64, total_time: f64, ) -> api::Outcome { state.run(move |e| api::create_artificial_timestamps(e, start_time, total_time)) } #[tauri::command(async)] pub fn merge(state: State, merge_type: MergeType, remove_gaps: bool) -> api::Outcome { state.core(move |core| core.creating(None, false, |e| api::merge(e, merge_type, remove_gaps))) } #[tauri::command(async)] pub fn extract(state: State) -> api::Outcome { state.core(|core| core.creating(None, false, api::extract)) } #[tauri::command(async)] pub fn elevation(state: State, ele: Vec) -> api::Outcome { state.run(move |e| api::elevation(e, &ele)) } #[tauri::command(async)] #[allow(clippy::too_many_arguments)] pub fn clean( state: State, west: f64, south: f64, east: f64, north: f64, clean_type: CleanType, trkpt: bool, wpt: bool, ) -> api::Outcome { state.run(move |e| api::clean(e, west, south, east, north, clean_type, trkpt, wpt)) } // Routing #[tauri::command(async)] #[allow(clippy::too_many_arguments)] pub fn route( state: State, revision: u32, start: u32, end: u32, lng: Vec, lat: Vec, ele: Vec, attributes: api::RouteAttributes, anchors: Vec, ) -> api::Outcome { state.run(move |e| { api::route( e, revision, start, end, &lng, &lat, &ele, &attributes, &anchors, ) }) } #[tauri::command(async)] pub fn insert_anchor(state: State, revision: u32, lng: f64, lat: f64) -> api::Outcome { state.run(move |e| api::insert_anchor(e, revision, lng, lat)) } #[tauri::command(async)] pub fn change_loop_start(state: State, revision: u32, index: u32) -> api::Outcome { state.run(move |e| api::change_loop_start(e, revision, index)) } #[tauri::command(async)] pub fn split( state: State, revision: u32, at: u32, split_type: SplitType, ) -> api::Outcome { state.core(move |core| core.creating(None, false, |e| api::split(e, revision, at, split_type))) }