umya_spreadsheet/structs/drawing/
light_rig.rs

1// a:lightRig
2use super::super::EnumValue;
3use super::LightRigDirectionValues;
4use super::LightRigValues;
5use super::Rotation;
6use crate::reader::driver::*;
7use crate::writer::driver::*;
8use quick_xml::events::{BytesStart, Event};
9use quick_xml::Reader;
10use quick_xml::Writer;
11use std::io::Cursor;
12
13#[derive(Clone, Default, Debug)]
14pub struct LightRig {
15    rig: EnumValue<LightRigValues>,
16    definition: EnumValue<LightRigDirectionValues>,
17    rotation: Option<Box<Rotation>>,
18}
19
20impl LightRig {
21    #[inline]
22    pub fn get_rig(&self) -> &LightRigValues {
23        self.rig.get_value()
24    }
25
26    #[inline]
27    pub fn set_rig(&mut self, value: LightRigValues) -> &mut LightRig {
28        self.rig.set_value(value);
29        self
30    }
31
32    #[inline]
33    pub fn get_definition(&self) -> &LightRigDirectionValues {
34        self.definition.get_value()
35    }
36
37    #[inline]
38    pub fn set_definition(&mut self, value: LightRigDirectionValues) -> &mut LightRig {
39        self.definition.set_value(value);
40        self
41    }
42
43    #[inline]
44    pub fn get_rotation(&self) -> Option<&Rotation> {
45        self.rotation.as_deref()
46    }
47
48    #[inline]
49    pub fn get_rotation_mut(&mut self) -> Option<&mut Rotation> {
50        self.rotation.as_deref_mut()
51    }
52
53    #[inline]
54    pub fn set_rotation(&mut self, value: Rotation) -> &mut Self {
55        self.rotation = Some(Box::new(value));
56        self
57    }
58
59    pub(crate) fn set_attributes<R: std::io::BufRead>(
60        &mut self,
61        reader: &mut Reader<R>,
62        e: &BytesStart,
63        empty_flag: bool,
64    ) {
65        set_string_from_xml!(self, e, rig, "rig");
66        set_string_from_xml!(self, e, definition, "dir");
67
68        if empty_flag {
69            return;
70        }
71
72        xml_read_loop!(
73            reader,
74            Event::Empty(ref e) => {
75                if e.name().into_inner() == b"a:rot" {
76                    let mut obj = Rotation::default();
77                    obj.set_attributes(reader, e);
78                    self.rotation = Some(Box::new(obj));
79                }
80            },
81            Event::End(ref e) => {
82                if e.name().into_inner() == b"a:lightRig" {
83                    return
84                }
85            },
86            Event::Eof => panic!("Error: Could not find {} end element", "a:lightRig")
87        );
88    }
89
90    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
91        let with_inner = self.rotation.is_some();
92        // a:lightRig
93        write_start_tag(
94            writer,
95            "a:lightRig",
96            vec![
97                ("rig", self.rig.get_value_string()),
98                ("dir", self.definition.get_value_string()),
99            ],
100            !with_inner,
101        );
102
103        if with_inner {
104            // a:rot
105            if let Some(v) = &self.rotation {
106                v.write_to(writer);
107            }
108            write_end_tag(writer, "a:lightRig");
109        }
110    }
111}