Skip to content
Snippets Groups Projects
Commit bfa75023 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Add "name" property to spectrometer

code cleanup
parent 13268718
No related branches found
No related tags found
No related merge requests found
Pipeline #7710 passed
......@@ -24,11 +24,7 @@ fn main() {
fn read_and_parse_model(path: &Path) -> Result<OpticScenery> {
print!("\nReading model...");
let contents = fs::read_to_string(path).map_err(|e| {
OpossumError::Console(format!(
"cannot read file {} : {}",
path.display(),
e
))
OpossumError::Console(format!("cannot read file {} : {}", path.display(), e))
})?;
let scenery: OpticScenery = serde_json::from_str(&contents).map_err(|e| {
OpossumError::OpticScenery(format!("error while parsing model file: {}", e))
......@@ -39,8 +35,8 @@ fn read_and_parse_model(path: &Path) -> Result<OpticScenery> {
fn do_it() -> Result<()> {
let opossum_args = Args::try_from(PartialArgs::parse())?;
let mut scenery=read_and_parse_model(&opossum_args.file_path)?;
let mut scenery = read_and_parse_model(&opossum_args.file_path)?;
let mut dot_path = opossum_args.report_directory.clone();
dot_path.push(opossum_args.file_path.file_stem().unwrap());
dot_path.set_extension("dot");
......
......@@ -27,7 +27,6 @@ pub enum SpectrometerType {
/// Ocean Optics HR2000
HR2000,
}
#[derive(Default)]
/// (ideal) spectrometer
///
/// It normally measures / displays the spectrum of the incoming light.
......@@ -45,13 +44,29 @@ pub struct Spectrometer {
spectrometer_type: SpectrometerType,
props: Properties,
}
fn create_default_props() -> Properties {
let mut props = Properties::default();
props.set("name", "spectrometer".into());
props
}
impl Default for Spectrometer {
fn default() -> Self {
Self {
light_data: Default::default(),
spectrometer_type: Default::default(),
props: create_default_props(),
}
}
}
impl Spectrometer {
/// Creates a new [`Spectrometer`] of the given [`SpectrometerType`].
pub fn new(spectrometer_type: SpectrometerType) -> Self {
Spectrometer {
light_data: None,
spectrometer_type,
props: Properties::default(),
props: create_default_props(),
}
}
/// Returns the meter type of this [`Spectrometer`].
......
......@@ -67,11 +67,11 @@ pub trait Optical: Dottable {
Err(OpossumError::Other("cannot cast to group".into()))
}
/// Return the properties of this [`Optical`].
///
///
/// Return all properties of an optical node. Note, that some properties might be read-only.
fn properties(&self) -> &Properties;
/// Set a property of this [`Optical`].
///
///
/// Set a property of an optical node. This property must already exist (e.g. defined in new() / default() functions of the node).
///
/// # Errors
......@@ -89,7 +89,7 @@ pub trait Optical: Dottable {
Ok(())
}
/// Return a JSON representation of the current state of this [`Optical`].
///
///
/// This function must be overridden for generating output in the analysis report. Mainly detector nodes use this feature.
/// The default implementation is to return a JSON `null` value.
fn report(&self) -> serde_json::Value {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment