From 206c7af1eb2c8ae87f33ec8cc0aeee99093ba55a Mon Sep 17 00:00:00 2001 From: crissnb Date: Sun, 10 Mar 2024 19:00:27 +0100 Subject: [PATCH] fixes regions not being removed in scenarios with many regions --- src/main/java/org/gecko/viewmodel/EditorViewModel.java | 1 + src/main/java/org/gecko/viewmodel/RegionViewModel.java | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gecko/viewmodel/EditorViewModel.java b/src/main/java/org/gecko/viewmodel/EditorViewModel.java index 6d096e41..58ef5f3e 100644 --- a/src/main/java/org/gecko/viewmodel/EditorViewModel.java +++ b/src/main/java/org/gecko/viewmodel/EditorViewModel.java @@ -111,6 +111,7 @@ public void updateRegions() throws ModelException { .map(element -> (StateViewModel) element) .collect(Collectors.toSet()); for (RegionViewModel regionViewModel : regionViewModels) { + regionViewModel.clearStates(); for (StateViewModel stateViewModel : stateViewModels) { regionViewModel.checkStateInRegion(stateViewModel); regionViewModel.updateTarget(); diff --git a/src/main/java/org/gecko/viewmodel/RegionViewModel.java b/src/main/java/org/gecko/viewmodel/RegionViewModel.java index 0c65b2e3..652ae8cd 100644 --- a/src/main/java/org/gecko/viewmodel/RegionViewModel.java +++ b/src/main/java/org/gecko/viewmodel/RegionViewModel.java @@ -64,6 +64,10 @@ public void removeState(@NonNull StateViewModel state) { statesProperty.remove(state); } + public void clearStates() { + statesProperty.clear(); + } + @Override public Object accept(@NonNull PositionableViewModelElementVisitor visitor) { return visitor.visit(this); @@ -86,7 +90,7 @@ public Color getColor() { } /** - * Checks if the given state is in the region and adds it to the region if it is or removes it if it is not. + * Checks if the given state is in the region and adds it to the region if it is. * * @param state the state to check */ @@ -98,8 +102,6 @@ public void checkStateInRegion(StateViewModel state) { state.getSize().getY()); if (regionBound.intersects(stateBound)) { addState(state); - } else { - removeState(state); } }