umya_spreadsheet/structs/drawing/spreadsheet/
group_shape.rs1use super::GroupShapeProperties;
3use super::NonVisualGroupShapeProperties;
4use super::Picture;
5use super::Shape;
6use crate::reader::driver::*;
7use crate::structs::raw::RawRelationships;
8use crate::writer::driver::*;
9use quick_xml::events::{BytesStart, Event};
10use quick_xml::Reader;
11use quick_xml::Writer;
12use std::io::Cursor;
13use thin_vec::ThinVec;
14
15#[derive(Clone, Default, Debug)]
16pub struct GroupShape {
17 non_visual_group_shape_properties: NonVisualGroupShapeProperties,
18 group_shape_properties: GroupShapeProperties,
19 picture_collection: ThinVec<Picture>,
20 shape_collection: ThinVec<Shape>,
21}
22
23impl GroupShape {
24 #[inline]
25 pub fn get_non_visual_group_shape_properties(&self) -> &NonVisualGroupShapeProperties {
26 &self.non_visual_group_shape_properties
27 }
28
29 #[inline]
30 pub fn get_non_visual_group_shape_properties_mut(
31 &mut self,
32 ) -> &mut NonVisualGroupShapeProperties {
33 &mut self.non_visual_group_shape_properties
34 }
35
36 #[inline]
37 pub fn set_non_visual_group_shape_properties(&mut self, value: NonVisualGroupShapeProperties) {
38 self.non_visual_group_shape_properties = value;
39 }
40
41 #[inline]
42 pub fn get_group_shape_properties(&self) -> &GroupShapeProperties {
43 &self.group_shape_properties
44 }
45
46 #[inline]
47 pub fn get_group_shape_properties_mut(&mut self) -> &mut GroupShapeProperties {
48 &mut self.group_shape_properties
49 }
50
51 #[inline]
52 pub fn set_group_shape_properties(&mut self, value: GroupShapeProperties) {
53 self.group_shape_properties = value;
54 }
55
56 #[inline]
57 pub fn get_picture_collection(&self) -> &[Picture] {
58 &self.picture_collection
59 }
60
61 #[inline]
62 pub fn get_picture_collection_mut(&mut self) -> &mut ThinVec<Picture> {
63 &mut self.picture_collection
64 }
65
66 #[inline]
67 pub fn add_picture_collection(&mut self, value: Picture) {
68 self.picture_collection.push(value);
69 }
70
71 #[inline]
72 pub fn get_shape_collection(&self) -> &[Shape] {
73 &self.shape_collection
74 }
75
76 #[inline]
77 pub fn get_shape_collection_mut(&mut self) -> &mut ThinVec<Shape> {
78 &mut self.shape_collection
79 }
80
81 #[inline]
82 pub fn add_shape_collection(&mut self, value: Shape) {
83 self.shape_collection.push(value);
84 }
85
86 pub(crate) fn set_attributes<R: std::io::BufRead>(
87 &mut self,
88 reader: &mut Reader<R>,
89 _e: &BytesStart,
90 drawing_relationships: Option<&RawRelationships>,
91 ) {
92 xml_read_loop!(
93 reader,
94 Event::Start(ref e) => {
95 match e.name().into_inner() {
96 b"xdr:nvGrpSpPr" => {
97 self.non_visual_group_shape_properties.set_attributes(reader, e);
98 }
99 b"xdr:grpSpPr" => {
100 self.group_shape_properties.set_attributes(reader, e);
101 }
102 b"xdr:pic" => {
103 let mut obj = Picture::default();
104 obj.set_attributes(reader, e, drawing_relationships);
105 self.add_picture_collection(obj);
106 }
107 b"xdr:sp" => {
108 let mut obj = Shape::default();
109 obj.set_attributes(reader, e, drawing_relationships);
110 self.add_shape_collection(obj);
111 }
112 _ => (),
113 }
114 },
115 Event::End(ref e) => {
116 if e.name().into_inner() == b"xdr:grpSp" {
117 return;
118 }
119 },
120 Event::Eof => panic!("Error: Could not find {} end element", "xdr:grpSp")
121 );
122 }
123
124 pub(crate) fn write_to(
125 &self,
126 writer: &mut Writer<Cursor<Vec<u8>>>,
127 rel_list: &mut Vec<(String, String)>,
128 ) {
129 write_start_tag(writer, "xdr:grpSp", vec![], false);
131
132 &self.non_visual_group_shape_properties.write_to(writer);
134
135 &self.group_shape_properties.write_to(writer);
137
138 for obj in &self.picture_collection {
140 obj.write_to(writer, rel_list);
141 }
142
143 for obj in &self.shape_collection {
145 obj.write_to(writer, rel_list, &0);
146 }
147
148 write_end_tag(writer, "xdr:grpSp");
149 }
150}