diff --git a/src/object_pool/mod.rs b/src/object_pool/mod.rs index db59117..c12c414 100644 --- a/src/object_pool/mod.rs +++ b/src/object_pool/mod.rs @@ -2,1705 +2,21 @@ pub mod colour; pub mod reader; pub mod writer; +mod object; +mod object_attributes; +mod object_id; mod object_pool; +mod object_type; +mod vt_version; use crate::network_management::name::NAME; -use bitvec::field::BitField; -use bitvec::order::{Lsb0, Msb0}; -use bitvec::vec::BitVec; -use bitvec::view::BitView; pub use colour::Colour; pub use object_pool::ObjectPool; - -use strum_macros::FromRepr; -use ParseError::UnknownObjectType; +pub use object_type::ObjectType; #[derive(Debug)] pub enum ParseError { DataEmpty, UnknownObjectType, } - -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum ObjectType { - WorkingSet = 0, - DataMask = 1, - AlarmMask = 2, - Container = 3, - SoftKeyMask = 4, - Key = 5, - Button = 6, - InputBoolean = 7, - InputString = 8, - InputNumber = 9, - InputList = 10, - OutputString = 11, - OutputNumber = 12, - OutputLine = 13, - OutputRectangle = 14, - OutputEllipse = 15, - OutputPolygon = 16, - OutputMeter = 17, - OutputLinearBarGraph = 18, - OutputArchedBarGraph = 19, - PictureGraphic = 20, - NumberVariable = 21, - StringVariable = 22, - FontAttributes = 23, - LineAttributes = 24, - FillAttributes = 25, - InputAttributes = 26, - ObjectPointer = 27, - Macro = 28, - AuxiliaryFunctionType1 = 29, - AuxiliaryInputType1 = 30, - AuxiliaryFunctionType2 = 31, - AuxiliaryInputType2 = 32, - AuxiliaryControlDesignatorType2 = 33, - WindowMask = 34, - KeyGroup = 35, - GraphicsContext = 36, - OutputList = 37, - ExtendedInputAttributes = 38, - ColourMap = 39, - ObjectLabelReferenceList = 40, - ExternalObjectDefinition = 41, - ExternalReferenceName = 42, - ExternalObjectPointer = 43, - Animation = 44, - ColourPalette = 45, - GraphicData = 46, - WorkingSetSpecialControls = 47, - ScaledGraphic = 48, -} - -impl TryFrom for ObjectType { - type Error = ParseError; - - fn try_from(val: u8) -> Result { - match val { - 0 => Ok(Self::WorkingSet), - 1 => Ok(Self::DataMask), - 2 => Ok(Self::AlarmMask), - 3 => Ok(Self::Container), - 4 => Ok(Self::SoftKeyMask), - 5 => Ok(Self::Key), - 6 => Ok(Self::Button), - 7 => Ok(Self::InputBoolean), - 8 => Ok(Self::InputString), - 9 => Ok(Self::InputNumber), - 10 => Ok(Self::InputList), - 11 => Ok(Self::OutputString), - 12 => Ok(Self::OutputNumber), - 13 => Ok(Self::OutputLine), - 14 => Ok(Self::OutputRectangle), - 15 => Ok(Self::OutputEllipse), - 16 => Ok(Self::OutputPolygon), - 17 => Ok(Self::OutputMeter), - 18 => Ok(Self::OutputLinearBarGraph), - 19 => Ok(Self::OutputArchedBarGraph), - 20 => Ok(Self::PictureGraphic), - 21 => Ok(Self::NumberVariable), - 22 => Ok(Self::StringVariable), - 23 => Ok(Self::FontAttributes), - 24 => Ok(Self::LineAttributes), - 25 => Ok(Self::FillAttributes), - 26 => Ok(Self::InputAttributes), - 27 => Ok(Self::ObjectPointer), - 28 => Ok(Self::Macro), - 29 => Ok(Self::AuxiliaryFunctionType1), - 30 => Ok(Self::AuxiliaryInputType1), - 31 => Ok(Self::AuxiliaryFunctionType2), - 32 => Ok(Self::AuxiliaryInputType2), - 33 => Ok(Self::AuxiliaryControlDesignatorType2), - 34 => Ok(Self::WindowMask), - 35 => Ok(Self::KeyGroup), - 36 => Ok(Self::GraphicsContext), - 37 => Ok(Self::OutputList), - 38 => Ok(Self::ExtendedInputAttributes), - 39 => Ok(Self::ColourMap), - 40 => Ok(Self::ObjectLabelReferenceList), - 41 => Ok(Self::ExternalObjectDefinition), - 42 => Ok(Self::ExternalReferenceName), - 43 => Ok(Self::ExternalObjectPointer), - 44 => Ok(Self::Animation), - 45 => Ok(Self::ColourPalette), - 46 => Ok(Self::GraphicData), - 47 => Ok(Self::WorkingSetSpecialControls), - 48 => Ok(Self::ScaledGraphic), - _ => Err(UnknownObjectType), - } - } -} - -impl From for u8 { - fn from(val: ObjectType) -> Self { - match val { - ObjectType::WorkingSet => 0, - ObjectType::DataMask => 1, - ObjectType::AlarmMask => 2, - ObjectType::Container => 3, - ObjectType::SoftKeyMask => 4, - ObjectType::Key => 5, - ObjectType::Button => 6, - ObjectType::InputBoolean => 7, - ObjectType::InputString => 8, - ObjectType::InputNumber => 9, - ObjectType::InputList => 10, - ObjectType::OutputString => 11, - ObjectType::OutputNumber => 12, - ObjectType::OutputLine => 13, - ObjectType::OutputRectangle => 14, - ObjectType::OutputEllipse => 15, - ObjectType::OutputPolygon => 16, - ObjectType::OutputMeter => 17, - ObjectType::OutputLinearBarGraph => 18, - ObjectType::OutputArchedBarGraph => 19, - ObjectType::PictureGraphic => 20, - ObjectType::NumberVariable => 21, - ObjectType::StringVariable => 22, - ObjectType::FontAttributes => 23, - ObjectType::LineAttributes => 24, - ObjectType::FillAttributes => 25, - ObjectType::InputAttributes => 26, - ObjectType::ObjectPointer => 27, - ObjectType::Macro => 28, - ObjectType::AuxiliaryFunctionType1 => 29, - ObjectType::AuxiliaryInputType1 => 30, - ObjectType::AuxiliaryFunctionType2 => 31, - ObjectType::AuxiliaryInputType2 => 32, - ObjectType::AuxiliaryControlDesignatorType2 => 33, - ObjectType::WindowMask => 34, - ObjectType::KeyGroup => 35, - ObjectType::GraphicsContext => 36, - ObjectType::OutputList => 37, - ObjectType::ExtendedInputAttributes => 38, - ObjectType::ColourMap => 39, - ObjectType::ObjectLabelReferenceList => 40, - ObjectType::ExternalObjectDefinition => 41, - ObjectType::ExternalReferenceName => 42, - ObjectType::ExternalObjectPointer => 43, - ObjectType::Animation => 44, - ObjectType::ColourPalette => 45, - ObjectType::GraphicData => 46, - ObjectType::WorkingSetSpecialControls => 47, - ObjectType::ScaledGraphic => 48, - } - } -} - -#[derive(Debug, Default)] -pub enum VtVersion { - Version0, - Version1, - Version2, - #[default] - Version3, - Version4, - Version5, - Version6, -} - -impl From for u8 { - fn from(vt_version: VtVersion) -> Self { - match vt_version { - VtVersion::Version0 => 0, - VtVersion::Version1 => 1, - VtVersion::Version2 => 2, - VtVersion::Version3 => 3, - VtVersion::Version4 => 4, - VtVersion::Version5 => 5, - VtVersion::Version6 => 6, - } - } -} - -impl TryFrom for VtVersion { - type Error = ParseError; - - fn try_from(value: u8) -> Result { - match value { - 0 => Ok(VtVersion::Version0), - 1 => Ok(VtVersion::Version1), - 2 => Ok(VtVersion::Version2), - 3 => Ok(VtVersion::Version3), - 4 => Ok(VtVersion::Version4), - 5 => Ok(VtVersion::Version5), - 6 => Ok(VtVersion::Version6), - _ => Err(UnknownObjectType), - } - } -} - -#[derive(Debug)] -pub enum Object { - WorkingSet(WorkingSet), - DataMask(DataMask), - AlarmMask(AlarmMask), - Container(Container), - SoftKeyMask(SoftKeyMask), - Key(Key), - Button(Button), - InputBoolean(InputBoolean), - InputString(InputString), - InputNumber(InputNumber), - InputList(InputList), - OutputString(OutputString), - OutputNumber(OutputNumber), - OutputLine(OutputLine), - OutputRectangle(OutputRectangle), - OutputEllipse(OutputEllipse), - OutputPolygon(OutputPolygon), - OutputMeter(OutputMeter), - OutputLinearBarGraph(OutputLinearBarGraph), - OutputArchedBarGraph(OutputArchedBarGraph), - PictureGraphic(PictureGraphic), - NumberVariable(NumberVariable), - StringVariable(StringVariable), - FontAttributes(FontAttributes), - LineAttributes(LineAttributes), - FillAttributes(FillAttributes), - InputAttributes(InputAttributes), - ObjectPointer(ObjectPointer), - Macro(Macro), - AuxiliaryFunctionType1(AuxiliaryFunctionType1), - AuxiliaryInputType1(AuxiliaryInputType1), - AuxiliaryFunctionType2(AuxiliaryFunctionType2), - AuxiliaryInputType2(AuxiliaryInputType2), - AuxiliaryControlDesignatorType2(AuxiliaryControlDesignatorType2), - WindowMask(WindowMask), - KeyGroup(KeyGroup), - GraphicsContext(GraphicsContext), - OutputList(OutputList), - ExtendedInputAttributes(ExtendedInputAttributes), - ColourMap(ColourMap), - ObjectLabelReferenceList(ObjectLabelReferenceList), - ExternalObjectDefinition(ExternalObjectDefinition), - ExternalReferenceName(ExternalReferenceName), - ExternalObjectPointer(ExternalObjectPointer), - Animation(Animation), - ColourPalette(ColourPalette), - GraphicData(GraphicData), - WorkingSetSpecialControls(WorkingSetSpecialControls), - ScaledGraphic(ScaledGraphic), -} - -impl Object { - pub fn id(&self) -> ObjectId { - match self { - Object::WorkingSet(o) => o.id, - Object::DataMask(o) => o.id, - Object::AlarmMask(o) => o.id, - Object::Container(o) => o.id, - Object::SoftKeyMask(o) => o.id, - Object::Key(o) => o.id, - Object::Button(o) => o.id, - Object::InputBoolean(o) => o.id, - Object::InputString(o) => o.id, - Object::InputNumber(o) => o.id, - Object::InputList(o) => o.id, - Object::OutputString(o) => o.id, - Object::OutputNumber(o) => o.id, - Object::OutputLine(o) => o.id, - Object::OutputRectangle(o) => o.id, - Object::OutputEllipse(o) => o.id, - Object::OutputPolygon(o) => o.id, - Object::OutputMeter(o) => o.id, - Object::OutputLinearBarGraph(o) => o.id, - Object::OutputArchedBarGraph(o) => o.id, - Object::PictureGraphic(o) => o.id, - Object::NumberVariable(o) => o.id, - Object::StringVariable(o) => o.id, - Object::FontAttributes(o) => o.id, - Object::LineAttributes(o) => o.id, - Object::FillAttributes(o) => o.id, - Object::InputAttributes(o) => o.id, - Object::ObjectPointer(o) => o.id, - Object::Macro(o) => o.id, - Object::AuxiliaryFunctionType1(o) => o.id, - Object::AuxiliaryInputType1(o) => o.id, - Object::AuxiliaryFunctionType2(o) => o.id, - Object::AuxiliaryInputType2(o) => o.id, - Object::AuxiliaryControlDesignatorType2(o) => o.id, - Object::WindowMask(o) => o.id, - Object::KeyGroup(o) => o.id, - Object::GraphicsContext(o) => o.id, - Object::OutputList(o) => o.id, - Object::ExtendedInputAttributes(o) => o.id, - Object::ColourMap(o) => o.id, - Object::ObjectLabelReferenceList(o) => o.id, - Object::ExternalObjectDefinition(o) => o.id, - Object::ExternalReferenceName(o) => o.id, - Object::ExternalObjectPointer(o) => o.id, - Object::Animation(o) => o.id, - Object::ColourPalette(o) => o.id, - Object::GraphicData(o) => o.id, - Object::WorkingSetSpecialControls(o) => o.id, - Object::ScaledGraphic(o) => o.id, - } - } - - pub fn object_type(&self) -> ObjectType { - match self { - Object::WorkingSet(_) => ObjectType::WorkingSet, - Object::DataMask(_) => ObjectType::DataMask, - Object::AlarmMask(_) => ObjectType::AlarmMask, - Object::Container(_) => ObjectType::Container, - Object::SoftKeyMask(_) => ObjectType::SoftKeyMask, - Object::Key(_) => ObjectType::Key, - Object::Button(_) => ObjectType::Button, - Object::InputBoolean(_) => ObjectType::InputBoolean, - Object::InputString(_) => ObjectType::InputString, - Object::InputNumber(_) => ObjectType::InputNumber, - Object::InputList(_) => ObjectType::InputList, - Object::OutputString(_) => ObjectType::OutputString, - Object::OutputNumber(_) => ObjectType::OutputNumber, - Object::OutputLine(_) => ObjectType::OutputLine, - Object::OutputRectangle(_) => ObjectType::OutputRectangle, - Object::OutputEllipse(_) => ObjectType::OutputEllipse, - Object::OutputPolygon(_) => ObjectType::OutputPolygon, - Object::OutputMeter(_) => ObjectType::OutputMeter, - Object::OutputLinearBarGraph(_) => ObjectType::OutputLinearBarGraph, - Object::OutputArchedBarGraph(_) => ObjectType::OutputArchedBarGraph, - Object::PictureGraphic(_) => ObjectType::PictureGraphic, - Object::NumberVariable(_) => ObjectType::NumberVariable, - Object::StringVariable(_) => ObjectType::StringVariable, - Object::FontAttributes(_) => ObjectType::FontAttributes, - Object::LineAttributes(_) => ObjectType::LineAttributes, - Object::FillAttributes(_) => ObjectType::FillAttributes, - Object::InputAttributes(_) => ObjectType::InputAttributes, - Object::ObjectPointer(_) => ObjectType::ObjectPointer, - Object::Macro(_) => ObjectType::Macro, - Object::AuxiliaryFunctionType1(_) => ObjectType::AuxiliaryFunctionType1, - Object::AuxiliaryInputType1(_) => ObjectType::AuxiliaryInputType1, - Object::AuxiliaryFunctionType2(_) => ObjectType::AuxiliaryFunctionType2, - Object::AuxiliaryInputType2(_) => ObjectType::AuxiliaryInputType2, - Object::AuxiliaryControlDesignatorType2(_) => { - ObjectType::AuxiliaryControlDesignatorType2 - } - Object::WindowMask(_) => ObjectType::WindowMask, - Object::KeyGroup(_) => ObjectType::KeyGroup, - Object::GraphicsContext(_) => ObjectType::GraphicsContext, - Object::OutputList(_) => ObjectType::OutputList, - Object::ExtendedInputAttributes(_) => ObjectType::ExtendedInputAttributes, - Object::ColourMap(_) => ObjectType::ColourMap, - Object::ObjectLabelReferenceList(_) => ObjectType::ObjectLabelReferenceList, - Object::ExternalObjectDefinition(_) => ObjectType::ExternalObjectDefinition, - Object::ExternalReferenceName(_) => ObjectType::ExternalReferenceName, - Object::ExternalObjectPointer(_) => ObjectType::ExternalObjectPointer, - Object::Animation(_) => ObjectType::Animation, - Object::ColourPalette(_) => ObjectType::ColourPalette, - Object::GraphicData(_) => ObjectType::GraphicData, - Object::WorkingSetSpecialControls(_) => ObjectType::WorkingSetSpecialControls, - Object::ScaledGraphic(_) => ObjectType::ScaledGraphic, - } - } -} - -#[derive(FromRepr, Debug, PartialEq, Clone, Copy)] -#[repr(u8)] -pub enum WindowType { - FreeForm = 0, - NumericOutputValueWithUnits1x1 = 1, - NumericOutputValueNoUnits1x1 = 2, - StringOutputValue1x1 = 3, - NumericInputValueWithUnits1x1 = 4, - NumericInputValueNoUnits1x1 = 5, - StringInputValue1x1 = 6, - HorizontalLinearBarGraph1x1 = 7, - SingleButton1x1 = 8, - DoubleButton1x1 = 9, - NumericOutputValueWithUnits2x1 = 10, - NumericOutputValueNoUnits2x1 = 11, - StringOutputValue2x1 = 12, - NumericInputValueWithUnits2x1 = 13, - NumericInputValueNoUnits2x1 = 14, - StringInputValue2x1 = 15, - HorizontalLinearBarGraph2x1 = 16, - SingleButton2x1 = 17, - DoubleButton2x1 = 18, -} - -impl From for WindowType { - fn from(value: u8) -> Self { - WindowType::from_repr(value).unwrap() - } -} - -impl From for u8 { - fn from(value: WindowType) -> Self { - value.into() - } -} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum WindowMaskCellFormat { - CF1x1, - CF1x2, - CF1x3, - CF1x4, - CF1x5, - CF1x6, - CF2x1, - CF2x2, - CF2x3, - CF2x4, - CF2x5, - CF2x6, -} - -impl WindowMaskCellFormat { - const fn from_size(x: u8, y: u8) -> WindowMaskCellFormat { - let size = Point { x, y }; - match size { - Point { x: 1, y: 1 } => WindowMaskCellFormat::CF1x1, - Point { x: 1, y: 2 } => WindowMaskCellFormat::CF1x2, - Point { x: 1, y: 3 } => WindowMaskCellFormat::CF1x3, - Point { x: 1, y: 4 } => WindowMaskCellFormat::CF1x4, - Point { x: 1, y: 5 } => WindowMaskCellFormat::CF1x5, - Point { x: 1, y: 6 } => WindowMaskCellFormat::CF1x6, - Point { x: 2, y: 1 } => WindowMaskCellFormat::CF2x1, - Point { x: 2, y: 2 } => WindowMaskCellFormat::CF2x2, - Point { x: 2, y: 3 } => WindowMaskCellFormat::CF2x3, - Point { x: 2, y: 4 } => WindowMaskCellFormat::CF2x4, - Point { x: 2, y: 5 } => WindowMaskCellFormat::CF2x5, - Point { x: 2, y: 6 } => WindowMaskCellFormat::CF2x6, - _ => WindowMaskCellFormat::CF1x1, - } - } - - const fn size(self) -> Point { - match self { - WindowMaskCellFormat::CF1x1 => Point { x: 1, y: 1 }, - WindowMaskCellFormat::CF1x2 => Point { x: 1, y: 2 }, - WindowMaskCellFormat::CF1x3 => Point { x: 1, y: 3 }, - WindowMaskCellFormat::CF1x4 => Point { x: 1, y: 4 }, - WindowMaskCellFormat::CF1x5 => Point { x: 1, y: 5 }, - WindowMaskCellFormat::CF1x6 => Point { x: 1, y: 6 }, - WindowMaskCellFormat::CF2x1 => Point { x: 2, y: 1 }, - WindowMaskCellFormat::CF2x2 => Point { x: 2, y: 2 }, - WindowMaskCellFormat::CF2x3 => Point { x: 2, y: 3 }, - WindowMaskCellFormat::CF2x4 => Point { x: 2, y: 4 }, - WindowMaskCellFormat::CF2x5 => Point { x: 2, y: 5 }, - WindowMaskCellFormat::CF2x6 => Point { x: 2, y: 6 }, - } - } -} - -impl From for WindowMaskCellFormat { - fn from(value: u16) -> Self { - WindowMaskCellFormat::from_size((value << 8) as u8, value as u8) - } -} - -impl From for u16 { - fn from(value: WindowMaskCellFormat) -> Self { - let size = value.size(); - ((size.x as u16) << 8) | size.y as u16 - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct WindowMaskOptions { - pub available: bool, - pub transparent: bool, -} - -impl From for WindowMaskOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - WindowMaskOptions { - available: bit_data.pop().unwrap(), - transparent: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: WindowMaskOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.available); - bit_data.push(value.transparent); - bit_data.extend([0; 6]); - bit_data.load::() - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct ObjectId { - id: u16, -} - -impl ObjectId { - const NULL: ObjectId = ObjectId { id: u16::MAX }; - - pub fn new(id: u16) -> Result { - if id == Self::NULL.id { - Err(UnknownObjectType) - } else { - Ok(ObjectId { id }) - } - } -} - -pub struct NullableObjectId(Option); - -impl NullableObjectId { - pub const NULL: NullableObjectId = NullableObjectId(None); - pub fn new(id: u16) -> Self { - if id == ObjectId::NULL.id { - NullableObjectId(None) - } else { - NullableObjectId(Some(ObjectId::new(id).unwrap())) - } - } -} - -impl Default for NullableObjectId { - fn default() -> Self { - NullableObjectId::NULL - } -} - -impl From for NullableObjectId { - fn from(id: u16) -> Self { - NullableObjectId::new(id) - } -} - -impl From for u16 { - fn from(id: NullableObjectId) -> Self { - match id.0 { - Some(id) => id.id, - None => u16::from(ObjectId::NULL), - } - } -} - -impl From for NullableObjectId { - fn from(id: ObjectId) -> Self { - if id == ObjectId::NULL { - NullableObjectId(None) - } else { - NullableObjectId(Some(id)) - } - } -} - -impl Default for ObjectId { - fn default() -> Self { - Self::new(0).unwrap() - } -} -impl TryFrom for ObjectId { - type Error = ParseError; - - fn try_from(id: u16) -> Result { - ObjectId::new(id) - } -} - -impl From for u16 { - fn from(val: ObjectId) -> Self { - val.id - } -} -impl TryFrom<[u8; 2]> for ObjectId { - type Error = ParseError; - - fn try_from(val: [u8; 2]) -> Result { - ObjectId::new(u16::from_le_bytes(val)) - } -} -impl From for [u8; 2] { - fn from(val: ObjectId) -> Self { - val.id.to_le_bytes() - } -} -// impl From> for ObjectId { -// fn from(val: Vec) -> Self { -// let val: ObjectId = val.as_slice().into(); -// val -// } -// } -// impl From for Vec { -// fn from(val: ObjectId) -> Self { -// let val: [u8;2] = val.into(); -// val.to_vec() -// } -// } -impl TryFrom<&[u8]> for ObjectId { - type Error = ParseError; - - fn try_from(val: &[u8]) -> Result { - match val.len() { - 2.. => Ok(ObjectId::new(u16::from_le_bytes([val[0], val[1]]))?), - _ => Err(ParseError::DataEmpty), - } - } -} - -#[derive(Debug, PartialEq, Clone)] -pub struct ObjectRef { - pub id: ObjectId, - pub offset: Point, - // pub x: i16, - // pub y: i16, -} - -#[derive(Debug, PartialEq, Eq, Clone)] -pub struct MacroRef { - pub macro_id: u8, - pub event_id: u8, -} - -#[derive(Debug, Default, Clone, Copy, PartialEq)] -pub struct Point { - pub x: T, - pub y: T, -} - -impl core::ops::Add> for Point { - type Output = Point; - - fn add(self, rhs: Point) -> Self::Output { - Point { - x: (self.x as i16 + rhs.x) as u16, - y: (self.y as i16 + rhs.y) as u16, - } - } -} - -#[derive(Debug)] -pub struct ObjectLabel { - pub id: ObjectId, - pub string_variable_reference: ObjectId, - pub font_type: u8, - pub graphic_representation: ObjectId, -} - -#[derive(Debug, PartialEq)] -pub struct WorkingSet { - pub id: ObjectId, - pub background_colour: Colour, - pub selectable: bool, - pub active_mask: ObjectId, - pub object_refs: Vec, - pub macro_refs: Vec, - pub language_codes: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct DataMask { - pub id: ObjectId, - pub background_colour: u8, - pub soft_key_mask: ObjectId, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct AlarmMask { - pub id: ObjectId, - pub background_colour: u8, - pub soft_key_mask: ObjectId, - pub priority: u8, - pub acoustic_signal: u8, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct Container { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub hidden: bool, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct SoftKeyMask { - pub id: ObjectId, - pub background_colour: u8, - pub objects: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct Key { - pub id: ObjectId, - pub background_colour: u8, - pub key_code: u8, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct Button { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub background_colour: u8, - pub border_colour: u8, - pub key_code: u8, - pub options: ButtonOptions, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -pub enum ButtonState { - RELEASED, - LATCHED, -} - -impl From for bool { - fn from(value: ButtonState) -> Self { - match value { - ButtonState::RELEASED => false, - ButtonState::LATCHED => true, - } - } -} - -impl From for ButtonState { - fn from(value: bool) -> Self { - match value { - false => ButtonState::RELEASED, - true => ButtonState::LATCHED, - } - } -} - -#[derive(Debug, PartialEq, Clone, Copy)] -pub struct ButtonOptions { - pub latchable: bool, - pub state: ButtonState, - pub suppress_border: bool, - pub transparent_background: bool, - pub disabled: bool, - pub no_border: bool, -} - -impl From for ButtonOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - ButtonOptions { - latchable: bit_data.pop().unwrap(), - state: bit_data.pop().unwrap().into(), - suppress_border: bit_data.pop().unwrap(), - transparent_background: bit_data.pop().unwrap(), - disabled: bit_data.pop().unwrap(), - no_border: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: ButtonOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.latchable); - bit_data.push(value.state.into()); - bit_data.push(value.suppress_border); - bit_data.push(value.transparent_background); - bit_data.push(value.disabled); - bit_data.push(value.no_border); - bit_data.extend([0; 3]); - bit_data.load::() - } -} - -#[derive(Debug, PartialEq)] -pub struct InputBoolean { - pub id: ObjectId, - pub background_colour: u8, - pub width: u16, - pub foreground_colour: ObjectId, - pub variable_reference: ObjectId, - pub value: bool, - pub enabled: bool, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq)] -pub struct InputString { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub background_colour: u8, - pub font_attributes: ObjectId, - pub input_attributes: ObjectId, - pub options: InputStringOptions, - pub variable_reference: ObjectId, - pub justification: Alignment, - pub value: String, - pub enabled: bool, - pub macro_refs: Vec, -} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct Alignment { - pub horizontal: HorizontalAlignment, - pub vertical: VerticalAlignment, -} - -impl From for Alignment { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - Alignment { - horizontal: HorizontalAlignment::from([ - bit_data.pop().unwrap(), - bit_data.pop().unwrap(), - ]), - vertical: VerticalAlignment::from([bit_data.pop().unwrap(), bit_data.pop().unwrap()]), - } - } -} - -impl From for u8 { - fn from(value: Alignment) -> Self { - let mut bit_data: BitVec = BitVec::new(); - let horizontal_align: [bool; 2] = value.horizontal.into(); - let vertical_align: [bool; 2] = value.vertical.into(); - - bit_data.push(horizontal_align[0]); - bit_data.push(horizontal_align[1]); - - bit_data.push(vertical_align[0]); - bit_data.push(vertical_align[1]); - - bit_data.load::() - } -} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum HorizontalAlignment { - Left = 0, - Middle = 1, - Right = 2, - Reserved = 3, -} - -impl From<[bool; 2]> for HorizontalAlignment { - fn from(value: [bool; 2]) -> Self { - match value[0] { - false => match value[1] { - false => HorizontalAlignment::Left, - true => HorizontalAlignment::Middle, - }, - true => match value[1] { - false => HorizontalAlignment::Middle, - true => HorizontalAlignment::Reserved, - }, - } - } -} - -impl From for [bool; 2] { - fn from(value: HorizontalAlignment) -> Self { - match value { - HorizontalAlignment::Left => [false, false], - HorizontalAlignment::Middle => [false, true], - HorizontalAlignment::Right => [true, false], - HorizontalAlignment::Reserved => [true, true], - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum VerticalAlignment { - Top = 0, - Middle = 1, - Bottom = 2, - Reserved = 3, -} - -impl From<[bool; 2]> for VerticalAlignment { - fn from(value: [bool; 2]) -> Self { - match value[0] { - false => match value[1] { - false => VerticalAlignment::Top, - true => VerticalAlignment::Middle, - }, - true => match value[1] { - false => VerticalAlignment::Bottom, - true => VerticalAlignment::Reserved, - }, - } - } -} - -impl From for [bool; 2] { - fn from(value: VerticalAlignment) -> Self { - match value { - VerticalAlignment::Top => [false, false], - VerticalAlignment::Middle => [false, true], - VerticalAlignment::Bottom => [true, false], - VerticalAlignment::Reserved => [true, true], - } - } -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub struct InputStringOptions { - pub transparent: bool, - pub auto_wrap: bool, - pub wrap_on_hyphen: bool, -} - -impl From for InputStringOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - InputStringOptions { - transparent: bit_data.pop().unwrap(), - auto_wrap: bit_data.pop().unwrap(), - wrap_on_hyphen: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: InputStringOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.transparent); - bit_data.push(value.auto_wrap); - bit_data.push(value.wrap_on_hyphen); - bit_data.extend([0; 5]); - bit_data.load::() - } -} - -#[derive(Debug, Clone, PartialEq)] -pub struct InputNumber { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub background_colour: u8, - pub font_attributes: ObjectId, - pub options: NumberOptions, - pub variable_reference: ObjectId, - pub value: u32, - pub min_value: u32, - pub max_value: u32, - pub offset: i32, - pub scale: f32, - pub nr_of_decimals: u8, - pub format: FormatType, - pub justification: Alignment, - pub options2: InputNumberOptions, - pub macro_refs: Vec, -} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct InputNumberOptions { - pub enabled: bool, - pub real_time_editing: bool, -} - -impl From for InputNumberOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - InputNumberOptions { - enabled: bit_data.pop().unwrap(), - real_time_editing: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: InputNumberOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.enabled); - bit_data.push(value.real_time_editing); - bit_data.extend([0; 6]); - bit_data.load::() - } -} - -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum FormatType { - Decimal, - Exponential, -} - -impl From for FormatType { - fn from(value: bool) -> Self { - match value { - false => FormatType::Decimal, - true => FormatType::Exponential, - } - } -} - -impl From for bool { - fn from(value: FormatType) -> Self { - match value { - FormatType::Decimal => false, - FormatType::Exponential => true, - } - } -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub struct InputListOptions { - pub enabled: bool, - pub real_time_editing: bool, -} - -impl From for InputListOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - InputListOptions { - enabled: bit_data.pop().unwrap(), - real_time_editing: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: InputListOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.enabled); - bit_data.push(value.real_time_editing); - bit_data.extend([0; 6]); - bit_data.load::() - } -} - -#[derive(Debug, PartialEq, Clone)] -pub struct InputList { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub variable_reference: ObjectId, - pub value: u8, - pub options: InputListOptions, - pub list_items: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub struct OutputStringOptions { - pub transparent: bool, - pub auto_wrap: bool, - pub wrap_on_hyphen: bool, -} - -impl From for OutputStringOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - OutputStringOptions { - transparent: bit_data.pop().unwrap(), - auto_wrap: bit_data.pop().unwrap(), - wrap_on_hyphen: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: OutputStringOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.transparent); - bit_data.push(value.auto_wrap); - bit_data.push(value.wrap_on_hyphen); - bit_data.extend([0; 5]); - bit_data.load::() - } -} - -#[derive(Debug, PartialEq, Clone)] -pub struct OutputString { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub background_colour: u8, - pub font_attributes: ObjectId, - pub options: OutputStringOptions, - pub variable_reference: ObjectId, - pub justification: Alignment, - pub value: String, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq, Clone, Copy)] -pub struct NumberOptions { - pub transparent: bool, - pub display_leading_zeros: bool, - pub display_zero_as_blank: bool, - pub truncate: bool, -} - -impl From for NumberOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - NumberOptions { - transparent: bit_data.pop().unwrap(), - display_leading_zeros: bit_data.pop().unwrap(), - display_zero_as_blank: bit_data.pop().unwrap(), - truncate: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: NumberOptions) -> Self { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.transparent); - bit_data.push(value.display_leading_zeros); - bit_data.push(value.display_zero_as_blank); - bit_data.push(value.truncate); - bit_data.extend([0; 4]); - bit_data.load::() - } -} - -#[derive(Debug, PartialEq)] -pub struct OutputNumber { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub background_colour: u8, - pub font_attributes: ObjectId, - pub options: NumberOptions, - pub variable_reference: ObjectId, - pub value: u32, - pub offset: i32, - pub scale: f32, - pub nr_of_decimals: u8, - pub format: FormatType, - pub justification: Alignment, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct OutputList { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub variable_reference: ObjectId, - pub value: u8, - pub list_items: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub enum LineDirection { - TopLeftToBottomRight, - BottomLeftToTopRight, -} - -impl From for LineDirection { - fn from(value: u8) -> Self { - match value { - 0 => LineDirection::TopLeftToBottomRight, - 1 => LineDirection::BottomLeftToTopRight, - _ => panic!("Invalid line direction"), - } - } -} - -impl From for u8 { - fn from(value: LineDirection) -> Self { - match value { - LineDirection::TopLeftToBottomRight => 0, - LineDirection::BottomLeftToTopRight => 1, - } - } -} - -#[derive(Debug, PartialEq, Clone)] -pub struct OutputLine { - pub id: ObjectId, - pub line_attributes: ObjectId, - pub width: u16, - pub height: u16, - pub line_direction: LineDirection, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct OutputRectangle { - pub id: ObjectId, - pub line_attributes: ObjectId, - pub width: u16, - pub height: u16, - pub line_suppression: u8, - pub fill_attributes: ObjectId, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct OutputEllipse { - pub id: ObjectId, - pub line_attributes: ObjectId, - pub width: u16, - pub height: u16, - pub ellipse_type: u8, - pub start_angle: u8, - pub end_angle: u8, - pub fill_attributes: ObjectId, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct OutputPolygon { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub line_attributes: ObjectId, - pub fill_attributes: ObjectId, - pub polygon_type: u8, - pub points: Vec>, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct OutputMeter { - pub id: ObjectId, - pub width: u16, - pub needle_colour: u8, - pub border_colour: u8, - pub arc_and_tick_colour: u8, - pub options: u8, - pub nr_of_ticks: u8, - pub start_angle: u8, - pub end_angle: u8, - pub min_value: u16, - pub max_value: u16, - pub variable_reference: ObjectId, - pub value: u16, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct OutputLinearBarGraph { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub colour: u8, - pub target_line_colour: u8, - pub options: u8, - pub nr_of_ticks: u8, - pub min_value: u16, - pub max_value: u16, - pub variable_reference: ObjectId, - pub value: u16, - pub target_value_variable_reference: ObjectId, - pub target_value: u16, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct OutputArchedBarGraph { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub colour: u8, - pub target_line_colour: u8, - pub options: u8, - pub start_angle: u8, - pub end_angle: u8, - pub bar_graph_width: u16, - pub min_value: u16, - pub max_value: u16, - pub variable_reference: ObjectId, - pub value: u16, - pub target_value_variable_reference: ObjectId, - pub target_value: u16, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct PictureGraphic { - pub id: ObjectId, - pub width: u16, - pub actual_width: u16, - pub actual_height: u16, - pub format: u8, - pub options: u8, - pub transparency_colour: u8, - pub data: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct NumberVariable { - pub id: ObjectId, - pub value: u32, -} - -#[derive(Debug)] -pub struct StringVariable { - pub id: ObjectId, - pub value: String, -} - -#[derive(Debug)] -pub struct FontAttributes { - pub id: ObjectId, - pub font_colour: u8, - pub font_size: u8, - pub font_type: u8, - pub font_style: u8, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct LineAttributes { - pub id: ObjectId, - pub line_colour: u8, - pub line_width: u8, - pub line_art: u16, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct FillAttributes { - pub id: ObjectId, - pub fill_type: u8, - pub fill_colour: u8, - pub fill_pattern: ObjectId, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct InputAttributes { - pub id: ObjectId, - pub validation_type: u8, - pub validation_string: String, - pub macro_refs: Vec, -} - -#[derive(Debug, Copy, Clone)] -pub enum ValidationType { - ValidCharacters, - InvalidCharacters, -} - -impl From for u8 { - fn from(value: ValidationType) -> Self { - match value { - ValidationType::ValidCharacters => 0, - ValidationType::InvalidCharacters => 1, - } - } -} - -impl From for ValidationType { - fn from(value: u8) -> Self { - match value { - 0 => ValidationType::ValidCharacters, - 1 => ValidationType::InvalidCharacters, - _ => panic!("Invalid validation type"), - } - } -} - -#[derive(Debug)] -pub struct CharacterRange { - pub first_character: u16, - pub last_character: u16, -} - -#[derive(Debug)] -pub struct CodePlane { - pub number: u8, - pub character_ranges: Vec, -} - -#[derive(Debug)] -pub struct ExtendedInputAttributes { - pub id: ObjectId, - pub validation_type: ValidationType, - pub code_planes: Vec, -} - -#[derive(Debug)] -pub struct ObjectPointer { - pub id: ObjectId, - pub value: ObjectId, -} - -#[derive(Debug)] -pub struct Macro { - pub id: ObjectId, - pub commands: Vec, -} - -#[derive(Debug)] -pub struct AuxiliaryFunctionType1 { - pub id: ObjectId, - pub background_colour: u8, - pub function_type: u8, - pub object_refs: Vec, -} - -#[derive(Debug)] -pub struct AuxiliaryInputType1 { - pub id: ObjectId, - pub background_colour: u8, - pub function_type: u8, - pub input_id: u8, - pub object_refs: Vec, -} - -#[derive(Debug)] -pub struct AuxiliaryFunctionType2 { - pub id: ObjectId, - pub background_colour: u8, - pub function_attributes: u8, - pub object_refs: Vec, -} - -#[derive(Debug)] -pub struct AuxiliaryInputType2 { - pub id: ObjectId, - pub background_colour: u8, - pub function_attributes: u8, - pub object_refs: Vec, -} - -#[derive(Debug)] -pub struct AuxiliaryControlDesignatorType2 { - pub id: ObjectId, - pub pointer_type: u8, - pub auxiliary_object_id: ObjectId, -} - -#[derive(Debug)] -pub struct ColourMap { - pub id: ObjectId, - pub colour_map: Vec, -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub enum ColorFormat { - ColorMonochrome, - Color4Bit, - Color8Bit, -} - -impl From for u8 { - fn from(value: ColorFormat) -> Self { - match value { - ColorFormat::ColorMonochrome => 0, - ColorFormat::Color4Bit => 1, - ColorFormat::Color8Bit => 2, - } - } -} - -impl From for ColorFormat { - fn from(value: u8) -> Self { - match value { - 0 => ColorFormat::ColorMonochrome, - 1 => ColorFormat::Color4Bit, - 2 => ColorFormat::Color8Bit, - _ => panic!("Invalid color format: {}", value), - } - } -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub enum ColorOption { - ForegroundBackground, - LineFontFill, -} - -impl From for ColorOption { - fn from(value: bool) -> Self { - match value { - false => ColorOption::ForegroundBackground, - true => ColorOption::LineFontFill, - } - } -} - -impl From for bool { - fn from(value: ColorOption) -> Self { - match value { - ColorOption::ForegroundBackground => false, - ColorOption::LineFontFill => true, - } - } -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub struct GraphicsContextOptions { - pub transparent: bool, - pub color: ColorOption, -} - -impl From for GraphicsContextOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - GraphicsContextOptions { - transparent: bit_data.pop().unwrap(), - color: bit_data.pop().unwrap().into(), - } - } -} - -impl From for u8 { - fn from(value: GraphicsContextOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.transparent); - bit_data.push(value.color.into()); - bit_data.extend([0; 6]); - bit_data.load::() - } -} - -#[derive(Debug, PartialEq, Copy, Clone)] -pub struct GraphicsContext { - pub id: ObjectId, - pub viewport_width: u16, - pub viewport_height: u16, - pub viewport_x: i16, - pub viewport_y: i16, - pub canvas_width: u16, - pub canvas_height: u16, - pub viewport_zoom: f32, - pub graphics_cursor_x: i16, - pub graphics_cursor_y: i16, - pub foreground_colour: u8, - pub background_colour: u8, - pub font_attributes_object: ObjectId, - pub line_attributes_object: ObjectId, - pub fill_attributes_object: ObjectId, - pub format: ColorFormat, - pub options: GraphicsContextOptions, - pub transparency_colour: u8, -} - -#[derive(Debug, Clone, PartialEq)] -pub struct WindowMask { - pub id: ObjectId, - pub cell_format: WindowMaskCellFormat, - pub window_type: WindowType, - pub background_colour: u8, - pub options: WindowMaskOptions, - pub name: ObjectId, - pub window_title: ObjectId, - pub window_icon: ObjectId, - pub objects: Vec, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct KeyGroupOptions { - pub available: bool, - pub transparent: bool, -} - -impl From for KeyGroupOptions { - fn from(value: u8) -> Self { - let mut bit_data = value.view_bits::().to_bitvec(); - KeyGroupOptions { - available: bit_data.pop().unwrap(), - transparent: bit_data.pop().unwrap(), - } - } -} - -impl From for u8 { - fn from(value: KeyGroupOptions) -> u8 { - let mut bit_data: BitVec = BitVec::new(); - bit_data.push(value.available); - bit_data.push(value.transparent); - bit_data.extend([0; 6]); - bit_data.load::() - } -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct KeyGroup { - pub id: ObjectId, - pub options: KeyGroupOptions, - pub name: ObjectId, - pub key_group_icon: ObjectId, - pub objects: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct ObjectLabelReferenceList { - pub id: ObjectId, - pub object_labels: Vec, -} - -#[derive(Debug)] -pub struct ExternalObjectDefinition { - pub id: ObjectId, - pub options: u8, - pub name: NAME, - pub objects: Vec, -} - -#[derive(Debug)] -pub struct ExternalReferenceName { - pub id: ObjectId, - pub options: u8, - pub name: NAME, -} - -#[derive(Debug)] -pub struct ExternalObjectPointer { - pub id: ObjectId, - pub default_object_id: ObjectId, - pub external_reference_name_id: ObjectId, - pub external_object_id: ObjectId, -} - -#[derive(Debug)] -pub struct Animation { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub refresh_interval: u16, - pub value: u8, - pub enabled: bool, - pub first_child_index: u8, - pub last_child_index: u8, - pub default_child_index: u8, - pub options: u8, - pub object_refs: Vec, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct ColourPalette { - pub id: ObjectId, - pub options: u16, - pub colours: Vec, -} - -#[derive(Debug)] -pub struct GraphicData { - pub id: ObjectId, - pub format: u8, - pub data: Vec, -} - -#[derive(Debug)] -pub struct ScaledGraphic { - pub id: ObjectId, - pub width: u16, - pub height: u16, - pub scale_type: u8, - pub options: u8, - pub value: u16, - pub macro_refs: Vec, -} - -#[derive(Debug)] -pub struct WorkingSetSpecialControls { - pub id: ObjectId, - pub id_of_colour_map: ObjectId, - pub id_of_colour_palette: ObjectId, - pub language_pairs: Vec<(String, String)>, -} diff --git a/src/object_pool/object.rs b/src/object_pool/object.rs new file mode 100644 index 0000000..da3b369 --- /dev/null +++ b/src/object_pool/object.rs @@ -0,0 +1,1200 @@ +use crate::network_management::name::NAME; +use crate::object_pool::object_attributes::{ + MacroRef, ObjectLabel, ObjectRef, Point, WindowMaskCellFormat, WindowMaskOptions, WindowType, +}; +use crate::object_pool::object_id::ObjectId; +use crate::object_pool::{Colour, ObjectType}; +use bitvec::field::BitField; +use bitvec::order::{Lsb0, Msb0}; +use bitvec::vec::BitVec; +use bitvec::view::BitView; + +#[derive(Debug)] +pub enum Object { + WorkingSet(WorkingSet), + DataMask(DataMask), + AlarmMask(AlarmMask), + Container(Container), + SoftKeyMask(SoftKeyMask), + Key(Key), + Button(Button), + InputBoolean(InputBoolean), + InputString(InputString), + InputNumber(InputNumber), + InputList(InputList), + OutputString(OutputString), + OutputNumber(OutputNumber), + OutputLine(OutputLine), + OutputRectangle(OutputRectangle), + OutputEllipse(OutputEllipse), + OutputPolygon(OutputPolygon), + OutputMeter(OutputMeter), + OutputLinearBarGraph(OutputLinearBarGraph), + OutputArchedBarGraph(OutputArchedBarGraph), + PictureGraphic(PictureGraphic), + NumberVariable(NumberVariable), + StringVariable(StringVariable), + FontAttributes(FontAttributes), + LineAttributes(LineAttributes), + FillAttributes(FillAttributes), + InputAttributes(InputAttributes), + ObjectPointer(ObjectPointer), + Macro(Macro), + AuxiliaryFunctionType1(AuxiliaryFunctionType1), + AuxiliaryInputType1(AuxiliaryInputType1), + AuxiliaryFunctionType2(AuxiliaryFunctionType2), + AuxiliaryInputType2(AuxiliaryInputType2), + AuxiliaryControlDesignatorType2(AuxiliaryControlDesignatorType2), + WindowMask(WindowMask), + KeyGroup(KeyGroup), + GraphicsContext(GraphicsContext), + OutputList(OutputList), + ExtendedInputAttributes(ExtendedInputAttributes), + ColourMap(ColourMap), + ObjectLabelReferenceList(ObjectLabelReferenceList), + ExternalObjectDefinition(ExternalObjectDefinition), + ExternalReferenceName(ExternalReferenceName), + ExternalObjectPointer(ExternalObjectPointer), + Animation(Animation), + ColourPalette(ColourPalette), + GraphicData(GraphicData), + WorkingSetSpecialControls(WorkingSetSpecialControls), + ScaledGraphic(ScaledGraphic), +} + +impl Object { + pub fn id(&self) -> ObjectId { + match self { + Object::WorkingSet(o) => o.id, + Object::DataMask(o) => o.id, + Object::AlarmMask(o) => o.id, + Object::Container(o) => o.id, + Object::SoftKeyMask(o) => o.id, + Object::Key(o) => o.id, + Object::Button(o) => o.id, + Object::InputBoolean(o) => o.id, + Object::InputString(o) => o.id, + Object::InputNumber(o) => o.id, + Object::InputList(o) => o.id, + Object::OutputString(o) => o.id, + Object::OutputNumber(o) => o.id, + Object::OutputLine(o) => o.id, + Object::OutputRectangle(o) => o.id, + Object::OutputEllipse(o) => o.id, + Object::OutputPolygon(o) => o.id, + Object::OutputMeter(o) => o.id, + Object::OutputLinearBarGraph(o) => o.id, + Object::OutputArchedBarGraph(o) => o.id, + Object::PictureGraphic(o) => o.id, + Object::NumberVariable(o) => o.id, + Object::StringVariable(o) => o.id, + Object::FontAttributes(o) => o.id, + Object::LineAttributes(o) => o.id, + Object::FillAttributes(o) => o.id, + Object::InputAttributes(o) => o.id, + Object::ObjectPointer(o) => o.id, + Object::Macro(o) => o.id, + Object::AuxiliaryFunctionType1(o) => o.id, + Object::AuxiliaryInputType1(o) => o.id, + Object::AuxiliaryFunctionType2(o) => o.id, + Object::AuxiliaryInputType2(o) => o.id, + Object::AuxiliaryControlDesignatorType2(o) => o.id, + Object::WindowMask(o) => o.id, + Object::KeyGroup(o) => o.id, + Object::GraphicsContext(o) => o.id, + Object::OutputList(o) => o.id, + Object::ExtendedInputAttributes(o) => o.id, + Object::ColourMap(o) => o.id, + Object::ObjectLabelReferenceList(o) => o.id, + Object::ExternalObjectDefinition(o) => o.id, + Object::ExternalReferenceName(o) => o.id, + Object::ExternalObjectPointer(o) => o.id, + Object::Animation(o) => o.id, + Object::ColourPalette(o) => o.id, + Object::GraphicData(o) => o.id, + Object::WorkingSetSpecialControls(o) => o.id, + Object::ScaledGraphic(o) => o.id, + } + } + + pub fn object_type(&self) -> ObjectType { + match self { + Object::WorkingSet(_) => ObjectType::WorkingSet, + Object::DataMask(_) => ObjectType::DataMask, + Object::AlarmMask(_) => ObjectType::AlarmMask, + Object::Container(_) => ObjectType::Container, + Object::SoftKeyMask(_) => ObjectType::SoftKeyMask, + Object::Key(_) => ObjectType::Key, + Object::Button(_) => ObjectType::Button, + Object::InputBoolean(_) => ObjectType::InputBoolean, + Object::InputString(_) => ObjectType::InputString, + Object::InputNumber(_) => ObjectType::InputNumber, + Object::InputList(_) => ObjectType::InputList, + Object::OutputString(_) => ObjectType::OutputString, + Object::OutputNumber(_) => ObjectType::OutputNumber, + Object::OutputLine(_) => ObjectType::OutputLine, + Object::OutputRectangle(_) => ObjectType::OutputRectangle, + Object::OutputEllipse(_) => ObjectType::OutputEllipse, + Object::OutputPolygon(_) => ObjectType::OutputPolygon, + Object::OutputMeter(_) => ObjectType::OutputMeter, + Object::OutputLinearBarGraph(_) => ObjectType::OutputLinearBarGraph, + Object::OutputArchedBarGraph(_) => ObjectType::OutputArchedBarGraph, + Object::PictureGraphic(_) => ObjectType::PictureGraphic, + Object::NumberVariable(_) => ObjectType::NumberVariable, + Object::StringVariable(_) => ObjectType::StringVariable, + Object::FontAttributes(_) => ObjectType::FontAttributes, + Object::LineAttributes(_) => ObjectType::LineAttributes, + Object::FillAttributes(_) => ObjectType::FillAttributes, + Object::InputAttributes(_) => ObjectType::InputAttributes, + Object::ObjectPointer(_) => ObjectType::ObjectPointer, + Object::Macro(_) => ObjectType::Macro, + Object::AuxiliaryFunctionType1(_) => ObjectType::AuxiliaryFunctionType1, + Object::AuxiliaryInputType1(_) => ObjectType::AuxiliaryInputType1, + Object::AuxiliaryFunctionType2(_) => ObjectType::AuxiliaryFunctionType2, + Object::AuxiliaryInputType2(_) => ObjectType::AuxiliaryInputType2, + Object::AuxiliaryControlDesignatorType2(_) => { + ObjectType::AuxiliaryControlDesignatorType2 + } + Object::WindowMask(_) => ObjectType::WindowMask, + Object::KeyGroup(_) => ObjectType::KeyGroup, + Object::GraphicsContext(_) => ObjectType::GraphicsContext, + Object::OutputList(_) => ObjectType::OutputList, + Object::ExtendedInputAttributes(_) => ObjectType::ExtendedInputAttributes, + Object::ColourMap(_) => ObjectType::ColourMap, + Object::ObjectLabelReferenceList(_) => ObjectType::ObjectLabelReferenceList, + Object::ExternalObjectDefinition(_) => ObjectType::ExternalObjectDefinition, + Object::ExternalReferenceName(_) => ObjectType::ExternalReferenceName, + Object::ExternalObjectPointer(_) => ObjectType::ExternalObjectPointer, + Object::Animation(_) => ObjectType::Animation, + Object::ColourPalette(_) => ObjectType::ColourPalette, + Object::GraphicData(_) => ObjectType::GraphicData, + Object::WorkingSetSpecialControls(_) => ObjectType::WorkingSetSpecialControls, + Object::ScaledGraphic(_) => ObjectType::ScaledGraphic, + } + } +} + +#[derive(Debug, PartialEq)] +pub struct WorkingSet { + pub id: ObjectId, + pub background_colour: Colour, + pub selectable: bool, + pub active_mask: ObjectId, + pub object_refs: Vec, + pub macro_refs: Vec, + pub language_codes: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct DataMask { + pub id: ObjectId, + pub background_colour: u8, + pub soft_key_mask: ObjectId, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct AlarmMask { + pub id: ObjectId, + pub background_colour: u8, + pub soft_key_mask: ObjectId, + pub priority: u8, + pub acoustic_signal: u8, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct Container { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub hidden: bool, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct SoftKeyMask { + pub id: ObjectId, + pub background_colour: u8, + pub objects: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct Key { + pub id: ObjectId, + pub background_colour: u8, + pub key_code: u8, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct Button { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub background_colour: u8, + pub border_colour: u8, + pub key_code: u8, + pub options: ButtonOptions, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +pub enum ButtonState { + RELEASED, + LATCHED, +} + +impl From for bool { + fn from(value: ButtonState) -> Self { + match value { + ButtonState::RELEASED => false, + ButtonState::LATCHED => true, + } + } +} + +impl From for ButtonState { + fn from(value: bool) -> Self { + match value { + false => ButtonState::RELEASED, + true => ButtonState::LATCHED, + } + } +} + +#[derive(Debug, PartialEq, Clone, Copy)] +pub struct ButtonOptions { + pub latchable: bool, + pub state: ButtonState, + pub suppress_border: bool, + pub transparent_background: bool, + pub disabled: bool, + pub no_border: bool, +} + +impl From for ButtonOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + ButtonOptions { + latchable: bit_data.pop().unwrap(), + state: bit_data.pop().unwrap().into(), + suppress_border: bit_data.pop().unwrap(), + transparent_background: bit_data.pop().unwrap(), + disabled: bit_data.pop().unwrap(), + no_border: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: ButtonOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.latchable); + bit_data.push(value.state.into()); + bit_data.push(value.suppress_border); + bit_data.push(value.transparent_background); + bit_data.push(value.disabled); + bit_data.push(value.no_border); + bit_data.extend([0; 3]); + bit_data.load::() + } +} + +#[derive(Debug, PartialEq)] +pub struct InputBoolean { + pub id: ObjectId, + pub background_colour: u8, + pub width: u16, + pub foreground_colour: ObjectId, + pub variable_reference: ObjectId, + pub value: bool, + pub enabled: bool, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq)] +pub struct InputString { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub background_colour: u8, + pub font_attributes: ObjectId, + pub input_attributes: ObjectId, + pub options: InputStringOptions, + pub variable_reference: ObjectId, + pub justification: Alignment, + pub value: String, + pub enabled: bool, + pub macro_refs: Vec, +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct Alignment { + pub horizontal: HorizontalAlignment, + pub vertical: VerticalAlignment, +} + +impl From for Alignment { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + Alignment { + horizontal: HorizontalAlignment::from([ + bit_data.pop().unwrap(), + bit_data.pop().unwrap(), + ]), + vertical: VerticalAlignment::from([bit_data.pop().unwrap(), bit_data.pop().unwrap()]), + } + } +} + +impl From for u8 { + fn from(value: Alignment) -> Self { + let mut bit_data: BitVec = BitVec::new(); + let horizontal_align: [bool; 2] = value.horizontal.into(); + let vertical_align: [bool; 2] = value.vertical.into(); + + bit_data.push(horizontal_align[0]); + bit_data.push(horizontal_align[1]); + + bit_data.push(vertical_align[0]); + bit_data.push(vertical_align[1]); + + bit_data.load::() + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum HorizontalAlignment { + Left = 0, + Middle = 1, + Right = 2, + Reserved = 3, +} + +impl From<[bool; 2]> for HorizontalAlignment { + fn from(value: [bool; 2]) -> Self { + match value[0] { + false => match value[1] { + false => HorizontalAlignment::Left, + true => HorizontalAlignment::Middle, + }, + true => match value[1] { + false => HorizontalAlignment::Middle, + true => HorizontalAlignment::Reserved, + }, + } + } +} + +impl From for [bool; 2] { + fn from(value: HorizontalAlignment) -> Self { + match value { + HorizontalAlignment::Left => [false, false], + HorizontalAlignment::Middle => [false, true], + HorizontalAlignment::Right => [true, false], + HorizontalAlignment::Reserved => [true, true], + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum VerticalAlignment { + Top = 0, + Middle = 1, + Bottom = 2, + Reserved = 3, +} + +impl From<[bool; 2]> for VerticalAlignment { + fn from(value: [bool; 2]) -> Self { + match value[0] { + false => match value[1] { + false => VerticalAlignment::Top, + true => VerticalAlignment::Middle, + }, + true => match value[1] { + false => VerticalAlignment::Bottom, + true => VerticalAlignment::Reserved, + }, + } + } +} + +impl From for [bool; 2] { + fn from(value: VerticalAlignment) -> Self { + match value { + VerticalAlignment::Top => [false, false], + VerticalAlignment::Middle => [false, true], + VerticalAlignment::Bottom => [true, false], + VerticalAlignment::Reserved => [true, true], + } + } +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct InputStringOptions { + pub transparent: bool, + pub auto_wrap: bool, + pub wrap_on_hyphen: bool, +} + +impl From for InputStringOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + InputStringOptions { + transparent: bit_data.pop().unwrap(), + auto_wrap: bit_data.pop().unwrap(), + wrap_on_hyphen: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: InputStringOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.transparent); + bit_data.push(value.auto_wrap); + bit_data.push(value.wrap_on_hyphen); + bit_data.extend([0; 5]); + bit_data.load::() + } +} + +#[derive(Debug, Clone, PartialEq)] +pub struct InputNumber { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub background_colour: u8, + pub font_attributes: ObjectId, + pub options: NumberOptions, + pub variable_reference: ObjectId, + pub value: u32, + pub min_value: u32, + pub max_value: u32, + pub offset: i32, + pub scale: f32, + pub nr_of_decimals: u8, + pub format: FormatType, + pub justification: Alignment, + pub options2: InputNumberOptions, + pub macro_refs: Vec, +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub struct InputNumberOptions { + pub enabled: bool, + pub real_time_editing: bool, +} + +impl From for InputNumberOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + InputNumberOptions { + enabled: bit_data.pop().unwrap(), + real_time_editing: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: InputNumberOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.enabled); + bit_data.push(value.real_time_editing); + bit_data.extend([0; 6]); + bit_data.load::() + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum FormatType { + Decimal, + Exponential, +} + +impl From for FormatType { + fn from(value: bool) -> Self { + match value { + false => FormatType::Decimal, + true => FormatType::Exponential, + } + } +} + +impl From for bool { + fn from(value: FormatType) -> Self { + match value { + FormatType::Decimal => false, + FormatType::Exponential => true, + } + } +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct InputListOptions { + pub enabled: bool, + pub real_time_editing: bool, +} + +impl From for InputListOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + InputListOptions { + enabled: bit_data.pop().unwrap(), + real_time_editing: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: InputListOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.enabled); + bit_data.push(value.real_time_editing); + bit_data.extend([0; 6]); + bit_data.load::() + } +} + +#[derive(Debug, PartialEq, Clone)] +pub struct InputList { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub variable_reference: ObjectId, + pub value: u8, + pub options: InputListOptions, + pub list_items: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct OutputStringOptions { + pub transparent: bool, + pub auto_wrap: bool, + pub wrap_on_hyphen: bool, +} + +impl From for OutputStringOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + OutputStringOptions { + transparent: bit_data.pop().unwrap(), + auto_wrap: bit_data.pop().unwrap(), + wrap_on_hyphen: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: OutputStringOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.transparent); + bit_data.push(value.auto_wrap); + bit_data.push(value.wrap_on_hyphen); + bit_data.extend([0; 5]); + bit_data.load::() + } +} + +#[derive(Debug, PartialEq, Clone)] +pub struct OutputString { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub background_colour: u8, + pub font_attributes: ObjectId, + pub options: OutputStringOptions, + pub variable_reference: ObjectId, + pub justification: Alignment, + pub value: String, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq, Clone, Copy)] +pub struct NumberOptions { + pub transparent: bool, + pub display_leading_zeros: bool, + pub display_zero_as_blank: bool, + pub truncate: bool, +} + +impl From for NumberOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + NumberOptions { + transparent: bit_data.pop().unwrap(), + display_leading_zeros: bit_data.pop().unwrap(), + display_zero_as_blank: bit_data.pop().unwrap(), + truncate: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: NumberOptions) -> Self { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.transparent); + bit_data.push(value.display_leading_zeros); + bit_data.push(value.display_zero_as_blank); + bit_data.push(value.truncate); + bit_data.extend([0; 4]); + bit_data.load::() + } +} + +#[derive(Debug, PartialEq)] +pub struct OutputNumber { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub background_colour: u8, + pub font_attributes: ObjectId, + pub options: NumberOptions, + pub variable_reference: ObjectId, + pub value: u32, + pub offset: i32, + pub scale: f32, + pub nr_of_decimals: u8, + pub format: FormatType, + pub justification: Alignment, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq, Clone)] +pub struct OutputList { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub variable_reference: ObjectId, + pub value: u8, + pub list_items: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum LineDirection { + TopLeftToBottomRight, + BottomLeftToTopRight, +} + +impl From for LineDirection { + fn from(value: u8) -> Self { + match value { + 0 => LineDirection::TopLeftToBottomRight, + 1 => LineDirection::BottomLeftToTopRight, + _ => panic!("Invalid line direction"), + } + } +} + +impl From for u8 { + fn from(value: LineDirection) -> Self { + match value { + LineDirection::TopLeftToBottomRight => 0, + LineDirection::BottomLeftToTopRight => 1, + } + } +} + +#[derive(Debug, PartialEq, Clone)] +pub struct OutputLine { + pub id: ObjectId, + pub line_attributes: ObjectId, + pub width: u16, + pub height: u16, + pub line_direction: LineDirection, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct OutputRectangle { + pub id: ObjectId, + pub line_attributes: ObjectId, + pub width: u16, + pub height: u16, + pub line_suppression: u8, + pub fill_attributes: ObjectId, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct OutputEllipse { + pub id: ObjectId, + pub line_attributes: ObjectId, + pub width: u16, + pub height: u16, + pub ellipse_type: u8, + pub start_angle: u8, + pub end_angle: u8, + pub fill_attributes: ObjectId, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct OutputPolygon { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub line_attributes: ObjectId, + pub fill_attributes: ObjectId, + pub polygon_type: u8, + pub points: Vec>, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct OutputMeter { + pub id: ObjectId, + pub width: u16, + pub needle_colour: u8, + pub border_colour: u8, + pub arc_and_tick_colour: u8, + pub options: u8, + pub nr_of_ticks: u8, + pub start_angle: u8, + pub end_angle: u8, + pub min_value: u16, + pub max_value: u16, + pub variable_reference: ObjectId, + pub value: u16, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct OutputLinearBarGraph { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub colour: u8, + pub target_line_colour: u8, + pub options: u8, + pub nr_of_ticks: u8, + pub min_value: u16, + pub max_value: u16, + pub variable_reference: ObjectId, + pub value: u16, + pub target_value_variable_reference: ObjectId, + pub target_value: u16, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct OutputArchedBarGraph { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub colour: u8, + pub target_line_colour: u8, + pub options: u8, + pub start_angle: u8, + pub end_angle: u8, + pub bar_graph_width: u16, + pub min_value: u16, + pub max_value: u16, + pub variable_reference: ObjectId, + pub value: u16, + pub target_value_variable_reference: ObjectId, + pub target_value: u16, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct PictureGraphic { + pub id: ObjectId, + pub width: u16, + pub actual_width: u16, + pub actual_height: u16, + pub format: u8, + pub options: u8, + pub transparency_colour: u8, + pub data: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct NumberVariable { + pub id: ObjectId, + pub value: u32, +} + +#[derive(Debug)] +pub struct StringVariable { + pub id: ObjectId, + pub value: String, +} + +#[derive(Debug)] +pub struct FontAttributes { + pub id: ObjectId, + pub font_colour: u8, + pub font_size: u8, + pub font_type: u8, + pub font_style: u8, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct LineAttributes { + pub id: ObjectId, + pub line_colour: u8, + pub line_width: u8, + pub line_art: u16, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct FillAttributes { + pub id: ObjectId, + pub fill_type: u8, + pub fill_colour: u8, + pub fill_pattern: ObjectId, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct InputAttributes { + pub id: ObjectId, + pub validation_type: u8, + pub validation_string: String, + pub macro_refs: Vec, +} + +#[derive(Debug, Copy, Clone)] +pub enum ValidationType { + ValidCharacters, + InvalidCharacters, +} + +impl From for u8 { + fn from(value: ValidationType) -> Self { + match value { + ValidationType::ValidCharacters => 0, + ValidationType::InvalidCharacters => 1, + } + } +} + +impl From for ValidationType { + fn from(value: u8) -> Self { + match value { + 0 => ValidationType::ValidCharacters, + 1 => ValidationType::InvalidCharacters, + _ => panic!("Invalid validation type"), + } + } +} + +#[derive(Debug)] +pub struct CharacterRange { + pub first_character: u16, + pub last_character: u16, +} + +#[derive(Debug)] +pub struct CodePlane { + pub number: u8, + pub character_ranges: Vec, +} + +#[derive(Debug)] +pub struct ExtendedInputAttributes { + pub id: ObjectId, + pub validation_type: ValidationType, + pub code_planes: Vec, +} + +#[derive(Debug)] +pub struct ObjectPointer { + pub id: ObjectId, + pub value: ObjectId, +} + +#[derive(Debug)] +pub struct Macro { + pub id: ObjectId, + pub commands: Vec, +} + +#[derive(Debug)] +pub struct AuxiliaryFunctionType1 { + pub id: ObjectId, + pub background_colour: u8, + pub function_type: u8, + pub object_refs: Vec, +} + +#[derive(Debug)] +pub struct AuxiliaryInputType1 { + pub id: ObjectId, + pub background_colour: u8, + pub function_type: u8, + pub input_id: u8, + pub object_refs: Vec, +} + +#[derive(Debug)] +pub struct AuxiliaryFunctionType2 { + pub id: ObjectId, + pub background_colour: u8, + pub function_attributes: u8, + pub object_refs: Vec, +} + +#[derive(Debug)] +pub struct AuxiliaryInputType2 { + pub id: ObjectId, + pub background_colour: u8, + pub function_attributes: u8, + pub object_refs: Vec, +} + +#[derive(Debug)] +pub struct AuxiliaryControlDesignatorType2 { + pub id: ObjectId, + pub pointer_type: u8, + pub auxiliary_object_id: ObjectId, +} + +#[derive(Debug)] +pub struct ColourMap { + pub id: ObjectId, + pub colour_map: Vec, +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum ColorFormat { + ColorMonochrome, + Color4Bit, + Color8Bit, +} + +impl From for u8 { + fn from(value: ColorFormat) -> Self { + match value { + ColorFormat::ColorMonochrome => 0, + ColorFormat::Color4Bit => 1, + ColorFormat::Color8Bit => 2, + } + } +} + +impl From for ColorFormat { + fn from(value: u8) -> Self { + match value { + 0 => ColorFormat::ColorMonochrome, + 1 => ColorFormat::Color4Bit, + 2 => ColorFormat::Color8Bit, + _ => panic!("Invalid color format: {}", value), + } + } +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub enum ColorOption { + ForegroundBackground, + LineFontFill, +} + +impl From for ColorOption { + fn from(value: bool) -> Self { + match value { + false => ColorOption::ForegroundBackground, + true => ColorOption::LineFontFill, + } + } +} + +impl From for bool { + fn from(value: ColorOption) -> Self { + match value { + ColorOption::ForegroundBackground => false, + ColorOption::LineFontFill => true, + } + } +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct GraphicsContextOptions { + pub transparent: bool, + pub color: ColorOption, +} + +impl From for GraphicsContextOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + GraphicsContextOptions { + transparent: bit_data.pop().unwrap(), + color: bit_data.pop().unwrap().into(), + } + } +} + +impl From for u8 { + fn from(value: GraphicsContextOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.transparent); + bit_data.push(value.color.into()); + bit_data.extend([0; 6]); + bit_data.load::() + } +} + +#[derive(Debug, PartialEq, Copy, Clone)] +pub struct GraphicsContext { + pub id: ObjectId, + pub viewport_width: u16, + pub viewport_height: u16, + pub viewport_x: i16, + pub viewport_y: i16, + pub canvas_width: u16, + pub canvas_height: u16, + pub viewport_zoom: f32, + pub graphics_cursor_x: i16, + pub graphics_cursor_y: i16, + pub foreground_colour: u8, + pub background_colour: u8, + pub font_attributes_object: ObjectId, + pub line_attributes_object: ObjectId, + pub fill_attributes_object: ObjectId, + pub format: ColorFormat, + pub options: GraphicsContextOptions, + pub transparency_colour: u8, +} + +#[derive(Debug, Clone, PartialEq)] +pub struct WindowMask { + pub id: ObjectId, + pub cell_format: WindowMaskCellFormat, + pub window_type: WindowType, + pub background_colour: u8, + pub options: WindowMaskOptions, + pub name: ObjectId, + pub window_title: ObjectId, + pub window_icon: ObjectId, + pub objects: Vec, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct KeyGroupOptions { + pub available: bool, + pub transparent: bool, +} + +impl From for KeyGroupOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + KeyGroupOptions { + available: bit_data.pop().unwrap(), + transparent: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: KeyGroupOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.available); + bit_data.push(value.transparent); + bit_data.extend([0; 6]); + bit_data.load::() + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct KeyGroup { + pub id: ObjectId, + pub options: KeyGroupOptions, + pub name: ObjectId, + pub key_group_icon: ObjectId, + pub objects: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct ObjectLabelReferenceList { + pub id: ObjectId, + pub object_labels: Vec, +} + +#[derive(Debug)] +pub struct ExternalObjectDefinition { + pub id: ObjectId, + pub options: u8, + pub name: NAME, + pub objects: Vec, +} + +#[derive(Debug)] +pub struct ExternalReferenceName { + pub id: ObjectId, + pub options: u8, + pub name: NAME, +} + +#[derive(Debug)] +pub struct ExternalObjectPointer { + pub id: ObjectId, + pub default_object_id: ObjectId, + pub external_reference_name_id: ObjectId, + pub external_object_id: ObjectId, +} + +#[derive(Debug)] +pub struct Animation { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub refresh_interval: u16, + pub value: u8, + pub enabled: bool, + pub first_child_index: u8, + pub last_child_index: u8, + pub default_child_index: u8, + pub options: u8, + pub object_refs: Vec, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct ColourPalette { + pub id: ObjectId, + pub options: u16, + pub colours: Vec, +} + +#[derive(Debug)] +pub struct GraphicData { + pub id: ObjectId, + pub format: u8, + pub data: Vec, +} + +#[derive(Debug)] +pub struct ScaledGraphic { + pub id: ObjectId, + pub width: u16, + pub height: u16, + pub scale_type: u8, + pub options: u8, + pub value: u16, + pub macro_refs: Vec, +} + +#[derive(Debug)] +pub struct WorkingSetSpecialControls { + pub id: ObjectId, + pub id_of_colour_map: ObjectId, + pub id_of_colour_palette: ObjectId, + pub language_pairs: Vec<(String, String)>, +} diff --git a/src/object_pool/object_attributes.rs b/src/object_pool/object_attributes.rs new file mode 100644 index 0000000..dd158bc --- /dev/null +++ b/src/object_pool/object_attributes.rs @@ -0,0 +1,174 @@ +use crate::object_pool::object_id::ObjectId; +use bitvec::field::BitField; +use bitvec::order::Msb0; +use bitvec::vec::BitVec; +use bitvec::view::BitView; +use strum_macros::FromRepr; + +#[derive(FromRepr, Debug, PartialEq, Clone, Copy)] +#[repr(u8)] +pub enum WindowType { + FreeForm = 0, + NumericOutputValueWithUnits1x1 = 1, + NumericOutputValueNoUnits1x1 = 2, + StringOutputValue1x1 = 3, + NumericInputValueWithUnits1x1 = 4, + NumericInputValueNoUnits1x1 = 5, + StringInputValue1x1 = 6, + HorizontalLinearBarGraph1x1 = 7, + SingleButton1x1 = 8, + DoubleButton1x1 = 9, + NumericOutputValueWithUnits2x1 = 10, + NumericOutputValueNoUnits2x1 = 11, + StringOutputValue2x1 = 12, + NumericInputValueWithUnits2x1 = 13, + NumericInputValueNoUnits2x1 = 14, + StringInputValue2x1 = 15, + HorizontalLinearBarGraph2x1 = 16, + SingleButton2x1 = 17, + DoubleButton2x1 = 18, +} + +impl From for WindowType { + fn from(value: u8) -> Self { + WindowType::from_repr(value).unwrap() + } +} + +impl From for u8 { + fn from(value: WindowType) -> Self { + value.into() + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum WindowMaskCellFormat { + CF1x1, + CF1x2, + CF1x3, + CF1x4, + CF1x5, + CF1x6, + CF2x1, + CF2x2, + CF2x3, + CF2x4, + CF2x5, + CF2x6, +} + +impl WindowMaskCellFormat { + const fn from_size(x: u8, y: u8) -> WindowMaskCellFormat { + let size = Point { x, y }; + match size { + Point { x: 1, y: 1 } => WindowMaskCellFormat::CF1x1, + Point { x: 1, y: 2 } => WindowMaskCellFormat::CF1x2, + Point { x: 1, y: 3 } => WindowMaskCellFormat::CF1x3, + Point { x: 1, y: 4 } => WindowMaskCellFormat::CF1x4, + Point { x: 1, y: 5 } => WindowMaskCellFormat::CF1x5, + Point { x: 1, y: 6 } => WindowMaskCellFormat::CF1x6, + Point { x: 2, y: 1 } => WindowMaskCellFormat::CF2x1, + Point { x: 2, y: 2 } => WindowMaskCellFormat::CF2x2, + Point { x: 2, y: 3 } => WindowMaskCellFormat::CF2x3, + Point { x: 2, y: 4 } => WindowMaskCellFormat::CF2x4, + Point { x: 2, y: 5 } => WindowMaskCellFormat::CF2x5, + Point { x: 2, y: 6 } => WindowMaskCellFormat::CF2x6, + _ => WindowMaskCellFormat::CF1x1, + } + } + + pub const fn size(self) -> Point { + match self { + WindowMaskCellFormat::CF1x1 => Point { x: 1, y: 1 }, + WindowMaskCellFormat::CF1x2 => Point { x: 1, y: 2 }, + WindowMaskCellFormat::CF1x3 => Point { x: 1, y: 3 }, + WindowMaskCellFormat::CF1x4 => Point { x: 1, y: 4 }, + WindowMaskCellFormat::CF1x5 => Point { x: 1, y: 5 }, + WindowMaskCellFormat::CF1x6 => Point { x: 1, y: 6 }, + WindowMaskCellFormat::CF2x1 => Point { x: 2, y: 1 }, + WindowMaskCellFormat::CF2x2 => Point { x: 2, y: 2 }, + WindowMaskCellFormat::CF2x3 => Point { x: 2, y: 3 }, + WindowMaskCellFormat::CF2x4 => Point { x: 2, y: 4 }, + WindowMaskCellFormat::CF2x5 => Point { x: 2, y: 5 }, + WindowMaskCellFormat::CF2x6 => Point { x: 2, y: 6 }, + } + } +} + +impl From for WindowMaskCellFormat { + fn from(value: u16) -> Self { + WindowMaskCellFormat::from_size((value << 8) as u8, value as u8) + } +} + +impl From for u16 { + fn from(value: WindowMaskCellFormat) -> Self { + let size = value.size(); + ((size.x as u16) << 8) | size.y as u16 + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct WindowMaskOptions { + pub available: bool, + pub transparent: bool, +} + +impl From for WindowMaskOptions { + fn from(value: u8) -> Self { + let mut bit_data = value.view_bits::().to_bitvec(); + WindowMaskOptions { + available: bit_data.pop().unwrap(), + transparent: bit_data.pop().unwrap(), + } + } +} + +impl From for u8 { + fn from(value: WindowMaskOptions) -> u8 { + let mut bit_data: BitVec = BitVec::new(); + bit_data.push(value.available); + bit_data.push(value.transparent); + bit_data.extend([0; 6]); + bit_data.load::() + } +} + +#[derive(Debug, PartialEq, Clone)] +pub struct ObjectRef { + pub id: ObjectId, + pub offset: Point, + // pub x: i16, + // pub y: i16, +} + +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct MacroRef { + pub macro_id: u8, + pub event_id: u8, +} + +#[derive(Debug, Default, Clone, Copy, PartialEq)] +pub struct Point { + pub x: T, + pub y: T, +} + +impl core::ops::Add> for Point { + type Output = Point; + + fn add(self, rhs: Point) -> Self::Output { + Point { + x: (self.x as i16 + rhs.x) as u16, + y: (self.y as i16 + rhs.y) as u16, + } + } +} + +#[derive(Debug)] +pub struct ObjectLabel { + pub id: ObjectId, + pub string_variable_reference: ObjectId, + pub font_type: u8, + pub graphic_representation: ObjectId, +} diff --git a/src/object_pool/object_id.rs b/src/object_pool/object_id.rs new file mode 100644 index 0000000..747649e --- /dev/null +++ b/src/object_pool/object_id.rs @@ -0,0 +1,115 @@ +use crate::object_pool::ParseError; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct ObjectId { + id: u16, +} + +impl ObjectId { + const NULL: ObjectId = ObjectId { id: u16::MAX }; + + pub fn new(id: u16) -> Result { + if id == Self::NULL.id { + Err(ParseError::UnknownObjectType) + } else { + Ok(ObjectId { id }) + } + } +} + +pub struct NullableObjectId(Option); + +impl NullableObjectId { + pub const NULL: NullableObjectId = NullableObjectId(None); + pub fn new(id: u16) -> Self { + if id == ObjectId::NULL.id { + NullableObjectId(None) + } else { + NullableObjectId(Some(ObjectId::new(id).unwrap())) + } + } +} + +impl Default for NullableObjectId { + fn default() -> Self { + NullableObjectId::NULL + } +} + +impl From for NullableObjectId { + fn from(id: u16) -> Self { + NullableObjectId::new(id) + } +} + +impl From for u16 { + fn from(id: NullableObjectId) -> Self { + match id.0 { + Some(id) => id.id, + None => u16::from(ObjectId::NULL), + } + } +} + +impl From for NullableObjectId { + fn from(id: ObjectId) -> Self { + if id == ObjectId::NULL { + NullableObjectId(None) + } else { + NullableObjectId(Some(id)) + } + } +} + +impl Default for ObjectId { + fn default() -> Self { + Self::new(0).unwrap() + } +} +impl TryFrom for ObjectId { + type Error = ParseError; + + fn try_from(id: u16) -> Result { + ObjectId::new(id) + } +} + +impl From for u16 { + fn from(val: ObjectId) -> Self { + val.id + } +} +impl TryFrom<[u8; 2]> for ObjectId { + type Error = ParseError; + + fn try_from(val: [u8; 2]) -> Result { + ObjectId::new(u16::from_le_bytes(val)) + } +} +impl From for [u8; 2] { + fn from(val: ObjectId) -> Self { + val.id.to_le_bytes() + } +} +// impl From> for ObjectId { +// fn from(val: Vec) -> Self { +// let val: ObjectId = val.as_slice().into(); +// val +// } +// } +// impl From for Vec { +// fn from(val: ObjectId) -> Self { +// let val: [u8;2] = val.into(); +// val.to_vec() +// } +// } +impl TryFrom<&[u8]> for ObjectId { + type Error = ParseError; + + fn try_from(val: &[u8]) -> Result { + match val.len() { + 2.. => Ok(ObjectId::new(u16::from_le_bytes([val[0], val[1]]))?), + _ => Err(ParseError::DataEmpty), + } + } +} diff --git a/src/object_pool/object_pool.rs b/src/object_pool/object_pool.rs index 0f10b59..13125b5 100644 --- a/src/object_pool/object_pool.rs +++ b/src/object_pool/object_pool.rs @@ -1,10 +1,12 @@ use crate::object_pool::colour::Colour; -use crate::object_pool::{ +use crate::object_pool::object::{ AlarmMask, Button, Container, DataMask, GraphicsContext, InputBoolean, InputList, InputNumber, - InputString, Key, KeyGroup, LineAttributes, Object, ObjectId, ObjectType, OutputLine, - OutputList, OutputNumber, OutputString, PictureGraphic, SoftKeyMask, VtVersion, WindowMask, - WorkingSet, + InputString, Key, KeyGroup, LineAttributes, Object, OutputLine, OutputList, OutputNumber, + OutputString, PictureGraphic, SoftKeyMask, WindowMask, WorkingSet, }; +use crate::object_pool::object_id::ObjectId; +use crate::object_pool::vt_version::VtVersion; +use crate::object_pool::ObjectType; use core::cell::Cell; #[derive(Debug)] diff --git a/src/object_pool/object_type.rs b/src/object_pool/object_type.rs new file mode 100644 index 0000000..950384e --- /dev/null +++ b/src/object_pool/object_type.rs @@ -0,0 +1,170 @@ +use crate::object_pool::ParseError; +use crate::object_pool::ParseError::UnknownObjectType; + +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub enum ObjectType { + WorkingSet = 0, + DataMask = 1, + AlarmMask = 2, + Container = 3, + SoftKeyMask = 4, + Key = 5, + Button = 6, + InputBoolean = 7, + InputString = 8, + InputNumber = 9, + InputList = 10, + OutputString = 11, + OutputNumber = 12, + OutputLine = 13, + OutputRectangle = 14, + OutputEllipse = 15, + OutputPolygon = 16, + OutputMeter = 17, + OutputLinearBarGraph = 18, + OutputArchedBarGraph = 19, + PictureGraphic = 20, + NumberVariable = 21, + StringVariable = 22, + FontAttributes = 23, + LineAttributes = 24, + FillAttributes = 25, + InputAttributes = 26, + ObjectPointer = 27, + Macro = 28, + AuxiliaryFunctionType1 = 29, + AuxiliaryInputType1 = 30, + AuxiliaryFunctionType2 = 31, + AuxiliaryInputType2 = 32, + AuxiliaryControlDesignatorType2 = 33, + WindowMask = 34, + KeyGroup = 35, + GraphicsContext = 36, + OutputList = 37, + ExtendedInputAttributes = 38, + ColourMap = 39, + ObjectLabelReferenceList = 40, + ExternalObjectDefinition = 41, + ExternalReferenceName = 42, + ExternalObjectPointer = 43, + Animation = 44, + ColourPalette = 45, + GraphicData = 46, + WorkingSetSpecialControls = 47, + ScaledGraphic = 48, +} + +impl TryFrom for ObjectType { + type Error = ParseError; + + fn try_from(val: u8) -> Result { + match val { + 0 => Ok(Self::WorkingSet), + 1 => Ok(Self::DataMask), + 2 => Ok(Self::AlarmMask), + 3 => Ok(Self::Container), + 4 => Ok(Self::SoftKeyMask), + 5 => Ok(Self::Key), + 6 => Ok(Self::Button), + 7 => Ok(Self::InputBoolean), + 8 => Ok(Self::InputString), + 9 => Ok(Self::InputNumber), + 10 => Ok(Self::InputList), + 11 => Ok(Self::OutputString), + 12 => Ok(Self::OutputNumber), + 13 => Ok(Self::OutputLine), + 14 => Ok(Self::OutputRectangle), + 15 => Ok(Self::OutputEllipse), + 16 => Ok(Self::OutputPolygon), + 17 => Ok(Self::OutputMeter), + 18 => Ok(Self::OutputLinearBarGraph), + 19 => Ok(Self::OutputArchedBarGraph), + 20 => Ok(Self::PictureGraphic), + 21 => Ok(Self::NumberVariable), + 22 => Ok(Self::StringVariable), + 23 => Ok(Self::FontAttributes), + 24 => Ok(Self::LineAttributes), + 25 => Ok(Self::FillAttributes), + 26 => Ok(Self::InputAttributes), + 27 => Ok(Self::ObjectPointer), + 28 => Ok(Self::Macro), + 29 => Ok(Self::AuxiliaryFunctionType1), + 30 => Ok(Self::AuxiliaryInputType1), + 31 => Ok(Self::AuxiliaryFunctionType2), + 32 => Ok(Self::AuxiliaryInputType2), + 33 => Ok(Self::AuxiliaryControlDesignatorType2), + 34 => Ok(Self::WindowMask), + 35 => Ok(Self::KeyGroup), + 36 => Ok(Self::GraphicsContext), + 37 => Ok(Self::OutputList), + 38 => Ok(Self::ExtendedInputAttributes), + 39 => Ok(Self::ColourMap), + 40 => Ok(Self::ObjectLabelReferenceList), + 41 => Ok(Self::ExternalObjectDefinition), + 42 => Ok(Self::ExternalReferenceName), + 43 => Ok(Self::ExternalObjectPointer), + 44 => Ok(Self::Animation), + 45 => Ok(Self::ColourPalette), + 46 => Ok(Self::GraphicData), + 47 => Ok(Self::WorkingSetSpecialControls), + 48 => Ok(Self::ScaledGraphic), + _ => Err(UnknownObjectType), + } + } +} + +impl From for u8 { + fn from(val: ObjectType) -> Self { + match val { + ObjectType::WorkingSet => 0, + ObjectType::DataMask => 1, + ObjectType::AlarmMask => 2, + ObjectType::Container => 3, + ObjectType::SoftKeyMask => 4, + ObjectType::Key => 5, + ObjectType::Button => 6, + ObjectType::InputBoolean => 7, + ObjectType::InputString => 8, + ObjectType::InputNumber => 9, + ObjectType::InputList => 10, + ObjectType::OutputString => 11, + ObjectType::OutputNumber => 12, + ObjectType::OutputLine => 13, + ObjectType::OutputRectangle => 14, + ObjectType::OutputEllipse => 15, + ObjectType::OutputPolygon => 16, + ObjectType::OutputMeter => 17, + ObjectType::OutputLinearBarGraph => 18, + ObjectType::OutputArchedBarGraph => 19, + ObjectType::PictureGraphic => 20, + ObjectType::NumberVariable => 21, + ObjectType::StringVariable => 22, + ObjectType::FontAttributes => 23, + ObjectType::LineAttributes => 24, + ObjectType::FillAttributes => 25, + ObjectType::InputAttributes => 26, + ObjectType::ObjectPointer => 27, + ObjectType::Macro => 28, + ObjectType::AuxiliaryFunctionType1 => 29, + ObjectType::AuxiliaryInputType1 => 30, + ObjectType::AuxiliaryFunctionType2 => 31, + ObjectType::AuxiliaryInputType2 => 32, + ObjectType::AuxiliaryControlDesignatorType2 => 33, + ObjectType::WindowMask => 34, + ObjectType::KeyGroup => 35, + ObjectType::GraphicsContext => 36, + ObjectType::OutputList => 37, + ObjectType::ExtendedInputAttributes => 38, + ObjectType::ColourMap => 39, + ObjectType::ObjectLabelReferenceList => 40, + ObjectType::ExternalObjectDefinition => 41, + ObjectType::ExternalReferenceName => 42, + ObjectType::ExternalObjectPointer => 43, + ObjectType::Animation => 44, + ObjectType::ColourPalette => 45, + ObjectType::GraphicData => 46, + ObjectType::WorkingSetSpecialControls => 47, + ObjectType::ScaledGraphic => 48, + } + } +} diff --git a/src/object_pool/reader.rs b/src/object_pool/reader.rs index caa90da..10720a5 100644 --- a/src/object_pool/reader.rs +++ b/src/object_pool/reader.rs @@ -1,5 +1,19 @@ use super::*; use crate::object_pool::colour::Colour; +use crate::object_pool::object::{ + AlarmMask, Animation, AuxiliaryControlDesignatorType2, AuxiliaryFunctionType1, + AuxiliaryFunctionType2, AuxiliaryInputType1, AuxiliaryInputType2, Button, CharacterRange, + CodePlane, ColourMap, ColourPalette, Container, DataMask, ExtendedInputAttributes, + ExternalObjectDefinition, ExternalObjectPointer, ExternalReferenceName, FillAttributes, + FontAttributes, GraphicData, GraphicsContext, InputAttributes, InputBoolean, InputList, + InputNumber, InputString, Key, KeyGroup, KeyGroupOptions, LineAttributes, Macro, + NumberVariable, Object, ObjectLabelReferenceList, ObjectPointer, OutputArchedBarGraph, + OutputEllipse, OutputLine, OutputLinearBarGraph, OutputList, OutputMeter, OutputNumber, + OutputPolygon, OutputRectangle, OutputString, PictureGraphic, ScaledGraphic, SoftKeyMask, + StringVariable, WindowMask, WorkingSet, WorkingSetSpecialControls, +}; +use crate::object_pool::object_attributes::{MacroRef, ObjectLabel, ObjectRef, Point}; +use crate::object_pool::object_id::ObjectId; impl Object { pub fn read(data: &mut dyn Iterator) -> Result { @@ -212,7 +226,7 @@ impl Object { if d == 0 || d == 1 { Ok(d == 1) } else { - Err(UnknownObjectType) + Err(ParseError::UnknownObjectType) } } None => Err(ParseError::DataEmpty), @@ -1299,8 +1313,10 @@ impl Object { #[cfg(test)] mod tests { - use crate::object_pool::{Colour, Object, ObjectId, ObjectRef, ObjectType, Point}; - use crate::object_pool::{ObjectPool, WorkingSet}; + use crate::object_pool::object::{Object, WorkingSet}; + use crate::object_pool::object_attributes::{ObjectRef, Point}; + use crate::object_pool::object_id::ObjectId; + use crate::object_pool::{Colour, ObjectPool, ObjectType}; use std::vec::IntoIter; fn read_id_type(data: &mut dyn Iterator) -> ObjectId { @@ -1328,12 +1344,12 @@ mod tests { 0x00, //Number of object references 0x00, //Number of macro references 0x00, //Number of language codes - 0x00, 0x00, // Object ID reference 1 - 0x00, 0x00, // X Location reference 1 - 0x00, 0x00, // Y Location reference 1 - 0x00, 0x00, // Object ID reference 2 - 0x00, 0x00, // X Location reference 2 - 0x00, 0x00, // Y Location reference 2 + 0x00, 0xF1, // Object ID reference 1 + 0x00, 0x7B, // X Location reference 1 + 0x01, 0xC8, // Y Location reference 1 + 0x00, 0xF2, // Object ID reference 2 + 0x03, 0x15, // X Location reference 2 + 0x00, 0x0C, // Y Location reference 2 0x00, // Event ID reference 1 0x00, // Macro ID reference 1 0x00, // Event ID reference 2 @@ -1360,10 +1376,16 @@ mod tests { background_colour: Colour::new_by_id(0xF0), selectable: true, active_mask: ObjectId::default(), - object_refs: vec![ObjectRef { - id: ObjectId::new(0xF1).unwrap(), - offset: Point { x: 123, y: 456 }, - }], + object_refs: vec![ + ObjectRef { + id: ObjectId::new(0xF1).unwrap(), + offset: Point { x: 123, y: 456 }, + }, + ObjectRef { + id: ObjectId::new(0xF2).unwrap(), + offset: Point { x: 789, y: 12 }, + }, + ], macro_refs: vec![], language_codes: vec![], }; diff --git a/src/object_pool/vt_version.rs b/src/object_pool/vt_version.rs new file mode 100644 index 0000000..16410ab --- /dev/null +++ b/src/object_pool/vt_version.rs @@ -0,0 +1,45 @@ +use crate::object_pool::ParseError; +use crate::object_pool::ParseError::UnknownObjectType; + +#[derive(Debug, Default)] +pub enum VtVersion { + Version0, + Version1, + Version2, + #[default] + Version3, + Version4, + Version5, + Version6, +} + +impl From for u8 { + fn from(vt_version: VtVersion) -> Self { + match vt_version { + VtVersion::Version0 => 0, + VtVersion::Version1 => 1, + VtVersion::Version2 => 2, + VtVersion::Version3 => 3, + VtVersion::Version4 => 4, + VtVersion::Version5 => 5, + VtVersion::Version6 => 6, + } + } +} + +impl TryFrom for VtVersion { + type Error = ParseError; + + fn try_from(value: u8) -> Result { + match value { + 0 => Ok(VtVersion::Version0), + 1 => Ok(VtVersion::Version1), + 2 => Ok(VtVersion::Version2), + 3 => Ok(VtVersion::Version3), + 4 => Ok(VtVersion::Version4), + 5 => Ok(VtVersion::Version5), + 6 => Ok(VtVersion::Version6), + _ => Err(UnknownObjectType), + } + } +} diff --git a/src/object_pool/writer.rs b/src/object_pool/writer.rs index e4e949e..b202a60 100644 --- a/src/object_pool/writer.rs +++ b/src/object_pool/writer.rs @@ -1,5 +1,19 @@ use super::*; use crate::object_pool::colour::Colour; +use crate::object_pool::object::{ + AlarmMask, Animation, AuxiliaryControlDesignatorType2, AuxiliaryFunctionType1, + AuxiliaryFunctionType2, AuxiliaryInputType1, AuxiliaryInputType2, Button, CharacterRange, + CodePlane, ColourMap, ColourPalette, Container, DataMask, ExtendedInputAttributes, + ExternalObjectDefinition, ExternalObjectPointer, ExternalReferenceName, FillAttributes, + FontAttributes, GraphicData, GraphicsContext, InputAttributes, InputBoolean, InputList, + InputNumber, InputString, Key, KeyGroup, LineAttributes, Macro, NumberVariable, Object, + ObjectLabelReferenceList, ObjectPointer, OutputArchedBarGraph, OutputEllipse, OutputLine, + OutputLinearBarGraph, OutputList, OutputMeter, OutputNumber, OutputPolygon, OutputRectangle, + OutputString, PictureGraphic, ScaledGraphic, SoftKeyMask, StringVariable, WindowMask, + WorkingSet, WorkingSetSpecialControls, +}; +use crate::object_pool::object_attributes::{MacroRef, ObjectLabel, ObjectRef, Point}; +use crate::object_pool::object_id::ObjectId; impl Object { pub fn write(&self) -> Vec {