From: Fabian Stemmler Date: Mon, 15 Jul 2019 16:19:15 +0000 (+0200) Subject: Merge branch 'development' of X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=6e1902e006401ddea190178595bf6ae6357e74ad;hp=-c;p=Mograsim.git Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019 into development # Conflicts: # net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java --- 6e1902e006401ddea190178595bf6ae6357e74ad diff --combined net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java index e4fb3142,c5e06a54..58e1f6cb --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/HandleManager.java @@@ -8,6 -8,7 +8,7 @@@ import java.util.HashSet import java.util.List; import java.util.Map; import java.util.Set; + import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.stream.Collectors; @@@ -89,7 -90,7 +90,7 @@@ public class HandleManage comps.remove(interfaceComp); registerInterfaceComponent(interfaceComp); comps.forEach(c -> registerComponent(c)); - + model.getWires().forEach(w -> registerWire(w)); addHandle(cornerHandle = new CornerHandle(editor.toBeEdited)); } @@@ -114,19 -115,24 +115,24 @@@ private void registerWire(GUIWire wire) { - wire.addPathChangedListener((w, diff) -> + Point[] path = wire.getPath(); + AtomicInteger oldLength = new AtomicInteger(path == null ? 0 : path.length); + wire.addPathChangedListener(w -> { + Point[] newPath = w.getPath(); + int newLength = newPath == null ? 0 : newPath.length; + int diff = oldLength.getAndSet(newLength) - newLength; - if(diff != 0) + if (diff != 0) { - if(diff > 0) + if (diff > 0) { - for(int i = 0; i < diff; i++) + for (int i = 0; i < diff; i++) addWirePointHandle(w); } - + List wpHandles = pointHandlesPerWire.get(w); int size = wpHandles.size(); - for(int i = 0; i < size; i++) + for (int i = 0; i < size; i++) { wpHandles.get(i).setIndex(i); } @@@ -134,9 -140,9 +140,9 @@@ pointHandlesPerWire.get(w).forEach(h -> h.updatePos()); }); addWireHandle(wire); - if (wire.getPath() == null) + if (path == null) return; - for (int i = 0; i < wire.getPath().length; i++) + for (int i = 0; i < path.length; i++) { addWirePointHandle(wire); } @@@ -176,8 -182,8 +182,8 @@@ private void addInterfacePinHandle(Pin p) { - //The following is not an alternative to the cast, because the new pin is not yet in the map, when the listener is called - //editor.toBeEdited.getSubmodelMovablePins().get(p.name); + // The following is not an alternative to the cast, because the new pin is not yet in the map, when the listener is called + // editor.toBeEdited.getSubmodelMovablePins().get(p.name); MovablePin pM = (MovablePin) p; InterfacePinHandle h = new InterfacePinHandle(pM, editor.toBeEdited); handlePerInterfacePin.put(pM, h); @@@ -207,7 -213,7 +213,7 @@@ this.wirePointHandles.add(h); addHandle(h); } - + void destroyWirePointHandle(GUIWire owner, WirePointHandle h) { List handles = pointHandlesPerWire.get(owner); @@@ -219,7 -225,7 +225,7 @@@ private void removeWirePointHandles(GUIWire owner) { - if(!pointHandlesPerWire.containsKey(owner)) + if (!pointHandlesPerWire.containsKey(owner)) return; pointHandlesPerWire.get(owner).forEach(h -> { @@@ -270,7 -276,7 +276,7 @@@ { return handlePerWire.get(parent); } - + public Handle getInterfacePinHandle(Pin p) { return handlePerInterfacePin.get(p); @@@ -299,7 -305,7 +305,7 @@@ { return Collections.unmodifiableCollection(handlePerPin.values()); } - + /** * @return An unmodifiable view of all registered {@link InterfacePinHandle}s */ @@@ -342,11 -348,11 +348,11 @@@ if (!click(getWirePointHandles(), clicked, entryState, stateMask)) if (!click(getWireHandles(), clicked, entryState, stateMask)) if (!click(handlePerComp.values(), clicked, entryState, stateMask)) - entryState.clickedEmpty(clicked, stateMask); + entryState.clickedEmpty(clicked, stateMask); entryState.clicked(clicked, stateMask); } -- private boolean click(Collection handles, Point clicked, EditorState state, int stateMask) ++ private static boolean click(Collection handles, Point clicked, EditorState state, int stateMask) { for (Handle h : handles) if (h.click(clicked.x, clicked.y, stateMask, state)) diff --combined net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java index a5e97d4c,0e6c4555..199df99c --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/handles/WireHandle.java @@@ -10,9 -10,8 +10,8 @@@ import net.haspamelodica.swt.helper.swt import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle; import net.mograsim.logic.model.editor.states.EditorState; import net.mograsim.logic.model.model.wires.GUIWire; - import net.mograsim.logic.model.model.wires.GUIWire.PathChangedListener; - public class WireHandle extends Handle implements PathChangedListener + public class WireHandle extends Handle { private boolean selected = false; private final static double WIDTH = 2.0; @@@ -22,15 -21,15 +21,15 @@@ public WireHandle(GUIWire parent) { this.parent = parent; - parent.addPathChangedListener(this); + parent.addPathChangedListener(c -> updateBounds()); updateBounds(); } - + @Override void destroy() { super.destroy(); - parent.removePathChangedListener(this); + parent.removePathChangedListener(c -> updateBounds()); } public void updateBounds() @@@ -39,18 -38,18 +38,18 @@@ moveTo(r.x, r.y); setSize(r.width, r.height); } - + @Override public void render(GeneralGC gc) { - if(selected) + if (selected) { gc.setLineWidth(WIDTH); gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_YELLOW)); gc.drawPolyline(parent.getEffectivePath()); } } - + @Override public void onSelect() { @@@ -64,43 -63,42 +63,43 @@@ selected = false; callRedrawListeners(); } - + @Override public void reqDelete() { parent.destroy(); } - + @Override public boolean contains(double x, double y) { return click(parent, x, y).isPresent(); } - + @Override public boolean click(double x, double y, int stateMask, EditorState state) { Optional op = click(parent, x, y); - if(op.isEmpty()) + if (op.isEmpty()) return false; WireClickData data = op.get(); return state.clickedHandle(new WireHandleClickInfo(this, data.segment, data.pos, stateMask)); } - + public static class WireHandleClickInfo extends HandleClickInfo { public final int segment; public final Point posOnWire; + WireHandleClickInfo(WireHandle clicked, int segment, Point posOnWire, int stateMask) { super(clicked, stateMask); this.segment = segment; this.posOnWire = posOnWire; } - + } - + private static Optional click(GUIWire w, double x, double y) { Rectangle modifiedBounds = w.getBounds(); @@@ -113,8 -111,8 +112,8 @@@ double[] effectivePath = w.getEffectivePath(); for (int i = 3; i < effectivePath.length; i += 2) { - double a1 = effectivePath[i - 3], a2 = effectivePath[i - 2], b1 = effectivePath[i - 1], - b2 = effectivePath[i], r1 = b2 - a2, r2 = a1 - b1; + double a1 = effectivePath[i - 3], a2 = effectivePath[i - 2], b1 = effectivePath[i - 1], b2 = effectivePath[i], r1 = b2 - a2, + r2 = a1 - b1; double f = ((x - a1) * r2 + (a2 - y) * r1) / (-r2 * r2 - r1 * r1); if (f >= 0 && f <= 1) @@@ -147,16 -145,10 +146,10 @@@ */ public final int segment; } - + @Override public HandleType getType() { return HandleType.WIRE; } - - @Override - public void pathChanged(GUIWire wire, int diff) - { - updateBounds(); - } }