use crate::cot_base::{CursorOnTarget, Point, Sendable};
pub struct FencePoint {
pub latitude: f64,
pub longitude: f64,
}
pub struct Geofence {
pub cot: CursorOnTarget,
callsign: String,
contact: String,
message: String,
points: Vec<FencePoint>,
height: f64,
height_unit: i32,
}
impl Geofence {
pub fn new(
callsign: String,
contact: String,
message: String,
points: Vec<FencePoint>,
height: f64,
height_unit: i32,
) -> Geofence {
let cot = CursorOnTarget::new(
"geofence".to_string(),
None,
Some("u-d-f".to_string()),
"h-e".to_string(),
Some("UNCLASSIFIED".to_string()),
Point {
latitude: 0.0,
longitude: 0.0,
hae: CursorOnTarget::HAE_NONE,
ce: CursorOnTarget::CE_NONE,
le: CursorOnTarget::LE_NONE,
},
);
let mut geofence= Geofence {
cot: cot,
callsign: callsign,
contact: contact,
message: message,
points: points,
height: height,
height_unit: height_unit,
};
geofence.update_xml();
geofence
}
}
impl Sendable for Geofence{
fn update_xml(&mut self) {
let mut links = "".to_string();
for point in &self.points {
links.push_str(&format!(
r#" <link point="{lat},{lon}" />"#,
lat = point.latitude,
lon = point.longitude,
));
links.push_str("\n");
}
let details = format! {r#" <contact callsign="{callsign}" />
<strokeColor value="{stroke_colour}" />
<fillColor value="{fill_value}" />
<remarks>{remarks}</remarks>
{links}
<height value="{height}" />
<height_unit value="{height_unit}" />
<archive />"#,
callsign = self.callsign,
stroke_colour = -16711936,
fill_value = 822148864,
remarks = self.message,
links = links,
height = self.height,
height_unit = self.height_unit,
};
self.cot.set_xml_detail(details);
}
fn modify_field(&mut self, field: &str, value: &str) {
match field {
"callsign" => self.callsign = value.to_string(),
"contact" => self.contact = value.to_string(),
"message" => self.message = value.to_string(),
"height" => self.height = value.parse().unwrap(),
"height_unit" => self.height_unit = value.parse().unwrap(),
_ => (),
}
self.update_xml();
}
fn get_cot(&self)-> CursorOnTarget {
self.cot.clone()
}
}