Skip to content
Snippets Groups Projects
Commit a02e76b8 authored by y.zobus's avatar y.zobus
Browse files

Merge branch '346-wrong-dot-display-for-inverse-groups' into 'main'

fix: inverse group dot diagram now corrected

Closes #346

See merge request !220
parents 2e8639a9 8645ec62
No related branches found
No related tags found
1 merge request!220fix: inverse group dot diagram now corrected
Pipeline #13894 passed
...@@ -22,7 +22,7 @@ use std::{ ...@@ -22,7 +22,7 @@ use std::{
env, env,
fs::{create_dir, remove_dir_all, File}, fs::{create_dir, remove_dir_all, File},
io::{self, Write}, io::{self, Write},
path::Path, path::{Path, PathBuf},
}; };
fn read_and_parse_model(path: &Path) -> OpmResult<OpmDocument> { fn read_and_parse_model(path: &Path) -> OpmResult<OpmDocument> {
...@@ -30,15 +30,21 @@ fn read_and_parse_model(path: &Path) -> OpmResult<OpmDocument> { ...@@ -30,15 +30,21 @@ fn read_and_parse_model(path: &Path) -> OpmResult<OpmDocument> {
OpmDocument::from_file(path) OpmDocument::from_file(path)
} }
fn create_f_path(path: &Path, f_name: &str, f_ext: &str) -> PathBuf {
let mut f_path = path.to_path_buf();
f_path.push(f_name);
f_path.set_extension(f_ext);
f_path
}
fn create_dot_or_report_file_instance( fn create_dot_or_report_file_instance(
path: &Path, path: &Path,
f_name: &str, f_name: &str,
f_ext: &str, f_ext: &str,
print_str: &str, print_str: &str,
) -> OpmResult<File> { ) -> OpmResult<File> {
let mut f_path = path.to_path_buf(); let f_path = create_f_path(path, f_name, f_ext);
f_path.push(f_name);
f_path.set_extension(f_ext);
info!("Write {print_str} to {}...", f_path.display()); info!("Write {print_str} to {}...", f_path.display());
let _ = io::stdout().flush(); let _ = io::stdout().flush();
...@@ -53,8 +59,10 @@ fn create_dot_file(dot_path: &Path, scenery: &NodeGroup) -> OpmResult<()> { ...@@ -53,8 +59,10 @@ fn create_dot_file(dot_path: &Path, scenery: &NodeGroup) -> OpmResult<()> {
.map_err(|e| OpossumError::Other(format!("writing diagram file (.dot) failed: {e}")))?; .map_err(|e| OpossumError::Other(format!("writing diagram file (.dot) failed: {e}")))?;
let mut output = create_dot_or_report_file_instance(dot_path, "scenery", "svg", "diagram")?; let mut output = create_dot_or_report_file_instance(dot_path, "scenery", "svg", "diagram")?;
write!(output, "{}", scenery.toplevel_dot_svg()?)
.map_err(|e| OpossumError::Other(format!("writing diagram file (.svg) failed: {e}")))?; let f_path = create_f_path(dot_path, "scenery", "dot");
scenery.toplevel_dot_svg(&f_path, &mut output)?;
Ok(()) Ok(())
} }
fn create_data_dir(report_directory: &Path) -> OpmResult<()> { fn create_data_dir(report_directory: &Path) -> OpmResult<()> {
......
...@@ -28,7 +28,9 @@ use serde::{Deserialize, Serialize}; ...@@ -28,7 +28,9 @@ use serde::{Deserialize, Serialize};
use std::{ use std::{
cell::RefCell, cell::RefCell,
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},
fs::{self, File},
io::Write, io::Write,
path::PathBuf,
process::Stdio, process::Stdio,
rc::Rc, rc::Rc,
}; };
...@@ -394,8 +396,25 @@ impl NodeGroup { ...@@ -394,8 +396,25 @@ impl NodeGroup {
/// # Errors /// # Errors
/// ///
/// This function will return an error if the image generation fails (e.g. program not found, no memory left etc.). /// This function will return an error if the image generation fails (e.g. program not found, no memory left etc.).
pub fn toplevel_dot_svg(&self) -> OpmResult<String> { pub fn toplevel_dot_svg(&self, dot_str_file: &PathBuf, svg_file: &mut File) -> OpmResult<()> {
let dot_string = self.toplevel_dot("")?; let dot_string = fs::read_to_string(dot_str_file)
.map_err(|e| OpossumError::Other(format!("writing diagram file (.svg) failed: {e}")))?;
let svg_str = Self::dot_string_to_svg_str(dot_string.as_str())?;
write!(svg_file, "{svg_str}")
.map_err(|e| OpossumError::Other(format!("writing diagram file (.svg) failed: {e}")))
}
/// Converts a dot string to an svg string
/// # Attributes
/// `dot_string`: string that constains the dot information
/// # Errors
/// This function errors if
/// - the spawn of a childprocess fails
/// - the mutable stdin handle creation fails
/// - writing to child stdin fails
/// - output collection fails
/// - string to utf8 conversion fails
fn dot_string_to_svg_str(dot_string: &str) -> OpmResult<String> {
let mut child = std::process::Command::new("dot") let mut child = std::process::Command::new("dot")
.arg("-Tsvg:cairo") .arg("-Tsvg:cairo")
.arg("-Kdot") .arg("-Kdot")
......
...@@ -659,7 +659,9 @@ impl OpticGraph { ...@@ -659,7 +659,9 @@ impl OpticGraph {
//check direction //check direction
let rankdir = if rankdir == "LR" { "LR" } else { "TB" }; let rankdir = if rankdir == "LR" { "LR" } else { "TB" };
let mut dot_string = String::default(); let mut dot_string = String::default();
for node in self.nodes() { let sorted = self.topologically_sorted()?;
for idx in &sorted {
let node = self.node_by_idx(*idx)?;
let node_name = node.optical_ref.borrow().name(); let node_name = node.optical_ref.borrow().name();
let inverted = node.optical_ref.borrow().node_attr().inverted(); let inverted = node.optical_ref.borrow().node_attr().inverted();
let ports = node.optical_ref.borrow().ports(); let ports = node.optical_ref.borrow().ports();
......
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