mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Fix blocks, add tests, fix bounding box calc of some components
This commit is contained in:
@@ -35,6 +35,11 @@ public interface INetlistAnalyzer {
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return summarizer short name
|
||||
*/
|
||||
String getShortName();
|
||||
|
||||
/**
|
||||
* @return name of the icon to use
|
||||
*/
|
||||
|
||||
@@ -26,13 +26,16 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class Netlist implements Comparable<Netlist> {
|
||||
|
||||
private List<IDIYComponent<?>> components;
|
||||
private Set<Group> groups = new HashSet<Group>();
|
||||
private List<SwitchSetup> switchSetup = new ArrayList<SwitchSetup>();
|
||||
|
||||
public Netlist() {
|
||||
public Netlist(List<IDIYComponent<?>> components) {
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
public Set<Group> getGroups() {
|
||||
@@ -44,6 +47,10 @@ public class Netlist implements Comparable<Netlist> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<IDIYComponent<?>> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
public List<Group> getSortedGroups() {
|
||||
List<Group> list = new ArrayList<Group>(groups);
|
||||
Collections.sort(list);
|
||||
|
||||
@@ -417,14 +417,6 @@ public abstract class NetlistAnalyzer {
|
||||
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())
|
||||
res.add(n.getComponent());
|
||||
return res;
|
||||
}
|
||||
|
||||
protected int find(Node node, List<Group> groups) {
|
||||
for (int i = 0; i < groups.size(); i++)
|
||||
if (groups.get(i).getNodes().contains(node))
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.TreeSet;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.measures.Size;
|
||||
|
||||
@@ -68,7 +67,7 @@ public class CalcUtils {
|
||||
}
|
||||
|
||||
public static void expandConnections(Set<Connection> connections) {
|
||||
Set<Connection> toAdd = new HashSet<Connection>();
|
||||
Set<Connection> toAdd = new TreeSet<Connection>();
|
||||
for (Connection c1 : connections)
|
||||
for (Connection c2 : connections) {
|
||||
if (c1 == c2)
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.awt.geom.Point2D;
|
||||
*
|
||||
* @author bancika
|
||||
*/
|
||||
public class Connection {
|
||||
public class Connection implements Comparable<Connection> {
|
||||
|
||||
private Point2D p1;
|
||||
private Point2D p2;
|
||||
@@ -72,4 +72,22 @@ public class Connection {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Connection o) {
|
||||
int compare = Double.compare(p1.getX(), o.p1.getX());
|
||||
if (compare != 0)
|
||||
return compare;
|
||||
compare = Double.compare(p1.getY(), o.p1.getY());
|
||||
if (compare != 0)
|
||||
return compare;
|
||||
compare = Double.compare(p2.getX(), o.p2.getX());
|
||||
if (compare != 0)
|
||||
return compare;
|
||||
compare = Double.compare(p2.getY(), o.p2.getY());
|
||||
if (compare != 0)
|
||||
return compare;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
l * DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
@@ -46,6 +46,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
@@ -213,8 +214,12 @@ public class Presenter implements IPlugInPort {
|
||||
private Point2D previousScaledPoint;
|
||||
|
||||
private DIYTest test = null;
|
||||
|
||||
|
||||
public Presenter(IView view, IConfigurationManager<?> configManager) {
|
||||
this(view, configManager, false);
|
||||
}
|
||||
|
||||
public Presenter(IView view, IConfigurationManager<?> configManager, boolean importVariantsAndBlocks) {
|
||||
super();
|
||||
this.view = view;
|
||||
this.configManager = configManager;
|
||||
@@ -230,9 +235,11 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// lockedLayers = EnumSet.noneOf(ComponentLayer.class);
|
||||
// visibleLayers = EnumSet.allOf(ComponentLayer.class);
|
||||
upgradeVariants();
|
||||
importDefaultVariants();
|
||||
importDefaultBlocks();
|
||||
if (importVariantsAndBlocks) {
|
||||
upgradeVariants();
|
||||
importDefaultVariants();
|
||||
importDefaultBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
public void installPlugin(Supplier<IPlugIn> plugInSupplier) {
|
||||
@@ -2596,7 +2603,7 @@ public class Presenter implements IPlugInPort {
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("variants.xml"));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
xStream.toXML(defaultVariantMap, out);
|
||||
ProjectFileManager.xStreamSerializer.toXML(defaultVariantMap, out);
|
||||
out.close();
|
||||
// no more user variants
|
||||
configManager.writeValue(TEMPLATES_KEY, null);
|
||||
@@ -2617,9 +2624,7 @@ public class Presenter implements IPlugInPort {
|
||||
URL resource = Presenter.class.getResource("variants.xml");
|
||||
if (resource != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(resource.openStream());
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
Map<String, List<Template>> defaults = (Map<String, List<Template>>) xStream.fromXML(in);
|
||||
Map<String, List<Template>> defaults = (Map<String, List<Template>>) ProjectFileManager.xStreamSerializer.fromXML(in);
|
||||
in.close();
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
@@ -2657,9 +2662,7 @@ public class Presenter implements IPlugInPort {
|
||||
URL resource = Presenter.class.getResource("blocks.xml");
|
||||
if (resource != null) {
|
||||
BufferedInputStream in = new BufferedInputStream(resource.openStream());
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
Map<String, List<IDIYComponent<?>>> defaults = (Map<String, List<IDIYComponent<?>>>) xStream.fromXML(in);
|
||||
Map<String, List<IDIYComponent<?>>> defaults = (Map<String, List<IDIYComponent<?>>>) ProjectFileManager.xStreamSerializer.fromXML(in);
|
||||
in.close();
|
||||
|
||||
Map<String, List<IDIYComponent<?>>> blocksMap =
|
||||
@@ -3020,20 +3023,9 @@ public class Presenter implements IPlugInPort {
|
||||
public int importVariants(String fileName) throws IOException {
|
||||
LOG.debug(String.format("importVariants(%s)", fileName));
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileName));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
|
||||
VariantPackage pkg;
|
||||
|
||||
try {
|
||||
// old way
|
||||
pkg = (VariantPackage) xStream.fromXML(in);
|
||||
} catch (Exception e) {
|
||||
// new way
|
||||
in = new BufferedInputStream(new FileInputStream(fileName));
|
||||
ProjectFileManager.configure(xStream);
|
||||
pkg = (VariantPackage) xStream.fromXML(in);
|
||||
}
|
||||
XStream xStream = projectFileManager.getXStream();
|
||||
|
||||
VariantPackage pkg = (VariantPackage) xStream.fromXML(in);
|
||||
|
||||
in.close();
|
||||
|
||||
@@ -3070,21 +3062,10 @@ public class Presenter implements IPlugInPort {
|
||||
public int importBlocks(String fileName) throws IOException {
|
||||
LOG.debug(String.format("importBlocks(%s)", fileName));
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileName));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
XStream xStream = projectFileManager.getXStream();
|
||||
|
||||
BuildingBlockPackage pkg;
|
||||
BuildingBlockPackage pkg = (BuildingBlockPackage) xStream.fromXML(in);
|
||||
|
||||
try {
|
||||
// old way
|
||||
pkg = (BuildingBlockPackage) xStream.fromXML(in);
|
||||
} catch (Exception e) {
|
||||
// new way
|
||||
in = new BufferedInputStream(new FileInputStream(fileName));
|
||||
ProjectFileManager.configure(xStream);
|
||||
pkg = (BuildingBlockPackage) xStream.fromXML(in);
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
if (pkg == null || pkg.getBlocks().isEmpty())
|
||||
@@ -3223,7 +3204,7 @@ public class Presenter implements IPlugInPort {
|
||||
posList.add(new Position(switches.get(j), positions[j]));
|
||||
}
|
||||
List<Connection> connections = getConnections(switchPositions);
|
||||
Netlist graph = constructNetlist(nodes, connections, continuity);
|
||||
Netlist graph = constructNetlist(nodes, connections, continuity, currentProject.getComponents());
|
||||
|
||||
// merge graphs that are effectively the same
|
||||
if (result.containsKey(graph)) {
|
||||
@@ -3255,8 +3236,8 @@ public class Presenter implements IPlugInPort {
|
||||
return netlists;
|
||||
}
|
||||
|
||||
private Netlist constructNetlist(List<Node> nodes, List<Connection> connections, List<Area> continuityAreas) {
|
||||
Netlist netlist = new Netlist();
|
||||
private Netlist constructNetlist(List<Node> nodes, List<Connection> connections, List<Area> continuityAreas, List<IDIYComponent<?>> components) {
|
||||
Netlist netlist = new Netlist(components);
|
||||
|
||||
// debugging code
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
@@ -3363,7 +3344,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings({"unchecked", "unlikely-arg-type"})
|
||||
private List<Connection> getConnections(Map<ISwitch, Integer> switchPositions) {
|
||||
Set<Connection> connections = new HashSet<Connection>();
|
||||
Set<Connection> connections = new TreeSet<Connection>();
|
||||
|
||||
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
||||
ComponentType type =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||
|
||||
@@ -1,385 +1,136 @@
|
||||
<map>
|
||||
<entry>
|
||||
<string>TO-92 w/ 2 Leads</string>
|
||||
<list>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J1</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>720</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>740</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>1320</x>
|
||||
<y>250</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../borderColor"/>
|
||||
<leadColor>
|
||||
<red>117</red>
|
||||
<green>157</green>
|
||||
<blue>175</blue>
|
||||
<alpha>255</alpha>
|
||||
</leadColor>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J2</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>780</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>760</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>-177</x>
|
||||
<y>1259</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../borderColor"/>
|
||||
<leadColor>
|
||||
<red>117</red>
|
||||
<green>157</green>
|
||||
<blue>175</blue>
|
||||
<alpha>255</alpha>
|
||||
</leadColor>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.semiconductors.TransistorTO92>
|
||||
<name>Q1</name>
|
||||
<alpha>100</alpha>
|
||||
<value></value>
|
||||
<orientation>DEFAULT</orientation>
|
||||
<controlPoints>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>740</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>750</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>760</y>
|
||||
</java.awt.Point>
|
||||
</controlPoints>
|
||||
<bodyColor>
|
||||
<red>128</red>
|
||||
<green>128</green>
|
||||
<blue>128</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>89</red>
|
||||
<green>89</green>
|
||||
<blue>89</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../../org.diylc.components.connectivity.Jumper/borderColor"/>
|
||||
<display>NAME</display>
|
||||
<folded>false</folded>
|
||||
<pinSpacing>
|
||||
<value>0.05</value>
|
||||
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
|
||||
</pinSpacing>
|
||||
</org.diylc.components.semiconductors.TransistorTO92>
|
||||
</list>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>TO-92 w/ 3 Leads</string>
|
||||
<list>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J1</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>720</x>
|
||||
<y>620</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>760</x>
|
||||
<y>640</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>650</x>
|
||||
<y>-41</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../borderColor"/>
|
||||
<leadColor>
|
||||
<red>117</red>
|
||||
<green>157</green>
|
||||
<blue>175</blue>
|
||||
<alpha>255</alpha>
|
||||
</leadColor>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J2</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>720</x>
|
||||
<y>680</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>760</x>
|
||||
<y>660</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>-206</x>
|
||||
<y>95</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../borderColor"/>
|
||||
<leadColor>
|
||||
<red>117</red>
|
||||
<green>157</green>
|
||||
<blue>175</blue>
|
||||
<alpha>255</alpha>
|
||||
</leadColor>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J3</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>719</x>
|
||||
<y>650</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>760</x>
|
||||
<y>650</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>147</x>
|
||||
<y>-279</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../borderColor"/>
|
||||
<leadColor>
|
||||
<red>117</red>
|
||||
<green>157</green>
|
||||
<blue>175</blue>
|
||||
<alpha>255</alpha>
|
||||
</leadColor>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.semiconductors.TransistorTO92>
|
||||
<name>Q1</name>
|
||||
<alpha>100</alpha>
|
||||
<value></value>
|
||||
<orientation>DEFAULT</orientation>
|
||||
<controlPoints>
|
||||
<java.awt.Point>
|
||||
<x>760</x>
|
||||
<y>640</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>760</x>
|
||||
<y>650</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>760</x>
|
||||
<y>660</y>
|
||||
</java.awt.Point>
|
||||
</controlPoints>
|
||||
<bodyColor>
|
||||
<red>128</red>
|
||||
<green>128</green>
|
||||
<blue>128</blue>
|
||||
<alpha>255</alpha>
|
||||
</bodyColor>
|
||||
<borderColor>
|
||||
<red>89</red>
|
||||
<green>89</green>
|
||||
<blue>89</blue>
|
||||
<alpha>255</alpha>
|
||||
</borderColor>
|
||||
<labelColor reference="../../org.diylc.components.connectivity.Jumper/borderColor"/>
|
||||
<display>NAME</display>
|
||||
<folded>false</folded>
|
||||
<pinSpacing>
|
||||
<value>0.05</value>
|
||||
<unit class="org.diylc.core.measures.SizeUnit">in</unit>
|
||||
</pinSpacing>
|
||||
</org.diylc.components.semiconductors.TransistorTO92>
|
||||
</list>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>TO-92 w/ 2 Leads</string>
|
||||
<list>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J1</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>720</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>740</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>1320</x>
|
||||
<y>250</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper/bodyColor"/>
|
||||
<borderColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper/borderColor"/>
|
||||
<labelColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper/borderColor"/>
|
||||
<leadColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper/leadColor"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.connectivity.Jumper>
|
||||
<name>J2</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>780</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>760</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>-177</x>
|
||||
<y>1259</y>
|
||||
</java.awt.Point>
|
||||
</points>
|
||||
<bodyColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper[2]/bodyColor"/>
|
||||
<borderColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper[2]/borderColor"/>
|
||||
<labelColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper[2]/borderColor"/>
|
||||
<leadColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper[2]/leadColor"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</org.diylc.components.connectivity.Jumper>
|
||||
<org.diylc.components.semiconductors.TransistorTO92>
|
||||
<name>Q1</name>
|
||||
<alpha>100</alpha>
|
||||
<value></value>
|
||||
<orientation>DEFAULT</orientation>
|
||||
<controlPoints>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>740</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>750</y>
|
||||
</java.awt.Point>
|
||||
<java.awt.Point>
|
||||
<x>580</x>
|
||||
<y>760</y>
|
||||
</java.awt.Point>
|
||||
</controlPoints>
|
||||
<bodyColor reference="../../../../entry/list/org.diylc.components.semiconductors.TransistorTO92/bodyColor"/>
|
||||
<borderColor reference="../../../../entry/list/org.diylc.components.semiconductors.TransistorTO92/borderColor"/>
|
||||
<labelColor reference="../../../../entry/list/org.diylc.components.connectivity.Jumper/borderColor"/>
|
||||
<display>NAME</display>
|
||||
<folded>false</folded>
|
||||
<pinSpacing reference="../../../../entry/list/org.diylc.components.semiconductors.TransistorTO92/pinSpacing"/>
|
||||
</org.diylc.components.semiconductors.TransistorTO92>
|
||||
</list>
|
||||
</entry>
|
||||
</map>
|
||||
<entry>
|
||||
<string>TO-92 w/ 3 Leads</string>
|
||||
<list>
|
||||
<diylc.connectivity.Jumper>
|
||||
<name>J1</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<point x="3.6" y="3.1"/>
|
||||
<point x="3.8" y="3.2"/>
|
||||
<point x="3.25" y="-0.205"/>
|
||||
</points>
|
||||
<bodyColor hex="ffffff"/>
|
||||
<borderColor hex="000000"/>
|
||||
<labelColor hex="000000"/>
|
||||
<leadColor hex="759daf"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</diylc.connectivity.Jumper>
|
||||
<diylc.connectivity.Jumper>
|
||||
<name>J2</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<point x="3.6" y="3.4"/>
|
||||
<point x="3.8" y="3.3"/>
|
||||
<point x="-1.03" y="0.475"/>
|
||||
</points>
|
||||
<bodyColor hex="ffffff"/>
|
||||
<borderColor hex="000000"/>
|
||||
<labelColor hex="000000"/>
|
||||
<leadColor hex="759daf"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</diylc.connectivity.Jumper>
|
||||
<diylc.connectivity.Jumper>
|
||||
<name>J3</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<point x="3.595" y="3.25"/>
|
||||
<point x="3.8" y="3.25"/>
|
||||
<point x="0.735" y="-1.395"/>
|
||||
</points>
|
||||
<bodyColor hex="ffffff"/>
|
||||
<borderColor hex="000000"/>
|
||||
<labelColor hex="000000"/>
|
||||
<leadColor hex="759daf"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</diylc.connectivity.Jumper>
|
||||
<diylc.semiconductors.TransistorTO92>
|
||||
<name>Q1</name>
|
||||
<alpha>100</alpha>
|
||||
<value></value>
|
||||
<orientation>DEFAULT</orientation>
|
||||
<controlPoints>
|
||||
<point x="3.8" y="3.2"/>
|
||||
<point x="3.8" y="3.25"/>
|
||||
<point x="3.8" y="3.3"/>
|
||||
</controlPoints>
|
||||
<bodyColor hex="808080"/>
|
||||
<borderColor hex="595959"/>
|
||||
<labelColor hex="000000"/>
|
||||
<display>NAME</display>
|
||||
<folded>false</folded>
|
||||
<pinSpacing value="0.05" unit="in"/>
|
||||
</diylc.semiconductors.TransistorTO92>
|
||||
</list>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>TO-92 w/ 2 Leads</string>
|
||||
<list>
|
||||
<diylc.connectivity.Jumper>
|
||||
<name>J1</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<point x="2.9" y="3.6"/>
|
||||
<point x="2.9" y="3.7"/>
|
||||
<point x="6.6" y="1.25"/>
|
||||
</points>
|
||||
<bodyColor hex="ffffff"/>
|
||||
<borderColor hex="000000"/>
|
||||
<labelColor hex="000000"/>
|
||||
<leadColor hex="759daf"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</diylc.connectivity.Jumper>
|
||||
<diylc.connectivity.Jumper>
|
||||
<name>J2</name>
|
||||
<alpha>127</alpha>
|
||||
<points>
|
||||
<point x="2.9" y="3.9"/>
|
||||
<point x="2.9" y="3.8"/>
|
||||
<point x="-0.885" y="6.295"/>
|
||||
</points>
|
||||
<bodyColor hex="ffffff"/>
|
||||
<borderColor hex="000000"/>
|
||||
<labelColor hex="000000"/>
|
||||
<leadColor hex="759daf"/>
|
||||
<display>NAME</display>
|
||||
<flipStanding>false</flipStanding>
|
||||
<labelOriantation>Directional</labelOriantation>
|
||||
<moveLabel>false</moveLabel>
|
||||
<style>SOLID</style>
|
||||
</diylc.connectivity.Jumper>
|
||||
<diylc.semiconductors.TransistorTO92>
|
||||
<name>Q1</name>
|
||||
<alpha>100</alpha>
|
||||
<value></value>
|
||||
<orientation>DEFAULT</orientation>
|
||||
<controlPoints>
|
||||
<point x="2.9" y="3.7"/>
|
||||
<point x="2.9" y="3.75"/>
|
||||
<point x="2.9" y="3.8"/>
|
||||
</controlPoints>
|
||||
<bodyColor hex="808080"/>
|
||||
<borderColor hex="595959"/>
|
||||
<labelColor hex="000000"/>
|
||||
<display>NAME</display>
|
||||
<folded>false</folded>
|
||||
<pinSpacing value="0.05" unit="in"/>
|
||||
</diylc.semiconductors.TransistorTO92>
|
||||
</list>
|
||||
</entry>
|
||||
</map>
|
||||
@@ -3781,5 +3781,25 @@
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
<org.diylc.appframework.update.Version>
|
||||
<versionNumber>
|
||||
<major>4</major>
|
||||
<minor>22</minor>
|
||||
<build>2</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2022-03-18 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Fixed the issue with application hanging when loading certain files</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Fixed importing building blocks and variants from a file</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
</a>
|
||||
</java.util.Arrays_-ArrayList>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -67,7 +67,13 @@ public class ProjectFileManager {
|
||||
private XStream xStream;
|
||||
// Legacy deserializer for 3.0.1 through 3.0.7, loads Points referenced in
|
||||
// pixels.
|
||||
private XStream xStreamOld;
|
||||
private XStream xStreamOld;
|
||||
|
||||
public static final XStream xStreamSerializer = new XStream(new DomDriver("UTF-8"));
|
||||
|
||||
static {
|
||||
configure(xStreamSerializer);
|
||||
}
|
||||
|
||||
private String currentFileName = null;
|
||||
private boolean modified = false;
|
||||
@@ -100,7 +106,7 @@ public class ProjectFileManager {
|
||||
configure(xStream);
|
||||
this.xStreamOld = new XStream(new DomDriver());
|
||||
this.xStreamOld.addPermission(AnyTypePermission.ANY);
|
||||
xStreamOld.autodetectAnnotations(true);
|
||||
this.xStreamOld.autodetectAnnotations(true);
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
}
|
||||
|
||||
@@ -109,25 +115,23 @@ public class ProjectFileManager {
|
||||
xStream.alias("point", java.awt.geom.Point2D.class);
|
||||
xStream.alias("point", java.awt.geom.Point2D.Double.class);
|
||||
xStream.alias("font", java.awt.Font.class);
|
||||
// TODO figure out why I commented this out
|
||||
// xStream.alias("color", java.awt.Color.class);
|
||||
xStream.alias("project", Project.class);
|
||||
xStream.aliasPackage("diylc", "org.diylc.components");
|
||||
xStream.registerConverter(new PointConverter());
|
||||
xStream.registerConverter(new ColorConverter());
|
||||
xStream.registerConverter(new FontConverter());
|
||||
xStream.registerConverter(new MeasureConverter());
|
||||
xStream.registerConverter(new AreaConverter());
|
||||
xStream.addImmutableType(Color.class);
|
||||
xStream.addImmutableType(java.awt.geom.Point2D.class);
|
||||
xStream.addImmutableType(java.awt.geom.Point2D.Double.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Voltage.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Resistance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Capacitance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Current.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Power.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Inductance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Size.class);
|
||||
xStream.registerConverter(new AreaConverter());
|
||||
xStream.addImmutableType(Color.class, true);
|
||||
xStream.addImmutableType(java.awt.geom.Point2D.class, true);
|
||||
xStream.addImmutableType(java.awt.geom.Point2D.Double.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Voltage.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Resistance.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Capacitance.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Current.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Power.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Inductance.class, true);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Size.class, true);
|
||||
xStream.addPermission(AnyTypePermission.ANY);
|
||||
}
|
||||
|
||||
@@ -303,6 +307,9 @@ public class ProjectFileManager {
|
||||
int build = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||
|
||||
return new VersionNumber(major, minor, build);
|
||||
|
||||
}
|
||||
|
||||
public XStream getXStream() {
|
||||
return xStream;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -3,7 +3,7 @@ package org.diylc.components;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -33,4 +33,28 @@ public abstract class AbstractMultiPartComponent<T> extends AbstractLabeledCompo
|
||||
outline.add((Area)b);
|
||||
return outline;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Shape[] body = getBody();
|
||||
int margin = 20;
|
||||
double minX = 0;
|
||||
double minY = 0;
|
||||
double maxX = 0;
|
||||
double maxY = 0;
|
||||
for (Shape a : body) {
|
||||
if (a != null) {
|
||||
Rectangle2D bounds2d = a.getBounds2D();
|
||||
if (bounds2d.getMinX() < minX)
|
||||
minX = bounds2d.getMinX();
|
||||
if (bounds2d.getMinY() < minY)
|
||||
minY = bounds2d.getMinY();
|
||||
if (bounds2d.getMaxX() > maxX)
|
||||
maxX = bounds2d.getMaxX();
|
||||
if (bounds2d.getMaxY() > maxY)
|
||||
maxY = bounds2d.getMaxY();
|
||||
}
|
||||
}
|
||||
return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin, maxY - minY + 2 * margin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,17 +351,5 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Area[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Area a : body)
|
||||
if (a != null)
|
||||
area.add(a);
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,17 +375,5 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Shape[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Shape a : body)
|
||||
if (a != null)
|
||||
area.add(new Area(a));
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,19 +376,7 @@ public class NeutrikJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Area[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Area a : body)
|
||||
if (a != null)
|
||||
area.add(a);
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
|
||||
enum Mount {
|
||||
PCB, Panel
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
@@ -425,18 +423,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Area[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Area a : body)
|
||||
if (a != null)
|
||||
area.add(a);
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
public enum OpenJackType {
|
||||
|
||||
MONO, STEREO, SWITCHED;
|
||||
|
||||
@@ -31,9 +31,7 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
@@ -425,18 +423,6 @@ public class OpenJack1_8 extends AbstractMultiPartComponent<String> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Area[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Area a : body)
|
||||
if (a != null)
|
||||
area.add(a);
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
public enum OpenJackType {
|
||||
|
||||
MONO, STEREO, SWITCHED;
|
||||
|
||||
@@ -411,17 +411,5 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
|
||||
protected double getTheta() {
|
||||
return Math.toRadians(getAngle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Area[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Area a : body)
|
||||
if (a != null)
|
||||
area.add(a);
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
}
|
||||
|
||||
-14
@@ -363,20 +363,6 @@ public class RotarySelectorSwitch extends AbstractMultiPartComponent<String> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Area area = new Area();
|
||||
Area[] body = getBody();
|
||||
int margin = 20;
|
||||
for (Area a : body)
|
||||
if (a != null)
|
||||
area.add(a);
|
||||
Rectangle2D bounds = area.getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin,
|
||||
bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
|
||||
public static enum RotaryPositionCount {
|
||||
TWO(2), THREE(3), FOUR(4);
|
||||
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
*
|
||||
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
*
|
||||
* This file is part of DIYLC.
|
||||
*
|
||||
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
@@ -47,7 +45,7 @@ import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.netlist.Tree.ITreeWalker;
|
||||
|
||||
public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
|
||||
|
||||
private static Set<String> JACK_TYPES = new HashSet<String>();
|
||||
private static Set<String> POT_TYPES = new HashSet<String>();
|
||||
private static Set<String> PICKUP_TYPES = new HashSet<String>();
|
||||
@@ -55,84 +53,92 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
static {
|
||||
JACK_TYPES.add(OpenJack1_4.class.getCanonicalName());
|
||||
JACK_TYPES.add(ClosedJack1_4.class.getCanonicalName());
|
||||
|
||||
|
||||
POT_TYPES.add(PotentiometerPanel.class.getCanonicalName());
|
||||
|
||||
|
||||
PICKUP_TYPES.add(SingleCoilPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(HumbuckerPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(P90Pickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(JazzBassPickup.class.getCanonicalName());
|
||||
PICKUP_TYPES.add(PBassPickup.class.getCanonicalName());
|
||||
|
||||
|
||||
CAP_TYPES.add(RadialCeramicDiskCapacitor.class.getCanonicalName());
|
||||
CAP_TYPES.add(RadialFilmCapacitor.class.getCanonicalName());
|
||||
CAP_TYPES.add(AxialFilmCapacitor.class.getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String getName() {
|
||||
return "Analyze Guitar Diagrams";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return "guitar-diagrams";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
return "Guitar";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getFontName() {
|
||||
public String getFontName() {
|
||||
return new JLabel().getFont().getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private int positiveCount;
|
||||
private int negativeCount;
|
||||
private int noiseCount;
|
||||
|
||||
|
||||
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
|
||||
Tree tree = constructTree(netlist);
|
||||
|
||||
|
||||
Tree pickupTree = tree.filter(PICKUP_TYPES);
|
||||
|
||||
|
||||
if (pickupTree == null || pickupTree.getChildren().isEmpty()) {
|
||||
notes.add("No pickups are detected in this switch configuration");
|
||||
} else {
|
||||
positiveCount = 0;
|
||||
negativeCount = 0;
|
||||
noiseCount = 0;
|
||||
|
||||
|
||||
// analyze hum-cancellation and phase
|
||||
pickupTree.walk(new ITreeWalker() {
|
||||
|
||||
@Override
|
||||
public void visit(Tree t) {
|
||||
}
|
||||
public void visit(Tree t) {}
|
||||
|
||||
@Override
|
||||
public void visit(TreeLeaf l) {
|
||||
if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("->"))) ||
|
||||
(l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("<-"))))
|
||||
if ((l.toString().toLowerCase().contains("north")
|
||||
&& (l.toString().toLowerCase().contains("->")))
|
||||
|| (l.toString().toLowerCase().contains("south")
|
||||
&& (l.toString().toLowerCase().contains("<-"))))
|
||||
noiseCount++;
|
||||
if ((l.toString().toLowerCase().contains("north") && (l.toString().toLowerCase().contains("<-"))) ||
|
||||
(l.toString().toLowerCase().contains("south") && (l.toString().toLowerCase().contains("->"))))
|
||||
if ((l.toString().toLowerCase().contains("north")
|
||||
&& (l.toString().toLowerCase().contains("<-")))
|
||||
|| (l.toString().toLowerCase().contains("south")
|
||||
&& (l.toString().toLowerCase().contains("->"))))
|
||||
noiseCount--;
|
||||
|
||||
|
||||
if (l.toString().toLowerCase().contains("->"))
|
||||
positiveCount++;
|
||||
if (l.toString().toLowerCase().contains("<-"))
|
||||
negativeCount++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Set<IDIYComponent<?>> pickups = tree.extractComponents(PICKUP_TYPES);
|
||||
Map<IDIYComponent<?>, Tree> pickupRoots = new HashMap<IDIYComponent<?>, Tree>();
|
||||
|
||||
|
||||
// analyze each pickup separately to see how each coil is wired
|
||||
for (IDIYComponent<?> c : pickups) {
|
||||
if (c instanceof AbstractGuitarPickup) {
|
||||
AbstractGuitarPickup pickup = (AbstractGuitarPickup)c;
|
||||
AbstractGuitarPickup pickup = (AbstractGuitarPickup) c;
|
||||
if (((AbstractGuitarPickup) c).isHumbucker()) {
|
||||
TreeLeaf nLeaf = new TreeLeaf(pickup, 0, 1);
|
||||
TreeLeaf sLeaf = new TreeLeaf(pickup, 2, 3);
|
||||
@@ -141,8 +147,9 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
Tree parent = tree.findCommonParent(nTree, sTree);
|
||||
if (parent != null)
|
||||
pickupRoots.put(pickup, parent);
|
||||
if (nTree != null && sTree != null && parent != null) {
|
||||
notes.add("'" + pickup.getName() + "' pickup wired in humbucking mode with " + parent.getConnectionType().name().toLowerCase() + " coils");
|
||||
if (nTree != null && sTree != null && parent != null) {
|
||||
notes.add("'" + pickup.getName() + "' pickup wired in humbucking mode with "
|
||||
+ parent.getConnectionType().name().toLowerCase() + " coils");
|
||||
} else if ((nTree == null && sTree != null) || (nTree != null && sTree == null)) {
|
||||
notes.add("'" + pickup.getName() + "' pickup wired in coil-split mode");
|
||||
}
|
||||
@@ -154,53 +161,59 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// figure out how pickups are wired between them
|
||||
if (pickupRoots.size() > 1) {
|
||||
Tree root = tree.findCommonParent(new ArrayList<Tree>(pickupRoots.values()));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
boolean first = true;
|
||||
for (IDIYComponent<?> c : pickupRoots.keySet()) {
|
||||
if (!first)
|
||||
sb.append(pickupRoots.size() == 2 ? " and " : ", ");
|
||||
first = false;
|
||||
sb.append("'").append(c.getName()).append("'");
|
||||
}
|
||||
sb.append(" pickups engaged, wired in " ).append(root.getConnectionType().name().toLowerCase());
|
||||
sb.append(" pickups engaged, wired in ")
|
||||
.append(root.getConnectionType().name().toLowerCase());
|
||||
notes.add(sb.toString());
|
||||
} else if (pickupRoots.size() == 1) {
|
||||
AbstractGuitarPickup pickup = (AbstractGuitarPickup) pickupRoots.keySet().iterator().next();
|
||||
notes.add("'" + pickup.getName() + "' is the only engaged pickup");
|
||||
}
|
||||
|
||||
|
||||
boolean humCancelling = noiseCount == 0;
|
||||
|
||||
|
||||
if (humCancelling)
|
||||
notes.add("This configuration is hum-cancelling");
|
||||
else
|
||||
notes.add("This configuration is NOT hum-cancelling");
|
||||
|
||||
|
||||
if (positiveCount > 1 || negativeCount > 1 || (positiveCount == 1 && negativeCount == 1)) {
|
||||
boolean inPhase = (positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
|
||||
boolean inPhase =
|
||||
(positiveCount == 0 && negativeCount > 0) || (positiveCount > 0 && negativeCount == 0);
|
||||
if (inPhase)
|
||||
notes.add("All pickup coils are wired in-phase");
|
||||
else
|
||||
notes.add("Some pickup coils are wired OUT-of-phase");
|
||||
notes.add("Some pickup coils are wired OUT-of-phase");
|
||||
}
|
||||
|
||||
|
||||
// locate volume and tone pots
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupReverseMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupReverseMap = new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupMap =
|
||||
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupMap =
|
||||
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> tonePotPickupReverseMap =
|
||||
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
Map<IDIYComponent<?>, List<IDIYComponent<?>>> volPotPickupReverseMap =
|
||||
new HashMap<IDIYComponent<?>, List<IDIYComponent<?>>>();
|
||||
|
||||
Set<IDIYComponent<?>> pots = tree.extractComponents(POT_TYPES);
|
||||
for (IDIYComponent<?> pot : pots) {
|
||||
TreeLeaf leaf1 = new TreeLeaf(pot, 0, 1);
|
||||
TreeLeaf leaf2 = new TreeLeaf(pot, 1, 2);
|
||||
Tree tree1 = tree.locate(leaf1, false);
|
||||
Tree tree2 = tree.locate(leaf2, false);
|
||||
|
||||
|
||||
if ((tree1 == null && tree2 != null) || (tree1 != null && tree2 == null)) {
|
||||
boolean tonePotReversed = tree1 != null;
|
||||
Tree t = tree1 == null ? tree2 : tree1;
|
||||
@@ -210,7 +223,8 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
if (caps != null && caps.size() == 1) {
|
||||
for (Map.Entry<IDIYComponent<?>, Tree> r : pickupRoots.entrySet()) {
|
||||
Tree toneParent = tree.findCommonParent(p, r.getValue());
|
||||
if (toneParent != null && toneParent.getConnectionType() == TreeConnectionType.Parallel) {
|
||||
if (toneParent != null
|
||||
&& toneParent.getConnectionType() == TreeConnectionType.Parallel) {
|
||||
if (tonePotReversed) {
|
||||
List<IDIYComponent<?>> pickupList = tonePotPickupReverseMap.get(pot);
|
||||
if (pickupList == null) {
|
||||
@@ -231,23 +245,25 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// volume
|
||||
if (tree1 == null || tree2 == null)
|
||||
continue;
|
||||
for (Map.Entry<IDIYComponent<?>, Tree> r : pickupRoots.entrySet()) {
|
||||
Tree parent1 = tree.findCommonParent(tree1, r.getValue());
|
||||
Tree parent2 = tree.findCommonParent(tree2, r.getValue());
|
||||
if (parent1 != null && parent2 != null && parent1.getConnectionType() == TreeConnectionType.Series && parent2.getConnectionType() == TreeConnectionType.Parallel)
|
||||
{
|
||||
if (parent1 != null && parent2 != null
|
||||
&& parent1.getConnectionType() == TreeConnectionType.Series
|
||||
&& parent2.getConnectionType() == TreeConnectionType.Parallel) {
|
||||
List<IDIYComponent<?>> pickupList = volPotPickupMap.get(pot);
|
||||
if (pickupList == null) {
|
||||
pickupList = new ArrayList<IDIYComponent<?>>();
|
||||
volPotPickupMap.put(pot, pickupList);
|
||||
}
|
||||
pickupList.add(r.getKey());
|
||||
} else if (parent1 != null && parent2 != null && parent1.getConnectionType() == TreeConnectionType.Parallel && parent2.getConnectionType() == TreeConnectionType.Series)
|
||||
{
|
||||
} else if (parent1 != null && parent2 != null
|
||||
&& parent1.getConnectionType() == TreeConnectionType.Parallel
|
||||
&& parent2.getConnectionType() == TreeConnectionType.Series) {
|
||||
List<IDIYComponent<?>> pickupList = volPotPickupReverseMap.get(pot);
|
||||
if (pickupList == null) {
|
||||
pickupList = new ArrayList<IDIYComponent<?>>();
|
||||
@@ -257,81 +273,97 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupMap.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
|
||||
boolean first = true;
|
||||
for (IDIYComponent<?> c : e.getValue()) {
|
||||
StringBuilder sb = new StringBuilder(
|
||||
"'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
|
||||
boolean first = true;
|
||||
List<String> pickupNames =
|
||||
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
|
||||
for (String pickupName : pickupNames) {
|
||||
if (!first)
|
||||
sb.append(e.getValue().size() == 2 ? " and " : ", ");
|
||||
sb.append(pickupNames.size() == 2 ? " and " : ", ");
|
||||
first = false;
|
||||
sb.append("'").append(c.getName()).append("'");
|
||||
sb.append("'").append(pickupName).append("'");
|
||||
}
|
||||
notes.add(sb.toString());
|
||||
notes.add(sb.toString());
|
||||
}
|
||||
|
||||
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupReverseMap.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
|
||||
boolean first = true;
|
||||
for (IDIYComponent<?> c : e.getValue()) {
|
||||
|
||||
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : volPotPickupReverseMap
|
||||
.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder(
|
||||
"'" + e.getKey().getName() + "' potentiometer acts as a volume control for ");
|
||||
boolean first = true;
|
||||
List<String> pickupNames =
|
||||
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
|
||||
for (String pickupName : pickupNames) {
|
||||
if (!first)
|
||||
sb.append(e.getValue().size() == 2 ? " and " : ", ");
|
||||
sb.append(pickupNames.size() == 2 ? " and " : ", ");
|
||||
first = false;
|
||||
sb.append("'").append(c.getName()).append("'");
|
||||
sb.append("'").append(pickupName).append("'");
|
||||
}
|
||||
sb.append(", but is wired in REVERSE!");
|
||||
notes.add(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupMap.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
|
||||
boolean first = true;
|
||||
for (IDIYComponent<?> c : e.getValue()) {
|
||||
StringBuilder sb = new StringBuilder(
|
||||
"'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
|
||||
boolean first = true;
|
||||
List<String> pickupNames =
|
||||
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
|
||||
for (String pickupName : pickupNames) {
|
||||
if (!first)
|
||||
sb.append(e.getValue().size() == 2 ? " and " : ", ");
|
||||
sb.append(pickupNames.size() == 2 ? " and " : ", ");
|
||||
first = false;
|
||||
sb.append("'").append(c.getName()).append("'");
|
||||
sb.append("'").append(pickupName).append("'");
|
||||
}
|
||||
notes.add(sb.toString());
|
||||
notes.add(sb.toString());
|
||||
}
|
||||
|
||||
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupReverseMap.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder("'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
|
||||
boolean first = true;
|
||||
for (IDIYComponent<?> c : e.getValue()) {
|
||||
|
||||
for (Map.Entry<IDIYComponent<?>, List<IDIYComponent<?>>> e : tonePotPickupReverseMap
|
||||
.entrySet()) {
|
||||
StringBuilder sb = new StringBuilder(
|
||||
"'" + e.getKey().getName() + "' potentiometer acts as a tone control for ");
|
||||
boolean first = true;
|
||||
List<String> pickupNames =
|
||||
e.getValue().stream().map(x -> x.getName()).sorted().collect(Collectors.toList());
|
||||
for (String pickupName : pickupNames) {
|
||||
if (!first)
|
||||
sb.append(e.getValue().size() == 2 ? " and " : ", ");
|
||||
sb.append(pickupNames.size() == 2 ? " and " : ", ");
|
||||
first = false;
|
||||
sb.append("'").append(c.getName()).append("'");
|
||||
sb.append("'").append(pickupName).append("'");
|
||||
}
|
||||
sb.append(", but is wired in REVERSE!");
|
||||
notes.add(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
sb.append("Parallel/Series connectivity tree:<br><br>").append(tree.toHTML(0));
|
||||
if (!notes.isEmpty())
|
||||
if (!notes.isEmpty()) {
|
||||
Collections.sort(notes);
|
||||
sb.append("<br><br>Notes:<br>");
|
||||
for (String v : notes) {
|
||||
sb.append(" ").append(v).append("<br>");
|
||||
for (String v : notes) {
|
||||
sb.append(" ").append(v).append("<br>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new Summary(netlist, sb.toString());
|
||||
}
|
||||
|
||||
|
||||
public Tree constructTree(Netlist netlist) throws TreeException {
|
||||
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
|
||||
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
|
||||
|
||||
|
||||
if (jackTipNodes.size() == 0 || jackSleeveNodes.size() == 0) {
|
||||
throw new TreeException("Could not find anything connected to a jack tip terminal.");
|
||||
} else if (jackTipNodes.size() > 1 || jackSleeveNodes.size() > 1) {
|
||||
throw new TreeException("Multiple jacks found, could not proceed.");
|
||||
} else {
|
||||
} else {
|
||||
Node jackTip = jackTipNodes.get(0);
|
||||
Node jackSleeve = jackSleeveNodes.get(0);
|
||||
Node jackSleeve = jackSleeveNodes.get(0);
|
||||
return constructTreeBetween(netlist, jackTip, jackSleeve);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
@@ -38,6 +38,11 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
public String getName() {
|
||||
return "Generate Spice Netlist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortName() {
|
||||
return "spice";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
@@ -51,16 +56,7 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
|
||||
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||
// grab all components that are in the netlist
|
||||
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(extractComponents(netlist));
|
||||
Collections.sort(allComponents, new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<IDIYComponent<?>> allComponents = netlist.getComponents();
|
||||
|
||||
List<Group> groups = netlist.getSortedGroups();
|
||||
int unconnectedIndex = groups.size();
|
||||
@@ -71,7 +67,10 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
maxLen = c.getName().length();
|
||||
}
|
||||
|
||||
for (IDIYComponent<?> c : allComponents) {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
for (IDIYComponent<?> c : allComponents) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// change the prefix to match spice convention if needed
|
||||
String name = c.getName();
|
||||
String prefix = null;
|
||||
@@ -90,18 +89,18 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
if (c.getControlPointNodeName(i) == null)
|
||||
continue;
|
||||
|
||||
int pointIndex = i;
|
||||
int pointIndex = i;
|
||||
|
||||
// remap if needed
|
||||
if (c instanceof ISpiceMapper)
|
||||
pointIndex = ((ISpiceMapper)c).mapToSpiceNode(pointIndex);
|
||||
|
||||
int nodeIndex = find(new Node(c, pointIndex), groups);
|
||||
if (nodeIndex < 0)
|
||||
nodeIndex = unconnectedIndex++;
|
||||
|
||||
// 1-based convention
|
||||
nodeIndex++;
|
||||
|
||||
// remap if needed
|
||||
if (c instanceof ISpiceMapper)
|
||||
pointIndex = ((ISpiceMapper)c).mapToSpiceNode(pointIndex);
|
||||
nodeIndex++;
|
||||
|
||||
nodeIndices.add(nodeIndex);
|
||||
}
|
||||
@@ -120,9 +119,13 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
|
||||
sb.append(" ; ").append(comment);
|
||||
}
|
||||
sb.append("<br>");
|
||||
lines.add(sb.toString());
|
||||
}
|
||||
|
||||
return new Summary(netlist, sb.toString());
|
||||
return new Summary(netlist, lines
|
||||
.stream()
|
||||
.sorted()
|
||||
.collect(Collectors.joining("\n")));
|
||||
}
|
||||
|
||||
private static String formatSpiceNode(int i) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
OpenJack1_4 jack = new OpenJack1_4();
|
||||
SingleCoilPickup pickup = new SingleCoilPickup();
|
||||
pickup.setName("Pickup");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 1);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2);
|
||||
netlist.add(tipGroup).add(sleeveGroup);
|
||||
@@ -59,7 +59,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
pickup.setName("Pickup");
|
||||
PotentiometerPanel vol = new PotentiometerPanel();
|
||||
vol.setName("Volume");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup, vol));
|
||||
Group hotGroup = new Group().connect(pickup, 1).connect(vol, 0);
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2).connect(vol, 2);
|
||||
@@ -80,7 +80,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
tone.setName("Tone");
|
||||
RadialCeramicDiskCapacitor cap = new RadialCeramicDiskCapacitor();
|
||||
cap.setName("Cap");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup, vol, tone, cap));
|
||||
Group hotGroup = new Group().connect(pickup, 1).connect(vol, 0).connect(tone, 2);
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2).connect(vol, 2).connect(cap, 0);
|
||||
@@ -108,7 +108,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
cap1.setName("Cap1");
|
||||
RadialCeramicDiskCapacitor cap2 = new RadialCeramicDiskCapacitor();
|
||||
cap2.setName("Cap2");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
|
||||
Group hotGroup = new Group().connect(pickup1, 1).connect(vol, 0).connect(tone1, 2).connect(pickup2, 1).connect(tone2, 2);
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 2).connect(pickup2, 2).connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
|
||||
@@ -125,7 +125,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
OpenJack1_4 jack = new OpenJack1_4();
|
||||
SingleCoilPickup pickup = new SingleCoilPickup();
|
||||
pickup.setName("Pickup");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 2);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1);
|
||||
netlist.add(tipGroup).add(sleeveGroup);
|
||||
@@ -139,7 +139,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
OpenJack1_4 jack = new OpenJack1_4();
|
||||
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||
pickup.setName("Pickup");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0);
|
||||
Group coilTapGroup = new Group().connect(pickup, 1).connect(pickup, 2);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 3);
|
||||
@@ -154,7 +154,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
OpenJack1_4 jack = new OpenJack1_4();
|
||||
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||
pickup.setName("Pickup");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 3);
|
||||
Group coilTapGroup = new Group().connect(pickup, 1).connect(pickup, 2);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 0);
|
||||
@@ -169,7 +169,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
OpenJack1_4 jack = new OpenJack1_4();
|
||||
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||
pickup.setName("Pickup");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0).connect(pickup, 2);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1).connect(pickup, 3);
|
||||
netlist.add(tipGroup).add(sleeveGroup);
|
||||
@@ -183,7 +183,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
OpenJack1_4 jack = new OpenJack1_4();
|
||||
HumbuckerPickup pickup = new HumbuckerPickup();
|
||||
pickup.setName("Pickup");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup, 0).connect(pickup, 3);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 1).connect(pickup, 2);
|
||||
netlist.add(tipGroup).add(sleeveGroup);
|
||||
@@ -199,7 +199,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
pickup1.setName("Pickup1");
|
||||
HumbuckerPickup pickup2 = new HumbuckerPickup();
|
||||
pickup2.setName("Pickup2");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0);
|
||||
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
|
||||
Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
|
||||
@@ -218,7 +218,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
pickup1.setName("Pickup1");
|
||||
HumbuckerPickup pickup2 = new HumbuckerPickup();
|
||||
pickup2.setName("Pickup2");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0).connect(pickup2, 0);
|
||||
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
|
||||
Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
|
||||
@@ -236,7 +236,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
pickup1.setName("Pickup1");
|
||||
HumbuckerPickup pickup2 = new HumbuckerPickup();
|
||||
pickup2.setName("Pickup2");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0).connect(pickup2, 3);
|
||||
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
|
||||
Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
|
||||
@@ -264,7 +264,7 @@ public class GuitarNetlistAnalyzerTests {
|
||||
cap1.setName("Cap1");
|
||||
RadialCeramicDiskCapacitor cap2 = new RadialCeramicDiskCapacitor();
|
||||
cap2.setName("Cap2");
|
||||
Netlist netlist = new Netlist();
|
||||
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
|
||||
Group hotGroup = new Group().connect(pickup1, 0).connect(vol, 0).connect(tone1, 2).connect(pickup2, 0).connect(tone2, 2);
|
||||
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
|
||||
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 3).connect(pickup2, 3).connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.RegressionTestRunner"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="diylc-swing"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value=""C:\Users\bancika\Documents\GitHub\diy-layout-creator\diylc-regression-data" TEST user-files"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value=""C:\Users\bancika\Documents\GitHub\diy-layout-creator\diylc-regression-data" TEST travelcaster3"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="diylc-swing"/>
|
||||
</launchConfiguration>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<property name="jar.dir" value="${build.dir}/jar" />
|
||||
<property name="report.dir" value="${build.dir}/junitreport" />
|
||||
<property name="main.class" value="org.diylc.DIYLCStarter" />
|
||||
<property name="diylc.version" value="4.22.1" />
|
||||
<property name="diylc.version" value="4.22.2" />
|
||||
|
||||
<property name="osx.jre8.path" value="jre\osx\jre8u321\Contents\Home\" />
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ A-O-I REGULATOR
|
||||
AWG
|
||||
And
|
||||
C-B-E BJT
|
||||
C1
|
||||
C2
|
||||
Check Trace Proximity
|
||||
D-G-S JFET
|
||||
D-G-S MOSFET
|
||||
|
||||
@@ -37,6 +37,15 @@
|
||||
<update_contact>nbenitezl_AT_gmail.com</update_contact>
|
||||
<content_rating type="oars-1.1"/>
|
||||
<releases>
|
||||
<release version="4.22.2" date="2022-03-18">
|
||||
<description>
|
||||
<ul>
|
||||
<li>[Bug Fix] Fixed the issue with application hanging when loading certain files</li>
|
||||
<li>[Bug Fix] Fixed importing building blocks and variants from a file</li>
|
||||
</ul>
|
||||
</description>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases/tag/v4.22.2</url>
|
||||
</release>
|
||||
<release version="4.22.1" date="2022-03-07">
|
||||
<description>
|
||||
<ul>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -97,9 +97,6 @@ import org.diylc.swingframework.TextDialog;
|
||||
import org.diylc.swingframework.export.DrawingExporter;
|
||||
import org.diylc.utils.BomEntry;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
|
||||
public class ActionFactory {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ActionFactory.class);
|
||||
@@ -967,10 +964,8 @@ public class ActionFactory {
|
||||
LOG.debug("Exporting variants to " + file.getAbsolutePath());
|
||||
|
||||
try {
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
ProjectFileManager.configure(xStream);
|
||||
xStream.toXML(variantPkg, out);
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
ProjectFileManager.xStreamSerializer.toXML(variantPkg, out);
|
||||
out.close();
|
||||
LOG.info("Exported variants succesfully");
|
||||
} catch (IOException e) {
|
||||
@@ -1124,10 +1119,8 @@ public class ActionFactory {
|
||||
LOG.debug("Exporting variants to " + file.getAbsolutePath());
|
||||
|
||||
try {
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
ProjectFileManager.configure(xStream);
|
||||
xStream.toXML(variantPkg, out);
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
ProjectFileManager.xStreamSerializer.toXML(variantPkg, out);
|
||||
out.close();
|
||||
LOG.info("Exported building blocks succesfully");
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -122,7 +122,7 @@ public class MainFrame extends JFrame implements ISwingUI {
|
||||
|
||||
IConfigurationManager configManager = ConfigurationManager.getInstance();
|
||||
|
||||
this.presenter = new Presenter(this, configManager);
|
||||
this.presenter = new Presenter(this, configManager, true);
|
||||
|
||||
presenter.installPlugin(() -> new ToolBox(this));
|
||||
presenter.installPlugin(() -> new FileMenuPlugin(this));
|
||||
|
||||
@@ -21,33 +21,29 @@
|
||||
*/
|
||||
package org.diylc.swing.plugins.file;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.EnumSet;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.gui.DummyView;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.serialization.ProjectFileManager;
|
||||
import org.diylc.swing.gui.DummyView;
|
||||
import org.diylc.swingframework.IFileChooserAccessory;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
|
||||
/**
|
||||
* {@link JComponent} that shows preview of the selected project in {@link JFileChooser}. It's
|
||||
* hooked onto {@link JFileChooser} as {@link PropertyChangeListener} and refreshes when file is
|
||||
@@ -60,7 +56,6 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IPlugInPort presenter;
|
||||
private XStream xStream;
|
||||
private Project emptyProject;
|
||||
private RenderComponent renderComponent;
|
||||
private JLabel nameLabel;
|
||||
@@ -70,7 +65,6 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
|
||||
setPreferredSize(new Dimension(140, 128));
|
||||
presenter = new Presenter(new DummyView(), InMemoryConfigurationManager.getInstance());
|
||||
xStream = new XStream(new DomDriver());
|
||||
|
||||
emptyProject = new Project();
|
||||
emptyProject.setTitle("");
|
||||
@@ -97,7 +91,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, IF
|
||||
File selectedFile = (File) evt.getNewValue();
|
||||
try {
|
||||
FileInputStream in = new FileInputStream(selectedFile);
|
||||
selectedProject = (Project) xStream.fromXML(in);
|
||||
selectedProject = (Project) ProjectFileManager.xStreamSerializer.fromXML(in);
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
package org.diylc;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IView;
|
||||
|
||||
public class MockView implements IView {
|
||||
|
||||
private Map<Integer, List<String>> messages = new HashMap<Integer, List<String>>();
|
||||
|
||||
@Override
|
||||
public void showMessage(String message, String title, int messageType) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
messages.putIfAbsent(messageType, new ArrayList<String>());
|
||||
messages.get(messageType).add(message);
|
||||
}
|
||||
|
||||
public Map<Integer, List<String>> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.diylc;
|
||||
|
||||
import java.awt.Point;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.core.Template;
|
||||
import org.junit.Test;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class PresenterTests extends TestBase {
|
||||
@@ -24,4 +26,28 @@ public class PresenterTests extends TestBase {
|
||||
instantiateOneClick("Connectivity", "Solder Pad", new Point(1000, 1000));
|
||||
Assert.assertEquals(1, presenter.getCurrentProject().getComponents().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadVariants() {
|
||||
try {
|
||||
ComponentType resistorType = presenter.getComponentTypes().get("Passive").stream().filter(x -> x.getName().equals("Resistor")).findAny().get();
|
||||
List<Template> variantsFor = presenter.getVariantsFor(resistorType);
|
||||
Assert.assertEquals(0, variantsFor.size());
|
||||
presenter.importVariants("./test/resources/variants_test.xml");
|
||||
variantsFor = presenter.getVariantsFor(resistorType);
|
||||
Assert.assertTrue(!variantsFor.isEmpty());
|
||||
} catch (IOException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadBlocks() {
|
||||
try {
|
||||
int blocks = presenter.importBlocks("./test/resources/blocks_test.xml");
|
||||
Assert.assertTrue(blocks > 0);
|
||||
} catch (IOException e) {
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,16 @@ package org.diylc;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -16,7 +23,12 @@ import java.util.stream.Stream;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.appframework.update.VersionNumber;
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.Summary;
|
||||
import org.diylc.netlist.TreeException;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.plugins.file.ProjectDrawingProvider;
|
||||
import org.diylc.swingframework.export.DrawingExporter;
|
||||
@@ -32,6 +44,15 @@ public class RegressionTestRunner {
|
||||
System.out.println("No path and command provided");
|
||||
return;
|
||||
}
|
||||
//
|
||||
// URL url = DIYLCStarter.class.getResource("log4j.properties");
|
||||
// Properties properties = new Properties();
|
||||
// try {
|
||||
// properties.load(url.openStream());
|
||||
// PropertyConfigurator.configure(properties);
|
||||
// } catch (Exception e) {
|
||||
// System.err.println("Could not initialize log4j configuration: " + e.getMessage());
|
||||
// }
|
||||
|
||||
ConfigurationManager.getInstance().initialize("diylc-test");
|
||||
|
||||
@@ -66,17 +87,17 @@ public class RegressionTestRunner {
|
||||
Presenter presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
|
||||
VersionNumber currentVersionNumber = presenter.getCurrentVersionNumber();
|
||||
|
||||
String fileName = basePath + File.separator + "reports" + File.separator
|
||||
+ LocalDateTime.now().toString().replace(":", "_") + "-"
|
||||
+ "V" + currentVersionNumber.toString().replace('.', '_') + ".csv";
|
||||
String fileName = basePath + File.separator + "reports" + File.separator
|
||||
+ LocalDateTime.now().toString().replace(":", "_") + "-" + "V"
|
||||
+ currentVersionNumber.toString().replace('.', '_') + ".csv";
|
||||
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
|
||||
|
||||
|
||||
long okCount = results.stream().filter(x -> x.ok).count();
|
||||
long failCount = results.size() - okCount;
|
||||
long totalTime = results.stream().map(x -> x.duration).reduce(0l, (a, b) -> a + b);
|
||||
long avgTime = totalTime / results.size();
|
||||
|
||||
|
||||
writer.write("OK,Failed,Total Time,Avg Time");
|
||||
writer.newLine();
|
||||
writer.write(Long.toString(okCount));
|
||||
@@ -85,11 +106,11 @@ public class RegressionTestRunner {
|
||||
writer.write(",");
|
||||
writer.write(Long.toString(totalTime));
|
||||
writer.write(",");
|
||||
writer.write(Long.toString(avgTime));
|
||||
writer.write(Long.toString(avgTime));
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
writer.newLine();
|
||||
|
||||
|
||||
writer.write("File,Status,Message,Time");
|
||||
writer.newLine();
|
||||
results.stream().sorted(Comparator.comparing(x -> x.fileName)).forEach(item -> {
|
||||
@@ -108,9 +129,9 @@ public class RegressionTestRunner {
|
||||
});
|
||||
|
||||
writer.close();
|
||||
|
||||
System.out.println("OK files: " + okCount + "; Failed files: " + failCount
|
||||
+ "; totalTime: " + (totalTime / 1000) + "s" + "; avgTime: " + avgTime + "ms");
|
||||
|
||||
System.out.println("OK files: " + okCount + "; Failed files: " + failCount + "; totalTime: "
|
||||
+ (totalTime / 1000) + "s" + "; avgTime: " + avgTime + "ms");
|
||||
|
||||
System.out.println("Saved test report to: " + fileName);
|
||||
}
|
||||
@@ -134,8 +155,8 @@ public class RegressionTestRunner {
|
||||
}
|
||||
}
|
||||
RegressionTestResult testResult = processFile(file, command);
|
||||
System.out
|
||||
.println(testResult.fileName + ": " + (testResult.ok ? "OK" : testResult.message));
|
||||
System.out.println(
|
||||
testResult.fileName + ": " + (testResult.message == null ? "OK" : testResult.message));
|
||||
return Stream.of(testResult);
|
||||
}
|
||||
});
|
||||
@@ -144,16 +165,16 @@ public class RegressionTestRunner {
|
||||
private static RegressionTestResult processFile(File file, String command) {
|
||||
String prefix = "File: " + file.getName() + " status: ";
|
||||
try {
|
||||
IView view = new MockView();
|
||||
MockView view = new MockView();
|
||||
Presenter presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
|
||||
ProjectDrawingProvider drawingProvider =
|
||||
new ProjectDrawingProvider(presenter, false, true, false);
|
||||
presenter.loadProjectFromFile(file.getAbsolutePath());
|
||||
if ("PREPARE".equalsIgnoreCase(command)) {
|
||||
// generate PNG input image for comparison
|
||||
return prepareInputs(file, drawingProvider);
|
||||
return prepareInputs(file, drawingProvider, presenter);
|
||||
} else if ("TEST".equalsIgnoreCase(command)) {
|
||||
return testOutputs(file, prefix, presenter, drawingProvider);
|
||||
return testOutputs(file, prefix, presenter, drawingProvider, view);
|
||||
}
|
||||
return new RegressionTestResult(file.getName()).failed("Command not recognized");
|
||||
} catch (Exception e) {
|
||||
@@ -163,7 +184,7 @@ public class RegressionTestRunner {
|
||||
}
|
||||
|
||||
private static RegressionTestResult testOutputs(File file, String prefix, Presenter presenter,
|
||||
ProjectDrawingProvider drawingProvider) {
|
||||
ProjectDrawingProvider drawingProvider, MockView view) {
|
||||
RegressionTestResult res = new RegressionTestResult(file.getName());
|
||||
File baseDir = file.getParentFile().getParentFile().getParentFile().getParentFile();
|
||||
File outputDir = new File(baseDir.getAbsolutePath() + File.separator + "output" + File.separator
|
||||
@@ -210,11 +231,74 @@ public class RegressionTestRunner {
|
||||
if (ImageComparisonState.MATCH != imageComparisonResult.getImageComparisonState()) {
|
||||
return res.failed("Images do not match!");
|
||||
}
|
||||
return res.succedded();
|
||||
|
||||
List<INetlistAnalyzer> summarizers = presenter.getNetlistAnalyzers();
|
||||
if (summarizers != null) {
|
||||
List<Netlist> netlists = presenter.extractNetlists(true);
|
||||
|
||||
for (INetlistAnalyzer summarizer : summarizers) {
|
||||
File summaryOutputDir =
|
||||
new File(outputDir.getAbsolutePath() + File.separator + summarizer.getShortName());
|
||||
File summaryOutputFile = new File(summaryOutputDir.getAbsolutePath() + File.separator
|
||||
+ file.getName().replace(".diy", ".txt"));
|
||||
summaryOutputDir.mkdirs();
|
||||
if (summaryOutputFile.exists()) {
|
||||
summaryOutputFile.delete();
|
||||
}
|
||||
|
||||
File summaryInputDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
|
||||
+ File.separator + summarizer.getShortName());
|
||||
File summaryInputFile = new File(summaryInputDir.getAbsolutePath() + File.separator
|
||||
+ file.getName().replace(".diy", ".txt"));
|
||||
|
||||
if (!summaryInputFile.exists()) {
|
||||
return res.failed("Summary input file not found for: " + summarizer.getShortName());
|
||||
}
|
||||
|
||||
try {
|
||||
List<String> outputLines = new ArrayList<String>();
|
||||
try {
|
||||
writeSummariesToFile(netlists, summarizer, summaryOutputFile);
|
||||
outputLines = Files.readAllLines(Paths.get(summaryOutputFile.getAbsolutePath()));
|
||||
} catch (Exception e) {
|
||||
try (BufferedWriter writer = new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(summaryOutputFile, true), "UTF-8"))) {
|
||||
String line = e.getClass().getCanonicalName() + ": " + e.getMessage();
|
||||
writer.write(line);
|
||||
outputLines.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> inputLines =
|
||||
Files.readAllLines(Paths.get(summaryInputFile.getAbsolutePath()));
|
||||
|
||||
if (inputLines.size() != outputLines.size()) {
|
||||
return res.failed(
|
||||
"Summary input and output files do not match for: " + summarizer.getShortName());
|
||||
}
|
||||
for (int i = 0; i < inputLines.size(); i++) {
|
||||
if (!inputLines.get(i).equals(outputLines.get(i))) {
|
||||
return res.failed(
|
||||
"Summary input and output files do not match for: " + summarizer.getShortName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return res.failed(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String message = null;
|
||||
if (!view.getMessages().isEmpty()) {
|
||||
message = view.getMessages().entrySet().stream().flatMap(x -> x.getValue().stream())
|
||||
.reduce("", String::concat);
|
||||
}
|
||||
|
||||
return res.succedded(message);
|
||||
}
|
||||
|
||||
private static RegressionTestResult prepareInputs(File file,
|
||||
ProjectDrawingProvider drawingProvider) {
|
||||
ProjectDrawingProvider drawingProvider, IPlugInPort plugInPort) {
|
||||
RegressionTestResult res = new RegressionTestResult(file.getName());
|
||||
try {
|
||||
File pngDir =
|
||||
@@ -222,8 +306,32 @@ public class RegressionTestRunner {
|
||||
File pngFile = new File(
|
||||
pngDir.getAbsolutePath() + File.separator + file.getName().replace(".diy", ".png"));
|
||||
pngFile.getParentFile().mkdirs();
|
||||
if (!pngFile.exists()) {
|
||||
DrawingExporter.getInstance().exportPNG(drawingProvider, pngFile);
|
||||
|
||||
// always export image to ensure that rendering is done and continuity areas are populated
|
||||
DrawingExporter.getInstance().exportPNG(drawingProvider, pngFile);
|
||||
|
||||
List<INetlistAnalyzer> summarizers = plugInPort.getNetlistAnalyzers();
|
||||
if (summarizers != null) {
|
||||
List<Netlist> netlists = plugInPort.extractNetlists(true);
|
||||
|
||||
for (INetlistAnalyzer summarizer : summarizers) {
|
||||
File summaryDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
|
||||
+ File.separator + summarizer.getShortName());
|
||||
File summaryFile = new File(summaryDir.getAbsolutePath() + File.separator
|
||||
+ file.getName().replace(".diy", ".txt"));
|
||||
summaryDir.mkdirs();
|
||||
if (!summaryFile.exists()) {
|
||||
try {
|
||||
writeSummariesToFile(netlists, summarizer, summaryFile);
|
||||
|
||||
} catch (Exception e) {
|
||||
try (BufferedWriter writer = new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
|
||||
writer.write(e.getClass().getCanonicalName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return res.failed(e.getMessage());
|
||||
@@ -231,6 +339,23 @@ public class RegressionTestRunner {
|
||||
return res.succedded();
|
||||
}
|
||||
|
||||
private static void writeSummariesToFile(List<Netlist> netlists, INetlistAnalyzer summarizer,
|
||||
File summaryFile)
|
||||
throws TreeException, IOException, UnsupportedEncodingException, FileNotFoundException {
|
||||
List<Summary> summaries = summarizer.summarize(netlists, null);
|
||||
|
||||
try (BufferedWriter writer = new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
|
||||
for (Summary summary : summaries) {
|
||||
writer.write("<b>Switch configuration: ");
|
||||
writer.write(summary.getNetlist().getSwitchSetup().toString());
|
||||
writer.write("</b><br><br>");
|
||||
writer.write(summary.getSummary());
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class RegressionTestResult {
|
||||
boolean ok;
|
||||
String message;
|
||||
@@ -244,13 +369,18 @@ public class RegressionTestRunner {
|
||||
}
|
||||
|
||||
public RegressionTestResult succedded() {
|
||||
return succedded(null);
|
||||
}
|
||||
|
||||
public RegressionTestResult succedded(String message) {
|
||||
this.ok = true;
|
||||
this.message = message;
|
||||
this.duration = System.currentTimeMillis() - this.startTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RegressionTestResult failed(String message) {
|
||||
this.ok = true;
|
||||
this.ok = false;
|
||||
this.message = message;
|
||||
this.duration = System.currentTimeMillis() - this.startTime;
|
||||
return this;
|
||||
|
||||
@@ -2,9 +2,11 @@ package org.diylc;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Properties;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
|
||||
import org.diylc.common.ComponentType;
|
||||
@@ -17,6 +19,15 @@ public class TestBase {
|
||||
protected IView view;
|
||||
|
||||
public TestBase() {
|
||||
URL url = DIYLCStarter.class.getResource("log4j.properties");
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(url.openStream());
|
||||
PropertyConfigurator.configure(properties);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Could not initialize log4j configuration: " + e.getMessage());
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().initialize("diylc-test");
|
||||
view = new MockView();
|
||||
presenter = new Presenter(view, InMemoryConfigurationManager.getInstance());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user