mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
fix Highlight Connected Areas
This commit is contained in:
@@ -299,6 +299,7 @@ public class DrawingManager {
|
|||||||
if (!trackArea) {
|
if (!trackArea) {
|
||||||
g2dWrapper.stopTracking();
|
g2dWrapper.stopTracking();
|
||||||
}
|
}
|
||||||
|
Composite oldComposite = g2d.getComposite();
|
||||||
// Draw locked components in a new composite.
|
// Draw locked components in a new composite.
|
||||||
if (lockedComponents.contains(component)) {
|
if (lockedComponents.contains(component)) {
|
||||||
g2d.setComposite(lockedComposite);
|
g2d.setComposite(lockedComposite);
|
||||||
@@ -309,20 +310,21 @@ public class DrawingManager {
|
|||||||
|
|
||||||
if (drawOptions.contains(DrawOption.ENABLE_CACHING)) // go through the DrawingCache
|
if (drawOptions.contains(DrawOption.ENABLE_CACHING)) // go through the DrawingCache
|
||||||
DrawingCache.Instance.draw(component, g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, zoom, visibleRect);
|
DrawingCache.Instance.draw(component, g2dWrapper, state, drawOptions.contains(DrawOption.OUTLINE_MODE), project, zoom, visibleRect);
|
||||||
else // go stragiht to the wrapper
|
else // go straight to the wrapper
|
||||||
component.draw(g2dWrapper, state, outlineMode, project, g2dWrapper);
|
component.draw(g2dWrapper, state, outlineMode, project, g2dWrapper);
|
||||||
|
|
||||||
if (g2dWrapper.isTrackingContinuityArea()) {
|
if (g2dWrapper.isTrackingContinuityArea()) {
|
||||||
LOG.info("Component " + component.getName() + " of type " + component.getClass().getName() + " did not stop tracking continuity area.");
|
LOG.info("Component " + component.getName() + " of type " + component.getClass().getName() + " did not stop tracking continuity area.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// just in case, stop all tracking
|
|
||||||
g2dWrapper.stopTrackingContinuityArea();
|
|
||||||
g2dWrapper.stopTracking();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error drawing " + component.getName(), e);
|
LOG.error("Error drawing " + component.getName(), e);
|
||||||
failedComponents.add(component);
|
failedComponents.add(component);
|
||||||
} finally {
|
} finally {
|
||||||
|
// just in case, stop all tracking
|
||||||
|
g2dWrapper.stopTrackingContinuityArea();
|
||||||
|
g2dWrapper.stopTracking();
|
||||||
|
// revert composite
|
||||||
|
g2d.setComposite(oldComposite);
|
||||||
// record render stats
|
// record render stats
|
||||||
long componentEnd = System.nanoTime();
|
long componentEnd = System.nanoTime();
|
||||||
Counter stats = null;
|
Counter stats = null;
|
||||||
@@ -671,57 +673,39 @@ public class DrawingManager {
|
|||||||
boolean isChanged = false;
|
boolean isChanged = false;
|
||||||
|
|
||||||
List<Area> newAreas = new ArrayList<Area>();
|
List<Area> newAreas = new ArrayList<Area>();
|
||||||
boolean[] consumed = new boolean[areas.size()];
|
List<Boolean> consumed = new ArrayList<Boolean>();
|
||||||
for (int i = 0; i < areas.size(); i++) {
|
for (int i = 0; i < areas.size(); i++) {
|
||||||
Area a1 = areas.get(i);
|
consumed.add(false);
|
||||||
Rectangle2D bounds1 = a1.getBounds2D();
|
}
|
||||||
|
for (int i = 0; i < areas.size(); i++) {
|
||||||
Map<Area, Integer> candidates = new HashMap<Area, Integer>();
|
for (int j = i + 1; j < areas.size(); j++) {
|
||||||
|
if (consumed.get(j))
|
||||||
for (int j = i + 1; j < areas.size(); j++) {
|
continue;
|
||||||
// if (consumed[j])
|
Area a1 = areas.get(i);
|
||||||
// continue;
|
Area a2 = areas.get(j);
|
||||||
Area a2 = areas.get(j);
|
Area intersection = null;
|
||||||
Rectangle2D bounds2 = a2.getBounds2D();
|
if (a1.getBounds2D().intersects(a2.getBounds())) {
|
||||||
|
intersection = new Area(a1);
|
||||||
// maybe there's a direct connection between them, try that first because it's faster than area overlap
|
intersection.intersect(a2);
|
||||||
for (Connection p : connections) { // use getBounds to optimize the computation, don't get into complex math if not needed
|
}
|
||||||
if ((bounds1.contains(p.getP1()) && bounds2.contains(p.getP2()) && a1.contains(p.getP1()) && a2.contains(p.getP2())) ||
|
// if the two areas intersect, make a union and consume the second area
|
||||||
(bounds1.contains(p.getP2()) && bounds2.contains(p.getP1())) && a1.contains(p.getP2()) && a2.contains(p.getP1())) {
|
if (intersection != null && !intersection.isEmpty()) {
|
||||||
a1.add(a2);
|
a1.add(a2);
|
||||||
consumed[j] = true;
|
consumed.set(j, true);
|
||||||
break;
|
} else { // maybe there's a connection between them
|
||||||
}
|
for (Connection p : connections) { // use getBounds to optimize the computation, don't get into complex math if not needed
|
||||||
}
|
if ((a1.getBounds().contains(p.getP1()) && a2.getBounds().contains(p.getP2()) && a1.contains(p.getP1()) && a2.contains(p.getP2())) ||
|
||||||
|
(a1.getBounds().contains(p.getP2()) && a2.getBounds().contains(p.getP1())) && a1.contains(p.getP2()) && a2.contains(p.getP1())) {
|
||||||
if (bounds1.intersects(bounds2)) {
|
a1.add(a2);
|
||||||
candidates.put(a2, j);
|
consumed.set(j, true);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Set<Area> mergeQueue = new HashSet<Area>();
|
}
|
||||||
|
}
|
||||||
// run a parallel for-each to determine which areas overlap with a1 and add them to a queue to be added to a1 later
|
|
||||||
if (candidates.size() > 0) {
|
|
||||||
candidates.entrySet().parallelStream().forEach(x -> {
|
|
||||||
Area intersection = new Area(a1);
|
|
||||||
intersection.intersect(x.getKey());
|
|
||||||
if (intersection != null && !intersection.isEmpty()) {
|
|
||||||
synchronized (mergeQueue) {
|
|
||||||
mergeQueue.add(x.getKey());
|
|
||||||
}
|
|
||||||
consumed[x.getValue()] = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// if make a union of all intersecting areas
|
|
||||||
for(Area a2 : mergeQueue)
|
|
||||||
a1.add(a2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < areas.size(); i++)
|
for (int i = 0; i < areas.size(); i++)
|
||||||
if (!consumed[i])
|
if (!consumed.get(i))
|
||||||
newAreas.add(areas.get(i));
|
newAreas.add(areas.get(i));
|
||||||
else
|
else
|
||||||
isChanged = true;
|
isChanged = true;
|
||||||
|
|||||||
@@ -2937,6 +2937,10 @@
|
|||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Prevent the app from closing while running background operations, like saving and exporting files</description>
|
<description>Prevent the app from closing while running background operations, like saving and exporting files</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>BUG_FIX</changeType>
|
||||||
|
<description>Fixed the issue with "Highlight Connected Areas" not recognizing some conductive areas</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
|
|||||||
Reference in New Issue
Block a user