umya_spreadsheet/structs/drawing/spreadsheet/
connection_shape.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::super::Anchor,
15 NonVisualConnectionShapeProperties,
16 ShapeProperties,
17 ShapeStyle,
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 ConnectionShape {
30 anchor: Anchor,
31 non_visual_connection_shape_properties: NonVisualConnectionShapeProperties,
32 shape_properties: ShapeProperties,
33 shape_style: ShapeStyle,
34}
35
36impl ConnectionShape {
37 #[inline]
38 #[must_use]
39 pub fn anchor(&self) -> &Anchor {
40 &self.anchor
41 }
42
43 #[inline]
44 #[must_use]
45 #[deprecated(since = "3.0.0", note = "Use anchor()")]
46 pub fn get_anchor(&self) -> &Anchor {
47 self.anchor()
48 }
49
50 #[inline]
51 pub fn anchor_mut(&mut self) -> &mut Anchor {
52 &mut self.anchor
53 }
54
55 #[inline]
56 #[deprecated(since = "3.0.0", note = "Use anchor_mut()")]
57 pub fn get_anchor_mut(&mut self) -> &mut Anchor {
58 self.anchor_mut()
59 }
60
61 #[inline]
62 pub fn set_anchor(&mut self, value: Anchor) {
63 self.anchor = value;
64 }
65
66 #[inline]
67 #[must_use]
68 pub fn non_visual_connection_shape_properties(&self) -> &NonVisualConnectionShapeProperties {
69 &self.non_visual_connection_shape_properties
70 }
71
72 #[inline]
73 #[must_use]
74 #[deprecated(since = "3.0.0", note = "Use non_visual_connection_shape_properties()")]
75 pub fn get_non_visual_connection_shape_properties(
76 &self,
77 ) -> &NonVisualConnectionShapeProperties {
78 self.non_visual_connection_shape_properties()
79 }
80
81 #[inline]
82 pub fn non_visual_connection_shape_properties_mut(
83 &mut self,
84 ) -> &mut NonVisualConnectionShapeProperties {
85 &mut self.non_visual_connection_shape_properties
86 }
87
88 #[inline]
89 #[deprecated(
90 since = "3.0.0",
91 note = "Use non_visual_connection_shape_properties_mut()"
92 )]
93 pub fn get_non_visual_connection_shape_properties_mut(
94 &mut self,
95 ) -> &mut NonVisualConnectionShapeProperties {
96 self.non_visual_connection_shape_properties_mut()
97 }
98
99 #[inline]
100 pub fn set_non_visual_connection_shape_properties(
101 &mut self,
102 value: NonVisualConnectionShapeProperties,
103 ) {
104 self.non_visual_connection_shape_properties = value;
105 }
106
107 #[inline]
108 #[must_use]
109 pub fn shape_properties(&self) -> &ShapeProperties {
110 &self.shape_properties
111 }
112
113 #[inline]
114 #[must_use]
115 #[deprecated(since = "3.0.0", note = "Use shape_properties()")]
116 pub fn get_shape_properties(&self) -> &ShapeProperties {
117 self.shape_properties()
118 }
119
120 #[inline]
121 pub fn shape_properties_mut(&mut self) -> &mut ShapeProperties {
122 &mut self.shape_properties
123 }
124
125 #[inline]
126 #[deprecated(since = "3.0.0", note = "Use shape_properties_mut()")]
127 pub fn get_shape_properties_mut(&mut self) -> &mut ShapeProperties {
128 self.shape_properties_mut()
129 }
130
131 #[inline]
132 pub fn set_shape_properties(&mut self, value: ShapeProperties) {
133 self.shape_properties = value;
134 }
135
136 #[inline]
137 #[must_use]
138 pub fn shape_style(&self) -> &ShapeStyle {
139 &self.shape_style
140 }
141
142 #[inline]
143 #[must_use]
144 #[deprecated(since = "3.0.0", note = "Use shape_style()")]
145 pub fn get_shape_style(&self) -> &ShapeStyle {
146 self.shape_style()
147 }
148
149 #[inline]
150 pub fn shape_style_mut(&mut self) -> &mut ShapeStyle {
151 &mut self.shape_style
152 }
153
154 #[inline]
155 #[deprecated(since = "3.0.0", note = "Use stretch_mut()")]
156 pub fn get_shape_style_mut(&mut self) -> &mut ShapeStyle {
157 self.shape_style_mut()
158 }
159
160 #[inline]
161 pub fn set_shape_style(&mut self, value: ShapeStyle) {
162 self.shape_style = value;
163 }
164
165 pub(crate) fn set_attributes<R: std::io::BufRead>(
166 &mut self,
167 reader: &mut Reader<R>,
168 _e: &BytesStart,
169 drawing_relationships: Option<&RawRelationships>,
170 ) {
171 xml_read_loop!(
172 reader,
173 Event::Start(ref e) => {
174 match e.name().into_inner() {
175 b"xdr:nvCxnSpPr" => {
176 self.non_visual_connection_shape_properties
177 .set_attributes(reader, e);
178 }
179 b"xdr:spPr" => {
180 self.shape_properties.set_attributes(reader, e, drawing_relationships);
181 }
182 b"xdr:style" => {
183 self.shape_style.set_attributes(reader, e);
184 }
185 _ => (),
186 }
187 },
188 Event::End(ref e) => {
189 if e.name().into_inner() == b"xdr:cxnSp" {
190 return;
191 }
192 },
193 Event::Eof => panic!("Error: Could not find {} end element", "xdr:cxnSp")
194 );
195 }
196
197 pub(crate) fn write_to(
198 &self,
199 writer: &mut Writer<Cursor<Vec<u8>>>,
200 rel_list: &mut Vec<(String, String)>,
201 ) {
202 write_start_tag(writer, "xdr:cxnSp", vec![("macro", "").into()], false);
204
205 self.non_visual_connection_shape_properties.write_to(writer);
207
208 self.shape_properties.write_to(writer, rel_list);
210
211 self.shape_style.write_to(writer);
213
214 write_end_tag(writer, "xdr:cxnSp");
215 }
216}