From fc57e72e80cea7e1b567c40b61172a060f989772 Mon Sep 17 00:00:00 2001 From: elvis Date: Sat, 25 Oct 2025 17:46:42 +0200 Subject: [PATCH] trace to string --- reaction_systems_gui/src/app.rs | 15 +++++++++++++- reaction_systems_gui/src/app_logic.rs | 28 ++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/reaction_systems_gui/src/app.rs b/reaction_systems_gui/src/app.rs index bd893a7..82f10e9 100644 --- a/reaction_systems_gui/src/app.rs +++ b/reaction_systems_gui/src/app.rs @@ -284,6 +284,8 @@ pub enum NodeInstruction { PositiveTrace, SliceTrace, PositiveSliceTrace, + TraceToString, + PositiveTraceToString, } impl NodeInstruction { @@ -377,6 +379,8 @@ impl NodeInstruction { ("reactions", PositiveReactions), ], | Self::DecomposePositiveSystem => vec![("system", PositiveSystem)], + | Self::TraceToString => vec![("trace", Trace)], + | Self::PositiveTraceToString => vec![("trace", PositiveTrace)], } .into_iter() .map(|e| (e.0.to_string(), e.1)) @@ -442,6 +446,8 @@ impl NodeInstruction { ("context", PositiveContext), ("reactions", PositiveReactions), ], + | Self::TraceToString => vec![("out", String)], + | Self::PositiveTraceToString => vec![("out", String)], }; res.into_iter().map(|res| (res.0.to_string(), res.1)).collect::<_>() } @@ -857,6 +863,8 @@ impl NodeTemplateTrait for NodeInstruction { | Self::ComposePositiveSystem => "Compose a positive system", | Self::DecomposeSystem => "Decompose a system", | Self::DecomposePositiveSystem => "Decompose a positive system", + | Self::TraceToString => "Trace to string", + | Self::PositiveTraceToString => "Positive trace to string", }) } @@ -910,7 +918,10 @@ impl NodeTemplateTrait for NodeInstruction { | Self::DecomposePositiveSystem => vec!["Positive System"], | Self::Trace => vec!["Trace", "System"], | Self::PositiveTrace => vec!["Trace", "Positive System"], - | Self::SliceTrace | Self::PositiveSliceTrace => vec!["Trace"], + | Self::SliceTrace + | Self::PositiveSliceTrace + | Self::TraceToString + | Self::PositiveTraceToString => vec!["Trace"], } } @@ -992,6 +1003,8 @@ impl NodeTemplateIter for AllInstructions { NodeInstruction::ComposePositiveSystem, NodeInstruction::DecomposeSystem, NodeInstruction::DecomposePositiveSystem, + NodeInstruction::TraceToString, + NodeInstruction::PositiveTraceToString, ] } } diff --git a/reaction_systems_gui/src/app_logic.rs b/reaction_systems_gui/src/app_logic.rs index 588cebc..bd1c7a7 100644 --- a/reaction_systems_gui/src/app_logic.rs +++ b/reaction_systems_gui/src/app_logic.rs @@ -1589,7 +1589,33 @@ fn process_template( } else { anyhow::bail!("Not a positive system"); } - } + }, + | NodeInstruction::TraceToString => { + let trace = retrieve_from_cache![1]; + let hash_inputs = hash_inputs!(trace); + + if let BasicValue::Trace { value } = trace { + let res = BasicValue::String { + value: format!("{}", Formatter::from(translator, &value)), + }; + set_cache_output!((output_names.first().unwrap(), res, hash_inputs)); + } else { + anyhow::bail!("Not a trace"); + } + }, + | NodeInstruction::PositiveTraceToString => { + let trace = retrieve_from_cache![1]; + let hash_inputs = hash_inputs!(trace); + + if let BasicValue::PositiveTrace { value } = trace { + let res = BasicValue::String { + value: format!("{}", Formatter::from(translator, &value)), + }; + set_cache_output!((output_names.first().unwrap(), res, hash_inputs)); + } else { + anyhow::bail!("Not a positive trace"); + } + }, } Ok(None) }