netlist parse improvements

This commit is contained in:
bancika
2021-01-03 09:19:58 +01:00
parent 1737df8047
commit 458b853830
6 changed files with 79 additions and 25 deletions
@@ -40,7 +40,7 @@ public class Voltage extends AbstractMeasure<VoltageUnit> {
return new Voltage(value, unit);
}
public static Voltage parseCapacitance(String value) {
public static Voltage parseVoltage(String value) {
value = value.replace("*", "");
for (VoltageUnit unit : VoltageUnit.values()) {
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
@@ -42,9 +42,10 @@ public abstract class AbstractNetlistParser implements INetlistParser {
private static Size X_OFFSET = new Size(1.5d, SizeUnit.in);
private static Size Y_OFFSET = new Size(0.3d, SizeUnit.in);
private static int ROW_COUNT = 15;
private static int ROW_COUNT = 12;
public List<ParsedNetlistEntry> parseFile(String fileName, List<String> outputWarnings) throws NetlistParseException {
public List<ParsedNetlistEntry> parseFile(String fileName, List<String> outputWarnings)
throws NetlistParseException {
String content;
try {
content = new String(Files.readAllBytes(Paths.get(fileName)));
@@ -55,7 +56,8 @@ public abstract class AbstractNetlistParser implements INetlistParser {
return parse(content, outputWarnings);
}
public List<ParsedNetlistEntry> parse(String content, List<String> outputWarnings) throws NetlistParseException {
public List<ParsedNetlistEntry> parse(String content, List<String> outputWarnings)
throws NetlistParseException {
List<ParsedNetlistEntry> result = new ArrayList<ParsedNetlistEntry>();
Pattern pattern = Pattern.compile(getItemRegex(), Pattern.MULTILINE | Pattern.DOTALL);
@@ -75,9 +77,15 @@ public abstract class AbstractNetlistParser implements INetlistParser {
}
Map<String, Object> valueMap = new HashMap<String, Object>();
List<Class<?>> typeCandidates = getComponentTypeCandidates(type, valueMap);
if (typeCandidates == null) {
outputWarnings.add("Type mappings not found for " + type + ".");
List<Class<?>> typeCandidates;
try {
typeCandidates = getComponentTypeCandidates(type, valueMap);
if (typeCandidates == null) {
outputWarnings.add("Type mappings not found for " + type + ".");
continue;
}
} catch (Exception e) {
outputWarnings.add("Error parsing type mappings for " + type + ".");
continue;
}
@@ -94,16 +102,17 @@ public abstract class AbstractNetlistParser implements INetlistParser {
result.add(new ParsedNetlistEntry(typeCandidates, type, valueMap));
}
Collections.sort(result, new Comparator<ParsedNetlistEntry>() {
@Override
public int compare(ParsedNetlistEntry o1, ParsedNetlistEntry o2) {
int comp = o1.getRawType().compareToIgnoreCase(o2.getRawType());
if (comp == 0 && o1.getValues().containsKey("Name") && o2.getValues().containsKey("Name"))
comp = o1.getValues().get("Name").toString().compareToIgnoreCase(o2.getValues().get("Name").toString());
comp = o1.getValues().get("Name").toString()
.compareToIgnoreCase(o2.getValues().get("Name").toString());
return comp;
}
}
});
return result;
@@ -113,6 +122,7 @@ public abstract class AbstractNetlistParser implements INetlistParser {
List<String> outputWarnings) {
double dx = 0;
double dy = 0;
int rowIdx = 0;
List<IDIYComponent<?>> result = new ArrayList<IDIYComponent<?>>();
for (int i = 0; i < components.size(); i++) {
ParsedNetlistComponent parsedComponent = components.get(i);
@@ -133,18 +143,21 @@ public abstract class AbstractNetlistParser implements INetlistParser {
Point2D controlPoint = new Point2D.Double(p.getX() + dx, p.getY() + dy);
component.setControlPoint(controlPoint, j);
}
if (i > 0 && i % ROW_COUNT == 0) {
if (rowIdx + 1 == ROW_COUNT) {
dx += X_OFFSET.convertToPixels();
dy = 0;
rowIdx = 0;
} else {
dy += Y_OFFSET.convertToPixels();
rowIdx++;
}
Method[] methods = clazz.getMethods();
for (Map.Entry<String, Object> value : parsedComponent.getValues().entrySet()) {
try {
Optional<Method> first = Arrays.stream(methods).filter(x -> x.getName().equals("set" + value.getKey())).findFirst();
Optional<Method> first = Arrays.stream(methods)
.filter(x -> x.getName().equals("set" + value.getKey())).findFirst();
if (first.isPresent()) {
Method setter = first.get();
setter.invoke(component, value.getValue());