Skip to content

Commit

Permalink
fixed positions in recursive system pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
BenKenobie31415 committed Mar 10, 2024
1 parent d711205 commit 3a76819
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public class CopyPositionableViewModelElementVisitor implements PositionableView
private HashMap<Element, Pair<Point2D, Point2D>> elementToPosAndSize;
@Getter
private Set<PositionableViewModelElement<?>> failedCopies;
private final Set<Element> copiedElements;

public CopyPositionableViewModelElementVisitor(GeckoViewModel geckoViewModel) {
this.geckoViewModel = geckoViewModel;
isAutomatonCopy = geckoViewModel.getCurrentEditor().isAutomatonEditor();
originalToClipboard = new HashMap<>();
elementToPosAndSize = new HashMap<>();
copiedElements = new HashSet<>();
failedCopies = new HashSet<>();
}

Expand All @@ -62,6 +64,7 @@ public Void visit(SystemViewModel systemViewModel) {
originalToClipboard.putAll(copyResult.getValue());
originalToClipboard.put(original, copy);
savePositionRecursively(original);
copiedElements.add(copy);
return null;
}

Expand All @@ -71,6 +74,7 @@ public Void visit(RegionViewModel regionViewModel) {
Region copy = geckoViewModel.getGeckoModel().getModelFactory().copyRegion(original);
originalToClipboard.put(original, copy);
savePositionAndSize(copy, regionViewModel);
copiedElements.add(copy);
return null;
}

Expand All @@ -92,6 +96,7 @@ public Void visit(EdgeViewModel edgeViewModel) {
copy.setDestination(destinationOnClipboard);
copy.setContract(contractOnClipboard);
originalToClipboard.put(original, copy);
copiedElements.add(copy);
}
return null;
}
Expand All @@ -105,6 +110,7 @@ public Void visit(StateViewModel stateViewModel) {
originalToClipboard.putAll(copyResult.getValue());
originalToClipboard.put(original, copy);
savePositionAndSize(copy, stateViewModel);
copiedElements.add(copy);
return null;
}

Expand Down Expand Up @@ -143,6 +149,7 @@ public Void visit(SystemConnectionViewModel systemConnectionViewModel) {
throw new RuntimeException(e);
}
originalToClipboard.put(original, copy);
copiedElements.add(copy);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class PastePositionableViewModelElementAction extends Action {
private final GeckoViewModel geckoViewModel;
private final Set<PositionableViewModelElement<?>> pastedElements;
private final Point2D pasteOffset;
private CopyPositionableViewModelElementVisitor copyVisitor;

PastePositionableViewModelElementAction(GeckoViewModel geckoViewModel, Point2D center) {
this.geckoViewModel = geckoViewModel;
Expand All @@ -32,7 +31,7 @@ boolean run() throws GeckoException {

PastePositionableViewModelElementVisitor pasteVisitor =
new PastePositionableViewModelElementVisitor(geckoViewModel, copyVisitor, pasteOffset);
for (Element element : copyVisitor.getOriginalToClipboard().values()) {
for (Element element : copyVisitor.getCopiedElements()) {
element.accept(pasteVisitor);
}
while (!pasteVisitor.getUnsuccessfulPastes().isEmpty()) {
Expand All @@ -44,9 +43,9 @@ boolean run() throws GeckoException {
}
pasteVisitor.updatePositions();
pastedElements.addAll(pasteVisitor.getPastedElements());
Action selectAction =
/*Action selectAction =
geckoViewModel.getActionManager().getActionFactory().createSelectAction(pastedElements, true);
geckoViewModel.getActionManager().run(selectAction);
geckoViewModel.getActionManager().run(selectAction);*/
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ private void createRecursiveSystemViewModels(System systemToPaste) {
geckoViewModel.getViewModelFactory().createRegionViewModelFrom(region);
regionViewModel.setPosition(
copyVisitor.getElementToPosAndSize().get(clipboardToPasted.inverse().get(region)).getKey());
regionViewModel.setSize(
copyVisitor.getElementToPosAndSize().get(clipboardToPasted.inverse().get(region)).getValue());
} catch (MissingViewModelElementException e) {
throw new RuntimeException(e);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/gecko/model/ModelFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public Pair<System, Map<Element, Element>> copySystem(@NonNull System system, Ma
copy.getAutomaton().setStartState(copiedState);
}
stateToCopy.put(state, copiedState);
originalToCopy.put(state, copiedState);
}
for (Edge edge : system.getAutomaton().getEdges()) {
State copiedSource = stateToCopy.get(edge.getSource());
Expand Down

0 comments on commit 3a76819

Please sign in to comment.