Skip to content

Commit

Permalink
Restructure input processor modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
SutekhVRC committed Dec 9, 2023
1 parent 2221b46 commit 7a1f642
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 89 deletions.
47 changes: 3 additions & 44 deletions src-tauri/src/toy_handling/input_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
pub mod penetration_systems;

use std::fmt::Debug;

use dyn_clone::DynClone;
use serde::{Deserialize, Serialize};
use ts_rs::TS;

use crate::frontend::{frontend_types::FePenetrationSystem, ToFrontend};
use std::fmt::Debug;

use self::penetration_systems::PenetrationSystemType;
use super::ModeProcessorInputType;

use super::{
toyops::{ProcessingMode, ProcessingModeValues},
ModeProcessorInputType,
};
pub mod penetration_systems;

/*
* Penetration System Architecture
Expand All @@ -29,34 +19,3 @@ pub trait InputProcessor: DynClone + Debug + Send + Sync {
fn is_parameter(&self, param: &String) -> bool;
}
dyn_clone::clone_trait_object!(InputProcessor);

#[derive(Clone, Debug, Serialize, Deserialize, TS)]
pub struct PenetrationSystem {
#[serde(skip)]
pub pen_system: Option<Box<dyn InputProcessor>>,
pub pen_system_type: PenetrationSystemType,
pub pen_system_processing_mode: ProcessingMode,
#[serde(skip)]
pub pen_system_processing_mode_values: ProcessingModeValues,
}

impl Default for PenetrationSystem {
fn default() -> Self {
Self {
pen_system: None,
pen_system_type: PenetrationSystemType::NONE,
pen_system_processing_mode: ProcessingMode::Raw,
pen_system_processing_mode_values: ProcessingModeValues::Raw,
}
}
}

impl ToFrontend<FePenetrationSystem> for PenetrationSystem {
type OutputType = FePenetrationSystem;
fn to_frontend(&self) -> Self::OutputType {
FePenetrationSystem {
pen_system_type: self.pen_system_type.clone(),
pen_system_processing_mode: self.pen_system_processing_mode.to_frontend(),
}
}
}
44 changes: 0 additions & 44 deletions src-tauri/src/toy_handling/input_processor/penetration_systems.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pub mod sps;
pub mod tps;

use serde::{Deserialize, Serialize};
use ts_rs::TS;

use crate::{
frontend::{frontend_types::FePenetrationSystem, ToFrontend},
toy_handling::toyops::{ProcessingMode, ProcessingModeValues},
};

use super::InputProcessor;

#[derive(Clone, Debug, Serialize, Deserialize, TS)]
#[ts(export)]
pub enum PenetrationSystemType {
NONE,
TPS,
SPS,
}

#[derive(Clone, Debug, Serialize, Deserialize, TS)]
pub struct PenetrationSystem {
#[serde(skip)]
pub pen_system: Option<Box<dyn InputProcessor>>,
pub pen_system_type: PenetrationSystemType,
pub pen_system_processing_mode: ProcessingMode,
#[serde(skip)]
pub pen_system_processing_mode_values: ProcessingModeValues,
}

impl Default for PenetrationSystem {
fn default() -> Self {
Self {
pen_system: None,
pen_system_type: PenetrationSystemType::NONE,
pen_system_processing_mode: ProcessingMode::Raw,
pen_system_processing_mode_values: ProcessingModeValues::Raw,
}
}
}

impl ToFrontend<FePenetrationSystem> for PenetrationSystem {
type OutputType = FePenetrationSystem;
fn to_frontend(&self) -> Self::OutputType {
FePenetrationSystem {
pen_system_type: self.pen_system_type.clone(),
pen_system_processing_mode: self.pen_system_processing_mode.to_frontend(),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};
use ts_rs::TS;

use crate::toy_handling::{input_processor::InputProcessor, ModeProcessorInputType};

#[derive(Clone, Debug, Serialize, Deserialize, TS)]
pub struct SPSProcessor {
pub parameter_list: Vec<String>,
}

impl InputProcessor for SPSProcessor {
fn is_parameter(&self, param: &String) -> bool {
self.parameter_list.contains(param)
}

fn process(&self, _input: ModeProcessorInputType) -> Option<f64> {
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};
use ts_rs::TS;

use crate::toy_handling::{input_processor::InputProcessor, ModeProcessorInputType};

#[derive(Clone, Debug, Serialize, Deserialize, TS)]
pub struct TPSProcessor {
pub parameter_list: Vec<String>,
}

impl InputProcessor for TPSProcessor {
fn is_parameter(&self, param: &String) -> bool {
self.parameter_list.contains(param)
}

fn process(&self, _input: ModeProcessorInputType) -> Option<f64> {
todo!()
}
}
2 changes: 1 addition & 1 deletion src-tauri/src/toy_handling/toyops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
vcore::vcerror,
};

use crate::toy_handling::input_processor::PenetrationSystem;
use crate::toy_handling::input_processor::penetration_systems::PenetrationSystem;

#[derive(Clone, Debug)]
pub struct VCToy {
Expand Down

0 comments on commit 7a1f642

Please sign in to comment.