dis_rs/common/is_part_of/
model.rs

1use crate::common::{BodyInfo, Interaction};
2use crate::enumerations::{IsPartOfNature, IsPartOfPosition, PduType, StationName};
3use crate::is_part_of::builder::IsPartOfBuilder;
4use crate::model::{EntityId, EntityType, PduBody, VectorF32};
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8const IS_PART_OF_BODY_LENGTH: u16 = 40;
9
10/// 5.9.5 `IsPartOf` PDU
11///
12/// 7.8.5 `IsPartOf` PDU
13#[derive(Clone, Debug, Default, PartialEq)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct IsPartOf {
16    pub originating_simulation_id: EntityId,
17    pub receiving_entity_id: EntityId,
18    pub relationship: Relationship,
19    pub part_location: VectorF32,
20    pub named_location_id: NamedLocationId,
21    pub part_type: EntityType,
22}
23
24impl IsPartOf {
25    #[must_use]
26    pub fn builder() -> IsPartOfBuilder {
27        IsPartOfBuilder::new()
28    }
29
30    #[must_use]
31    pub fn into_builder(self) -> IsPartOfBuilder {
32        IsPartOfBuilder::new_from_body(self)
33    }
34
35    #[must_use]
36    pub fn into_pdu_body(self) -> PduBody {
37        PduBody::IsPartOf(self)
38    }
39}
40
41impl BodyInfo for IsPartOf {
42    fn body_length(&self) -> u16 {
43        IS_PART_OF_BODY_LENGTH
44    }
45
46    fn body_type(&self) -> PduType {
47        PduType::IsPartOf
48    }
49}
50
51impl Interaction for IsPartOf {
52    fn originator(&self) -> Option<&EntityId> {
53        Some(&self.originating_simulation_id)
54    }
55
56    fn receiver(&self) -> Option<&EntityId> {
57        Some(&self.receiving_entity_id)
58    }
59}
60
61/// 6.2.74 Relationship record
62#[derive(Clone, Debug, Default, PartialEq)]
63#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
64pub struct Relationship {
65    pub nature: IsPartOfNature,
66    pub position: IsPartOfPosition,
67}
68
69impl Relationship {
70    #[must_use]
71    pub fn with_nature(mut self, nature: IsPartOfNature) -> Self {
72        self.nature = nature;
73        self
74    }
75
76    #[must_use]
77    pub fn with_position(mut self, position: IsPartOfPosition) -> Self {
78        self.position = position;
79        self
80    }
81}
82
83/// 6.2.62 Named Location Identification record
84#[derive(Clone, Debug, Default, PartialEq)]
85#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
86pub struct NamedLocationId {
87    pub station_name: StationName,
88    pub station_number: u16,
89}
90
91impl NamedLocationId {
92    #[must_use]
93    pub fn with_station_name(mut self, station_name: StationName) -> Self {
94        self.station_name = station_name;
95        self
96    }
97
98    #[must_use]
99    pub fn with_station_number(mut self, station_number: u16) -> Self {
100        self.station_number = station_number;
101        self
102    }
103}