diff --git a/diylc/diylc-core/src/org/diylc/presenter/Connection.java b/diylc/diylc-core/src/org/diylc/presenter/Connection.java
new file mode 100644
index 00000000..73d41b10
--- /dev/null
+++ b/diylc/diylc-core/src/org/diylc/presenter/Connection.java
@@ -0,0 +1,53 @@
+package org.diylc.presenter;
+
+import java.awt.geom.Point2D;
+
+public class Connection {
+
+ private Point2D p1;
+ private Point2D p2;
+
+ public Connection(Point2D p1, Point2D p2) {
+ this.p1 = p1.getX() < p2.getX() || p1.getX() == p2.getX() && p1.getY() < p2.getY() ? p1 : p2;
+ this.p2 = p1.getX() < p2.getX() || p1.getX() == p2.getX() && p1.getY() < p2.getY() ? p2 : p1;
+ }
+
+ public Point2D getP1() {
+ return p1;
+ }
+
+ public Point2D getP2() {
+ return p2;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((p1 == null) ? 0 : p1.hashCode());
+ result = prime * result + ((p2 == null) ? 0 : p2.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Connection other = (Connection) obj;
+ if (p1 == null) {
+ if (other.p1 != null)
+ return false;
+ } else if (!p1.equals(other.p1))
+ return false;
+ if (p2 == null) {
+ if (other.p2 != null)
+ return false;
+ } else if (!p2.equals(other.p2))
+ return false;
+ return true;
+ }
+}
diff --git a/diylc/diylc-core/src/org/diylc/presenter/DrawingManager.java b/diylc/diylc-core/src/org/diylc/presenter/DrawingManager.java
index 0265cf91..0a6bea7e 100644
--- a/diylc/diylc-core/src/org/diylc/presenter/DrawingManager.java
+++ b/diylc/diylc-core/src/org/diylc/presenter/DrawingManager.java
@@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -509,14 +510,14 @@ public class DrawingManager {
// Find all individual continuity areas for all components
List preliminaryAreas = new ArrayList();
List checkBreakout = new ArrayList();
- List connections = new ArrayList();
+ Set connections = new HashSet();
for (IDIYComponent> c : project.getComponents()) {
ComponentArea a = getComponentArea(c);
ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class extends IDIYComponent>>) c.getClass());
if (type.isContinuity()) {
- connections.add(new Line2D.Double(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
+ connections.add(new Connection(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
}
if (a == null || a.getOutlineArea() == null)
@@ -547,11 +548,32 @@ public class DrawingManager {
// else
// areas.add(a);
}
+
+ expandConnections(connections);
crunchAreas(areas, connections);
return areas;
}
+
+ private void expandConnections(Set connections) {
+ Set toAdd = new HashSet();
+ for (Connection c1 : connections)
+ for (Connection c2 : connections) {
+ if (c1 == c2)
+ continue;
+ if (c1.getP1().distance(c2.getP1()) < CONTROL_POINT_SIZE)
+ toAdd.add(new Connection(c1.getP2(), c2.getP2()));
+ if (c1.getP1().distance(c2.getP2()) < CONTROL_POINT_SIZE)
+ toAdd.add(new Connection(c1.getP2(), c2.getP1()));
+ if (c1.getP2().distance(c2.getP1()) < CONTROL_POINT_SIZE)
+ toAdd.add(new Connection(c1.getP1(), c2.getP2()));
+ if (c1.getP2().distance(c2.getP2()) < CONTROL_POINT_SIZE)
+ toAdd.add(new Connection(c1.getP1(), c2.getP1()));
+ }
+ if (connections.addAll(toAdd))
+ expandConnections(connections);
+ }
/**
* Merges all areas that either overlap or are joined by connections.
@@ -560,7 +582,7 @@ public class DrawingManager {
* @param connections
* @return
*/
- private boolean crunchAreas(List areas, List connections) {
+ private boolean crunchAreas(List areas, Set connections) {
boolean isChanged = false;
List newAreas = new ArrayList();
@@ -581,7 +603,7 @@ public class DrawingManager {
a1.add(a2);
consumed.set(j, true);
} else { // maybe there's a connection between them
- for (Line2D p : connections) {
+ for (Connection p : connections) {
if ((a1.contains(p.getP1()) && a2.contains(p.getP2())) || (a1.contains(p.getP2()) && a2.contains(p.getP1()))) {
a1.add(a2);
consumed.set(j, true);
diff --git a/diylc/diylc-swing/update.xml b/diylc/diylc-swing/update.xml
index 8bf1e40d..f251a544 100644
--- a/diylc/diylc-swing/update.xml
+++ b/diylc/diylc-swing/update.xml
@@ -2569,5 +2569,21 @@
https://github.com/bancika/diy-layout-creator/releases
+
+
+ 3
+ 56
+ 0
+
+ 2019-03-02 00:00:00.000 CET
+
+
+
+ BUG_FIX
+ "Highlight Connected Areas" doesn't follow multiple chained wires and jumpers
+
+
+ https://github.com/bancika/diy-layout-creator/releases
+