Files
gpx.studio/tauri/src/commands/edit.rs
T

231 lines
5.9 KiB
Rust
Raw Normal View History

2026-10-14 08:51:38 +02:00
//! Editing the metadata, the style, the structure and the waypoints of the files, and the tools:
//! reversing, cropping, reducing, timestamps, merging, cleaning...
2026-10-17 22:17:17 +02:00
use gpx_engine::{CleanType, FileId, MergeType, Selection, SplitType, api};
2026-10-14 08:51:38 +02:00
use tauri::State;
use uuid::Uuid;
2026-10-14 09:22:07 +02:00
use crate::state::AppState;
2026-10-14 08:51:38 +02:00
2026-10-17 22:17:17 +02:00
/// 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.
2026-10-14 08:51:38 +02:00
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn metadata(state: State<AppState>, name: String, desc: String) -> api::Outcome {
2026-10-17 22:17:17 +02:00
state.core(move |core| {
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))
})
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
pub fn style(
state: State<AppState>,
color: Option<String>,
opacity: Option<f64>,
width: Option<f64>,
2026-10-14 09:22:07 +02:00
) -> api::Outcome {
state.run(move |e| api::style(e, color.as_deref(), opacity, width))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn new_track(state: State<AppState>) -> api::Outcome {
state.run(api::new_track)
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn new_track_segment(state: State<AppState>) -> api::Outcome {
state.run(api::new_track_segment)
2026-10-14 08:51:38 +02:00
}
// Waypoints
#[tauri::command(async)]
#[allow(clippy::too_many_arguments)]
pub fn new_waypoint(
state: State<AppState>,
lng: f64,
lat: f64,
ele: f64,
name: String,
desc: String,
icon: String,
link: String,
2026-10-14 09:22:07 +02:00
) -> api::Outcome {
state.run(move |e| api::new_waypoint(e, lng, lat, ele, &name, &desc, &icon, &link))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
pub fn move_waypoint(
state: State<AppState>,
file_id: Uuid,
waypoint_id: Uuid,
lng: f64,
lat: f64,
ele: f64,
2026-10-14 09:22:07 +02:00
) -> api::Outcome {
state.run(move |e| api::move_waypoint(e, file_id, waypoint_id, lng, lat, ele))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn delete_waypoint(state: State<AppState>, file_id: Uuid, waypoint_id: Uuid) -> api::Outcome {
state.run(move |e| api::delete_waypoint(e, file_id, waypoint_id))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
#[allow(clippy::too_many_arguments)]
pub fn update_waypoint(
state: State<AppState>,
file_id: Uuid,
waypoint_id: Uuid,
lng: f64,
lat: f64,
ele: f64,
name: String,
desc: String,
icon: String,
link: String,
2026-10-14 09:22:07 +02:00
) -> api::Outcome {
state.run(move |e| {
api::update_waypoint(
e,
file_id,
waypoint_id,
2026-10-14 08:51:38 +02:00
lng,
lat,
ele,
2026-10-14 09:22:07 +02:00
&name,
&desc,
&icon,
&link,
)
})
2026-10-14 08:51:38 +02:00
}
// Tools
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn reverse(state: State<AppState>) -> api::Outcome {
state.run(api::reverse)
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn round_trip(state: State<AppState>) -> api::Outcome {
state.run(api::round_trip)
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn crop(state: State<AppState>, start: u32, end: u32) -> api::Outcome {
state.run(move |e| api::crop(e, start, end))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn reduce(state: State<AppState>, tolerance: f64) -> api::Outcome {
state.run(move |e| api::reduce(e, tolerance))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
pub fn change_timestamps(
state: State<AppState>,
start_time: f64,
speed: f64,
ratio: f64,
2026-10-14 09:22:07 +02:00
) -> api::Outcome {
state.run(move |e| api::change_timestamps(e, start_time, speed, ratio))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
pub fn create_artificial_timestamps(
state: State<AppState>,
start_time: f64,
total_time: f64,
2026-10-14 09:22:07 +02:00
) -> api::Outcome {
state.run(move |e| api::create_artificial_timestamps(e, start_time, total_time))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn merge(state: State<AppState>, merge_type: MergeType, remove_gaps: bool) -> api::Outcome {
2026-10-16 18:14:59 +02:00
state.core(move |core| core.creating(None, false, |e| api::merge(e, merge_type, remove_gaps)))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn extract(state: State<AppState>) -> api::Outcome {
2026-10-16 18:14:59 +02:00
state.core(|core| core.creating(None, false, api::extract))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
2026-10-14 09:22:07 +02:00
pub fn elevation(state: State<AppState>, ele: Vec<f64>) -> api::Outcome {
state.run(move |e| api::elevation(e, &ele))
2026-10-14 08:51:38 +02:00
}
#[tauri::command(async)]
#[allow(clippy::too_many_arguments)]
pub fn clean(
state: State<AppState>,
west: f64,
south: f64,
east: f64,
north: f64,
clean_type: CleanType,
trkpt: bool,
wpt: bool,
2026-10-14 09:22:07 +02:00
) -> 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<AppState>,
revision: u32,
start: u32,
end: u32,
lng: Vec<f64>,
lat: Vec<f64>,
ele: Vec<f64>,
attributes: api::RouteAttributes,
anchors: Vec<u32>,
) -> 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<AppState>, 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<AppState>, 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<AppState>,
revision: u32,
at: u32,
split_type: SplitType,
) -> api::Outcome {
2026-10-16 18:14:59 +02:00
state.core(move |core| core.creating(None, false, |e| api::split(e, revision, at, split_type)))
2026-10-14 08:51:38 +02:00
}