rustapi/actions/
iso_camera.rs1use rusterix::D3Camera;
2
3use crate::editor::EDITCAMERA;
4use crate::prelude::*;
5
6pub struct IsoCamera {
7 id: TheId,
8 nodeui: TheNodeUI,
9}
10
11impl Action for IsoCamera {
12 fn new() -> Self
13 where
14 Self: Sized,
15 {
16 let mut nodeui: TheNodeUI = TheNodeUI::default();
17
18 let item = TheNodeUIItem::FloatEditSlider(
19 "actionIsoAzimuth".into(),
20 "".into(),
21 "".into(),
22 135.0,
23 0.0..=360.0,
24 true,
25 );
26 nodeui.add_item(item);
27
28 let item = TheNodeUIItem::FloatEditSlider(
29 "actionIsoElevation".into(),
30 "".into(),
31 "".into(),
32 35.264,
33 0.0..=90.0,
34 true,
35 );
36 nodeui.add_item(item);
37
38 let item = TheNodeUIItem::FloatEditSlider(
39 "actionIsoScale".into(),
40 "".into(),
41 "".into(),
42 4.0,
43 2.0..=70.0,
44 true,
45 );
46 nodeui.add_item(item);
47
48 Self {
49 id: TheId::named(&fl!("action_iso_camera")),
50 nodeui,
51 }
52 }
53
54 fn id(&self) -> TheId {
55 self.id.clone()
56 }
57
58 fn info(&self) -> String {
59 fl!("action_iso_camera_desc")
60 }
61
62 fn role(&self) -> ActionRole {
63 ActionRole::Camera
64 }
65
66 fn accel(&self) -> Option<TheAccelerator> {
67 Some(TheAccelerator::new(TheAcceleratorKey::CTRLCMD, '4'))
68 }
69
70 fn is_applicable(&self, _map: &Map, _ctx: &mut TheContext, server_ctx: &ServerContext) -> bool {
71 server_ctx.get_map_context() == MapContext::Region
73 }
74
75 fn apply(
76 &self,
77 _map: &mut Map,
78 ui: &mut TheUI,
79 ctx: &mut TheContext,
80 server_ctx: &mut ServerContext,
81 ) -> Option<ProjectUndoAtom> {
82 let azimuth = self.nodeui.get_f32_value("actionIsoAzimuth").unwrap_or(0.0);
83
84 let elevation = self
85 .nodeui
86 .get_f32_value("actionIsoElevation")
87 .unwrap_or(0.0);
88
89 let scale = self.nodeui.get_f32_value("actionIsoScale").unwrap_or(4.0);
90
91 EDITCAMERA
92 .write()
93 .unwrap()
94 .iso_camera
95 .set_parameter_f32("azimuth_deg", azimuth);
96
97 EDITCAMERA
98 .write()
99 .unwrap()
100 .iso_camera
101 .set_parameter_f32("elevation_deg", elevation);
102
103 EDITCAMERA
104 .write()
105 .unwrap()
106 .iso_camera
107 .set_parameter_f32("scale", scale);
108
109 server_ctx.editing_surface = None;
110 ui.set_widget_value("Editor View Switch", ctx, TheValue::Int(2));
111 ctx.ui.send(TheEvent::IndexChanged(
112 TheId::named("Editor View Switch"),
113 2,
114 ));
115
116 None
117 }
118
119 fn apply_project(
120 &self,
121 project: &mut Project,
122 _ui: &mut TheUI,
123 _ctx: &mut TheContext,
124 server_ctx: &mut ServerContext,
125 ) {
126 crate::editor::TOOLLIST
127 .write()
128 .unwrap()
129 .update_geometry_overlay_3d(project, server_ctx);
130 }
131
132 fn params(&self) -> TheNodeUI {
133 self.nodeui.clone()
134 }
135
136 fn handle_event(
137 &mut self,
138 event: &TheEvent,
139 _project: &mut Project,
140 _ui: &mut TheUI,
141 _ctx: &mut TheContext,
142 _server_ctx: &mut ServerContext,
143 ) -> bool {
144 self.nodeui.handle_event(event)
145 }
146}