use crate::cot_base::{CursorOnTarget, Sendable};
use std::fmt::{Debug, Formatter, Result as FmtResult};
pub struct Bullseye {
pub cot: CursorOnTarget,
callsign: String,
title: String,
edge_to_center: bool,
mils: bool,
has_range_rings: bool,
ring_dist: f64,
ring_num: i32,
range_ring_visible: bool,
distance: f64,
bullseye_uid: String,
bearing_ref: String,
}
impl Debug for Bullseye {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.debug_struct("Bullseye")
.field("cot", &self.cot)
.field("callsign", &self.callsign)
.field("title", &self.title)
.field("edge_to_center", &self.edge_to_center)
.field("mils", &self.mils)
.field("has_range_rings", &self.has_range_rings)
.field("ring_dist", &self.ring_dist)
.field("ring_num", &self.ring_num)
.field("range_ring_visible", &self.range_ring_visible)
.field("distance", &self.distance)
.field("bullseye_uid", &self.bullseye_uid)
.field("bearing_ref", &self.bearing_ref)
.finish()
}
}
impl Bullseye {
pub fn new(
cot: CursorOnTarget,
callsign: String,
title: String,
edge_to_center: bool,
mils: bool,
has_range_rings: bool,
ring_dist: f64,
ring_num: i32,
range_ring_visible: bool,
distance: f64,
bullseye_uid: String,
bearing_ref: String,
) -> Bullseye {
let mut new_bullseye = Bullseye {
cot,
callsign,
title,
edge_to_center,
mils,
has_range_rings,
ring_dist,
ring_num,
range_ring_visible,
distance,
bullseye_uid,
bearing_ref,
};
new_bullseye.cot.type_string = Some("u-r-b-bullseye".to_string());
new_bullseye.update_xml();
new_bullseye
}
pub fn get_xml(&mut self) -> String {
self.cot.get_xml()
}
pub fn get_xml_bytes(&mut self) -> Vec<u8> {
self.cot.get_xml_bytes()
}
}
impl Sendable for Bullseye {
fn update_xml(&mut self) {
let details = format!(
r#" <archive />
<contact callsign="{callsign}" />
<bullseye title="{title}" edgeToCenter="{edge_to_centre}" mils="{mils}" hasRangeRings="{rings}" ringDist="{dist}" ringNum="{num}" rangeRingVisible="{visable}" distance="{distance}" bullseyeUID="{bullseye_id}" bearingRef="{bearing}" />"#,
callsign = self.callsign,
title = self.title,
edge_to_centre = self.edge_to_center,
mils = self.mils,
rings = self.has_range_rings,
dist = self.ring_dist,
num = self.ring_num,
visable = self.range_ring_visible,
distance = self.distance,
bullseye_id = self.bullseye_uid,
bearing = self.bearing_ref
);
self.cot.set_xml_detail(details);
}
fn modify_field(&mut self, field: &str, value: &str) {
match field {
"callsign" => self.callsign = value.to_string(),
"title" => self.title = value.to_string(),
"edge_to_center" => self.edge_to_center = value.parse().unwrap(),
"mils" => self.mils = value.parse().unwrap(),
"has_range_rings" => self.has_range_rings = value.parse().unwrap(),
"ring_dist" => self.ring_dist = value.parse().unwrap(),
"ring_num" => self.ring_num = value.parse().unwrap(),
"range_ring_visible" => self.range_ring_visible = value.parse().unwrap(),
"distance" => self.distance = value.parse().unwrap(),
"bullseye_uid" => self.bullseye_uid = value.to_string(),
"bearing_ref" => self.bearing_ref = value.to_string(),
_ => println!("Field not found"),
}
}
fn get_cot(&self)-> CursorOnTarget {
self.cot.clone()
}
}