Skip to main content

umya_spreadsheet/structs/drawing/spreadsheet/
group_shape.rs

1// xdr:grpSp
2use std::io::Cursor;
3
4use quick_xml::{
5    Reader,
6    Writer,
7    events::{
8        BytesStart,
9        Event,
10    },
11};
12
13use super::{
14    GroupShapeProperties,
15    NonVisualGroupShapeProperties,
16    Picture,
17    Shape,
18};
19use crate::{
20    reader::driver::xml_read_loop,
21    structs::raw::RawRelationships,
22    writer::driver::{
23        write_end_tag,
24        write_start_tag,
25    },
26};
27
28#[derive(Clone, Default, Debug)]
29pub struct GroupShape {
30    non_visual_group_shape_properties: NonVisualGroupShapeProperties,
31    group_shape_properties:            GroupShapeProperties,
32    picture_collection:                Vec<Picture>,
33    shape_collection:                  Vec<Shape>,
34}
35
36impl GroupShape {
37    #[inline]
38    #[must_use]
39    pub fn non_visual_group_shape_properties(&self) -> &NonVisualGroupShapeProperties {
40        &self.non_visual_group_shape_properties
41    }
42
43    #[inline]
44    #[must_use]
45    #[deprecated(since = "3.0.0", note = "Use non_visual_group_shape_properties()")]
46    pub fn get_non_visual_group_shape_properties(&self) -> &NonVisualGroupShapeProperties {
47        self.non_visual_group_shape_properties()
48    }
49
50    #[inline]
51    pub fn non_visual_group_shape_properties_mut(&mut self) -> &mut NonVisualGroupShapeProperties {
52        &mut self.non_visual_group_shape_properties
53    }
54
55    #[inline]
56    #[deprecated(since = "3.0.0", note = "Use non_visual_group_shape_properties_mut()")]
57    pub fn get_non_visual_group_shape_properties_mut(
58        &mut self,
59    ) -> &mut NonVisualGroupShapeProperties {
60        self.non_visual_group_shape_properties_mut()
61    }
62
63    #[inline]
64    pub fn set_non_visual_group_shape_properties(&mut self, value: NonVisualGroupShapeProperties) {
65        self.non_visual_group_shape_properties = value;
66    }
67
68    #[inline]
69    #[must_use]
70    pub fn group_shape_properties(&self) -> &GroupShapeProperties {
71        &self.group_shape_properties
72    }
73
74    #[inline]
75    #[must_use]
76    #[deprecated(since = "3.0.0", note = "Use group_shape_properties()")]
77    pub fn get_group_shape_properties(&self) -> &GroupShapeProperties {
78        self.group_shape_properties()
79    }
80
81    #[inline]
82    pub fn group_shape_properties_mut(&mut self) -> &mut GroupShapeProperties {
83        &mut self.group_shape_properties
84    }
85
86    #[inline]
87    #[deprecated(since = "3.0.0", note = "Use group_shape_properties_mut()")]
88    pub fn get_group_shape_properties_mut(&mut self) -> &mut GroupShapeProperties {
89        self.group_shape_properties_mut()
90    }
91
92    #[inline]
93    pub fn set_group_shape_properties(&mut self, value: GroupShapeProperties) {
94        self.group_shape_properties = value;
95    }
96
97    #[inline]
98    #[must_use]
99    pub fn picture_collection(&self) -> &[Picture] {
100        &self.picture_collection
101    }
102
103    #[inline]
104    #[must_use]
105    #[deprecated(since = "3.0.0", note = "Use picture_collection()")]
106    pub fn get_picture_collection(&self) -> &[Picture] {
107        self.picture_collection()
108    }
109
110    #[inline]
111    pub fn picture_collection_mut(&mut self) -> &mut Vec<Picture> {
112        &mut self.picture_collection
113    }
114
115    #[inline]
116    #[deprecated(since = "3.0.0", note = "Use picture_collection_mut()")]
117    pub fn get_picture_collection_mut(&mut self) -> &mut Vec<Picture> {
118        self.picture_collection_mut()
119    }
120
121    #[inline]
122    pub fn add_picture_collection(&mut self, value: Picture) {
123        self.picture_collection.push(value);
124    }
125
126    #[inline]
127    #[must_use]
128    pub fn shape_collection(&self) -> &[Shape] {
129        &self.shape_collection
130    }
131
132    #[inline]
133    #[must_use]
134    #[deprecated(since = "3.0.0", note = "Use shape_collection()")]
135    pub fn get_shape_collection(&self) -> &[Shape] {
136        self.shape_collection()
137    }
138
139    #[inline]
140    pub fn shape_collection_mut(&mut self) -> &mut Vec<Shape> {
141        &mut self.shape_collection
142    }
143
144    #[inline]
145    #[deprecated(since = "3.0.0", note = "Use shape_collection_mut()")]
146    pub fn get_shape_collection_mut(&mut self) -> &mut Vec<Shape> {
147        self.shape_collection_mut()
148    }
149
150    #[inline]
151    pub fn add_shape_collection(&mut self, value: Shape) {
152        self.shape_collection.push(value);
153    }
154
155    pub(crate) fn set_attributes<R: std::io::BufRead>(
156        &mut self,
157        reader: &mut Reader<R>,
158        _e: &BytesStart,
159        drawing_relationships: Option<&RawRelationships>,
160    ) {
161        xml_read_loop!(
162            reader,
163            Event::Start(ref e) => {
164                match e.name().into_inner() {
165                    b"xdr:nvGrpSpPr" => {
166                        self.non_visual_group_shape_properties.set_attributes(reader, e);
167                    }
168                    b"xdr:grpSpPr" => {
169                        self.group_shape_properties.set_attributes(reader, e);
170                    }
171                    b"xdr:pic" => {
172                        let mut obj = Picture::default();
173                        obj.set_attributes(reader, e, drawing_relationships);
174                        self.add_picture_collection(obj);
175                    }
176                    b"xdr:sp" => {
177                        let mut obj = Shape::default();
178                        obj.set_attributes(reader, e, drawing_relationships);
179                        self.add_shape_collection(obj);
180                    }
181                    _ => (),
182                }
183            },
184            Event::End(ref e) => {
185                if e.name().into_inner() == b"xdr:grpSp" {
186                    return;
187                }
188            },
189            Event::Eof => panic!("Error: Could not find {} end element", "xdr:grpSp")
190        );
191    }
192
193    pub(crate) fn write_to(
194        &self,
195        writer: &mut Writer<Cursor<Vec<u8>>>,
196        rel_list: &mut Vec<(String, String)>,
197    ) {
198        // xdr:grpSp
199        write_start_tag(writer, "xdr:grpSp", vec![], false);
200
201        // xdr:nvGrpSpPr
202        self.non_visual_group_shape_properties.write_to(writer);
203
204        // xdr:grpSpPr
205        self.group_shape_properties.write_to(writer);
206
207        // xdr:pic
208        for obj in &self.picture_collection {
209            obj.write_to(writer, rel_list);
210        }
211
212        // xdr:sp
213        for obj in &self.shape_collection {
214            obj.write_to(writer, rel_list, 0);
215        }
216
217        write_end_tag(writer, "xdr:grpSp");
218    }
219}