mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 01:02:08 +10:00
Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bb3b37f23b | |||
| fcea5975a8 | |||
| 2294ac45a2 | |||
| 5598f22b2f | |||
| 812b7adb28 | |||
| 9fd5a8fe96 | |||
| 0b8952e354 | |||
| 5c47ff1ef0 | |||
| b85b93404b | |||
| b46f46aa99 | |||
| 48266d3b27 | |||
| eb6cc76f02 | |||
| a5d512ca37 | |||
| 1d038b5f8c | |||
| 9366f9c602 | |||
| 23b4fcae02 | |||
| 14a994e68f | |||
| 894ff1a2cb | |||
| 78dcd27e1d | |||
| 714db98afa | |||
| 2faa2c6d61 | |||
| 3c45336afe | |||
| a0601cc83d | |||
| 9925d58347 | |||
| 6c241b3180 | |||
| 838adc9a51 | |||
| 41d2b73cca | |||
| 8d3789a0b0 | |||
| 95f65dcdf1 | |||
| 3d0f9554b0 | |||
| 0c21e013b4 | |||
| f8e24b0937 | |||
| 37d5ce18fc | |||
| e9a2785344 | |||
| 4de3b6d97c | |||
| 92a2bb9809 | |||
| 440b953531 | |||
| 1bc11e09ab | |||
| f20b896184 | |||
| 49d93b42a4 | |||
| b279510e5c | |||
| a83cda9ecd | |||
| f63b422a8c | |||
| 7af919b303 | |||
| 1c1ec2fcf5 | |||
| 8ccdd84a6f | |||
| 54ff518438 | |||
| c893b37fdf | |||
| 81e259bb62 | |||
| d5aac6b265 | |||
| d544797047 | |||
| 8ed2c0c9a5 | |||
| 2d1cf515d6 | |||
| 2553ffbba7 |
@@ -19,6 +19,7 @@
|
||||
<li>group components together and treat them as one, e.g. move, edit or delete </li>
|
||||
<li>export the output to image, PDF or printer </li>
|
||||
<li>export PCB trace mask suitable for toner transfer </li>
|
||||
<li>export the circuit to a SPICE compatible netlist (beta) </li>
|
||||
<li>create a Bill of Materials as a part of the project or export it to few different file formats </li>
|
||||
<li>analyze guitar wirings and show detailed pickup configuration in each switch configuration</li>
|
||||
<li>zoom in/out feature </li>
|
||||
|
||||
@@ -21,23 +21,23 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class BuildingBlockPackage {
|
||||
|
||||
private Map<String, Collection<IDIYComponent<?>>> block;
|
||||
private Map<String, List<IDIYComponent<?>>> block;
|
||||
private String owner;
|
||||
|
||||
public BuildingBlockPackage(Map<String, Collection<IDIYComponent<?>>> blocks, String owner) {
|
||||
public BuildingBlockPackage(Map<String, List<IDIYComponent<?>>> blocks, String owner) {
|
||||
super();
|
||||
this.block = blocks;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public Map<String, Collection<IDIYComponent<?>>> getBlocks() {
|
||||
public Map<String, List<IDIYComponent<?>>> getBlocks() {
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,18 +43,16 @@ public class ComponentType {
|
||||
private Class<? extends IDIYComponent<?>> instanceClass;
|
||||
private double zOrder;
|
||||
private boolean flexibleZOrder;
|
||||
private boolean stretchable;
|
||||
private BomPolicy bomPolicy;
|
||||
private boolean autoEdit;
|
||||
private IComponentTransformer transformer;
|
||||
private KeywordPolicy keywordPolicy;
|
||||
private String keywordTag;
|
||||
private boolean continuity;
|
||||
|
||||
public ComponentType(String name, String description, CreationMethod creationMethod, String category,
|
||||
String namePrefix, String author, Icon icon, Class<? extends IDIYComponent<?>> instanceClass, double zOrder,
|
||||
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit,
|
||||
IComponentTransformer transformer, KeywordPolicy keywordPolicy, String keywordTag, boolean continuity) {
|
||||
boolean flexibleZOrder, BomPolicy bomPolicy, boolean autoEdit, IComponentTransformer transformer,
|
||||
KeywordPolicy keywordPolicy, String keywordTag) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -66,13 +64,11 @@ public class ComponentType {
|
||||
this.instanceClass = instanceClass;
|
||||
this.zOrder = zOrder;
|
||||
this.flexibleZOrder = flexibleZOrder;
|
||||
this.stretchable = stretchable;
|
||||
this.bomPolicy = bomPolicy;
|
||||
this.autoEdit = autoEdit;
|
||||
this.transformer = transformer;
|
||||
this.keywordPolicy = keywordPolicy;
|
||||
this.keywordTag = keywordTag;
|
||||
this.continuity = continuity;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -115,10 +111,6 @@ public class ComponentType {
|
||||
return flexibleZOrder;
|
||||
}
|
||||
|
||||
public boolean isStretchable() {
|
||||
return stretchable;
|
||||
}
|
||||
|
||||
public BomPolicy getBomPolicy() {
|
||||
return bomPolicy;
|
||||
}
|
||||
@@ -139,10 +131,6 @@ public class ComponentType {
|
||||
return keywordTag;
|
||||
}
|
||||
|
||||
public boolean isContinuity() {
|
||||
return continuity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
|
||||
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.io.Serializable;
|
||||
|
||||
public class Favorite implements Serializable, Comparable<Favorite> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private FavoriteType type;
|
||||
private String name;
|
||||
|
||||
public Favorite(FavoriteType type, String name) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public FavoriteType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.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;
|
||||
Favorite other = (Favorite) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (type != other.type)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type + ":" + name;
|
||||
}
|
||||
|
||||
public enum FavoriteType {
|
||||
Component, Block
|
||||
}
|
||||
|
||||
public String toDisplay() {
|
||||
String[] parts = name.split("\\.");
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Favorite o) {
|
||||
return toDisplay().compareToIgnoreCase(o.toDisplay());
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import java.util.List;
|
||||
import org.diylc.netlist.Netlist;
|
||||
import org.diylc.netlist.Node;
|
||||
import org.diylc.netlist.Summary;
|
||||
import org.diylc.netlist.Tree;
|
||||
import org.diylc.netlist.TreeException;
|
||||
|
||||
public interface INetlistAnalyzer {
|
||||
@@ -52,10 +51,7 @@ public interface INetlistAnalyzer {
|
||||
List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param netlist
|
||||
* @return
|
||||
* @throws TreeException
|
||||
* @return name of the font to be used for display.
|
||||
*/
|
||||
Tree constructTree(Netlist netlist) throws TreeException;
|
||||
String getFontName();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,10 @@ public interface INetlistProcessor {
|
||||
/**
|
||||
* Finds all {@link Netlist}s for each switch position combination.
|
||||
*
|
||||
* @param includeSwitches
|
||||
* @return
|
||||
*/
|
||||
List<Netlist> extractNetlists();
|
||||
List<Netlist> extractNetlists(boolean includeSwitches);
|
||||
|
||||
/**
|
||||
* Finds all available {@link INetlistAnalyzer} implementations.
|
||||
|
||||
@@ -75,6 +75,7 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
public static final String HIGHLIGHT_CONTINUITY_AREA = "highlightContinuityArea";
|
||||
public static final String HARDWARE_ACCELERATION = "hardwareAcceleration";
|
||||
public static final String EXTRA_SPACE_KEY = "extraSpace";
|
||||
public static final String FAVORITES_KEY = "favorites";
|
||||
|
||||
public static final int DND_TOGGLE_STICKY = 0x1;
|
||||
public static final int DND_TOGGLE_SNAP = 0x40000000;
|
||||
@@ -121,8 +122,9 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
||||
*
|
||||
* @param project
|
||||
* @param freshStart
|
||||
* @param optional file name when loading from a file
|
||||
*/
|
||||
void loadProject(Project project, boolean freshStart);
|
||||
void loadProject(Project project, boolean freshStart, String filename);
|
||||
|
||||
/**
|
||||
* Creates a new project.
|
||||
|
||||
@@ -23,21 +23,14 @@ package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@@ -147,54 +140,6 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
return !clip.intersects(rect);
|
||||
}
|
||||
|
||||
protected void drawCenteredText(Graphics2D g2d, String text, int x, int y, HorizontalAlignment horizontalAlignment,
|
||||
VerticalAlignment verticalAlignment) {
|
||||
String[] parts = text.split("\n");
|
||||
if (parts.length > 1) {
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle stringBounds = fontMetrics.getStringBounds(parts[0], g2d).getBounds();
|
||||
for (int i = 0; i < parts.length; i++)
|
||||
drawCenteredText(g2d, parts[i], x, (int)(y - stringBounds.height * (parts.length - 1) / 2d + i * stringBounds.height), horizontalAlignment, verticalAlignment);
|
||||
return;
|
||||
}
|
||||
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle stringBounds = fontMetrics.getStringBounds(text, g2d).getBounds();
|
||||
|
||||
Font font = g2d.getFont();
|
||||
FontRenderContext renderContext = g2d.getFontRenderContext();
|
||||
GlyphVector glyphVector = font.createGlyphVector(renderContext, text);
|
||||
Rectangle visualBounds = glyphVector.getVisualBounds().getBounds();
|
||||
|
||||
int textX = 0;
|
||||
switch (horizontalAlignment) {
|
||||
case CENTER:
|
||||
textX = x - stringBounds.width / 2;
|
||||
break;
|
||||
case LEFT:
|
||||
textX = x;
|
||||
break;
|
||||
case RIGHT:
|
||||
textX = x - stringBounds.width;
|
||||
break;
|
||||
}
|
||||
|
||||
int textY = 0;
|
||||
switch (verticalAlignment) {
|
||||
case TOP:
|
||||
textY = y + stringBounds.height;
|
||||
break;
|
||||
case CENTER:
|
||||
textY = y - visualBounds.height / 2 - visualBounds.y;
|
||||
break;
|
||||
case BOTTOM:
|
||||
textY = y - visualBounds.y;
|
||||
break;
|
||||
}
|
||||
|
||||
g2d.drawString(text, textX, textY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public IDIYComponent<T> clone() throws CloneNotSupportedException {
|
||||
try {
|
||||
@@ -292,4 +237,19 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSectionNames(int pointIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonPointName(int pointIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
public interface IContinuity {
|
||||
|
||||
/**
|
||||
* Tests control point connectivity.
|
||||
*
|
||||
* @param index1
|
||||
* @param index2
|
||||
* @return true if the two points are connected, false otherwise.
|
||||
*/
|
||||
boolean arePointsConnected(int index1, int index2);
|
||||
}
|
||||
@@ -130,6 +130,25 @@ public interface IDIYComponent<T> extends Serializable {
|
||||
*/
|
||||
String getInternalLinkName(int index1, int index2);
|
||||
|
||||
/**
|
||||
* @param pointIndex
|
||||
* @return name of the internal section containing the specified point, or null if the component does not have internal sections.
|
||||
* One point can be shared between multiple sections, in which case, the result may contain more than one element.
|
||||
*/
|
||||
String[] getSectionNames(int pointIndex);
|
||||
|
||||
/**
|
||||
* @param pointIndex
|
||||
* @return name of the common point that joins all the other points with the same name together, e.g. GND
|
||||
*/
|
||||
String getCommonPointName(int pointIndex);
|
||||
|
||||
/**
|
||||
* @param pointIndex
|
||||
* @return true if the control point can move without affecting other points' position, false otherwise
|
||||
*/
|
||||
boolean canPointMoveFreely(int pointIndex);
|
||||
|
||||
/**
|
||||
* Draws the component onto the {@link Graphics2D}.
|
||||
*
|
||||
|
||||
@@ -82,12 +82,6 @@ public @interface ComponentDescriptor {
|
||||
*/
|
||||
boolean flexibleZOrder() default false;
|
||||
|
||||
/**
|
||||
* @return when false, moving one control point will cause all the others to move together with
|
||||
* it.
|
||||
*/
|
||||
boolean stretchable() default true;
|
||||
|
||||
/**
|
||||
* @return controls what should be shown the BOM
|
||||
*/
|
||||
@@ -117,12 +111,4 @@ public @interface ComponentDescriptor {
|
||||
* @return
|
||||
*/
|
||||
String keywordTag() default "";
|
||||
|
||||
/**
|
||||
* For components that show continuity between the two ending points, e.d. wires, jumpers, etc.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean continuity() default false;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -28,10 +27,27 @@ import java.util.Set;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class NetlistAnalyzer {
|
||||
public abstract class NetlistAnalyzer {
|
||||
|
||||
public NetlistAnalyzer() {}
|
||||
|
||||
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
|
||||
Map<String, Summary> summaries = new HashMap<String, Summary>();
|
||||
for (Netlist n : netlists) {
|
||||
Summary s = summarize(n, preferredOutput);
|
||||
if (summaries.containsKey(s.getSummary()))
|
||||
summaries.get(s.getSummary()).append(n);
|
||||
else
|
||||
summaries.put(s.getSummary(), s);
|
||||
}
|
||||
|
||||
List<Summary> res = new ArrayList<Summary>(summaries.values());
|
||||
Collections.sort(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected abstract Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException;
|
||||
|
||||
public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) {
|
||||
Tree tree = new Tree(TreeConnectionType.Parallel);
|
||||
connectNodes(netlist, nodeA, nodeB, tree.getChildren(), new Tree(TreeConnectionType.Series), new HashSet<Node>());
|
||||
@@ -199,45 +215,45 @@ public class NetlistAnalyzer {
|
||||
paths.addAll(unmerged);
|
||||
}
|
||||
}
|
||||
|
||||
protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath,
|
||||
List<List<TreeLeaf>> allPaths, Set<Node> visited) {
|
||||
if (nodeA == nodeB) {
|
||||
allPaths.add(currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
// System.out.println("Finding path between " + nodeA + " and " + nodeB);
|
||||
|
||||
Group groupA = findGroup(netlist, nodeA);
|
||||
|
||||
if (groupA == null)
|
||||
return;
|
||||
|
||||
if (groupA.getNodes().contains(nodeB)) {
|
||||
allPaths.add(currentPath);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Node n : groupA.getNodes()) {
|
||||
IDIYComponent<?> c = n.getComponent();
|
||||
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
|
||||
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
|
||||
Node newNodeA = new Node(c, i);
|
||||
if (!visited.contains(newNodeA)) {
|
||||
List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath);
|
||||
if (!currentPath.contains(l))
|
||||
newCurrentPath.add(l);
|
||||
Set<Node> newVisited = new HashSet<Node>(visited);
|
||||
newVisited.add(nodeA);
|
||||
newVisited.add(newNodeA);
|
||||
findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath,
|
||||
// List<List<TreeLeaf>> allPaths, Set<Node> visited) {
|
||||
// if (nodeA == nodeB) {
|
||||
// allPaths.add(currentPath);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // System.out.println("Finding path between " + nodeA + " and " + nodeB);
|
||||
//
|
||||
// Group groupA = findGroup(netlist, nodeA);
|
||||
//
|
||||
// if (groupA == null)
|
||||
// return;
|
||||
//
|
||||
// if (groupA.getNodes().contains(nodeB)) {
|
||||
// allPaths.add(currentPath);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// for (Node n : groupA.getNodes()) {
|
||||
// IDIYComponent<?> c = n.getComponent();
|
||||
// for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||
// if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
|
||||
// TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
|
||||
// Node newNodeA = new Node(c, i);
|
||||
// if (!visited.contains(newNodeA)) {
|
||||
// List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath);
|
||||
// if (!currentPath.contains(l))
|
||||
// newCurrentPath.add(l);
|
||||
// Set<Node> newVisited = new HashSet<Node>(visited);
|
||||
// newVisited.add(nodeA);
|
||||
// newVisited.add(newNodeA);
|
||||
// findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
protected Group findGroup(Netlist netlist, Node node) {
|
||||
for (Group g : netlist.getGroups())
|
||||
@@ -246,62 +262,62 @@ public class NetlistAnalyzer {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
// List<Group> res = new ArrayList<Group>();
|
||||
// for (Group g : netlist.getGroups()) {
|
||||
// for (Node n : g.getNodes()) {
|
||||
// if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
// res.add(g);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Group group) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
// protected List<Node> find(Set<String> typeNames, String nodeName, Group group) {
|
||||
// List<Node> res = new ArrayList<Node>();
|
||||
//
|
||||
// for (Node n : group.getNodes()) {
|
||||
// if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
// res.add(n);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
|
||||
for (Node n : group.getNodes()) {
|
||||
if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(n);
|
||||
}
|
||||
}
|
||||
// protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
// List<Group> res = new ArrayList<Group>();
|
||||
// for (Group g : netlist.getGroups()) {
|
||||
// for (Node n : g.getNodes()) {
|
||||
// if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
// res.add(g);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist,
|
||||
Collection<IDIYComponent<?>> belongTo) {
|
||||
List<Group> res = new ArrayList<Group>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if ((belongTo == null || belongTo.contains(n.getComponent()))
|
||||
&& (typeNames.contains(n.getComponent().getClass().getCanonicalName()))
|
||||
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(g);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist,
|
||||
// Collection<IDIYComponent<?>> belongTo) {
|
||||
// List<Group> res = new ArrayList<Group>();
|
||||
// for (Group g : netlist.getGroups()) {
|
||||
// for (Node n : g.getNodes()) {
|
||||
// if ((belongTo == null || belongTo.contains(n.getComponent()))
|
||||
// && (typeNames.contains(n.getComponent().getClass().getCanonicalName()))
|
||||
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
// res.add(g);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
@@ -316,119 +332,153 @@ public class NetlistAnalyzer {
|
||||
return res;
|
||||
}
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
// protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
|
||||
// List<Node> res = new ArrayList<Node>();
|
||||
// for (Group g : netlist.getGroups()) {
|
||||
//
|
||||
// boolean inGroup;
|
||||
// if (inGroupWith == null) {
|
||||
// inGroup = true;
|
||||
// } else {
|
||||
// inGroup = true;
|
||||
// for (Node n1 : inGroupWith)
|
||||
// if (!g.getNodes().contains(n1)) {
|
||||
// inGroup = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (Node n : g.getNodes()) {
|
||||
// if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
// res.add(n);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
|
||||
boolean inGroup;
|
||||
if (inGroupWith == null) {
|
||||
inGroup = true;
|
||||
} else {
|
||||
inGroup = true;
|
||||
for (Node n1 : inGroupWith)
|
||||
if (!g.getNodes().contains(n1)) {
|
||||
inGroup = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist,
|
||||
// Collection<IDIYComponent<?>> belongTo) {
|
||||
// List<Node> res = new ArrayList<Node>();
|
||||
// for (Group g : netlist.getGroups()) {
|
||||
//
|
||||
// for (Node n : g.getNodes()) {
|
||||
// if ((belongTo == null || belongTo.contains(n.getComponent()))
|
||||
// && typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
// res.add(n);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return res;
|
||||
// }
|
||||
|
||||
for (Node n : g.getNodes()) {
|
||||
if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// protected boolean allMatch(Collection<Node> nodes, String name) {
|
||||
// for (Node n : nodes)
|
||||
// if (!n.getDisplayName().equalsIgnoreCase(name))
|
||||
// return false;
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist,
|
||||
Collection<IDIYComponent<?>> belongTo) {
|
||||
List<Node> res = new ArrayList<Node>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
|
||||
for (Node n : g.getNodes()) {
|
||||
if ((belongTo == null || belongTo.contains(n.getComponent()))
|
||||
&& typeNames.contains(n.getComponent().getClass().getCanonicalName())
|
||||
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
|
||||
res.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected boolean allMatch(Collection<Node> nodes, String name) {
|
||||
for (Node n : nodes)
|
||||
if (!n.getDisplayName().equalsIgnoreCase(name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
|
||||
Set<IDIYComponent<?>> extracted = extractComponents(nodes);
|
||||
return extracted.containsAll(components);
|
||||
}
|
||||
|
||||
protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
|
||||
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
|
||||
for (Node n : nodes)
|
||||
components.add(n.getComponent());
|
||||
return components;
|
||||
}
|
||||
// protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
|
||||
// Set<IDIYComponent<?>> extracted = extractComponents(nodes);
|
||||
// return extracted.containsAll(components);
|
||||
// }
|
||||
//
|
||||
// protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
|
||||
// Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
|
||||
// for (Node n : nodes)
|
||||
// components.add(n.getComponent());
|
||||
// return components;
|
||||
// }
|
||||
|
||||
protected String extractName(IDIYComponent<?> c) {
|
||||
return c.getName() + " " + c.getValueForDisplay();
|
||||
}
|
||||
|
||||
protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (IDIYComponent<?> c : components)
|
||||
names.add(c.getName() + " " + c.getValueForDisplay());
|
||||
Collections.sort(names);
|
||||
return names;
|
||||
public static List<Set<IDIYComponent<?>>> extractComponentGroups(List<Netlist> netlists) {
|
||||
List<Set<IDIYComponent<?>>> res = new ArrayList<Set<IDIYComponent<?>>>();
|
||||
for (Netlist n : netlists) {
|
||||
res.addAll(extractComponentGroups(n));
|
||||
}
|
||||
|
||||
protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) {
|
||||
Netlist res = new Netlist();
|
||||
res.getSwitchSetup().addAll(netlist.getSwitchSetup());
|
||||
|
||||
Group merged = new Group();
|
||||
|
||||
// merge
|
||||
for (Group g : netlist.getGroups()) {
|
||||
boolean needsMerging = false;
|
||||
for (Node n : nodesToMerge) {
|
||||
if (g.getNodes().contains(n)) {
|
||||
needsMerging = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (needsMerging) {
|
||||
for (Node n : g.getNodes()) {
|
||||
if (!nodesToMerge.contains(n))
|
||||
merged.getNodes().add(n);
|
||||
}
|
||||
} else {
|
||||
res.getGroups().add(g.clone());
|
||||
}
|
||||
}
|
||||
|
||||
if (!merged.getNodes().isEmpty())
|
||||
res.getGroups().add(merged);
|
||||
|
||||
// purge
|
||||
for (Group g : res.getGroups()) {
|
||||
g.getNodes().removeAll(nodesToPurge);
|
||||
}
|
||||
|
||||
System.out.println("Before:\n" + netlist);
|
||||
System.out.println("After:\n" + res);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static List<Set<IDIYComponent<?>>> extractComponentGroups(Netlist netlist) {
|
||||
List<Set<IDIYComponent<?>>> res = new ArrayList<Set<IDIYComponent<?>>>();
|
||||
for (Group g : netlist.getGroups()) {
|
||||
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
|
||||
for (Node n : g.getNodes())
|
||||
components.add(n.getComponent());
|
||||
res.add(components);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static Set<IDIYComponent<?>> extractComponents(Netlist netlist) {
|
||||
Set<IDIYComponent<?>> res = new HashSet<IDIYComponent<?>>();
|
||||
for (Group g : netlist.getGroups())
|
||||
for (Node n : g.getNodes())
|
||||
res.add(n.getComponent());
|
||||
return res;
|
||||
}
|
||||
|
||||
protected int find(Node node, List<Group> groups) {
|
||||
for (int i = 0; i < groups.size(); i++)
|
||||
if (groups.get(i).getNodes().contains(node))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
|
||||
// List<String> names = new ArrayList<String>();
|
||||
// for (IDIYComponent<?> c : components)
|
||||
// names.add(c.getName() + " " + c.getValueForDisplay());
|
||||
// Collections.sort(names);
|
||||
// return names;
|
||||
// }
|
||||
//
|
||||
// protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) {
|
||||
// Netlist res = new Netlist();
|
||||
// res.getSwitchSetup().addAll(netlist.getSwitchSetup());
|
||||
//
|
||||
// Group merged = new Group();
|
||||
//
|
||||
// // merge
|
||||
// for (Group g : netlist.getGroups()) {
|
||||
// boolean needsMerging = false;
|
||||
// for (Node n : nodesToMerge) {
|
||||
// if (g.getNodes().contains(n)) {
|
||||
// needsMerging = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (needsMerging) {
|
||||
// for (Node n : g.getNodes()) {
|
||||
// if (!nodesToMerge.contains(n))
|
||||
// merged.getNodes().add(n);
|
||||
// }
|
||||
// } else {
|
||||
// res.getGroups().add(g.clone());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!merged.getNodes().isEmpty())
|
||||
// res.getGroups().add(merged);
|
||||
//
|
||||
// // purge
|
||||
// for (Group g : res.getGroups()) {
|
||||
// g.getNodes().removeAll(nodesToPurge);
|
||||
// }
|
||||
//
|
||||
// System.out.println("Before:\n" + netlist);
|
||||
// System.out.println("After:\n" + res);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
protected boolean intersect(List<Group> groups, Node node) {
|
||||
for (Group g : groups)
|
||||
if (g.getNodes().contains(node))
|
||||
|
||||
@@ -48,7 +48,8 @@ public class Node implements Comparable<Node> {
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return component.getControlPointNodeName(pointIndex);
|
||||
String[] section = component.getSectionNames(pointIndex);
|
||||
return (section == null || section.length > 1 ? "" : section[0] + ".") + component.getControlPointNodeName(pointIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,6 +82,8 @@ public class Node implements Comparable<Node> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (component.getControlPointCount() == 1)
|
||||
return component.getName();
|
||||
return component.getName() + "." + getDisplayName() /*+ " @ (" + component.getControlPoint(pointIndex).getX() + ":" + component.getControlPoint(pointIndex).getY() + ")"*/;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,31 +21,27 @@
|
||||
*/
|
||||
package org.diylc.netlist;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Summary {
|
||||
public class Summary implements Comparable<Summary> {
|
||||
|
||||
private Netlist netlist;
|
||||
private List<String> notes;
|
||||
private Tree tree;
|
||||
private String summary;
|
||||
|
||||
public Summary(Netlist netlist, List<String> notes, Tree tree) {
|
||||
public Summary(Netlist netlist, String summary) {
|
||||
super();
|
||||
this.netlist = netlist;
|
||||
this.notes = notes;
|
||||
this.tree = tree;
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
public Netlist getNetlist() {
|
||||
return netlist;
|
||||
}
|
||||
|
||||
public List<String> getNotes() {
|
||||
return notes;
|
||||
public void append(Netlist netlist) {
|
||||
this.netlist.getSwitchSetup().addAll(netlist.getSwitchSetup());
|
||||
}
|
||||
|
||||
public Tree getTree() {
|
||||
return tree;
|
||||
public String getSummary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +49,7 @@ public class Summary {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((netlist == null) ? 0 : netlist.hashCode());
|
||||
result = prime * result + ((notes == null) ? 0 : notes.hashCode());
|
||||
result = prime * result + ((summary == null) ? 0 : summary.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -71,16 +67,21 @@ public class Summary {
|
||||
return false;
|
||||
} else if (!netlist.equals(other.netlist))
|
||||
return false;
|
||||
if (notes == null) {
|
||||
if (other.notes != null)
|
||||
if (summary == null) {
|
||||
if (other.summary != null)
|
||||
return false;
|
||||
} else if (!notes.equals(other.notes))
|
||||
} else if (!summary.equals(other.summary))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return notes.toString();
|
||||
return summary.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Summary o) {
|
||||
return netlist.compareTo(o.netlist);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
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.presenter;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
/**
|
||||
* Serializes {@link Color} objects as hex values instead of r/g/b. Backwards compatible when unmarshalling.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class ColorConverter extends com.thoughtworks.xstream.converters.extended.ColorConverter {
|
||||
|
||||
@Override
|
||||
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
Color c = (Color) object;
|
||||
writer.addAttribute("hex", String.format("%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
if (reader.getAttribute("hex") != null)
|
||||
return Color.decode("#" + reader.getAttribute("hex"));
|
||||
return super.unmarshal(reader, context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
return Color.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
@@ -92,13 +92,11 @@ public class ComponentProcessor {
|
||||
Icon icon;
|
||||
double zOrder;
|
||||
boolean flexibleZOrder;
|
||||
boolean stretchable;
|
||||
BomPolicy bomPolicy;
|
||||
boolean autoEdit;
|
||||
IComponentTransformer transformer;
|
||||
KeywordPolicy keywordPolicy;
|
||||
String keywordTag;
|
||||
boolean continuity;
|
||||
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
||||
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
|
||||
name = annotation.name();
|
||||
@@ -109,13 +107,11 @@ public class ComponentProcessor {
|
||||
author = annotation.author();
|
||||
zOrder = annotation.zOrder();
|
||||
flexibleZOrder = annotation.flexibleZOrder();
|
||||
stretchable = annotation.stretchable();
|
||||
bomPolicy = annotation.bomPolicy();
|
||||
autoEdit = annotation.autoEdit();
|
||||
transformer = getComponentTransformer(annotation.transformer());
|
||||
keywordPolicy = annotation.keywordPolicy();
|
||||
keywordTag = annotation.keywordTag();
|
||||
continuity = annotation.continuity();
|
||||
} else { // default
|
||||
return null;
|
||||
}
|
||||
@@ -137,7 +133,7 @@ public class ComponentProcessor {
|
||||
}
|
||||
ComponentType componentType =
|
||||
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag, continuity);
|
||||
flexibleZOrder, bomPolicy, autoEdit, transformer, keywordPolicy, keywordTag);
|
||||
componentTypeMap.put(clazz.getName(), componentType);
|
||||
return componentType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
public class Connection {
|
||||
|
||||
private Point2D p1;
|
||||
private Point2D p2;
|
||||
|
||||
public Connection(Point2D p1, Point2D p2) {
|
||||
this.p1 = p1.getX() < p2.getX() || p1.getX() == p2.getX() && p1.getY() < p2.getY() ? p1 : p2;
|
||||
this.p2 = p1.getX() < p2.getX() || p1.getX() == p2.getX() && p1.getY() < p2.getY() ? p2 : p1;
|
||||
}
|
||||
|
||||
public Point2D getP1() {
|
||||
return p1;
|
||||
}
|
||||
|
||||
public Point2D getP2() {
|
||||
return p2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((p1 == null) ? 0 : p1.hashCode());
|
||||
result = prime * result + ((p2 == null) ? 0 : p2.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;
|
||||
Connection other = (Connection) obj;
|
||||
if (p1 == null) {
|
||||
if (other.p1 != null)
|
||||
return false;
|
||||
} else if (!p1.equals(other.p1))
|
||||
return false;
|
||||
if (p2 == null) {
|
||||
if (other.p2 != null)
|
||||
return false;
|
||||
} else if (!p2.equals(other.p2))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -42,7 +43,6 @@ import java.util.Set;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.GridType;
|
||||
@@ -50,6 +50,7 @@ import org.diylc.common.IComponentFiler;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
@@ -504,19 +505,19 @@ public class DrawingManager {
|
||||
continuityArea = null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Area> getContinuityAreas(Project project) {
|
||||
// Find all individual continuity areas for all components
|
||||
List<Area> preliminaryAreas = new ArrayList<Area>();
|
||||
List<Boolean> checkBreakout = new ArrayList<Boolean>();
|
||||
List<Line2D> connections = new ArrayList<Line2D>();
|
||||
Set<Connection> connections = new HashSet<Connection>();
|
||||
for (IDIYComponent<?> c : project.getComponents()) {
|
||||
ComponentArea a = getComponentArea(c);
|
||||
|
||||
ComponentType type =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||
if (type.isContinuity()) {
|
||||
connections.add(new Line2D.Double(c.getControlPoint(0), c.getControlPoint(c.getControlPointCount() - 1)));
|
||||
if (c instanceof IContinuity) {
|
||||
for (int i = 0; i < c.getControlPointCount() - 1; i++)
|
||||
for (int j = i + 1; j < c.getControlPointCount(); j++)
|
||||
if (((IContinuity)c).arePointsConnected(i, j))
|
||||
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
|
||||
}
|
||||
|
||||
if (a == null || a.getOutlineArea() == null)
|
||||
@@ -548,11 +549,32 @@ public class DrawingManager {
|
||||
// areas.add(a);
|
||||
}
|
||||
|
||||
expandConnections(connections);
|
||||
|
||||
crunchAreas(areas, connections);
|
||||
|
||||
return areas;
|
||||
}
|
||||
|
||||
public void expandConnections(Set<Connection> connections) {
|
||||
Set<Connection> toAdd = new HashSet<Connection>();
|
||||
for (Connection c1 : connections)
|
||||
for (Connection c2 : connections) {
|
||||
if (c1 == c2)
|
||||
continue;
|
||||
if (c1.getP1().distance(c2.getP1()) < CONTROL_POINT_SIZE)
|
||||
toAdd.add(new Connection(c1.getP2(), c2.getP2()));
|
||||
if (c1.getP1().distance(c2.getP2()) < CONTROL_POINT_SIZE)
|
||||
toAdd.add(new Connection(c1.getP2(), c2.getP1()));
|
||||
if (c1.getP2().distance(c2.getP1()) < CONTROL_POINT_SIZE)
|
||||
toAdd.add(new Connection(c1.getP1(), c2.getP2()));
|
||||
if (c1.getP2().distance(c2.getP2()) < CONTROL_POINT_SIZE)
|
||||
toAdd.add(new Connection(c1.getP1(), c2.getP1()));
|
||||
}
|
||||
if (connections.addAll(toAdd))
|
||||
expandConnections(connections);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges all areas that either overlap or are joined by connections.
|
||||
*
|
||||
@@ -560,7 +582,7 @@ public class DrawingManager {
|
||||
* @param connections
|
||||
* @return
|
||||
*/
|
||||
private boolean crunchAreas(List<Area> areas, List<Line2D> connections) {
|
||||
private boolean crunchAreas(List<Area> areas, Set<Connection> connections) {
|
||||
boolean isChanged = false;
|
||||
|
||||
List<Area> newAreas = new ArrayList<Area>();
|
||||
@@ -574,15 +596,19 @@ public class DrawingManager {
|
||||
continue;
|
||||
Area a1 = areas.get(i);
|
||||
Area a2 = areas.get(j);
|
||||
Area intersection = new Area(a1);
|
||||
Area intersection = null;
|
||||
if (a1.getBounds2D().intersects(a2.getBounds())) {
|
||||
intersection = new Area(a1);
|
||||
intersection.intersect(a2);
|
||||
}
|
||||
// if the two areas intersect, make a union and consume the second area
|
||||
if (!intersection.isEmpty()) {
|
||||
if (intersection != null && !intersection.isEmpty()) {
|
||||
a1.add(a2);
|
||||
consumed.set(j, true);
|
||||
} else { // maybe there's a connection between them
|
||||
for (Line2D p : connections) {
|
||||
if ((a1.contains(p.getP1()) && a2.contains(p.getP2())) || (a1.contains(p.getP2()) && a2.contains(p.getP1()))) {
|
||||
for (Connection p : connections) { // use getBounds to optimize the computation, don't get into complex math if not needed
|
||||
if ((a1.getBounds().contains(p.getP1()) && a2.getBounds().contains(p.getP2()) && a1.contains(p.getP1()) && a2.contains(p.getP2())) ||
|
||||
(a1.getBounds().contains(p.getP2()) && a2.getBounds().contains(p.getP1())) && a1.contains(p.getP2()) && a2.contains(p.getP1())) {
|
||||
a1.add(a2);
|
||||
consumed.set(j, true);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
|
||||
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.presenter;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
/**
|
||||
* Serializes {@link Font} objects in a more compact fashion. Backwards compatible when unmarshalling.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class FontConverter extends com.thoughtworks.xstream.converters.extended.FontConverter {
|
||||
|
||||
@Override
|
||||
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
Font f = (Font) object;
|
||||
writer.addAttribute("name", f.getFontName());
|
||||
writer.addAttribute("size", Integer.toString(f.getSize()));
|
||||
writer.addAttribute("style", Integer.toString(f.getStyle()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
if (reader.getAttribute("name") != null) {
|
||||
return new Font(reader.getAttribute("name"), Integer.parseInt(reader.getAttribute("style")), Integer.parseInt(reader.getAttribute("size")));
|
||||
}
|
||||
return super.unmarshal(reader, context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
return Font.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,10 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
@@ -62,11 +64,11 @@ public class InstantiationManager {
|
||||
private Point potentialControlPoint;
|
||||
|
||||
public static final ComponentType clipboardType = new ComponentType("Clipboard contents",
|
||||
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
|
||||
false, null, KeywordPolicy.NEVER_SHOW, null, false);
|
||||
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, null,
|
||||
false, null, KeywordPolicy.NEVER_SHOW, null);
|
||||
public static final ComponentType blockType = new ComponentType("Building block",
|
||||
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
|
||||
false, null, KeywordPolicy.NEVER_SHOW, null, false);
|
||||
"Components from the building block", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, null,
|
||||
false, null, KeywordPolicy.NEVER_SHOW, null);
|
||||
|
||||
public InstantiationManager() {}
|
||||
|
||||
@@ -139,15 +141,33 @@ public class InstantiationManager {
|
||||
return changeMade;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void pasteComponents(Collection<IDIYComponent<?>> components, Point scaledPoint, boolean snapToGrid,
|
||||
Size gridSpacing, boolean autoGroup) {
|
||||
Size gridSpacing, boolean autoGroup, Project currentProject) {
|
||||
// Adjust location of components so they are centered under the mouse
|
||||
// cursor
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
|
||||
Set<String> existingNames = new HashSet<String>();
|
||||
for (IDIYComponent<?> c : currentProject.getComponents())
|
||||
existingNames.add(c.getName());
|
||||
|
||||
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(currentProject.getComponents());
|
||||
|
||||
for (IDIYComponent<?> component : components) {
|
||||
// assign a new name if it already exists in the project
|
||||
if (existingNames.contains(component.getName())) {
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
String newName = createUniqueName(componentType, allComponents);
|
||||
existingNames.add(newName);
|
||||
component.setName(newName);
|
||||
allComponents.add(component);
|
||||
}
|
||||
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
Point p = component.getControlPoint(i);
|
||||
if (p.x > maxX) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
|
||||
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.presenter;
|
||||
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
|
||||
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
/**
|
||||
* Serializes objects of types derived from {@link AbstractMeasure} objects in a compact format. Backwards compatible when unmarshalling.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public class MeasureConverter implements Converter {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
AbstractMeasure m = (AbstractMeasure) object;
|
||||
if (m.getValue() != null)
|
||||
writer.addAttribute("value", Double.toString(m.getValue()));
|
||||
if (m.getUnit() != null)
|
||||
writer.addAttribute("unit", m.getUnit().name());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
Double value = null;
|
||||
String unitStr = null;
|
||||
if (reader.getAttribute("value") != null) {
|
||||
value = Double.parseDouble(reader.getAttribute("value"));
|
||||
unitStr = reader.getAttribute("unit");
|
||||
} else {
|
||||
if (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
if (reader.getNodeName().equals("value"))
|
||||
value = Double.parseDouble(reader.getValue());
|
||||
else if (reader.getNodeName().equals("unit"))
|
||||
unitStr = reader.getValue();
|
||||
reader.moveUp();
|
||||
}
|
||||
if (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
if (reader.getNodeName().equals("value"))
|
||||
value = Double.parseDouble(reader.getValue());
|
||||
else if (reader.getNodeName().equals("unit"))
|
||||
unitStr = reader.getValue();
|
||||
reader.moveUp();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Class requiredType = context.getRequiredType();
|
||||
ParameterizedTypeImpl generic = (ParameterizedTypeImpl)requiredType.getGenericSuperclass();
|
||||
Class unitType = (Class)generic.getActualTypeArguments()[0];
|
||||
Object unit = unitStr == null ? null : Enum.valueOf(unitType, unitStr);
|
||||
return requiredType.getConstructor(Double.class, unitType).newInstance(value, unit);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public boolean canConvert(Class clazz) {
|
||||
return AbstractMeasure.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.BufferedInputStream;
|
||||
@@ -51,6 +50,7 @@ import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.appframework.miscutils.JarScanner;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||
import org.diylc.appframework.update.Version;
|
||||
@@ -68,6 +68,7 @@ import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.common.VariantPackage;
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.ISwitch;
|
||||
import org.diylc.core.IView;
|
||||
@@ -79,6 +80,7 @@ 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.NetlistAnalyzer;
|
||||
import org.diylc.netlist.Node;
|
||||
import org.diylc.netlist.Position;
|
||||
import org.diylc.netlist.SwitchSetup;
|
||||
@@ -132,7 +134,8 @@ public class Presenter implements IPlugInPort {
|
||||
defaultVariantMap = new TreeMap<String, List<Template>>(String.CASE_INSENSITIVE_ORDER);
|
||||
defaultVariantMap.putAll(map);
|
||||
in.close();
|
||||
LOG.info(String.format("Loaded default variants for %d components", defaultVariantMap == null ? 0 : defaultVariantMap.size()));
|
||||
LOG.info(String.format("Loaded default variants for %d components", defaultVariantMap == null ? 0
|
||||
: defaultVariantMap.size()));
|
||||
} catch (IOException e) {
|
||||
LOG.error("Could not load default variants", e);
|
||||
}
|
||||
@@ -262,7 +265,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public Dimension getCanvasDimensions(boolean useZoom, boolean includeExtraSpace) {
|
||||
return drawingManager.getCanvasDimensions(currentProject, useZoom ? drawingManager.getZoomLevel() : 1/ Constants.PIXEL_SIZE, includeExtraSpace);
|
||||
return drawingManager.getCanvasDimensions(currentProject, useZoom ? drawingManager.getZoomLevel()
|
||||
: 1 / Constants.PIXEL_SIZE, includeExtraSpace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -271,13 +275,13 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadProject(Project project, boolean freshStart) {
|
||||
public void loadProject(Project project, boolean freshStart, String filename) {
|
||||
LOG.info(String.format("loadProject(%s, %s)", project.getTitle(), freshStart));
|
||||
this.currentProject = project;
|
||||
drawingManager.clearComponentAreaMap();
|
||||
drawingManager.clearContinuityArea();
|
||||
updateSelection(EMPTY_SELECTION);
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart, filename);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
||||
messageDispatcher.dispatchMessage(EventType.LAYER_VISIBILITY_CHANGED, currentProject.getHiddenLayers());
|
||||
@@ -289,7 +293,7 @@ public class Presenter implements IPlugInPort {
|
||||
try {
|
||||
Project project = new Project();
|
||||
instantiationManager.fillWithDefaultProperties(project, null);
|
||||
loadProject(project, true);
|
||||
loadProject(project, true, null);
|
||||
projectFileManager.startNewFile();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not create new file", e);
|
||||
@@ -300,10 +304,11 @@ public class Presenter implements IPlugInPort {
|
||||
@Override
|
||||
public void loadProjectFromFile(String fileName) {
|
||||
LOG.info(String.format("loadProjectFromFile(%s)", fileName));
|
||||
List<String> warnings = null;
|
||||
try {
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
warnings = new ArrayList<String>();
|
||||
Project project = (Project) projectFileManager.deserializeProjectFromFile(fileName, warnings);
|
||||
loadProject(project, true);
|
||||
loadProject(project, true, fileName);
|
||||
projectFileManager.fireFileStatusChanged();
|
||||
if (!warnings.isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder("<html>File was opened, but there were some issues with it:<br><br>");
|
||||
@@ -317,7 +322,15 @@ public class Presenter implements IPlugInPort {
|
||||
addToRecentFiles(fileName);
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Could not load file", ex);
|
||||
view.showMessage("Could not open file " + fileName + ". Check the log for details.", "Error", IView.ERROR_MESSAGE);
|
||||
String errorMessage = "Could not open file " + fileName + ". Check the log for details.";
|
||||
if (warnings != null && !warnings.isEmpty()) {
|
||||
errorMessage += " Possible reasons are:\n\n";
|
||||
for (String warn : warnings) {
|
||||
errorMessage += warn;
|
||||
errorMessage += "\n";
|
||||
}
|
||||
}
|
||||
view.showMessage(errorMessage, "Error", IView.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,6 +404,14 @@ public class Presenter implements IPlugInPort {
|
||||
Set<Class<?>> componentTypeClasses = null;
|
||||
try {
|
||||
componentTypeClasses = Utils.getClasses("org.diylc.components");
|
||||
try {
|
||||
List<Class<?>> additionalComponentTypeClasses =
|
||||
JarScanner.getInstance().scanFolder("library", IDIYComponent.class);
|
||||
if (additionalComponentTypeClasses != null)
|
||||
componentTypeClasses.addAll(additionalComponentTypeClasses);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Could not find additional type classes", e);
|
||||
}
|
||||
|
||||
for (Class<?> clazz : componentTypeClasses) {
|
||||
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
|
||||
@@ -489,10 +510,7 @@ public class Presenter implements IPlugInPort {
|
||||
getLockedComponents(),
|
||||
groupedComponents,
|
||||
Arrays.asList(instantiationManager.getFirstControlPoint(),
|
||||
instantiationManager.getPotentialControlPoint()),
|
||||
componentSlotToDraw,
|
||||
dragInProgress,
|
||||
externalZoom);
|
||||
instantiationManager.getPotentialControlPoint()), componentSlotToDraw, dragInProgress, externalZoom);
|
||||
List<String> failedComponentNames = new ArrayList<String>();
|
||||
for (IDIYComponent<?> component : failedComponents) {
|
||||
failedComponentNames.add(component.getName());
|
||||
@@ -559,10 +577,11 @@ public class Presenter implements IPlugInPort {
|
||||
List<IDIYComponent<?>> componentSlot = instantiationManager.getComponentSlot();
|
||||
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
|
||||
for (IDIYComponent<?> component : componentSlot) {
|
||||
addComponent(component, true);
|
||||
currentProject.getComponents().add(component);
|
||||
newSelection.add(component);
|
||||
}
|
||||
// group components if there's more than one, e.g. building blocks, but not clipboard contents
|
||||
// group components if there's more than one, e.g. building blocks, but not clipboard
|
||||
// contents
|
||||
if (componentSlot.size() > 1 && !componentTypeSlot.getName().toLowerCase().contains("clipboard")) {
|
||||
this.currentProject.getGroups().add(new HashSet<IDIYComponent<?>>(componentSlot));
|
||||
}
|
||||
@@ -666,7 +685,7 @@ public class Presenter implements IPlugInPort {
|
||||
// don't allow to create component with the same points
|
||||
if (scaledPoint == null || scaledPoint.equals(firstPoint))
|
||||
return;
|
||||
// componentSlot.get(0).setControlPoint(scaledPoint, 1);
|
||||
// componentSlot.get(0).setControlPoint(scaledPoint, 1);
|
||||
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>();
|
||||
for (IDIYComponent<?> component : componentSlot) {
|
||||
addComponent(component, true);
|
||||
@@ -808,7 +827,6 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void mouseMoved(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
||||
if (point == null)
|
||||
@@ -844,24 +862,15 @@ public class Presenter implements IPlugInPort {
|
||||
// Go backwards so we take the highest z-order components first.
|
||||
for (int i = currentProject.getComponents().size() - 1; i >= 0; i--) {
|
||||
IDIYComponent<?> component = currentProject.getComponents().get(i);
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
for (int pointIndex = 0; pointIndex < component.getControlPointCount(); pointIndex++) {
|
||||
Point controlPoint = component.getControlPoint(pointIndex);
|
||||
// Only consider selected components that are not grouped.
|
||||
if (selectedComponents.contains(component) && componentType.isStretchable()
|
||||
if (selectedComponents.contains(component) && component.canPointMoveFreely(pointIndex)
|
||||
&& findAllGroupedComponents(component).size() == 1) {
|
||||
try {
|
||||
if (previousScaledPoint.distance(controlPoint) < DrawingManager.CONTROL_POINT_SIZE) {
|
||||
Set<Integer> indices = new HashSet<Integer>();
|
||||
if (componentType.isStretchable()) {
|
||||
indices.add(pointIndex);
|
||||
} else {
|
||||
for (int j = 0; j < component.getControlPointCount(); j++) {
|
||||
indices.add(j);
|
||||
}
|
||||
}
|
||||
components.put(component, indices);
|
||||
break;
|
||||
}
|
||||
@@ -873,8 +882,12 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
|
||||
Point2D inPoint = new Point2D.Double(1.0d * previousScaledPoint.x / Constants.PIXELS_PER_INCH, 1.0d * previousScaledPoint.y / Constants.PIXELS_PER_INCH);
|
||||
Point2D mmPoint = new Point2D.Double(inPoint.getX() * SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d, inPoint.getY() * SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d);
|
||||
Point2D inPoint =
|
||||
new Point2D.Double(1.0d * previousScaledPoint.x / Constants.PIXELS_PER_INCH, 1.0d * previousScaledPoint.y
|
||||
/ Constants.PIXELS_PER_INCH);
|
||||
Point2D mmPoint =
|
||||
new Point2D.Double(inPoint.getX() * SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d, inPoint.getY()
|
||||
* SizeUnit.in.getFactor() / SizeUnit.cm.getFactor() * 10d);
|
||||
|
||||
messageDispatcher.dispatchMessage(EventType.MOUSE_MOVED, previousScaledPoint, inPoint, mmPoint);
|
||||
|
||||
@@ -938,8 +951,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (rect.y + rect.height > maxY)
|
||||
maxY = rect.y + rect.height;
|
||||
} else if (currentProject.getComponents().contains(c))
|
||||
LOG.debug("Area is null for " + c.getName() + " of type "
|
||||
+ c.getClass().getName());
|
||||
LOG.debug("Area is null for " + c.getName() + " of type " + c.getClass().getName());
|
||||
}
|
||||
|
||||
if (ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
@@ -1088,15 +1100,10 @@ public class Presenter implements IPlugInPort {
|
||||
*
|
||||
* @param controlPointMap
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void includeStuckComponents(Map<IDIYComponent<?>, Set<Integer>> controlPointMap) {
|
||||
int oldSize = controlPointMap.size();
|
||||
LOG.trace("Expanding selected component map");
|
||||
for (IDIYComponent<?> component : currentProject.getComponents()) {
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom(
|
||||
(Class<? extends IDIYComponent<?>>) component.getClass());
|
||||
|
||||
// Check if there's a control point in the current selection
|
||||
// that matches with one of its control points.
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
@@ -1129,7 +1136,7 @@ public class Presenter implements IPlugInPort {
|
||||
// For stretchable components just add the
|
||||
// matching component. Otherwise, add all control
|
||||
// points.
|
||||
if (componentType.isStretchable()) {
|
||||
if (component.canPointMoveFreely(i)) {
|
||||
indices.add(i);
|
||||
} else {
|
||||
for (int k = 0; k < component.getControlPointCount(); k++) {
|
||||
@@ -1179,7 +1186,8 @@ public class Presenter implements IPlugInPort {
|
||||
return true;
|
||||
|
||||
previousDragPoint.translate(actualD.x, actualD.y);
|
||||
} else if (selectedComponents.isEmpty() && instantiationManager.getComponentTypeSlot() == null && previousDragPoint != null) {
|
||||
} else if (selectedComponents.isEmpty() && instantiationManager.getComponentTypeSlot() == null
|
||||
&& previousDragPoint != null) {
|
||||
// If there's no selection, the only thing to do is update the
|
||||
// selection rectangle and refresh.
|
||||
Rectangle oldSelectionRect = selectionRect == null ? null : new Rectangle(selectionRect);
|
||||
@@ -1191,8 +1199,7 @@ public class Presenter implements IPlugInPort {
|
||||
// selectionRect);
|
||||
} else if (instantiationManager.getComponentSlot() != null) {
|
||||
this.previousScaledPoint = scalePoint(point);
|
||||
instantiationManager.updateSingleClick(previousScaledPoint, isSnapToGrid(),
|
||||
currentProject.getGridSpacing());
|
||||
instantiationManager.updateSingleClick(previousScaledPoint, isSnapToGrid(), currentProject.getGridSpacing());
|
||||
}
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
return true;
|
||||
@@ -1245,7 +1252,7 @@ public class Presenter implements IPlugInPort {
|
||||
// actually moved after snapping.
|
||||
if (entry.getValue().contains(index)) {
|
||||
controlPoints[index].translate(actualDx, actualDy);
|
||||
controlPoints[index].translate((int)extraSpace, (int)extraSpace);
|
||||
controlPoints[index].translate((int) extraSpace, (int) extraSpace);
|
||||
if (controlPoints[index].x < 0 || controlPoints[index].y < 0 || controlPoints[index].x > d.width
|
||||
|| controlPoints[index].y > d.height) {
|
||||
// At least one control point went out of bounds.
|
||||
@@ -1534,7 +1541,7 @@ public class Presenter implements IPlugInPort {
|
||||
public void pasteComponents(Collection<IDIYComponent<?>> components, boolean autoGroup) {
|
||||
LOG.info(String.format("pasteComponents(%s, %s)", components, autoGroup));
|
||||
instantiationManager.pasteComponents(components, this.previousScaledPoint, isSnapToGrid(),
|
||||
currentProject.getGridSpacing(), autoGroup);
|
||||
currentProject.getGridSpacing(), autoGroup, this.currentProject);
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, instantiationManager.getComponentTypeSlot(),
|
||||
instantiationManager.getFirstControlPoint());
|
||||
@@ -1664,7 +1671,8 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.LAYER_STATE_CHANGED, currentProject.getLockedLayers());
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), locked ? "Lock Layer" : "Unlock Layer");
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(),
|
||||
locked ? "Lock Layer" : "Unlock Layer");
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
}
|
||||
@@ -1682,7 +1690,8 @@ public class Presenter implements IPlugInPort {
|
||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||
messageDispatcher.dispatchMessage(EventType.LAYER_VISIBILITY_CHANGED, currentProject.getHiddenLayers());
|
||||
if (!oldProject.equals(currentProject)) {
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), visible ? "Show Layer" : "Hide Layer");
|
||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(),
|
||||
visible ? "Show Layer" : "Hide Layer");
|
||||
projectFileManager.notifyFileChange();
|
||||
}
|
||||
}
|
||||
@@ -1907,6 +1916,8 @@ public class Presenter implements IPlugInPort {
|
||||
public void expandSelection(ExpansionMode expansionMode) {
|
||||
LOG.info(String.format("expandSelection(%s)", expansionMode));
|
||||
List<IDIYComponent<?>> newSelection = new ArrayList<IDIYComponent<?>>(this.selectedComponents);
|
||||
List<Netlist> netlists = extractNetlists(false);
|
||||
List<Set<IDIYComponent<?>>> allGroups = NetlistAnalyzer.extractComponentGroups(netlists);
|
||||
// Find control points of all selected components and all types
|
||||
Set<String> selectedNamePrefixes = new HashSet<String>();
|
||||
if (expansionMode == ExpansionMode.SAME_TYPE) {
|
||||
@@ -1918,22 +1929,25 @@ public class Presenter implements IPlugInPort {
|
||||
// Now try to find components that intersect with at least one component
|
||||
// in the pool.
|
||||
for (IDIYComponent<?> component : getCurrentProject().getComponents()) {
|
||||
// no need to consider it, it's already in the selection
|
||||
if (newSelection.contains(component))
|
||||
continue;
|
||||
// construct a list of component groups that contain the current component
|
||||
List<Set<IDIYComponent<?>>> componentGroups = new ArrayList<Set<IDIYComponent<?>>>();
|
||||
for (Set<IDIYComponent<?>> e : allGroups)
|
||||
if (e.contains(component))
|
||||
componentGroups.add(e);
|
||||
if (componentGroups.isEmpty())
|
||||
continue;
|
||||
// Skip already selected components or ones that cannot be stuck to
|
||||
// other components.
|
||||
ComponentArea area = drawingManager.getComponentArea(component);
|
||||
if (newSelection.contains(component) || !component.isControlPointSticky(0) || area == null
|
||||
|| area.getOutlineArea() == null)
|
||||
continue;
|
||||
boolean matches = false;
|
||||
for (IDIYComponent<?> selectedComponent : this.selectedComponents) {
|
||||
ComponentArea selectedArea = drawingManager.getComponentArea(selectedComponent);
|
||||
if (selectedArea == null || selectedArea.getOutlineArea() == null)
|
||||
continue;
|
||||
Area intersection = new Area(area.getOutlineArea());
|
||||
intersection.intersect(selectedArea.getOutlineArea());
|
||||
if (!intersection.isEmpty()) {
|
||||
outer: for (IDIYComponent<?> selectedComponent : this.selectedComponents) {
|
||||
// try to find the selectedComponent in one of the groups
|
||||
for (Set<IDIYComponent<?>> s : componentGroups)
|
||||
if (s.contains(selectedComponent)) {
|
||||
matches = true;
|
||||
break;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2161,10 +2175,10 @@ public class Presenter implements IPlugInPort {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (componentType == null) {
|
||||
// controlPointMap.clear();
|
||||
// updateSelection(EMPTY_SELECTION);
|
||||
// }
|
||||
// if (componentType == null) {
|
||||
// controlPointMap.clear();
|
||||
// updateSelection(EMPTY_SELECTION);
|
||||
// }
|
||||
|
||||
// try to find a default template if none is provided
|
||||
if (componentType != null && template == null) {
|
||||
@@ -2274,12 +2288,11 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
variants.add(template);
|
||||
|
||||
if (System.getProperty("org.diylc.WriteStaticVariants", "false").equalsIgnoreCase("true"))
|
||||
{
|
||||
if (System.getProperty("org.diylc.WriteStaticVariants", "false").equalsIgnoreCase("true")) {
|
||||
if (defaultVariantMap == null)
|
||||
defaultVariantMap = new HashMap<String, List<Template>>();
|
||||
// unify default and user-variants
|
||||
for(Map.Entry<String, List<Template>> entry : variantMap.entrySet()) {
|
||||
for (Map.Entry<String, List<Template>> entry : variantMap.entrySet()) {
|
||||
if (defaultVariantMap.containsKey(entry.getKey())) {
|
||||
defaultVariantMap.get(entry.getKey()).addAll(entry.getValue());
|
||||
} else {
|
||||
@@ -2440,8 +2453,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (templateName.equals(defaultTemplateMap.get(key1)) || templateName.equals(defaultTemplateMap.get(key2))) {
|
||||
defaultTemplateMap.remove(key1);
|
||||
defaultTemplateMap.remove(key2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// get rid of legacy key
|
||||
defaultTemplateMap.remove(key2);
|
||||
defaultTemplateMap.put(key1, templateName);
|
||||
@@ -2491,12 +2503,13 @@ public class Presenter implements IPlugInPort {
|
||||
* @return
|
||||
*/
|
||||
private Point scalePoint(Point point) {
|
||||
Point p = point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
Point p =
|
||||
point == null ? null : new Point((int) (point.x / drawingManager.getZoomLevel()),
|
||||
(int) (point.y / drawingManager.getZoomLevel()));
|
||||
|
||||
if (p != null && ConfigurationManager.getInstance().readBoolean(EXTRA_SPACE_KEY, true)) {
|
||||
double extraSpace = drawingManager.getExtraSpace(currentProject);
|
||||
p.translate((int)(-extraSpace), (int)(-extraSpace));
|
||||
p.translate((int) (-extraSpace), (int) (-extraSpace));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -2505,11 +2518,20 @@ public class Presenter implements IPlugInPort {
|
||||
@Override
|
||||
public void saveSelectionAsBlock(String blockName) {
|
||||
LOG.debug(String.format("saveSelectionAsBlock(%s)", blockName));
|
||||
Map<String, Collection<IDIYComponent<?>>> blocks =
|
||||
(Map<String, Collection<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
if (blocks == null)
|
||||
blocks = new HashMap<String, Collection<IDIYComponent<?>>>();
|
||||
blocks.put(blockName, this.selectedComponents);
|
||||
blocks = new HashMap<String, List<IDIYComponent<?>>>();
|
||||
List<IDIYComponent<?>> blockComponents = new ArrayList<IDIYComponent<?>>(this.selectedComponents);
|
||||
Collections.sort(blockComponents, new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
return new Integer(currentProject.getComponents().indexOf(o1)).compareTo(currentProject.getComponents()
|
||||
.indexOf(o2));
|
||||
}
|
||||
});
|
||||
blocks.put(blockName, blockComponents);
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks);
|
||||
}
|
||||
|
||||
@@ -2517,8 +2539,8 @@ public class Presenter implements IPlugInPort {
|
||||
@Override
|
||||
public void loadBlock(String blockName) throws InvalidBlockException {
|
||||
LOG.debug(String.format("loadBlock(%s)", blockName));
|
||||
Map<String, Collection<IDIYComponent<?>>> blocks =
|
||||
(Map<String, Collection<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
if (blocks != null) {
|
||||
Collection<IDIYComponent<?>> components = blocks.get(blockName);
|
||||
if (components == null)
|
||||
@@ -2548,8 +2570,8 @@ public class Presenter implements IPlugInPort {
|
||||
@Override
|
||||
public void deleteBlock(String blockName) {
|
||||
LOG.debug(String.format("deleteBlock(%s)", blockName));
|
||||
Map<String, Collection<IDIYComponent<?>>> blocks =
|
||||
(Map<String, Collection<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
if (blocks != null) {
|
||||
blocks.remove(blockName);
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks);
|
||||
@@ -2595,8 +2617,7 @@ public class Presenter implements IPlugInPort {
|
||||
for (Map.Entry<String, List<Template>> entry : pkg.getVariants().entrySet()) {
|
||||
List<Template> templates;
|
||||
templates = variantMap.get(entry.getKey());
|
||||
if (templates == null)
|
||||
{
|
||||
if (templates == null) {
|
||||
templates = new ArrayList<Template>();
|
||||
variantMap.put(entry.getKey(), templates);
|
||||
}
|
||||
@@ -2626,13 +2647,13 @@ public class Presenter implements IPlugInPort {
|
||||
if (pkg == null || pkg.getBlocks().isEmpty())
|
||||
return 0;
|
||||
|
||||
Map<String, Collection<IDIYComponent<?>>> blocks =
|
||||
(Map<String, Collection<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
Map<String, List<IDIYComponent<?>>> blocks =
|
||||
(Map<String, List<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
if (blocks == null) {
|
||||
blocks = new HashMap<String, Collection<IDIYComponent<?>>>();
|
||||
blocks = new HashMap<String, List<IDIYComponent<?>>>();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Collection<IDIYComponent<?>>> entry : pkg.getBlocks().entrySet()) {
|
||||
for (Map.Entry<String, List<IDIYComponent<?>>> entry : pkg.getBlocks().entrySet()) {
|
||||
blocks.put(entry.getKey() + " [" + pkg.getOwner() + "]", entry.getValue());
|
||||
}
|
||||
|
||||
@@ -2668,7 +2689,8 @@ public class Presenter implements IPlugInPort {
|
||||
typeMap.put(type.getInstanceClass().getCanonicalName(), type);
|
||||
typeMap.put(type.getCategory() + "." + type.getName(), type);
|
||||
if (type.getCategory().contains("Electro-Mechanical"))
|
||||
typeMap.put(type.getCategory().replace("Electro-Mechanical", "Electromechanical") + "." + type.getName(), type);
|
||||
typeMap.put(type.getCategory().replace("Electro-Mechanical", "Electromechanical") + "." + type.getName(),
|
||||
type);
|
||||
}
|
||||
|
||||
Map<String, List<Template>> newVariantMap = new HashMap<String, List<Template>>();
|
||||
@@ -2677,7 +2699,10 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
for (Map.Entry<String, List<Template>> entry : variantMap.entrySet()) {
|
||||
if (typeMap.containsKey(entry.getKey())) {
|
||||
newVariantMap.put(typeMap.get(entry.getKey()).getInstanceClass().getCanonicalName(), entry.getValue()); // great, nothing to upgrade
|
||||
newVariantMap.put(typeMap.get(entry.getKey()).getInstanceClass().getCanonicalName(), entry.getValue()); // great,
|
||||
// nothing
|
||||
// to
|
||||
// upgrade
|
||||
} else {
|
||||
LOG.warn("Could not upgrade variants for: " + entry.getKey());
|
||||
}
|
||||
@@ -2688,27 +2713,29 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Netlist> extractNetlists() {
|
||||
public List<Netlist> extractNetlists(boolean includeSwitches) {
|
||||
Map<Netlist, Netlist> result = new HashMap<Netlist, Netlist>();
|
||||
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()) {
|
||||
if (!(c instanceof IContinuity)) {
|
||||
for (int i = 0; i < c.getControlPointCount(); i++) {
|
||||
String nodeName = c.getControlPointNodeName(i);
|
||||
if (nodeName != null) {
|
||||
if (nodeName != null && (!includeSwitches || !ISwitch.class.isAssignableFrom(type.getInstanceClass()))) {
|
||||
nodes.add(new Node(c, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// extract switches
|
||||
if (ISwitch.class.isAssignableFrom(type.getInstanceClass()))
|
||||
switches.add((ISwitch)c);
|
||||
if (includeSwitches && ISwitch.class.isAssignableFrom(type.getInstanceClass()))
|
||||
switches.add((ISwitch) c);
|
||||
}
|
||||
|
||||
// save us the trouble
|
||||
@@ -2752,7 +2779,7 @@ public class Presenter implements IPlugInPort {
|
||||
switchPositions.put(switches.get(j), positions[j]);
|
||||
posList.add(new Position(switches.get(j), positions[j]));
|
||||
}
|
||||
List<Line2D> connections = getConnections(switchPositions);
|
||||
List<Connection> connections = getConnections(switchPositions);
|
||||
Netlist graph = constructNetlist(nodes, connections, continuity);
|
||||
|
||||
// merge graphs that are effectively the same
|
||||
@@ -2785,20 +2812,20 @@ public class Presenter implements IPlugInPort {
|
||||
return netlists;
|
||||
}
|
||||
|
||||
private Netlist constructNetlist(List<Node> nodes, List<Line2D> connections, List<Area> continuityAreas) {
|
||||
private Netlist constructNetlist(List<Node> nodes, List<Connection> connections, List<Area> continuityAreas) {
|
||||
Netlist netlist = new Netlist();
|
||||
|
||||
// debugging code
|
||||
// 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());
|
||||
// debugging code
|
||||
// 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++)
|
||||
@@ -2808,10 +2835,14 @@ public class Presenter implements IPlugInPort {
|
||||
Point2D point1 = node1.getComponent().getControlPoint(node1.getPointIndex());
|
||||
Point2D point2 = node2.getComponent().getControlPoint(node2.getPointIndex());
|
||||
|
||||
String commonPoint1 = node1.getComponent().getCommonPointName(node1.getPointIndex());
|
||||
String commonPoint2 = node2.getComponent().getCommonPointName(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()])) {
|
||||
if (point1.distance(point2) < t
|
||||
|| checkGraphConnection(point1, point2, connections, continuityAreas, new boolean[connections.size()])
|
||||
|| checkGraphConnection(point2, point1, connections, continuityAreas, new boolean[connections.size()])
|
||||
|| (commonPoint1 != null && commonPoint1.equalsIgnoreCase(commonPoint2))) {
|
||||
boolean added = false;
|
||||
// add to an existing vertex if possible
|
||||
for (Group g : netlist.getGroups())
|
||||
@@ -2855,7 +2886,7 @@ public class Presenter implements IPlugInPort {
|
||||
return netlist;
|
||||
}
|
||||
|
||||
private boolean checkGraphConnection(Point2D point1, Point2D point2, List<Line2D> connections,
|
||||
private boolean checkGraphConnection(Point2D point1, Point2D point2, List<Connection> connections,
|
||||
List<Area> continuityAreas, boolean[] visited) {
|
||||
double t = DrawingManager.CONTROL_POINT_SIZE;
|
||||
|
||||
@@ -2871,7 +2902,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (visited[i])
|
||||
continue;
|
||||
|
||||
Line2D c = connections.get(i);
|
||||
Connection c = connections.get(i);
|
||||
if (point1.distance(c.getP1()) < t) {
|
||||
visited[i] = true;
|
||||
if (checkGraphConnection(c.getP2(), point2, connections, continuityAreas, visited))
|
||||
@@ -2888,27 +2919,32 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Line2D> getConnections(Map<ISwitch, Integer> switchPositions) {
|
||||
List<Line2D> connections = new ArrayList<Line2D>();
|
||||
private List<Connection> getConnections(Map<ISwitch, Integer> switchPositions) {
|
||||
Set<Connection> connections = new HashSet<Connection>();
|
||||
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)));
|
||||
if (c instanceof IContinuity) {
|
||||
for (int i = 0; i < c.getControlPointCount() - 1; i++)
|
||||
for (int j = i + 1; j < c.getControlPointCount(); j++)
|
||||
if (((IContinuity) c).arePointsConnected(i, j))
|
||||
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
|
||||
}
|
||||
// handle switches
|
||||
if (ISwitch.class.isAssignableFrom(type.getInstanceClass()) && switchPositions.containsKey(c)) {
|
||||
int position = switchPositions.get(c);
|
||||
ISwitch s = (ISwitch)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)));
|
||||
connections.add(new Connection(c.getControlPoint(i), c.getControlPoint(j)));
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
drawingManager.expandConnections(connections);
|
||||
|
||||
return new ArrayList<Connection>(connections);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2923,6 +2959,15 @@ public class Presenter implements IPlugInPort {
|
||||
result.add((INetlistAnalyzer) clazz.newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(result, new Comparator<INetlistAnalyzer>() {
|
||||
|
||||
@Override
|
||||
public int compare(INetlistAnalyzer o1, INetlistAnalyzer o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not load INetlistSummarizer implementations", e);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -43,10 +44,13 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||
import org.diylc.appframework.update.VersionNumber;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.parsing.IOldFileParser;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@@ -92,7 +96,23 @@ public class ProjectFileManager {
|
||||
}
|
||||
};
|
||||
xStream.autodetectAnnotations(true);
|
||||
xStream.alias("point", java.awt.Point.class);
|
||||
xStream.alias("font", java.awt.Font.class);
|
||||
xStream.alias("project", Project.class);
|
||||
xStream.aliasPackage("diylc", "org.diylc.components");
|
||||
xStream.registerConverter(new PointConverter());
|
||||
xStream.registerConverter(new ColorConverter());
|
||||
xStream.registerConverter(new FontConverter());
|
||||
xStream.registerConverter(new MeasureConverter());
|
||||
xStream.addImmutableType(Color.class);
|
||||
xStream.addImmutableType(java.awt.Point.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Voltage.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Resistance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Capacitance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Current.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Power.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Inductance.class);
|
||||
xStream.addImmutableType(org.diylc.core.measures.Size.class);
|
||||
this.xStreamOld = new XStream(new DomDriver());
|
||||
xStreamOld.autodetectAnnotations(true);
|
||||
this.messageDispatcher = messageDispatcher;
|
||||
@@ -150,7 +170,7 @@ public class ProjectFileManager {
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(new InputSource(new InputStreamReader(new FileInputStream(file))));
|
||||
doc.getDocumentElement().normalize();
|
||||
if (doc.getDocumentElement().getNodeName().equalsIgnoreCase(Project.class.getName())) {
|
||||
if (doc.getDocumentElement().getNodeName().equals(Project.class.getName()) || doc.getDocumentElement().getNodeName().equals("project")) {
|
||||
project = parseV3File(fileName, warnings);
|
||||
} else {
|
||||
if (!doc.getDocumentElement().getNodeName().equalsIgnoreCase("layout")) {
|
||||
@@ -193,13 +213,21 @@ public class ProjectFileManager {
|
||||
|
||||
private Project parseV3File(String fileName, List<String> warnings) throws IOException {
|
||||
Project project;
|
||||
VersionNumber fileVersion;
|
||||
try {
|
||||
fileVersion = readV3Version(fileName);
|
||||
if (fileVersion.compareTo(Presenter.CURRENT_VERSION) > 0)
|
||||
warnings.add("The file is created with a newer version of DIYLC and may contain features that are not supported by your version of DIYLC. Please update.");
|
||||
} catch (Exception e) {
|
||||
warnings.add("Could not read file version number, the file may be corrupted.");
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(fileName);
|
||||
missingFields.clear();
|
||||
try {
|
||||
Reader reader = new InputStreamReader(fis, "UTF-8");
|
||||
project = (Project) xStream.fromXML(reader);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Could not open with the new xStream, trying the old one");
|
||||
LOG.warn("Could not open with the new xStream, trying the old one", e);
|
||||
fis.close();
|
||||
fis = new FileInputStream(fileName);
|
||||
project = (Project) xStreamOld.fromXML(fis);
|
||||
@@ -210,4 +238,31 @@ public class ProjectFileManager {
|
||||
fis.close();
|
||||
return project;
|
||||
}
|
||||
|
||||
private VersionNumber readV3Version(String fileName) throws Exception {
|
||||
File fXmlFile = new File(fileName);
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(fXmlFile);
|
||||
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
NodeList nList = doc.getElementsByTagName("fileVersion");
|
||||
|
||||
int items = nList.getLength();
|
||||
|
||||
if (items != 1)
|
||||
throw new Exception("File version information could not be read from the XML.");
|
||||
|
||||
Node versionNode = nList.item(0);
|
||||
Node n = versionNode.getFirstChild().getNextSibling();
|
||||
int major = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||
n = n.getNextSibling().getNextSibling();
|
||||
int minor = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||
n = n.getNextSibling().getNextSibling();
|
||||
int build = Integer.parseInt(n.getFirstChild().getNodeValue());
|
||||
|
||||
return new VersionNumber(major, minor, build);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
|
||||
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.awt;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
|
||||
/**
|
||||
* Globally available utility classes, mostly for string manipulation.
|
||||
*
|
||||
* @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
|
||||
*/
|
||||
public class StringUtils {
|
||||
|
||||
public static void drawWrappedText(String text, Graphics2D g2d, int x, int y, int maxWidth, HorizontalAlignment horizontalAlignment) {
|
||||
FontMetrics textMetrics = g2d.getFontMetrics();
|
||||
List<String> lines = wrap(text, textMetrics, maxWidth);
|
||||
int lineHeight = textMetrics.getHeight();
|
||||
|
||||
if (horizontalAlignment == HorizontalAlignment.CENTER)
|
||||
x += maxWidth / 2;
|
||||
else if (horizontalAlignment == HorizontalAlignment.RIGHT)
|
||||
x += maxWidth;
|
||||
|
||||
for (String line : lines) {
|
||||
drawCenteredText(g2d, line, x, y, horizontalAlignment, VerticalAlignment.BOTTOM);
|
||||
y += lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of strings, one for each line in the string after it has been wrapped to fit
|
||||
* lines of <var>maxWidth</var>. Lines end with any of cr, lf, or cr lf. A line ending at the end
|
||||
* of the string will not output a further, empty string.
|
||||
* <p>
|
||||
* This code assumes <var>str</var> is not <code>null</code>.
|
||||
*
|
||||
* @param str the string to split
|
||||
* @param fm needed for string width calculations
|
||||
* @param maxWidth the max line width, in points
|
||||
* @return a non-empty list of strings
|
||||
*/
|
||||
public static List<String> wrap(String str, FontMetrics fm, int maxWidth) {
|
||||
List<String> lines = splitIntoLines(str);
|
||||
if (lines.size() == 0)
|
||||
return lines;
|
||||
|
||||
ArrayList<String> strings = new ArrayList<String>();
|
||||
for (Iterator<String> iter = lines.iterator(); iter.hasNext();)
|
||||
wrapLineInto((String) iter.next(), strings, fm, maxWidth);
|
||||
return strings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a line of text and font metrics information, wrap the line and add the new line(s) to
|
||||
* <var>list</var>.
|
||||
*
|
||||
* @param line a line of text
|
||||
* @param list an output list of strings
|
||||
* @param fm font metrics
|
||||
* @param maxWidth maximum width of the line(s)
|
||||
*/
|
||||
public static void wrapLineInto(String line, List<String> list, FontMetrics fm, int maxWidth) {
|
||||
int len = line.length();
|
||||
int width;
|
||||
while (len > 0 && (width = fm.stringWidth(line)) > maxWidth) {
|
||||
// Guess where to split the line. Look for the next space before
|
||||
// or after the guess.
|
||||
int guess = len * maxWidth / width;
|
||||
String before = line.substring(0, guess).trim();
|
||||
|
||||
width = fm.stringWidth(before);
|
||||
int pos;
|
||||
if (width > maxWidth) // Too long
|
||||
pos = findBreakBefore(line, guess);
|
||||
else { // Too short or possibly just right
|
||||
pos = findBreakAfter(line, guess);
|
||||
if (pos != -1) { // Make sure this doesn't make us too long
|
||||
before = line.substring(0, pos).trim();
|
||||
if (fm.stringWidth(before) > maxWidth)
|
||||
pos = findBreakBefore(line, guess);
|
||||
}
|
||||
}
|
||||
if (pos == -1)
|
||||
pos = guess; // Split in the middle of the word
|
||||
|
||||
list.add(line.substring(0, pos).trim());
|
||||
line = line.substring(pos).trim();
|
||||
len = line.length();
|
||||
}
|
||||
if (len > 0)
|
||||
list.add(line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first whitespace character or '-' in <var>line</var> that is at or
|
||||
* before <var>start</var>. Returns -1 if no such character is found.
|
||||
*
|
||||
* @param line a string
|
||||
* @param start where to star looking
|
||||
*/
|
||||
public static int findBreakBefore(String line, int start) {
|
||||
for (int i = start; i >= 0; --i) {
|
||||
char c = line.charAt(i);
|
||||
if (Character.isWhitespace(c) || c == '-')
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first whitespace character or '-' in <var>line</var> that is at or
|
||||
* after <var>start</var>. Returns -1 if no such character is found.
|
||||
*
|
||||
* @param line a string
|
||||
* @param start where to star looking
|
||||
*/
|
||||
public static int findBreakAfter(String line, int start) {
|
||||
int len = line.length();
|
||||
for (int i = start; i < len; ++i) {
|
||||
char c = line.charAt(i);
|
||||
if (Character.isWhitespace(c) || c == '-')
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of strings, one for each line in the string. Lines end with any of cr, lf, or
|
||||
* cr lf. A line ending at the end of the string will not output a further, empty string.
|
||||
* <p>
|
||||
* This code assumes <var>str</var> is not <code>null</code>.
|
||||
*
|
||||
* @param str the string to split
|
||||
* @return a non-empty list of strings
|
||||
*/
|
||||
public static List<String> splitIntoLines(String str) {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
|
||||
int len = str.length();
|
||||
if (len == 0) {
|
||||
strings.add("");
|
||||
return strings;
|
||||
}
|
||||
|
||||
int lineStart = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char c = str.charAt(i);
|
||||
if (c == '\r') {
|
||||
int newlineLength = 1;
|
||||
if ((i + 1) < len && str.charAt(i + 1) == '\n')
|
||||
newlineLength = 2;
|
||||
strings.add(str.substring(lineStart, i));
|
||||
lineStart = i + newlineLength;
|
||||
if (newlineLength == 2) // skip \n next time through loop
|
||||
++i;
|
||||
} else if (c == '\n') {
|
||||
strings.add(str.substring(lineStart, i));
|
||||
lineStart = i + 1;
|
||||
}
|
||||
}
|
||||
if (lineStart < len)
|
||||
strings.add(str.substring(lineStart));
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
public static void drawCenteredText(Graphics2D g2d, String text, int x, int y, HorizontalAlignment horizontalAlignment,
|
||||
VerticalAlignment verticalAlignment) {
|
||||
String[] parts = text.split("\n");
|
||||
if (parts.length > 1) {
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle stringBounds = fontMetrics.getStringBounds(parts[0], g2d).getBounds();
|
||||
for (int i = 0; i < parts.length; i++)
|
||||
drawCenteredText(g2d, parts[i], x, (int)(y - stringBounds.height * (parts.length - 1) / 2d + i * stringBounds.height), horizontalAlignment, verticalAlignment);
|
||||
return;
|
||||
}
|
||||
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle stringBounds = fontMetrics.getStringBounds(text, g2d).getBounds();
|
||||
|
||||
Font font = g2d.getFont();
|
||||
FontRenderContext renderContext = g2d.getFontRenderContext();
|
||||
GlyphVector glyphVector = font.createGlyphVector(renderContext, text);
|
||||
Rectangle visualBounds = glyphVector.getVisualBounds().getBounds();
|
||||
|
||||
int textX = 0;
|
||||
switch (horizontalAlignment) {
|
||||
case CENTER:
|
||||
textX = x - stringBounds.width / 2;
|
||||
break;
|
||||
case LEFT:
|
||||
textX = x;
|
||||
break;
|
||||
case RIGHT:
|
||||
textX = x - stringBounds.width;
|
||||
break;
|
||||
}
|
||||
|
||||
int textY = 0;
|
||||
switch (verticalAlignment) {
|
||||
case TOP:
|
||||
textY = y + stringBounds.height;
|
||||
break;
|
||||
case CENTER:
|
||||
textY = y - visualBounds.height / 2 - visualBounds.y;
|
||||
break;
|
||||
case BOTTOM:
|
||||
textY = y - visualBounds.y;
|
||||
break;
|
||||
}
|
||||
|
||||
g2d.drawString(text, textX, textY);
|
||||
}
|
||||
}
|
||||
@@ -31,13 +31,13 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.components.semiconductors.SymbolFlipping;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -57,16 +57,31 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
public static Color COLOR = Color.black;
|
||||
|
||||
protected String value = "";
|
||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) };
|
||||
protected Color color = COLOR;
|
||||
protected SymbolFlipping flip = SymbolFlipping.NONE;
|
||||
protected Display display = Display.NAME;
|
||||
transient protected Shape[] body;
|
||||
protected Orientation orientation = Orientation.DEFAULT;
|
||||
protected boolean moveLabel = false;
|
||||
|
||||
public Abstract3LegSymbol() {
|
||||
super();
|
||||
updateControlPoints();
|
||||
controlPoints[3] = getDefaultLabelPosition(controlPoints);
|
||||
}
|
||||
|
||||
public Point[] getControlPoints() {
|
||||
if (controlPoints.length == 3) {
|
||||
controlPoints = new Point[] { controlPoints[0], controlPoints[1], controlPoints[2], getDefaultLabelPosition(controlPoints) };
|
||||
}
|
||||
return controlPoints;
|
||||
}
|
||||
|
||||
protected Point getDefaultLabelPosition(Point[] oldControlPoints) {
|
||||
int f = flip == SymbolFlipping.X ? -1 : 1;
|
||||
int d = flip == SymbolFlipping.X ? (int) PIN_SPACING.convertToPixels() / 2 : 0;
|
||||
return new Point(oldControlPoints[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d), oldControlPoints[0].y);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,8 +103,6 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
}
|
||||
g2d.setColor(finalColor);
|
||||
|
||||
// Draw transistor
|
||||
|
||||
if (this.body == null) {
|
||||
this.body = getBody();
|
||||
applyOrientation(this.body);
|
||||
@@ -97,6 +110,8 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
|
||||
AffineTransform old = g2d.getTransform();
|
||||
|
||||
Point[] controlPoints = getControlPoints();
|
||||
|
||||
if (this.flip == SymbolFlipping.Y) {
|
||||
g2d.translate(0, controlPoints[0].y);
|
||||
g2d.scale(1, -1);
|
||||
@@ -144,59 +159,80 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||
Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds());
|
||||
|
||||
drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode),
|
||||
if (getMoveLabel()) {
|
||||
StringUtils.drawCenteredText(g2d, label, controlPoints[3].x, controlPoints[3].y, flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT
|
||||
: HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
} else {
|
||||
StringUtils.drawCenteredText(g2d, label, getLabelX(shapeRect, textRect, fontMetrics, outlineMode),
|
||||
getLabelY(shapeRect, textRect, fontMetrics, outlineMode), flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT
|
||||
: HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
return getControlPoints()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
return getControlPoints().length;
|
||||
}
|
||||
|
||||
protected int getLabelX(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||
int f = flip == SymbolFlipping.X ? -1 : 1;
|
||||
int d = flip == SymbolFlipping.X ? (int) PIN_SPACING.convertToPixels() / 2 : 0;
|
||||
return controlPoints[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d);
|
||||
return getControlPoints()[0].x + f * (int) (PIN_SPACING.convertToPixels() * 1.5 + d);
|
||||
}
|
||||
|
||||
protected int getLabelY(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics, boolean outlineMode) {
|
||||
return controlPoints[0].y;
|
||||
return getControlPoints()[0].y;
|
||||
}
|
||||
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
Point[] controlPoints = getControlPoints();
|
||||
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
|
||||
int f = flip == SymbolFlipping.X ? -1 : 1;
|
||||
|
||||
controlPoints[1].x = x + f * pinSpacing * 2;
|
||||
// set default point positions
|
||||
controlPoints[1].x = x + pinSpacing * 2;
|
||||
controlPoints[1].y = y - pinSpacing * 2;
|
||||
|
||||
controlPoints[2].x = x + f * pinSpacing * 2;
|
||||
controlPoints[2].x = x + pinSpacing * 2;
|
||||
controlPoints[2].y = y + pinSpacing * 2;
|
||||
|
||||
controlPoints[3].x = x + (int) (PIN_SPACING.convertToPixels() * 2);
|
||||
controlPoints[3].y = y;
|
||||
|
||||
// apply rotation if needed
|
||||
if (getOrientation() != Orientation.DEFAULT)
|
||||
{
|
||||
Point first = this.controlPoints[0];
|
||||
Point first = controlPoints[0];
|
||||
double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y);
|
||||
for (int i = 1; i < this.controlPoints.length; i++) {
|
||||
rotate.transform(this.controlPoints[i], this.controlPoints[i]);
|
||||
for (int i = 1; i < controlPoints.length; i++) {
|
||||
rotate.transform(controlPoints[i], controlPoints[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// flip at the end
|
||||
if (flip == SymbolFlipping.X) {
|
||||
controlPoints[1].x = controlPoints[0].x - (controlPoints[1].x - controlPoints[0].x);
|
||||
controlPoints[2].x = controlPoints[0].x - (controlPoints[2].x - controlPoints[0].x);
|
||||
controlPoints[3].x = controlPoints[0].x - (controlPoints[3].x - controlPoints[0].x);
|
||||
}
|
||||
if (flip == SymbolFlipping.Y) {
|
||||
controlPoints[1].y = controlPoints[0].y - (controlPoints[1].y - controlPoints[0].y);
|
||||
controlPoints[2].y = controlPoints[0].y - (controlPoints[2].y - controlPoints[0].y);
|
||||
controlPoints[3].y = controlPoints[0].y - (controlPoints[3].y - controlPoints[0].y);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
return index < 3 || getMoveLabel() ? VisibilityPolicy.WHEN_SELECTED : VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -212,17 +248,27 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
return index < 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
getControlPoints()[index].setLocation(point);
|
||||
|
||||
// make sure we have a new drawing
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return pointIndex == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
return index >= 3;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public SymbolFlipping getFlip() {
|
||||
return flip;
|
||||
@@ -245,6 +291,15 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Moveable Label")
|
||||
public boolean getMoveLabel() {
|
||||
return moveLabel;
|
||||
}
|
||||
|
||||
public void setMoveLabel(boolean moveLabel) {
|
||||
this.moveLabel = moveLabel;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
return display;
|
||||
@@ -274,7 +329,7 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
if (getOrientation() == Orientation.DEFAULT)
|
||||
return;
|
||||
|
||||
Point first = this.controlPoints[0];
|
||||
Point first = getControlPoints()[0];
|
||||
double angle = Double.parseDouble(getOrientation().name().replace("_", ""));
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.toRadians(angle), first.x, first.y);
|
||||
|
||||
@@ -285,6 +340,13 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
if (index >= 3)
|
||||
return null;
|
||||
return Integer.toString(index + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns transistor shape consisting of 3 parts, in this order: main body, connectors, polarity
|
||||
* arrow.
|
||||
|
||||
@@ -36,10 +36,13 @@ import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.ShadedPaint;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.LineStyle;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
@@ -70,7 +73,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
protected Size length;
|
||||
protected Size width;
|
||||
protected Point[] points = new Point[] {new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0)};
|
||||
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0), new Point(0, 0)};
|
||||
protected Color bodyColor = Color.white;
|
||||
protected Color borderColor = Color.black;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
@@ -78,6 +81,11 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
protected Display display = Display.NAME;
|
||||
private boolean flipStanding = false;
|
||||
private LabelOriantation labelOriantation = LabelOriantation.Directional;
|
||||
protected boolean moveLabel = false;
|
||||
|
||||
// parameters for adjusting the label control point
|
||||
protected Double gamma = null;
|
||||
protected Double r = null;
|
||||
|
||||
protected AbstractLeadedComponent() {
|
||||
super();
|
||||
@@ -89,27 +97,66 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
} catch (NullPointerException e) {
|
||||
// This will happen if components do not have any shape.
|
||||
}
|
||||
points[2] = calculateLabelPosition(points[0], points[1]);
|
||||
}
|
||||
|
||||
protected boolean IsCopperArea() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Point[] getPoints() {
|
||||
// convert old points to new
|
||||
if (points.length == 2) {
|
||||
points = new Point[] { points[0], points[1], calculateLabelPosition(points[0], points[1]) };
|
||||
// to make standing components backward compatible and not show a label until the user switches the display to something else
|
||||
if (isStanding())
|
||||
display = Display.NONE;
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
protected Point calculateLabelPosition(Point point1, Point point2) {
|
||||
double x = (point1.x + point2.x) / 2.0;
|
||||
double y = (point1.y + point2.y) / 2.0;
|
||||
return new Point((int) x, (int) y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
double distance = points[0].distance(points[1]);
|
||||
if (gamma != null) {
|
||||
// recalculate center position and theta, then adjust label point accordingly, while preserving alpha and p
|
||||
double x = (getPoints()[1].x + getPoints()[0].x) / 2.0;
|
||||
double y = (getPoints()[1].y + getPoints()[0].y) / 2.0;
|
||||
double theta = Math.atan2(getPoints()[1].y - getPoints()[0].y, getPoints()[1].x - getPoints()[0].x);
|
||||
double beta = gamma - (Math.PI / 2 - theta);
|
||||
getPoints()[2].setLocation(x + Math.cos(beta) * r, y + Math.sin(beta) * r);
|
||||
gamma = null;
|
||||
r = null;
|
||||
}
|
||||
|
||||
double distance = getPoints()[0].distance(getPoints()[1]);
|
||||
Shape shape = getBodyShape();
|
||||
// If there's no body, just draw the line connecting the ending points.
|
||||
if (shape == null) {
|
||||
drawLead(g2d, componentState, drawingObserver, IsCopperArea());
|
||||
} else if (supportsStandingMode() && length.convertToPixels() > points[0].distance(points[1])) {
|
||||
return;
|
||||
}
|
||||
|
||||
AffineTransform oldTransform = g2d.getTransform();
|
||||
double width;
|
||||
double length;
|
||||
Rectangle shapeRect;
|
||||
double theta = Math.atan2(getPoints()[1].y - getPoints()[0].y, getPoints()[1].x - getPoints()[0].x);
|
||||
|
||||
if (isStanding()) {
|
||||
// When ending points are too close draw the component in standing
|
||||
// mode.
|
||||
int width = getClosestOdd(this.width.convertToPixels());
|
||||
width = length = getClosestOdd(this.width.convertToPixels());
|
||||
Shape body =
|
||||
new Ellipse2D.Double((getFlipStanding() ? points[1] : points[0]).x - width / 2,
|
||||
(getFlipStanding() ? points[1] : points[0]).y - width / 2, width, width);
|
||||
new Ellipse2D.Double((getFlipStanding() ? getPoints()[1] : getPoints()[0]).x - width / 2,
|
||||
(getFlipStanding() ? getPoints()[1] : getPoints()[0]).y - width / 2, width, width);
|
||||
shapeRect = body.getBounds();
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
@@ -138,11 +185,10 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
}
|
||||
} else {
|
||||
// Normal mode with component body in the center and two lead parts.
|
||||
Rectangle shapeRect = shape.getBounds();
|
||||
double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
|
||||
shapeRect = shape.getBounds();
|
||||
// Go back to the original transformation to draw leads.
|
||||
if (!outlineMode) {
|
||||
AffineTransform textTransform = g2d.getTransform();
|
||||
// AffineTransform textTransform = g2d.getTransform();
|
||||
// if (length.convertToPixels() > points[0].distance(points[1]))
|
||||
// {
|
||||
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
@@ -157,14 +203,14 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
|
||||
Area leadArea = new Area();
|
||||
|
||||
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
|
||||
int endY = (int) (points[0].y + Math.sin(theta) * leadLength);
|
||||
Line2D line = new Line2D.Double(points[0].x, points[0].y, endX, endY);
|
||||
int endX = (int) (getPoints()[0].x + Math.cos(theta) * leadLength);
|
||||
int endY = (int) (getPoints()[0].y + Math.sin(theta) * leadLength);
|
||||
Line2D line = new Line2D.Double(getPoints()[0].x, getPoints()[0].y, endX, endY);
|
||||
leadArea.add(new Area(leadStroke.createStrokedShape(line)));
|
||||
|
||||
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
|
||||
endY = (int) (points[1].y + Math.sin(theta - Math.PI) * leadLength);
|
||||
line = new Line2D.Double(points[1].x, points[1].y, endX, endY);
|
||||
endX = (int) (getPoints()[1].x + Math.cos(theta - Math.PI) * leadLength);
|
||||
endY = (int) (getPoints()[1].y + Math.sin(theta - Math.PI) * leadLength);
|
||||
line = new Line2D.Double(getPoints()[1].x, getPoints()[1].y, endX, endY);
|
||||
leadArea.add(new Area(leadStroke.createStrokedShape(line)));
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||
@@ -178,13 +224,10 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
g2d.setColor(leadColor);
|
||||
drawLeads(g2d, theta, leadLength);
|
||||
}
|
||||
g2d.setTransform(textTransform);
|
||||
// g2d.setTransform(textTransform);
|
||||
}
|
||||
// Transform graphics to draw the body in the right place and at the
|
||||
// right angle.
|
||||
AffineTransform oldTransform = null;
|
||||
double width;
|
||||
double length;
|
||||
if (useShapeRectAsPosition()) {
|
||||
width = shapeRect.getHeight();
|
||||
length = shapeRect.getWidth();
|
||||
@@ -192,8 +235,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
width = getWidth().convertToPixels();
|
||||
length = getLength().convertToPixels();
|
||||
}
|
||||
oldTransform = g2d.getTransform();
|
||||
g2d.translate((points[0].x + points[1].x - length) / 2, (points[0].y + points[1].y - width) / 2);
|
||||
g2d.translate((getPoints()[0].x + getPoints()[1].x - length) / 2, (getPoints()[0].y + getPoints()[1].y - width) / 2);
|
||||
g2d.rotate(theta, length / 2, width / 2);
|
||||
// Draw body.
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
@@ -244,6 +286,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
decorateComponentBody(g2d, outlineMode);
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw label.
|
||||
g2d.setFont(project.getFont());
|
||||
@@ -275,33 +318,59 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
|
||||
// Don't offset in outline mode.
|
||||
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width, (int) textRect.getWidth());
|
||||
|
||||
// Adjust label angle if needed to make sure that it's readable.
|
||||
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
|
||||
g2d.rotate(Math.PI, length / 2, width / 2);
|
||||
theta += Math.PI;
|
||||
offset = -offset;
|
||||
}
|
||||
if (getLabelOriantation() == LabelOriantation.Horizontal) {
|
||||
|
||||
if (getMoveLabel()) {
|
||||
g2d.setTransform(oldTransform);
|
||||
double x = (points[0].x + points[1].x - length) / 2.0;
|
||||
double y = (points[0].y + points[1].y - width) / 2.0;
|
||||
g2d.translate(getPoints()[2].x, getPoints()[2].y);
|
||||
if (getLabelOriantation() != LabelOriantation.Horizontal) {
|
||||
g2d.rotate(theta);
|
||||
}
|
||||
StringUtils.drawCenteredText(g2d, label, offset, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
g2d.setTransform(oldTransform);
|
||||
} else {
|
||||
if (isStanding() || getLabelOriantation() == LabelOriantation.Horizontal) {
|
||||
g2d.setTransform(oldTransform);
|
||||
double x = (getPoints()[0].x + getPoints()[1].x - length) / 2.0;
|
||||
double y = (getPoints()[0].y + getPoints()[1].y - width) / 2.0;
|
||||
g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset),
|
||||
(int)(y + calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)));
|
||||
(int)(y + calculateLabelYOffset(shapeRect, textRect, fontMetrics)));
|
||||
} else {
|
||||
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
|
||||
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
||||
calculateLabelYOffset(shapeRect, textRect, fontMetrics));
|
||||
g2d.setTransform(oldTransform);
|
||||
}
|
||||
}
|
||||
// if (getLabelOriantation() == LabelOriantation.Horizontal) {
|
||||
//
|
||||
// drawCenteredText(g2d, label, getNewPoints()[2].x, getNewPoints()[2].x, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
// g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset),
|
||||
// (int)(y + calculateLabelYCoordinate(shapeRect, textRect, fontMetrics)));
|
||||
// } else {
|
||||
// g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
|
||||
// calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
|
||||
// g2d.setTransform(oldTransform);
|
||||
// }
|
||||
}
|
||||
|
||||
protected boolean isStanding() {
|
||||
return supportsStandingMode() && this.length.convertToPixels() > getPoints()[0].distance(getPoints()[1]);
|
||||
}
|
||||
|
||||
private void drawLeads(Graphics2D g2d, double theta, double leadLength) {
|
||||
double endX = points[0].x + Math.cos(theta) * leadLength;
|
||||
double endY = points[0].y + Math.sin(theta) * leadLength;
|
||||
g2d.draw(new Line2D.Double(points[0].x, points[0].y, endX, endY));
|
||||
double endX = getPoints()[0].x + Math.cos(theta) * leadLength;
|
||||
double endY = getPoints()[0].y + Math.sin(theta) * leadLength;
|
||||
g2d.draw(new Line2D.Double(getPoints()[0].x, getPoints()[0].y, endX, endY));
|
||||
|
||||
endX = points[1].x + Math.cos(theta - Math.PI) * leadLength;
|
||||
endY = points[1].y + Math.sin(theta - Math.PI) * leadLength;
|
||||
g2d.draw(new Line2D.Double(points[1].x, points[1].y, endX, endY));
|
||||
endX = getPoints()[1].x + Math.cos(theta - Math.PI) * leadLength;
|
||||
endY = getPoints()[1].y + Math.sin(theta - Math.PI) * leadLength;
|
||||
g2d.draw(new Line2D.Double(getPoints()[1].x, getPoints()[1].y, endX, endY));
|
||||
}
|
||||
|
||||
private void drawLead(Graphics2D g2d, ComponentState componentState, IDrawingObserver observer, boolean isCopperArea) {
|
||||
@@ -310,7 +379,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
|
||||
float thickness = getLeadThickness();
|
||||
|
||||
Line2D line = new Line2D.Double(points[0].x, points[0].y, points[1].x, points[1].y);
|
||||
Line2D line = new Line2D.Double(getPoints()[0].x, getPoints()[0].y, getPoints()[1].x, getPoints()[1].y);
|
||||
|
||||
if (shouldShadeLeads()) {
|
||||
// for some reason the stroked line gets approx 1px thicker when converted to shape
|
||||
@@ -366,7 +435,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
|
||||
protected int calculateLabelYOffset(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
|
||||
return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent();
|
||||
}
|
||||
|
||||
@@ -447,27 +516,48 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return points.length;
|
||||
return getPoints().length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return (Point) points[index];
|
||||
return (Point) getPoints()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
return index < 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.ALWAYS;
|
||||
return getMoveLabel() || index < 2 ? VisibilityPolicy.ALWAYS : VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canControlPointOverlap(int index) {
|
||||
return index >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
points[index].setLocation(point);
|
||||
// when moving one of the ending points, try to retain the angle and distance from the center point to label point
|
||||
if (index < 2) {
|
||||
if (gamma == null) {
|
||||
double x = (getPoints()[1].x + getPoints()[0].x) / 2.0;
|
||||
double y = (getPoints()[1].y + getPoints()[0].y) / 2.0;
|
||||
double theta = Math.atan2(getPoints()[1].y - getPoints()[0].y, getPoints()[1].x - getPoints()[0].x);
|
||||
double beta = Math.atan2(getPoints()[2].y - y, getPoints()[2].x - x);
|
||||
gamma = beta + (Math.PI / 2 - theta);
|
||||
r = getPoints()[2].distance(x, y);
|
||||
} else { // in case when we are copy pasting we don't want to recalculate 3rd point position as they will all move in unison
|
||||
// when we moved the first point, gamma and r were initialized, so now we are canceling
|
||||
gamma = null;
|
||||
r = null;
|
||||
}
|
||||
}
|
||||
|
||||
getPoints()[index].setLocation(point);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Color")
|
||||
@@ -541,7 +631,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
|
||||
@Override
|
||||
public String getInternalLinkName(int index1, int index2) {
|
||||
if ((index1 == 0 && index2 == getControlPointCount() - 1) || (index2 == 0 && index1 == getControlPointCount() - 1))
|
||||
if ((index1 == 0 && index2 == 1) || (index2 == 0 && index1 == 1))
|
||||
return getName();
|
||||
return null;
|
||||
}
|
||||
@@ -560,6 +650,22 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
|
||||
this.flipStanding = flipStanding;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Moveable Label")
|
||||
public boolean getMoveLabel() {
|
||||
return moveLabel;
|
||||
}
|
||||
|
||||
public void setMoveLabel(boolean moveLabel) {
|
||||
this.moveLabel = moveLabel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
if (index >= 2)
|
||||
return null;
|
||||
return Integer.toString(index + 1);
|
||||
}
|
||||
|
||||
public enum LabelOriantation {
|
||||
Directional, Horizontal
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.diylc.components;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.common.LabelPosition;
|
||||
@@ -62,7 +63,7 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
|
||||
protected int calculateLabelYOffset(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
|
||||
if (labelPosition == LabelPosition.ABOVE) {
|
||||
return -5;
|
||||
} else {
|
||||
@@ -70,6 +71,15 @@ public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedCom
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point calculateLabelPosition(Point point1, Point point2) {
|
||||
double x = (point1.x + point2.x) / 2.0;
|
||||
double y = (point1.y + point2.y) / 2.0;
|
||||
double theta = Math.atan2(point2.y - point1.y, point2.x - point2.x) - Math.PI / 2;
|
||||
double r = width.convertToPixels() / 2 + LABEL_FONT.getSize() / 2;
|
||||
return new Point((int) (x + Math.cos(theta) * r), (int) (y + Math.sin(theta) * r));
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label Position")
|
||||
public LabelPosition getLabelPosition() {
|
||||
return labelPosition;
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
@@ -116,11 +117,11 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|
||||
String label = yType == CoordinateType.Letters ? getCoordinateLabel(c) : Integer.toString(c);
|
||||
|
||||
drawPoint.y += yOffset;
|
||||
drawCenteredText(g2d, label,
|
||||
StringUtils.drawCenteredText(g2d, label,
|
||||
firstPoint.x + xOffset, drawPoint.y,
|
||||
HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||
if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) {
|
||||
drawCenteredText(g2d, label,
|
||||
StringUtils.drawCenteredText(g2d, label,
|
||||
secondPoint.x - xOffset, drawPoint.y,
|
||||
HorizontalAlignment.RIGHT, VerticalAlignment.CENTER);
|
||||
}
|
||||
@@ -146,11 +147,11 @@ public abstract class AbstractBoard extends AbstractTransparentComponent<String>
|
||||
String label = xType == CoordinateType.Letters ? getCoordinateLabel(c) : Integer.toString(c);
|
||||
|
||||
drawPoint.x += xOffset;
|
||||
drawCenteredText(g2d, label,
|
||||
StringUtils.drawCenteredText(g2d, label,
|
||||
drawPoint.x, firstPoint.y - 2,
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.TOP);
|
||||
if (getCoordinateDisplay() == CoordinateDisplay.Both_Sides) {
|
||||
drawCenteredText(g2d, label,
|
||||
StringUtils.drawCenteredText(g2d, label,
|
||||
drawPoint.x, (int) (secondPoint.y - COORDINATE_FONT_SIZE),
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.BOTTOM);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
@@ -46,7 +47,7 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Breadboard", category = "Boards", author = "Branislav Stojkovic",
|
||||
description = "Prototyping solderless breadboard", instanceNamePrefix = "BB", stretchable = false,
|
||||
description = "Prototyping solderless breadboard", instanceNamePrefix = "BB",
|
||||
zOrder = IDIYComponent.BOARD, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME)
|
||||
public class Breadboard extends AbstractComponent<Void> {
|
||||
@@ -146,7 +147,7 @@ public class Breadboard extends AbstractComponent<Void> {
|
||||
} else {
|
||||
coordinateX = (int) (point.x + offset + 10.5 * spacing);
|
||||
}
|
||||
drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
|
||||
StringUtils.drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
|
||||
section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||
for (int x = 0; x < 5; x++) {
|
||||
int holeX = (int) (point.x + offset + (x + 6) * spacing);
|
||||
@@ -159,9 +160,9 @@ public class Breadboard extends AbstractComponent<Void> {
|
||||
// Draw horizontal labels
|
||||
if (y == 0) {
|
||||
g2d.setColor(COORDINATE_COLOR);
|
||||
drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y),
|
||||
StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y),
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.TOP);
|
||||
drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y
|
||||
StringUtils.drawCenteredText(g2d, new String(new byte[] {(byte) (a + x + 5 * section)}), holeX, (int) (point.y
|
||||
+ spacing * 30 + COORDINATE_FONT_SIZE / 2), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
|
||||
}
|
||||
}
|
||||
@@ -218,7 +219,7 @@ public class Breadboard extends AbstractComponent<Void> {
|
||||
} else {
|
||||
coordinateX = (int) (point.x + offset + 10.5 * spacing);
|
||||
}
|
||||
drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
|
||||
StringUtils.drawCenteredText(g2d, new Integer(y + 1).toString(), coordinateX, (int) (point.y + (y + 1) * spacing),
|
||||
section == 0 ? HorizontalAlignment.RIGHT : HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
|
||||
// for (int x = 0; x < 5; x++) {
|
||||
int holeX1 = (int) (point.x + offset + 6 * spacing);
|
||||
@@ -314,6 +315,11 @@ public class Breadboard extends AbstractComponent<Void> {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TerminalStripTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
@@ -51,9 +52,9 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards",
|
||||
instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction", stretchable = false,
|
||||
instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction",
|
||||
zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = TerminalStripTransformer.class)
|
||||
public class TerminalStrip extends AbstractTransparentComponent<String> {
|
||||
public class TerminalStrip extends AbstractTransparentComponent<String> implements IContinuity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -455,4 +456,14 @@ public class TerminalStrip extends AbstractTransparentComponent<String> {
|
||||
public String getControlPointNodeName(int index) {
|
||||
return "TerminalStrip" + index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean arePointsConnected(int index1, int index2) {
|
||||
return Math.abs(index1 - index2) == getTerminalCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,4 +167,9 @@ public class CopperTrace extends AbstractLeadedComponent<Void> {
|
||||
public String getControlPointNodeName(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getMoveLabel() {
|
||||
// override to disable edit
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Cut Line", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Cut line", instanceNamePrefix = "CL", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Cut line", instanceNamePrefix = "CL", zOrder = IDIYComponent.COMPONENT,
|
||||
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
|
||||
public class CutLine extends AbstractTransparentComponent<Void> {
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Dot", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Connector dot", instanceNamePrefix = "Dot", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Connector dot", instanceNamePrefix = "Dot", zOrder = IDIYComponent.COMPONENT,
|
||||
bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false, transformer = SimpleComponentTransformer.class)
|
||||
public class Dot extends AbstractComponent<Void> {
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Eyelet", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet", stretchable = false,
|
||||
description = "Eyelet or turret terminal", instanceNamePrefix = "Eyelet",
|
||||
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class)
|
||||
public class Eyelet extends AbstractComponent<String> {
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.SimpleComponentTransformer;
|
||||
import org.diylc.components.AbstractCurvedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
@@ -38,8 +39,8 @@ import org.diylc.utils.Constants;
|
||||
@ComponentDescriptor(name = "Hookup Wire", author = "Branislav Stojkovic", category = "Connectivity",
|
||||
instanceNamePrefix = "W", description = "Flexible wire with two control points", zOrder = IDIYComponent.COMPONENT,
|
||||
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
transformer = SimpleComponentTransformer.class, continuity = true)
|
||||
public class HookupWire extends AbstractCurvedComponent<Void> {
|
||||
transformer = SimpleComponentTransformer.class)
|
||||
public class HookupWire extends AbstractCurvedComponent<Void> implements IContinuity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -132,4 +133,9 @@ public class HookupWire extends AbstractCurvedComponent<Void> {
|
||||
public void setStripeColor(Color stripeColor) {
|
||||
this.stripeColor = stripeColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean arePointsConnected(int index1, int index2) {
|
||||
return Math.abs(index1 - index2) == getControlPointCount() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.diylc.common.SimpleComponentTransformer;
|
||||
import org.diylc.components.AbstractLeadedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
@@ -41,8 +42,8 @@ import org.diylc.core.measures.Size;
|
||||
@ComponentDescriptor(name = "Jumper", author = "Branislav Stojkovic", category = "Connectivity",
|
||||
creationMethod = CreationMethod.POINT_BY_POINT, instanceNamePrefix = "J", description = "",
|
||||
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
transformer = SimpleComponentTransformer.class, continuity = true)
|
||||
public class Jumper extends AbstractLeadedComponent<Void> {
|
||||
transformer = SimpleComponentTransformer.class)
|
||||
public class Jumper extends AbstractLeadedComponent<Void> implements IContinuity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -157,4 +158,14 @@ public class Jumper extends AbstractLeadedComponent<Void> {
|
||||
public Display getDisplay() {
|
||||
return super.getDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean arePointsConnected(int index1, int index2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean getMoveLabel() {
|
||||
// override to disable edit
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false,
|
||||
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad",
|
||||
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "PCB", transformer = SimpleComponentTransformer.class)
|
||||
public class SolderPad extends AbstractComponent<Void> {
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Trace Cut", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Designates the place where a trace on the vero board needs to be cut", instanceNamePrefix = "Cut",
|
||||
stretchable = false, zOrder = IDIYComponent.BOARD + 1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
zOrder = IDIYComponent.BOARD + 1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
transformer = SimpleComponentTransformer.class)
|
||||
public class TraceCut extends AbstractComponent<Void> {
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Turret Lug", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Turret terminal lug", instanceNamePrefix = "Turret", stretchable = false,
|
||||
description = "Turret terminal lug", instanceNamePrefix = "Turret",
|
||||
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = SimpleComponentTransformer.class)
|
||||
public class Turret extends AbstractComponent<String> {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.SimpleComponentTransformer;
|
||||
import org.diylc.components.AbstractCurvedComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IContinuity;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
@@ -47,8 +48,8 @@ import org.diylc.utils.Constants;
|
||||
@ComponentDescriptor(name = "Twisted Leads", author = "Branislav Stojkovic", category = "Connectivity",
|
||||
instanceNamePrefix = "W", description = "A pair of flexible leads twisted tighly together", zOrder = IDIYComponent.COMPONENT,
|
||||
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
transformer = SimpleComponentTransformer.class, continuity = true)
|
||||
public class TwistedWire extends AbstractCurvedComponent<Void> {
|
||||
transformer = SimpleComponentTransformer.class)
|
||||
public class TwistedWire extends AbstractCurvedComponent<Void> implements IContinuity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -432,4 +433,9 @@ public class TwistedWire extends AbstractCurvedComponent<Void> {
|
||||
|
||||
return calculateLength(left, precision) + calculateLength(right, precision);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean arePointsConnected(int index1, int index2) {
|
||||
return Math.abs(index1 - index2) == getControlPointCount() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "9V Battery Snap", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
|
||||
description = "", zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
|
||||
autoEdit = false, transformer = BatterySnapTransformer.class)
|
||||
public class BatterySnap9V extends AbstractTransparentComponent<String> {
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
@@ -54,7 +55,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Cliff 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false,
|
||||
description = "Cliff-style closed panel mount 1/4\" phono jack",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class)
|
||||
public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -246,7 +247,7 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
g2d.setFont(project.getFont());
|
||||
int centerX = (controlPoints[0].x + controlPoints[3].x) / 2;
|
||||
int centerY = (controlPoints[0].y + controlPoints[3].y) / 2;
|
||||
drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
|
||||
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
|
||||
}
|
||||
@@ -338,4 +339,9 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.GeneralPath;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
@@ -54,7 +55,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Closed 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Enclosed panel mount 1/4\" phono jack", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class)
|
||||
public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -269,7 +270,7 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
Rectangle bounds = body[0].getBounds();
|
||||
int centerX = bounds.x + bounds.width / 2;
|
||||
int centerY = bounds.y + bounds.height / 2;
|
||||
drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, name, centerX, centerY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
|
||||
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
|
||||
}
|
||||
@@ -364,4 +365,9 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.diylc.components.transform.DIL_ICTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.ISwitch;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
@@ -55,9 +56,9 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "DIP Switch", author = "Branislav Stojkovic", category = "Electro-Mechanical",
|
||||
instanceNamePrefix = "SW", description = "Dual-in-line package switch", stretchable = false,
|
||||
instanceNamePrefix = "SW", description = "Dual-in-line package switch",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
|
||||
public class DIPSwitch extends AbstractTransparentComponent<String> {
|
||||
public class DIPSwitch extends AbstractTransparentComponent<String> implements ISwitch {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -313,6 +314,7 @@ public class DIPSwitch extends AbstractTransparentComponent<String> {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
Area mainArea = getBody()[0];
|
||||
if (!outlineMode) {
|
||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
@@ -513,4 +515,43 @@ public class DIPSwitch extends AbstractTransparentComponent<String> {
|
||||
return Integer.parseInt(toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPositionCount() {
|
||||
return (int) Math.pow(2, getSwitchCount().getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPositionName(int position) {
|
||||
String binary = toBinary(position);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < getSwitchCount().getValue(); i++) {
|
||||
if (sb.length() > 0)
|
||||
sb.append("-");
|
||||
sb.append(binary.charAt(i) == '0' ? "OFF" : "ON");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean arePointsConnected(int index1, int index2, int position) {
|
||||
String binary = toBinary(position);
|
||||
return Math.abs(index1 - index2) == getSwitchCount().getValue() && binary.charAt(index1 < index2 ? index1 : index2) == '1';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private String toBinary(int n) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
do {
|
||||
builder.append(n % 2);
|
||||
n = n / 2;
|
||||
} while (n > 0);
|
||||
while (builder.length() < getSwitchCount().getValue())
|
||||
builder.append("0");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Fuse Holder (Panel)", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Panel mounted fuse holder", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Panel mounted fuse holder", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "FH", autoEdit = false)
|
||||
public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -69,7 +69,7 @@ public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
|
||||
private static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
private static Color LABEL_COLOR = Color.white;
|
||||
|
||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0)};
|
||||
protected Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0) };
|
||||
transient protected Area[] body;
|
||||
protected String name;
|
||||
protected String value = "";
|
||||
@@ -331,4 +331,9 @@ public class FuseHolderPanel extends AbstractMultiPartComponent<String> {
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "IEC Socket", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Panel mounted IEC power socket", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Panel mounted IEC power socket", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "IEC", autoEdit = false)
|
||||
public class IECSocket extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -385,4 +385,9 @@ public class IECSocket extends AbstractMultiPartComponent<String> {
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Mini Relay", author = "Branislav Stojkovic", category = "Electro-Mechanical",
|
||||
instanceNamePrefix = "RY", description = "Miniature PCB mount relay, like Omron G5V-1 or G5V-2",
|
||||
stretchable = false, zOrder = IDIYComponent.COMPONENT)
|
||||
zOrder = IDIYComponent.COMPONENT)
|
||||
public class MiniRelay extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -304,6 +304,8 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
|
||||
g2d.fill(mainArea);
|
||||
g2d.setComposite(oldComposite);
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
for (Point point : controlPoints) {
|
||||
@@ -425,6 +427,11 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
|
||||
this.body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum RelayType {
|
||||
SPDT, DPDT;
|
||||
}
|
||||
|
||||
+11
-4
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@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", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "SW", autoEdit = false)
|
||||
public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchType> implements ISwitch {
|
||||
|
||||
@@ -243,6 +243,8 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
|
||||
public void setSpacing(Size spacing) {
|
||||
this.spacing = spacing;
|
||||
updateControlPoints();
|
||||
// Reset body shape.
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -391,11 +393,16 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
|
||||
}
|
||||
|
||||
// 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 String getControlPointNodeName(int index) {
|
||||
// we don't want the switch to produce any nodes, it just makes connections
|
||||
return null;
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
@@ -52,12 +53,12 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Open 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono", stretchable = false,
|
||||
description = "Switchcraft-style open panel mount 1/4\" phono jack, stereo and mono",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
|
||||
public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
|
||||
private static final double RING_THETA = Math.PI * 0.795;
|
||||
private static final double SLEEVE_THETA = Math.PI * 0.295;
|
||||
private static final double SLEEVE_THETA = Math.PI * 0.29444444444;
|
||||
private static final double SLEEVE_SWITCHED_THETA = Math.PI * 4 / 3;
|
||||
private static final double SWITCH_THETA = Math.PI * 5 / 3;
|
||||
|
||||
@@ -77,7 +78,9 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
private String value = "";
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient Area[] body;
|
||||
@Deprecated
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Integer angle = 0;
|
||||
private OpenJackType type = OpenJackType.MONO;
|
||||
private boolean showLabels = true;
|
||||
|
||||
@@ -86,7 +89,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
@@ -162,40 +164,24 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
Point sleeveLabel = new Point(0, 0);
|
||||
ringTransform.transform(tipLabel, ringOrSwitchLabel);
|
||||
sleeveTransform.transform(tipLabel, sleeveLabel);
|
||||
double theta = 0;
|
||||
// Rotate if needed
|
||||
if (orientation != Orientation.DEFAULT) {
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (theta != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, controlPoints[0].x, controlPoints[0].y);
|
||||
if (getTheta() != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), controlPoints[0].x, controlPoints[0].y);
|
||||
rotation.transform(tipLabel, tipLabel);
|
||||
rotation.transform(ringOrSwitchLabel, ringOrSwitchLabel);
|
||||
rotation.transform(sleeveLabel, sleeveLabel);
|
||||
}
|
||||
drawCenteredText(g2d, "T", tipLabel.x, tipLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "S", sleeveLabel.x, sleeveLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "T", tipLabel.x, tipLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "S", sleeveLabel.x, sleeveLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
if (getType() == OpenJackType.STEREO)
|
||||
drawCenteredText(g2d, "R", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "R", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
if (getType() == OpenJackType.SWITCHED)
|
||||
drawCenteredText(g2d, "Sw", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "Sw", ringOrSwitchLabel.x, ringOrSwitchLabel.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Area[4];
|
||||
@@ -255,25 +241,9 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
body[3] = ringOrSwitch;
|
||||
}
|
||||
|
||||
double theta = 0;
|
||||
// Rotate if needed
|
||||
if (orientation != Orientation.DEFAULT) {
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Rotate if needed
|
||||
if (theta != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||
if (getTheta() != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), x, y);
|
||||
// Skip the last one because it's already rotated
|
||||
for (int i = 0; i < body.length; i++) {
|
||||
Shape shape = body[i];
|
||||
@@ -288,7 +258,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
return body;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private void updateControlPoints() {
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
@@ -302,20 +271,8 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
AffineTransform.getRotateInstance(getType() == OpenJackType.SWITCHED ? SWITCH_THETA : RING_THETA, x, centerY).transform(controlPoints[0], controlPoints[2]);
|
||||
|
||||
// Rotate if needed
|
||||
if (orientation != Orientation.DEFAULT) {
|
||||
double theta = 0;
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||
if (getTheta() != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), x, y);
|
||||
for (Point point : controlPoints) {
|
||||
rotation.transform(point, point);
|
||||
}
|
||||
@@ -388,17 +345,27 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
public Integer getAngle() {
|
||||
if (angle == null) {
|
||||
if (orientation != null && orientation != Orientation.DEFAULT)
|
||||
angle = Integer.parseInt(orientation.name().replace("_", ""));
|
||||
else
|
||||
angle = 0;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
public void setAngle(Integer angle) {
|
||||
this.angle = angle;
|
||||
updateControlPoints();
|
||||
// Invalidate the body
|
||||
body = null;
|
||||
}
|
||||
|
||||
protected double getTheta() {
|
||||
return Math.toRadians(getAngle());
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public OpenJackType getType() {
|
||||
return type;
|
||||
@@ -433,6 +400,11 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum OpenJackType {
|
||||
|
||||
MONO, STEREO, SWITCHED;
|
||||
|
||||
+29
-40
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Pilot Lamp Holder", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Fender-style pilot bulb holder for T2 and T-3 ¼ miniature bayonet lamps", stretchable = false,
|
||||
description = "Fender-style pilot bulb holder for T2 and T-3 ¼ miniature bayonet lamps",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PL")
|
||||
public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -61,6 +61,8 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
private static Color BASE_COLOR = Color.lightGray;
|
||||
private static Color WAFER_COLOR = Color.decode("#CD8500");
|
||||
|
||||
private static final double SLEEVE_THETA = Math.PI * 0.29444444444;
|
||||
|
||||
private static Size THREAD_OUTER_DIAMETER = new Size(11 / 16d, SizeUnit.in);
|
||||
private static Size NUT_DIAMETER = new Size(14 / 16d, SizeUnit.in);
|
||||
private static Size THREAD_THICKNESS = new Size(0.05d, SizeUnit.in);
|
||||
@@ -76,7 +78,9 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
private String value = "";
|
||||
private Point[] controlPoints = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) };
|
||||
transient Area[] body;
|
||||
@Deprecated
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Integer angle = 0;
|
||||
|
||||
public PilotLampHolder() {
|
||||
super();
|
||||
@@ -154,7 +158,6 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
drawSelectionOutline(g2d, componentState, outlineMode, project, drawingObserver);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Area[6];
|
||||
@@ -191,7 +194,7 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
Area sleeve =
|
||||
new Area(new RoundRectangle2D.Double(x - springWidth / 2, y - holeToEdge, springWidth, springLength,
|
||||
springWidth, springWidth));
|
||||
sleeve.transform(AffineTransform.getRotateInstance(Math.PI * 0.295, x, centerY));
|
||||
sleeve.transform(AffineTransform.getRotateInstance(SLEEVE_THETA, x, centerY));
|
||||
sleeve.add(new Area(new Ellipse2D.Double(x - ringDiameter / 2, centerY - ringDiameter / 2, ringDiameter, ringDiameter)));
|
||||
sleeve.subtract(new Area(new Ellipse2D.Double(x - innerDiameter / 2, centerY - innerDiameter / 2, innerDiameter, innerDiameter)));
|
||||
|
||||
@@ -232,24 +235,8 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
nut.subtract(link);
|
||||
thread.subtract(link);
|
||||
|
||||
double theta = 0;
|
||||
// Rotate if needed
|
||||
if (orientation != Orientation.DEFAULT) {
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (theta != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||
if (getTheta() != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(getTheta(), x, y);
|
||||
for (Area area : body) {
|
||||
if (area != null)
|
||||
area.transform(rotation);
|
||||
@@ -264,7 +251,6 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
return body;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
private void updateControlPoints() {
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
@@ -283,20 +269,8 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
rotation.transform(controlPoints[2], controlPoints[3]);
|
||||
|
||||
// Rotate if needed
|
||||
if (orientation != Orientation.DEFAULT) {
|
||||
double theta = 0;
|
||||
switch (orientation) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
rotation = AffineTransform.getRotateInstance(theta, x, y);
|
||||
if (getTheta() != 0) {
|
||||
rotation = AffineTransform.getRotateInstance(getTheta(), x, y);
|
||||
for (Point point : controlPoints) {
|
||||
rotation.transform(point, point);
|
||||
}
|
||||
@@ -413,14 +387,29 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
public Integer getAngle() {
|
||||
if (angle == null) {
|
||||
if (orientation != null && orientation != Orientation.DEFAULT)
|
||||
angle = Integer.parseInt(orientation.name().replace("_", ""));
|
||||
else
|
||||
angle = 0;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
public void setAngle(Integer angle) {
|
||||
this.angle = angle;
|
||||
updateControlPoints();
|
||||
// Invalidate the body
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected double getTheta() {
|
||||
return Math.toRadians(getAngle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.awt.geom.Area;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
@@ -50,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Plastic DC Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Panel mount plastic DC jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Panel mount plastic DC jack", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "J", autoEdit = false)
|
||||
public class PlasticDCJack extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -182,9 +183,9 @@ public class PlasticDCJack extends AbstractMultiPartComponent<String> {
|
||||
int spacing = (int) SPACING.convertToPixels();
|
||||
g2d.setColor(MARKING_COLOR);
|
||||
g2d.setFont(project.getFont().deriveFont(12f));
|
||||
drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "+" : "-", controlPoints[0].x,
|
||||
StringUtils.drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "+" : "-", controlPoints[0].x,
|
||||
controlPoints[0].y - spacing * 7 / 16, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "_" : "+", controlPoints[2].x,
|
||||
StringUtils.drawCenteredText(g2d, getPolarity() == DCPolarity.CENTER_NEGATIVE ? "_" : "+", controlPoints[2].x,
|
||||
controlPoints[2].y - spacing * 3 / 4, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
@@ -262,4 +263,9 @@ public class PlasticDCJack extends AbstractMultiPartComponent<String> {
|
||||
public void setPolarity(DCPolarity polarity) {
|
||||
this.polarity = polarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "RCA Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "Panel mount RCA phono jack socket", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
|
||||
description = "Panel mount RCA phono jack socket", zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J")
|
||||
public class RCAJack extends AbstractMultiPartComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -320,4 +319,9 @@ public class RCAJack extends AbstractMultiPartComponent<String> {
|
||||
public String getControlPointNodeName(int index) {
|
||||
return getName() + (index == 0 ? "Tip" : "Sleeve");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
-473
@@ -1,473 +0,0 @@
|
||||
/*
|
||||
|
||||
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.components.electromechanical;
|
||||
//
|
||||
//import java.awt.AlphaComposite;
|
||||
//import java.awt.Color;
|
||||
//import java.awt.Composite;
|
||||
//import java.awt.FontMetrics;
|
||||
//import java.awt.Graphics2D;
|
||||
//import java.awt.Point;
|
||||
//import java.awt.Rectangle;
|
||||
//import java.awt.geom.Area;
|
||||
//import java.awt.geom.Rectangle2D;
|
||||
//import java.awt.geom.RoundRectangle2D;
|
||||
//
|
||||
//import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
//import org.diylc.common.Display;
|
||||
//import org.diylc.common.IPlugInPort;
|
||||
//import org.diylc.common.ObjectCache;
|
||||
//import org.diylc.common.Orientation;
|
||||
//import org.diylc.components.AbstractTransparentComponent;
|
||||
//import org.diylc.core.ComponentState;
|
||||
//import org.diylc.core.IDIYComponent;
|
||||
//import org.diylc.core.IDrawingObserver;
|
||||
//import org.diylc.core.Project;
|
||||
//import org.diylc.core.Theme;
|
||||
//import org.diylc.core.VisibilityPolicy;
|
||||
//import org.diylc.core.annotations.ComponentDescriptor;
|
||||
//import org.diylc.core.annotations.EditableProperty;
|
||||
//import org.diylc.core.annotations.KeywordPolicy;
|
||||
//import org.diylc.core.measures.Size;
|
||||
//import org.diylc.core.measures.SizeUnit;
|
||||
//import org.diylc.utils.Constants;
|
||||
//
|
||||
//@ComponentDescriptor(name = "Subminiature DIL Relay", author = "Branislav Stojkovic", category = "Electromechanical",
|
||||
// instanceNamePrefix = "RY", description = "Subminiature DIL relay with one or two poles", stretchable = false,
|
||||
// zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
//public class SubminiatureDILRelay extends AbstractTransparentComponent<String> {
|
||||
//
|
||||
// private static final long serialVersionUID = 1L;
|
||||
//
|
||||
// public static Color BODY_COLOR = Color.decode("#EDEDD5");
|
||||
// public static Color BORDER_COLOR = BODY_COLOR.darker();
|
||||
// public static Color PIN_COLOR = Color.decode("#00B2EE");
|
||||
// public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
|
||||
// public static Color INDENT_COLOR = Color.gray.darker();
|
||||
// public static Color LABEL_COLOR = Color.darkGray;
|
||||
// public static int EDGE_RADIUS = 6;
|
||||
// public static Size PIN_SIZE = new Size(0.04d, SizeUnit.in);
|
||||
// public static Size INDENT_SIZE = new Size(0.05d, SizeUnit.in);
|
||||
//
|
||||
// public static Size PIN_SPACING = new Size(0.2d, SizeUnit.in);
|
||||
// public static Size ROW_SPACING = new Size(0.3d, SizeUnit.in);
|
||||
// public static Size SECTION_SPACING = new Size(0.3d, SizeUnit.in);
|
||||
//
|
||||
// private String value = "";
|
||||
// private Orientation orientation = Orientation.DEFAULT;
|
||||
// private PinCount pinCount = PinCount._4;
|
||||
// private Size pinSpacing = PIN_SPACING;
|
||||
// private Size rowSpacing = ROW_SPACING;
|
||||
// private Size sectionSpacing = SECTION_SPACING;
|
||||
// private Point[] controlPoints = new Point[] {new Point(0, 0)};
|
||||
// protected Display display = Display.NAME;
|
||||
// private Color bodyColor = BODY_COLOR;
|
||||
// private Color borderColor = BORDER_COLOR;
|
||||
// private Color labelColor = LABEL_COLOR;
|
||||
// private Color indentColor = INDENT_COLOR;
|
||||
// transient private Area[] body;
|
||||
//
|
||||
// public SubminiatureDILRelay() {
|
||||
// super();
|
||||
// updateControlPoints();
|
||||
// }
|
||||
//
|
||||
// @EditableProperty
|
||||
// public String getValue() {
|
||||
// return value;
|
||||
// }
|
||||
//
|
||||
// public void setValue(String value) {
|
||||
// this.value = value;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty
|
||||
// public Orientation getOrientation() {
|
||||
// return orientation;
|
||||
// }
|
||||
//
|
||||
// public void setOrientation(Orientation orientation) {
|
||||
// this.orientation = orientation;
|
||||
// updateControlPoints();
|
||||
// // Reset body shape.
|
||||
// body = null;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Contacts")
|
||||
// public PinCount getPinCount() {
|
||||
// return pinCount;
|
||||
// }
|
||||
//
|
||||
// public void setPinCount(PinCount pinCount) {
|
||||
// this.pinCount = pinCount;
|
||||
// updateControlPoints();
|
||||
// // Reset body shape;
|
||||
// body = null;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Pin spacing")
|
||||
// public Size getPinSpacing() {
|
||||
// return pinSpacing;
|
||||
// }
|
||||
//
|
||||
// public void setPinSpacing(Size pinSpacing) {
|
||||
// this.pinSpacing = pinSpacing;
|
||||
// updateControlPoints();
|
||||
// // Reset body shape;
|
||||
// body = null;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Row spacing")
|
||||
// public Size getRowSpacing() {
|
||||
// return rowSpacing;
|
||||
// }
|
||||
//
|
||||
// public void setRowSpacing(Size rowSpacing) {
|
||||
// this.rowSpacing = rowSpacing;
|
||||
// updateControlPoints();
|
||||
// // Reset body shape;
|
||||
// body = null;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Section spacing")
|
||||
// public Size getSectionSpacing() {
|
||||
// return sectionSpacing;
|
||||
// }
|
||||
//
|
||||
// public void setSectionSpacing(Size sectionSpacing) {
|
||||
// this.sectionSpacing = sectionSpacing;
|
||||
// updateControlPoints();
|
||||
// // Reset body shape;
|
||||
// body = null;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty
|
||||
// public Display getDisplay() {
|
||||
// if (display == null) {
|
||||
// display = Display.VALUE;
|
||||
// }
|
||||
// return display;
|
||||
// }
|
||||
//
|
||||
// public void setDisplay(Display display) {
|
||||
// this.display = display;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getControlPointCount() {
|
||||
// return controlPoints.length;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Point getControlPoint(int index) {
|
||||
// return controlPoints[index];
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isControlPointSticky(int index) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
// return VisibilityPolicy.NEVER;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setControlPoint(Point point, int index) {
|
||||
// controlPoints[index].setLocation(point);
|
||||
// body = null;
|
||||
// }
|
||||
//
|
||||
// private void updateControlPoints() {
|
||||
// Point firstPoint = controlPoints[0];
|
||||
// controlPoints = new Point[pinCount.getValue() * 2];
|
||||
// controlPoints[0] = firstPoint;
|
||||
// int pinSpacing = (int) this.pinSpacing.convertToPixels();
|
||||
// int sectionSpacing = (int) this.sectionSpacing.convertToPixels();
|
||||
// int rowSpacing = (int) this.rowSpacing.convertToPixels();
|
||||
// // Update control points.
|
||||
// int dx1;
|
||||
// int dy1;
|
||||
// int dx2;
|
||||
// int dy2;
|
||||
// for (int i = 0; i < pinCount.getValue(); i++) {
|
||||
// int spacing = i == pinCount.getValue() - 1 ? sectionSpacing + (i - 1) * pinSpacing : i * pinSpacing;
|
||||
// switch (orientation) {
|
||||
// case DEFAULT:
|
||||
// dx1 = 0;
|
||||
// dy1 = spacing;
|
||||
// dx2 = rowSpacing;
|
||||
// dy2 = spacing;
|
||||
// break;
|
||||
// case _90:
|
||||
// dx1 = -spacing;
|
||||
// dy1 = 0;
|
||||
// dx2 = -spacing;
|
||||
// dy2 = rowSpacing;
|
||||
// break;
|
||||
// case _180:
|
||||
// dx1 = 0;
|
||||
// dy1 = -spacing;
|
||||
// dx2 = -rowSpacing;
|
||||
// dy2 = -spacing;
|
||||
// break;
|
||||
// case _270:
|
||||
// dx1 = spacing;
|
||||
// dy1 = 0;
|
||||
// dx2 = spacing;
|
||||
// dy2 = -rowSpacing;
|
||||
// break;
|
||||
// default:
|
||||
// throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
// }
|
||||
// controlPoints[i] = new Point(firstPoint.x + dx1, firstPoint.y + dy1);
|
||||
// controlPoints[i + pinCount.getValue()] = new Point(firstPoint.x + dx2, firstPoint.y + dy2);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public Area[] getBody() {
|
||||
// if (body == null) {
|
||||
// body = new Area[2];
|
||||
//
|
||||
// int pinSize = (int) PIN_SIZE.convertToPixels();
|
||||
//
|
||||
// int minX = Integer.MAX_VALUE;
|
||||
// int maxX = Integer.MIN_VALUE;
|
||||
// int minY = Integer.MAX_VALUE;
|
||||
// int maxY = Integer.MIN_VALUE;
|
||||
// for (int i = 0; i < this.controlPoints.length; i++) {
|
||||
// if (this.controlPoints[i].x > maxX)
|
||||
// maxX = this.controlPoints[i].x;
|
||||
// if (this.controlPoints[i].x < minX)
|
||||
// minX = this.controlPoints[i].x;
|
||||
// if (this.controlPoints[i].y > maxY)
|
||||
// maxY = this.controlPoints[i].y;
|
||||
// if (this.controlPoints[i].y < minY)
|
||||
// minY = this.controlPoints[i].y;
|
||||
// }
|
||||
// int width = maxX - minX;
|
||||
// int height = maxY - minY;
|
||||
//
|
||||
// Area indentation = null;
|
||||
// int indentationSize = getClosestOdd(INDENT_SIZE.convertToPixels());
|
||||
// switch (orientation) {
|
||||
// case DEFAULT:
|
||||
// indentation =
|
||||
// new Area(new Rectangle2D.Double(minX + width / 2 - indentationSize / 2, minY - indentationSize / 2
|
||||
// - pinSize, indentationSize, indentationSize));
|
||||
// break;
|
||||
// case _90:
|
||||
// indentation =
|
||||
// new Area(new Rectangle2D.Double(minX + width - indentationSize / 2 + pinSize, minY + height / 2
|
||||
// - indentationSize / 2, indentationSize, indentationSize));
|
||||
// break;
|
||||
// case _180:
|
||||
// indentation =
|
||||
// new Area(new Rectangle2D.Double(minX + width / 2 - indentationSize / 2, minY + height - indentationSize
|
||||
// / 2 + pinSize, indentationSize, indentationSize));
|
||||
// break;
|
||||
// case _270:
|
||||
// indentation =
|
||||
// new Area(new Rectangle2D.Double(minX - indentationSize / 2 - pinSize, minY + height / 2 - indentationSize
|
||||
// / 2, indentationSize, indentationSize));
|
||||
// break;
|
||||
// default:
|
||||
// throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
// }
|
||||
//
|
||||
// body[0] =
|
||||
// new Area(new RoundRectangle2D.Double(minX - pinSize, minY - pinSize, width + 2 * pinSize, height + 2
|
||||
// * pinSize, EDGE_RADIUS, EDGE_RADIUS));
|
||||
// body[1] = indentation;
|
||||
// if (indentation != null) {
|
||||
// indentation.intersect(body[0]);
|
||||
// }
|
||||
// }
|
||||
// return body;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
// IDrawingObserver drawingObserver) {
|
||||
// if (checkPointsClipped(g2d.getClip())) {
|
||||
// return;
|
||||
// }
|
||||
// Area mainArea = getBody()[0];
|
||||
//
|
||||
// Composite oldComposite = g2d.getComposite();
|
||||
// if (alpha < MAX_ALPHA) {
|
||||
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
// }
|
||||
// g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor());
|
||||
// g2d.fill(mainArea);
|
||||
// g2d.setComposite(oldComposite);
|
||||
//
|
||||
// Color finalBorderColor;
|
||||
// if (outlineMode) {
|
||||
// Theme theme =
|
||||
// (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
// finalBorderColor =
|
||||
// componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
// : theme.getOutlineColor();
|
||||
// } else {
|
||||
// finalBorderColor =
|
||||
// componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
// : getBorderColor();
|
||||
// }
|
||||
// g2d.setColor(finalBorderColor);
|
||||
// g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
// if (outlineMode) {
|
||||
// Area area = new Area(mainArea);
|
||||
// area.subtract(getBody()[1]);
|
||||
// g2d.draw(area);
|
||||
// } else {
|
||||
// g2d.draw(mainArea);
|
||||
// if (getBody()[1] != null) {
|
||||
// g2d.setColor(getIndentColor());
|
||||
// g2d.fill(getBody()[1]);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!outlineMode) {
|
||||
// int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
// for (Point point : controlPoints) {
|
||||
// g2d.setColor(PIN_COLOR);
|
||||
// g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||
// g2d.setColor(PIN_BORDER_COLOR);
|
||||
// g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Draw label.
|
||||
// g2d.setFont(LABEL_FONT);
|
||||
// Color finalLabelColor;
|
||||
// if (outlineMode) {
|
||||
// Theme theme =
|
||||
// (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
// finalLabelColor =
|
||||
// componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
// : theme.getOutlineColor();
|
||||
// } else {
|
||||
// finalLabelColor =
|
||||
// componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
// : getLabelColor();
|
||||
// }
|
||||
// g2d.setColor(finalLabelColor);
|
||||
// FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||
// String label = "";
|
||||
// label = (getDisplay() == Display.NAME) ? getName() : getValue();
|
||||
// if (getDisplay() == Display.NONE) {
|
||||
// label = "";
|
||||
// }
|
||||
// if (getDisplay() == Display.BOTH) {
|
||||
// label = getName() + " " + (getValue() == null ? "" : getValue().toString());
|
||||
// }
|
||||
// Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
|
||||
// int textHeight = (int) (rect.getHeight());
|
||||
// int textWidth = (int) (rect.getWidth());
|
||||
// // Center text horizontally and vertically
|
||||
// Rectangle bounds = mainArea.getBounds();
|
||||
// int x = bounds.x + (bounds.width - textWidth) / 2;
|
||||
// int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent();
|
||||
// g2d.drawString(label, x, y);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
// int radius = 6 * width / 32;
|
||||
// g2d.setColor(BODY_COLOR);
|
||||
// g2d.fillRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
|
||||
// g2d.setColor(BORDER_COLOR);
|
||||
// g2d.drawRoundRect(width / 6, 1, 4 * width / 6, height - 4, radius, radius);
|
||||
// int pinSize = 2 * width / 32;
|
||||
// g2d.setColor(PIN_COLOR);
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// if (i == 1)
|
||||
// continue;
|
||||
// g2d.fillOval(width / 3 - pinSize, (height / 5) * (i + 1) - 1, pinSize, pinSize);
|
||||
// g2d.fillOval(2 * width / 3 + 1, (height / 5) * (i + 1) - 1, pinSize, pinSize);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Body")
|
||||
// public Color getBodyColor() {
|
||||
// if (bodyColor == null) {
|
||||
// bodyColor = BODY_COLOR;
|
||||
// }
|
||||
// return bodyColor;
|
||||
// }
|
||||
//
|
||||
// public void setBodyColor(Color bodyColor) {
|
||||
// this.bodyColor = bodyColor;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Border")
|
||||
// public Color getBorderColor() {
|
||||
// if (borderColor == null) {
|
||||
// borderColor = BORDER_COLOR;
|
||||
// }
|
||||
// return borderColor;
|
||||
// }
|
||||
//
|
||||
// public void setBorderColor(Color borderColor) {
|
||||
// this.borderColor = borderColor;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Label")
|
||||
// public Color getLabelColor() {
|
||||
// if (labelColor == null) {
|
||||
// labelColor = LABEL_COLOR;
|
||||
// }
|
||||
// return labelColor;
|
||||
// }
|
||||
//
|
||||
// public void setLabelColor(Color labelColor) {
|
||||
// this.labelColor = labelColor;
|
||||
// }
|
||||
//
|
||||
// @EditableProperty(name = "Indent")
|
||||
// public Color getIndentColor() {
|
||||
// if (indentColor == null) {
|
||||
// indentColor = INDENT_COLOR;
|
||||
// }
|
||||
// return indentColor;
|
||||
// }
|
||||
//
|
||||
// public void setIndentColor(Color indentColor) {
|
||||
// this.indentColor = indentColor;
|
||||
// }
|
||||
//
|
||||
// public static enum PinCount {
|
||||
//
|
||||
// _3, _4, _5;
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return name().replace("_", "").concat(" per side");
|
||||
// }
|
||||
//
|
||||
// public int getValue() {
|
||||
// return Integer.parseInt(name().replace("_", ""));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -26,6 +26,7 @@ import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.Orientation;
|
||||
@@ -90,8 +91,8 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
|
||||
break;
|
||||
}
|
||||
|
||||
drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
protected void drawMainLabel(Graphics2D g2d, Project project, boolean outlineMode, ComponentState componentState) {
|
||||
@@ -120,7 +121,7 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
|
||||
}
|
||||
g2d.translate(0, getMainLabelYOffset());
|
||||
|
||||
drawCenteredText(g2d, getName(), 0, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, getName(), 0, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
|
||||
g2d.setTransform(originalTx);
|
||||
}
|
||||
@@ -189,6 +190,11 @@ public abstract class AbstractGuitarPickup extends AbstractTransparentComponent<
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Polarity getPolarity() {
|
||||
if (polarity == null)
|
||||
|
||||
+4
-3
@@ -21,6 +21,7 @@ import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.OrientationHV;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
@@ -60,11 +61,11 @@ public abstract class AbstractSingleOrHumbuckerPickup extends AbstractGuitarPick
|
||||
}
|
||||
|
||||
if (getPolarity() == Polarity.North || getPolarity() == Polarity.South) {
|
||||
drawCenteredText(g2d, getPolarity().name().substring(0, 1), (points[1].x + points[2].x) / 2 + dx, (points[1].y + points[2].y) / 2 + dy, HorizontalAlignment.CENTER,
|
||||
StringUtils.drawCenteredText(g2d, getPolarity().name().substring(0, 1), (points[1].x + points[2].x) / 2 + dx, (points[1].y + points[2].y) / 2 + dy, HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.CENTER);
|
||||
} else {
|
||||
drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "N", (points[0].x + points[1].x) / 2 + dx, (points[0].y + points[1].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "S", (points[2].x + points[3].x) / 2 + dx, (points[2].y + points[3].y) / 2 + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Humbucker Pickup", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Double-coil humbucker guitar pickup (PAF, Mini Humbuckers, Filtertrons)", stretchable = false,
|
||||
description = "Double-coil humbucker guitar pickup (PAF, Mini Humbuckers, Filtertrons)",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
|
||||
public class HumbuckerPickup extends AbstractGuitarPickup {
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Jazz Bass Pickup", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Single coil pickup for Jazz Bass and similar guitars", stretchable = false,
|
||||
description = "Single coil pickup for Jazz Bass and similar guitars",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
|
||||
public class JazzBassPickup extends AbstractSingleOrHumbuckerPickup {
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "LP Toggle Switch", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Les Paul style 3 position toggle switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Les Paul style 3 position toggle switch", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "SW")
|
||||
public class LPSwitch extends AbstractTransparentComponent<String> implements ISwitch {
|
||||
|
||||
@@ -301,6 +301,11 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
@@ -323,12 +328,12 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
// we don't want the switch to produce any nodes, it just makes connections
|
||||
return null;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String getControlPointNodeName(int index) {
|
||||
// // we don't want the switch to produce any nodes, it just makes connections
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// switch stuff
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Lever Switch", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Strat-style lever switch", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Strat-style lever switch", zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "SW", keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||
keywordTag = "Guitar Wiring Diagram")
|
||||
public class LeverSwitch extends AbstractTransparentComponent<String> implements ISwitch {
|
||||
@@ -428,11 +428,11 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
// we don't want the switch to produce any nodes, it just makes connections
|
||||
return null;
|
||||
}
|
||||
// @Override
|
||||
// public String getControlPointNodeName(int index) {
|
||||
// // we don't want the switch to produce any nodes, it just makes connections
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// switch stuff
|
||||
|
||||
@@ -476,4 +476,9 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "P-90 Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Single coil P-90 guitar pickup, both \"dog ear\" and \"soap bar\"", stretchable = false,
|
||||
description = "Single coil P-90 guitar pickup, both \"dog ear\" and \"soap bar\"",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
|
||||
public class P90Pickup extends AbstractSingleOrHumbuckerPickup {
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "P- Bass Pickup", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Split-coil pickup for P-Bass and similar guitars", stretchable = false,
|
||||
description = "Split-coil pickup for P-Bass and similar guitars",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
|
||||
public class PBassPickup extends AbstractSingleOrHumbuckerPickup {
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Single Coil Pickup", category = "Guitar", author = "Branislav Stojkovic",
|
||||
description = "Single coil guitar pickup, both Strat and Tele style", stretchable = false,
|
||||
description = "Single coil guitar pickup, both Strat and Tele style",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "PKP", autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
|
||||
public class SingleCoilPickup extends AbstractSingleOrHumbuckerPickup {
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.diylc.utils.BomEntry;
|
||||
import org.diylc.utils.BomMaker;
|
||||
|
||||
@ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "",
|
||||
instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW,
|
||||
instanceNamePrefix = "BOM", zOrder = IDIYComponent.TEXT, bomPolicy = BomPolicy.NEVER_SHOW,
|
||||
autoEdit = false)
|
||||
public class BOM extends AbstractComponent<Void> {
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Ground", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "GND", description = "Ground schematic symbol", stretchable = false,
|
||||
instanceNamePrefix = "GND", description = "Ground schematic symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false)
|
||||
public class GroundSymbol extends AbstractComponent<Void> {
|
||||
|
||||
@@ -133,12 +133,17 @@ public class GroundSymbol extends AbstractComponent<Void> {
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
this.point = point;
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public String getControlPointNodeName(int index) {
|
||||
// return getName();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
return getName();
|
||||
public String getCommonPointName(int pointIndex) {
|
||||
return "GND";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
|
||||
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc",
|
||||
description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT,
|
||||
flexibleZOrder = true, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW)
|
||||
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW)
|
||||
public class Image extends AbstractTransparentComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc",
|
||||
description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true,
|
||||
stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
|
||||
bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
|
||||
public class Label extends AbstractComponent<String> {
|
||||
|
||||
public static String DEFAULT_TEXT = "Double click to edit text";
|
||||
@@ -244,7 +244,7 @@ public class Label extends AbstractComponent<String> {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Vertical alignment")
|
||||
@EditableProperty(name = "Vertical Alignment")
|
||||
public VerticalAlignment getVerticalAlignment() {
|
||||
if (verticalAlignment == null) {
|
||||
verticalAlignment = VerticalAlignment.CENTER;
|
||||
@@ -256,7 +256,7 @@ public class Label extends AbstractComponent<String> {
|
||||
this.verticalAlignment = verticalAlignment;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Horizontal alignment")
|
||||
@EditableProperty(name = "Horizontal Alignment")
|
||||
public HorizontalAlignment getHorizontalAlignment() {
|
||||
if (horizontalAlignment == null) {
|
||||
horizontalAlignment = HorizontalAlignment.CENTER;
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc",
|
||||
description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE,
|
||||
flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
|
||||
flexibleZOrder = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
|
||||
public class PCBText extends AbstractComponent<Void> {
|
||||
|
||||
public static String DEFAULT_TEXT = "Double click to edit text";
|
||||
@@ -118,12 +118,16 @@ public class PCBText extends AbstractComponent<Void> {
|
||||
break;
|
||||
}
|
||||
|
||||
AffineTransform oldTx = g2d.getTransform();
|
||||
|
||||
// Flip horizontally
|
||||
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
|
||||
tx.translate(-2 * x - textWidth, 0);
|
||||
g2d.transform(tx);
|
||||
|
||||
g2d.drawString(text, x, y);
|
||||
|
||||
g2d.setTransform(oldTx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
|
||||
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.components.misc;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.components.transform.TextTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.MultiLineText;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Auto-Wrap Label", author = "Branislav Stojkovic", category = "Misc",
|
||||
description = "User defined label with auto-wrapped text", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true,
|
||||
bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
|
||||
public class WrapLabel extends AbstractComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Size DEFAULT_WIDTH = new Size(1.5d, SizeUnit.in);
|
||||
public static Size DEFAULT_HEIGHT = new Size(0.5d, SizeUnit.in);
|
||||
|
||||
protected Point[] controlPoints = new Point[] {new Point(0, 0),
|
||||
new Point((int) DEFAULT_WIDTH.convertToPixels(), (int) DEFAULT_HEIGHT.convertToPixels())};
|
||||
protected Point firstPoint = new Point();
|
||||
protected Point secondPoint = new Point();
|
||||
|
||||
private Font font = LABEL_FONT;
|
||||
private Color color = LABEL_COLOR;
|
||||
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.LEFT;
|
||||
|
||||
private String value = "The quick brown fox jumped over a lazy dog";
|
||||
|
||||
public WrapLabel() {
|
||||
}
|
||||
|
||||
@MultiLineText
|
||||
@EditableProperty
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
firstPoint.setLocation(Math.min(controlPoints[0].x, controlPoints[1].x),
|
||||
Math.min(controlPoints[0].y, controlPoints[1].y));
|
||||
secondPoint.setLocation(Math.max(controlPoints[0].x, controlPoints[1].x),
|
||||
Math.max(controlPoints[0].y, controlPoints[1].y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.WHEN_SELECTED;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Font getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
public void setFont(Font font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
//Bold and italic fields are named to be alphabetically after Font. This is
|
||||
// important!
|
||||
|
||||
@EditableProperty(name = "Font Bold")
|
||||
public boolean getBold() {
|
||||
return font.isBold();
|
||||
}
|
||||
|
||||
public void setBold(boolean bold) {
|
||||
if (bold) {
|
||||
if (font.isItalic()) {
|
||||
font = font.deriveFont(Font.BOLD + Font.ITALIC);
|
||||
} else {
|
||||
font = font.deriveFont(Font.BOLD);
|
||||
}
|
||||
} else {
|
||||
if (font.isItalic()) {
|
||||
font = font.deriveFont(Font.ITALIC);
|
||||
} else {
|
||||
font = font.deriveFont(Font.PLAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Font Italic")
|
||||
public boolean getItalic() {
|
||||
return font.isItalic();
|
||||
}
|
||||
|
||||
public void setItalic(boolean italic) {
|
||||
if (italic) {
|
||||
if (font.isBold()) {
|
||||
font = font.deriveFont(Font.BOLD + Font.ITALIC);
|
||||
} else {
|
||||
font = font.deriveFont(Font.ITALIC);
|
||||
}
|
||||
} else {
|
||||
if (font.isBold()) {
|
||||
font = font.deriveFont(Font.BOLD);
|
||||
} else {
|
||||
font = font.deriveFont(Font.PLAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Font Size")
|
||||
public int getFontSize() {
|
||||
return font.getSize();
|
||||
}
|
||||
|
||||
public void setFontSize(int size) {
|
||||
font = font.deriveFont((float) size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
g2d.setColor(componentState == ComponentState.SELECTED ? LABEL_COLOR_SELECTED : color);
|
||||
g2d.setFont(font);
|
||||
|
||||
int x = firstPoint.x;
|
||||
int y = firstPoint.y;
|
||||
int maxWidth = secondPoint.x - firstPoint.x;
|
||||
|
||||
StringUtils.drawWrappedText(value, g2d, x, y, maxWidth, horizontalAlignment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
g2d.setColor(LABEL_COLOR);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(10f * width / 32).deriveFont(Font.PLAIN));
|
||||
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
Rectangle2D rect = fontMetrics.getStringBounds("Wrap", g2d);
|
||||
|
||||
int textHeight = (int) (rect.getHeight());
|
||||
int textWidth = (int) (rect.getWidth());
|
||||
|
||||
int x = (width - textWidth) / 2 + 1;
|
||||
int y = (int) (4f * width / 32) + fontMetrics.getAscent();
|
||||
|
||||
g2d.drawString("Wrap", x, y);
|
||||
y += g2d.getFont().getSize();
|
||||
g2d.drawString("Text", x, y);
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Horizontal Alignment")
|
||||
public HorizontalAlignment getHorizontalAlignment() {
|
||||
if (horizontalAlignment == null) {
|
||||
horizontalAlignment = HorizontalAlignment.CENTER;
|
||||
}
|
||||
return horizontalAlignment;
|
||||
}
|
||||
|
||||
public void setHorizontalAlignment(HorizontalAlignment alignment) {
|
||||
this.horizontalAlignment = alignment;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -57,7 +58,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Audio Transformer", author = "Branislav Stojkovic", category = "Passive",
|
||||
instanceNamePrefix = "TR", description = "Small signal audio transformer with EI core", stretchable = false,
|
||||
instanceNamePrefix = "TR", description = "Small signal audio transformer with EI core",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
|
||||
public class AudioTransformer extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -315,11 +316,11 @@ public class AudioTransformer extends AbstractMultiPartComponent<String> {
|
||||
AffineTransform tx = getTx();
|
||||
if (tx != null)
|
||||
tx.transform(wPoint, wPoint);
|
||||
drawCenteredText(g2d, "P", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "P", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
wPoint = new Point((int) (controlPoints[0].x + windingSpacing.convertToPixels() - project.getFontSize()), (int) (controlPoints[0].y + leadSpacing.convertToPixels()));
|
||||
if (tx != null)
|
||||
tx.transform(wPoint, wPoint);
|
||||
drawCenteredText(g2d, "S", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "S", wPoint.x, wPoint.y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
|
||||
// Draw label.
|
||||
Color finalLabelColor;
|
||||
@@ -518,4 +519,9 @@ public class AudioTransformer extends AbstractMultiPartComponent<String> {
|
||||
this.secondaryCT = secondaryCT;
|
||||
updateControlPoints();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -56,7 +57,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Multi-Section Capacitor", author = "Branislav Stojkovic", category = "Passive",
|
||||
instanceNamePrefix = "C", description = "Multi-section vertically mounted electrolytic capacitor, similar to JJ, CE and others",
|
||||
stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacitance[]> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -414,7 +415,7 @@ public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacita
|
||||
|
||||
Rectangle bounds = area[0].getBounds();
|
||||
|
||||
drawCenteredText(g2d, label, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, label, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
|
||||
// draw polarity markers
|
||||
g2d.setColor(pinColor.darker());
|
||||
@@ -516,4 +517,9 @@ public class MultiSectionCapacitor extends AbstractTransparentComponent<Capacita
|
||||
public void setPinColor(Color pinColor) {
|
||||
this.pinColor = pinColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Potentiometer", author = "Branislav Stojkovic", category = "Passive",
|
||||
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
|
||||
description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT, stretchable = false,
|
||||
description = "Panel mount potentiometer with solder lugs", zOrder = IDIYComponent.COMPONENT,
|
||||
transformer = PotentiometerTransformer.class)
|
||||
public class PotentiometerPanel extends AbstractPotentiometer {
|
||||
|
||||
@@ -470,6 +470,11 @@ public class PotentiometerPanel extends AbstractPotentiometer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
ThroughHole("Through Hole"), PCB("PCB");
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ package org.diylc.components.passive;
|
||||
import java.awt.Color;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.GeneralPath;
|
||||
@@ -36,7 +37,7 @@ import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "Potentiometer", author = "MCbx", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "VR", description = "Potentiometer symbol", stretchable = false,
|
||||
instanceNamePrefix = "VR", description = "Potentiometer symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Schematic")
|
||||
public class PotentiometerSymbol extends Abstract3LegSymbol {
|
||||
|
||||
@@ -48,6 +49,7 @@ public class PotentiometerSymbol extends Abstract3LegSymbol {
|
||||
|
||||
public Shape[] getBody() {
|
||||
Shape[] body = new Shape[3];
|
||||
Point[] controlPoints = getControlPoints();
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transformer Coil", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "L",
|
||||
description = "Transformer coil symbol. Use multiple instances together with \"Transformer Core Symbol\"<br>to draw transformer schematics.",
|
||||
stretchable = false, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||
keywordTag = "Schematic")
|
||||
public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.Voltage> {
|
||||
|
||||
@@ -282,4 +282,9 @@ public class TransformerCoil extends AbstractComponent<org.diylc.core.measures.V
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transformer Core", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "T",
|
||||
description = "Transformer core symbol. Use multiple instances together with \"Transformer Coil Symbol\"<br>to draw transformer schematics.",
|
||||
stretchable = true, zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG,
|
||||
creationMethod = CreationMethod.POINT_BY_POINT, keywordTag = "Schematic")
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG, creationMethod = CreationMethod.POINT_BY_POINT, keywordTag = "Schematic")
|
||||
public class TransformerCore extends AbstractComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -154,6 +153,10 @@ public class TransformerCore extends AbstractComponent<Void> {
|
||||
@Override
|
||||
public void setValue(Void value) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
|
||||
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
|
||||
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT,
|
||||
stretchable = false)
|
||||
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT)
|
||||
public class TrimmerPotentiometer extends AbstractPotentiometer {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -530,6 +529,11 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum TrimmerType {
|
||||
FLAT_SMALL("Horizontal Small 1"), FLAT_SMALL2("Horizontal Small 2"), FLAT_XSMALL("Horizontal X-Small"), FLAT_LARGE(
|
||||
"Horizontal Medium"), FLAT_XLARGE("Horizontal Large"), VERTICAL_INLINE("Vertical Inline"), VERTICAL_OFFSET(
|
||||
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
|
||||
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.components.semiconductors;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Area;
|
||||
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.netlist.ISpiceMapper;
|
||||
|
||||
public abstract class AbstractTransistorPackage extends AbstractTransparentComponent<String> implements ISpiceMapper {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected String value = "";
|
||||
protected TransistorPinout pinout;
|
||||
protected Orientation orientation = Orientation.DEFAULT;
|
||||
protected Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient protected Area[] body;
|
||||
|
||||
protected Color bodyColor;
|
||||
protected Color borderColor;
|
||||
protected Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
|
||||
public AbstractTransistorPackage() {
|
||||
}
|
||||
|
||||
protected abstract void updateControlPoints();
|
||||
|
||||
@Override
|
||||
public int mapToSpiceNode(int index) {
|
||||
if (getPinout() == null)
|
||||
return index;
|
||||
|
||||
switch (getPinout()) {
|
||||
case BJT_CBE:
|
||||
return index;
|
||||
case BJT_EBC:
|
||||
return 2 - index;
|
||||
case JFET_DGS:
|
||||
case MOSFET_DGS:
|
||||
return index;
|
||||
case JFET_DSG:
|
||||
case MOSFET_DSG:
|
||||
switch (index) {
|
||||
case 0: return 0;
|
||||
case 1: return 2;
|
||||
case 2: return 1;
|
||||
}
|
||||
case JFET_GSD:
|
||||
case MOSFET_GSD:
|
||||
switch (index) {
|
||||
case 0: return 1;
|
||||
case 1: return 2;
|
||||
case 2: return 0;
|
||||
}
|
||||
case JFET_SGD:
|
||||
case MOSFET_SGD:
|
||||
return 2 - index;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
return getPinout() == null ? "Pinout not configured, validate this line" : (getPinout().toString() + " pinout");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
if (getPinout() == null)
|
||||
return null;
|
||||
return getPinout().name().substring(0, 1);
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label")
|
||||
public Color getLabelColor() {
|
||||
if (labelColor == null) {
|
||||
labelColor = LABEL_COLOR;
|
||||
}
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public TransistorPinout getPinout() {
|
||||
return pinout;
|
||||
}
|
||||
|
||||
public void setPinout(TransistorPinout pinout) {
|
||||
this.pinout = pinout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
if (index >= 3)
|
||||
return null;
|
||||
return Integer.toString(index + 1);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
@@ -36,7 +37,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "BJT", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "Bipolar junction transistor schematic symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
|
||||
public class BJTSymbol extends Abstract3LegSymbol {
|
||||
|
||||
@@ -46,6 +47,7 @@ public class BJTSymbol extends Abstract3LegSymbol {
|
||||
|
||||
public Shape[] getBody() {
|
||||
Shape[] body = new Shape[3];
|
||||
Point[] controlPoints = getControlPoints();
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -61,7 +62,7 @@ import org.diylc.core.measures.Voltage;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Bridge Rectifier", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "BR", description = "Few variations of bridge rectifier chips", stretchable = false,
|
||||
instanceNamePrefix = "BR", description = "Few variations of bridge rectifier chips",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
|
||||
public class BridgeRectifier extends AbstractTransparentComponent<String> {
|
||||
|
||||
@@ -561,7 +562,7 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
|
||||
break;
|
||||
}
|
||||
|
||||
drawCenteredText(g2d, pointLabels[i], point.x + dx, point.y + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, pointLabels[i], point.x + dx, point.y + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,10 +582,10 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
|
||||
g2d.fillOval(width * 2 / 8, height * 6 / 8 - pinSize, pinSize, pinSize);
|
||||
g2d.setColor(LABEL_COLOR);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(8f * width / 32));
|
||||
drawCenteredText(g2d, "+", width * 2 / 8 + 1, height * 2 / 8 + 4 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "-", width * 2 / 8 + 1, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 2 / 8 + 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "+", width * 2 / 8 + 1, height * 2 / 8 + 4 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "-", width * 2 / 8 + 1, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 2 / 8 + 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "~", width * 6 / 8 - 2 * width / 32, height * 6 / 8 - 5 * width / 32, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
@@ -663,6 +664,11 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
|
||||
this.labelOriantation = labelOriantation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum RectifierType {
|
||||
|
||||
MiniDIP1("DFM A", PinShape.Square),
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "DIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "IC", description = "Dual-in-line package IC", stretchable = false,
|
||||
instanceNamePrefix = "IC", description = "Dual-in-line package IC",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
|
||||
public class DIL_IC extends AbstractTransparentComponent<String> {
|
||||
|
||||
@@ -538,6 +538,11 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
|
||||
this.displayNumbers = numbers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum PinCount {
|
||||
|
||||
_4, _6, _8, _10, _12, _14, _16, _18, _20, _22, _24, _26, _28, _30, _32, _34, _36, _38, _40, _42, _44, _46, _48, _50;
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -53,7 +54,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "IC", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "IC", description = "IC symbol with 3 or 5 contacts", stretchable = false,
|
||||
instanceNamePrefix = "IC", description = "IC symbol with 3 or 5 contacts",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
|
||||
public class ICSymbol extends AbstractTransparentComponent<String> {
|
||||
|
||||
@@ -134,12 +135,12 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
|
||||
if (display == Display.BOTH) {
|
||||
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
|
||||
}
|
||||
drawCenteredText(g2d, label, x, controlPoints[0].y + pinSpacing, HorizontalAlignment.CENTER,
|
||||
StringUtils.drawCenteredText(g2d, label, x, controlPoints[0].y + pinSpacing, HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.CENTER);
|
||||
// Draw +/- markers
|
||||
drawCenteredText(g2d, getFlip() ? "+" : "-", controlPoints[0].x + pinSpacing, controlPoints[0].y, HorizontalAlignment.CENTER,
|
||||
StringUtils.drawCenteredText(g2d, getFlip() ? "+" : "-", controlPoints[0].x + pinSpacing, controlPoints[0].y, HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, getFlip() ? "-" : "+", controlPoints[1].x + pinSpacing, controlPoints[1].y, HorizontalAlignment.CENTER,
|
||||
StringUtils.drawCenteredText(g2d, getFlip() ? "-" : "+", controlPoints[1].x + pinSpacing, controlPoints[1].y, HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
@@ -156,8 +157,8 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
|
||||
g2d.fill(area);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(8f));
|
||||
drawCenteredText(g2d, "-", 3 * margin, height / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
drawCenteredText(g2d, "+", 3 * margin + 1, height * 2 / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "-", 3 * margin, height / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, "+", 3 * margin + 1, height * 2 / 3, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
// g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND,
|
||||
// BasicStroke.JOIN_ROUND));
|
||||
g2d.draw(area);
|
||||
@@ -296,4 +297,9 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.GeneralPath;
|
||||
@@ -34,7 +35,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "JFET", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "Q", description = "JFET transistor schematic symbol", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "JFET transistor schematic symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
|
||||
public class JFETSymbol extends Abstract3LegSymbol {
|
||||
|
||||
@@ -44,6 +45,7 @@ public class JFETSymbol extends Abstract3LegSymbol {
|
||||
|
||||
public Shape[] getBody() {
|
||||
Shape[] body = new Shape[3];
|
||||
Point[] controlPoints = getControlPoints();
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -51,7 +52,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Logic Gate", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "LG", description = "Basic logic gate schematic symbols", stretchable = false,
|
||||
instanceNamePrefix = "LG", description = "Basic logic gate schematic symbols",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
|
||||
public class LogicGateSymbol extends AbstractTransparentComponent<String> {
|
||||
|
||||
@@ -132,7 +133,7 @@ public class LogicGateSymbol extends AbstractTransparentComponent<String> {
|
||||
if (display == Display.BOTH) {
|
||||
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
|
||||
}
|
||||
drawCenteredText(g2d, label, x, controlPoints[0].y + (getControlPointCount() == 2 ? 0 : pinSpacing), HorizontalAlignment.CENTER,
|
||||
StringUtils.drawCenteredText(g2d, label, x, controlPoints[0].y + (getControlPointCount() == 2 ? 0 : pinSpacing), HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.CENTER);
|
||||
}
|
||||
|
||||
@@ -318,6 +319,11 @@ public class LogicGateSymbol extends AbstractTransparentComponent<String> {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum GateType {
|
||||
Buffer(false), Not(true), Or(false), And(false), Xor(false), Nor(true), Nand(true), Xnor(true);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.GeneralPath;
|
||||
@@ -34,7 +35,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "MOSFET", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "Q", description = "MOSFET transistor schematic symbol", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "MOSFET transistor schematic symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_TAG_AND_VALUE, keywordTag = "Schematic")
|
||||
public class MOSFETSymbol extends Abstract3LegSymbol {
|
||||
|
||||
@@ -44,6 +45,7 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
|
||||
|
||||
public Shape[] getBody() {
|
||||
Shape[] body = new Shape[3];
|
||||
Point[] controlPoints = getControlPoints();
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
|
||||
@@ -55,7 +55,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "SIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "IC", description = "Single-in-line package IC", stretchable = false,
|
||||
instanceNamePrefix = "IC", description = "Single-in-line package IC",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = SIL_ICTransformer.class)
|
||||
public class SIL_IC extends AbstractTransparentComponent<String> {
|
||||
|
||||
@@ -145,6 +145,11 @@ public class SIL_IC extends AbstractTransparentComponent<String> {
|
||||
body = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.diylc.components.semiconductors;
|
||||
|
||||
public enum TransistorPinout {
|
||||
|
||||
BJT_EBC, BJT_CBE, JFET_DSG, JFET_GSD, JFET_DGS, JFET_SGD, MOSFET_DSG, MOSFET_GSD, MOSFET_DGS, MOSFET_SGD;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String[] parts = name().split("_");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < parts[1].length(); i++) {
|
||||
if (i > 0)
|
||||
sb.append("-");
|
||||
sb.append(parts[1].charAt(i));
|
||||
}
|
||||
sb.append(" ").append(parts[0]);
|
||||
return sb.toString();
|
||||
};
|
||||
}
|
||||
@@ -37,15 +37,12 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TO1Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
@@ -54,9 +51,9 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-1)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with small metal body", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "Transistor with small metal body",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO1Transformer.class)
|
||||
public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
public class TransistorTO1 extends AbstractTransistorPackage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -71,14 +68,6 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
public static Size BODY_LENGTH = new Size(0.4d, SizeUnit.in);
|
||||
public static Size EDGE_RADIUS = new Size(2d, SizeUnit.mm);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient private Area body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
private boolean folded = false;
|
||||
private Size pinSpacing = PIN_SPACING;
|
||||
|
||||
@@ -86,56 +75,12 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
super();
|
||||
updateControlPoints();
|
||||
alpha = (byte) 100;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
bodyColor = BODY_COLOR;
|
||||
borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) getPinSpacing().convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -162,7 +107,7 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Area getBody() {
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
int x = (controlPoints[0].x + controlPoints[1].x + controlPoints[2].x) / 3;
|
||||
int y = (controlPoints[0].y + controlPoints[1].y + controlPoints[2].y) / 3;
|
||||
@@ -170,41 +115,44 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
int bodyLength = getClosestOdd(BODY_LENGTH.convertToPixels());
|
||||
int edgeRadius = (int) EDGE_RADIUS.convertToPixels();
|
||||
|
||||
Area newBody = null;
|
||||
|
||||
if (folded) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x - bodyLength, y - bodyDiameter / 2, bodyLength, bodyDiameter,
|
||||
edgeRadius, edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x - bodyLength / 2, y - bodyDiameter / 2, bodyLength / 2,
|
||||
newBody.add(new Area(new Rectangle2D.Double(x - bodyLength / 2, y - bodyDiameter / 2, bodyLength / 2,
|
||||
bodyDiameter)));
|
||||
break;
|
||||
case _90:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x - bodyDiameter / 2, y - bodyLength, bodyDiameter, bodyLength,
|
||||
edgeRadius, edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyLength / 2, bodyDiameter,
|
||||
newBody.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyLength / 2, bodyDiameter,
|
||||
bodyLength / 2)));
|
||||
break;
|
||||
case _180:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x, y - bodyDiameter / 2, bodyLength, bodyDiameter, edgeRadius,
|
||||
edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyLength / 2, bodyDiameter)));
|
||||
newBody.add(new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyLength / 2, bodyDiameter)));
|
||||
break;
|
||||
case _270:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new RoundRectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength, edgeRadius,
|
||||
edgeRadius));
|
||||
body.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength / 2)));
|
||||
newBody.add(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyLength / 2)));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
} else {
|
||||
body = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
}
|
||||
|
||||
body = new Area[] { newBody };
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -228,7 +176,7 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
|
||||
}
|
||||
|
||||
Area mainArea = getBody();
|
||||
Area mainArea = getBody()[0];
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
@@ -298,15 +246,6 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public boolean getFolded() {
|
||||
return folded;
|
||||
@@ -330,34 +269,4 @@ public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label")
|
||||
public Color getLabelColor() {
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,15 +37,12 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TO220Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
@@ -54,9 +51,9 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-220)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class)
|
||||
public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
public class TransistorTO220 extends AbstractTransistorPackage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -78,15 +75,8 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
public static Size LEAD_LENGTH = new Size(3.5d, SizeUnit.mm);
|
||||
public static Size LEAD_THICKNESS = new Size(0.8d, SizeUnit.mm);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient private Shape[] body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color tabColor = TAB_COLOR;
|
||||
private Color tabBorderColor = TAB_BORDER_COLOR;
|
||||
private Display display = Display.NAME;
|
||||
private boolean folded = false;
|
||||
private Size leadLength = LEAD_LENGTH;
|
||||
|
||||
@@ -94,56 +84,12 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
super();
|
||||
updateControlPoints();
|
||||
alpha = (byte) 100;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
bodyColor = BODY_COLOR;
|
||||
borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -170,9 +116,9 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Shape[] getBody() {
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
body = new Shape[2];
|
||||
body = new Area[2];
|
||||
int x = controlPoints[0].x;
|
||||
int y = controlPoints[0].y;
|
||||
int pinSpacing = (int) PIN_SPACING.convertToPixels();
|
||||
@@ -187,68 +133,68 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
if (folded) {
|
||||
body[0] = new Rectangle2D.Double(x + leadLength, y + pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth);
|
||||
body[0] = new Area(new Rectangle2D.Double(x + leadLength, y + pinSpacing - bodyWidth / 2, bodyHeight, bodyWidth));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x + leadLength + bodyHeight, y + pinSpacing - bodyWidth / 2, tabHeight,
|
||||
bodyWidth));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x + leadLength + bodyHeight + tabHeight / 2
|
||||
- tabHoleDiameter / 2, y + pinSpacing - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y + pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth);
|
||||
body[1] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y + pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x + bodyThickness / 2 - tabThickness, y + pinSpacing - bodyWidth / 2,
|
||||
tabThickness, bodyWidth);
|
||||
tabThickness, bodyWidth));
|
||||
}
|
||||
break;
|
||||
case _90:
|
||||
if (folded) {
|
||||
body[0] = new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + leadLength, bodyWidth, bodyHeight);
|
||||
body[0] = new Area(new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + leadLength, bodyWidth, bodyHeight));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + leadLength + bodyHeight, bodyWidth,
|
||||
tabHeight));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x - pinSpacing - tabHoleDiameter / 2, y
|
||||
+ leadLength + bodyHeight + tabHeight / 2 - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness);
|
||||
body[1] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x - pinSpacing - bodyWidth / 2, y + bodyThickness / 2 - tabThickness, bodyWidth,
|
||||
tabThickness);
|
||||
tabThickness));
|
||||
}
|
||||
break;
|
||||
case _180:
|
||||
if (folded) {
|
||||
body[0] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - leadLength - bodyHeight, y - pinSpacing - bodyWidth / 2, bodyHeight,
|
||||
bodyWidth);
|
||||
bodyWidth));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x - leadLength - bodyHeight - tabHeight,
|
||||
y - pinSpacing - bodyWidth / 2, tabHeight, bodyWidth));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x - leadLength - bodyHeight - tabHeight / 2
|
||||
- tabHoleDiameter / 2, y - pinSpacing - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth);
|
||||
body[1] =
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, tabThickness, bodyWidth);
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, bodyThickness, bodyWidth));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x - bodyThickness / 2, y - pinSpacing - bodyWidth / 2, tabThickness, bodyWidth));
|
||||
}
|
||||
break;
|
||||
case _270:
|
||||
if (folded) {
|
||||
body[0] =
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - leadLength - bodyHeight, bodyWidth,
|
||||
bodyHeight);
|
||||
bodyHeight));
|
||||
body[1] =
|
||||
new Area(new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2,
|
||||
y - leadLength - bodyHeight - tabHeight, bodyWidth, tabHeight));
|
||||
((Area) body[1]).subtract(new Area(new Ellipse2D.Double(x + pinSpacing - tabHoleDiameter / 2, y
|
||||
- leadLength - bodyHeight - tabHeight / 2 - tabHoleDiameter / 2, tabHoleDiameter, tabHoleDiameter)));
|
||||
} else {
|
||||
body[0] =
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness);
|
||||
body[1] =
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, tabThickness);
|
||||
body[0] = new Area(
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, bodyThickness));
|
||||
body[1] = new Area(
|
||||
new Rectangle2D.Double(x + pinSpacing - bodyWidth / 2, y - bodyThickness / 2, bodyWidth, tabThickness));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -382,7 +328,7 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
} else {
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
: LABEL_COLOR;
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
String label = "";
|
||||
@@ -428,24 +374,6 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
g2d.drawLine(width / 2 + bodySize / 3, margin + tabSize + bodySize, width / 2 + bodySize / 3, height - margin);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Tab")
|
||||
public Color getTabColor() {
|
||||
return tabColor;
|
||||
@@ -488,16 +416,4 @@ public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
public void setTabBorderColor(Color tabBorderColor) {
|
||||
this.tabBorderColor = tabBorderColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-3)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with large metal body", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "Transistor with large metal body",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
public class TransistorTO3 extends AbstractTransparentComponent<String> {
|
||||
|
||||
|
||||
@@ -37,15 +37,12 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.TO92Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
@@ -54,9 +51,9 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-92)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false,
|
||||
instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO92Transformer.class)
|
||||
public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
public class TransistorTO92 extends AbstractTransistorPackage {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -69,14 +66,6 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
public static Size PIN_SPACING = new Size(0.05d, SizeUnit.in);
|
||||
public static Size BODY_DIAMETER = new Size(0.2d, SizeUnit.in);
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point[] controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
|
||||
transient private Area body;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
private Color labelColor = LABEL_COLOR;
|
||||
protected Display display = Display.NAME;
|
||||
private boolean folded = false;
|
||||
private Size pinSpacing = PIN_SPACING;
|
||||
|
||||
@@ -84,27 +73,8 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
super();
|
||||
updateControlPoints();
|
||||
alpha = (byte) 100;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
updateControlPoints();
|
||||
// Reset body shape;
|
||||
body = null;
|
||||
bodyColor = BODY_COLOR;
|
||||
borderColor = BORDER_COLOR;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
@@ -134,32 +104,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return controlPoints.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point getControlPoint(int index) {
|
||||
return controlPoints[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point point, int index) {
|
||||
controlPoints[index].setLocation(point);
|
||||
body = null;
|
||||
}
|
||||
|
||||
private void updateControlPoints() {
|
||||
protected void updateControlPoints() {
|
||||
int pinSpacing = (int) getPinSpacing().convertToPixels();
|
||||
// Update control points.
|
||||
int x = controlPoints[0].x;
|
||||
@@ -186,25 +131,27 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
public Area getBody() {
|
||||
public Area[] getBody() {
|
||||
if (body == null) {
|
||||
int x = (controlPoints[0].x + controlPoints[1].x + controlPoints[2].x) / 3;
|
||||
int y = (controlPoints[0].y + controlPoints[1].y + controlPoints[2].y) / 3;
|
||||
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
|
||||
|
||||
Area newBody = null;
|
||||
|
||||
if (folded) {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body = new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
case _90:
|
||||
body = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
case _180:
|
||||
body = new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
case _270:
|
||||
body = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyDiameter));
|
||||
newBody = new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y, bodyDiameter, bodyDiameter));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
@@ -212,33 +159,35 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
} else {
|
||||
switch (orientation) {
|
||||
case DEFAULT:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, 3 * bodyDiameter / 4,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter, y - bodyDiameter / 2, 3 * bodyDiameter / 4,
|
||||
bodyDiameter)));
|
||||
break;
|
||||
case _90:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y - bodyDiameter, bodyDiameter,
|
||||
3 * bodyDiameter / 4)));
|
||||
break;
|
||||
case _180:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x + bodyDiameter / 4, y - bodyDiameter / 2,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x + bodyDiameter / 4, y - bodyDiameter / 2,
|
||||
3 * bodyDiameter / 4, bodyDiameter)));
|
||||
break;
|
||||
case _270:
|
||||
body =
|
||||
newBody =
|
||||
new Area(new Ellipse2D.Double(x - bodyDiameter / 2, y - bodyDiameter / 2, bodyDiameter, bodyDiameter));
|
||||
body.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y + bodyDiameter / 4, bodyDiameter,
|
||||
newBody.subtract(new Area(new Rectangle2D.Double(x - bodyDiameter / 2, y + bodyDiameter / 4, bodyDiameter,
|
||||
3 * bodyDiameter / 4)));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
}
|
||||
|
||||
body = new Area[] { newBody };
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -261,7 +210,7 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
}
|
||||
}
|
||||
|
||||
Area mainArea = getBody();
|
||||
Area mainArea = getBody()[0];
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
|
||||
@@ -337,46 +286,4 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
g2d.fillOval(width / 2 - pinSize / 2, (height / 4) * (i + 1), pinSize, pinSize);
|
||||
}
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Body")
|
||||
public Color getBodyColor() {
|
||||
return bodyColor;
|
||||
}
|
||||
|
||||
public void setBodyColor(Color bodyColor) {
|
||||
this.bodyColor = bodyColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Border")
|
||||
public Color getBorderColor() {
|
||||
return borderColor;
|
||||
}
|
||||
|
||||
public void setBorderColor(Color borderColor) {
|
||||
this.borderColor = borderColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Label")
|
||||
public Color getLabelColor() {
|
||||
if (labelColor == null) {
|
||||
labelColor = LABEL_COLOR;
|
||||
}
|
||||
return labelColor;
|
||||
}
|
||||
|
||||
public void setLabelColor(Color labelColor) {
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Display getDisplay() {
|
||||
if (display == null) {
|
||||
display = Display.NAME;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
public void setDisplay(Display display) {
|
||||
this.display = display;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,6 +407,11 @@ public abstract class PassiveSMDComponent<T> extends AbstractTransparentComponen
|
||||
this.labelColor = labelColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum SMDSize {
|
||||
|
||||
_0805(new Size(0.05d, SizeUnit.in), new Size(0.08d, SizeUnit.in)), _1206(new Size(1.6d, SizeUnit.mm), new Size(3.2d,
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||
import org.diylc.core.measures.Capacitance;
|
||||
|
||||
@ComponentDescriptor(name = "SMD Capacitor", author = "Branislav Stojkovic", category = "SMD",
|
||||
instanceNamePrefix = "C", description = "Surface mount capacitor", stretchable = false,
|
||||
instanceNamePrefix = "C", description = "Surface mount capacitor",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
public class SMDCapacitor extends PassiveSMDComponent<Capacitance> {
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||
import org.diylc.core.measures.Resistance;
|
||||
|
||||
@ComponentDescriptor(name = "SMD Resistor", author = "Branislav Stojkovic", category = "SMD", instanceNamePrefix = "C",
|
||||
description = "Surface mount resistor", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
description = "Surface mount resistor", zOrder = IDIYComponent.COMPONENT,
|
||||
keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
public class SMDResistor extends PassiveSMDComponent<Resistance> {
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.Display;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
@@ -121,7 +122,7 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
||||
if (display == Display.BOTH) {
|
||||
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
|
||||
}
|
||||
drawCenteredText(g2d, label, rect.x + rect.width, rect.y + rect.height, HorizontalAlignment.RIGHT,
|
||||
StringUtils.drawCenteredText(g2d, label, rect.x + rect.width, rect.y + rect.height, HorizontalAlignment.RIGHT,
|
||||
VerticalAlignment.BOTTOM);
|
||||
}
|
||||
|
||||
@@ -297,4 +298,9 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
|
||||
rotate.transform(this.controlPoints[i], this.controlPoints[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "Diode", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "V", description = "Diode tube symbol", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "V", description = "Diode tube symbol", zOrder = IDIYComponent.COMPONENT,
|
||||
keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TubeSymbolTransformer.class)
|
||||
public class DiodeSymbol extends AbstractTubeSymbol {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "Pentode", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "V", description = "Pentode tube symbol", stretchable = false,
|
||||
instanceNamePrefix = "V", description = "Pentode tube symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE,
|
||||
transformer = TubeSymbolTransformer.class)
|
||||
public class PentodeSymbol extends AbstractTubeSymbol {
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
|
||||
@ComponentDescriptor(name = "Triode", author = "Branislav Stojkovic", category = "Schematic Symbols",
|
||||
instanceNamePrefix = "V", description = "Triode tube symbol", stretchable = false,
|
||||
instanceNamePrefix = "V", description = "Triode tube symbol",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE,
|
||||
transformer = TubeSymbolTransformer.class)
|
||||
public class TriodeSymbol extends AbstractTubeSymbol {
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
@@ -53,7 +54,7 @@ import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Tube Socket", author = "Branislav Stojkovic", category = "Tubes",
|
||||
instanceNamePrefix = "V", description = "Various types of tube/valve sockets", stretchable = false,
|
||||
instanceNamePrefix = "V", description = "Various types of tube/valve sockets",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
|
||||
@@ -314,7 +315,7 @@ public class TubeSocket extends AbstractTransparentComponent<String> {
|
||||
double theta = Math.atan2(controlPoints[i + 1].y - controlPoints[0].y, controlPoints[i + 1].x - controlPoints[0].x);
|
||||
double x = controlPoints[i + 1].x - Math.cos(theta) * electrodeLabelOffset;
|
||||
double y = controlPoints[i + 1].y - Math.sin(theta) * electrodeLabelOffset;
|
||||
drawCenteredText(g2d, label, (int)x, (int)y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, label, (int)x, (int)y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import org.diylc.common.INetlistAnalyzer;
|
||||
import org.diylc.components.electromechanical.ClosedJack1_4;
|
||||
import org.diylc.components.electromechanical.OpenJack1_4;
|
||||
@@ -69,7 +71,7 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Guitar Diagrams";
|
||||
return "Analyze Guitar Diagrams (beta)";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,19 +79,17 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
return "Guitar";
|
||||
}
|
||||
|
||||
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
|
||||
List<Summary> summaries = new ArrayList<Summary>();
|
||||
for (Netlist n : netlists)
|
||||
summaries.add(summarize(n, preferredOutput));
|
||||
|
||||
return summaries;
|
||||
@Override
|
||||
public String getFontName() {
|
||||
return new JLabel().getFont().getName();
|
||||
}
|
||||
|
||||
|
||||
private int positiveCount;
|
||||
private int negativeCount;
|
||||
private int noiseCount;
|
||||
|
||||
private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||
protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
|
||||
List<String> notes = new ArrayList<String>();
|
||||
|
||||
Tree tree = constructTree(netlist);
|
||||
@@ -309,11 +309,18 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
|
||||
}
|
||||
}
|
||||
|
||||
return new Summary(netlist, notes, tree);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("Parallel/Series connectivity tree:<br><br>").append(tree.toHTML(0));
|
||||
if (!notes.isEmpty())
|
||||
sb.append("<br><br>Notes:<br>");
|
||||
for (String v : notes) {
|
||||
sb.append(" ").append(v).append("<br>");
|
||||
}
|
||||
|
||||
return new Summary(netlist, sb.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree constructTree(Netlist netlist) throws TreeException {
|
||||
List<Node> jackTipNodes = find(JACK_TYPES, "Tip", netlist);
|
||||
List<Node> jackSleeveNodes = find(JACK_TYPES, "Sleeve", netlist);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Maps DIYLC component control points to spice-compatible node indices.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public interface ISpiceMapper {
|
||||
|
||||
int mapToSpiceNode(int pontIndex);
|
||||
|
||||
String getComment();
|
||||
|
||||
String getPrefix();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user