diff --git a/src/main/java/de/neemann/digital/draw/elements/Circuit.java b/src/main/java/de/neemann/digital/draw/elements/Circuit.java index ac5dadd87..6d94e919f 100644 --- a/src/main/java/de/neemann/digital/draw/elements/Circuit.java +++ b/src/main/java/de/neemann/digital/draw/elements/Circuit.java @@ -515,8 +515,19 @@ public class Circuit implements Copyable { * @return the first element or null if there is no element at the given position */ public VisualElement getElementAt(Vector pos) { + return getElementAt(pos, false); + } + + /** + * Returns the element at the given position + * + * @param pos the cursor position + * @param includeText if true the label text is included in matching + * @return the first element or null if there is no element at the given position + */ + public VisualElement getElementAt(Vector pos, boolean includeText) { for (VisualElement element : visualElements) - if (element.matches(pos, false)) + if (element.matches(pos, includeText)) return element; return null; } 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 0862c52ce..aac6bb1f9 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -5,11 +5,10 @@ */ package de.neemann.digital.gui.components; -import de.neemann.digital.core.NodeException; -import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.core.*; import de.neemann.digital.core.Observer; -import de.neemann.digital.core.SyncAccess; import de.neemann.digital.core.element.*; +import de.neemann.digital.core.io.Const; import de.neemann.digital.core.io.In; import de.neemann.digital.core.io.InValue; import de.neemann.digital.core.io.Out; @@ -346,6 +345,18 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib } }.setAcceleratorCTRLplus('D').enableAcceleratorIn(this); + new ToolTipAction("insertTunnel") { + @Override + public void actionPerformed(ActionEvent actionEvent) { + if (activeMouseController == mouseNormal) { + VisualElement tunnel = + new VisualElement(Tunnel.DESCRIPTION.getName()) + .setShapeFactory(shapeFactory); + setPartToInsert(tunnel); + } + } + }.setAccelerator("T").enableAcceleratorIn(this); + ToolTipAction plus = new PlusMinusAction(1).setAccelerator("PLUS").enableAcceleratorIn(this); getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), plus); @@ -1288,8 +1299,12 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib mouseNormal.activate(); VisualElement ve = null; - if (activeMouseController instanceof MouseControllerNormal) - ve = getCircuit().getElementAt(getPosVector(lastMousePos.x, lastMousePos.y)); + if (activeMouseController instanceof MouseControllerNormal) { + Vector pos = getPosVector(lastMousePos.x, lastMousePos.y); + ve = getCircuit().getElementAt(pos); + if (ve == null) + ve = getCircuit().getElementAt(pos, true); + } return ve; } @@ -1403,6 +1418,10 @@ public class CircuitComponent extends JComponent implements ChangedListener, Lib int number = ve.getElementAttributes().get(Keys.INPUT_COUNT) + delta; if (number >= Keys.INPUT_COUNT.getMin() && number <= Keys.INPUT_COUNT.getMax()) modify(new ModifyAttribute<>(ve, Keys.INPUT_COUNT, number)); + } else if (ve.equalsDescription(Const.DESCRIPTION)) { + long v = ve.getElementAttributes().get(Keys.VALUE) + delta; + v &= Bits.mask(ve.getElementAttributes().getBits()); + modify(new ModifyAttribute<>(ve, Keys.VALUE, v)); } } catch (ElementNotFoundException e1) { // do nothing on error diff --git a/src/test/resources/docu/static_de.xml b/src/test/resources/docu/static_de.xml index 08fdd7e4d..47cc848c9 100644 --- a/src/test/resources/docu/static_de.xml +++ b/src/test/resources/docu/static_de.xml @@ -657,6 +657,7 @@ Aktuelle Auswahl duplizieren ohne die Zwischenablage zu verändern. Rotieren der Elemente beim Einfügen Zuletzt eingefügtes Element noch einmal einfügen + Einfügen eines Tunnels Neue Schaltung Schaltung öffnen Speichern der Schaltung @@ -669,8 +670,12 @@ Abbrechen der aktuellen Aktion Löschen der selektierten Elemente Löschen der selektierten Elemente - Erhöht die Anzahl der Eingänge in dem Element, auf welches die Maus zeigt. - Erniedrigt die Anzahl der Eingänge in dem Element, auf welches die Maus zeigt. + Erhöht die Anzahl der Eingänge in dem Element, auf welches die Maus zeigt. Bei Konstanten + wird der Wert erhöht. + + Erniedrigt die Anzahl der Eingänge in dem Element, auf welches die Maus zeigt. Bei + Konstanten wird der Wert verringert. + Vergrößern Verkleinern Einpassen diff --git a/src/test/resources/docu/static_en.xml b/src/test/resources/docu/static_en.xml index a9023d0ce..85d94ea20 100644 --- a/src/test/resources/docu/static_en.xml +++ b/src/test/resources/docu/static_en.xml @@ -595,6 +595,7 @@ Duplicate the current selection without modifying the clipboard. While inserting this rotates the components. Inserts the last inserted component again. + Inserts a new tunnel. New circuit. Open circuit. Save the circuit. @@ -607,8 +608,12 @@ Abort the current action. Removes the selected components. Removes the selected components. - Increases the number of inputs at the component the mouse points to. - Decreases the number of inputs at the component the mouse points to. + Increases the number of inputs at the component the mouse points to. If it is used with + constants, the value is increased. + + Decreases the number of inputs at the component the mouse points to. If it is used with + constants, the value is decreased. + Zoom In Zoom Out Fit to size