mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
netlist summarizer infrastructure added
This commit is contained in:
@@ -25,7 +25,24 @@ import java.util.List;
|
||||
|
||||
import org.diylc.netlist.Netlist;
|
||||
|
||||
/**
|
||||
* Interface for {@link Netlist} related operations.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public interface INetlistProcessor {
|
||||
|
||||
/**
|
||||
* Finds all {@link Netlist}s for each switch position combination.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Netlist> extractNetlists();
|
||||
|
||||
/**
|
||||
* Finds all available {@link INetlistSummarizer} implementations.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<INetlistSummarizer> getNetlistSummarizers();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.diylc.common;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.Node;
|
||||
import org.diylc.netlist.Summary;
|
||||
|
||||
public interface INetlistSummarizer {
|
||||
|
||||
/**
|
||||
* @return summarizer name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return name of the icon to use
|
||||
*/
|
||||
String getIconName();
|
||||
|
||||
/**
|
||||
* Summarizes all {@link Netlist}s provided.
|
||||
*
|
||||
* @param netlists
|
||||
* @param preferredOutput optional, needed only where there's more than one possible output node.
|
||||
* @return
|
||||
*/
|
||||
List<Summary> summarize(List<Netlist> netlists, Node preferredOutput);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
|
||||
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.List;
|
||||
|
||||
public class Summary {
|
||||
|
||||
private Netlist netlist;
|
||||
private List<String> notes;
|
||||
|
||||
public Summary(Netlist netlist, List<String> notes) {
|
||||
super();
|
||||
this.netlist = netlist;
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public Netlist getNetlist() {
|
||||
return netlist;
|
||||
}
|
||||
|
||||
public List<String> getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((netlist == null) ? 0 : netlist.hashCode());
|
||||
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Summary other = (Summary) obj;
|
||||
if (netlist == null) {
|
||||
if (other.netlist != null)
|
||||
return false;
|
||||
} else if (!netlist.equals(other.netlist))
|
||||
return false;
|
||||
if (notes == null) {
|
||||
if (other.notes != null)
|
||||
return false;
|
||||
} else if (!notes.equals(other.notes))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return notes.toString();
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,7 @@ import org.diylc.common.EventType;
|
||||
import org.diylc.common.IComponentFiler;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.IKeyProcessor;
|
||||
import org.diylc.common.INetlistSummarizer;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -76,11 +77,11 @@ import org.diylc.core.Theme;
|
||||
import org.diylc.core.annotations.IAutoCreator;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.netlist.Group;
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.SwitchSetup;
|
||||
import org.diylc.netlist.Node;
|
||||
import org.diylc.netlist.Position;
|
||||
import org.diylc.netlist.Group;
|
||||
import org.diylc.netlist.SwitchSetup;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
@@ -2882,98 +2883,27 @@ public class Presenter implements IPlugInPort {
|
||||
if (s.arePointsConnected(i, j, position))
|
||||
connections.add(new Line2D.Double(c.getControlPoint(i), c.getControlPoint(j)));
|
||||
}
|
||||
}
|
||||
|
||||
// // grab continuity areas
|
||||
// List<Area> continuity = drawingManager.getContinuityAreas(currentProject);
|
||||
//
|
||||
// mergeConnections(connections, continuity);
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
}
|
||||
|
||||
// private void mergeConnections(List<Line2D> connections, List<Area> continuity) {
|
||||
// List<Line2D> merged = new ArrayList<Line2D>();
|
||||
// boolean[] visited = new boolean[connections.size()];
|
||||
// for (int i = 0; i < visited.length; i++)
|
||||
// visited[i] = false;
|
||||
//
|
||||
// double t = DrawingManager.CONTROL_POINT_SIZE;
|
||||
//
|
||||
// for (int i = 0; i < visited.length - 1; i++) {
|
||||
// if (visited[i])
|
||||
// continue;
|
||||
// for (int j = i + 1; j < visited.length; j++) {
|
||||
// if (visited[j])
|
||||
// continue;
|
||||
// Line2D c1 = connections.get(i);
|
||||
// Line2D c2 = connections.get(j);
|
||||
// Point2D p1 = null;
|
||||
// Point2D p2 = null;
|
||||
// boolean connected = false;
|
||||
// // test direct continuity between two connections
|
||||
// if (!connected && c1.getP1().distance(c2.getP1()) < t) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP2();
|
||||
// p2 = c2.getP2();
|
||||
// }
|
||||
// if (!connected && c1.getP1().distance(c2.getP2()) < t) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP2();
|
||||
// p2 = c2.getP1();
|
||||
// }
|
||||
// if (!connected && c1.getP2().distance(c2.getP1()) < t) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP1();
|
||||
// p2 = c2.getP2();
|
||||
// }
|
||||
// if (!connected && c1.getP2().distance(c2.getP2()) < t) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP1();
|
||||
// p2 = c2.getP1();
|
||||
// }
|
||||
// // if that failed, try using continuity areas
|
||||
// if (!connected) {
|
||||
// for (Area a : continuity) {
|
||||
// if (!connected && a.contains(c1.getP1()) && a.contains(c2.getP1())) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP2();
|
||||
// p2 = c2.getP2();
|
||||
// break;
|
||||
// }
|
||||
// if (!connected && a.contains(c1.getP1()) && a.contains(c2.getP2())) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP2();
|
||||
// p2 = c2.getP1();
|
||||
// break;
|
||||
// }
|
||||
// if (!connected && a.contains(c1.getP2()) && a.contains(c2.getP1())) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP1();
|
||||
// p2 = c2.getP2();
|
||||
// break;
|
||||
// }
|
||||
// if (!connected && a.contains(c1.getP2()) && a.contains(c2.getP2())) {
|
||||
// connected = true;
|
||||
// p1 = c1.getP1();
|
||||
// p2 = c2.getP1();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (connected) {
|
||||
// visited[i] = visited[j] = true;
|
||||
// merged.add(new Line2D.Double(p1, p2));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // replace connections with merged
|
||||
// if (!merged.isEmpty()) {
|
||||
//// connections.clear();
|
||||
// connections.addAll(merged);
|
||||
// mergeConnections(connections, continuity); // attempt another round of merging if needed
|
||||
// }
|
||||
// }
|
||||
@Override
|
||||
public List<INetlistSummarizer> getNetlistSummarizers() {
|
||||
Set<Class<?>> classes;
|
||||
try {
|
||||
classes = Utils.getClasses("org.diylc.netlist");
|
||||
List<INetlistSummarizer> result = new ArrayList<INetlistSummarizer>();
|
||||
|
||||
for (Class<?> clazz : classes) {
|
||||
if (!Modifier.isAbstract(clazz.getModifiers()) && INetlistSummarizer.class.isAssignableFrom(clazz)) {
|
||||
result.add((INetlistSummarizer) clazz.newInstance());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not load INetlistSummarizer implementations", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -21,14 +21,11 @@
|
||||
*/
|
||||
package org.diylc.awt;
|
||||
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
/**
|
||||
* Creates an are covered by the two circles and the area between them bordered by the two external common tangents.
|
||||
*
|
||||
@@ -54,8 +51,4 @@ public class TwoCircleTangent extends Area {
|
||||
a.add(new Area(path));
|
||||
add(a);
|
||||
}
|
||||
|
||||
public TwoCircleTangent(Shape s) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
return VisibilityPolicy.ALWAYS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.common.INetlistSummarizer;
|
||||
|
||||
public class GuitarDiagramSummarizer implements INetlistSummarizer {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Guitar Diagrams";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIconName() {
|
||||
return "Guitar";
|
||||
}
|
||||
|
||||
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) {
|
||||
List<Summary> summaries = new ArrayList<Summary>();
|
||||
for (Netlist n : netlists)
|
||||
summaries.add(summarize(n, preferredOutput));
|
||||
|
||||
return summaries;
|
||||
}
|
||||
|
||||
private Summary summarize(Netlist netlist, Node preferredOutput) {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
notes.add("test");
|
||||
return new Summary(netlist, notes);
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -63,7 +63,7 @@ public enum IconLoader {
|
||||
"component_add.png"), History("history.png"), DocumentPlain("document_plain.png"), FitToSize("fit_to_size.png"), DocumentsGear(
|
||||
"documents_gear.png"), SplashResistor("splash_resistor.png"), SplashCeramic("splash_ceramic.png"), SplashElectrolytic(
|
||||
"splash_electrolytic.png"), SplashFilm("splash_film.png"), Splash("splash.png"), Help("help2.png"), ScrollInformation("scroll_information.png"),
|
||||
Node("node.png"), Web("web.png");
|
||||
Node("node.png"), Web("web.png"), Guitar("guitar.png"), Scientist("scientist.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 808 B |
Binary file not shown.
|
After Width: | Height: | Size: 903 B |
@@ -49,6 +49,7 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.BuildingBlockPackage;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.INetlistSummarizer;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
@@ -65,6 +66,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.netlist.Group;
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.Summary;
|
||||
import org.diylc.presenter.Presenter;
|
||||
import org.diylc.swing.gui.DialogFactory;
|
||||
import org.diylc.swing.gui.editor.PropertyEditorDialog;
|
||||
@@ -255,6 +257,10 @@ public class ActionFactory {
|
||||
public GenerateNetlistAction createGenerateNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI) {
|
||||
return new GenerateNetlistAction(plugInPort, swingUI);
|
||||
}
|
||||
|
||||
public SummarizeNetlistAction createSummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI, INetlistSummarizer summarizer) {
|
||||
return new SummarizeNetlistAction(plugInPort, swingUI, summarizer);
|
||||
}
|
||||
|
||||
// File menu actions.
|
||||
|
||||
@@ -1667,20 +1673,56 @@ public class ActionFactory {
|
||||
for (Netlist netlist : res) {
|
||||
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(netlist.getSwitchSetup()).append("</b><br><br>Connected node groups:<br>");
|
||||
for (Group v : netlist.getSortedGroups()) {
|
||||
// boolean first = true;
|
||||
// for (Node n : v.getSortedNodes()) {
|
||||
// if (!first)
|
||||
// sb.append(" <-> ");
|
||||
// first = false;
|
||||
//
|
||||
// }
|
||||
sb.append(" ").append(v.getSortedNodes()).append("<br>");
|
||||
}
|
||||
sb.append("</p><br><hr>");
|
||||
}
|
||||
sb.append("</html>");
|
||||
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "Netlist", new Dimension(600, 480)).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SummarizeNetlistAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private IPlugInPort plugInPort;
|
||||
private ISwingUI swingUI;
|
||||
private INetlistSummarizer summarizer;
|
||||
|
||||
public SummarizeNetlistAction(IPlugInPort plugInPort, ISwingUI swingUI, INetlistSummarizer summarizer) {
|
||||
super();
|
||||
this.plugInPort = plugInPort;
|
||||
this.swingUI = swingUI;
|
||||
this.summarizer = summarizer;
|
||||
putValue(AbstractAction.NAME, "Analyze " + summarizer.getName());
|
||||
putValue(AbstractAction.SMALL_ICON, Enum.valueOf(IconLoader.class, summarizer.getIconName()).getIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<Netlist> netlists = plugInPort.extractNetlists();
|
||||
if (netlists == null || netlists.isEmpty()) {
|
||||
swingUI.showMessage("The generated netlist is empty, nothing to show.", "Netlist", ISwingUI.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Summary> res = summarizer.summarize(netlists, null);
|
||||
if (res == null) {
|
||||
swingUI.showMessage("The generated summary is empty, nothing to show.", "Analyze", ISwingUI.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("<html>");
|
||||
|
||||
for (Summary summary : res) {
|
||||
sb.append("<p style=\"font-family: " + new JLabel().getFont().getName() + "; font-size: 9px\"><b>Switch configuration: ").append(summary.getNetlist().getSwitchSetup()).append("</b><br><br>Notes:<br><br>");
|
||||
for (String v : summary.getNotes()) {
|
||||
sb.append(" ").append(v).append("<br>");
|
||||
}
|
||||
sb.append("</p><br><hr>");
|
||||
}
|
||||
sb.append("</html>");
|
||||
new TextDialog(swingUI.getOwnerFrame().getRootPane(), sb.toString(), "Netlist", new Dimension(600, 480)).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,11 @@ import java.awt.Toolkit;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.INetlistSummarizer;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.images.IconLoader;
|
||||
@@ -86,9 +87,16 @@ public class FileMenuPlugin implements IPlugIn, IDynamicSubmenuHandler {
|
||||
swingUI.injectMenuAction(
|
||||
actionFactory.createPrintAction(traceMaskDrawingProvider, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
|
||||
| KeyEvent.SHIFT_DOWN_MASK), TRACE_MASK_TITLE);
|
||||
swingUI.injectSubmenu(ANALYZE_TITLE, IconLoader.Node.getIcon(), FILE_TITLE);
|
||||
swingUI.injectSubmenu(ANALYZE_TITLE, IconLoader.Scientist.getIcon(), FILE_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createBomAction(plugInPort), ANALYZE_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createGenerateNetlistAction(plugInPort, swingUI), ANALYZE_TITLE);
|
||||
|
||||
List<INetlistSummarizer> summarizers = plugInPort.getNetlistSummarizers();
|
||||
if (summarizers != null) {
|
||||
for(INetlistSummarizer summarizer : summarizers)
|
||||
swingUI.injectMenuAction(actionFactory.createSummarizeNetlistAction(plugInPort, swingUI, summarizer), ANALYZE_TITLE);
|
||||
}
|
||||
|
||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||
swingUI.injectSubmenu(INTEGRATION_TITLE, IconLoader.Node.getIcon(), FILE_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createImportBlocksAction(swingUI, plugInPort), INTEGRATION_TITLE);
|
||||
|
||||
Reference in New Issue
Block a user