From cf323d03ad43cd445b929ec0dfa757fa33020812 Mon Sep 17 00:00:00 2001 From: hneemann Date: Thu, 7 Jan 2021 18:51:41 +0100 Subject: [PATCH] in generic circuits the origin is flagged with a circle --- .../gui/components/CircuitComponent.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java index c363fd9b1..a9c5bfe29 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -570,9 +570,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib removeHighLighted(); } - Circuit circuit = shallowCopy; - if (circuit == null) - circuit = getCircuit(); + Circuit circuit = getCircuitOrShallowCopy(); Vector pos = getPosVector(event); VisualElement ve = circuit.getElementAt(pos); @@ -874,10 +872,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib gr2.transform(transform); long time = System.currentTimeMillis(); - if (shallowCopy != null) - shallowCopy.drawTo(gr, highLighted, highLightStyle, modelSync); - else - getCircuit().drawTo(gr, highLighted, highLightStyle, modelSync); + getCircuitOrShallowCopy().drawTo(gr, highLighted, highLightStyle, modelSync); time = System.currentTimeMillis() - time; if (time > 500) antiAlias = false; @@ -929,6 +924,15 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib gr2.fill(new Rectangle2D.Double(xx, yy, delta, delta)); } } + + if (getCircuit().getAttributes().get(Keys.IS_GENERIC)) { + double dx = (p2.getX() - p1.getX()) / cx / 2; + double dy = (p2.getY() - p1.getY()) / cy / 2; + + Point2D.Double origin = new Point2D.Double(); + transform.transform(new Point(0, 0), origin); + gr2.drawOval((int) (origin.getX() - dy), (int) (origin.getY() - dy), (int) (dx * 2), (int) (dy * 2)); + } } /** @@ -981,6 +985,13 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib return undoManager.getActual(); } + private Circuit getCircuitOrShallowCopy() { + if (shallowCopy != null) + return shallowCopy; + else + return undoManager.getActual(); + } + /** * Sets a circuit to this component * @@ -1004,7 +1015,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib */ public void fitCircuit() { GraphicMinMax gr = new GraphicMinMax(); - getCircuit().drawTo(gr); + getCircuitOrShallowCopy().drawTo(gr); AffineTransform newTrans = new AffineTransform(); if (gr.getMin() != null && getWidth() != 0 && getHeight() != 0) { @@ -1303,9 +1314,8 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib public void currentToDefault() { if (!isLocked()) { Modifications.Builder builder = new Modifications.Builder<>(Lang.get("menu_actualToDefault")); - Circuit circuit = shallowCopy; - if (circuit == null) - circuit = getCircuit(); + + Circuit circuit = getCircuitOrShallowCopy(); for (VisualElement ve : circuit.getElements()) if (ve.equalsDescription(In.DESCRIPTION)) { ObservableValue ov = ((InputShape) ve.getShape()).getObservableValue(); @@ -2501,11 +2511,7 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib } private VisualElement getInteractiveElementAt(MouseEvent e) { - Circuit circuit; - if (shallowCopy != null) - circuit = shallowCopy; - else - circuit = getCircuit(); + Circuit circuit = getCircuitOrShallowCopy(); List elementList = circuit.getElementListAt(getPosVector(e), false); for (VisualElement ve : elementList) { if (ve.isInteractive())