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