mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Improved performance of "Highlight Connected Areas" feature, especially
with bigger projects
This commit is contained in:
@@ -89,7 +89,8 @@ public class DrawingManager {
|
|||||||
// determine which components are invalidated when they are not in the map.
|
// determine which components are invalidated when they are not in the map.
|
||||||
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
|
private Map<IDIYComponent<?>, ComponentState> lastDrawnStateMap;
|
||||||
|
|
||||||
private Area continuityArea;
|
private Area currentContinuityArea;
|
||||||
|
private List<Area> continuityAreaCache = null;
|
||||||
|
|
||||||
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
private Composite slotComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||||
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
private Composite lockedComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
|
||||||
@@ -403,12 +404,12 @@ public class DrawingManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (continuityArea != null
|
if (currentContinuityArea != null
|
||||||
&& (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) {
|
&& (ConfigurationManager.getInstance().readBoolean(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false))) {
|
||||||
Composite oldComposite = g2d.getComposite();
|
Composite oldComposite = g2d.getComposite();
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
|
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
|
||||||
g2d.setColor(Color.green);
|
g2d.setColor(Color.green);
|
||||||
g2d.fill(continuityArea);
|
g2d.fill(currentContinuityArea);
|
||||||
g2d.setComposite(oldComposite);
|
g2d.setComposite(oldComposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,7 +451,8 @@ public class DrawingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearContinuityArea() {
|
public void clearContinuityArea() {
|
||||||
this.continuityArea = null;
|
currentContinuityArea = null;
|
||||||
|
continuityAreaCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) {
|
public List<IDIYComponent<?>> findComponentsAt(Point point, Project project) {
|
||||||
@@ -503,16 +505,17 @@ public class DrawingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void findContinuityAreaAtPoint(Project project, Point p) {
|
public void findContinuityAreaAtPoint(Project project, Point p) {
|
||||||
List<Area> areas = getContinuityAreas(project);
|
if (continuityAreaCache == null)
|
||||||
|
continuityAreaCache = getContinuityAreas(project);
|
||||||
|
|
||||||
for (Area a : areas) {
|
for (Area a : continuityAreaCache) {
|
||||||
if (a.contains(p)) {
|
if (a.contains(p)) {
|
||||||
continuityArea = a;
|
currentContinuityArea = a;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
continuityArea = null;
|
currentContinuityArea = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Area> getContinuityAreas(Project project) {
|
public List<Area> getContinuityAreas(Project project) {
|
||||||
@@ -598,13 +601,10 @@ public class DrawingManager {
|
|||||||
boolean isChanged = false;
|
boolean isChanged = false;
|
||||||
|
|
||||||
List<Area> newAreas = new ArrayList<Area>();
|
List<Area> newAreas = new ArrayList<Area>();
|
||||||
List<Boolean> consumed = new ArrayList<Boolean>();
|
boolean[] consumed = new boolean[areas.size()];
|
||||||
for (int i = 0; i < areas.size(); i++) {
|
|
||||||
consumed.add(false);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < areas.size(); i++) {
|
for (int i = 0; i < areas.size(); i++) {
|
||||||
for (int j = i + 1; j < areas.size(); j++) {
|
for (int j = i + 1; j < areas.size(); j++) {
|
||||||
if (consumed.get(j))
|
if (consumed[j])
|
||||||
continue;
|
continue;
|
||||||
Area a1 = areas.get(i);
|
Area a1 = areas.get(i);
|
||||||
Area a2 = areas.get(j);
|
Area a2 = areas.get(j);
|
||||||
@@ -616,13 +616,13 @@ public class DrawingManager {
|
|||||||
// if the two areas intersect, make a union and consume the second area
|
// if the two areas intersect, make a union and consume the second area
|
||||||
if (intersection != null && !intersection.isEmpty()) {
|
if (intersection != null && !intersection.isEmpty()) {
|
||||||
a1.add(a2);
|
a1.add(a2);
|
||||||
consumed.set(j, true);
|
consumed[j] = true;
|
||||||
} else { // maybe there's a connection between them
|
} 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
|
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())) ||
|
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())) {
|
(a1.getBounds().contains(p.getP2()) && a2.getBounds().contains(p.getP1())) && a1.contains(p.getP2()) && a2.contains(p.getP1())) {
|
||||||
a1.add(a2);
|
a1.add(a2);
|
||||||
consumed.set(j, true);
|
consumed[j] = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,7 +630,7 @@ public class DrawingManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < areas.size(); i++)
|
for (int i = 0; i < areas.size(); i++)
|
||||||
if (!consumed.get(i))
|
if (!consumed[i])
|
||||||
newAreas.add(areas.get(i));
|
newAreas.add(areas.get(i));
|
||||||
else
|
else
|
||||||
isChanged = true;
|
isChanged = true;
|
||||||
|
|||||||
@@ -2866,6 +2866,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added "Duodecar B12C" tube socket type</description>
|
<description>Added "Duodecar B12C" tube socket type</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Improved performance of "Highlight Connected Areas" feature, especially with bigger projects</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>Choosing a default theme in the Config menut causes the app to fail to start and some components to fail to render</description>
|
<description>Choosing a default theme in the Config menut causes the app to fail to start and some components to fail to render</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user