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

OpticGraph: implement d13n of edges.

opticscnery example now exports model file (opticscenery.opm)
parent 7019a369
No related branches found
No related tags found
1 merge request!16Implement basic serialization / deserialization of OPOSSUM models
Pipeline #7589 passed
......@@ -4,5 +4,6 @@
/book
*.dot
*.svg
# exclude OPOSSUM model files
*.opm
# include dot files in /files_for_testing/*
\ No newline at end of file
......@@ -16,6 +16,10 @@ fn main() -> Result<(), OpossumError> {
let serialized=serde_yaml::to_string(&scenery).unwrap();
println!("{}", serialized);
let path = "opticscenery.opm";
let mut output = File::create(path).unwrap();
write!(output, "{}", serialized).unwrap();
let restored= serde_yaml::from_str::<OpticScenery>(&serialized);
println!("{:?}", restored);
......
......@@ -13,8 +13,8 @@ use petgraph::algo::*;
use petgraph::prelude::NodeIndex;
use petgraph::visit::EdgeRef;
use petgraph::Direction::Incoming;
use serde::ser::SerializeStruct;
use serde::Serialize;
//use serde::ser::SerializeStruct;
//use serde::Serialize;
use serde_derive::{Serialize, Deserialize};
type Result<T> = std::result::Result<T, OpossumError>;
......
......@@ -170,26 +170,14 @@ impl<'de> Deserialize<'de> for OpticGraph {
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("an OpticGraph")
}
fn visit_seq<A>(self, mut seq: A) -> std::result::Result<OpticGraph, A::Error>
where
A: SeqAccess<'de>,
{
println!("visit seq");
let g = OpticGraph::default();
// let node_type = seq
// .next_element()?
// .ok_or_else(|| de::Error::invalid_length(0, &self))?;
// let properties = seq
// .next_element()?
// .ok_or_else(|| de::Error::invalid_length(1, &self))?;
// let node =
// create_node_ref(node_type).map_err(|e| de::Error::custom(e.to_string()))?;
// node.0
// .borrow_mut()
// .set_properties(&properties)
// .map_err(|e| de::Error::custom(e.to_string()))?;
Ok(g)
}
// fn visit_seq<A>(self, mut seq: A) -> std::result::Result<OpticGraph, A::Error>
// where
// A: SeqAccess<'de>,
// {
// println!("visit seq");
// let g = OpticGraph::default();
// Ok(g)
// }
fn visit_map<A>(self, mut map: A) -> std::result::Result<OpticGraph, A::Error>
where
A: MapAccess<'de>,
......@@ -215,10 +203,14 @@ impl<'de> Deserialize<'de> for OpticGraph {
}
}
let nodes = nodes.ok_or_else(|| de::Error::missing_field("nodes"))?;
let _edges = edges.ok_or_else(|| de::Error::missing_field("edges"))?;
let edges = edges.ok_or_else(|| de::Error::missing_field("edges"))?;
for node in nodes.iter() {
g.0.add_node(node.clone());
}
for edge in edges.iter() {
g.0
.add_edge(edge.0, edge.1, Light::new(edge.2, edge.3));
}
Ok(g)
}
}
......
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