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

connect_nodes check src & target ports

parent 133ef2ae
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,9 @@ fn main() {
scenery.connect_nodes(n1, "rear", n2, "front").unwrap();
scenery.connect_nodes(n2, "rear", n3, "front").unwrap();
scenery.connect_nodes(n3, "rear", n4, "front").unwrap();
scenery.connect_nodes(n4, "rear", n3i, "front").unwrap();
scenery.connect_nodes(n3i, "rear", n2i, "front").unwrap();
scenery.connect_nodes(n2i, "rear", n1i, "front").unwrap();
scenery.connect_nodes(n4, "rear", n3i, "rear").unwrap();
scenery.connect_nodes(n3i, "front", n2i, "rear").unwrap();
scenery.connect_nodes(n2i, "front", n1i, "rear").unwrap();
let mut group = NodeGroup::new();
let g_n1 = group.add_node(OpticNode::new("Beamsplitter", NodeDummy));
......
......@@ -42,9 +42,9 @@ fn main() {
);
scenery.connect_nodes(pump_compressor_node, "rear", pump_shg_node, "front");
scenery.connect_nodes(pump_shg_node, "rear", pump_splitter_node, "front");
scenery.connect_nodes(pump_splitter_node, "rear", uOPA_1_node, "front");
scenery.connect_nodes(pump_splitter_node, "transmitted", uOPA_1_node, "front").unwrap();
scenery.connect_nodes(uOPA_1_node, "rear", uOPA_2_node, "front");
scenery.connect_nodes(pump_splitter_node, "rear", uOPA_2_node, "front");
scenery.connect_nodes(pump_splitter_node, "reflected", uOPA_2_node, "front").unwrap();
let mut scenery_2 = OpticScenery::new();
scenery_2.set_description("PHELIX uOPA Pump Pre-Amplifier".into());
......
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct Light {
src_port: String,
target_port: String
}
\ No newline at end of file
src_port: String,
target_port: String,
}
impl Light {
pub fn new(src_port: &str, target_port: &str) -> Self {
Self {
src_port: src_port.into(),
target_port: target_port.into(),
}
}
}
......@@ -55,17 +55,33 @@ impl OpticScenery {
target_node: NodeIndex,
target_port: &str,
) -> Result<EdgeIndex> {
if self.g.node_weight(src_node).is_none() {
if let Some(source) = self.g.node_weight(src_node) {
if source.ports().outputs().contains(&src_port.into()) {
} else {
return Err(OpossumError::OpticScenery(
format!("source node {} does not have a port {}", source.name(), src_port),
));
}
} else {
return Err(OpossumError::OpticScenery(
"source node with gievn index does not exist".into(),
"source node with given index does not exist".into(),
));
}
if self.g.node_weight(target_node).is_none() {
if let Some(target) = self.g.node_weight(target_node) {
if target.ports().inputs().contains(&target_port.into()) {
} else {
return Err(OpossumError::OpticScenery(
format!("target node {} does not have a port {}", target.name(), target_port),
));
}
} else {
return Err(OpossumError::OpticScenery(
"target node with given index does not exist".into(),
));
}
let edge_index = self.g.add_edge(src_node, target_node, Light::default());
let edge_index = self.g.add_edge(src_node, target_node, Light::new("", ""));
if is_cyclic_directed(&self.g) {
self.g.remove_edge(edge_index);
return Err(OpossumError::OpticScenery(
......
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