Compare commits
2 Commits
5a2577b2bc
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 95814bf633 | |||
| 267bb6c513 |
@ -65,6 +65,7 @@ pub enum BasicDataType {
|
||||
PositiveAssertFunction,
|
||||
PositiveGroupFunction,
|
||||
Svg,
|
||||
BooleanNetwork,
|
||||
}
|
||||
|
||||
/// Should reflect `BasicDataType`'s values, holding the data that will be
|
||||
@ -180,6 +181,9 @@ pub enum BasicValue {
|
||||
Svg {
|
||||
value: super::svg::Svg,
|
||||
},
|
||||
BooleanNetwork {
|
||||
value: rsprocess::boolean::BooleanNetwork,
|
||||
},
|
||||
}
|
||||
|
||||
impl Hash for BasicValue {
|
||||
@ -222,7 +226,8 @@ impl Hash for BasicValue {
|
||||
PositiveReactions,
|
||||
PositiveAssertFunction,
|
||||
PositiveGroupFunction,
|
||||
Svg
|
||||
Svg,
|
||||
BooleanNetwork
|
||||
);
|
||||
|
||||
match self {
|
||||
@ -350,6 +355,11 @@ pub enum NodeInstruction {
|
||||
PositiveTrace,
|
||||
PositiveSliceTrace,
|
||||
PositiveTraceToString,
|
||||
|
||||
// BooleanNetworks
|
||||
BooleanNetwork,
|
||||
BNtoRS,
|
||||
BNtoPositiveRS,
|
||||
}
|
||||
|
||||
impl NodeInstruction {
|
||||
@ -502,6 +512,9 @@ impl NodeInstruction {
|
||||
| Self::SaveRasterization => vec![("path", Path), ("value", Svg)],
|
||||
| Self::ExecuteCommand => vec![("command", String), ("value", String)],
|
||||
| Self::ToSingleProducts => vec![("sys", System)],
|
||||
| Self::BooleanNetwork => vec![("value", String)],
|
||||
| Self::BNtoRS => vec![("value", BooleanNetwork)],
|
||||
| Self::BNtoPositiveRS => vec![("value", BooleanNetwork)],
|
||||
}
|
||||
.into_iter()
|
||||
.map(|e| (e.0.to_string(), e.1))
|
||||
@ -602,6 +615,9 @@ impl NodeInstruction {
|
||||
| Self::SaveRasterization => vec![],
|
||||
| Self::ExecuteCommand => vec![("out", String)],
|
||||
| Self::ToSingleProducts => vec![("out", System)],
|
||||
| Self::BooleanNetwork => vec![("out", BooleanNetwork)],
|
||||
| Self::BNtoRS => vec![("out", System)],
|
||||
| Self::BNtoPositiveRS => vec![("out", PositiveSystem)],
|
||||
};
|
||||
res.into_iter()
|
||||
.map(|res| (res.0.to_string(), res.1))
|
||||
@ -706,6 +722,9 @@ impl NodeInstruction {
|
||||
assert::positive_grouping::PositiveAssert::default()
|
||||
),
|
||||
| BasicDataType::Svg => helper!(Svg, super::svg::Svg::default()),
|
||||
| BasicDataType::BooleanNetwork =>
|
||||
helper!(BooleanNetwork,
|
||||
rsprocess::boolean::BooleanNetwork::default())
|
||||
}
|
||||
}
|
||||
|
||||
@ -762,6 +781,7 @@ impl NodeInstruction {
|
||||
| BasicDataType::PositiveGroupFunction =>
|
||||
helper!(PositiveGroupFunction),
|
||||
| BasicDataType::Svg => helper!(Svg),
|
||||
| BasicDataType::BooleanNetwork => helper!(BooleanNetwork),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -816,12 +836,12 @@ impl OutputsCache {
|
||||
s.finish()
|
||||
}
|
||||
|
||||
pub fn input_hashes(&self, key: &OutputId) -> Option<Vec<u64>> {
|
||||
pub(crate) fn input_hashes(&self, key: &OutputId) -> Option<Vec<u64>> {
|
||||
let internals = self.internals.read().unwrap();
|
||||
internals.hash_inputs.get(key).map(|el| el.1.to_vec())
|
||||
}
|
||||
|
||||
pub fn same_hash_inputs(&self, key: &OutputId, inputs: &[u64]) -> bool {
|
||||
pub(crate) fn same_hash_inputs(&self, key: &OutputId, inputs: &[u64]) -> bool {
|
||||
let hash_inputs = inputs.iter().fold(0, |acc, x| acc ^ x);
|
||||
let internals = self.internals.read().unwrap();
|
||||
internals
|
||||
@ -840,7 +860,7 @@ impl OutputsCache {
|
||||
internals.hash_inputs.insert(key, (hash_inputs, inputs));
|
||||
}
|
||||
|
||||
pub fn retrieve_cache_output(
|
||||
pub(crate) fn retrieve_cache_output(
|
||||
&self,
|
||||
graph: &NodeGraph,
|
||||
node_id: NodeId,
|
||||
@ -860,12 +880,12 @@ impl OutputsCache {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn retrieve_output(&self, key: OutputId) -> Option<BasicValue> {
|
||||
pub(crate) fn retrieve_output(&self, key: OutputId) -> Option<BasicValue> {
|
||||
let internals = self.internals.read().unwrap();
|
||||
internals.values.get(&key).cloned()
|
||||
}
|
||||
|
||||
pub fn populate_output(
|
||||
pub(crate) fn populate_output(
|
||||
&self,
|
||||
graph: &NodeGraph,
|
||||
node_id: NodeId,
|
||||
@ -878,36 +898,35 @@ impl OutputsCache {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn invalidate_cache(&self, key: &OutputId) {
|
||||
pub(crate) fn invalidate_cache(&self, key: &OutputId) {
|
||||
let mut internals = self.internals.write().unwrap();
|
||||
internals.hash_inputs.remove(key);
|
||||
internals.hash_values.remove(key);
|
||||
internals.values.remove(key);
|
||||
}
|
||||
|
||||
pub fn invalidate_outputs(&self, graph: &NodeGraph, node_id: NodeId) {
|
||||
pub(crate) fn invalidate_outputs(&self, graph: &NodeGraph, node_id: NodeId) {
|
||||
for output_id in graph[node_id].output_ids() {
|
||||
self.invalidate_cache(&output_id);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn reset_cache(&self) {
|
||||
pub(crate) fn reset_cache(&self) {
|
||||
let mut internals = self.internals.write().unwrap();
|
||||
*internals = CacheInternals::default();
|
||||
}
|
||||
|
||||
pub fn get_last_state(&self) -> Option<BasicValue> {
|
||||
pub(crate) fn get_last_state(&self) -> Option<BasicValue> {
|
||||
let internals = self.internals.read().unwrap();
|
||||
internals.last_output.clone()
|
||||
}
|
||||
|
||||
pub fn invalidate_last_state(&self) {
|
||||
pub(crate) fn invalidate_last_state(&self) {
|
||||
let mut internals = self.internals.write().unwrap();
|
||||
internals.last_output = None;
|
||||
}
|
||||
|
||||
pub fn set_last_state(&self, val: BasicValue) {
|
||||
pub(crate) fn set_last_state(&self, val: BasicValue) {
|
||||
let mut internals = self.internals.write().unwrap();
|
||||
internals.last_output = Some(val);
|
||||
}
|
||||
@ -967,6 +986,8 @@ impl DataTypeTrait<GlobalState> for BasicDataType {
|
||||
| Self::GroupFunction => Color32::from_hex("#750086"),
|
||||
| Self::PositiveAssertFunction => Color32::from_hex("#35C9FD"),
|
||||
| Self::PositiveGroupFunction => Color32::from_hex("#02B7F3"),
|
||||
|
||||
| Self::BooleanNetwork => Color32::from_hex("#9437FF"),
|
||||
}.expect("Wrong color specification.")
|
||||
}
|
||||
|
||||
@ -1005,6 +1026,7 @@ impl DataTypeTrait<GlobalState> for BasicDataType {
|
||||
| Self::PositiveGroupFunction =>
|
||||
Cow::Borrowed("positive group function"),
|
||||
| Self::Svg => Cow::Borrowed("svg"),
|
||||
| Self::BooleanNetwork => Cow::Borrowed("boolean network"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1114,6 +1136,9 @@ impl NodeTemplateTrait for NodeInstruction {
|
||||
| Self::ExecuteCommand => "Execute Command",
|
||||
|
||||
| Self::ToSingleProducts => "Convert to Single Products",
|
||||
| Self::BooleanNetwork => "Create Boolean Network",
|
||||
| Self::BNtoRS => "Convert Boolean Network to RS",
|
||||
| Self::BNtoPositiveRS => "Convert Boolean Network to Positive RS",
|
||||
})
|
||||
}
|
||||
|
||||
@ -1199,6 +1224,9 @@ impl NodeTemplateTrait for NodeInstruction {
|
||||
| Self::Sleep | Self::StringToSvg | Self::SaveSvg
|
||||
| Self::SaveRasterization | Self::ExecuteCommand =>
|
||||
vec!["General"],
|
||||
| Self::BooleanNetwork
|
||||
| Self::BNtoRS
|
||||
| Self::BNtoPositiveRS => vec!["Boolean Network"],
|
||||
}
|
||||
}
|
||||
|
||||
@ -1309,6 +1337,9 @@ impl NodeTemplateIter for AllInstructions {
|
||||
NodeInstruction::SaveRasterization,
|
||||
NodeInstruction::ExecuteCommand,
|
||||
NodeInstruction::ToSingleProducts,
|
||||
NodeInstruction::BooleanNetwork,
|
||||
NodeInstruction::BNtoRS,
|
||||
NodeInstruction::BNtoPositiveRS,
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -1451,6 +1482,9 @@ impl WidgetValueTrait for BasicValue {
|
||||
| BasicValue::Svg { value: _ } => {
|
||||
ui.label(param_name);
|
||||
},
|
||||
| BasicValue::BooleanNetwork { value: _ } => {
|
||||
ui.label(param_name);
|
||||
},
|
||||
}
|
||||
|
||||
responses
|
||||
@ -2469,6 +2503,11 @@ fn get_layout(
|
||||
| BasicValue::Svg { value } => {
|
||||
return WidgetLayout::Image(value.get_texture(ctx));
|
||||
},
|
||||
| BasicValue::BooleanNetwork { value } => text.append(
|
||||
&format!("{}", Formatter::from(translator, &value)),
|
||||
0.,
|
||||
Default::default(),
|
||||
),
|
||||
},
|
||||
| Err(err) => {
|
||||
text.append(&format!("{err:?}"), 0., TextFormat {
|
||||
|
||||
@ -105,14 +105,13 @@ fn generate_to_evaluate(
|
||||
}
|
||||
}
|
||||
}
|
||||
dependencies.reverse();
|
||||
|
||||
// then keep only the ones that have an input that is different or not
|
||||
// cached
|
||||
let mut res = vec![];
|
||||
let mut invalid_ids = HashSet::new();
|
||||
|
||||
for n_id in dependencies {
|
||||
for &n_id in dependencies.iter().rev() {
|
||||
let mut input_hashes = vec![];
|
||||
|
||||
match graph[n_id].user_data.template {
|
||||
@ -2727,6 +2726,72 @@ fn process_template(
|
||||
anyhow::bail!("Not a system");
|
||||
}
|
||||
},
|
||||
| NodeInstruction::BooleanNetwork => {
|
||||
let s = retrieve_from_cache![1];
|
||||
let hash_inputs = hash_inputs!(s);
|
||||
|
||||
if let BasicValue::String { value } = s {
|
||||
let res = grammar_separated::boolean::BooleanNetworkParser::new()
|
||||
.parse(&mut translator.lock().unwrap(), &value);
|
||||
|
||||
let value = match res {
|
||||
| Ok(s) => s,
|
||||
| Err(parse_error) => {
|
||||
return Ok(Some(BasicValue::Error {
|
||||
value: helper::reformat_error(
|
||||
parse_error,
|
||||
&value,
|
||||
ctx,
|
||||
),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
let res = BasicValue::BooleanNetwork { value };
|
||||
|
||||
set_cache_output!((
|
||||
output_names.first().unwrap(),
|
||||
res,
|
||||
hash_inputs
|
||||
));
|
||||
} else {
|
||||
anyhow::bail!("Not a string");
|
||||
}
|
||||
},
|
||||
| NodeInstruction::BNtoRS => {
|
||||
let s = retrieve_from_cache![1];
|
||||
let hash_inputs = hash_inputs!(s);
|
||||
|
||||
if let BasicValue::BooleanNetwork { value } = s {
|
||||
let res = BasicValue::System {
|
||||
value: value.into(),
|
||||
};
|
||||
set_cache_output!((
|
||||
output_names.first().unwrap(),
|
||||
res,
|
||||
hash_inputs
|
||||
));
|
||||
} else {
|
||||
anyhow::bail!("Not a boolean network");
|
||||
}
|
||||
},
|
||||
| NodeInstruction::BNtoPositiveRS => {
|
||||
let s = retrieve_from_cache![1];
|
||||
let hash_inputs = hash_inputs!(s);
|
||||
|
||||
if let BasicValue::BooleanNetwork { value } = s {
|
||||
let res = BasicValue::PositiveSystem {
|
||||
value: value.into(),
|
||||
};
|
||||
set_cache_output!((
|
||||
output_names.first().unwrap(),
|
||||
res,
|
||||
hash_inputs
|
||||
));
|
||||
} else {
|
||||
anyhow::bail!("Not a boolean network");
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user