Skip to content

Commit

Permalink
Delete constraints when depending features are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Nov 9, 2023
1 parent 2e9df89 commit 58fd757
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 37 deletions.
77 changes: 40 additions & 37 deletions detailer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,47 +77,50 @@ impl<'a> Widget<'a> {
let mut commands: Vec<ToolResponse> = Vec::with_capacity(4);
let mut changed = false;
let selected: Vec<FeatureKey> = self.drawing.selected_map.keys().map(|k| *k).collect();
for k in selected {
ui.push_id(k, |ui| {
match self.drawing.feature_mut(k) {
Some(Feature::Point(_, x, y)) => Widget::show_selection_entry_point(
ui,
&mut commands,
&mut changed,
&k,
x,
y,
),
Some(Feature::LineSegment(_, _p1, _p2)) => {
Widget::show_selection_entry_line(ui, &mut commands, &mut changed, &k)

egui::ScrollArea::vertical().show(ui, |ui| {
for k in selected {
ui.push_id(k, |ui| {
match self.drawing.feature_mut(k) {
Some(Feature::Point(_, x, y)) => Widget::show_selection_entry_point(
ui,
&mut commands,
&mut changed,
&k,
x,
y,
),
Some(Feature::LineSegment(_, _p1, _p2)) => {
Widget::show_selection_entry_line(ui, &mut commands, &mut changed, &k)
}
None => {}
}
None => {}
}

let constraints = self.drawing.constraints_by_feature(&k);
if constraints.len() > 0 {
egui::CollapsingHeader::new("Constraints")
.default_open(true)
.show(ui, |ui| {
for ck in constraints {
match self.drawing.constraint_mut(ck) {
Some(Constraint::Fixed(_, _, x, y)) => {
Widget::show_constraint_fixed(
ui,
&mut commands,
&mut changed,
&ck,
x,
y,
)
let constraints = self.drawing.constraints_by_feature(&k);
if constraints.len() > 0 {
egui::CollapsingHeader::new("Constraints")
.default_open(true)
.show(ui, |ui| {
for ck in constraints {
match self.drawing.constraint_mut(ck) {
Some(Constraint::Fixed(_, _, x, y)) => {
Widget::show_constraint_fixed(
ui,
&mut commands,
&mut changed,
&ck,
x,
y,
)
}
None => {}
}
None => {}
}
}
});
}
});
}
});
}
});
}
});

for c in commands.drain(..) {
self.handler.handle(self.drawing, self.tools, c);
Expand Down
6 changes: 6 additions & 0 deletions drawing/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ impl Data {

let out = match self.features.remove(k) {
Some(_v) => {
// Find and remove any constraints dependent on what we just removed.
let dependent_constraints = self.constraints.by_feature(&k);
for c in dependent_constraints {
self.constraints.delete(c);
}

// Find and also remove any features dependent on what we just removed.
let to_delete: std::collections::HashSet<FeatureKey> = self
.features
Expand Down

0 comments on commit 58fd757

Please sign in to comment.