mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
graph improvmeents
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.diylc.graph.Graph;
|
||||
@@ -28,5 +29,5 @@ import org.diylc.graph.GraphKey;
|
||||
|
||||
public interface IGraphProcessor {
|
||||
|
||||
Map<GraphKey, Graph> extractGraphs();
|
||||
Map<Graph, List<GraphKey>> extractGraphs();
|
||||
}
|
||||
|
||||
@@ -283,6 +283,6 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
return getName() + "." + index;
|
||||
return Integer.toString(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,36 @@ public class Graph {
|
||||
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.getNode1()).append(" - ").append(v.getNode2()).append("\n");
|
||||
sb.append("\t").append(v).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -52,6 +52,6 @@ public class Node {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return component.getName() + "." + pointIndex + " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")";
|
||||
return component.getName() + "." + component.getControlPointNodeName(pointIndex) /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,34 @@
|
||||
package org.diylc.graph;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class Vertex {
|
||||
|
||||
private Node node1;
|
||||
private Node node2;
|
||||
private Set<Node> nodes = new HashSet<Node>();
|
||||
|
||||
public Vertex(Node node1, Node node2) {
|
||||
this.node1 = node1;
|
||||
this.node2 = node2;
|
||||
nodes.add(node1);
|
||||
nodes.add(node2);
|
||||
}
|
||||
|
||||
public Node getNode1() {
|
||||
return node1;
|
||||
Iterator<Node> i = nodes.iterator();
|
||||
return i.next();
|
||||
}
|
||||
|
||||
public Node getNode2() {
|
||||
return node2;
|
||||
}
|
||||
|
||||
Iterator<Node> i = nodes.iterator();
|
||||
i.next();
|
||||
return i.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((node1 == null) ? 0 : node1.hashCode());
|
||||
result = prime * result + ((node2 == null) ? 0 : node2.hashCode());
|
||||
result = prime * result + ((nodes == null) ? 0 : nodes.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -36,21 +41,16 @@ public class Vertex {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Vertex other = (Vertex) obj;
|
||||
if (node1 == null) {
|
||||
if (other.node1 != null)
|
||||
if (nodes == null) {
|
||||
if (other.nodes != null)
|
||||
return false;
|
||||
} else if (!node1.equals(other.node1))
|
||||
return false;
|
||||
if (node2 == null) {
|
||||
if (other.node2 != null)
|
||||
return false;
|
||||
} else if (!node2.equals(other.node2))
|
||||
} else if (!nodes.equals(other.nodes))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return node1.toString() + " -> " + node2.toString();
|
||||
return getNode1().toString() + " <-> " + getNode2().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ public class Presenter implements IPlugInPort {
|
||||
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
||||
try {
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
||||
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
||||
loadProject(project, true);
|
||||
projectFileManager.fireFileStatusChanged();
|
||||
if (!warnings.isEmpty()) {
|
||||
@@ -2687,8 +2687,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<GraphKey, Graph> extractGraphs() {
|
||||
Map<GraphKey, Graph> result = new HashMap<GraphKey, Graph>();
|
||||
public Map<Graph, List<GraphKey>> extractGraphs() {
|
||||
Map<Graph, List<GraphKey>> result = new HashMap<Graph, List<GraphKey>>();
|
||||
List<Node> nodes = new ArrayList<Node>();
|
||||
|
||||
List<ISwitch> switches = new ArrayList<ISwitch>();
|
||||
@@ -2753,7 +2753,15 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
List<Line2D> connections = getConnections(switchPositions);
|
||||
Graph graph = constructGraph(nodes, connections, continuity);
|
||||
result.put(new GraphKey(posList), graph);
|
||||
|
||||
// merge graphs that are effectivelly the same
|
||||
if (result.containsKey(graph)) {
|
||||
result.get(graph).add(new GraphKey(posList));
|
||||
} else {
|
||||
List<GraphKey> list = new ArrayList<GraphKey>();
|
||||
list.add(new GraphKey(posList));
|
||||
result.put(graph, list);
|
||||
}
|
||||
|
||||
// find the next combination if possible
|
||||
if (positions[i] < switches.get(i).getPositionCount() - 1) {
|
||||
|
||||
Reference in New Issue
Block a user