graph improvmeents

This commit is contained in:
Branislav Stojkovic
2019-02-15 23:39:54 +01:00
parent f53ad8c206
commit ddfc615a6a
11 changed files with 715 additions and 559 deletions
@@ -21,6 +21,7 @@
*/ */
package org.diylc.common; package org.diylc.common;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.diylc.graph.Graph; import org.diylc.graph.Graph;
@@ -28,5 +29,5 @@ import org.diylc.graph.GraphKey;
public interface IGraphProcessor { 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 @Override
public String getControlPointNodeName(int index) { 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); 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 @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (Vertex v : vertices) { 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(); return sb.toString();
} }
@@ -52,6 +52,6 @@ public class Node {
@Override @Override
public String toString() { 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; package org.diylc.graph;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class Vertex { public class Vertex {
private Node node1; private Set<Node> nodes = new HashSet<Node>();
private Node node2;
public Vertex(Node node1, Node node2) { public Vertex(Node node1, Node node2) {
this.node1 = node1; nodes.add(node1);
this.node2 = node2; nodes.add(node2);
} }
public Node getNode1() { public Node getNode1() {
return node1; Iterator<Node> i = nodes.iterator();
return i.next();
} }
public Node getNode2() { public Node getNode2() {
return node2; Iterator<Node> i = nodes.iterator();
} i.next();
return i.next();
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((node1 == null) ? 0 : node1.hashCode()); result = prime * result + ((nodes == null) ? 0 : nodes.hashCode());
result = prime * result + ((node2 == null) ? 0 : node2.hashCode());
return result; return result;
} }
@@ -36,21 +41,16 @@ public class Vertex {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
Vertex other = (Vertex) obj; Vertex other = (Vertex) obj;
if (node1 == null) { if (nodes == null) {
if (other.node1 != null) if (other.nodes != null)
return false; return false;
} else if (!node1.equals(other.node1)) } else if (!nodes.equals(other.nodes))
return false;
if (node2 == null) {
if (other.node2 != null)
return false;
} else if (!node2.equals(other.node2))
return false; return false;
return true; return true;
} }
@Override @Override
public String toString() { 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)); LOG.info(String.format("loadProjectFromFile(%s)", fileName));
try { try {
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings); Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
loadProject(project, true); loadProject(project, true);
projectFileManager.fireFileStatusChanged(); projectFileManager.fireFileStatusChanged();
if (!warnings.isEmpty()) { if (!warnings.isEmpty()) {
@@ -2687,8 +2687,8 @@ public class Presenter implements IPlugInPort {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Map<GraphKey, Graph> extractGraphs() { public Map<Graph, List<GraphKey>> extractGraphs() {
Map<GraphKey, Graph> result = new HashMap<GraphKey, Graph>(); Map<Graph, List<GraphKey>> result = new HashMap<Graph, List<GraphKey>>();
List<Node> nodes = new ArrayList<Node>(); List<Node> nodes = new ArrayList<Node>();
List<ISwitch> switches = new ArrayList<ISwitch>(); List<ISwitch> switches = new ArrayList<ISwitch>();
@@ -2753,7 +2753,15 @@ public class Presenter implements IPlugInPort {
} }
List<Line2D> connections = getConnections(switchPositions); List<Line2D> connections = getConnections(switchPositions);
Graph graph = constructGraph(nodes, connections, continuity); 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 // find the next combination if possible
if (positions[i] < switches.get(i).getPositionCount() - 1) { if (positions[i] < switches.get(i).getPositionCount() - 1) {
Binary file not shown.
File diff suppressed because it is too large Load Diff
@@ -65,10 +65,11 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
private static Color BODY_COLOR = Color.white; private static Color BODY_COLOR = Color.white;
private static Color BASE_COLOR = Color.gray; private static Color BASE_COLOR = Color.gray;
private static Color POINT_COLOR = Color.lightGray; // private static Color POINT_COLOR = Color.lightGray;
private static Size WIDTH = new Size(15.5d, SizeUnit.mm); private static Size WIDTH = new Size(15.5d, SizeUnit.mm);
private static Size LENGTH = new Size(83d, SizeUnit.mm); private static Size LENGTH = new Size(83d, SizeUnit.mm);
private static Size BASE_RADIUS = new Size(0.15d, SizeUnit.in); private static Size BASE_RADIUS = new Size(0.15d, SizeUnit.in);
private static Size POINT_SPACING = new Size(0.1d, SizeUnit.in);
// strat-specific // strat-specific
private static Size STRAT_LIP_WIDTH = new Size(5d, SizeUnit.mm); private static Size STRAT_LIP_WIDTH = new Size(5d, SizeUnit.mm);
@@ -99,7 +100,52 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
private Color poleColor = METAL_COLOR; private Color poleColor = METAL_COLOR;
private Color baseColor = BASE_COLOR; private Color baseColor = BASE_COLOR;
private SingleCoilType type = SingleCoilType.Stratocaster; private SingleCoilType type = SingleCoilType.Stratocaster;
private PolePieceType polePieceType = PolePieceType.Rods; private PolePieceType polePieceType = PolePieceType.Rods;
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0)};
public SingleCoilPickup() {
updateControlPoints();
}
private Point[] getControlPoints() {
if (controlPoints == null) {
controlPoints =
new Point[] {controlPoint, new Point(controlPoint.x, controlPoint.y),
new Point(controlPoint.x, controlPoint.y), new Point(controlPoint.x, controlPoint.y)};
updateControlPoints();
}
return controlPoints;
}
@SuppressWarnings("incomplete-switch")
private void updateControlPoints() {
Point[] points = getControlPoints();
int pointSpacing = (int) POINT_SPACING.convertToPixels();
int dx = 1;
int dy = 0;
if (orientation != Orientation.DEFAULT) {
switch (orientation) {
case _90:
dx = 0;
dy = -1;
break;
case _180:
dx = -1;
dy = 0;
break;
case _270:
dx = 0;
dy = 1;
break;
}
}
points[1].setLocation(points[0].x + dx * pointSpacing, points[0].y + dy * pointSpacing);
points[2]
.setLocation(points[0].x + 2 * dx * pointSpacing, points[0].y + 2 * dy * pointSpacing);
points[3]
.setLocation(points[0].x + 3 * dx * pointSpacing, points[0].y + 3 * dy * pointSpacing);
}
@Override @Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
@@ -120,8 +166,8 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
g2d.fill(body[3]); g2d.fill(body[3]);
else else
g2d.fill(body[0]); g2d.fill(body[0]);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR); // g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR);
g2d.fill(body[1]); // g2d.fill(body[1]);
// g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); // g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color);
// g2d.fill(body[3]); // g2d.fill(body[3]);
@@ -190,9 +236,10 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
public Shape[] getBody() { public Shape[] getBody() {
if (body == null) { if (body == null) {
body = new Shape[5]; body = new Shape[5];
int x = controlPoint.x; Point[] points = getControlPoints();
int y = controlPoint.y; int x = (points[0].x + points[3].x) / 2;
int y = (points[0].y + points[3].y) / 2;;
int width = (int) WIDTH.convertToPixels(); int width = (int) WIDTH.convertToPixels();
int length = (int) LENGTH.convertToPixels(); int length = (int) LENGTH.convertToPixels();
int stratInnerLength = (int) STRAT_INNER_LENGTH.convertToPixels(); int stratInnerLength = (int) STRAT_INNER_LENGTH.convertToPixels();
@@ -388,7 +435,7 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
@Override @Override
public int getControlPointCount() { public int getControlPointCount() {
return 1; return 4;
} }
@Override @Override
@@ -403,12 +450,12 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
@Override @Override
public Point getControlPoint(int index) { public Point getControlPoint(int index) {
return controlPoint; return getControlPoints()[index];
} }
@Override @Override
public void setControlPoint(Point point, int index) { public void setControlPoint(Point point, int index) {
this.controlPoint.setLocation(point); getControlPoints()[index].setLocation(point);
// Invalidate the body // Invalidate the body
body = null; body = null;
} }
@@ -432,7 +479,8 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
public void setOrientation(Orientation orientation) { public void setOrientation(Orientation orientation) {
this.orientation = orientation; this.orientation = orientation;
// Invalidate the body // Invalidate the body
body = null; body = null;
updateControlPoints();
} }
@EditableProperty @EditableProperty
@@ -468,7 +516,17 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
@Override @Override
public String getControlPointNodeName(int index) { public String getControlPointNodeName(int index) {
return getName() + ".PickupTerminal"; switch (index) {
case 0:
return"North Start";
case 1:
return "North End";
case 2:
return "South Start";
case 3:
return "South End";
}
return null;
} }
public enum SingleCoilType { public enum SingleCoilType {
Binary file not shown.
Binary file not shown.