mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 243b13c37c | |||
| 4660467df5 | |||
| 73a12bc107 | |||
| ece6015a7f | |||
| 1cbdf505fe | |||
| f0c1970784 |
@@ -0,0 +1,116 @@
|
||||
package org.diylc.common;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.core.Angle;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.presenter.ComponentProcessor;
|
||||
|
||||
public class DefaultComponentTransformer implements IComponentTransformer {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DefaultComponentTransformer.class);
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
List<PropertyWrapper> properties =
|
||||
ComponentProcessor.getInstance().extractProperties(component.getClass());
|
||||
|
||||
for (PropertyWrapper property : properties) {
|
||||
if (property.getType().isAssignableFrom(Orientation.class)
|
||||
|| property.getType().isAssignableFrom(OrientationHV.class)
|
||||
|| property.getType().isAssignableFrom(Angle.class))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
boolean canRotate = false;
|
||||
List<PropertyWrapper> properties =
|
||||
ComponentProcessor.getInstance().extractProperties(component.getClass());
|
||||
|
||||
for (PropertyWrapper property : properties) {
|
||||
try {
|
||||
property.readFrom(component);
|
||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException
|
||||
| SecurityException | NoSuchMethodException e) {
|
||||
LOG.warn("Error while rotating component " + component.getName(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (property.getType().isAssignableFrom(Orientation.class)) {
|
||||
canRotate = true;
|
||||
|
||||
Orientation o = (Orientation) property.getValue();
|
||||
int oValue = o.ordinal();
|
||||
oValue += direction;
|
||||
if (oValue < 0)
|
||||
oValue = Orientation.values().length - 1;
|
||||
if (oValue >= Orientation.values().length)
|
||||
oValue = 0;
|
||||
o = Orientation.values()[oValue];
|
||||
property.setValue(o);
|
||||
}
|
||||
|
||||
if (property.getType().isAssignableFrom(OrientationHV.class)) {
|
||||
canRotate = true;
|
||||
|
||||
OrientationHV o = (OrientationHV) property.getValue();
|
||||
int oValue = o.ordinal();
|
||||
oValue += direction;
|
||||
if (oValue < 0)
|
||||
oValue = OrientationHV.values().length - 1;
|
||||
if (oValue >= OrientationHV.values().length)
|
||||
oValue = 0;
|
||||
o = OrientationHV.values()[oValue];
|
||||
property.setValue(o);
|
||||
}
|
||||
|
||||
if (property.getType().isAssignableFrom(Angle.class)) {
|
||||
canRotate = true;
|
||||
|
||||
Angle angle = (Angle) property.getValue();
|
||||
Angle newAngle = angle.rotate(direction);
|
||||
property.setValue(newAngle);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Error while rotating component " + component.getName(), e);
|
||||
}
|
||||
|
||||
if (canRotate) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction,
|
||||
center.getX(), center.getY());
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point2D p = new Point2D.Double();
|
||||
rotate.transform(component.getControlPoint(index), p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
|
||||
try {
|
||||
property.writeTo(component);
|
||||
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException
|
||||
| SecurityException | NoSuchMethodException e) {
|
||||
LOG.warn("Error while rotating component " + component.getName(), e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {}
|
||||
}
|
||||
@@ -1,52 +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.common;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class DefaultTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ package org.diylc.core.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import org.diylc.common.DefaultTransformer;
|
||||
import org.diylc.common.DefaultComponentTransformer;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
@@ -94,7 +94,7 @@ public @interface ComponentDescriptor {
|
||||
/**
|
||||
* @return if the component can be rotated and/or mirrored, returns a class of the transformer that can do it
|
||||
*/
|
||||
Class<? extends IComponentTransformer> transformer() default DefaultTransformer.class;
|
||||
Class<? extends IComponentTransformer> transformer() default DefaultComponentTransformer.class;
|
||||
|
||||
/**
|
||||
* Defines if and how a component should appear in auto-generated project keywords. See
|
||||
|
||||
@@ -4349,5 +4349,25 @@
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
<org.diylc.appframework.update.Version>
|
||||
<versionNumber>
|
||||
<major>4</major>
|
||||
<minor>37</minor>
|
||||
<build>0</build>
|
||||
</versionNumber>
|
||||
<releaseDate>2023-04-27 00:00:00.000 CET</releaseDate>
|
||||
<name></name>
|
||||
<changes>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>'Proto Board 780 Holes' added with two variations (sponsored by Pete Olivier)</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Ability to rotate (almost) all components using keyboard shortcuts and 'Transform Selection' menu</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
</changes>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
</a>
|
||||
</java.util.Arrays_-ArrayList>
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,515 @@
|
||||
/*
|
||||
*
|
||||
* 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.boards;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import org.diylc.awt.StringUtils;
|
||||
import org.diylc.common.HorizontalAlignment;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.transform.ProtoBoardTransformer;
|
||||
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.KeywordPolicy;
|
||||
import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
|
||||
@ComponentDescriptor(name = "Proto Board 780 Holes", category = "Boards",
|
||||
author = "Branislav Stojkovic",
|
||||
description = "Prototyping board similar to Radio Shack 276-168B or MPJA 33304",
|
||||
instanceNamePrefix = "BB", zOrder = IDIYComponent.BOARD,
|
||||
bomPolicy = BomPolicy.SHOW_ONLY_TYPE_NAME, autoEdit = false,
|
||||
keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, enableCache = true,
|
||||
transformer = ProtoBoardTransformer.class)
|
||||
public class ProtoBoard780 extends AbstractProtoBoard {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static Color FILL_COLOR = Color.decode("#6B9B6B");
|
||||
public static Size SPACING = new Size(0.1d, SizeUnit.in);
|
||||
public static Color SELECTION_COLOR = Color.red;
|
||||
public static Color PAD_COLOR = COPPER_COLOR;
|
||||
public static Color TRACE_COLOR = PAD_COLOR.brighter();
|
||||
|
||||
public static Color HOLE_COLOR = Color.white;
|
||||
|
||||
public static float COORDINATE_FONT_SIZE = 9f;
|
||||
public static Color COORDINATE_COLOR = Color.decode("#DDDDDD");
|
||||
|
||||
public static Size PAD_SIZE = new Size(2d, SizeUnit.mm);
|
||||
|
||||
public static Size WIDTH_SIZE = new Size(72d, SizeUnit.mm);
|
||||
public static Size LENGTH_SIZE = new Size(95d, SizeUnit.mm);
|
||||
|
||||
protected Point2D point = new Point2D.Double(0, 0);
|
||||
|
||||
protected Color boardColor = FILL_COLOR;
|
||||
protected Color padColor = PAD_COLOR;
|
||||
protected Color traceColor = TRACE_COLOR;
|
||||
protected Color textColor = COORDINATE_COLOR;
|
||||
|
||||
public static Size MOUNTING_HORIZONTAL_SPACING_MPJA = new Size(60d, SizeUnit.mm);
|
||||
public static Size MOUNTING_HORIZONTAL_SPACING_RS = new Size(56d, SizeUnit.mm);
|
||||
public static Size MOUNTING_HOLE_SIZE = new Size(3d, SizeUnit.mm);
|
||||
|
||||
protected ProtoBoard780Type type = ProtoBoard780Type.MPJA;
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// adjust the angle
|
||||
double theta = 0;
|
||||
switch (getOrientation()) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
if (theta != 0) {
|
||||
g2d.rotate(theta, point.getX(), point.getY());
|
||||
}
|
||||
|
||||
double spacing = SPACING.convertToPixels();
|
||||
|
||||
// draw body
|
||||
g2d.setColor(boardColor);
|
||||
int width = (int) WIDTH_SIZE.convertToPixels();
|
||||
int length = (int) LENGTH_SIZE.convertToPixels();
|
||||
|
||||
int mountingHoleSize = (int) MOUNTING_HOLE_SIZE.convertToPixels();
|
||||
|
||||
Shape rect = new Rectangle2D.Double(point.getX(), point.getY(), width, length);
|
||||
g2d.fill(rect);
|
||||
Color finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: boardColor.darker();
|
||||
g2d.setColor(finalBorderColor);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
|
||||
drawingObserver.stopTracking();
|
||||
|
||||
g2d.draw(rect);
|
||||
|
||||
int padSize = getClosestOdd(PAD_SIZE.convertToPixels());
|
||||
int holeSize = getClosestOdd(padSize / 3);
|
||||
|
||||
g2d.setFont(LABEL_FONT.deriveFont(COORDINATE_FONT_SIZE));
|
||||
|
||||
double offsetY = spacing * 0.5;
|
||||
|
||||
// top section
|
||||
for (int i = 0; i < 15; i++) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(padSize - 2f));
|
||||
|
||||
g2d.setColor(traceColor);
|
||||
int padX = (int) (point.getX() + width / 2 - 7 * spacing + i * spacing);
|
||||
drawingObserver.startTrackingContinuityArea(true);
|
||||
g2d.drawLine(padX, (int) (point.getY() + offsetY), padX,
|
||||
(int) (point.getY() + spacing + offsetY));
|
||||
drawingObserver.stopTrackingContinuityArea();
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
int padY = (int) (point.getY() + spacing * j + offsetY);
|
||||
|
||||
g2d.setColor(padColor);
|
||||
|
||||
drawingObserver.startTrackingContinuityArea(true);
|
||||
|
||||
g2d.fillOval(padX - padSize / 2, padY - padSize / 2, padSize, padSize);
|
||||
|
||||
drawingObserver.stopTrackingContinuityArea();
|
||||
|
||||
g2d.setColor(padColor.darker());
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||
|
||||
g2d.drawOval(padX - padSize / 2, padY - padSize / 2, padSize, padSize);
|
||||
|
||||
g2d.setColor(HOLE_COLOR);
|
||||
g2d.fillOval(padX - holeSize / 2, padY - holeSize / 2, holeSize, holeSize);
|
||||
}
|
||||
}
|
||||
// top section labels
|
||||
g2d.setColor(textColor);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int x = i == 0 ? 1 : i * 5;
|
||||
int padX = (int) (point.getX() + width / 2 - 8 * spacing + x * spacing);
|
||||
int padY = (int) (point.getY() + spacing * 2);
|
||||
|
||||
// // flip the coordinates for MPJA
|
||||
// if (type == ProtoBoard780Type.MPJA) {
|
||||
// x = i == 3 ? 1 : (3 - i) * 5;
|
||||
// }
|
||||
|
||||
StringUtils.drawCenteredText(g2d, Integer.toString(x), padX, padY, HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.BOTTOM);
|
||||
}
|
||||
|
||||
|
||||
offsetY = spacing * 5.5;
|
||||
|
||||
// draw 3-pad traces and vertical traces
|
||||
drawingObserver.startTrackingContinuityArea(true);
|
||||
g2d.setColor(traceColor);
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(padSize - 2f));
|
||||
|
||||
// the outer bus
|
||||
g2d.drawLine((int) (point.getX() + width / 2 - 13 * spacing),
|
||||
(int) (point.getY() - 2 * spacing + offsetY),
|
||||
(int) (point.getX() + width / 2 + 13 * spacing),
|
||||
(int) (point.getY() - 2 * spacing + offsetY));
|
||||
g2d.drawLine((int) (point.getX() + width / 2 - 13 * spacing),
|
||||
(int) (point.getY() - 2 * spacing + offsetY),
|
||||
(int) (point.getX() + width / 2 - 13 * spacing),
|
||||
(int) (point.getY() + (29 + (type == ProtoBoard780Type.RS ? 2 : 0)) * spacing + offsetY));
|
||||
g2d.drawLine((int) (point.getX() + width / 2 + 13 * spacing),
|
||||
(int) (point.getY() - 2 * spacing + offsetY),
|
||||
(int) (point.getX() + width / 2 + 13 * spacing),
|
||||
(int) (point.getY() + (29 + (type == ProtoBoard780Type.RS ? 2 : 0)) * spacing + offsetY));
|
||||
|
||||
// horizontal long traces
|
||||
g2d.drawLine((int) (point.getX() + width / 2 - 12 * spacing), (int) (point.getY() + offsetY),
|
||||
(int) (point.getX() + width / 2 + 12 * spacing), (int) (point.getY() + offsetY));
|
||||
g2d.drawLine((int) (point.getX() + width / 2 - 12 * spacing),
|
||||
(int) (point.getY() + spacing * 29 + offsetY),
|
||||
(int) (point.getX() + width / 2 + 12 * spacing),
|
||||
(int) (point.getY() + spacing * 29 + offsetY));
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int padX = (int) (point.getX() + width / 2 - 12 * spacing + (i * 5 + 1) * spacing);
|
||||
|
||||
// vertical traces
|
||||
g2d.drawLine((int) (padX - spacing), (int) (point.getY() + offsetY), (int) (padX - spacing),
|
||||
(int) (point.getY() + spacing * 28 + offsetY));
|
||||
g2d.drawLine((int) (padX + 3 * spacing), (int) (point.getY() + spacing + offsetY),
|
||||
(int) (padX + 3 * spacing), (int) (point.getY() + spacing * 29 + offsetY));
|
||||
|
||||
for (int j = 1; j < 29; j++) {
|
||||
int padY = (int) (point.getY() + spacing * j + offsetY);
|
||||
|
||||
// 3-pad traces
|
||||
g2d.drawLine(padX, padY, (int) (padX + 2 * spacing), padY);
|
||||
}
|
||||
}
|
||||
drawingObserver.stopTrackingContinuityArea();
|
||||
|
||||
// draw main pads
|
||||
for (int i = 0; i < 25; i++) {
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(padSize - 2f));
|
||||
|
||||
g2d.setColor(padColor);
|
||||
int padX = (int) (point.getX() + width / 2 - 12 * spacing + i * spacing);
|
||||
// drawingObserver.startTrackingContinuityArea(true);
|
||||
// g2d.drawLine(padX, (int)(point.getY() + offsetY), padX, (int)(point.getY() + spacing +
|
||||
// offsetY));
|
||||
// drawingObserver.stopTrackingContinuityArea();
|
||||
|
||||
for (int j = 0; j < 30; j++) {
|
||||
int padY = (int) (point.getY() + spacing * j + offsetY);
|
||||
|
||||
g2d.setColor(padColor);
|
||||
|
||||
drawingObserver.startTrackingContinuityArea(true);
|
||||
|
||||
g2d.fillOval(padX - padSize / 2, padY - padSize / 2, padSize, padSize);
|
||||
|
||||
drawingObserver.stopTrackingContinuityArea();
|
||||
|
||||
g2d.setColor(padColor.darker());
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||
|
||||
g2d.drawOval(padX - padSize / 2, padY - padSize / 2, padSize, padSize);
|
||||
|
||||
g2d.setColor(HOLE_COLOR);
|
||||
g2d.fillOval(padX - holeSize / 2, padY - holeSize / 2, holeSize, holeSize);
|
||||
}
|
||||
}
|
||||
|
||||
g2d.setColor(textColor);
|
||||
|
||||
// horizontal coordinates
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int x = i == 0 ? 1 : i * 5;
|
||||
int padX = (int) (point.getX() + width / 2 - 13 * spacing + x * spacing);
|
||||
int padY = (int) (point.getY() - spacing + offsetY);
|
||||
|
||||
String label = String.valueOf((char) ('A' + i));
|
||||
|
||||
StringUtils.drawCenteredText(g2d, label, padX, padY, HorizontalAlignment.CENTER,
|
||||
VerticalAlignment.BOTTOM);
|
||||
// StringUtils.drawCenteredText(g2d, label, padX, padY + spacing * 31,
|
||||
// HorizontalAlignment.CENTER,
|
||||
// VerticalAlignment.TOP);
|
||||
}
|
||||
|
||||
// vertical coordinates
|
||||
for (int i = 0; i < 7; i++) {
|
||||
int y = i == 0 ? 1 : i * 5;
|
||||
|
||||
int padX = (int) (point.getX() + width / 2 - 14 * spacing);
|
||||
int padY = (int) (point.getY() + spacing * (y - 1) + offsetY);
|
||||
|
||||
StringUtils.drawCenteredText(g2d, Integer.toString(y), padX, padY, HorizontalAlignment.LEFT,
|
||||
VerticalAlignment.BOTTOM);
|
||||
}
|
||||
|
||||
// model name
|
||||
g2d.setFont(LABEL_FONT.deriveFont(COORDINATE_FONT_SIZE * 1.8f));
|
||||
int x = (int) (point.getX() + width / 2);
|
||||
int y = (int) (point.getY() + length - spacing * 1.5);
|
||||
StringUtils.drawCenteredText(g2d,
|
||||
type == ProtoBoard780Type.RS ? "Radio Shack 276-168B" : "MPJA.COM 33304 PB", x, y,
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
|
||||
// mounting holes
|
||||
int dx = (int) (type == ProtoBoard780Type.RS ? 11 * spacing : 12 * spacing);
|
||||
int holeY = (int) (point.getY() + spacing * (type == ProtoBoard780Type.RS ? 1 : 1.5));
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
g2d.setColor(HOLE_COLOR);
|
||||
|
||||
g2d.fillOval((int) (point.getX() + width / 2) - dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
g2d.fillOval((int) (point.getX() + width / 2) + dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
|
||||
g2d.setColor(finalBorderColor);
|
||||
|
||||
g2d.drawOval((int) (point.getX() + width / 2) - dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
g2d.drawOval((int) (point.getX() + width / 2) + dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
|
||||
holeY = (int) (point.getY() + length - spacing);
|
||||
|
||||
g2d.setColor(HOLE_COLOR);
|
||||
|
||||
g2d.fillOval((int) (point.getX() + width / 2) - dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
g2d.fillOval((int) (point.getX() + width / 2) + dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
|
||||
g2d.setColor(finalBorderColor);
|
||||
|
||||
g2d.drawOval((int) (point.getX() + width / 2) - dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
g2d.drawOval((int) (point.getX() + width / 2) + dx - mountingHoleSize / 2,
|
||||
holeY - mountingHoleSize / 2, mountingHoleSize, mountingHoleSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int factor = 32 / width;
|
||||
g2d.setColor(FILL_COLOR);
|
||||
g2d.fillRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
|
||||
g2d.setColor(FILL_COLOR.darker());
|
||||
g2d.drawRect(2 / factor, 2 / factor, width - 4 / factor, height - 4 / factor);
|
||||
|
||||
g2d.setColor(PAD_COLOR.brighter());
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2 / factor));
|
||||
|
||||
int size = (int) (8.0 / factor);
|
||||
|
||||
g2d.drawLine(width / 3 - 2 / factor + size / 2, 6 / factor + size / 2, width,
|
||||
6 / factor + size / 2);
|
||||
g2d.drawLine(width / 3 - 2 / factor + size / 2, 2 * width / 3 - 2 / factor + size / 2, width,
|
||||
2 * width / 3 - 2 / factor + size / 2);
|
||||
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
|
||||
|
||||
g2d.setColor(PAD_COLOR);
|
||||
g2d.fillRect(width / 3 - 2 / factor, 6 / factor, size, size);
|
||||
g2d.setColor(PAD_COLOR.darker());
|
||||
g2d.drawRect(width / 3 - 2 / factor, 6 / factor, size, size);
|
||||
|
||||
g2d.setColor(PAD_COLOR);
|
||||
g2d.fillOval(2 * width / 3 - 2 / factor, 6 / factor, size, size);
|
||||
g2d.setColor(PAD_COLOR.darker());
|
||||
g2d.drawOval(2 * width / 3 - 2 / factor, 6 / factor, size, size);
|
||||
|
||||
g2d.setColor(PAD_COLOR);
|
||||
g2d.fillRect(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, size, size);
|
||||
g2d.setColor(PAD_COLOR.darker());
|
||||
g2d.drawRect(width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, size, size);
|
||||
|
||||
g2d.setColor(PAD_COLOR);
|
||||
g2d.fillOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, size, size);
|
||||
g2d.setColor(PAD_COLOR.darker());
|
||||
g2d.drawOval(2 * width / 3 - 2 / factor, 2 * width / 3 - 2 / factor, size, size);
|
||||
|
||||
g2d.setColor(HOLE_COLOR);
|
||||
g2d.fillOval(width / 3 - 2 / factor + size / 2 - 1, 6 / factor + size / 2 - 1, 3, 3);
|
||||
g2d.fillOval(width / 3 - 2 / factor + size / 2 - 1, 2 * width / 3 - 2 / factor + size / 2 - 1,
|
||||
3, 3);
|
||||
g2d.fillOval(2 * width / 3 - 2 / factor + size / 2 - 1, 6 / factor + size / 2 - 1, 3, 3);
|
||||
g2d.fillOval(2 * width / 3 - 2 / factor + size / 2 - 1,
|
||||
2 * width / 3 - 2 / factor + size / 2 - 1, 3, 3);
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Board Color")
|
||||
public Color getBoardColor() {
|
||||
return boardColor;
|
||||
}
|
||||
|
||||
public void setBoardColor(Color boardColor) {
|
||||
this.boardColor = boardColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Pad Color")
|
||||
public Color getPadColor() {
|
||||
return padColor;
|
||||
}
|
||||
|
||||
public void setPadColor(Color padColor) {
|
||||
this.padColor = padColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Trace Color")
|
||||
public Color getTraceColor() {
|
||||
return traceColor;
|
||||
}
|
||||
|
||||
public void setTraceColor(Color traceColor) {
|
||||
this.traceColor = traceColor;
|
||||
}
|
||||
|
||||
@EditableProperty(name = "Text Color")
|
||||
public Color getTextColor() {
|
||||
return textColor;
|
||||
}
|
||||
|
||||
public void setTextColor(Color textColor) {
|
||||
this.textColor = textColor;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public ProtoBoard780Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ProtoBoard780Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getControlPointCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPointMoveFreely(int pointIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public Point2D getControlPoint(int index) {
|
||||
if (index == 0)
|
||||
return point;
|
||||
|
||||
// create a synthetic second control point for clipping check and to make sure that we cannot
|
||||
// drag the right side of the board off the screen
|
||||
|
||||
// adjust the angle
|
||||
double theta = 0;
|
||||
switch (getOrientation()) {
|
||||
case _90:
|
||||
theta = Math.PI / 2;
|
||||
break;
|
||||
case _180:
|
||||
theta = Math.PI;
|
||||
break;
|
||||
case _270:
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
int width = (int) WIDTH_SIZE.convertToPixels();
|
||||
int length = (int) LENGTH_SIZE.convertToPixels();
|
||||
Point2D secondPoint = new Point2D.Double(point.getX() + width, point.getY() + length);
|
||||
if (theta != 0) {
|
||||
AffineTransform tx = AffineTransform.getRotateInstance(theta, point.getX(), point.getY());
|
||||
tx.transform(secondPoint, secondPoint);
|
||||
}
|
||||
return secondPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlPointSticky(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
|
||||
return VisibilityPolicy.NEVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setControlPoint(Point2D point, int index) {
|
||||
if (index == 0)
|
||||
this.point.setLocation(point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Void value) {}
|
||||
|
||||
@Override
|
||||
public String getControlPointNodeName(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle2D getCachingBounds() {
|
||||
Point2D finalSecondPoint = getControlPoint(1);
|
||||
return new Rectangle2D.Double(Math.min(point.getX(), finalSecondPoint.getX()),
|
||||
Math.min(point.getY(), finalSecondPoint.getY()),
|
||||
Math.abs(finalSecondPoint.getX() - point.getX()) + 2,
|
||||
Math.abs(finalSecondPoint.getY() - point.getY()) + 2);
|
||||
}
|
||||
|
||||
public static enum ProtoBoard780Type {
|
||||
RS, MPJA
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,21 @@
|
||||
/*
|
||||
|
||||
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/>.
|
||||
|
||||
*/
|
||||
*
|
||||
* 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;
|
||||
@@ -38,7 +35,6 @@ 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.DIL_ICTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -54,10 +50,10 @@ import org.diylc.core.measures.Size;
|
||||
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",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class,
|
||||
enableCache = true)
|
||||
@ComponentDescriptor(name = "DIP Switch", author = "Branislav Stojkovic",
|
||||
category = "Electro-Mechanical", instanceNamePrefix = "SW",
|
||||
description = "Dual-in-line package switch", zOrder = IDIYComponent.COMPONENT,
|
||||
keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true)
|
||||
public class DIPSwitch extends AbstractTransparentComponent<String> implements ISwitch {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -239,7 +235,8 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
controlPoints[i] = new Point2D.Double(firstPoint.getX() + dx1, firstPoint.getY() + dy1);
|
||||
controlPoints[i + switchCount.getValue()] = new Point2D.Double(firstPoint.getX() + dx2, firstPoint.getY() + dy2);
|
||||
controlPoints[i + switchCount.getValue()] =
|
||||
new Point2D.Double(firstPoint.getX() + dx2, firstPoint.getY() + dy2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,8 +261,12 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
x -= (bodyWidth - rowSpacing) / 2;
|
||||
y -= pinSpacing / 2;
|
||||
for (int i = 0; i < getSwitchCount().getValue(); i++) {
|
||||
tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, controlPoints[i].getY() - tickSize / 2, tickSize, tickSize)));
|
||||
tickHoleArea.add(new Area(
|
||||
new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2,
|
||||
controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize)));
|
||||
tickArea.add(new Area(
|
||||
new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2,
|
||||
controlPoints[i].getY() - tickSize / 2, tickSize, tickSize)));
|
||||
}
|
||||
break;
|
||||
case _90:
|
||||
@@ -274,8 +275,11 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
x -= (pinSpacing / 2) + width - pinSpacing;
|
||||
y -= (bodyWidth - rowSpacing) / 2;
|
||||
for (int i = 0; i < getSwitchCount().getValue(); i++) {
|
||||
tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickHoleLength)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickSize)));
|
||||
tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2,
|
||||
controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize,
|
||||
tickHoleLength)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2,
|
||||
controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickSize)));
|
||||
}
|
||||
break;
|
||||
case _180:
|
||||
@@ -284,8 +288,12 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
x -= rowSpacing + (bodyWidth - rowSpacing) / 2;
|
||||
y -= (pinSpacing / 2) + height - pinSpacing;
|
||||
for (int i = getSwitchCount().getValue(); i < controlPoints.length; i++) {
|
||||
tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2, controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing + tickHoleLength) / 2 - tickSize, controlPoints[i].getY() - tickSize / 2, tickSize, tickSize)));
|
||||
tickHoleArea.add(new Area(
|
||||
new Rectangle2D.Double(controlPoints[i].getX() + (rowSpacing - tickHoleLength) / 2,
|
||||
controlPoints[i].getY() - tickSize / 2, tickHoleLength, tickSize)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(
|
||||
controlPoints[i].getX() + (rowSpacing + tickHoleLength) / 2 - tickSize,
|
||||
controlPoints[i].getY() - tickSize / 2, tickSize, tickSize)));
|
||||
}
|
||||
break;
|
||||
case _270:
|
||||
@@ -294,14 +302,20 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
x -= pinSpacing / 2;
|
||||
y -= rowSpacing + (bodyWidth - rowSpacing) / 2;
|
||||
for (int i = getSwitchCount().getValue(); i < controlPoints.length; i++) {
|
||||
tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize, tickHoleLength)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2 + tickHoleLength - tickSize, tickSize, tickSize)));
|
||||
tickHoleArea.add(new Area(new Rectangle2D.Double(controlPoints[i].getX() - tickSize / 2,
|
||||
controlPoints[i].getY() + (rowSpacing - tickHoleLength) / 2, tickSize,
|
||||
tickHoleLength)));
|
||||
tickArea.add(new Area(new Rectangle2D.Double(
|
||||
controlPoints[i].getX() - tickSize / 2, controlPoints[i].getY()
|
||||
+ (rowSpacing - tickHoleLength) / 2 + tickHoleLength - tickSize,
|
||||
tickSize, tickSize)));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
body[0] = new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS));
|
||||
body[0] =
|
||||
new Area(new RoundRectangle2D.Double(x, y, width, height, EDGE_RADIUS, EDGE_RADIUS));
|
||||
body[1] = tickHoleArea;
|
||||
body[2] = tickArea;
|
||||
}
|
||||
@@ -309,8 +323,8 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
@@ -320,11 +334,17 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
for (Point2D point : controlPoints) {
|
||||
g2d.setColor(PIN_COLOR);
|
||||
int pinWidth = getClosestOdd(pinSize / (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 2f : 1f));
|
||||
int pinHeight = getClosestOdd(pinSize / (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 1f : 2f));
|
||||
g2d.fillRect((int)(point.getX() - pinWidth / 2), (int)(point.getY() - pinHeight / 2), pinWidth, pinHeight);
|
||||
int pinWidth = getClosestOdd(pinSize
|
||||
/ (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 2f
|
||||
: 1f));
|
||||
int pinHeight = getClosestOdd(pinSize
|
||||
/ (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180 ? 1f
|
||||
: 2f));
|
||||
g2d.fillRect((int) (point.getX() - pinWidth / 2), (int) (point.getY() - pinHeight / 2),
|
||||
pinWidth, pinHeight);
|
||||
g2d.setColor(PIN_BORDER_COLOR);
|
||||
g2d.drawRect((int)(point.getX() - pinWidth / 2), (int)(point.getY() - pinHeight / 2), pinWidth, pinHeight);
|
||||
g2d.drawRect((int) (point.getX() - pinWidth / 2), (int) (point.getY() - pinHeight / 2),
|
||||
pinWidth, pinHeight);
|
||||
}
|
||||
}
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
@@ -337,14 +357,16 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
|
||||
Color finalBorderColor;
|
||||
if (outlineMode) {
|
||||
Theme theme =
|
||||
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: getBorderColor();
|
||||
}
|
||||
g2d.setColor(finalBorderColor);
|
||||
@@ -375,14 +397,16 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
g2d.setFont(project.getFont());
|
||||
Color finalLabelColor;
|
||||
if (outlineMode) {
|
||||
Theme theme =
|
||||
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? LABEL_COLOR_SELECTED
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
@@ -424,7 +448,7 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
g2d.translate(0, textHeight / 2);
|
||||
}
|
||||
|
||||
g2d.drawString(l, (int)x, (int)y);
|
||||
g2d.drawString(l, (int) x, (int) y);
|
||||
|
||||
g2d.setTransform(oldTransform);
|
||||
}
|
||||
@@ -441,9 +465,11 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
int tickHoleLength = (int) (width * 0.4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
g2d.setColor(TICK_COLOR.darker());
|
||||
g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, tickHoleLength, tickSize);
|
||||
g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2,
|
||||
tickHoleLength, tickSize);
|
||||
g2d.setColor(TICK_COLOR);
|
||||
g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, tickSize, tickSize);
|
||||
g2d.fillRect((width - tickHoleLength) / 2, (height / 5) * (i + 1) - tickSize / 2, tickSize,
|
||||
tickSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,7 +562,8 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
@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';
|
||||
return Math.abs(index1 - index2) == getSwitchCount().getValue()
|
||||
&& binary.charAt(index1 < index2 ? index1 : index2) == '1';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -548,14 +575,15 @@ public class DIPSwitch extends AbstractTransparentComponent<String> implements I
|
||||
public Rectangle2D getCachingBounds() {
|
||||
int margin = 20;
|
||||
Rectangle2D bounds = getBody()[0].getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin,
|
||||
bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
private String toBinary(int n) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
do {
|
||||
builder.append(n % 2);
|
||||
n = n / 2;
|
||||
builder.append(n % 2);
|
||||
n = n / 2;
|
||||
} while (n > 0);
|
||||
while (builder.length() < getSwitchCount().getValue())
|
||||
builder.append("0");
|
||||
|
||||
+44
-39
@@ -1,24 +1,21 @@
|
||||
/*
|
||||
|
||||
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/>.
|
||||
|
||||
*/
|
||||
*
|
||||
* 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;
|
||||
@@ -51,10 +48,10 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Tactile Micro-Switch", author = "Branislav Stojkovic", category = "Electro-Mechanical",
|
||||
instanceNamePrefix = "SW", description = "4-pin tactile momentary switch",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class,
|
||||
enableCache = true)
|
||||
@ComponentDescriptor(name = "Tactile Micro-Switch", author = "Branislav Stojkovic",
|
||||
category = "Electro-Mechanical", instanceNamePrefix = "SW",
|
||||
description = "4-pin tactile momentary switch", zOrder = IDIYComponent.COMPONENT,
|
||||
keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true)
|
||||
public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -186,8 +183,10 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
default:
|
||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||
}
|
||||
controlPoints[i] = new Point2D.Double((int) (firstPoint.getX() + dx1), (int) (firstPoint.getY() + dy1));
|
||||
controlPoints[i + PIN_COUNT / 2] = new Point2D.Double((int) (firstPoint.getX() + dx2), (int) (firstPoint.getY() + dy2));
|
||||
controlPoints[i] =
|
||||
new Point2D.Double((int) (firstPoint.getX() + dx1), (int) (firstPoint.getY() + dy1));
|
||||
controlPoints[i + PIN_COUNT / 2] =
|
||||
new Point2D.Double((int) (firstPoint.getX() + dx2), (int) (firstPoint.getY() + dy2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,8 +216,8 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
@@ -229,7 +228,8 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
if (!outlineMode) {
|
||||
int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2;
|
||||
for (Point2D point : controlPoints) {
|
||||
Rectangle2D rect = new Rectangle2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, pinSize, pinSize);
|
||||
Rectangle2D rect = new Rectangle2D.Double(point.getX() - pinSize / 2,
|
||||
point.getY() - pinSize / 2, pinSize, pinSize);
|
||||
g2d.setColor(PIN_COLOR);
|
||||
g2d.fill(rect);
|
||||
g2d.setColor(PIN_BORDER_COLOR);
|
||||
@@ -252,14 +252,16 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
|
||||
Color finalBorderColor;
|
||||
if (outlineMode) {
|
||||
Theme theme =
|
||||
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: getBorderColor();
|
||||
}
|
||||
g2d.setColor(finalBorderColor);
|
||||
@@ -278,14 +280,16 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
|
||||
Color finalLabelColor;
|
||||
if (outlineMode) {
|
||||
Theme theme =
|
||||
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? LABEL_COLOR_SELECTED
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
@@ -319,7 +323,7 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
g2d.translate(0, textHeight / 2);
|
||||
}
|
||||
|
||||
g2d.drawString(l, (int)x, (int)y);
|
||||
g2d.drawString(l, (int) x, (int) y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -406,6 +410,7 @@ public class TactileMicroSwitch extends AbstractLabeledComponent<String> {
|
||||
maxY = p.getY();
|
||||
}
|
||||
|
||||
return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin, maxY - minY + 2 * margin);
|
||||
return new Rectangle2D.Double(minX - margin, minY - margin, maxX - minX + 2 * margin,
|
||||
maxY - minY + 2 * margin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Mini Signal Transformer", author = "Branislav Stojkovic", category = "Passive",
|
||||
instanceNamePrefix = "TR", description = "Miniature PCB-mount signal transformer with EI core",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
public class AudioTransformer extends AbstractMultiPartComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
/*
|
||||
|
||||
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/>.
|
||||
|
||||
*/
|
||||
*
|
||||
* 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.AlphaComposite;
|
||||
@@ -45,7 +42,6 @@ import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractLabeledComponent;
|
||||
import org.diylc.components.AbstractLeadedComponent.LabelOriantation;
|
||||
import org.diylc.components.RoundedPolygon;
|
||||
import org.diylc.components.transform.DIL_ICTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -61,10 +57,10 @@ import org.diylc.core.measures.SizeUnit;
|
||||
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",
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class,
|
||||
enableCache = true)
|
||||
@ComponentDescriptor(name = "Bridge Rectifier", author = "Branislav Stojkovic",
|
||||
category = "Semiconductors", instanceNamePrefix = "BR",
|
||||
description = "Few variations of bridge rectifier chips", zOrder = IDIYComponent.COMPONENT,
|
||||
keywordPolicy = KeywordPolicy.SHOW_VALUE, enableCache = true)
|
||||
public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -74,22 +70,22 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
private static Size MINI_HORIZONTAL_SPACING = new Size(0.3d, SizeUnit.in);
|
||||
private static Size MINI_VERTICAL_SPACING = new Size(0.2d, SizeUnit.in);
|
||||
|
||||
private static int[] MINI1_LABEL_SPACING_X = new int[] { 1, -1, -1, 1 };
|
||||
private static int[] MINI2_LABEL_SPACING_X = new int[] { 1, -1, 1, -1 };
|
||||
private static int[] MINI1_LABEL_SPACING_X = new int[] {1, -1, -1, 1};
|
||||
private static int[] MINI2_LABEL_SPACING_X = new int[] {1, -1, 1, -1};
|
||||
|
||||
private static Size MINI_ROUND_DIAMETER = new Size(9.1d, SizeUnit.mm);
|
||||
private static Size MINI_ROUND_SPACING = new Size(0.2d, SizeUnit.in);
|
||||
private static int[] MINI_ROUND_LABEL_SPACING_Y = new int[] { 1, 1, -1, -1 };
|
||||
private static int[] MINI_ROUND_LABEL_SPACING_Y = new int[] {1, 1, -1, -1};
|
||||
|
||||
private static Size INLINE_LENGTH = new Size(23.2d, SizeUnit.mm);
|
||||
private static Size INLINE_WIDTH = new Size(2.7d, SizeUnit.mm);
|
||||
private static Size INLINE_SPACING = new Size(0.2d, SizeUnit.in);
|
||||
private static int[] INLINE_LABEL_SPACING_Y = new int[] { -1, -1, 1, 1 };
|
||||
private static int[] INLINE_LABEL_SPACING_Y = new int[] {-1, -1, 1, 1};
|
||||
|
||||
private static Size BR3_LENGTH = new Size(0.6d, SizeUnit.in);
|
||||
private static Size BR3_SPACING = new Size(0.425d, SizeUnit.in);
|
||||
private static Size BR3_HOLE_SIZE = new Size(3d, SizeUnit.mm);
|
||||
private static int[] BR3_LABEL_SPACING_Y = new int[] { 1, 1, -1, -1 };
|
||||
private static int[] BR3_LABEL_SPACING_Y = new int[] {1, 1, -1, -1};
|
||||
|
||||
public static Color BODY_COLOR = Color.gray;
|
||||
public static Color BORDER_COLOR = Color.gray.darker();
|
||||
@@ -103,8 +99,9 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
|
||||
private String value = "";
|
||||
private Orientation orientation = Orientation.DEFAULT;
|
||||
private Point2D[] controlPoints = new Point2D[] { new Point2D.Double(0, 0), new Point2D.Double(0, 0), new Point2D.Double(0, 0), new Point2D.Double(0, 0) };
|
||||
private String[] pointLabels = new String[] { "+", "~", "~", "-" };
|
||||
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0),
|
||||
new Point2D.Double(0, 0), new Point2D.Double(0, 0), new Point2D.Double(0, 0)};
|
||||
private String[] pointLabels = new String[] {"+", "~", "~", "-"};
|
||||
protected Display display = Display.BOTH;
|
||||
private Color bodyColor = BODY_COLOR;
|
||||
private Color borderColor = BORDER_COLOR;
|
||||
@@ -241,7 +238,8 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
theta = Math.PI * 3 / 2;
|
||||
break;
|
||||
}
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(theta, firstPoint.getX(), firstPoint.getY());
|
||||
AffineTransform rotation =
|
||||
AffineTransform.getRotateInstance(theta, firstPoint.getX(), firstPoint.getY());
|
||||
|
||||
for (int i = 1; i < controlPoints.length; i++) {
|
||||
rotation.transform(controlPoints[i], controlPoints[i]);
|
||||
@@ -254,8 +252,10 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
if (body == null) {
|
||||
body = new Area[2];
|
||||
|
||||
double centerX = (controlPoints[0].getX() + controlPoints[1].getX() + controlPoints[2].getX() + controlPoints[3].getX()) / 4;
|
||||
double centerY = (controlPoints[0].getY() + controlPoints[1].getY() + controlPoints[2].getY() + controlPoints[3].getY()) / 4;
|
||||
double centerX = (controlPoints[0].getX() + controlPoints[1].getX() + controlPoints[2].getX()
|
||||
+ controlPoints[3].getX()) / 4;
|
||||
double centerY = (controlPoints[0].getY() + controlPoints[1].getY() + controlPoints[2].getY()
|
||||
+ controlPoints[3].getY()) / 4;
|
||||
|
||||
int width = 0;
|
||||
int length = 0;
|
||||
@@ -289,36 +289,40 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
case MiniDIP1:
|
||||
case MiniDIP2:
|
||||
case InLine:
|
||||
body[0] = new Area(new RoundRectangle2D.Double(centerX - length / 2, centerY - width / 2, length, width, EDGE_RADIUS, EDGE_RADIUS));
|
||||
body[0] = new Area(new RoundRectangle2D.Double(centerX - length / 2, centerY - width / 2,
|
||||
length, width, EDGE_RADIUS, EDGE_RADIUS));
|
||||
break;
|
||||
case MiniRound1:
|
||||
case MiniRound2:
|
||||
body[0] = new Area(new Ellipse2D.Double(centerX - length / 2, centerY - width / 2, length, width));
|
||||
body[0] = new Area(
|
||||
new Ellipse2D.Double(centerX - length / 2, centerY - width / 2, length, width));
|
||||
break;
|
||||
case SquareBR3:
|
||||
double margin = (BR3_LENGTH.convertToPixels() - BR3_SPACING.convertToPixels()) / 2;
|
||||
double holeSize = BR3_HOLE_SIZE.convertToPixels();
|
||||
//
|
||||
// Path2D path = new Path2D.Double();
|
||||
// path.moveTo(centerX - width / 2 + margin, centerY - width / 2);
|
||||
// path.lineTo(centerX + width / 2, centerY - width / 2);
|
||||
// path.lineTo(centerX + width / 2, centerY + width / 2);
|
||||
// path.lineTo(centerX - width / 2, centerY + width / 2);
|
||||
// path.lineTo(centerX - width / 2, centerY - width / 2 + margin);
|
||||
// path.closePath();
|
||||
//
|
||||
// Path2D path = new Path2D.Double();
|
||||
// path.moveTo(centerX - width / 2 + margin, centerY - width / 2);
|
||||
// path.lineTo(centerX + width / 2, centerY - width / 2);
|
||||
// path.lineTo(centerX + width / 2, centerY + width / 2);
|
||||
// path.lineTo(centerX - width / 2, centerY + width / 2);
|
||||
// path.lineTo(centerX - width / 2, centerY - width / 2 + margin);
|
||||
// path.closePath();
|
||||
|
||||
RoundedPolygon poly = new RoundedPolygon(new Point2D[] {
|
||||
new Point2D.Double(centerX, centerY - width / 2),
|
||||
new Point2D.Double(centerX + width / 2, centerY - width / 2),
|
||||
new Point2D.Double(centerX + width / 2, centerY + width / 2),
|
||||
new Point2D.Double(centerX - width / 2, centerY + width / 2),
|
||||
new Point2D.Double(centerX - width / 2, (int) (centerY - width / 2 + margin)),
|
||||
new Point2D.Double((int) (centerX - width / 2 + margin), centerY - width / 2),
|
||||
RoundedPolygon poly =
|
||||
new RoundedPolygon(new Point2D[] {new Point2D.Double(centerX, centerY - width / 2),
|
||||
new Point2D.Double(centerX + width / 2, centerY - width / 2),
|
||||
new Point2D.Double(centerX + width / 2, centerY + width / 2),
|
||||
new Point2D.Double(centerX - width / 2, centerY + width / 2),
|
||||
new Point2D.Double(centerX - width / 2, (int) (centerY - width / 2 + margin)),
|
||||
new Point2D.Double((int) (centerX - width / 2 + margin), centerY - width / 2),
|
||||
|
||||
}, new double[] { EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS / 2 , EDGE_RADIUS / 2});
|
||||
}, new double[] {EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS, EDGE_RADIUS / 2,
|
||||
EDGE_RADIUS / 2});
|
||||
|
||||
body[0] = new Area(poly);
|
||||
body[0].subtract(new Area(new Ellipse2D.Double(centerX - holeSize / 2, centerY - holeSize / 2, holeSize, holeSize)));
|
||||
body[0].subtract(new Area(new Ellipse2D.Double(centerX - holeSize / 2,
|
||||
centerY - holeSize / 2, holeSize, holeSize)));
|
||||
|
||||
if (orientation != Orientation.DEFAULT) {
|
||||
double theta = 0;
|
||||
@@ -346,15 +350,16 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
|
||||
Project project, IDrawingObserver drawingObserver) {
|
||||
if (checkPointsClipped(g2d.getClip())) {
|
||||
return;
|
||||
}
|
||||
Area mainArea = getBody()[0];
|
||||
|
||||
PinShape pinShape = rectifierType.getPinShape();
|
||||
int pinSize = (int) (pinShape == PinShape.Round ? ROUND_PIN_SIZE.convertToPixels() : SQUARE_PIN_SIZE.convertToPixels()) / 2 * 2;
|
||||
int pinSize = (int) (pinShape == PinShape.Round ? ROUND_PIN_SIZE.convertToPixels()
|
||||
: SQUARE_PIN_SIZE.convertToPixels()) / 2 * 2;
|
||||
|
||||
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1f));
|
||||
if (!outlineMode) {
|
||||
@@ -362,9 +367,11 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
g2d.setColor(PIN_COLOR);
|
||||
Shape shape;
|
||||
if (pinShape == PinShape.Round)
|
||||
shape = new Ellipse2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, pinSize, pinSize);
|
||||
shape = new Ellipse2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2,
|
||||
pinSize, pinSize);
|
||||
else
|
||||
shape = new Rectangle2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2, pinSize, pinSize);
|
||||
shape = new Rectangle2D.Double(point.getX() - pinSize / 2, point.getY() - pinSize / 2,
|
||||
pinSize, pinSize);
|
||||
g2d.fill(shape);
|
||||
g2d.setColor(PIN_BORDER_COLOR);
|
||||
g2d.draw(shape);
|
||||
@@ -381,14 +388,16 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
|
||||
Color finalBorderColor;
|
||||
if (outlineMode) {
|
||||
Theme theme =
|
||||
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalBorderColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? SELECTION_COLOR
|
||||
: getBorderColor();
|
||||
}
|
||||
g2d.setColor(finalBorderColor);
|
||||
@@ -399,10 +408,10 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
g2d.draw(area);
|
||||
} else {
|
||||
g2d.draw(mainArea);
|
||||
// if (getBody()[1] != null) {
|
||||
// g2d.setColor(getIndentColor());
|
||||
// g2d.fill(getBody()[1]);
|
||||
// }
|
||||
// if (getBody()[1] != null) {
|
||||
// g2d.setColor(getIndentColor());
|
||||
// g2d.fill(getBody()[1]);
|
||||
// }
|
||||
}
|
||||
|
||||
drawingObserver.stopTracking();
|
||||
@@ -416,14 +425,16 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
|
||||
Color finalLabelColor;
|
||||
if (outlineMode) {
|
||||
Theme theme =
|
||||
(Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
|
||||
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
|
||||
Constants.DEFAULT_THEME);
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? LABEL_COLOR_SELECTED
|
||||
: theme.getOutlineColor();
|
||||
} else {
|
||||
finalLabelColor =
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
|
||||
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
|
||||
? LABEL_COLOR_SELECTED
|
||||
: getLabelColor();
|
||||
}
|
||||
g2d.setColor(finalLabelColor);
|
||||
@@ -452,7 +463,8 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
|
||||
AffineTransform oldTransform = g2d.getTransform();
|
||||
|
||||
if (getLabelOriantation() == LabelOriantation.Directional && (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180)) {
|
||||
if (getLabelOriantation() == LabelOriantation.Directional
|
||||
&& (getOrientation() == Orientation.DEFAULT || getOrientation() == Orientation._180)) {
|
||||
double centerX = bounds.getX() + bounds.width / 2;
|
||||
double centerY = bounds.getY() + bounds.height / 2;
|
||||
g2d.rotate(-Math.PI / 2, centerX, centerY);
|
||||
@@ -468,7 +480,7 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
if (rectifierType == RectifierType.SquareBR3)
|
||||
y -= BR3_HOLE_SIZE.convertToPixels();
|
||||
|
||||
g2d.drawString(l, (int)x, (int)y);
|
||||
g2d.drawString(l, (int) x, (int) y);
|
||||
|
||||
g2d.setTransform(oldTransform);
|
||||
}
|
||||
@@ -477,7 +489,7 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
// draw pin numbers
|
||||
g2d.setFont(project.getFont().deriveFont((float) (project.getFont().getSize2D() * 0.8)));
|
||||
g2d.setColor(finalLabelColor);
|
||||
for (int i = 0; i <controlPoints.length; i++) {
|
||||
for (int i = 0; i < controlPoints.length; i++) {
|
||||
Point2D point = controlPoints[i];
|
||||
|
||||
int dx = 0;
|
||||
@@ -517,8 +529,8 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
dy = p1;
|
||||
break;
|
||||
case _180:
|
||||
dx = - dx;
|
||||
dy = - dy;
|
||||
dx = -dx;
|
||||
dy = -dy;
|
||||
break;
|
||||
case _270:
|
||||
int p2 = dx;
|
||||
@@ -537,8 +549,8 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
dy = -p1;
|
||||
break;
|
||||
case _180:
|
||||
dx = - dx;
|
||||
dy = - dy;
|
||||
dx = -dx;
|
||||
dy = -dy;
|
||||
break;
|
||||
case _270:
|
||||
int p2 = dx;
|
||||
@@ -567,14 +579,16 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
break;
|
||||
}
|
||||
|
||||
StringUtils.drawCenteredText(g2d, pointLabels[i], point.getX() + dx, point.getY() + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
StringUtils.drawCenteredText(g2d, pointLabels[i], point.getX() + dx, point.getY() + dy,
|
||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawIcon(Graphics2D g2d, int width, int height) {
|
||||
int margin = (int) (2f * width / 32);
|
||||
Area area = new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2 * margin));
|
||||
Area area =
|
||||
new Area(new Ellipse2D.Double(margin / 2, margin, width - 2 * margin, width - 2 * margin));
|
||||
g2d.setColor(BODY_COLOR);
|
||||
g2d.fill(area);
|
||||
g2d.setColor(BORDER_COLOR);
|
||||
@@ -587,10 +601,14 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
g2d.fillOval(width * 2 / 8, height * 6 / 8 - pinSize, pinSize, pinSize);
|
||||
g2d.setColor(LABEL_COLOR);
|
||||
g2d.setFont(LABEL_FONT.deriveFont(8f * width / 32));
|
||||
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);
|
||||
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")
|
||||
@@ -678,17 +696,15 @@ public class BridgeRectifier extends AbstractLabeledComponent<String> {
|
||||
public Rectangle2D getCachingBounds() {
|
||||
int margin = 20;
|
||||
Rectangle2D bounds = getBody()[0].getBounds2D();
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin, bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin,
|
||||
bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
|
||||
}
|
||||
|
||||
public static enum RectifierType {
|
||||
|
||||
MiniDIP1("DFM A", PinShape.Square),
|
||||
MiniDIP2("DFM B", PinShape.Square),
|
||||
MiniRound1("Round WOG A", PinShape.Round),
|
||||
MiniRound2("Round WOG B", PinShape.Round),
|
||||
InLine("In-Line D-44", PinShape.Round),
|
||||
SquareBR3("Square BR-3", PinShape.Round);
|
||||
MiniDIP1("DFM A", PinShape.Square), MiniDIP2("DFM B", PinShape.Square), MiniRound1(
|
||||
"Round WOG A", PinShape.Round), MiniRound2("Round WOG B", PinShape.Round), InLine(
|
||||
"In-Line D-44", PinShape.Round), SquareBR3("Square BR-3", PinShape.Round);
|
||||
|
||||
private String label;
|
||||
private PinShape pinShape;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<property name="jar.dir" value="${build.dir}/jar" />
|
||||
<property name="report.dir" value="${build.dir}/junitreport" />
|
||||
<property name="main.class" value="org.diylc.DIYLCStarter" />
|
||||
<property name="diylc.version" value="4.36.0" />
|
||||
<property name="diylc.version" value="4.37.0" />
|
||||
|
||||
<property name="osx.jre8.path" value="tools\jre\osx\jre8u321\Contents\Home\" />
|
||||
<property name="osx.jre8m1.path" value="tools\jre\osx\zulu-8.jre\Contents\Home\" />
|
||||
|
||||
@@ -49,6 +49,7 @@ AWG
|
||||
Alternate
|
||||
And
|
||||
Angle Offset
|
||||
Apply Model
|
||||
B-C-E BJT
|
||||
Background
|
||||
Box
|
||||
@@ -103,6 +104,7 @@ I-G-O REGULATOR
|
||||
Italiano
|
||||
Lin
|
||||
Log
|
||||
MPJA
|
||||
Markers
|
||||
Maximum number of switching combinations exceeded. Allowed: %s, actual: %s
|
||||
NPN
|
||||
@@ -126,6 +128,8 @@ PCB
|
||||
PNP
|
||||
Poles
|
||||
Português
|
||||
RS
|
||||
RY1
|
||||
Rectangle
|
||||
Rev log
|
||||
S-G-D JFET
|
||||
|
||||
@@ -37,6 +37,15 @@
|
||||
<update_contact>nbenitezl_AT_gmail.com</update_contact>
|
||||
<content_rating type="oars-1.1"/>
|
||||
<releases>
|
||||
<release version="4.37.0" date="2023-04-27">
|
||||
<description>
|
||||
<ul>
|
||||
<li>[New Feature] 'Proto Board 780 Holes' added with two variations (sponsored by Pete Olivier)</li>
|
||||
<li>[Improvement] Ability to rotate (almost) all components using keyboard shortcuts and 'Transform Selection' menu</li>
|
||||
</ul>
|
||||
</description>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases/tag/v4.37.0</url>
|
||||
</release>
|
||||
<release version="4.36.0" date="2023-03-30">
|
||||
<description>
|
||||
<ul>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user