Skip to content
Snippets Groups Projects
reference.rs 953 B
Newer Older
Udo Eisenbarth's avatar
Udo Eisenbarth committed
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use crate::optic_node::{Dottable, OpticNode, Optical};
use crate::optic_ports::OpticPorts;
/// A virtual component referring to another existing component. This node type is necessary in order to model resonators (loops) or double-pass systems.
pub struct NodeReference {
Udo Eisenbarth's avatar
Udo Eisenbarth committed
    reference: Weak<RefCell<OpticNode>>,
impl NodeReference {
    pub fn from_node(node: Rc<RefCell<OpticNode>>) -> OpticNode {
        let node_ref = Self {
            reference: Rc::downgrade(&node),
        };
Udo Eisenbarth's avatar
Udo Eisenbarth committed
        OpticNode::new(&format!("Ref: \"{}\"", &node.borrow().name()), node_ref)
impl Optical for NodeReference {
    fn node_type(&self) -> &str {
        "reference"
    }
    fn ports(&self) -> OpticPorts {
        self.reference.upgrade().unwrap().borrow().ports().clone()
impl Dottable for NodeReference {
    fn node_color(&self) -> &str {
        "lightsalmon3"