RENAME: Junction -> Node
This commit is contained in:
parent
d881c8ff04
commit
228d78c739
@ -13,9 +13,9 @@ public class CONFIG {
|
||||
|
||||
public static boolean SHOW_WIRE_DETAILS = true;
|
||||
|
||||
public static boolean SHOW_JUNCTION_VOLTAGES = false;
|
||||
public static boolean SHOW_NODE_VOLTAGES = false;
|
||||
|
||||
public static boolean SHOW_JUNCTION_NAMES = false;
|
||||
public static boolean SHOW_NODE_NAMES = false;
|
||||
|
||||
public static final double VOLTAGE_HIGH_MIN = 0.1;
|
||||
|
||||
@ -43,15 +43,15 @@ public class CONFIG {
|
||||
|
||||
public static final int P95 = (int) round(0.95 * RASTER);
|
||||
|
||||
public static final int JUNCTION_RADIUS = (int) round(0.09 * RASTER);
|
||||
public static final int NODE_RADIUS = (int) round(0.09 * RASTER);
|
||||
|
||||
public static final int JUNCTION_RADIUS_HOVER = (int) round(1.5 * JUNCTION_RADIUS);
|
||||
public static final int NODE_RADIUS_HOVER = (int) round(1.5 * NODE_RADIUS);
|
||||
|
||||
public static final Color PART_BACK_COLOR = new Color(224, 224, 224);
|
||||
|
||||
public static final Color PART_HOVER_COLOR = new Color(192, 192, 192, 128);
|
||||
|
||||
public static final Color JUNCTION_HOVER_BORDER_COLOR = Color.BLACK;
|
||||
public static final Color NODE_HOVER_BORDER_COLOR = Color.BLACK;
|
||||
|
||||
public static final Color RASTER_COLOR = Color.gray;
|
||||
|
||||
@ -67,7 +67,7 @@ public class CONFIG {
|
||||
|
||||
public static final BasicStroke RASTER_STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, new float[]{5}, 0);
|
||||
|
||||
public static final BasicStroke JUNCTION_STROKE = new BasicStroke(1);
|
||||
public static final BasicStroke NODE_STROKE = new BasicStroke(1);
|
||||
|
||||
public static final BasicStroke HOVER_STROKE = new BasicStroke(2);
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package de.ph87.electro.circuit;
|
||||
import de.ph87.electro.circuit.calculation.Calculation;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
import de.ph87.electro.circuit.wire.WireDto;
|
||||
import lombok.Getter;
|
||||
@ -48,13 +48,13 @@ public class Circuit {
|
||||
parts.add(part);
|
||||
}
|
||||
for (final WireDto wire : dto.getWires()) {
|
||||
final Junction a = findJunctionByUuid(wire.getA()).orElseThrow();
|
||||
final Junction b = findJunctionByUuid(wire.getB()).orElseThrow();
|
||||
final Node a = findNodeByUuid(wire.getA()).orElseThrow();
|
||||
final Node b = findNodeByUuid(wire.getB()).orElseThrow();
|
||||
wires.add(new Wire(a, b));
|
||||
}
|
||||
}
|
||||
|
||||
public Wire connect(final Junction a, final Junction b) {
|
||||
public Wire connect(final Node a, final Node b) {
|
||||
final Wire wire = new Wire(a, b);
|
||||
wires.add(wire);
|
||||
return wire;
|
||||
@ -80,7 +80,7 @@ public class Circuit {
|
||||
|
||||
public void removePart(final Part part) {
|
||||
if (parts.remove(part)) {
|
||||
part.getJunctions().stream().flatMap(junction -> junction.getWires().stream()).toList().forEach(this::disconnect); // jep, first toList(), then forEach (due to concurrent modification)
|
||||
part.getNodes().stream().flatMap(node -> node.getWires().stream()).toList().forEach(this::disconnect); // jep, first toList(), then forEach (due to concurrent modification)
|
||||
} else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
@ -114,8 +114,8 @@ public class Circuit {
|
||||
return streamParts().filter(p -> p.getPosition().equals(aligned)).findFirst();
|
||||
}
|
||||
|
||||
public Optional<Junction> findJunctionByUuid(@NonNull final String junctionUuid) {
|
||||
return parts.stream().map(part -> part.findJunctionByUuid(junctionUuid)).filter(Optional::isPresent).map(Optional::get).findFirst();
|
||||
public Optional<Node> findNodeByUuid(@NonNull final String nodeUuid) {
|
||||
return parts.stream().map(part -> part.findNodeByUuid(nodeUuid)).filter(Optional::isPresent).map(Optional::get).findFirst();
|
||||
}
|
||||
|
||||
public Optional<Wire> findWireByPosition(final Point position) {
|
||||
|
||||
@ -2,7 +2,7 @@ package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.part.Orientation;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
@ -59,7 +59,7 @@ public class CircuitPainter {
|
||||
}
|
||||
|
||||
private static void drawVoltages(final Circuit circuit, final Graphics2D g) {
|
||||
if (!SHOW_JUNCTION_VOLTAGES && !SHOW_JUNCTION_NAMES) {
|
||||
if (!SHOW_NODE_VOLTAGES && !SHOW_NODE_NAMES) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -68,23 +68,23 @@ public class CircuitPainter {
|
||||
final int third = g.getFont().getSize() / 3;
|
||||
|
||||
for (Part part : circuit.getParts()) {
|
||||
for (final Junction junction : part.getJunctions()) {
|
||||
final Point absolute = junction.getAbsolute();
|
||||
if (SHOW_JUNCTION_NAMES) {
|
||||
for (final Node node : part.getNodes()) {
|
||||
final Point absolute = node.getAbsolute();
|
||||
if (SHOW_NODE_NAMES) {
|
||||
int offsetY = third;
|
||||
if (SHOW_JUNCTION_VOLTAGES) {
|
||||
if (SHOW_NODE_VOLTAGES) {
|
||||
offsetY -= third;
|
||||
}
|
||||
final String string = junction.getName();
|
||||
final String string = node.getName();
|
||||
final Rectangle2D bounds = g.getFontMetrics().getStringBounds(string, g);
|
||||
g.drawString(string, absolute.x - (int) (bounds.getWidth() / 2), absolute.y + offsetY);
|
||||
}
|
||||
if (SHOW_JUNCTION_VOLTAGES) {
|
||||
if (SHOW_NODE_VOLTAGES) {
|
||||
int offsetY = third;
|
||||
if (SHOW_JUNCTION_NAMES) {
|
||||
if (SHOW_NODE_NAMES) {
|
||||
offsetY += 2 * third;
|
||||
}
|
||||
final String string = "%.1fV".formatted(junction.getVoltage());
|
||||
final String string = "%.1fV".formatted(node.getVoltage());
|
||||
final Rectangle2D bounds = g.getFontMetrics().getStringBounds(string, g);
|
||||
g.drawString(string, absolute.x - (int) (bounds.getWidth() / 2), absolute.y + offsetY);
|
||||
}
|
||||
@ -92,11 +92,11 @@ public class CircuitPainter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawLine(final Graphics2D g, final Junction a, final Junction b, final Color color, final Stroke stroke) {
|
||||
public static void drawLine(final Graphics2D g, final Node a, final Node b, final Color color, final Stroke stroke) {
|
||||
drawLine(g, a.getInside(), b.getInside(), color, stroke);
|
||||
}
|
||||
|
||||
public static void drawLine(final Graphics2D g, final Junction a, final Point b, final Color color, final Stroke stroke) {
|
||||
public static void drawLine(final Graphics2D g, final Node a, final Point b, final Color color, final Stroke stroke) {
|
||||
drawLine(g, a.getInside(), b, color, stroke);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -19,7 +19,7 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
|
||||
private Part part = null;
|
||||
|
||||
private Junction junction = null;
|
||||
private Node node = null;
|
||||
|
||||
private Wire wire = null;
|
||||
|
||||
@ -96,15 +96,15 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
if (junction != null) {
|
||||
final Junction source = junction;
|
||||
if (node != null) {
|
||||
final Node source = node;
|
||||
hoverUpdate(event);
|
||||
if (junction != null) {
|
||||
final Wire wire = circuitPanel.getCircuit().connect(source, junction);
|
||||
if (node != null) {
|
||||
final Wire wire = circuitPanel.getCircuit().connect(source, node);
|
||||
log.info("Wire CREATED: {}", wire);
|
||||
circuitPanel.getCircuit().evaluate();
|
||||
} else {
|
||||
log.info("No Wire created: No destination junction found!");
|
||||
log.info("No Wire created: No destination node found!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,8 +115,8 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
private void hoverUpdate(final MouseEvent event) {
|
||||
final Point position = event.getPoint();
|
||||
part = circuitPanel.getCircuit().findPartByPosition(position).orElse(null);
|
||||
junction = part != null ? part.findJunctionByPosition(position).orElse(null) : null;
|
||||
if (junction != null) {
|
||||
node = part != null ? part.findNodeByPosition(position).orElse(null) : null;
|
||||
if (node != null) {
|
||||
part = null;
|
||||
wire = null;
|
||||
return;
|
||||
@ -129,19 +129,19 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
|
||||
public void drawHover(final Graphics2D g) {
|
||||
if (part != null) {
|
||||
g.setColor(JUNCTION_HOVER_BORDER_COLOR);
|
||||
g.setColor(NODE_HOVER_BORDER_COLOR);
|
||||
g.setStroke(HOVER_STROKE);
|
||||
g.drawRect(part.getPosition().x, part.getPosition().y, RASTER, RASTER);
|
||||
}
|
||||
if (junction != null) {
|
||||
final Point absolute = junction.getAbsolute();
|
||||
if (node != null) {
|
||||
final Point absolute = node.getAbsolute();
|
||||
|
||||
g.setColor(junction.getColor());
|
||||
g.fillArc(absolute.x - JUNCTION_RADIUS_HOVER, absolute.y - JUNCTION_RADIUS_HOVER, 2 * JUNCTION_RADIUS_HOVER, 2 * JUNCTION_RADIUS_HOVER, 0, 360);
|
||||
g.setColor(node.getColor());
|
||||
g.fillArc(absolute.x - NODE_RADIUS_HOVER, absolute.y - NODE_RADIUS_HOVER, 2 * NODE_RADIUS_HOVER, 2 * NODE_RADIUS_HOVER, 0, 360);
|
||||
|
||||
g.setColor(JUNCTION_HOVER_BORDER_COLOR);
|
||||
g.setColor(NODE_HOVER_BORDER_COLOR);
|
||||
g.setStroke(HOVER_STROKE);
|
||||
g.drawArc(absolute.x - JUNCTION_RADIUS_HOVER, absolute.y - JUNCTION_RADIUS_HOVER, 2 * JUNCTION_RADIUS_HOVER, 2 * JUNCTION_RADIUS_HOVER, 0, 360);
|
||||
g.drawArc(absolute.x - NODE_RADIUS_HOVER, absolute.y - NODE_RADIUS_HOVER, 2 * NODE_RADIUS_HOVER, 2 * NODE_RADIUS_HOVER, 0, 360);
|
||||
}
|
||||
if (wire != null) {
|
||||
final Point aa = wire.getA().getAbsolute();
|
||||
@ -163,10 +163,10 @@ class CircuitPanelMouseAdapter extends MouseAdapter {
|
||||
g.setColor(PART_HOVER_COLOR);
|
||||
g.fillRect(dragging.x - P50, dragging.y - P50, RASTER, RASTER);
|
||||
}
|
||||
if (junction != null) {
|
||||
g.setColor(junction.getColor());
|
||||
if (node != null) {
|
||||
g.setColor(node.getColor());
|
||||
g.setStroke(WIRE_STROKE);
|
||||
final Point absolute = junction.getAbsolute();
|
||||
final Point absolute = node.getAbsolute();
|
||||
g.drawLine(absolute.x, absolute.y, dragging.x, dragging.y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import de.ph87.electro.CONFIG;
|
||||
import de.ph87.electro.circuit.Circuit;
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import de.ph87.electro.circuit.part.parts.Battery;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
import lombok.Getter;
|
||||
@ -23,7 +23,7 @@ import static java.lang.Math.max;
|
||||
@Getter
|
||||
public class Calculation {
|
||||
|
||||
private final List<Junction> junctions = new ArrayList<>();
|
||||
private final List<Node> nodes = new ArrayList<>();
|
||||
|
||||
private final Set<Part> parts = new HashSet<>();
|
||||
|
||||
@ -40,11 +40,11 @@ public class Calculation {
|
||||
final List<Battery> batteries = new ArrayList<>(circuit.streamParts().flatMap(Battery::filterCast).toList());
|
||||
while (!batteries.isEmpty()) {
|
||||
final Battery pivot = batteries.removeFirst();
|
||||
final Set<Junction> connectedJunctions = new HashSet<>();
|
||||
pivot.getPlus().collectConnectedJunctions(connectedJunctions);
|
||||
pivot.getMinus().collectConnectedJunctions(connectedJunctions);
|
||||
connectedJunctions.stream().map(Junction::getOwner).flatMap(Battery::filterCast).forEach(batteries::remove);
|
||||
calculations.add(new Calculation(connectedJunctions, pivot));
|
||||
final Set<Node> connectedNodes = new HashSet<>();
|
||||
pivot.getPlus().collectConnectedNodes(connectedNodes);
|
||||
pivot.getMinus().collectConnectedNodes(connectedNodes);
|
||||
connectedNodes.stream().map(Node::getOwner).flatMap(Battery::filterCast).forEach(batteries::remove);
|
||||
calculations.add(new Calculation(connectedNodes, pivot));
|
||||
}
|
||||
return calculations;
|
||||
}
|
||||
@ -54,18 +54,18 @@ public class Calculation {
|
||||
currents = new ArrayRealVector(numNodes);
|
||||
}
|
||||
|
||||
private Calculation(final Set<Junction> connectedJunctions, final Battery pivot) {
|
||||
for (final Junction junction : connectedJunctions) {
|
||||
parts.add(junction.getOwner());
|
||||
if (!junctions.contains(junction) && junction != pivot.getMinus()) {
|
||||
private Calculation(final Set<Node> connectedNodes, final Battery pivot) {
|
||||
for (final Node node : connectedNodes) {
|
||||
parts.add(node.getOwner());
|
||||
if (!nodes.contains(node) && node != pivot.getMinus()) {
|
||||
// pivot.minus is GND and cannot be part of the matrix (linear dependency)
|
||||
this.junctions.add(junction);
|
||||
this.nodes.add(node);
|
||||
}
|
||||
wires.addAll(junction.getWires());
|
||||
wires.addAll(node.getWires());
|
||||
}
|
||||
|
||||
matrix = new Array2DRowRealMatrix(this.junctions.size(), this.junctions.size());
|
||||
currents = new ArrayRealVector(this.junctions.size());
|
||||
matrix = new Array2DRowRealMatrix(this.nodes.size(), this.nodes.size());
|
||||
currents = new ArrayRealVector(this.nodes.size());
|
||||
fromSchematic();
|
||||
solve();
|
||||
toSchematic();
|
||||
@ -81,8 +81,8 @@ public class Calculation {
|
||||
}
|
||||
if (part instanceof final Battery battery) {
|
||||
final double current = battery.getVoltage() / battery.getResistance();
|
||||
final int indexMinus = getJunctionIndex(battery.getMinus());
|
||||
final int indexPlus = getJunctionIndex(battery.getPlus());
|
||||
final int indexMinus = getNodeIndex(battery.getMinus());
|
||||
final int indexPlus = getNodeIndex(battery.getPlus());
|
||||
addCurrentSource(indexMinus, indexPlus, current);
|
||||
}
|
||||
});
|
||||
@ -91,13 +91,13 @@ public class Calculation {
|
||||
private void toSchematic() {
|
||||
wires.forEach(wire -> wire.setCurrent(getCurrent(wire)));
|
||||
parts.forEach(part -> {
|
||||
part.getJunctions().forEach(junction -> junction.setVoltage(getPotential(junction)));
|
||||
part.getNodes().forEach(node -> node.setVoltage(getPotential(node)));
|
||||
part.postCalculate();
|
||||
});
|
||||
}
|
||||
|
||||
private double getPotential(final @NonNull Junction junction) {
|
||||
final int index = getJunctionIndex(junction);
|
||||
private double getPotential(final @NonNull Node node) {
|
||||
final int index = getNodeIndex(node);
|
||||
if (index < 0) {
|
||||
return 0; // per definition
|
||||
}
|
||||
@ -108,25 +108,25 @@ public class Calculation {
|
||||
}
|
||||
|
||||
private double getCurrent(final Wire wire) {
|
||||
final int indexA = getJunctionIndex(wire.getA());
|
||||
final int indexB = getJunctionIndex(wire.getB());
|
||||
final int indexA = getNodeIndex(wire.getA());
|
||||
final int indexB = getNodeIndex(wire.getB());
|
||||
final double conductance = indexA >= 0 && indexB >= 0 ? matrix.getEntry(indexA, indexB) : 1 / CONFIG.NO_RESISTANCE;
|
||||
final double potentialDifference = getPotential(wire.getB()) - getPotential(wire.getA());
|
||||
return conductance * potentialDifference;
|
||||
}
|
||||
|
||||
private int getJunctionIndex(@NonNull final Junction junction) {
|
||||
for (int i = 0; i < junctions.size(); i++) {
|
||||
if (junctions.get(i) == junction) {
|
||||
private int getNodeIndex(@NonNull final Node node) {
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
if (nodes.get(i) == node) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void addResistor(final Junction a, final Junction b, final double resistance) {
|
||||
final int indexA = getJunctionIndex(a);
|
||||
final int indexB = getJunctionIndex(b);
|
||||
public void addResistor(final Node a, final Node b, final double resistance) {
|
||||
final int indexA = getNodeIndex(a);
|
||||
final int indexB = getNodeIndex(b);
|
||||
addResistor(indexA, indexB, resistance);
|
||||
}
|
||||
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
package de.ph87.electro.circuit.part;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class InnerConnection {
|
||||
|
||||
public final Junction a;
|
||||
public final Node a;
|
||||
|
||||
public final Junction b;
|
||||
public final Node b;
|
||||
|
||||
public final double resistance;
|
||||
|
||||
public InnerConnection(final Junction a, final Junction b, final double resistance) {
|
||||
public InnerConnection(final Node a, final Node b, final double resistance) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.resistance = resistance;
|
||||
}
|
||||
|
||||
public Stream<Junction> filter(final Junction junction) {
|
||||
if (a == junction) {
|
||||
public Stream<Node> filter(final Node node) {
|
||||
if (a == node) {
|
||||
return Stream.of(b);
|
||||
} else if (b == junction) {
|
||||
} else if (b == node) {
|
||||
return Stream.of(a);
|
||||
}
|
||||
return Stream.empty();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import de.ph87.electro.circuit.part.parts.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
@ -32,7 +32,7 @@ public abstract class Part {
|
||||
|
||||
protected Orientation orientation = Orientation.R0;
|
||||
|
||||
private final List<Junction> junctions = new ArrayList<>();
|
||||
private final List<Node> nodes = new ArrayList<>();
|
||||
|
||||
@NonNull
|
||||
private AffineTransform transform;
|
||||
@ -64,17 +64,17 @@ public abstract class Part {
|
||||
return new Point((int) round(result.getX()), (int) round(result.getY()));
|
||||
}
|
||||
|
||||
protected Junction addJunction(final String name, final int x, final int y) {
|
||||
return addJunction(new Junction(this, name, new Point(x, y)));
|
||||
protected Node addNode(final String name, final int x, final int y) {
|
||||
return addNode(new Node(this, name, new Point(x, y)));
|
||||
}
|
||||
|
||||
protected Junction addJunction(final JunctionDto dto, final int x, final int y) {
|
||||
return addJunction(new Junction(this, dto, new Point(x, y)));
|
||||
protected Node addNode(final NodeDto dto, final int x, final int y) {
|
||||
return addNode(new Node(this, dto, new Point(x, y)));
|
||||
}
|
||||
|
||||
private Junction addJunction(final Junction junction) {
|
||||
junctions.add(junction);
|
||||
return junction;
|
||||
private Node addNode(final Node node) {
|
||||
nodes.add(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
public void setPosition(final Point position) {
|
||||
@ -91,7 +91,7 @@ public abstract class Part {
|
||||
g.setColor(PART_BACK_COLOR);
|
||||
g.fillRect(0, 0, RASTER, RASTER);
|
||||
_render(g);
|
||||
junctions.forEach(junction -> junction.draw(g));
|
||||
nodes.forEach(node -> node.draw(g));
|
||||
_labels(g);
|
||||
}
|
||||
|
||||
@ -115,12 +115,12 @@ public abstract class Part {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Optional<Junction> findJunctionByUuid(final String junctionUuid) {
|
||||
return junctions.stream().filter(junction -> junction.getUuid().equals(junctionUuid)).findFirst();
|
||||
public Optional<Node> findNodeByUuid(final String nodeUuid) {
|
||||
return nodes.stream().filter(node -> node.getUuid().equals(nodeUuid)).findFirst();
|
||||
}
|
||||
|
||||
public Optional<Junction> findJunctionByPosition(final Point position) {
|
||||
return junctions.stream().filter(junction -> junction.intersects(position)).findFirst();
|
||||
public Optional<Node> findNodeByPosition(final Point position) {
|
||||
return nodes.stream().filter(node -> node.intersects(position)).findFirst();
|
||||
}
|
||||
|
||||
public static Part fromDto(final PartDto abstractDto) {
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
package de.ph87.electro.circuit.part.junction;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class JunctionDto {
|
||||
|
||||
private String uuid;
|
||||
|
||||
private String name;
|
||||
|
||||
public JunctionDto(final Junction junction) {
|
||||
this.uuid = junction.getUuid();
|
||||
this.name = junction.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package de.ph87.electro.circuit.part.junction;
|
||||
package de.ph87.electro.circuit.part.node;
|
||||
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
@ -15,7 +15,7 @@ import static de.ph87.electro.CONFIG.*;
|
||||
|
||||
@Getter
|
||||
@ToString(onlyExplicitlyIncluded = true)
|
||||
public class Junction {
|
||||
public class Node {
|
||||
|
||||
@ToString.Include
|
||||
private final String uuid;
|
||||
@ -37,17 +37,17 @@ public class Junction {
|
||||
@ToString.Include
|
||||
@SuppressWarnings("unused") // lombok toString
|
||||
public List<String> destinations() {
|
||||
return wires.stream().map(wire -> wire.getOpposite(this)).map(Junction::getUuid).toList();
|
||||
return wires.stream().map(wire -> wire.getOpposite(this)).map(Node::getUuid).toList();
|
||||
}
|
||||
|
||||
public Junction(final Part owner, final String name, final Point inside) {
|
||||
public Node(final Part owner, final String name, final Point inside) {
|
||||
this.owner = owner;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
this.inside = inside;
|
||||
}
|
||||
|
||||
public Junction(final Part owner, final JunctionDto dto, final Point inside) {
|
||||
public Node(final Part owner, final NodeDto dto, final Point inside) {
|
||||
this.owner = owner;
|
||||
this.uuid = dto.getUuid();
|
||||
this.name = dto.getName();
|
||||
@ -61,24 +61,24 @@ public class Junction {
|
||||
|
||||
public void draw(final Graphics2D g) {
|
||||
g.setColor(color);
|
||||
g.fillArc(inside.x - JUNCTION_RADIUS, inside.y - JUNCTION_RADIUS, 2 * JUNCTION_RADIUS, 2 * JUNCTION_RADIUS, 0, 360);
|
||||
g.fillArc(inside.x - NODE_RADIUS, inside.y - NODE_RADIUS, 2 * NODE_RADIUS, 2 * NODE_RADIUS, 0, 360);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setStroke(JUNCTION_STROKE);
|
||||
g.drawArc(inside.x - JUNCTION_RADIUS, inside.y - JUNCTION_RADIUS, 2 * JUNCTION_RADIUS, 2 * JUNCTION_RADIUS, 0, 360);
|
||||
g.setStroke(NODE_STROKE);
|
||||
g.drawArc(inside.x - NODE_RADIUS, inside.y - NODE_RADIUS, 2 * NODE_RADIUS, 2 * NODE_RADIUS, 0, 360);
|
||||
}
|
||||
|
||||
public boolean intersects(final Point position) {
|
||||
return getAbsolute().distance(position) <= JUNCTION_RADIUS_HOVER;
|
||||
return getAbsolute().distance(position) <= NODE_RADIUS_HOVER;
|
||||
}
|
||||
|
||||
public void collectConnectedJunctions(final Set<Junction> connected) {
|
||||
public void collectConnectedNodes(final Set<Node> connected) {
|
||||
if (connected.contains(this)) {
|
||||
return;
|
||||
}
|
||||
connected.add(this);
|
||||
wires.forEach(wire -> wire.getOpposite(this).collectConnectedJunctions(connected));
|
||||
owner.getInnerConnections().stream().flatMap(innerConnection -> innerConnection.filter(this)).forEach(opposite -> opposite.collectConnectedJunctions(connected));
|
||||
wires.forEach(wire -> wire.getOpposite(this).collectConnectedNodes(connected));
|
||||
owner.getInnerConnections().stream().flatMap(innerConnection -> innerConnection.filter(this)).forEach(opposite -> opposite.collectConnectedNodes(connected));
|
||||
}
|
||||
|
||||
public Point getAbsolute() {
|
||||
21
src/main/java/de/ph87/electro/circuit/part/node/NodeDto.java
Normal file
21
src/main/java/de/ph87/electro/circuit/part/node/NodeDto.java
Normal file
@ -0,0 +1,21 @@
|
||||
package de.ph87.electro.circuit.part.node;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class NodeDto {
|
||||
|
||||
private String uuid;
|
||||
|
||||
private String name;
|
||||
|
||||
public NodeDto(final Node node) {
|
||||
this.uuid = node.getUuid();
|
||||
this.name = node.getName();
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,7 +2,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -29,9 +29,9 @@ public class Battery extends Part {
|
||||
|
||||
private static final int PLUS_H = (int) round(0.6 * RASTER);
|
||||
|
||||
private final Junction minus;
|
||||
private final Node minus;
|
||||
|
||||
private final Junction plus;
|
||||
private final Node plus;
|
||||
|
||||
@Setter
|
||||
@ToString.Include
|
||||
@ -43,14 +43,14 @@ public class Battery extends Part {
|
||||
|
||||
public Battery(final Point position) {
|
||||
super("Batterie", position);
|
||||
minus = addJunction("MINUS", P10, P50);
|
||||
plus = addJunction("PLUS", P90, P50);
|
||||
minus = addNode("MINUS", P10, P50);
|
||||
plus = addNode("PLUS", P90, P50);
|
||||
}
|
||||
|
||||
public Battery(final BatteryDto dto) {
|
||||
super(dto);
|
||||
minus = addJunction(dto.getMinus(), P10, P50);
|
||||
plus = addJunction(dto.getPlus(), P90, P50);
|
||||
minus = addNode(dto.getMinus(), P10, P50);
|
||||
plus = addNode(dto.getPlus(), P90, P50);
|
||||
voltage = dto.getVoltage();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,16 +11,16 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class BatteryDto extends PartDto {
|
||||
|
||||
private JunctionDto minus;
|
||||
private NodeDto minus;
|
||||
|
||||
private JunctionDto plus;
|
||||
private NodeDto plus;
|
||||
|
||||
private double voltage;
|
||||
|
||||
public BatteryDto(final Battery battery) {
|
||||
super(battery);
|
||||
this.minus = new JunctionDto(battery.getMinus());
|
||||
this.plus = new JunctionDto(battery.getPlus());
|
||||
this.minus = new NodeDto(battery.getMinus());
|
||||
this.plus = new NodeDto(battery.getPlus());
|
||||
this.voltage = battery.getVoltage();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -14,20 +14,20 @@ import static de.ph87.electro.CONFIG.P90;
|
||||
@ToString(callSuper = true)
|
||||
public class ConnectorCorner extends Part {
|
||||
|
||||
private final Junction j0;
|
||||
private final Node j0;
|
||||
|
||||
private final Junction j1;
|
||||
private final Node j1;
|
||||
|
||||
public ConnectorCorner(final Point position) {
|
||||
super("", position);
|
||||
j0 = addJunction("J0", P10, P10);
|
||||
j1 = addJunction("J1", P90, P90);
|
||||
j0 = addNode("J0", P10, P10);
|
||||
j1 = addNode("J1", P90, P90);
|
||||
}
|
||||
|
||||
public ConnectorCorner(final ConnectorCornerDto dto) {
|
||||
super(dto);
|
||||
j0 = addJunction(dto.getJ0(), P10, P10);
|
||||
j1 = addJunction(dto.getJ1(), P90, P90);
|
||||
j0 = addNode(dto.getJ0(), P10, P10);
|
||||
j1 = addNode(dto.getJ1(), P90, P90);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,13 +11,13 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class ConnectorCornerDto extends PartDto {
|
||||
|
||||
private JunctionDto j0;
|
||||
private NodeDto j0;
|
||||
|
||||
private JunctionDto j1;
|
||||
private NodeDto j1;
|
||||
|
||||
public ConnectorCornerDto(final ConnectorCorner part) {
|
||||
j0 = new JunctionDto(part.getJ0());
|
||||
j1 = new JunctionDto(part.getJ1());
|
||||
j0 = new NodeDto(part.getJ0());
|
||||
j1 = new NodeDto(part.getJ1());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -14,20 +14,20 @@ import static de.ph87.electro.CONFIG.P50;
|
||||
@ToString(callSuper = true)
|
||||
public class ConnectorEdge extends Part {
|
||||
|
||||
private final Junction j0;
|
||||
private final Node j0;
|
||||
|
||||
private final Junction j1;
|
||||
private final Node j1;
|
||||
|
||||
public ConnectorEdge(final Point position) {
|
||||
super("", position);
|
||||
j0 = addJunction("J0", P10, P50);
|
||||
j1 = addJunction("J1", P50, P10);
|
||||
j0 = addNode("J0", P10, P50);
|
||||
j1 = addNode("J1", P50, P10);
|
||||
}
|
||||
|
||||
public ConnectorEdge(final ConnectorEdgeDto dto) {
|
||||
super(dto);
|
||||
j0 = addJunction(dto.getJ0(), P10, P50);
|
||||
j1 = addJunction(dto.getJ1(), P50, P10);
|
||||
j0 = addNode(dto.getJ0(), P10, P50);
|
||||
j1 = addNode(dto.getJ1(), P50, P10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,13 +11,13 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class ConnectorEdgeDto extends PartDto {
|
||||
|
||||
private JunctionDto j0;
|
||||
private NodeDto j0;
|
||||
|
||||
private JunctionDto j1;
|
||||
private NodeDto j1;
|
||||
|
||||
public ConnectorEdgeDto(final ConnectorEdge part) {
|
||||
j0 = new JunctionDto(part.getJ0());
|
||||
j1 = new JunctionDto(part.getJ1());
|
||||
j0 = new NodeDto(part.getJ0());
|
||||
j1 = new NodeDto(part.getJ1());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -13,16 +13,16 @@ import static de.ph87.electro.CONFIG.P50;
|
||||
@ToString(callSuper = true)
|
||||
public class ConnectorMiddle extends Part {
|
||||
|
||||
private final Junction junction;
|
||||
private final Node node;
|
||||
|
||||
public ConnectorMiddle(final Point position) {
|
||||
super("", position);
|
||||
junction = addJunction("J", P50, P50);
|
||||
node = addNode("J", P50, P50);
|
||||
}
|
||||
|
||||
public ConnectorMiddle(final ConnectorMiddleDto dto) {
|
||||
super(dto);
|
||||
junction = addJunction(dto.getJunction(), P50, P50);
|
||||
node = addNode(dto.getNode(), P50, P50);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,10 +11,10 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class ConnectorMiddleDto extends PartDto {
|
||||
|
||||
private JunctionDto junction;
|
||||
private NodeDto node;
|
||||
|
||||
public ConnectorMiddleDto(final ConnectorMiddle part) {
|
||||
junction = new JunctionDto(part.getJunction());
|
||||
node = new NodeDto(part.getNode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Orientation;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -36,9 +36,9 @@ public class Light extends Part {
|
||||
|
||||
private static final Color BULB_OFF_COLOR = Color.DARK_GRAY;
|
||||
|
||||
private final Junction a;
|
||||
private final Node a;
|
||||
|
||||
private final Junction b;
|
||||
private final Node b;
|
||||
|
||||
private double resistance = 15;
|
||||
|
||||
@ -52,14 +52,14 @@ public class Light extends Part {
|
||||
|
||||
public Light(final Point position) {
|
||||
super("Licht", position);
|
||||
a = addJunction("A", P10, P50);
|
||||
b = addJunction("B", P90, P50);
|
||||
a = addNode("A", P10, P50);
|
||||
b = addNode("B", P90, P50);
|
||||
}
|
||||
|
||||
public Light(final LightDto dto) {
|
||||
super(dto);
|
||||
a = addJunction(dto.getB(), P10, P50);
|
||||
b = addJunction(dto.getA(), P90, P50);
|
||||
a = addNode(dto.getB(), P10, P50);
|
||||
b = addNode(dto.getA(), P90, P50);
|
||||
resistance = dto.getResistance();
|
||||
maxVoltage = dto.getMaxVoltage();
|
||||
defect = dto.isDefect();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,9 +11,9 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class LightDto extends PartDto {
|
||||
|
||||
private JunctionDto a;
|
||||
private NodeDto a;
|
||||
|
||||
private JunctionDto b;
|
||||
private NodeDto b;
|
||||
|
||||
private double resistance;
|
||||
|
||||
@ -23,8 +23,8 @@ public class LightDto extends PartDto {
|
||||
|
||||
public LightDto(final Light light) {
|
||||
super(light);
|
||||
this.a = new JunctionDto(light.getB());
|
||||
this.b = new JunctionDto(light.getA());
|
||||
this.a = new NodeDto(light.getB());
|
||||
this.b = new NodeDto(light.getA());
|
||||
this.defect = light.isDefect();
|
||||
this.resistance = light.getResistance();
|
||||
this.maxVoltage = light.getMaxVoltage();
|
||||
|
||||
@ -2,7 +2,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@ -18,11 +18,11 @@ import static java.lang.Math.max;
|
||||
@ToString(callSuper = true)
|
||||
public class Poti extends Part {
|
||||
|
||||
private final Junction common;
|
||||
private final Node common;
|
||||
|
||||
private final Junction middle;
|
||||
private final Node middle;
|
||||
|
||||
private final Junction end;
|
||||
private final Node end;
|
||||
|
||||
@Setter
|
||||
private double resistance = 10;
|
||||
@ -31,16 +31,16 @@ public class Poti extends Part {
|
||||
|
||||
public Poti(final Point position) {
|
||||
super("Poti", position);
|
||||
common = addJunction("C", P10, P50);
|
||||
middle = addJunction("M", P50, P10);
|
||||
end = addJunction("E", P90, P50);
|
||||
common = addNode("C", P10, P50);
|
||||
middle = addNode("M", P50, P10);
|
||||
end = addNode("E", P90, P50);
|
||||
}
|
||||
|
||||
public Poti(final PotiDto dto) {
|
||||
super(dto);
|
||||
common = addJunction(dto.getCommon().getName(), P10, P50);
|
||||
middle = addJunction(dto.getMiddle().getName(), P50, P10);
|
||||
end = addJunction(dto.getEnd().getName(), P90, P50);
|
||||
common = addNode(dto.getCommon().getName(), P10, P50);
|
||||
middle = addNode(dto.getMiddle().getName(), P50, P10);
|
||||
end = addNode(dto.getEnd().getName(), P90, P50);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@ -12,11 +12,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class PotiDto extends PartDto {
|
||||
|
||||
private JunctionDto common;
|
||||
private NodeDto common;
|
||||
|
||||
private JunctionDto middle;
|
||||
private NodeDto middle;
|
||||
|
||||
private JunctionDto end;
|
||||
private NodeDto end;
|
||||
|
||||
@Setter
|
||||
private double resistance;
|
||||
@ -25,9 +25,9 @@ public class PotiDto extends PartDto {
|
||||
private double ratio;
|
||||
|
||||
public PotiDto(final Poti poti) {
|
||||
common = new JunctionDto(poti.getCommon());
|
||||
middle = new JunctionDto(poti.getMiddle());
|
||||
end = new JunctionDto(poti.getEnd());
|
||||
common = new NodeDto(poti.getCommon());
|
||||
middle = new NodeDto(poti.getMiddle());
|
||||
end = new NodeDto(poti.getEnd());
|
||||
resistance = poti.getResistance();
|
||||
ratio = poti.getRatio();
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -18,22 +18,22 @@ public class Switch1x1 extends Part {
|
||||
|
||||
private static final Point END = new Point(P90, P25);
|
||||
|
||||
private final Junction common;
|
||||
private final Node common;
|
||||
|
||||
private final Junction output;
|
||||
private final Node output;
|
||||
|
||||
private boolean state = false;
|
||||
|
||||
public Switch1x1(final Point position) {
|
||||
super("Ausschalter", position);
|
||||
common = addJunction("C", P10, P50);
|
||||
output = addJunction("O", P90, P50);
|
||||
common = addNode("C", P10, P50);
|
||||
output = addNode("O", P90, P50);
|
||||
}
|
||||
|
||||
public Switch1x1(final Switch1x1Dto dto) {
|
||||
super(dto);
|
||||
common = addJunction(dto.getCommon(), P10, P50);
|
||||
output = addJunction(dto.getOutput(), P90, P50);
|
||||
common = addNode(dto.getCommon(), P10, P50);
|
||||
output = addNode(dto.getOutput(), P90, P50);
|
||||
state = dto.isState();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,16 +11,16 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class Switch1x1Dto extends PartDto {
|
||||
|
||||
private JunctionDto common;
|
||||
private NodeDto common;
|
||||
|
||||
private JunctionDto output;
|
||||
private NodeDto output;
|
||||
|
||||
private boolean state;
|
||||
|
||||
public Switch1x1Dto(final Switch1x1 switch1X1) {
|
||||
super(switch1X1);
|
||||
this.common = new JunctionDto(switch1X1.getCommon());
|
||||
this.output = new JunctionDto(switch1X1.getOutput());
|
||||
this.common = new NodeDto(switch1X1.getCommon());
|
||||
this.output = new NodeDto(switch1X1.getOutput());
|
||||
this.state = switch1X1.isState();
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -16,26 +16,26 @@ import static de.ph87.electro.circuit.CircuitPainter.drawLine;
|
||||
@ToString(callSuper = true)
|
||||
public class Switch1x2 extends Part {
|
||||
|
||||
private final Junction common;
|
||||
private final Node common;
|
||||
|
||||
private final Junction output0;
|
||||
private final Node output0;
|
||||
|
||||
private final Junction output1;
|
||||
private final Node output1;
|
||||
|
||||
private boolean state = false;
|
||||
|
||||
public Switch1x2(final Point position) {
|
||||
super("Wechselschalter", position);
|
||||
common = addJunction("C", P10, P50);
|
||||
output0 = addJunction("O0", P90, P25);
|
||||
output1 = addJunction("O1", P90, P75);
|
||||
common = addNode("C", P10, P50);
|
||||
output0 = addNode("O0", P90, P25);
|
||||
output1 = addNode("O1", P90, P75);
|
||||
}
|
||||
|
||||
public Switch1x2(final Switch1x2Dto dto) {
|
||||
super(dto);
|
||||
common = addJunction(dto.getCommon(), P10, P50);
|
||||
output0 = addJunction(dto.getOutput0(), P90, P25);
|
||||
output1 = addJunction(dto.getOutput1(), P90, P75);
|
||||
common = addNode(dto.getCommon(), P10, P50);
|
||||
output0 = addNode(dto.getOutput0(), P90, P25);
|
||||
output1 = addNode(dto.getOutput1(), P90, P75);
|
||||
state = dto.isState();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,19 +11,19 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class Switch1x2Dto extends PartDto {
|
||||
|
||||
private JunctionDto common;
|
||||
private NodeDto common;
|
||||
|
||||
private JunctionDto output0;
|
||||
private NodeDto output0;
|
||||
|
||||
private JunctionDto output1;
|
||||
private NodeDto output1;
|
||||
|
||||
private boolean state;
|
||||
|
||||
public Switch1x2Dto(final Switch1x2 switch1X2) {
|
||||
super(switch1X2);
|
||||
this.common = new JunctionDto(switch1X2.getCommon());
|
||||
this.output0 = new JunctionDto(switch1X2.getOutput0());
|
||||
this.output1 = new JunctionDto(switch1X2.getOutput1());
|
||||
this.common = new NodeDto(switch1X2.getCommon());
|
||||
this.output0 = new NodeDto(switch1X2.getOutput0());
|
||||
this.output1 = new NodeDto(switch1X2.getOutput1());
|
||||
this.state = switch1X2.isState();
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@ -16,30 +16,30 @@ import static de.ph87.electro.circuit.CircuitPainter.drawLine;
|
||||
@ToString(callSuper = true)
|
||||
public class SwitchCross extends Part {
|
||||
|
||||
private final Junction common0;
|
||||
private final Node common0;
|
||||
|
||||
private final Junction common1;
|
||||
private final Node common1;
|
||||
|
||||
private final Junction output0;
|
||||
private final Node output0;
|
||||
|
||||
private final Junction output1;
|
||||
private final Node output1;
|
||||
|
||||
private boolean state = false;
|
||||
|
||||
public SwitchCross(final Point position) {
|
||||
super("Kreuzschalter", position);
|
||||
common0 = addJunction("C0", P10, P25);
|
||||
common1 = addJunction("C1", P10, P75);
|
||||
output0 = addJunction("O0", P90, P25);
|
||||
output1 = addJunction("O1", P90, P75);
|
||||
common0 = addNode("C0", P10, P25);
|
||||
common1 = addNode("C1", P10, P75);
|
||||
output0 = addNode("O0", P90, P25);
|
||||
output1 = addNode("O1", P90, P75);
|
||||
}
|
||||
|
||||
public SwitchCross(final SwitchCrossDto dto) {
|
||||
super(dto);
|
||||
common0 = addJunction(dto.getCommon0(), P10, P25);
|
||||
common1 = addJunction(dto.getCommon1(), P10, P75);
|
||||
output0 = addJunction(dto.getOutput0(), P90, P25);
|
||||
output1 = addJunction(dto.getOutput1(), P90, P75);
|
||||
common0 = addNode(dto.getCommon0(), P10, P25);
|
||||
common1 = addNode(dto.getCommon1(), P10, P75);
|
||||
output0 = addNode(dto.getOutput0(), P90, P25);
|
||||
output1 = addNode(dto.getOutput1(), P90, P75);
|
||||
state = dto.isState();
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
@ -11,22 +11,22 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class SwitchCrossDto extends PartDto {
|
||||
|
||||
private JunctionDto common0;
|
||||
private NodeDto common0;
|
||||
|
||||
private JunctionDto common1;
|
||||
private NodeDto common1;
|
||||
|
||||
private JunctionDto output0;
|
||||
private NodeDto output0;
|
||||
|
||||
private JunctionDto output1;
|
||||
private NodeDto output1;
|
||||
|
||||
private boolean state;
|
||||
|
||||
public SwitchCrossDto(final SwitchCross switchCross) {
|
||||
super(switchCross);
|
||||
this.common0 = new JunctionDto(switchCross.getCommon0());
|
||||
this.common1 = new JunctionDto(switchCross.getCommon1());
|
||||
this.output0 = new JunctionDto(switchCross.getOutput0());
|
||||
this.output1 = new JunctionDto(switchCross.getOutput1());
|
||||
this.common0 = new NodeDto(switchCross.getCommon0());
|
||||
this.common1 = new NodeDto(switchCross.getCommon1());
|
||||
this.output0 = new NodeDto(switchCross.getOutput0());
|
||||
this.output1 = new NodeDto(switchCross.getOutput1());
|
||||
this.state = switchCross.isState();
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package de.ph87.electro.circuit.part.parts;
|
||||
import de.ph87.electro.circuit.part.InnerConnection;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.math3.linear.ArrayRealVector;
|
||||
@ -29,9 +29,9 @@ public class Voltmeter extends Part {
|
||||
|
||||
private static final double DEGREES_RANGE = 90;
|
||||
|
||||
private final Junction a;
|
||||
private final Node a;
|
||||
|
||||
private final Junction b;
|
||||
private final Node b;
|
||||
|
||||
@Setter
|
||||
private double min = -3;
|
||||
@ -43,15 +43,15 @@ public class Voltmeter extends Part {
|
||||
|
||||
public Voltmeter(final Point position) {
|
||||
super("Voltmeter", position);
|
||||
a = addJunction("A", P10, P90);
|
||||
b = addJunction("B", P90, P90);
|
||||
a = addNode("A", P10, P90);
|
||||
b = addNode("B", P90, P90);
|
||||
postCalculate(); // TODO remove
|
||||
}
|
||||
|
||||
public Voltmeter(final PartDto dto) {
|
||||
super(dto);
|
||||
a = addJunction("A", P10, P90);
|
||||
b = addJunction("B", P90, P90);
|
||||
a = addNode("A", P10, P90);
|
||||
b = addNode("B", P90, P90);
|
||||
postCalculate(); // TODO remove
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit.part.parts;
|
||||
|
||||
import de.ph87.electro.circuit.part.PartDto;
|
||||
import de.ph87.electro.circuit.part.junction.JunctionDto;
|
||||
import de.ph87.electro.circuit.part.node.NodeDto;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@ -12,9 +12,9 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
public class VoltmeterDto extends PartDto {
|
||||
|
||||
private JunctionDto a;
|
||||
private NodeDto a;
|
||||
|
||||
private JunctionDto b;
|
||||
private NodeDto b;
|
||||
|
||||
@Setter
|
||||
private double min;
|
||||
@ -23,8 +23,8 @@ public class VoltmeterDto extends PartDto {
|
||||
private double max;
|
||||
|
||||
public VoltmeterDto(final Voltmeter voltmeter) {
|
||||
a = new JunctionDto(voltmeter.getA());
|
||||
b = new JunctionDto(voltmeter.getB());
|
||||
a = new NodeDto(voltmeter.getA());
|
||||
b = new NodeDto(voltmeter.getB());
|
||||
min = voltmeter.getMin();
|
||||
max = voltmeter.getMax();
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package de.ph87.electro.circuit.wire;
|
||||
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
@ -17,16 +17,16 @@ public class Wire {
|
||||
|
||||
@Getter
|
||||
@NonNull
|
||||
private final Junction a;
|
||||
private final Node a;
|
||||
|
||||
@Getter
|
||||
@NonNull
|
||||
private final Junction b;
|
||||
private final Node b;
|
||||
|
||||
@Setter
|
||||
private double current = Double.NaN;
|
||||
|
||||
public Wire(@NonNull final Junction a, @NonNull final Junction b) {
|
||||
public Wire(@NonNull final Node a, @NonNull final Node b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
a.getWires().add(this);
|
||||
@ -54,17 +54,17 @@ public class Wire {
|
||||
return distance <= WIRE_HOVER_STROKE_BACK.getLineWidth();
|
||||
}
|
||||
|
||||
public Junction getOpposite(final Junction junction) {
|
||||
if (a == junction) {
|
||||
public Node getOpposite(final Node node) {
|
||||
if (a == node) {
|
||||
return b;
|
||||
} else if (b == junction) {
|
||||
} else if (b == node) {
|
||||
return a;
|
||||
}
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
public double getCurrent(final Junction junction) {
|
||||
return junction == a ? current : -current;
|
||||
public double getCurrent(final Node node) {
|
||||
return node == a ? current : -current;
|
||||
}
|
||||
|
||||
public void draw(final Graphics2D g) {
|
||||
|
||||
@ -18,8 +18,8 @@ public class Sidebar extends JPanel {
|
||||
addButton("Neu", null, newCircuit, new Color(128, 202, 255));
|
||||
|
||||
addToggle("Details", () -> SHOW_WIRE_DETAILS, v -> SHOW_WIRE_DETAILS = v);
|
||||
addToggle("Namen", () -> SHOW_JUNCTION_NAMES, v -> SHOW_JUNCTION_NAMES = v);
|
||||
addToggle("Spannungen", () -> SHOW_JUNCTION_VOLTAGES, v -> SHOW_JUNCTION_VOLTAGES = v);
|
||||
addToggle("Namen", () -> SHOW_NODE_NAMES, v -> SHOW_NODE_NAMES = v);
|
||||
addToggle("Spannungen", () -> SHOW_NODE_VOLTAGES, v -> SHOW_NODE_VOLTAGES = v);
|
||||
|
||||
final Point ZERO = new Point();
|
||||
addPart(new Battery(ZERO));
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package de.ph87.electro.circuit;
|
||||
|
||||
import de.ph87.electro.circuit.calculation.Calculation;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import de.ph87.electro.circuit.part.parts.Battery;
|
||||
import de.ph87.electro.circuit.part.parts.Light;
|
||||
import de.ph87.electro.circuit.wire.Wire;
|
||||
@ -26,11 +26,11 @@ class CalculationServiceTest {
|
||||
circuit.streamParts().forEach(part -> {
|
||||
log.info("");
|
||||
log.info(part.toString());
|
||||
for (final Junction junction : part.getJunctions()) {
|
||||
log.info(" \"%s\" = %.2f V".formatted(junction.getName(), junction.getVoltage()));
|
||||
for (final Wire wire : junction.getWires()) {
|
||||
final Junction opposite = wire.getOpposite(junction);
|
||||
log.info(" -> %s.%s = %.2f A".formatted(opposite.getOwner().getName(), opposite.getName(), wire.getCurrent(junction)));
|
||||
for (final Node node : part.getNodes()) {
|
||||
log.info(" \"%s\" = %.2f V".formatted(node.getName(), node.getVoltage()));
|
||||
for (final Wire wire : node.getWires()) {
|
||||
final Node opposite = wire.getOpposite(node);
|
||||
log.info(" -> %s.%s = %.2f A".formatted(opposite.getOwner().getName(), opposite.getName(), wire.getCurrent(node)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -3,7 +3,7 @@ package de.ph87.electro.circuit.io;
|
||||
import de.ph87.electro.circuit.Circuit;
|
||||
import de.ph87.electro.circuit.CircuitIOService;
|
||||
import de.ph87.electro.circuit.part.Part;
|
||||
import de.ph87.electro.circuit.part.junction.Junction;
|
||||
import de.ph87.electro.circuit.part.node.Node;
|
||||
import de.ph87.electro.circuit.part.parts.Battery;
|
||||
import de.ph87.electro.circuit.part.parts.Light;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -50,19 +50,19 @@ class CircuitIOServiceTest {
|
||||
assertEquals(originalPart.getName(), reloadedPart.getName());
|
||||
assertEquals(originalPart.getPosition(), reloadedPart.getPosition());
|
||||
assertEquals(originalPart.getOrientation(), reloadedPart.getOrientation());
|
||||
assertEquals(originalPart.getJunctions().size(), reloadedPart.getJunctions().size());
|
||||
for (final Junction originalJunction : originalPart.getJunctions()) {
|
||||
System.out.printf(" - Junction: %s\n", originalJunction.getUuid());
|
||||
final Junction reloadedJunction = reloadedPart.getJunctions().stream().filter(junction -> junction.getUuid().equals(originalJunction.getUuid())).findFirst().orElseThrow();
|
||||
assertEquals(originalJunction.getUuid(), reloadedJunction.getUuid());
|
||||
assertEquals(originalJunction.getName(), reloadedJunction.getName());
|
||||
assertEquals(originalJunction.getAbsolute(), reloadedJunction.getAbsolute());
|
||||
assertEquals(originalJunction.getWires().size(), reloadedJunction.getWires().size());
|
||||
originalJunction.getWires().stream()
|
||||
.map(originalWire -> originalWire.getOpposite(originalJunction))
|
||||
assertEquals(originalPart.getNodes().size(), reloadedPart.getNodes().size());
|
||||
for (final Node originalNode : originalPart.getNodes()) {
|
||||
System.out.printf(" - Node: %s\n", originalNode.getUuid());
|
||||
final Node reloadedNode = reloadedPart.getNodes().stream().filter(node -> node.getUuid().equals(originalNode.getUuid())).findFirst().orElseThrow();
|
||||
assertEquals(originalNode.getUuid(), reloadedNode.getUuid());
|
||||
assertEquals(originalNode.getName(), reloadedNode.getName());
|
||||
assertEquals(originalNode.getAbsolute(), reloadedNode.getAbsolute());
|
||||
assertEquals(originalNode.getWires().size(), reloadedNode.getWires().size());
|
||||
originalNode.getWires().stream()
|
||||
.map(originalWire -> originalWire.getOpposite(originalNode))
|
||||
.forEach(originalDestination -> {
|
||||
System.out.printf(" - Destinations: %s\n", originalDestination.getUuid());
|
||||
final Junction reloadedDestination = reloadedJunction.getWires().stream().map(wire -> wire.getOpposite(reloadedJunction)).filter(destination -> destination.getUuid().equals(originalDestination.getUuid())).findFirst().orElseThrow();
|
||||
final Node reloadedDestination = reloadedNode.getWires().stream().map(wire -> wire.getOpposite(reloadedNode)).filter(destination -> destination.getUuid().equals(originalDestination.getUuid())).findFirst().orElseThrow();
|
||||
assertEquals(originalDestination.getUuid(), reloadedDestination.getUuid());
|
||||
assertEquals(originalDestination.getOwner().getUuid(), reloadedDestination.getOwner().getUuid());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user