mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
ground work for graph analysis
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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.common;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.diylc.graph.Graph;
|
||||||
|
import org.diylc.graph.GraphKey;
|
||||||
|
|
||||||
|
public interface IGraphProcessor {
|
||||||
|
|
||||||
|
Map<GraphKey, Graph> extractGraphs();
|
||||||
|
}
|
||||||
@@ -53,7 +53,7 @@ import org.diylc.core.Theme;
|
|||||||
* @see EventType
|
* @see EventType
|
||||||
*/
|
*/
|
||||||
public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, IVariantProcessor,
|
public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyProcessor, IVariantProcessor,
|
||||||
IBlockProcessor {
|
IBlockProcessor, IGraphProcessor {
|
||||||
|
|
||||||
public static final String ANTI_ALIASING_KEY = "antiAliasing";
|
public static final String ANTI_ALIASING_KEY = "antiAliasing";
|
||||||
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
|
public static final String HI_QUALITY_RENDER_KEY = "hiQualityRender";
|
||||||
|
|||||||
@@ -280,4 +280,9 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
|||||||
}
|
}
|
||||||
return o1.equals(o2);
|
return o1.equals(o2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + "." + index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,8 +111,18 @@ public interface IDIYComponent<T> extends Serializable {
|
|||||||
*/
|
*/
|
||||||
boolean canControlPointOverlap(int index);
|
boolean canControlPointOverlap(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param index
|
||||||
|
* @return {@link VisibilityPolicy} of the control point.
|
||||||
|
*/
|
||||||
VisibilityPolicy getControlPointVisibilityPolicy(int index);
|
VisibilityPolicy getControlPointVisibilityPolicy(int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param index
|
||||||
|
* @return name of the control point node, if the control point represents a graph node, null otherwise.
|
||||||
|
*/
|
||||||
|
String getControlPointNodeName(int index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the component onto the {@link Graphics2D}.
|
* Draws the component onto the {@link Graphics2D}.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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.core;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for all component that can act as switches. They must have at least one position.
|
||||||
|
*
|
||||||
|
* @author Branislav Stojkovic
|
||||||
|
*/
|
||||||
|
public interface ISwitch {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a positive number of positions.
|
||||||
|
*/
|
||||||
|
int getPositionCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position
|
||||||
|
* @return name of switch positions, e.g. "ON", "OFF"...
|
||||||
|
*/
|
||||||
|
String getPositionName(int position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests control point connectivity.
|
||||||
|
*
|
||||||
|
* @param index1
|
||||||
|
* @param index2
|
||||||
|
* @param position
|
||||||
|
* @return true if the two points are connected in the given switch position, false otherwise.
|
||||||
|
*/
|
||||||
|
boolean arePointsConnected(int index1, int index2, int position);
|
||||||
|
}
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
package org.diylc.graph;
|
package org.diylc.graph;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Graph {
|
public class Graph {
|
||||||
|
|
||||||
private Dictionary<String, Position> positions;
|
private Set<Vertex> vertices = new HashSet<Vertex>();
|
||||||
private Set<Node> nodes;
|
|
||||||
|
|
||||||
public Graph() {
|
public Graph() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<String, Position> getPositions() {
|
public Set<Vertex> getVertices() {
|
||||||
return positions;
|
return vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Node> getNodes() {
|
public boolean verticesMatch(Graph other) {
|
||||||
return nodes;
|
return this.vertices.equals(other.vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean nodesMatch(Graph other) {
|
@Override
|
||||||
return this.nodes.equals(other.nodes);
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Vertex v : vertices) {
|
||||||
|
sb.append("\t").append(v.getNode1()).append(" - ").append(v.getNode2()).append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package org.diylc.graph;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GraphKey {
|
||||||
|
|
||||||
|
private List<Position> positions;
|
||||||
|
|
||||||
|
public GraphKey(List<Position> positions) {
|
||||||
|
super();
|
||||||
|
this.positions = positions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Position> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,25 @@
|
|||||||
package org.diylc.graph;
|
package org.diylc.graph;
|
||||||
|
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
|
|
||||||
public class Node {
|
public class Node {
|
||||||
|
|
||||||
private String type;
|
private IDIYComponent<?> component;
|
||||||
private String component;
|
private int pointIndex;
|
||||||
private String terminal;
|
|
||||||
|
|
||||||
public Node() {}
|
public Node(IDIYComponent<?> component, int pointIndex) {
|
||||||
|
super();
|
||||||
public String getType() {
|
this.component = component;
|
||||||
return type;
|
this.pointIndex = pointIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getComponent() {
|
public IDIYComponent<?> getComponent() {
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTerminal() {
|
public int getPointIndex() {
|
||||||
return terminal;
|
return pointIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,8 +27,7 @@ public class Node {
|
|||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((component == null) ? 0 : component.hashCode());
|
result = prime * result + ((component == null) ? 0 : component.hashCode());
|
||||||
result = prime * result + ((terminal == null) ? 0 : terminal.hashCode());
|
result = prime * result + pointIndex;
|
||||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,21 +45,13 @@ public class Node {
|
|||||||
return false;
|
return false;
|
||||||
} else if (!component.equals(other.component))
|
} else if (!component.equals(other.component))
|
||||||
return false;
|
return false;
|
||||||
if (terminal == null) {
|
if (pointIndex != other.pointIndex)
|
||||||
if (other.terminal != null)
|
|
||||||
return false;
|
|
||||||
} else if (!terminal.equals(other.terminal))
|
|
||||||
return false;
|
|
||||||
if (type == null) {
|
|
||||||
if (other.type != null)
|
|
||||||
return false;
|
|
||||||
} else if (!type.equals(other.type))
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return type + "." + component + "." + terminal;
|
return component.getName() + "." + pointIndex + " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
package org.diylc.graph;
|
package org.diylc.graph;
|
||||||
|
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.ISwitch;
|
||||||
|
|
||||||
public class Position {
|
public class Position {
|
||||||
|
|
||||||
private String ownerType;
|
private ISwitch theSwitch;
|
||||||
private String owner;
|
private int position;
|
||||||
private String name;
|
|
||||||
|
|
||||||
public Position() {
|
public Position(ISwitch theSwitch, int position) {
|
||||||
|
super();
|
||||||
|
this.theSwitch = theSwitch;
|
||||||
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwnerType() {
|
public ISwitch getSwitch() {
|
||||||
return ownerType;
|
return theSwitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwner() {
|
public int getPosition() {
|
||||||
return owner;
|
return position;
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + position;
|
||||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
result = prime * result + ((theSwitch == null) ? 0 : theSwitch.hashCode());
|
||||||
result = prime * result + ((ownerType == null) ? 0 : ownerType.hashCode());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,26 +40,18 @@ public class Position {
|
|||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Position other = (Position) obj;
|
Position other = (Position) obj;
|
||||||
if (name == null) {
|
if (position != other.position)
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
return false;
|
||||||
} else if (!name.equals(other.name))
|
if (theSwitch == null) {
|
||||||
|
if (other.theSwitch != null)
|
||||||
return false;
|
return false;
|
||||||
if (owner == null) {
|
} else if (!theSwitch.equals(other.theSwitch))
|
||||||
if (other.owner != null)
|
|
||||||
return false;
|
|
||||||
} else if (!owner.equals(other.owner))
|
|
||||||
return false;
|
|
||||||
if (ownerType == null) {
|
|
||||||
if (other.ownerType != null)
|
|
||||||
return false;
|
|
||||||
} else if (!ownerType.equals(other.ownerType))
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ownerType + "." + owner + "." + name;
|
return (theSwitch instanceof IDIYComponent<?> ? ((IDIYComponent<?>) theSwitch).getName() + "." : "") + theSwitch.getPositionName(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ public class Vertex {
|
|||||||
private Node node1;
|
private Node node1;
|
||||||
private Node node2;
|
private Node node2;
|
||||||
|
|
||||||
public Vertex() {
|
public Vertex(Node node1, Node node2) {
|
||||||
|
this.node1 = node1;
|
||||||
|
this.node2 = node2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getNode1() {
|
public Node getNode1() {
|
||||||
|
|||||||
@@ -487,19 +487,32 @@ public class DrawingManager {
|
|||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void findContinuityAreaAtPoint(Project project, Point p) {
|
public void findContinuityAreaAtPoint(Project project, Point p) {
|
||||||
|
List<Area> areas = getContinuityAreas(project);
|
||||||
|
|
||||||
|
for (Area a : areas) {
|
||||||
|
if (a.contains(p)) {
|
||||||
|
continuityArea = a;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continuityArea = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<Area> getContinuityAreas(Project project) {
|
||||||
// Find all individual continuity areas for all components
|
// Find all individual continuity areas for all components
|
||||||
List<Area> preliminaryAreas = new ArrayList<Area>();
|
List<Area> preliminaryAreas = new ArrayList<Area>();
|
||||||
List<Boolean> checkBreakout = new ArrayList<Boolean>();
|
List<Boolean> checkBreakout = new ArrayList<Boolean>();
|
||||||
List<Connection> connections = new ArrayList<Connection>();
|
List<Line2D> connections = new ArrayList<Line2D>();
|
||||||
for (IDIYComponent<?> c : project.getComponents()) {
|
for (IDIYComponent<?> c : project.getComponents()) {
|
||||||
ComponentArea a = getComponentArea(c);
|
ComponentArea a = getComponentArea(c);
|
||||||
|
|
||||||
ComponentType type =
|
ComponentType type =
|
||||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||||
if (type.isContinuity()) {
|
if (type.isContinuity()) {
|
||||||
connections.add(new Connection(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
|
connections.add(new Line2D.Double(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a == null || a.getOutlineArea() == null)
|
if (a == null || a.getOutlineArea() == null)
|
||||||
@@ -533,17 +546,17 @@ public class DrawingManager {
|
|||||||
|
|
||||||
crunchAreas(areas, connections);
|
crunchAreas(areas, connections);
|
||||||
|
|
||||||
for (Area a : areas) {
|
return areas;
|
||||||
if (a.contains(p)) {
|
|
||||||
continuityArea = a;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continuityArea = null;
|
/**
|
||||||
}
|
* Merges all areas that either overlap or are joined by connections.
|
||||||
|
*
|
||||||
private boolean crunchAreas(List<Area> areas, List<Connection> connections) {
|
* @param areas
|
||||||
|
* @param connections
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean crunchAreas(List<Area> areas, List<Line2D> connections) {
|
||||||
boolean isChanged = false;
|
boolean isChanged = false;
|
||||||
|
|
||||||
List<Area> newAreas = new ArrayList<Area>();
|
List<Area> newAreas = new ArrayList<Area>();
|
||||||
@@ -564,8 +577,8 @@ public class DrawingManager {
|
|||||||
a1.add(a2);
|
a1.add(a2);
|
||||||
consumed.set(j, true);
|
consumed.set(j, true);
|
||||||
} else { // maybe there's a connection between them
|
} else { // maybe there's a connection between them
|
||||||
for (Connection p : connections) {
|
for (Line2D p : connections) {
|
||||||
if ((a1.contains(p.pointA) && a2.contains(p.pointB)) || (a1.contains(p.pointB) && a2.contains(p.pointA))) {
|
if ((a1.contains(p.getP1()) && a2.contains(p.getP2())) || (a1.contains(p.getP2()) && a2.contains(p.getP1()))) {
|
||||||
a1.add(a2);
|
a1.add(a2);
|
||||||
consumed.set(j, true);
|
consumed.set(j, true);
|
||||||
break;
|
break;
|
||||||
@@ -624,24 +637,4 @@ public class DrawingManager {
|
|||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Connection {
|
|
||||||
|
|
||||||
private Point pointA;
|
|
||||||
private Point pointB;
|
|
||||||
|
|
||||||
public Connection(Point pointA, Point pointB) {
|
|
||||||
super();
|
|
||||||
this.pointA = pointA;
|
|
||||||
this.pointB = pointB;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point getPointA() {
|
|
||||||
return pointA;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Point getPointB() {
|
|
||||||
return pointB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.awt.Point;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.dnd.DnDConstants;
|
import java.awt.dnd.DnDConstants;
|
||||||
import java.awt.geom.Area;
|
import java.awt.geom.Area;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@@ -67,6 +68,7 @@ import org.diylc.common.PropertyWrapper;
|
|||||||
import org.diylc.common.VariantPackage;
|
import org.diylc.common.VariantPackage;
|
||||||
import org.diylc.core.ExpansionMode;
|
import org.diylc.core.ExpansionMode;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
import org.diylc.core.ISwitch;
|
||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
import org.diylc.core.Template;
|
import org.diylc.core.Template;
|
||||||
@@ -74,6 +76,11 @@ import org.diylc.core.Theme;
|
|||||||
import org.diylc.core.annotations.IAutoCreator;
|
import org.diylc.core.annotations.IAutoCreator;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
import org.diylc.core.measures.SizeUnit;
|
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.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
@@ -2677,4 +2684,271 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, newVariantMap);
|
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, newVariantMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Map<GraphKey, Graph> extractGraphs() {
|
||||||
|
Map<GraphKey, Graph> result = new HashMap<GraphKey, Graph>();
|
||||||
|
List<Node> nodes = new ArrayList<Node>();
|
||||||
|
|
||||||
|
List<ISwitch> switches = new ArrayList<ISwitch>();
|
||||||
|
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
||||||
|
ComponentType type =
|
||||||
|
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||||
|
// extract nodes
|
||||||
|
if (!type.isContinuity()) {
|
||||||
|
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||||
|
String nodeName = c.getControlPointNodeName(i);
|
||||||
|
if (nodeName != null) {
|
||||||
|
nodes.add(new Node(c, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract switches
|
||||||
|
if (ISwitch.class.isAssignableFrom(type.getInstanceClass()))
|
||||||
|
switches.add((ISwitch)c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save us the trouble
|
||||||
|
if (nodes.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// if there are no switches, make one with 1 position so we get 1 result back
|
||||||
|
if (switches.isEmpty())
|
||||||
|
switches.add(new ISwitch() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPositionName(int position) {
|
||||||
|
return "Default";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPositionCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean arePointsConnected(int index1, int index2, int position) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// construct all possible combinations
|
||||||
|
int[] positions = new int[switches.size()];
|
||||||
|
for (int i = 0; i < switches.size(); i++)
|
||||||
|
positions[i] = 0;
|
||||||
|
|
||||||
|
// grab continuity areas
|
||||||
|
List<Area> continuity = drawingManager.getContinuityAreas(currentProject);
|
||||||
|
|
||||||
|
int i = switches.size() - 1;
|
||||||
|
while (i >= 0) {
|
||||||
|
// process the current combination
|
||||||
|
Map<ISwitch, Integer> switchPositions = new HashMap<ISwitch, Integer>();
|
||||||
|
List<Position> posList = new ArrayList<Position>();
|
||||||
|
for (int j = 0; j < positions.length; j++) {
|
||||||
|
switchPositions.put(switches.get(j), positions[j]);
|
||||||
|
posList.add(new Position(switches.get(j), positions[j]));
|
||||||
|
}
|
||||||
|
List<Line2D> connections = getConnections(switchPositions);
|
||||||
|
Graph graph = constructGraph(nodes, connections, continuity);
|
||||||
|
result.put(new GraphKey(posList), graph);
|
||||||
|
|
||||||
|
// find the next combination if possible
|
||||||
|
if (positions[i] < switches.get(i).getPositionCount() - 1) {
|
||||||
|
positions[i]++;
|
||||||
|
} else {
|
||||||
|
while (i >= 0 && positions[i] == switches.get(i).getPositionCount() - 1)
|
||||||
|
i--;
|
||||||
|
if (i >= 0) {
|
||||||
|
positions[i]++;
|
||||||
|
for (int j = i + 1; j < positions.length; j++)
|
||||||
|
positions[j] = 0;
|
||||||
|
i = switches.size() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Graph constructGraph(List<Node> nodes, List<Line2D> connections, List<Area> continuityAreas) {
|
||||||
|
Graph graph = new Graph();
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Nodes:").append("\n");
|
||||||
|
for (Node n : nodes) {
|
||||||
|
sb.append(n.toString()).append("\n");
|
||||||
|
}
|
||||||
|
sb.append("Connections:").append("\n");
|
||||||
|
for (Line2D n : connections) {
|
||||||
|
sb.append(n.getP1()).append(":").append(n.getP2()).append("\n");
|
||||||
|
}
|
||||||
|
LOG.debug(sb.toString());
|
||||||
|
|
||||||
|
double t = DrawingManager.CONTROL_POINT_SIZE;
|
||||||
|
for (int i = 0; i < nodes.size() - 1; i++)
|
||||||
|
for (int j = i + 1; j < nodes.size(); j++) {
|
||||||
|
Node node1 = nodes.get(i);
|
||||||
|
Node node2 = nodes.get(j);
|
||||||
|
Point2D point1 = node1.getComponent().getControlPoint(node1.getPointIndex());
|
||||||
|
Point2D point2 = node2.getComponent().getControlPoint(node2.getPointIndex());
|
||||||
|
|
||||||
|
// try both directions
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkGraphConnection(Point2D point1, Point2D point2, List<Line2D> connections,
|
||||||
|
List<Area> continuityAreas, boolean[] visited) {
|
||||||
|
double t = DrawingManager.CONTROL_POINT_SIZE;
|
||||||
|
|
||||||
|
if (point1.distance(point2) < t)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (Area a : continuityAreas) {
|
||||||
|
if (a.contains(point1) && a.contains(point2))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < connections.size(); i++) {
|
||||||
|
if (visited[i])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Line2D c = connections.get(i);
|
||||||
|
if (point1.distance(c.getP1()) < t) {
|
||||||
|
visited[i] = true;
|
||||||
|
if (checkGraphConnection(c.getP2(), point2, connections, continuityAreas, visited))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (point1.distance(c.getP2()) < t) {
|
||||||
|
visited[i] = true;
|
||||||
|
if (checkGraphConnection(c.getP1(), point2, connections, continuityAreas, visited))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private List<Line2D> getConnections(Map<ISwitch, Integer> switchPositions) {
|
||||||
|
List<Line2D> connections = new ArrayList<Line2D>();
|
||||||
|
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
||||||
|
ComponentType type =
|
||||||
|
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||||
|
// handle direct connections
|
||||||
|
if (type.isContinuity()) {
|
||||||
|
connections.add(new Line2D.Double(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
|
||||||
|
}
|
||||||
|
// handle switches
|
||||||
|
if (ISwitch.class.isAssignableFrom(type.getInstanceClass()) && switchPositions.containsKey(c)) {
|
||||||
|
int position = switchPositions.get(c);
|
||||||
|
ISwitch s = (ISwitch)c;
|
||||||
|
for (int i = 0; i < c.getControlPointCount() - 1; i++)
|
||||||
|
for (int j = i + 1; j < c.getControlPointCount(); j++)
|
||||||
|
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
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,4 +164,9 @@ public class MockDIYComponent extends AbstractComponent<Capacitance> {
|
|||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
g2d.drawString("X", 10, 10);
|
g2d.drawString("X", 10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -124,6 +124,11 @@ public class BlankBoard extends AbstractBoard {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
static enum Type {
|
static enum Type {
|
||||||
ROUND, SQUARE;
|
ROUND, SQUARE;
|
||||||
|
|
||||||
|
|||||||
@@ -366,6 +366,11 @@ public class Breadboard extends AbstractComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public enum BreadboardSize {
|
public enum BreadboardSize {
|
||||||
Half, Full
|
Half, Full
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,11 @@ public class EyeletBoard extends AbstractBoard {
|
|||||||
this.spacing = spacing;
|
this.spacing = spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
int factor = 32 / width;
|
int factor = 32 / width;
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ public class MarshallPerfBoard extends AbstractBoard {
|
|||||||
this.spacing = spacing;
|
this.spacing = spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
int factor = 32 / width;
|
int factor = 32 / width;
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ public class PerfBoard extends AbstractBoard {
|
|||||||
this.spacing = spacing;
|
this.spacing = spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
int factor = 32 / width;
|
int factor = 32 / width;
|
||||||
|
|||||||
@@ -450,4 +450,9 @@ public class TerminalStrip extends AbstractTransparentComponent<String> {
|
|||||||
public void setBorderColor(Color borderColor) {
|
public void setBorderColor(Color borderColor) {
|
||||||
this.borderColor = borderColor;
|
this.borderColor = borderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return "TerminalStrip" + index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,4 +237,9 @@ public class TriPadBoard extends AbstractBoard {
|
|||||||
this.stripSpan = stripSpan;
|
this.stripSpan = stripSpan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,6 +150,11 @@ public class VeroBoard extends AbstractBoard {
|
|||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
int factor = 32 / width;
|
int factor = 32 / width;
|
||||||
|
|||||||
@@ -162,4 +162,9 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
|
|||||||
protected boolean IsCopperArea() {
|
protected boolean IsCopperArea() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,4 +111,9 @@ public class CurvedTrace extends AbstractCurvedComponent<Void> {
|
|||||||
public LineStyle getStyle() {
|
public LineStyle getStyle() {
|
||||||
return super.getStyle();
|
return super.getStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,4 +157,9 @@ public class CutLine extends AbstractTransparentComponent<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,4 +127,9 @@ public class Dot extends AbstractComponent<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,4 +165,9 @@ public class Eyelet extends AbstractComponent<String> {
|
|||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,11 @@ public class GroundFill extends AbstractComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||||
int factor = 32 / width;
|
int factor = 32 / width;
|
||||||
|
|||||||
@@ -264,6 +264,11 @@ public class Line extends AbstractLeadedComponent<Void> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public Color getLabelColor() {
|
public Color getLabelColor() {
|
||||||
|
|||||||
@@ -183,6 +183,11 @@ public class SolderPad extends AbstractComponent<Void> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
|||||||
@@ -231,4 +231,9 @@ public class TraceCut extends AbstractComponent<Void> {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return super.getName();
|
return super.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,4 +163,9 @@ public class Turret extends AbstractComponent<String> {
|
|||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -426,9 +426,7 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum RelayType {
|
public static enum RelayType {
|
||||||
|
|
||||||
SPDT, DPDT;
|
SPDT, DPDT;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum RelaySize {
|
public static enum RelaySize {
|
||||||
|
|||||||
+48
-1
@@ -39,6 +39,7 @@ import org.diylc.components.AbstractTransparentComponent;
|
|||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.IDrawingObserver;
|
import org.diylc.core.IDrawingObserver;
|
||||||
|
import org.diylc.core.ISwitch;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
import org.diylc.core.Theme;
|
import org.diylc.core.Theme;
|
||||||
import org.diylc.core.VisibilityPolicy;
|
import org.diylc.core.VisibilityPolicy;
|
||||||
@@ -52,7 +53,7 @@ import org.diylc.utils.Constants;
|
|||||||
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
@ComponentDescriptor(name = "Mini Toggle Switch", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||||
description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
description = "Panel mounted mini toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||||
instanceNamePrefix = "SW", autoEdit = false)
|
instanceNamePrefix = "SW", autoEdit = false)
|
||||||
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> {
|
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> implements ISwitch {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@@ -378,4 +379,50 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
|
|||||||
public void setBorderColor(Color borderColor) {
|
public void setBorderColor(Color borderColor) {
|
||||||
this.borderColor = borderColor;
|
this.borderColor = borderColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch stuff
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
// we don't want the switch to produce any nodes, it just makes connections
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPositionCount() {
|
||||||
|
switch (switchType) {
|
||||||
|
case SPST:
|
||||||
|
case SPDT:
|
||||||
|
case DPDT:
|
||||||
|
case _3PDT:
|
||||||
|
case _4PDT:
|
||||||
|
case _5PDT:
|
||||||
|
return 2;
|
||||||
|
case _DP3T_mustang:
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPositionName(int position) {
|
||||||
|
return Integer.toString(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean arePointsConnected(int index1, int index2, int position) {
|
||||||
|
switch (switchType) {
|
||||||
|
case SPST:
|
||||||
|
return position == 1;
|
||||||
|
case SPDT:
|
||||||
|
case DPDT:
|
||||||
|
case _3PDT:
|
||||||
|
case _4PDT:
|
||||||
|
case _5PDT:
|
||||||
|
return (index2 - index1) < 3 && index1 % 3 == position && index2 % 3 == position + 1;
|
||||||
|
case _DP3T_mustang:
|
||||||
|
return (index2 - index1) < 3 && index1 % 3 == 0 && index2 % 3 == position + 1;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,4 +315,9 @@ public class RCAJack extends AbstractMultiPartComponent<String> {
|
|||||||
// Invalidate the body
|
// Invalidate the body
|
||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + (index == 0 ? "Tip" : "Sleeve");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -569,6 +569,11 @@ public class HumbuckerPickup extends AbstractTransparentComponent<String> {
|
|||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return "PickupTerminal";
|
||||||
|
}
|
||||||
|
|
||||||
public static enum HumbuckerType {
|
public static enum HumbuckerType {
|
||||||
|
|
||||||
PAF(WIDTH, LENGTH, POLE_SIZE), Mini(WIDTH_MINI, LENGTH_MINI, POLE_SIZE), Filtertron(WIDTH_FILTERTRON, LENGTH_FILTERTRON, POLE_SIZE_FILTERTRON);
|
PAF(WIDTH, LENGTH, POLE_SIZE), Mini(WIDTH_MINI, LENGTH_MINI, POLE_SIZE), Filtertron(WIDTH_FILTERTRON, LENGTH_FILTERTRON, POLE_SIZE_FILTERTRON);
|
||||||
|
|||||||
@@ -326,4 +326,9 @@ public class JazzBassPickup extends AbstractTransparentComponent<String> {
|
|||||||
public void setPoleColor(Color poleColor) {
|
public void setPoleColor(Color poleColor) {
|
||||||
this.poleColor = poleColor;
|
this.poleColor = poleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + ".PickupTerminal";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,6 +351,11 @@ public class P90Pickup extends AbstractTransparentComponent<String> {
|
|||||||
this.poleColor = poleColor;
|
this.poleColor = poleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + ".PickupTerminal";
|
||||||
|
}
|
||||||
|
|
||||||
public enum P90Type {
|
public enum P90Type {
|
||||||
DOG_EAR("Dog Ear", DOG_EAR_LENGTH, DOG_EAR_WIDTH, DOG_EAR_EDGE_RADIUS), SOAP_BAR("Soap Bar", SOAP_BAR_LENGTH,
|
DOG_EAR("Dog Ear", DOG_EAR_LENGTH, DOG_EAR_WIDTH, DOG_EAR_EDGE_RADIUS), SOAP_BAR("Soap Bar", SOAP_BAR_LENGTH,
|
||||||
SOAP_BAR_WIDTH, SOAP_BAR_EDGE_RADIUS);
|
SOAP_BAR_WIDTH, SOAP_BAR_EDGE_RADIUS);
|
||||||
|
|||||||
@@ -314,4 +314,9 @@ public class PBassPickup extends AbstractTransparentComponent<String> {
|
|||||||
public void setPoleColor(Color poleColor) {
|
public void setPoleColor(Color poleColor) {
|
||||||
this.poleColor = poleColor;
|
this.poleColor = poleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + ".PickupTerminal";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -466,6 +466,11 @@ public class SingleCoilPickup extends AbstractTransparentComponent<String> {
|
|||||||
this.poleColor = poleColor;
|
this.poleColor = poleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + ".PickupTerminal";
|
||||||
|
}
|
||||||
|
|
||||||
public enum SingleCoilType {
|
public enum SingleCoilType {
|
||||||
Stratocaster, Telecaster;
|
Stratocaster, Telecaster;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ public class BOM extends AbstractComponent<Void> {
|
|||||||
private Point point = new Point(0, 0);
|
private Point point = new Point(0, 0);
|
||||||
private Color color = COLOR;
|
private Color color = COLOR;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||||
IDrawingObserver drawingObserver) {
|
IDrawingObserver drawingObserver) {
|
||||||
|
|||||||
@@ -132,5 +132,8 @@ public class BatterySymbol extends AbstractSchematicLeadedSymbol<String> {
|
|||||||
* width / 32);
|
* width / 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + "." + (index == 0 ? "+" : "-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,11 @@ public class GroundSymbol extends AbstractComponent<Void> {
|
|||||||
this.point = point;
|
this.point = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||||
return VisibilityPolicy.WHEN_SELECTED;
|
return VisibilityPolicy.WHEN_SELECTED;
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private Point point = new Point(0, 0);
|
private Point point = new Point(0, 0);
|
||||||
@XStreamConverter(IconImageConverter.class)
|
@XStreamConverter(IconImageConverter.class)
|
||||||
private ImageIcon image = ICON;
|
private ImageIcon image = ICON;
|
||||||
|
|||||||
@@ -283,4 +283,9 @@ public class Label extends AbstractComponent<String> {
|
|||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.text = value;
|
this.text = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -312,4 +312,9 @@ public class PCBText extends AbstractComponent<Void> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,4 +117,9 @@ public class BJTSymbol extends Abstract3LegSymbol {
|
|||||||
|
|
||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return getName() + "." + index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ public abstract class AbstractShape extends AbstractTransparentComponent<Void> {
|
|||||||
Math.max(controlPoints[0].y, controlPoints[1].y));
|
Math.max(controlPoints[0].y, controlPoints[1].y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getControlPointNodeName(int index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public Void getValue() {
|
public Void getValue() {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -2440,7 +2440,7 @@
|
|||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Better rendering of TO-3 transformer package</description>
|
<description>Better rendering of TO-3 transistor package</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
|
|||||||
Reference in New Issue
Block a user