Skip to content

Commit

Permalink
Fixed bug for actions when selecting multiple nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
oskari1 committed Dec 2, 2023
1 parent 477d6d3 commit 2414c6b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 78 deletions.
16 changes: 9 additions & 7 deletions axiom-profiler-GUI/src/results/filters/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use yew::prelude::*;
use material_yew::WeakComponentLink;

pub enum Msg {
AddFilter(Filter),
AddFilters(Vec<Filter>),
RemoveNthFilter(usize),
ResetFilters,
SetToPrevious,
Expand Down Expand Up @@ -54,11 +54,13 @@ impl yew::html::Component for FilterChain {

fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::AddFilter(filter) => {
log!("Adding filter ", filter.to_string());
Msg::AddFilters(filters) => {
self.prev_filter_chain = self.filter_chain.clone();
self.filter_chain.push(filter);
ctx.props().apply_filter.emit(filter);
for filter in filters {
log!("Adding filter ", filter.to_string());
self.filter_chain.push(filter);
ctx.props().apply_filter.emit(filter);
}
ctx.props().render_graph.emit(UserPermission::default());
true
}
Expand Down Expand Up @@ -109,11 +111,11 @@ impl yew::html::Component for FilterChain {
.collect();
let reset_filters = ctx.link().callback(|_| Msg::ResetFilters);

let add_filter = ctx.link().callback(Msg::AddFilter);
let add_filters = ctx.link().callback(Msg::AddFilters);
html!(
<>
<GraphFilter
add_filter={add_filter.clone()}
add_filters={add_filters.clone()}
dependency={ctx.props().dependency.clone()}
/>
<h2>{"Filter chain:"}</h2>
Expand Down
18 changes: 9 additions & 9 deletions axiom-profiler-GUI/src/results/filters/graph_filters.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::selected_node::SelectedNode;
use super::selected_node::SelectedNodes;
use crate::utils::input_state::{InputValue, UsizeInput};
use petgraph::{stable_graph::NodeIndex, Direction};
use smt_log_parser::{
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Filter {

#[derive(Properties, PartialEq)]
pub struct GraphFilterProps {
pub add_filter: Callback<Filter>,
pub add_filters: Callback<Vec<Filter>>,
pub dependency: AttrValue,
}

Expand All @@ -77,17 +77,17 @@ pub fn graph_filter(props: &GraphFilterProps) -> Html {

let add_max_line_nr_filter = {
let max_node_idx = max_node_idx.clone();
let callback = props.add_filter.clone();
Callback::from(move |_| callback.emit(Filter::MaxNodeIdx(max_node_idx.value)))
let callback = props.add_filters.clone();
Callback::from(move |_| callback.emit(vec![Filter::MaxNodeIdx(max_node_idx.value)]))
};
let add_theory_filter = {
let callback = props.add_filter.clone();
Callback::from(move |_| callback.emit(Filter::IgnoreTheorySolving))
let callback = props.add_filters.clone();
Callback::from(move |_| callback.emit(vec![Filter::IgnoreTheorySolving]))
};
let add_max_insts_filter = {
let max_instantiations = max_instantiations.clone();
let callback = props.add_filter.clone();
Callback::from(move |_| callback.emit(Filter::MaxInsts(max_instantiations.value)))
let callback = props.add_filters.clone();
Callback::from(move |_| callback.emit(vec![Filter::MaxInsts(max_instantiations.value)]))
};
html! {
<div>
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn graph_filter(props: &GraphFilterProps) -> Html {
</div>
{if selected_inst.len() > 0 {
html! {
<SelectedNode selected_nodes={selected_inst} action={props.add_filter.clone()} />
<SelectedNodes selected_nodes={selected_inst} action={props.add_filters.clone()} />
}
} else {
html! {}
Expand Down
79 changes: 17 additions & 62 deletions axiom-profiler-GUI/src/results/filters/selected_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,31 @@ use yew::{prelude::*, virtual_dom::VNode};
use super::graph_filters::Filter;

#[derive(Properties, PartialEq)]
pub struct SelectedNodeProps {
pub struct SelectedNodesProps {
pub selected_nodes: Vec<InstInfo>,
pub action: Callback<Filter>,
pub action: Callback<Vec<Filter>>,
}

#[function_component(SelectedNode)]
pub fn selected_node(props: &SelectedNodeProps) -> Html {
let hide_subtree = {
#[function_component(SelectedNodes)]
pub fn selected_node(props: &SelectedNodesProps) -> Html {
let callback_from = |filter_for_inst: Box<dyn Fn(&InstInfo) -> Filter>| {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::VisitSubTreeWithRoot(inst.node_index, false));
}
})
};
let show_subtree = {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::VisitSubTreeWithRoot(inst.node_index, true));
}
})
};
let show_children = {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::ShowNeighbours(inst.node_index, Outgoing))
}
})
};
let show_parents = {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::ShowNeighbours(inst.node_index, Incoming))
}
})
};
let show_source_tree = {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::VisitSourceTree(inst.node_index, true))
}
})
};
let hide_source_tree = {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::VisitSourceTree(inst.node_index, false))
}
})
};
let ignore_quantifier = {
let callback = props.action.clone();
let selected_insts = props.selected_nodes.clone();
Callback::from(move |_| {
for inst in &selected_insts {
callback.emit(Filter::IgnoreQuantifier(inst.quant))
}
let filters: Vec<Filter> = selected_insts
.iter()
.map(&filter_for_inst)
.collect();
callback.emit(filters);
})
};
let show_subtree = callback_from(Box::new(|inst: &InstInfo| Filter::VisitSubTreeWithRoot(inst.node_index, true)));
let hide_subtree = callback_from(Box::new(|inst: &InstInfo| Filter::VisitSubTreeWithRoot(inst.node_index, false)));
let show_children = callback_from(Box::new(|inst: &InstInfo| Filter::ShowNeighbours(inst.node_index, Outgoing)));
let show_parents = callback_from(Box::new(|inst: &InstInfo| Filter::ShowNeighbours(inst.node_index, Incoming)));
let show_source_tree = callback_from(Box::new(|inst: &InstInfo| Filter::VisitSourceTree(inst.node_index, true)));
let hide_source_tree = callback_from(Box::new(|inst: &InstInfo| Filter::VisitSourceTree(inst.node_index, false)));
let ignore_quantifier = callback_from(Box::new(|inst: &InstInfo| Filter::IgnoreQuantifier(inst.quant)));
let mut selected_nodes = props
.selected_nodes
.iter()
Expand Down

0 comments on commit 2414c6b

Please sign in to comment.