Compare commits

..

54 Commits

Author SHA1 Message Date
Branislav Stojkovic bb3b37f23b patched osx component loading issue, investigate further 2019-03-25 08:21:20 +01:00
Branislav Stojkovic fcea5975a8 change backup folder name 2019-03-24 21:38:27 +01:00
Branislav Stojkovic 2294ac45a2 copy loaded file as-is to backup folder 2019-03-24 21:37:37 +01:00
Branislav Stojkovic 5598f22b2f Added "Auto-Wrap Label" component
extracted string rendering function into a separate class
2019-03-24 08:34:28 +01:00
Branislav Stojkovic 812b7adb28 remove newPoints and reuse points for backward compatibility 2019-03-23 22:44:09 +01:00
Branislav Stojkovic 9fd5a8fe96 redo relaxed validation 2019-03-23 19:11:06 +01:00
Branislav Stojkovic 0b8952e354 relax validation of control point collision while dragging 2019-03-23 18:54:44 +01:00
Branislav Stojkovic 5c47ff1ef0 added ability to include or exclude switches from netlist analyzer 2019-03-23 18:05:28 +01:00
Branislav Stojkovic b85b93404b Added mini toolbar in the top-right corner of the screen with transform
actions exposed for quick access
2019-03-22 23:37:59 +01:00
Branislav Stojkovic b46f46aa99 When pasting a group of components that contain at least one "PCB Text"
instance, some of the other components get rendered mirrored while
position the pasted components
2019-03-22 22:29:05 +01:00
Branislav Stojkovic 48266d3b27 fix the 3rd control point when copy-pasting 2019-03-22 21:04:54 +01:00
Branislav Stojkovic eb6cc76f02 make autosave params configurable 2019-03-22 20:58:27 +01:00
Branislav Stojkovic a5d512ca37 Merge branch 'master' of https://github.com/bancika/diy-layout-creator.git 2019-03-22 16:39:23 +01:00
Branislav Stojkovic 1d038b5f8c better log 2019-03-22 16:39:08 +01:00
Branislav Stojkovic 9366f9c602 Auto-save plugin now works by periodically creating project backups in
user\.diylc\autoSave directory and maintains file history, keeping the
last X versions of the file. Maximum size for all backups is
configurable and pre-set to 64MB
2019-03-22 16:38:01 +01:00
bancika 23b4fcae02 Update README.md 2019-03-22 10:34:55 +01:00
Branislav Stojkovic 14a994e68f Improve "Expand Selection" feature to use the same algorithm as netlists
for better precision<
2019-03-22 00:47:28 +01:00
Branislav Stojkovic 894ff1a2cb Assign new name for pasted component if the project already contains
components under that name
2019-03-20 22:35:28 +01:00
Branislav Stojkovic 78dcd27e1d Some schematic symbols (transistors, potentiometer...) get into bad
state when rotated and flipped at the same time
2019-03-20 20:06:38 +01:00
Branislav Stojkovic 714db98afa deleted old file
fixed pin rendering on some components
2019-03-20 19:27:46 +01:00
Branislav Stojkovic 2faa2c6d61 reorganized "stretchable" property into more granular control at the
point level

added controlable label to pot symbol and transistor symbols
2019-03-20 19:21:31 +01:00
Branislav Stojkovic 3c45336afe rename a function 2019-03-19 21:26:03 +01:00
Branislav Stojkovic a0601cc83d better default label position on schematic symbols 2019-03-19 19:03:21 +01:00
Branislav Stojkovic 9925d58347 keep label oriantation the same between the two modes 2019-03-18 22:57:30 +01:00
Branislav Stojkovic 6c241b3180 added third control point to leaded components to set label position 2019-03-18 22:49:27 +01:00
Branislav Stojkovic 838adc9a51 reorganize netlist code, comment out unused functions 2019-03-14 22:36:43 +01:00
Branislav Stojkovic 41d2b73cca Merge switch configurations that yield with the same effective wiring
for "Analyze Guitar Wirings" module, for more compact report
2019-03-14 22:26:49 +01:00
Branislav Stojkovic 8d3789a0b0 update file 2019-03-14 11:19:15 +01:00
Branislav Stojkovic 95f65dcdf1 scan library folder for more jars 2019-03-14 11:14:32 +01:00
Branislav Stojkovic 3d0f9554b0 Honor all possible combinations of "DIP Switch" positions when creating
a netlist
2019-03-14 10:32:51 +01:00
Branislav Stojkovic 0c21e013b4 improve node display for single point componenets 2019-03-14 10:03:04 +01:00
Branislav Stojkovic f8e24b0937 Improve performance of netlist calculations 2019-03-14 00:08:39 +01:00
Branislav Stojkovic 37d5ce18fc Z-order of components sometimes gets wrong when importing a DIY file
into another file
2019-03-13 21:24:55 +01:00
Branislav Stojkovic e9a2785344 Honor "Terminal Strip" connectivity when creating a netlist 2019-03-13 20:54:24 +01:00
Branislav Stojkovic 4de3b6d97c Output SPICE node names in the "Nxxx" format
join all nodes connected to GND together
2019-03-13 19:23:35 +01:00
Branislav Stojkovic 92a2bb9809 fix "Ground Symbol" jumping 2019-03-10 22:58:36 +01:00
Branislav Stojkovic 440b953531 fix orientation parsing 2019-03-10 22:53:01 +01:00
Branislav Stojkovic 1bc11e09ab release 2019-03-10 22:36:09 +01:00
Branislav Stojkovic f20b896184 release 2019-03-10 22:32:34 +01:00
Branislav Stojkovic 49d93b42a4 update.xml 2019-03-10 17:51:21 +01:00
Branislav Stojkovic b279510e5c Detect when a file is created with a newer version of DIYLC and show a
warning

Force correct prefix for transistors in spice
2019-03-10 09:03:22 +01:00
Branislav Stojkovic a83cda9ecd custom XStream converters for more compact files 2019-03-09 21:45:34 +01:00
Branislav Stojkovic f63b422a8c Cleaner XML format for .DIY files with less cross-references
pinout update
2019-03-09 20:15:36 +01:00
Branislav Stojkovic 7af919b303 move section handling to base component interface
do analysis in background thread
2019-03-09 18:01:42 +01:00
Branislav Stojkovic 1c1ec2fcf5 refactor transistor packages with a base class, add pinouts 2019-03-09 17:24:34 +01:00
Branislav Stojkovic 8ccdd84a6f add support to map DIYLC pin indices to spice 2019-03-09 16:47:18 +01:00
Branislav Stojkovic 54ff518438 basic implementation of spice exporter 2019-03-09 14:46:00 +01:00
Branislav Stojkovic c893b37fdf don't show favorites for categories 2019-03-09 11:27:15 +01:00
Branislav Stojkovic 81e259bb62 fix the sorting for favorites 2019-03-09 11:24:44 +01:00
Branislav Stojkovic d5aac6b265 When in "Highlight Connected Area" mode, the status bar shows useful
information making it harder to forget what the mode does
2019-03-09 11:19:32 +01:00
Branislav Stojkovic d544797047 Ability to tag components and building blocks as favorites 2019-03-09 10:42:39 +01:00
Branislav Stojkovic 8ed2c0c9a5 "Mini Toggle Switch" doesn't reset body size after changing terminal
spacing
2019-03-08 18:36:37 +01:00
Branislav Stojkovic 2d1cf515d6 "Highlight Connected Areas" doesn't follow multiple chained wires and
jumpers
2019-03-06 00:15:53 +01:00
Branislav Stojkovic 2553ffbba7 z-order of building blocks 2019-03-04 10:34:53 +01:00
122 changed files with 3790 additions and 2195 deletions
+1
View File
@@ -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 {
@@ -50,12 +49,9 @@ public interface INetlistAnalyzer {
* @throws TreeException
*/
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.
@@ -74,7 +74,8 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
public static final String SHOW_GRID_KEY = "showGrid";
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 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;
@@ -120,9 +121,10 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
* Loads specified {@link Project}.
*
* @param project
* @param freshStart
* @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.
@@ -21,25 +21,18 @@
*/
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 java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.Shape;
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;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.EditableProperty;
/**
* Abstract implementation of {@link IDIYComponent} that contains component name and toString.
@@ -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 {
@@ -291,5 +236,20 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
@Override
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);
}
@@ -24,7 +24,7 @@ package org.diylc.core;
import java.awt.Graphics2D;
import java.awt.Point;
import java.io.Serializable;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
@@ -128,7 +128,26 @@ public interface IDIYComponent<T> extends Serializable {
* @param index2
* @return name of the internal linked formed by the two control points, null if they do not form an internal link
*/
String getInternalLinkName(int index1, int index2);
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
*/
@@ -116,13 +110,5 @@ 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;
String keywordTag() default "";
}
@@ -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,9 +27,26 @@ 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);
@@ -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;
}
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());
}
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));
}
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 Tree getTree() {
return tree;
public void append(Netlist netlist) {
this.netlist.getSwitchSetup().addAll(netlist.getSwitchSetup());
}
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);
}
}
@@ -72,9 +72,9 @@ public class SwitchSetup implements Comparable<SwitchSetup> {
public String toString() {
StringBuilder sb = new StringBuilder();
for (Position s : positions)
{
{
if (sb.length() > 0)
sb.append(":");
sb.append(":");
sb.append(s.toString());
}
return sb.toString();
@@ -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;
String keywordTag;
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();
keywordTag = annotation.keywordTag();
} 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)
@@ -547,11 +548,32 @@ public class DrawingManager {
// else
// 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);
intersection.intersect(a2);
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,16 +141,34 @@ 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;
for (IDIYComponent<?> component : components) {
for (int i = 0; i < component.getControlPointCount(); i++) {
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) {
maxX = p.x;
@@ -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);
}
}
File diff suppressed because it is too large Load Diff
@@ -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;
@@ -91,8 +95,24 @@ public class ProjectFileManager {
};
}
};
xStream.autodetectAnnotations(true);
xStream.registerConverter(new PointConverter());
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")) {
@@ -192,14 +212,22 @@ public class ProjectFileManager {
}
private Project parseV3File(String fileName, List<String> warnings) throws IOException {
Project project;
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);
@@ -209,5 +237,32 @@ 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);
}
}
@@ -21,33 +21,33 @@
*/
package org.diylc.components;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
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;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
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.semiconductors.SymbolFlipping;
import org.diylc.core.ComponentState;
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.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
@@ -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 Orientation orientation = Orientation.DEFAULT;
protected boolean moveLabel = false;
public Abstract3LegSymbol() {
super();
updateControlPoints();
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,14 +103,14 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
}
g2d.setColor(finalColor);
// Draw transistor
if (this.body == null) {
this.body = getBody();
applyOrientation(this.body);
}
AffineTransform old = g2d.getTransform();
AffineTransform old = g2d.getTransform();
Point[] controlPoints = getControlPoints();
if (this.flip == SymbolFlipping.Y) {
g2d.translate(0, controlPoints[0].y);
@@ -142,61 +157,82 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
FontMetrics fontMetrics = g2d.getFontMetrics();
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),
getLabelY(shapeRect, textRect, fontMetrics, outlineMode), flip == SymbolFlipping.X ? HorizontalAlignment.RIGHT
: HorizontalAlignment.LEFT, VerticalAlignment.CENTER);
Rectangle shapeRect = body[0].getBounds().union(body[1].getBounds()).union(body[2].getBounds());
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.
int pinSpacing = (int) PIN_SPACING.convertToPixels();
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,15 +248,25 @@ 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
@@ -243,6 +289,15 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
public void setColor(Color color) {
this.color = color;
}
@EditableProperty(name = "Moveable Label")
public boolean getMoveLabel() {
return moveLabel;
}
public void setMoveLabel(boolean moveLabel) {
this.moveLabel = moveLabel;
}
@EditableProperty
@@ -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);
@@ -283,6 +338,13 @@ public abstract class Abstract3LegSymbol extends AbstractComponent<String> {
body[i] = rotate.createTransformedShape(body[i]);
}
}
}
@Override
public String getControlPointNodeName(int index) {
if (index >= 3)
return null;
return Integer.toString(index + 1);
}
/**
@@ -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();
@@ -88,28 +96,67 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
// This should never happen because Size supports cloning.
} 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;
// right angle.
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,64 +286,91 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
decorateComponentBody(g2d, outlineMode);
g2d.setComposite(oldComposite);
}
}
// Draw label.
g2d.setFont(project.getFont());
if (useShapeRectAsPosition()) {
g2d.translate(shapeRect.x, shapeRect.y);
// Draw label.
g2d.setFont(project.getFont());
if (useShapeRectAsPosition()) {
g2d.translate(shapeRect.x, shapeRect.y);
}
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
: labelColor;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics();
String label = "";
label = display == Display.NAME ? getName() : (getValue() == null ? "" : getValue().toString());
if (display == Display.NONE) {
label = "";
}
if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
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 (getMoveLabel()) {
g2d.setTransform(oldTransform);
g2d.translate(getPoints()[2].x, getPoints()[2].y);
if (getLabelOriantation() != LabelOriantation.Horizontal) {
g2d.rotate(theta);
}
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
: labelColor;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics();
String label = "";
label = display == Display.NAME ? getName() : (getValue() == null ? "" : getValue().toString());
if (display == Display.NONE) {
label = "";
}
if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
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);
offset = -offset;
}
if (getLabelOriantation() == LabelOriantation.Horizontal) {
StringUtils.drawCenteredText(g2d, label, offset, 0, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
g2d.setTransform(oldTransform);
} else {
if (isStanding() || getLabelOriantation() == LabelOriantation.Horizontal) {
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;
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);
public void setControlPoint(Point point, int index) {
// 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;
}
@@ -559,7 +649,23 @@ public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComp
public void setFlipStanding(boolean flipStanding) {
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
}
@@ -21,13 +21,14 @@
*/
package org.diylc.components;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.geom.Rectangle2D;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.common.LabelPosition;
import org.diylc.core.ComponentState;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.common.LabelPosition;
import org.diylc.core.ComponentState;
import org.diylc.core.annotations.EditableProperty;
public abstract class AbstractSchematicLeadedSymbol<T> extends AbstractLeadedComponent<T> {
@@ -62,12 +63,21 @@ 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 {
return (int) (shapeRect.getHeight() + textRect.getHeight());
}
}
@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")
@@ -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);
@@ -312,6 +313,11 @@ public class Breadboard extends AbstractComponent<Void> {
@Override
public int getControlPointCount() {
return 2;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@SuppressWarnings("incomplete-switch")
@@ -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;
@@ -454,5 +455,15 @@ public class TerminalStrip extends AbstractTransparentComponent<String> {
@Override
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;
@@ -131,5 +132,10 @@ 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;
@@ -156,5 +157,15 @@ public class Jumper extends AbstractLeadedComponent<Void> {
@Override
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);
}
@@ -337,5 +338,10 @@ public class CliffJack1_4 extends AbstractMultiPartComponent<String> {
public void setOrientation(Orientation orientation) {
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);
}
@@ -363,5 +364,10 @@ public class ClosedJack1_4 extends AbstractMultiPartComponent<String> {
return "Ring";
}
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;
@@ -312,7 +313,8 @@ public class DIPSwitch extends AbstractTransparentComponent<String> {
IDrawingObserver drawingObserver) {
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;
@@ -512,5 +514,44 @@ public class DIPSwitch extends AbstractTransparentComponent<String> {
public int getValue() {
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 = "";
@@ -330,5 +330,10 @@ 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> {
@@ -384,5 +384,10 @@ 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;
@@ -302,7 +302,9 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BODY_COLOR);
g2d.fill(mainArea);
g2d.setComposite(oldComposite);
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;
@@ -423,6 +425,11 @@ public class MiniRelay extends AbstractTransparentComponent<String> {
updateControlPoints();
// Invalidate body
this.body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public static enum RelayType {
@@ -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 {
@@ -242,7 +242,9 @@ public class MiniToggleSwitch extends AbstractTransparentComponent<ToggleSwitchT
public void setSpacing(Size spacing) {
this.spacing = spacing;
updateControlPoints();
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;
@@ -76,8 +77,10 @@ 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;
private Orientation orientation = Orientation.DEFAULT;
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);
}
@@ -386,17 +343,27 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<String> {
public void setValue(String value) {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Invalidate the body
body = null;
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 setAngle(Integer angle) {
this.angle = angle;
updateControlPoints();
// Invalidate the body
body = null;
}
protected double getTheta() {
return Math.toRadians(getAngle());
}
@EditableProperty
@@ -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;
@@ -52,14 +52,16 @@ 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> {
private static final long serialVersionUID = 1L;
private static Color BASE_COLOR = Color.lightGray;
private static Color WAFER_COLOR = Color.decode("#CD8500");
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);
@@ -75,8 +77,10 @@ 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;
private Orientation orientation = Orientation.DEFAULT;
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)));
@@ -230,26 +233,10 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
body[5] = link;
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;
}
}
thread.subtract(link);
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);
}
@@ -412,15 +386,30 @@ public class PilotLampHolder extends AbstractMultiPartComponent<String> {
this.value = value;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
// Invalidate the body
body = null;
@EditableProperty
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 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);
}
@@ -261,5 +262,10 @@ 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;
@@ -319,5 +318,10 @@ public class RCAJack extends AbstractMultiPartComponent<String> {
@Override
public String getControlPointNodeName(int index) {
return getName() + (index == 0 ? "Tip" : "Sleeve");
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
}
@@ -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)
@@ -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 {
@@ -299,6 +299,11 @@ public class LPSwitch extends AbstractTransparentComponent<String> implements IS
this.controlPoints[index].setLocation(point);
// Invalidate the body
body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@Override
@@ -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
@@ -475,5 +475,10 @@ public class LeverSwitch extends AbstractTransparentComponent<String> implements
return (index1 == 0 || index1 == 12 || index2 == 11 || index2 == 23) && index2 - index1 == position + 1;
}
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";
@@ -116,14 +116,18 @@ public class PCBText extends AbstractComponent<Void> {
case _270:
g2d.rotate(Math.PI * 3 / 2, point.x, point.y);
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.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;
@@ -517,5 +518,10 @@ public class AudioTransformer extends AbstractMultiPartComponent<String> {
public void setSecondaryCT(boolean secondaryCT) {
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());
@@ -515,5 +516,10 @@ 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 {
@@ -468,6 +468,11 @@ public class PotentiometerPanel extends AbstractPotentiometer {
return (index1 + 1) + "-" + (index2 + 1);
return null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public enum Type {
@@ -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 {
@@ -47,7 +48,8 @@ public class PotentiometerSymbol extends Abstract3LegSymbol {
}
public Shape[] getBody() {
Shape[] body = new Shape[3];
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> {
@@ -281,5 +281,10 @@ 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;
@@ -529,6 +528,11 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
updateControlPoints();
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(
@@ -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 {
@@ -45,7 +46,8 @@ public class BJTSymbol extends Abstract3LegSymbol {
protected BJTPolarity polarity = BJTPolarity.NPN;
public Shape[] getBody() {
Shape[] body = new Shape[3];
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")
@@ -661,6 +662,11 @@ public class BridgeRectifier extends AbstractTransparentComponent<String> {
public void setLabelOriantation(LabelOriantation labelOriantation) {
this.labelOriantation = labelOriantation;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public static enum RectifierType {
@@ -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> {
@@ -536,6 +536,11 @@ public class DIL_IC extends AbstractTransparentComponent<String> {
public void setDisplayNumbers(DisplayNumbers numbers) {
this.displayNumbers = numbers;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public static enum PinCount {
@@ -21,39 +21,40 @@
*/
package org.diylc.components.semiconductors;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment;
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;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.geom.Area;
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;
import org.diylc.common.ObjectCache;
import org.diylc.common.VerticalAlignment;
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 = "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);
@@ -295,5 +296,10 @@ public class ICSymbol extends AbstractTransparentComponent<String> {
public void setDisplay(Display display) {
this.display = display;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
}
@@ -22,10 +22,11 @@
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;
import org.diylc.common.ObjectCache;
import org.diylc.components.Abstract3LegSymbol;
import org.diylc.core.IDIYComponent;
@@ -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 {
@@ -43,7 +44,8 @@ public class JFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() {
Shape[] body = new Shape[3];
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);
}
@@ -317,6 +318,11 @@ public class LogicGateSymbol extends AbstractTransparentComponent<String> {
public void setDisplay(Display display) {
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,10 +22,11 @@
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;
import org.diylc.common.ObjectCache;
import org.diylc.components.Abstract3LegSymbol;
import org.diylc.core.IDIYComponent;
@@ -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 {
@@ -43,7 +44,8 @@ public class MOSFETSymbol extends Abstract3LegSymbol {
protected FETPolarity polarity = FETPolarity.NEGATIVE;
public Shape[] getBody() {
Shape[] body = new Shape[3];
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> {
@@ -143,6 +143,11 @@ public class SIL_IC extends AbstractTransparentComponent<String> {
updateControlPoints();
// Reset body shape;
body = null;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
@EditableProperty
@@ -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();
};
}
@@ -21,42 +21,39 @@
*/
package org.diylc.components.semiconductors;
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.Ellipse2D;
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.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;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
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.Ellipse2D;
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.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.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 = "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,71 +68,19 @@ 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;
public TransistorTO1() {
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;
alpha = (byte) 100;
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,49 +107,52 @@ 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;
int bodyDiameter = getClosestOdd(BODY_DIAMETER.convertToPixels());
int bodyLength = getClosestOdd(BODY_LENGTH.convertToPixels());
int edgeRadius = (int) EDGE_RADIUS.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;
}
}
@@ -21,42 +21,39 @@
*/
package org.diylc.components.semiconductors;
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.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
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;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
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.Shape;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
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.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 = "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,72 +75,21 @@ 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;
public TransistorTO220() {
super();
updateControlPoints();
alpha = (byte) 100;
alpha = (byte) 100;
bodyColor = BODY_COLOR;
borderColor = BORDER_COLOR;
}
@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;
}
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;
@@ -487,17 +415,5 @@ 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> {
@@ -21,42 +21,39 @@
*/
package org.diylc.components.semiconductors;
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.RenderingHints;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
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;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
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.RenderingHints;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
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.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 = "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,42 +66,15 @@ 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;
private Size pinSpacing = PIN_SPACING;
public TransistorTO92() {
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;
alpha = (byte) 100;
bodyColor = BODY_COLOR;
borderColor = BORDER_COLOR;
}
@EditableProperty
@@ -132,34 +102,9 @@ public class TransistorTO92 extends AbstractTransparentComponent<String> {
// 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;
}
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());
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;
}
}
@@ -31,7 +31,7 @@ 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;
@@ -405,6 +405,11 @@ public abstract class PassiveSMDComponent<T> extends AbstractTransparentComponen
public void setLabelColor(Color labelColor) {
this.labelColor = labelColor;
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
public static enum SMDSize {
@@ -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> {
@@ -21,30 +21,31 @@
*/
package org.diylc.components.tube;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import org.diylc.appframework.miscutils.ConfigurationManager;
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;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
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;
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;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
@@ -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);
}
@@ -296,5 +297,10 @@ public abstract class AbstractTubeSymbol extends AbstractComponent<String> {
for (int i = 1; i < this.controlPoints.length; i++) {
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,27 +71,25 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
@Override
public String getName() {
return "Guitar Diagrams";
return "Analyze Guitar Diagrams (beta)";
}
@Override
public String getIconName() {
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("&nbsp;&nbsp;").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);

Some files were not shown because too many files have changed in this diff Show More