use crate::cot_base::{CursorOnTarget, Sendable};
pub struct Measure {
pub cot: CursorOnTarget,
callsign: String,
range: f64,
bearing: f64,
inclination: f64,
range_units: i32,
bearing_units: i32,
north_ref: i32,
color: i32,
stroke_color: i32,
stroke_weight: f64,
}
impl Measure {
pub fn new(
cot: CursorOnTarget,
callsign: String,
range: f64,
bearing: f64,
inclination: f64,
range_units: i32,
bearing_units: i32,
north_ref: i32,
color: i32,
stroke_color: i32,
stroke_weight: f64,
) -> Measure {
let mut new_measure = Measure {
cot,
callsign,
range,
bearing,
inclination,
range_units,
bearing_units,
north_ref,
color,
stroke_color,
stroke_weight,
};
new_measure.cot.type_string = Some("u-rb-a".to_string());
new_measure.cot.how_string = "h-e".to_string();
new_measure.update_xml();
new_measure
}
}
impl Sendable for Measure {
fn update_xml(&mut self) {
let details = format! {r#" <contact callsign="{callsign}" />
<range value="{range}" />
<bearing value="{bearing}" />
<inclination value="{inclination}" />
<rangeUnits value="{range_units}" />
<bearingUnits value="{bearing_units}" />
<northRef value="{north_ef}" />
<color value="{color}" />
<strokeColor value="{stroke_color}" />
<strokeWeight value="{stroke_weight}" />
<archive />
<remarks />"#,
callsign = self.callsign,
range = self.range,
bearing = self.bearing,
inclination = self.inclination,
range_units = self.range_units,
bearing_units = self.bearing_units,
north_ef = self.north_ref,
color = self.color,
stroke_color = self.stroke_color,
stroke_weight = self.stroke_weight,
};
self.cot.set_xml_detail(details);
}
fn modify_field(&mut self, field: &str, value: &str) {
match field {
"callsign" => self.callsign = value.to_string(),
"range" => self.range = value.parse().unwrap(),
"bearing" => self.bearing = value.parse().unwrap(),
"inclination" => self.inclination = value.parse().unwrap(),
"range_units" => self.range_units = value.parse().unwrap(),
"bearing_units" => self.bearing_units = value.parse().unwrap(),
"north_ref" => self.north_ref = value.parse().unwrap(),
"color" => self.color = value.parse().unwrap(),
"stroke_color" => self.stroke_color = value.parse().unwrap(),
"stroke_weight" => self.stroke_weight = value.parse().unwrap(),
_ => println!("Field not found"),
}
}
fn get_cot(&self)-> CursorOnTarget {
self.cot.clone()
}
}