mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
netlist parse improvements
This commit is contained in:
@@ -40,7 +40,7 @@ public class Voltage extends AbstractMeasure<VoltageUnit> {
|
|||||||
return new Voltage(value, unit);
|
return new Voltage(value, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Voltage parseCapacitance(String value) {
|
public static Voltage parseVoltage(String value) {
|
||||||
value = value.replace("*", "");
|
value = value.replace("*", "");
|
||||||
for (VoltageUnit unit : VoltageUnit.values()) {
|
for (VoltageUnit unit : VoltageUnit.values()) {
|
||||||
if (value.toLowerCase().endsWith(unit.toString().toLowerCase())) {
|
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 X_OFFSET = new Size(1.5d, SizeUnit.in);
|
||||||
private static Size Y_OFFSET = new Size(0.3d, 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;
|
String content;
|
||||||
try {
|
try {
|
||||||
content = new String(Files.readAllBytes(Paths.get(fileName)));
|
content = new String(Files.readAllBytes(Paths.get(fileName)));
|
||||||
@@ -55,7 +56,8 @@ public abstract class AbstractNetlistParser implements INetlistParser {
|
|||||||
return parse(content, outputWarnings);
|
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>();
|
List<ParsedNetlistEntry> result = new ArrayList<ParsedNetlistEntry>();
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile(getItemRegex(), Pattern.MULTILINE | Pattern.DOTALL);
|
Pattern pattern = Pattern.compile(getItemRegex(), Pattern.MULTILINE | Pattern.DOTALL);
|
||||||
@@ -75,11 +77,17 @@ public abstract class AbstractNetlistParser implements INetlistParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> valueMap = new HashMap<String, Object>();
|
Map<String, Object> valueMap = new HashMap<String, Object>();
|
||||||
List<Class<?>> typeCandidates = getComponentTypeCandidates(type, valueMap);
|
List<Class<?>> typeCandidates;
|
||||||
|
try {
|
||||||
|
typeCandidates = getComponentTypeCandidates(type, valueMap);
|
||||||
if (typeCandidates == null) {
|
if (typeCandidates == null) {
|
||||||
outputWarnings.add("Type mappings not found for " + type + ".");
|
outputWarnings.add("Type mappings not found for " + type + ".");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
outputWarnings.add("Error parsing type mappings for " + type + ".");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (String propertyName : getPropertyNames()) {
|
for (String propertyName : getPropertyNames()) {
|
||||||
String valueStr = matcher.group(propertyName).trim();
|
String valueStr = matcher.group(propertyName).trim();
|
||||||
@@ -101,7 +109,8 @@ public abstract class AbstractNetlistParser implements INetlistParser {
|
|||||||
public int compare(ParsedNetlistEntry o1, ParsedNetlistEntry o2) {
|
public int compare(ParsedNetlistEntry o1, ParsedNetlistEntry o2) {
|
||||||
int comp = o1.getRawType().compareToIgnoreCase(o2.getRawType());
|
int comp = o1.getRawType().compareToIgnoreCase(o2.getRawType());
|
||||||
if (comp == 0 && o1.getValues().containsKey("Name") && o2.getValues().containsKey("Name"))
|
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 comp;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -113,6 +122,7 @@ public abstract class AbstractNetlistParser implements INetlistParser {
|
|||||||
List<String> outputWarnings) {
|
List<String> outputWarnings) {
|
||||||
double dx = 0;
|
double dx = 0;
|
||||||
double dy = 0;
|
double dy = 0;
|
||||||
|
int rowIdx = 0;
|
||||||
List<IDIYComponent<?>> result = new ArrayList<IDIYComponent<?>>();
|
List<IDIYComponent<?>> result = new ArrayList<IDIYComponent<?>>();
|
||||||
for (int i = 0; i < components.size(); i++) {
|
for (int i = 0; i < components.size(); i++) {
|
||||||
ParsedNetlistComponent parsedComponent = components.get(i);
|
ParsedNetlistComponent parsedComponent = components.get(i);
|
||||||
@@ -134,17 +144,20 @@ public abstract class AbstractNetlistParser implements INetlistParser {
|
|||||||
component.setControlPoint(controlPoint, j);
|
component.setControlPoint(controlPoint, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > 0 && i % ROW_COUNT == 0) {
|
if (rowIdx + 1 == ROW_COUNT) {
|
||||||
dx += X_OFFSET.convertToPixels();
|
dx += X_OFFSET.convertToPixels();
|
||||||
dy = 0;
|
dy = 0;
|
||||||
|
rowIdx = 0;
|
||||||
} else {
|
} else {
|
||||||
dy += Y_OFFSET.convertToPixels();
|
dy += Y_OFFSET.convertToPixels();
|
||||||
|
rowIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Method[] methods = clazz.getMethods();
|
Method[] methods = clazz.getMethods();
|
||||||
for (Map.Entry<String, Object> value : parsedComponent.getValues().entrySet()) {
|
for (Map.Entry<String, Object> value : parsedComponent.getValues().entrySet()) {
|
||||||
try {
|
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()) {
|
if (first.isPresent()) {
|
||||||
Method setter = first.get();
|
Method setter = first.get();
|
||||||
setter.invoke(component, value.getValue());
|
setter.invoke(component, value.getValue());
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.diylc.components.passive.AxialElectrolyticCapacitor;
|
import org.diylc.components.passive.AxialElectrolyticCapacitor;
|
||||||
import org.diylc.components.passive.AxialFilmCapacitor;
|
import org.diylc.components.passive.AxialFilmCapacitor;
|
||||||
import org.diylc.components.passive.CapacitorSymbol;
|
import org.diylc.components.passive.CapacitorSymbol;
|
||||||
@@ -14,20 +15,28 @@ import org.diylc.components.passive.RadialElectrolytic;
|
|||||||
import org.diylc.components.passive.RadialFilmCapacitor;
|
import org.diylc.components.passive.RadialFilmCapacitor;
|
||||||
import org.diylc.components.passive.Resistor;
|
import org.diylc.components.passive.Resistor;
|
||||||
import org.diylc.components.passive.ResistorSymbol;
|
import org.diylc.components.passive.ResistorSymbol;
|
||||||
|
import org.diylc.components.semiconductors.BJTSymbol;
|
||||||
import org.diylc.components.semiconductors.DIL_IC;
|
import org.diylc.components.semiconductors.DIL_IC;
|
||||||
import org.diylc.components.semiconductors.DiodeGlass;
|
import org.diylc.components.semiconductors.DiodeGlass;
|
||||||
import org.diylc.components.semiconductors.DiodePlastic;
|
import org.diylc.components.semiconductors.DiodePlastic;
|
||||||
import org.diylc.components.semiconductors.DiodeSymbol;
|
import org.diylc.components.semiconductors.DiodeSymbol;
|
||||||
|
import org.diylc.components.semiconductors.JFETSymbol;
|
||||||
import org.diylc.components.semiconductors.LED;
|
import org.diylc.components.semiconductors.LED;
|
||||||
import org.diylc.components.semiconductors.LEDSymbol;
|
import org.diylc.components.semiconductors.LEDSymbol;
|
||||||
|
import org.diylc.components.semiconductors.MOSFETSymbol;
|
||||||
import org.diylc.components.semiconductors.PhotoDiodeSymbol;
|
import org.diylc.components.semiconductors.PhotoDiodeSymbol;
|
||||||
import org.diylc.components.semiconductors.SchottkyDiodeSymbol;
|
import org.diylc.components.semiconductors.SchottkyDiodeSymbol;
|
||||||
|
import org.diylc.components.semiconductors.TransistorTO220;
|
||||||
|
import org.diylc.components.semiconductors.TransistorTO92;
|
||||||
import org.diylc.components.semiconductors.ZenerDiodeSymbol;
|
import org.diylc.components.semiconductors.ZenerDiodeSymbol;
|
||||||
import org.diylc.core.measures.Capacitance;
|
import org.diylc.core.measures.Capacitance;
|
||||||
import org.diylc.core.measures.Resistance;
|
import org.diylc.core.measures.Resistance;
|
||||||
|
import org.diylc.core.measures.Voltage;
|
||||||
|
|
||||||
public class TangoNetlistParser extends AbstractNetlistParser {
|
public class TangoNetlistParser extends AbstractNetlistParser {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(TangoNetlistParser.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Tango";
|
return "Tango";
|
||||||
@@ -65,7 +74,20 @@ public class TangoNetlistParser extends AbstractNetlistParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type.toUpperCase().startsWith("CAP_ELECTRO")) {
|
if (type.toUpperCase().startsWith("CAP_ELECTRO")) {
|
||||||
additionalOutputs.put("Polarized", true);
|
boolean polarized = true;
|
||||||
|
if (type.toUpperCase().endsWith("_NP")) {
|
||||||
|
polarized = false;
|
||||||
|
type = type.substring(0, type.length() - 3);
|
||||||
|
}
|
||||||
|
if (type.length() > "CAP_ELECTRO".length()) {
|
||||||
|
String voltage = type.substring("CAP_ELECTRO".length() + 1) + "V";
|
||||||
|
try {
|
||||||
|
additionalOutputs.put("VoltageNew", Voltage.parseVoltage(voltage));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Error while parsing voltage " + voltage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
additionalOutputs.put("Polarized", polarized);
|
||||||
types.add(AxialElectrolyticCapacitor.class);
|
types.add(AxialElectrolyticCapacitor.class);
|
||||||
types.add(RadialElectrolytic.class);
|
types.add(RadialElectrolytic.class);
|
||||||
types.add(MultiSectionCapacitor.class);
|
types.add(MultiSectionCapacitor.class);
|
||||||
@@ -96,6 +118,20 @@ public class TangoNetlistParser extends AbstractNetlistParser {
|
|||||||
types.add(LEDSymbol.class);
|
types.add(LEDSymbol.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type.equalsIgnoreCase("TO92")) {
|
||||||
|
types.add(TransistorTO92.class);
|
||||||
|
types.add(BJTSymbol.class);
|
||||||
|
types.add(MOSFETSymbol.class);
|
||||||
|
types.add(JFETSymbol.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equalsIgnoreCase("TO220")) {
|
||||||
|
types.add(TransistorTO220.class);
|
||||||
|
types.add(BJTSymbol.class);
|
||||||
|
types.add(MOSFETSymbol.class);
|
||||||
|
types.add(JFETSymbol.class);
|
||||||
|
}
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<property name="jar.dir" value="${build.dir}/jar" />
|
<property name="jar.dir" value="${build.dir}/jar" />
|
||||||
<property name="report.dir" value="${build.dir}/junitreport" />
|
<property name="report.dir" value="${build.dir}/junitreport" />
|
||||||
<property name="main.class" value="org.diylc.DIYLCStarter" />
|
<property name="main.class" value="org.diylc.DIYLCStarter" />
|
||||||
<property name="diylc.version" value="4.14.0" />
|
<property name="diylc.version" value="4.15.0" />
|
||||||
|
|
||||||
<property name="osx.jre8.path" value="jre\osx\jdk8u275-b01-jre\Contents\Home\" />
|
<property name="osx.jre8.path" value="jre\osx\jdk8u275-b01-jre\Contents\Home\" />
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -524,7 +524,8 @@ public class ActionFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return LangUtil.translate("Netlist files");
|
List<String> ext = extensions.stream().map(ex -> "*." + ex).collect(Collectors.toList());
|
||||||
|
return LangUtil.translate("Netlist files") + " (" + String.join(",", ext) + ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -546,6 +547,8 @@ public class ActionFactory {
|
|||||||
LOG.debug("Importing netlist from " + file.getAbsolutePath());
|
LOG.debug("Importing netlist from " + file.getAbsolutePath());
|
||||||
List<String> outputWarnings = new ArrayList<String>();
|
List<String> outputWarnings = new ArrayList<String>();
|
||||||
List<ParsedNetlistEntry> entries = parser.parseFile(file.getAbsolutePath(), outputWarnings);
|
List<ParsedNetlistEntry> entries = parser.parseFile(file.getAbsolutePath(), outputWarnings);
|
||||||
|
if (!outputWarnings.isEmpty())
|
||||||
|
LOG.warn("Parsing produced warnings:\n" + String.join("\n", outputWarnings));
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -560,6 +563,8 @@ public class ActionFactory {
|
|||||||
List<ParsedNetlistComponent> parsedComponents = entries.stream().map(entry ->
|
List<ParsedNetlistComponent> parsedComponents = entries.stream().map(entry ->
|
||||||
new ParsedNetlistComponent(results.get(entry.getRawType()), entry.getValues())).collect(Collectors.toList());
|
new ParsedNetlistComponent(results.get(entry.getRawType()), entry.getValues())).collect(Collectors.toList());
|
||||||
List<IDIYComponent<?>> components = parser.generateComponents(parsedComponents, outputWarnings);
|
List<IDIYComponent<?>> components = parser.generateComponents(parsedComponents, outputWarnings);
|
||||||
|
if (!outputWarnings.isEmpty())
|
||||||
|
LOG.warn("Component creation produced warnings:\n" + String.join("\n", outputWarnings));
|
||||||
plugInPort.pasteComponents(components, false, false);
|
plugInPort.pasteComponents(components, false, false);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user