"Highlight Connected Areas" doesn't follow multiple chained wires and

jumpers
This commit is contained in:
Branislav Stojkovic
2019-03-06 00:15:53 +01:00
parent 2553ffbba7
commit 2d1cf515d6
3 changed files with 95 additions and 4 deletions
@@ -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;
}
}
@@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -509,14 +510,14 @@ public class DrawingManager {
// Find all individual continuity areas for all components // Find all individual continuity areas for all components
List<Area> preliminaryAreas = new ArrayList<Area>(); List<Area> preliminaryAreas = new ArrayList<Area>();
List<Boolean> checkBreakout = new ArrayList<Boolean>(); List<Boolean> checkBreakout = new ArrayList<Boolean>();
List<Line2D> connections = new ArrayList<Line2D>(); Set<Connection> connections = new HashSet<Connection>();
for (IDIYComponent<?> c : project.getComponents()) { for (IDIYComponent<?> c : project.getComponents()) {
ComponentArea a = getComponentArea(c); ComponentArea a = getComponentArea(c);
ComponentType type = ComponentType type =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass()); ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
if (type.isContinuity()) { 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) if (a == null || a.getOutlineArea() == null)
@@ -547,11 +548,32 @@ public class DrawingManager {
// else // else
// areas.add(a); // areas.add(a);
} }
expandConnections(connections);
crunchAreas(areas, connections); crunchAreas(areas, connections);
return areas; return areas;
} }
private void expandConnections(Set<Connection> connections) {
Set<Connection> toAdd = new HashSet<Connection>();
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. * Merges all areas that either overlap or are joined by connections.
@@ -560,7 +582,7 @@ public class DrawingManager {
* @param connections * @param connections
* @return * @return
*/ */
private boolean crunchAreas(List<Area> areas, List<Line2D> connections) { private boolean crunchAreas(List<Area> areas, Set<Connection> connections) {
boolean isChanged = false; boolean isChanged = false;
List<Area> newAreas = new ArrayList<Area>(); List<Area> newAreas = new ArrayList<Area>();
@@ -581,7 +603,7 @@ public class DrawingManager {
a1.add(a2); a1.add(a2);
consumed.set(j, true); consumed.set(j, true);
} else { // maybe there's a connection between them } 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()))) { if ((a1.contains(p.getP1()) && a2.contains(p.getP2())) || (a1.contains(p.getP2()) && a2.contains(p.getP1()))) {
a1.add(a2); a1.add(a2);
consumed.set(j, true); consumed.set(j, true);
+16
View File
@@ -2569,5 +2569,21 @@
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>3</major>
<minor>56</minor>
<build>0</build>
</versionNumber>
<releaseDate>2019-03-02 00:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>"Highlight Connected Areas" doesn't follow multiple chained wires and jumpers</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a> </a>
</java.util.Arrays_-ArrayList> </java.util.Arrays_-ArrayList>