use crate::{GizmoMode, GizmoSpace, Mat4, with_context, with_context_mut};
pub fn select_structure(type_name: &str, name: &str) {
with_context_mut(|ctx| {
ctx.select_structure(type_name, name);
});
}
pub fn deselect_structure() {
with_context_mut(|ctx| {
ctx.deselect_structure();
});
}
#[must_use]
pub fn get_selected_structure() -> Option<(String, String)> {
with_context(|ctx| {
ctx.selected_structure()
.map(|(t, n)| (t.to_string(), n.to_string()))
})
}
#[must_use]
pub fn has_selection() -> bool {
with_context(polyscope_core::Context::has_selection)
}
pub fn set_gizmo_mode(mode: GizmoMode) {
with_context_mut(|ctx| {
ctx.gizmo_mut().mode = mode;
});
}
#[must_use]
pub fn get_gizmo_mode() -> GizmoMode {
with_context(|ctx| ctx.gizmo().mode)
}
pub fn set_gizmo_space(space: GizmoSpace) {
with_context_mut(|ctx| {
ctx.gizmo_mut().space = space;
});
}
#[must_use]
pub fn get_gizmo_space() -> GizmoSpace {
with_context(|ctx| ctx.gizmo().space)
}
pub fn set_gizmo_visible(visible: bool) {
with_context_mut(|ctx| {
ctx.gizmo_mut().visible = visible;
});
}
#[must_use]
pub fn is_gizmo_visible() -> bool {
with_context(|ctx| ctx.gizmo().visible)
}
pub fn set_gizmo_snap_translate(snap: f32) {
with_context_mut(|ctx| {
ctx.gizmo_mut().snap_translate = snap;
});
}
pub fn set_gizmo_snap_rotate(snap_degrees: f32) {
with_context_mut(|ctx| {
ctx.gizmo_mut().snap_rotate = snap_degrees;
});
}
pub fn set_gizmo_snap_scale(snap: f32) {
with_context_mut(|ctx| {
ctx.gizmo_mut().snap_scale = snap;
});
}
pub fn set_selected_transform(transform: Mat4) {
with_context_mut(|ctx| {
if let Some((type_name, name)) = ctx.selected_structure.clone() {
if let Some(structure) = ctx.registry.get_mut(&type_name, &name) {
structure.set_transform(transform);
}
}
});
}
#[must_use]
pub fn get_selected_transform() -> Mat4 {
with_context(|ctx| {
if let Some((type_name, name)) = ctx.selected_structure() {
ctx.registry
.get(type_name, name)
.map_or(Mat4::IDENTITY, polyscope_core::Structure::transform)
} else {
Mat4::IDENTITY
}
})
}
pub fn reset_selected_transform() {
set_selected_transform(Mat4::IDENTITY);
}