use std::io::Cursor;
use quick_xml::{
Reader,
Writer,
events::{
BytesStart,
Event,
},
};
use super::{
super::super::Anchor,
NonVisualConnectionShapeProperties,
ShapeProperties,
ShapeStyle,
};
use crate::{
reader::driver::xml_read_loop,
structs::raw::RawRelationships,
writer::driver::{
write_end_tag,
write_start_tag,
},
};
#[derive(Clone, Default, Debug)]
pub struct ConnectionShape {
anchor: Anchor,
non_visual_connection_shape_properties: NonVisualConnectionShapeProperties,
shape_properties: ShapeProperties,
shape_style: ShapeStyle,
}
impl ConnectionShape {
#[inline]
#[must_use]
pub fn anchor(&self) -> &Anchor {
&self.anchor
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use anchor()")]
pub fn get_anchor(&self) -> &Anchor {
self.anchor()
}
#[inline]
pub fn anchor_mut(&mut self) -> &mut Anchor {
&mut self.anchor
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use anchor_mut()")]
pub fn get_anchor_mut(&mut self) -> &mut Anchor {
self.anchor_mut()
}
#[inline]
pub fn set_anchor(&mut self, value: Anchor) {
self.anchor = value;
}
#[inline]
#[must_use]
pub fn non_visual_connection_shape_properties(&self) -> &NonVisualConnectionShapeProperties {
&self.non_visual_connection_shape_properties
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use non_visual_connection_shape_properties()")]
pub fn get_non_visual_connection_shape_properties(
&self,
) -> &NonVisualConnectionShapeProperties {
self.non_visual_connection_shape_properties()
}
#[inline]
pub fn non_visual_connection_shape_properties_mut(
&mut self,
) -> &mut NonVisualConnectionShapeProperties {
&mut self.non_visual_connection_shape_properties
}
#[inline]
#[deprecated(
since = "3.0.0",
note = "Use non_visual_connection_shape_properties_mut()"
)]
pub fn get_non_visual_connection_shape_properties_mut(
&mut self,
) -> &mut NonVisualConnectionShapeProperties {
self.non_visual_connection_shape_properties_mut()
}
#[inline]
pub fn set_non_visual_connection_shape_properties(
&mut self,
value: NonVisualConnectionShapeProperties,
) {
self.non_visual_connection_shape_properties = value;
}
#[inline]
#[must_use]
pub fn shape_properties(&self) -> &ShapeProperties {
&self.shape_properties
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use shape_properties()")]
pub fn get_shape_properties(&self) -> &ShapeProperties {
self.shape_properties()
}
#[inline]
pub fn shape_properties_mut(&mut self) -> &mut ShapeProperties {
&mut self.shape_properties
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use shape_properties_mut()")]
pub fn get_shape_properties_mut(&mut self) -> &mut ShapeProperties {
self.shape_properties_mut()
}
#[inline]
pub fn set_shape_properties(&mut self, value: ShapeProperties) {
self.shape_properties = value;
}
#[inline]
#[must_use]
pub fn shape_style(&self) -> &ShapeStyle {
&self.shape_style
}
#[inline]
#[must_use]
#[deprecated(since = "3.0.0", note = "Use shape_style()")]
pub fn get_shape_style(&self) -> &ShapeStyle {
self.shape_style()
}
#[inline]
pub fn shape_style_mut(&mut self) -> &mut ShapeStyle {
&mut self.shape_style
}
#[inline]
#[deprecated(since = "3.0.0", note = "Use stretch_mut()")]
pub fn get_shape_style_mut(&mut self) -> &mut ShapeStyle {
self.shape_style_mut()
}
#[inline]
pub fn set_shape_style(&mut self, value: ShapeStyle) {
self.shape_style = value;
}
pub(crate) fn set_attributes<R: std::io::BufRead>(
&mut self,
reader: &mut Reader<R>,
_e: &BytesStart,
drawing_relationships: Option<&RawRelationships>,
) {
xml_read_loop!(
reader,
Event::Start(ref e) => {
match e.name().into_inner() {
b"xdr:nvCxnSpPr" => {
self.non_visual_connection_shape_properties
.set_attributes(reader, e);
}
b"xdr:spPr" => {
self.shape_properties.set_attributes(reader, e, drawing_relationships);
}
b"xdr:style" => {
self.shape_style.set_attributes(reader, e);
}
_ => (),
}
},
Event::End(ref e) => {
if e.name().into_inner() == b"xdr:cxnSp" {
return;
}
},
Event::Eof => panic!("Error: Could not find {} end element", "xdr:cxnSp")
);
}
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
write_start_tag(writer, "xdr:cxnSp", vec![("macro", "").into()], false);
self.non_visual_connection_shape_properties.write_to(writer);
self.shape_properties.write_to(writer, rel_list);
self.shape_style.write_to(writer);
write_end_tag(writer, "xdr:cxnSp");
}
}