From 6e5174750f0461a3b05af80c4e775320084bea64 Mon Sep 17 00:00:00 2001 From: Branislav Stojkovic Date: Sat, 16 Feb 2019 09:40:55 +0100 Subject: [PATCH] rename graph-related stuff into netlists --- ...hProcessor.java => INetlistProcessor.java} | 8 +- .../src/org/diylc/common/IPlugInPort.java | 2 +- .../diylc-core/src/org/diylc/graph/Graph.java | 54 ------------- .../src/org/diylc/graph/GraphKey.java | 54 ------------- .../src/org/diylc/graph/Vertex.java | 56 ------------- .../src/org/diylc/netlist/Group.java | 80 +++++++++++++++++++ .../src/org/diylc/netlist/Netlist.java | 75 +++++++++++++++++ .../org/diylc/{graph => netlist}/Node.java | 29 ++++++- .../diylc/{graph => netlist}/Position.java | 28 ++++++- .../src/org/diylc/netlist/SwitchSetup.java | 80 +++++++++++++++++++ .../src/org/diylc/presenter/Presenter.java | 39 +++++---- 11 files changed, 319 insertions(+), 186 deletions(-) rename diylc/diylc-core/src/org/diylc/common/{IGraphProcessor.java => INetlistProcessor.java} (81%) delete mode 100644 diylc/diylc-core/src/org/diylc/graph/Graph.java delete mode 100644 diylc/diylc-core/src/org/diylc/graph/GraphKey.java delete mode 100644 diylc/diylc-core/src/org/diylc/graph/Vertex.java create mode 100644 diylc/diylc-core/src/org/diylc/netlist/Group.java create mode 100644 diylc/diylc-core/src/org/diylc/netlist/Netlist.java rename diylc/diylc-core/src/org/diylc/{graph => netlist}/Node.java (56%) rename diylc/diylc-core/src/org/diylc/{graph => netlist}/Position.java (55%) create mode 100644 diylc/diylc-core/src/org/diylc/netlist/SwitchSetup.java diff --git a/diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java b/diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java similarity index 81% rename from diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java rename to diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java index 293b79a3..8e09dfd0 100644 --- a/diylc/diylc-core/src/org/diylc/common/IGraphProcessor.java +++ b/diylc/diylc-core/src/org/diylc/common/INetlistProcessor.java @@ -24,10 +24,10 @@ package org.diylc.common; import java.util.List; import java.util.Map; -import org.diylc.graph.Graph; -import org.diylc.graph.GraphKey; +import org.diylc.netlist.Netlist; +import org.diylc.netlist.SwitchSetup; -public interface IGraphProcessor { +public interface INetlistProcessor { - Map> extractGraphs(); + Map> extractNetlists(); } diff --git a/diylc/diylc-core/src/org/diylc/common/IPlugInPort.java b/diylc/diylc-core/src/org/diylc/common/IPlugInPort.java index 7e7e8547..4972d299 100644 --- a/diylc/diylc-core/src/org/diylc/common/IPlugInPort.java +++ b/diylc/diylc-core/src/org/diylc/common/IPlugInPort.java @@ -53,7 +53,7 @@ import org.diylc.core.Theme; * @see EventType */ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, IVariantProcessor, - IBlockProcessor, IGraphProcessor { + IBlockProcessor, INetlistProcessor { public static final String ANTI_ALIASING_KEY = "antiAliasing"; public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender"; diff --git a/diylc/diylc-core/src/org/diylc/graph/Graph.java b/diylc/diylc-core/src/org/diylc/graph/Graph.java deleted file mode 100644 index 6d5d8790..00000000 --- a/diylc/diylc-core/src/org/diylc/graph/Graph.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.diylc.graph; - -import java.util.HashSet; -import java.util.Set; - -public class Graph { - - private Set vertices = new HashSet(); - - public Graph() { - } - - public Set getVertices() { - return vertices; - } - - public boolean verticesMatch(Graph other) { - return this.vertices.equals(other.vertices); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((vertices == null) ? 0 : vertices.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; - Graph other = (Graph) obj; - if (vertices == null) { - if (other.vertices != null) - return false; - } else if (!vertices.equals(other.vertices)) - return false; - return true; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (Vertex v : vertices) { - sb.append("\t").append(v).append("\n"); - } - return sb.toString(); - } -} diff --git a/diylc/diylc-core/src/org/diylc/graph/GraphKey.java b/diylc/diylc-core/src/org/diylc/graph/GraphKey.java deleted file mode 100644 index f703e016..00000000 --- a/diylc/diylc-core/src/org/diylc/graph/GraphKey.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.diylc.graph; - -import java.util.List; - -public class GraphKey { - - private List positions; - - public GraphKey(List positions) { - super(); - this.positions = positions; - } - - public List getPositions() { - return positions; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((positions == null) ? 0 : positions.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; - GraphKey other = (GraphKey) obj; - if (positions == null) { - if (other.positions != null) - return false; - } else if (!positions.equals(other.positions)) - return false; - return true; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (Position s : positions) - { - if (sb.length() > 0) - sb.append(":"); - sb.append(s.toString()); - } - return sb.toString(); - } -} diff --git a/diylc/diylc-core/src/org/diylc/graph/Vertex.java b/diylc/diylc-core/src/org/diylc/graph/Vertex.java deleted file mode 100644 index d019861d..00000000 --- a/diylc/diylc-core/src/org/diylc/graph/Vertex.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.diylc.graph; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -public class Vertex { - - private Set nodes = new HashSet(); - - public Vertex(Node node1, Node node2) { - nodes.add(node1); - nodes.add(node2); - } - - public Node getNode1() { - Iterator i = nodes.iterator(); - return i.next(); - } - - public Node getNode2() { - Iterator i = nodes.iterator(); - i.next(); - return i.next(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((nodes == null) ? 0 : nodes.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; - Vertex other = (Vertex) obj; - if (nodes == null) { - if (other.nodes != null) - return false; - } else if (!nodes.equals(other.nodes)) - return false; - return true; - } - - @Override - public String toString() { - return getNode1().toString() + " <-> " + getNode2().toString(); - } -} diff --git a/diylc/diylc-core/src/org/diylc/netlist/Group.java b/diylc/diylc-core/src/org/diylc/netlist/Group.java new file mode 100644 index 00000000..1c4730f7 --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/netlist/Group.java @@ -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 . + +*/ +package org.diylc.netlist; + +import java.util.HashSet; +import java.util.Set; + +/** + * Represents a group of {@link Node}s that are connected together. + * + * @author Branislav Stojkovic + */ +public class Group { + + private Set nodes = new HashSet(); + + public Group(Node node1, Node node2) { + nodes.add(node1); + nodes.add(node2); + } + + public Set getNodes() { + return nodes; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((nodes == null) ? 0 : nodes.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; + Group other = (Group) obj; + if (nodes == null) { + if (other.nodes != null) + return false; + } else if (!nodes.equals(other.nodes)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Node n : nodes) { + if (sb.length() > 0) + sb.append(" <-> "); + sb.append(n); + } + return sb.toString(); + } +} diff --git a/diylc/diylc-core/src/org/diylc/netlist/Netlist.java b/diylc/diylc-core/src/org/diylc/netlist/Netlist.java new file mode 100644 index 00000000..3e36ce11 --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/netlist/Netlist.java @@ -0,0 +1,75 @@ +/* + + 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 . + +*/ +package org.diylc.netlist; + +import java.util.HashSet; +import java.util.Set; + +public class Netlist { + + private Set vertices = new HashSet(); + + public Netlist() { + } + + public Set getVertices() { + return vertices; + } + + public boolean verticesMatch(Netlist other) { + return this.vertices.equals(other.vertices); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((vertices == null) ? 0 : vertices.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; + Netlist other = (Netlist) obj; + if (vertices == null) { + if (other.vertices != null) + return false; + } else if (!vertices.equals(other.vertices)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Group v : vertices) { + sb.append("\t").append(v).append("\n"); + } + return sb.toString(); + } +} diff --git a/diylc/diylc-core/src/org/diylc/graph/Node.java b/diylc/diylc-core/src/org/diylc/netlist/Node.java similarity index 56% rename from diylc/diylc-core/src/org/diylc/graph/Node.java rename to diylc/diylc-core/src/org/diylc/netlist/Node.java index 01c2a2e6..bf5b4e8f 100644 --- a/diylc/diylc-core/src/org/diylc/graph/Node.java +++ b/diylc/diylc-core/src/org/diylc/netlist/Node.java @@ -1,8 +1,33 @@ -package org.diylc.graph; +/* + + 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 . + +*/ +package org.diylc.netlist; import org.diylc.core.IDIYComponent; - +/** + * Represents a single node in a {@link Netlist}, uniquely defined by a component and a control point. + * + * @author Branislav Stojkovic + */ public class Node { private IDIYComponent component; diff --git a/diylc/diylc-core/src/org/diylc/graph/Position.java b/diylc/diylc-core/src/org/diylc/netlist/Position.java similarity index 55% rename from diylc/diylc-core/src/org/diylc/graph/Position.java rename to diylc/diylc-core/src/org/diylc/netlist/Position.java index bf44d8eb..d2015f14 100644 --- a/diylc/diylc-core/src/org/diylc/graph/Position.java +++ b/diylc/diylc-core/src/org/diylc/netlist/Position.java @@ -1,8 +1,34 @@ -package org.diylc.graph; +/* + + 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 . + +*/ +package org.diylc.netlist; import org.diylc.core.IDIYComponent; import org.diylc.core.ISwitch; +/** + * Represents a single position of a switch, uniquely defined by the switch and the position. + * + * @author Branislav Stojkovic + */ public class Position { private ISwitch theSwitch; diff --git a/diylc/diylc-core/src/org/diylc/netlist/SwitchSetup.java b/diylc/diylc-core/src/org/diylc/netlist/SwitchSetup.java new file mode 100644 index 00000000..078d7f48 --- /dev/null +++ b/diylc/diylc-core/src/org/diylc/netlist/SwitchSetup.java @@ -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 . + +*/ +package org.diylc.netlist; + +import java.util.List; + +/** + * Represents a full switch configuration of the whole {@link Netlist}, containing one position of each switch in the {@link Netlist}. + * + * @author Branislav Stojkovic + */ +public class SwitchSetup { + + private List positions; + + public SwitchSetup(List positions) { + super(); + this.positions = positions; + } + + public List getPositions() { + return positions; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((positions == null) ? 0 : positions.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; + SwitchSetup other = (SwitchSetup) obj; + if (positions == null) { + if (other.positions != null) + return false; + } else if (!positions.equals(other.positions)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Position s : positions) + { + if (sb.length() > 0) + sb.append(":"); + sb.append(s.toString()); + } + return sb.toString(); + } +} diff --git a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java index 53096004..8fcfe9e7 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/Presenter.java +++ b/diylc/diylc-core/src/org/diylc/presenter/Presenter.java @@ -76,11 +76,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.graph.Graph; -import org.diylc.graph.GraphKey; -import org.diylc.graph.Node; -import org.diylc.graph.Position; -import org.diylc.graph.Vertex; +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.utils.Constants; import com.thoughtworks.xstream.XStream; @@ -2687,8 +2687,8 @@ public class Presenter implements IPlugInPort { @SuppressWarnings("unchecked") @Override - public Map> extractGraphs() { - Map> result = new HashMap>(); + public Map> extractNetlists() { + Map> result = new HashMap>(); List nodes = new ArrayList(); List switches = new ArrayList(); @@ -2752,14 +2752,14 @@ public class Presenter implements IPlugInPort { posList.add(new Position(switches.get(j), positions[j])); } List connections = getConnections(switchPositions); - Graph graph = constructGraph(nodes, connections, continuity); + Netlist graph = constructGraph(nodes, connections, continuity); // merge graphs that are effectivelly the same if (result.containsKey(graph)) { - result.get(graph).add(new GraphKey(posList)); + result.get(graph).add(new SwitchSetup(posList)); } else { - List list = new ArrayList(); - list.add(new GraphKey(posList)); + List list = new ArrayList(); + list.add(new SwitchSetup(posList)); result.put(graph, list); } @@ -2781,8 +2781,8 @@ public class Presenter implements IPlugInPort { return result; } - private Graph constructGraph(List nodes, List connections, List continuityAreas) { - Graph graph = new Graph(); + private Netlist constructGraph(List nodes, List connections, List continuityAreas) { + Netlist graph = new Netlist(); // StringBuilder sb = new StringBuilder(); // sb.append("Nodes:").append("\n"); @@ -2807,7 +2807,18 @@ public class Presenter implements IPlugInPort { if (point1.distance(point2) < t || checkGraphConnection(point1, point2, connections, continuityAreas, new boolean[connections.size()]) || checkGraphConnection(point2, point1, connections, continuityAreas, new boolean[connections.size()])) { - graph.getVertices().add(new Vertex(node1, node2)); + boolean added = false; + // add to an existing vertex if possible + for (Group v :graph.getVertices()) + if (v.getNodes().contains(node1)) { + v.getNodes().add(node2); + added = true; + } else if (v.getNodes().contains(node2)) { + v.getNodes().add(node1); + added = true; + } + if (!added) + graph.getVertices().add(new Group(node1, node2)); } }