Newer
Older
use crate::properties::{Properties, Property};
type Result<T> = std::result::Result<T, OpossumError>;
/// A virtual component referring to another existing component.
///
/// This node type is necessary in order to model resonators (loops) or double-pass systems.
/// - input ports of the referenced [`Optical`]
/// - output ports of the referenced [`Optical`]
pub struct NodeReference {
reference: Option<Weak<RefCell<dyn Optical>>>,
// Create new [`OpticNode`] (of type [`NodeReference`]) from another existing [`OpticNode`].
pub fn from_node(node: Rc<RefCell<dyn Optical>>) -> Self {
reference: Some(Rc::downgrade(&node)),
impl Optical for NodeReference {
fn node_type(&self) -> &str {
"reference"
}
if let Some(rf) = &self.reference {
rf.upgrade().unwrap().borrow().ports().clone()
} else {
OpticPorts::default()
}
fn analyze(
&mut self,
incoming_data: LightResult,
analyzer_type: &AnalyzerType,
) -> Result<LightResult> {
if let Some(rf) = &self.reference {
rf.upgrade()
.unwrap()
.borrow_mut()
.analyze(incoming_data, analyzer_type)
Err(OpossumError::Analysis(
"reference node has no reference defined".into(),
))
fn properties(&self) -> &Properties {
&self.props
}
fn set_property(&mut self, name: &str, prop: Property) -> Result<()> {
if self.props.set(name, prop).is_none() {
Err(OpossumError::Other("property not defined".into()))
} else {
Ok(())
}
}
impl Dottable for NodeReference {
fn node_color(&self) -> &str {
"lightsalmon3"