umya_spreadsheet/structs/drawing/spreadsheet/
connection_shape.rs

1// xdr:cxnSp
2use super::super::super::Anchor;
3use super::NonVisualConnectionShapeProperties;
4use super::ShapeProperties;
5use super::ShapeStyle;
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;
13
14#[derive(Clone, Default, Debug)]
15pub struct ConnectionShape {
16    anchor: Anchor,
17    non_visual_connection_shape_properties: NonVisualConnectionShapeProperties,
18    shape_properties: ShapeProperties,
19    shape_style: ShapeStyle,
20}
21
22impl ConnectionShape {
23    #[inline]
24    pub fn get_anchor(&self) -> &Anchor {
25        &self.anchor
26    }
27
28    #[inline]
29    pub fn get_anchor_mut(&mut self) -> &mut Anchor {
30        &mut self.anchor
31    }
32
33    #[inline]
34    pub fn set_anchor(&mut self, value: Anchor) {
35        self.anchor = value;
36    }
37
38    #[inline]
39    pub fn get_non_visual_connection_shape_properties(
40        &self,
41    ) -> &NonVisualConnectionShapeProperties {
42        &self.non_visual_connection_shape_properties
43    }
44
45    #[inline]
46    pub fn get_non_visual_connection_shape_properties_mut(
47        &mut self,
48    ) -> &mut NonVisualConnectionShapeProperties {
49        &mut self.non_visual_connection_shape_properties
50    }
51
52    #[inline]
53    pub fn set_non_visual_connection_shape_properties(
54        &mut self,
55        value: NonVisualConnectionShapeProperties,
56    ) {
57        self.non_visual_connection_shape_properties = value;
58    }
59
60    #[inline]
61    pub fn get_shape_properties(&self) -> &ShapeProperties {
62        &self.shape_properties
63    }
64
65    #[inline]
66    pub fn get_shape_properties_mut(&mut self) -> &mut ShapeProperties {
67        &mut self.shape_properties
68    }
69
70    #[inline]
71    pub fn set_shape_properties(&mut self, value: ShapeProperties) {
72        self.shape_properties = value;
73    }
74
75    #[inline]
76    pub fn get_shape_style(&self) -> &ShapeStyle {
77        &self.shape_style
78    }
79
80    #[inline]
81    pub fn get_shape_style_mut(&mut self) -> &mut ShapeStyle {
82        &mut self.shape_style
83    }
84
85    #[inline]
86    pub fn set_shape_style(&mut self, value: ShapeStyle) {
87        self.shape_style = value;
88    }
89
90    pub(crate) fn set_attributes<R: std::io::BufRead>(
91        &mut self,
92        reader: &mut Reader<R>,
93        _e: &BytesStart,
94        drawing_relationships: Option<&RawRelationships>,
95    ) {
96        xml_read_loop!(
97            reader,
98            Event::Start(ref e) => {
99                match e.name().into_inner() {
100                    b"xdr:nvCxnSpPr" => {
101                        self.non_visual_connection_shape_properties
102                            .set_attributes(reader, e);
103                        }
104                    b"xdr:spPr" => {
105                        self.shape_properties.set_attributes(reader, e, drawing_relationships);
106                    }
107                    b"xdr:style" => {
108                        self.shape_style.set_attributes(reader, e);
109                    }
110                    _ => (),
111                }
112            },
113            Event::End(ref e) => {
114                if e.name().into_inner() == b"xdr:cxnSp" {
115                    return;
116                }
117            },
118            Event::Eof => panic!("Error: Could not find {} end element", "xdr:cxnSp")
119        );
120    }
121
122    pub(crate) fn write_to(
123        &self,
124        writer: &mut Writer<Cursor<Vec<u8>>>,
125        rel_list: &mut Vec<(String, String)>,
126    ) {
127        // xdr:cxnSp
128        write_start_tag(writer, "xdr:cxnSp", vec![("macro", "")], false);
129
130        // xdr:nvCxnSpPr
131        self.non_visual_connection_shape_properties.write_to(writer);
132
133        // xdr:spPr
134        self.shape_properties.write_to(writer, rel_list);
135
136        // xdr:style
137        self.shape_style.write_to(writer);
138
139        write_end_tag(writer, "xdr:cxnSp");
140    }
141}