Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 52 additions & 42 deletions src/jls/edit/SimpleEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2837,10 +2837,14 @@ private boolean overlap() {
}
}*/

untouchAll(); // may have moved and stopped touching

// check every element in the selected set
for (Element sel : selected) {

// only one element needs to be intersecting the selected element to count as overlap
boolean anyIntersection = false;

// check against every element in the circuit
for (Element el : circuit.getElements()) {

Expand All @@ -2850,6 +2854,7 @@ private boolean overlap() {

// check simple overlap of areas
if (sel.intersects(el)) {
anyIntersection = true;

// no overlap if possible connection,
boolean ok = false;
Expand Down Expand Up @@ -2925,16 +2930,14 @@ else if (el instanceof Wire) {
}

// selected is not a wire end
else {
// if not a wire end, ignore
else if (el instanceof WireEnd) {

WireEnd end = (WireEnd)el;

// put to wire end
for (Put put : sel.getAllPuts()) {

// if not a wire end, ignore
if (!(el instanceof WireEnd))
continue;
WireEnd end = (WireEnd)el;

// if don't line up, ignore
if (put.getX() != end.getX() || put.getY() != end.getY()) {
continue;
Expand Down Expand Up @@ -2971,52 +2974,59 @@ else if (el instanceof Wire) {
return true;
}
}
}

// no intersection, but wires may be overlapping wire ends
// or puts might line up
else {
// no intersection, but wires may be overlapping wire ends
// or puts might line up
if (!anyIntersection) {

// see if wires connected to a wire end dragged onto wire ends
if (sel instanceof WireEnd) {
WireEnd end = (WireEnd)sel;
for (Wire wire : end.getWires()) {
for (Element elm : circuit.getElements()) {
if (sel == elm)
continue;
if (!(elm instanceof WireEnd)) {
continue;
}
WireEnd otherEnd = (WireEnd)elm;
if (wire.touches(otherEnd)) {
overlapMessage = "overlap";
untouchAll();
return true;
}
// see if wires connected to a wire end dragged onto wire ends
if (sel instanceof WireEnd) {
WireEnd end = (WireEnd)sel;
for (Wire wire : end.getWires()) {
for (Element el : circuit.getElements()) {
if (sel == el)
continue;
if (!(el instanceof WireEnd)) {
continue;
}
WireEnd otherEnd = (WireEnd)el;
if (wire.touches(otherEnd)) {
overlapMessage = "overlap";
untouchAll();
return true;
}
}
}
}

// see if wires connected to puts dragged onto wire ends
for (Put p : sel.getAllPuts()) {
if (p.isAttached()) {
Wire wire = p.getWireEnd().getOnlyWire();
for (Element elm : circuit.getElements()) {
if (sel == elm)
continue;
if (!(elm instanceof WireEnd)) {
continue;
}
WireEnd otherEnd = (WireEnd)elm;
if (wire.touches(otherEnd)) {
overlapMessage = "overlap";
untouchAll();
return true;
}
// see if wires connected to puts dragged onto wire ends
for (Put p : sel.getAllPuts()) {
if (p.isAttached()) {
Wire wire = p.getWireEnd().getOnlyWire();
for (Element el : circuit.getElements()) {
if (sel == el)
continue;
if (!(el instanceof WireEnd)) {
continue;
}
WireEnd otherEnd = (WireEnd)el;
if (wire.touches(otherEnd)) {
overlapMessage = "overlap";
untouchAll();
return true;
}
}
}
}

// check all put combinations
for (Element el : circuit.getElements()) {

// ignore elements in the selected set
if (selected.contains(el))
continue;

// check all put combinations
for (Put p1 : sel.getAllPuts()) {
for (Put p2 : el.getAllPuts()) {

Expand Down