Improve "Expand Selection" feature to use the same algorithm as netlists

for better precision<
This commit is contained in:
Branislav Stojkovic
2019-03-22 00:47:28 +01:00
parent 894ff1a2cb
commit 14a994e68f
11 changed files with 78 additions and 18 deletions
@@ -398,7 +398,26 @@ public abstract class NetlistAnalyzer {
return c.getName() + " " + c.getValueForDisplay();
}
protected Set<IDIYComponent<?>> extractComponents(Netlist netlist) {
public static List<Set<IDIYComponent<?>>> extractComponentGroups(List<Netlist> netlists) {
List<Set<IDIYComponent<?>>> res = new ArrayList<Set<IDIYComponent<?>>>();
for (Netlist n : netlists) {
res.addAll(extractComponentGroups(n));
}
return res;
}
public static List<Set<IDIYComponent<?>>> extractComponentGroups(Netlist netlist) {
List<Set<IDIYComponent<?>>> res = new ArrayList<Set<IDIYComponent<?>>>();
for (Group g : netlist.getGroups()) {
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
for (Node n : g.getNodes())
components.add(n.getComponent());
res.add(components);
}
return res;
}
public static Set<IDIYComponent<?>> extractComponents(Netlist netlist) {
Set<IDIYComponent<?>> res = new HashSet<IDIYComponent<?>>();
for (Group g : netlist.getGroups())
for (Node n : g.getNodes())
@@ -80,6 +80,7 @@ import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.netlist.Group;
import org.diylc.netlist.Netlist;
import org.diylc.netlist.NetlistAnalyzer;
import org.diylc.netlist.Node;
import org.diylc.netlist.Position;
import org.diylc.netlist.SwitchSetup;
@@ -1905,6 +1906,8 @@ public class Presenter implements IPlugInPort {
public void expandSelection(ExpansionMode expansionMode) {
LOG.info(String.format("expandSelection(%s)", expansionMode));
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(this.selectedComponents);
List<Netlist> netlists = extractNetlists();
List<Set<IDIYComponent<?>>> allGroups = NetlistAnalyzer.extractComponentGroups(netlists);
// Find control points of all selected components and all types
Set<String> selectedNamePrefixes = new HashSet<String>();
if (expansionMode == ExpansionMode.SAME_TYPE) {
@@ -1916,23 +1919,26 @@ public class Presenter implements IPlugInPort {
// Now try to find components that intersect with at least one component
// in the pool.
for (IDIYComponent<?> component : getCurrentProject().getComponents()) {
// no need to consider it, it's already in the selection
if (newSelection.contains(component))
continue;
// construct a list of component groups that contain the current component
List<Set<IDIYComponent<?>>> componentGroups = new ArrayList<Set<IDIYComponent<?>>>();
for (Set<IDIYComponent<?>> e : allGroups)
if (e.contains(component))
componentGroups.add(e);
if (componentGroups.isEmpty())
continue;
// Skip already selected components or ones that cannot be stuck to
// other components.
ComponentArea area = drawingManager.getComponentArea(component);
if (newSelection.contains(component) || !component.isControlPointSticky(0) || area == null
|| area.getOutlineArea() == null)
continue;
boolean matches = false;
for (IDIYComponent<?> selectedComponent : this.selectedComponents) {
ComponentArea selectedArea = drawingManager.getComponentArea(selectedComponent);
if (selectedArea == null || selectedArea.getOutlineArea() == null)
continue;
Area intersection = new Area(area.getOutlineArea());
intersection.intersect(selectedArea.getOutlineArea());
if (!intersection.isEmpty()) {
matches = true;
break;
}
outer: for (IDIYComponent<?> selectedComponent : this.selectedComponents) {
// try to find the selectedComponent in one of the groups
for (Set<IDIYComponent<?>> s : componentGroups)
if (s.contains(selectedComponent)) {
matches = true;
break outer;
}
}
if (matches) {
Binary file not shown.
@@ -29,7 +29,7 @@ import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment;
@@ -334,6 +334,13 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
body[i] = rotate.createTransformedShape(body[i]);
}
}
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 3)
return null;
return Integer.toString(index + 1);
}
/**
@@ -623,7 +623,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
@Override
public String getInternalLinkName(int index1, int index2) {
if ((index1 == 0 && index2 == getControlPointCount() - 1) || (index2 == 0 && index1 == getControlPointCount() - 1))
if ((index1 == 0 && index2 == 1) || (index2 == 0 && index1 == 1))
return getName();
return null;
}
@@ -650,6 +650,13 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setMoveLabel(boolean moveLabel) {
this.moveLabel = moveLabel;
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 2)
return null;
return Integer.toString(index + 1);
}
public enum LabelOriantation {
Directional, Horizontal
@@ -167,4 +167,9 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
public String getControlPointNodeName(int index) {
return null;
}
public boolean getMoveLabel() {
// override to disable edit
return false;
}
}
@@ -162,5 +162,10 @@ public class Jumper extends AbstractLeadedComponent<Void> implements IContinuity
@Override
public boolean arePointsConnected(int index1, int index2) {
return true;
}
}
public boolean getMoveLabel() {
// override to disable edit
return false;
}
}
@@ -201,4 +201,11 @@ public abstract class AbstractTransistorPackage extends AbstractTransparentCompo
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 3)
return null;
return Integer.toString(index + 1);
}
}
Binary file not shown.
Binary file not shown.
+4
View File
@@ -2646,6 +2646,10 @@
<changeType>IMPROVEMENT</changeType>
<description>Output SPICE node names in the "Nxxx" format</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Improve "Expand Selection" feature to use the same algorithm as netlists for better precision</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Improve performance of netlist calculations</description>