1use crate::document::{Document, Property};
4use std::collections::HashMap;
5
6#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
7pub enum FrameRate {
8 #[default]
9 Default,
10 Fps120,
11 Fps100,
12 Fps60,
13 Fps50,
14 Fps48,
15 Fps30,
16 Fps30Drop,
17 NtsDropFrame,
18 NtsFullFrame,
19 Pal,
20 Cinema,
21 Fps1000,
22 CinemaNd,
23 Custom,
24 Max,
25}
26
27#[derive(Debug)]
28pub struct GlobalSettings<'a> {
29 document: &'a Document,
30 global_settings: &'a HashMap<String, Property>,
31}
32
33impl<'a> GlobalSettings<'a> {
34 pub fn new(document: &'a Document, global_settings: &'a HashMap<String, Property>) -> Self {
35 Self {
36 document,
37 global_settings,
38 }
39 }
40
41 pub fn document(&self) -> &'a Document {
42 self.document
43 }
44
45 pub fn global_settings(&self) -> &'a HashMap<String, Property> {
46 self.global_settings
47 }
48
49 pub fn up_axis(&self) -> i32 {
50 self.global_settings
51 .get("UpAxis")
52 .and_then(|prop| match prop {
53 Property::Int(i) => Some(*i),
54 _ => None,
55 })
56 .unwrap_or(1)
57 }
58
59 pub fn up_axis_sign(&self) -> i32 {
60 self.global_settings
61 .get("UpAxisSign")
62 .and_then(|prop| match prop {
63 Property::Int(i) => Some(*i),
64 _ => None,
65 })
66 .unwrap_or(1)
67 }
68
69 pub fn front_axis(&self) -> i32 {
70 self.global_settings
71 .get("FrontAxis")
72 .and_then(|prop| match prop {
73 Property::Int(i) => Some(*i),
74 _ => None,
75 })
76 .unwrap_or(2)
77 }
78
79 pub fn front_axis_sign(&self) -> i32 {
80 self.global_settings
81 .get("FrontAxisSign")
82 .and_then(|prop| match prop {
83 Property::Int(i) => Some(*i),
84 _ => None,
85 })
86 .unwrap_or(1)
87 }
88
89 pub fn coord_axis(&self) -> i32 {
90 self.global_settings
91 .get("CoordAxis")
92 .and_then(|prop| match prop {
93 Property::Int(i) => Some(*i),
94 _ => None,
95 })
96 .unwrap_or(0)
97 }
98
99 pub fn coord_axis_sign(&self) -> i32 {
100 self.global_settings
101 .get("CoordAxisSign")
102 .and_then(|prop| match prop {
103 Property::Int(i) => Some(*i),
104 _ => None,
105 })
106 .unwrap_or(1)
107 }
108
109 pub fn original_up_axis(&self) -> i32 {
110 self.global_settings
111 .get("OriginalUpAxis")
112 .and_then(|prop| match prop {
113 Property::Int(i) => Some(*i),
114 _ => None,
115 })
116 .unwrap_or(0)
117 }
118
119 pub fn original_up_axis_sign(&self) -> i32 {
120 self.global_settings
121 .get("OriginalUpAxisSign")
122 .and_then(|prop| match prop {
123 Property::Int(i) => Some(*i),
124 _ => None,
125 })
126 .unwrap_or(1)
127 }
128
129 pub fn unit_scale_factor(&self) -> f32 {
130 self.global_settings
131 .get("UnitScaleFactor")
132 .and_then(|prop| match prop {
133 Property::Float(f) => Some(*f),
134 _ => None,
135 })
136 .unwrap_or(1.0)
137 }
138
139 pub fn original_unit_scale_factor(&self) -> f32 {
140 self.global_settings
141 .get("OriginalUnitScaleFactor")
142 .and_then(|prop| match prop {
143 Property::Float(f) => Some(*f),
144 _ => None,
145 })
146 .unwrap_or(1.0)
147 }
148
149 pub fn ambient_color(&self) -> [f32; 3] {
150 self.global_settings
151 .get("AmbientColor")
152 .and_then(|prop| match prop {
153 Property::Vec3(v) => Some(*v),
154 _ => None,
155 })
156 .unwrap_or([0.0, 0.0, 0.0])
157 }
158
159 pub fn default_camera(&self) -> String {
160 self.global_settings
161 .get("DefaultCamera")
162 .and_then(|prop| match prop {
163 Property::String(s) => Some(s.to_string()),
164 _ => None,
165 })
166 .unwrap_or("".to_string())
167 }
168
169 pub fn time_span_start(&self) -> u64 {
170 self.global_settings
171 .get("TimeSpanStart")
172 .and_then(|prop| match prop {
173 Property::ULongLong(u) => Some(*u),
174 _ => None,
175 })
176 .unwrap_or(0)
177 }
178
179 pub fn time_span_stop(&self) -> u64 {
180 self.global_settings
181 .get("TimeSpanStop")
182 .and_then(|prop| match prop {
183 Property::ULongLong(u) => Some(*u),
184 _ => None,
185 })
186 .unwrap_or(0)
187 }
188
189 pub fn custom_frame_rate(&self) -> f32 {
190 self.global_settings
191 .get("CustomFrameRate")
192 .and_then(|prop| match prop {
193 Property::Float(f) => Some(*f),
194 _ => None,
195 })
196 .unwrap_or(-1.0)
197 }
198
199 pub fn frame_rate(&self) -> FrameRate {
200 let i = self
201 .global_settings
202 .get("TimeMode")
203 .and_then(|prop| match prop {
204 Property::Int(i) => Some(*i),
205 _ => None,
206 })
207 .unwrap_or(0);
208 match i {
209 0 => FrameRate::Default,
210 1 => FrameRate::Fps120,
211 2 => FrameRate::Fps100,
212 3 => FrameRate::Fps60,
213 4 => FrameRate::Fps50,
214 5 => FrameRate::Fps48,
215 6 => FrameRate::Fps30,
216 7 => FrameRate::Fps30Drop,
217 8 => FrameRate::NtsDropFrame,
218 9 => FrameRate::NtsFullFrame,
219 10 => FrameRate::Pal,
220 11 => FrameRate::Cinema,
221 12 => FrameRate::Fps1000,
222 13 => FrameRate::CinemaNd,
223 14 => FrameRate::Custom,
224 15 => FrameRate::Max,
225 _ => FrameRate::Default,
226 }
227 }
228}