1use crate::{GizmoMode, GizmoSpace, Mat4, with_context, with_context_mut};
2
3pub fn select_structure(type_name: &str, name: &str) {
8 with_context_mut(|ctx| {
9 ctx.select_structure(type_name, name);
10 });
11}
12
13pub fn deselect_structure() {
15 with_context_mut(|ctx| {
16 ctx.deselect_structure();
17 });
18}
19
20#[must_use]
22pub fn get_selected_structure() -> Option<(String, String)> {
23 with_context(|ctx| {
24 ctx.selected_structure()
25 .map(|(t, n)| (t.to_string(), n.to_string()))
26 })
27}
28
29#[must_use]
31pub fn has_selection() -> bool {
32 with_context(polyscope_core::Context::has_selection)
33}
34
35pub fn set_gizmo_mode(mode: GizmoMode) {
37 with_context_mut(|ctx| {
38 ctx.gizmo_mut().mode = mode;
39 });
40}
41
42#[must_use]
44pub fn get_gizmo_mode() -> GizmoMode {
45 with_context(|ctx| ctx.gizmo().mode)
46}
47
48pub fn set_gizmo_space(space: GizmoSpace) {
50 with_context_mut(|ctx| {
51 ctx.gizmo_mut().space = space;
52 });
53}
54
55#[must_use]
57pub fn get_gizmo_space() -> GizmoSpace {
58 with_context(|ctx| ctx.gizmo().space)
59}
60
61pub fn set_gizmo_visible(visible: bool) {
63 with_context_mut(|ctx| {
64 ctx.gizmo_mut().visible = visible;
65 });
66}
67
68#[must_use]
70pub fn is_gizmo_visible() -> bool {
71 with_context(|ctx| ctx.gizmo().visible)
72}
73
74pub fn set_gizmo_snap_translate(snap: f32) {
78 with_context_mut(|ctx| {
79 ctx.gizmo_mut().snap_translate = snap;
80 });
81}
82
83pub fn set_gizmo_snap_rotate(snap_degrees: f32) {
87 with_context_mut(|ctx| {
88 ctx.gizmo_mut().snap_rotate = snap_degrees;
89 });
90}
91
92pub fn set_gizmo_snap_scale(snap: f32) {
96 with_context_mut(|ctx| {
97 ctx.gizmo_mut().snap_scale = snap;
98 });
99}
100
101pub fn set_selected_transform(transform: Mat4) {
105 with_context_mut(|ctx| {
106 if let Some((type_name, name)) = ctx.selected_structure.clone() {
107 if let Some(structure) = ctx.registry.get_mut(&type_name, &name) {
108 structure.set_transform(transform);
109 }
110 }
111 });
112}
113
114#[must_use]
118pub fn get_selected_transform() -> Mat4 {
119 with_context(|ctx| {
120 if let Some((type_name, name)) = ctx.selected_structure() {
121 ctx.registry
122 .get(type_name, name)
123 .map_or(Mat4::IDENTITY, polyscope_core::Structure::transform)
124 } else {
125 Mat4::IDENTITY
126 }
127 })
128}
129
130pub fn reset_selected_transform() {
134 set_selected_transform(Mat4::IDENTITY);
135}