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

Add report function to OpticScenery

parent 714fcae2
No related branches found
No related tags found
No related merge requests found
......@@ -14,15 +14,15 @@ fn main() {
let n3 = scenery.add_element("Faraday", Dummy);
let n4 = scenery.add_element("0° mirror", Dummy);
let mut node= NodeReference::new(scenery.node_ref(n1).unwrap());
let mut node= NodeReference::new(scenery.node(n1).unwrap());
node.set_inverted(true);
let n1r=scenery.add_node(node);
let mut node= NodeReference::new(scenery.node_ref(n3).unwrap());
let mut node= NodeReference::new(scenery.node(n3).unwrap());
node.set_inverted(true);
let n3r = scenery.add_node(node);
let mut node= NodeReference::new(scenery.node_ref(n2).unwrap());
let mut node= NodeReference::new(scenery.node(n2).unwrap());
node.set_inverted(true);
let n2r = scenery.add_node(node);
......
......@@ -27,16 +27,15 @@ fn main() {
let path = "src_detector.dot";
let mut output = File::create(path).unwrap();
write!(output, "{}", scenery.to_dot()).unwrap();
println!("{:?}", scenery.node_ref(i_s).unwrap());
println!("{:?}", scenery.node_ref(i_d1).unwrap());
println!("{:?}", scenery.node_ref(i_d2).unwrap());
scenery.report();
println!("");
let mut analyzer=AnalyzerEnergy::new(&scenery);
print!("Analyze...");
match analyzer.analyze() {
Ok(_) => println!("Sucessful"),
Err(e) => println!("Error: {}",e)
}
println!("{:?}", scenery.node_ref(i_d1).unwrap());
println!("{:?}", scenery.node_ref(i_d2).unwrap());
println!("");
scenery.report();
}
use std::collections::HashMap;
use std::fmt::Debug;
use crate::{
lightdata::LightData,
......@@ -9,7 +10,7 @@ use crate::{
type Result<T> = std::result::Result<T, OpossumError>;
/// This node represents a source of light. Hence it has only one output port (out1) and no input ports. Source nodes usually are the first nodes of an optic scenery.
#[derive(Debug, Default)]
#[derive(Default)]
pub struct Source {
light_data: Option<LightData>,
}
......@@ -32,6 +33,16 @@ impl Source {
self.light_data = Some(light_data);
}
}
impl Debug for Source {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.light_data {
Some(data) => write!(f,"{}",data),
None => write!(f, "no data"),
}
}
}
impl Optical for Source {
fn node_type(&self) -> &str {
"light source"
......
use crate::error::OpossumError;
use std::collections::HashSet;
use crate::optic_node::OpticNode;
/// Structure defining the optical ports (input / output terminals) of an [`OpticNode`].
#[derive(Default, Debug, Clone)]
......
......@@ -7,6 +7,7 @@ use crate::error::OpossumError;
use crate::light::Light;
use crate::lightdata::LightData;
use crate::optic_node::{OpticComponent, OpticNode, LightResult};
use petgraph::Direction::{Incoming, Outgoing};
use petgraph::algo::toposort;
use petgraph::algo::*;
use petgraph::prelude::{DiGraph, EdgeIndex, NodeIndex};
......@@ -118,14 +119,14 @@ impl OpticScenery {
.edges_directed(target_node, petgraph::Direction::Incoming)
.any(|e| e.weight().target_port() == target_port)
}
/// Return a reference to the [`OpticNode`] specifiec by the node index.
/// Return a reference to the [`OpticNode`] specified by its node index.
///
/// This function is mainly useful for setting up a reference node.
///
/// # Errors
///
/// This function will return an error if the node does not exist.
pub fn node_ref(&self, node: NodeIndex) -> Result<Rc<RefCell<OpticNode>>> {
/// This function will return [`OpossumError::OpticScenery`]if the node does not exist.
pub fn node(&self, node: NodeIndex) -> Result<Rc<RefCell<OpticNode>>> {
if let Some(node) = self.g.node_weight(node) {
Ok(node.to_owned())
} else {
......@@ -225,6 +226,18 @@ impl OpticScenery {
println!("No outgoing edge found with given port name");
}
}
pub fn report(&self) {
let src_nodes=&self.g.externals(Incoming);
let sink_nodes=&self.g.externals(Outgoing);
println!("Sources:");
for idx in src_nodes.clone().into_iter() {
println!("{:?}", self.node(idx).unwrap().borrow());
}
println!("Sinks:");
for idx in sink_nodes.clone().into_iter() {
println!("{:?}", self.node(idx).unwrap().borrow());
}
}
}
#[cfg(test)]
......
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