umya_spreadsheet/structs/drawing/
light_rig.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::{
14 super::EnumValue,
15 LightRigDirectionValues,
16 LightRigValues,
17 Rotation,
18};
19use crate::{
20 reader::driver::{
21 get_attribute,
22 set_string_from_xml,
23 xml_read_loop,
24 },
25 writer::driver::{
26 write_end_tag,
27 write_start_tag,
28 },
29};
30
31#[derive(Clone, Default, Debug)]
32pub struct LightRig {
33 rig: EnumValue<LightRigValues>,
34 definition: EnumValue<LightRigDirectionValues>,
35 rotation: Option<Box<Rotation>>,
36}
37
38impl LightRig {
39 #[inline]
40 #[must_use]
41 pub fn rig(&self) -> &LightRigValues {
42 self.rig.value()
43 }
44
45 #[inline]
46 #[must_use]
47 #[deprecated(since = "3.0.0", note = "Use rig()")]
48 pub fn get_rig(&self) -> &LightRigValues {
49 self.rig()
50 }
51
52 #[inline]
53 pub fn set_rig(&mut self, value: LightRigValues) -> &mut LightRig {
54 self.rig.set_value(value);
55 self
56 }
57
58 #[inline]
59 #[must_use]
60 pub fn definition(&self) -> &LightRigDirectionValues {
61 self.definition.value()
62 }
63
64 #[inline]
65 #[must_use]
66 #[deprecated(since = "3.0.0", note = "Use definition()")]
67 pub fn get_definition(&self) -> &LightRigDirectionValues {
68 self.definition()
69 }
70
71 #[inline]
72 pub fn set_definition(&mut self, value: LightRigDirectionValues) -> &mut LightRig {
73 self.definition.set_value(value);
74 self
75 }
76
77 #[inline]
78 #[must_use]
79 pub fn rotation(&self) -> Option<&Rotation> {
80 self.rotation.as_deref()
81 }
82
83 #[inline]
84 #[must_use]
85 #[deprecated(since = "3.0.0", note = "Use rotation()")]
86 pub fn get_rotation(&self) -> Option<&Rotation> {
87 self.rotation()
88 }
89
90 #[inline]
91 pub fn rotation_mut(&mut self) -> Option<&mut Rotation> {
92 self.rotation.as_deref_mut()
93 }
94
95 #[inline]
96 #[deprecated(since = "3.0.0", note = "Use rotation_mut()")]
97 pub fn get_rotation_mut(&mut self) -> Option<&mut Rotation> {
98 self.rotation_mut()
99 }
100
101 #[inline]
102 pub fn set_rotation(&mut self, value: Rotation) -> &mut Self {
103 self.rotation = Some(Box::new(value));
104 self
105 }
106
107 pub(crate) fn set_attributes<R: std::io::BufRead>(
108 &mut self,
109 reader: &mut Reader<R>,
110 e: &BytesStart,
111 empty_flag: bool,
112 ) {
113 set_string_from_xml!(self, e, rig, "rig");
114 set_string_from_xml!(self, e, definition, "dir");
115
116 if empty_flag {
117 return;
118 }
119
120 xml_read_loop!(
121 reader,
122 Event::Empty(ref e) => {
123 if e.name().into_inner() == b"a:rot" {
124 let mut obj = Rotation::default();
125 obj.set_attributes(reader, e);
126 self.rotation = Some(Box::new(obj));
127 }
128 },
129 Event::End(ref e) => {
130 if e.name().into_inner() == b"a:lightRig" {
131 return
132 }
133 },
134 Event::Eof => panic!("Error: Could not find {} end element", "a:lightRig")
135 );
136 }
137
138 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
139 let with_inner = self.rotation.is_some();
140 write_start_tag(
142 writer,
143 "a:lightRig",
144 vec![
145 ("rig", self.rig.value_string()).into(),
146 ("dir", self.definition.value_string()).into(),
147 ],
148 !with_inner,
149 );
150
151 if with_inner {
152 if let Some(v) = &self.rotation {
154 v.write_to(writer);
155 }
156 write_end_tag(writer, "a:lightRig");
157 }
158 }
159}