#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BeamCapMode {
#[default]
Sphere,
Butt,
Hemisphere,
}
impl std::fmt::Display for BeamCapMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BeamCapMode::Sphere => write!(f, "sphere"),
BeamCapMode::Butt => write!(f, "butt"),
BeamCapMode::Hemisphere => write!(f, "hemisphere"),
}
}
}
impl std::str::FromStr for BeamCapMode {
type Err = crate::error::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"sphere" => Ok(BeamCapMode::Sphere),
"butt" => Ok(BeamCapMode::Butt),
"hemisphere" => Ok(BeamCapMode::Hemisphere),
_ => Err(crate::error::Error::InvalidXml(format!(
"Invalid cap mode '{}'. Must be 'sphere', 'butt', or 'hemisphere'",
s
))),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Beam {
pub v1: usize,
pub v2: usize,
pub r1: Option<f64>,
pub r2: Option<f64>,
pub cap1: Option<BeamCapMode>,
pub cap2: Option<BeamCapMode>,
pub property_id: Option<u32>,
pub p1: Option<u32>,
pub p2: Option<u32>,
}
impl Beam {
pub fn new(v1: usize, v2: usize) -> Self {
Self {
v1,
v2,
r1: None,
r2: None,
cap1: None,
cap2: None,
property_id: None,
p1: None,
p2: None,
}
}
pub fn with_radius(v1: usize, v2: usize, r1: f64) -> Self {
Self {
v1,
v2,
r1: Some(r1),
r2: None,
cap1: None,
cap2: None,
property_id: None,
p1: None,
p2: None,
}
}
pub fn with_radii(v1: usize, v2: usize, r1: f64, r2: f64) -> Self {
Self {
v1,
v2,
r1: Some(r1),
r2: Some(r2),
cap1: None,
cap2: None,
property_id: None,
p1: None,
p2: None,
}
}
}
#[derive(Debug, Clone)]
pub struct Ball {
pub vindex: usize,
pub radius: Option<f64>,
pub property_index: Option<u32>,
pub property_id: Option<u32>,
}
impl Ball {
pub fn new(vindex: usize) -> Self {
Self {
vindex,
radius: None,
property_index: None,
property_id: None,
}
}
}
#[derive(Debug, Clone)]
pub struct BeamSet {
pub radius: f64,
pub min_length: f64,
pub cap_mode: BeamCapMode,
pub beams: Vec<Beam>,
pub clipping_mesh_id: Option<u32>,
pub representation_mesh_id: Option<u32>,
pub clipping_mode: Option<String>,
pub ball_mode: Option<String>,
pub ball_radius: Option<f64>,
pub property_id: Option<u32>,
pub property_index: Option<u32>,
pub beam_set_refs: Vec<usize>,
pub balls: Vec<Ball>,
pub ball_set_refs: Vec<usize>,
}
impl BeamSet {
pub fn new() -> Self {
Self {
radius: 1.0,
min_length: 0.0001,
cap_mode: BeamCapMode::Sphere,
beams: Vec::new(),
clipping_mesh_id: None,
representation_mesh_id: None,
clipping_mode: None,
ball_mode: None,
ball_radius: None,
property_id: None,
property_index: None,
beam_set_refs: Vec::new(),
balls: Vec::new(),
ball_set_refs: Vec::new(),
}
}
pub fn with_radius(radius: f64) -> Self {
Self {
radius,
min_length: 0.0001,
cap_mode: BeamCapMode::Sphere,
beams: Vec::new(),
clipping_mesh_id: None,
representation_mesh_id: None,
clipping_mode: None,
ball_mode: None,
ball_radius: None,
property_id: None,
property_index: None,
beam_set_refs: Vec::new(),
balls: Vec::new(),
ball_set_refs: Vec::new(),
}
}
}
impl Default for BeamSet {
fn default() -> Self {
Self::new()
}
}