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

Further implementation of OpticScenery

parent 0cd6929e
No related branches found
No related tags found
No related merge requests found
/target
/.vscode
/book/book
*.dot
\ No newline at end of file
use opossum::opticscenery::*;
use opossum::optic_scenery::*;
use std::fs::File;
use std::io::Write;
fn main() {
println!("opticscenery example");
println!("default opticscenery: {:?}",Opticscenery::default());
println!("opticscenery example");
let scenery = OpticScenery::default();
println!("default opticscenery: {:?}", scenery);
println!("export to `dot` format: {}", scenery.to_dot());
let path = "graph.dot";
let mut output = File::create(path).unwrap();
write!(output, "{}", scenery.to_dot()).unwrap();
}
//! This is the documentation for the OPOSSUM software package. OPOSSUM stands for OPen-source Optics Simulation Software and Unified Modeller.
//!
/// The basic structure containing the entire optical model
pub mod opticscenery;
\ No newline at end of file
pub mod optic_scenery;
/// The basic structure representing an optical element
pub mod optic_node;
\ No newline at end of file
#[derive(Debug, Default)]
pub struct OpticNode {
name: String,
}
impl OpticNode {
/// Creates a new [`OpticNode`].
pub fn new(name: String) -> Self {
Self { name }
}
/// Sets the name of this [`OpticNode`].
pub fn set_name(&mut self, name: String) {
self.name = name;
}
/// Returns a reference to the name of this [`OpticNode`].
pub fn name(&self) -> &str {
self.name.as_ref()
}
}
use crate::optic_node::OpticNode;
use petgraph::dot::Dot;
use petgraph::prelude::{DiGraph, NodeIndex};
/// Opticscenery represents the overall optical model and additional metatdata. All optical elements (OpticNodes) have to be added to this
/// structure in order to be considered for an analysis.
#[derive(Default, Debug)]
pub struct OpticScenery {
g: DiGraph<OpticNode, ()>,
description: String,
}
impl OpticScenery {
/// Creates a new (default) [`OpticScenery`].
pub fn new() -> Self {
Self::default()
}
/// Add a given [`OpticNode`] to the graph of this [`OpticScenery`].
///
/// This command just adds an [`OpticNode`] but does not connect it to existing nodes in the graph. The given node is
/// consumed (owned) by the [`OpticScenery`].
pub fn add_node(&mut self, node: OpticNode) -> NodeIndex {
self.g.add_node(node)
}
/// Export the optic graph into the `dot` format to be used in combination with the [`graphviz`](https://graphviz.org/) software.
pub fn to_dot(&self) -> String {
format!("{:?}", Dot::new(&self.g))
}
/// Analyze this [`OpticScenery`] using a given OpticAnalyzer.
pub fn analyze(&self) {
todo!();
}
/// Sets the description of this [`OpticScenery`].
pub fn set_description(&mut self, description: String) {
self.description = description;
}
/// Returns a reference to the description of this [`OpticScenery`].
pub fn description(&self) -> &str {
self.description.as_ref()
}
}
use petgraph::prelude::DiGraph;
use petgraph::dot::Dot;
#[derive(Default, Debug)]
pub struct Opticscenery {
g: DiGraph<i32,()>
}
impl Opticscenery {
pub fn to_dot(self: &Self) -> String {
format!("{:?}",Dot::new(&self.g))
}
}
\ No newline at end of file
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