mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
added more transformers
This commit is contained in:
@@ -18,6 +18,7 @@ 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.SIL_ICTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -33,7 +34,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "SIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "IC", description = "Single-in-line package IC", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = SIL_ICTransformer.class)
|
||||
public class SIL_IC extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -18,6 +18,7 @@ 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;
|
||||
@@ -33,7 +34,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-1 package)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with small metal body", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO1Transformer.class)
|
||||
public class TransistorTO1 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -18,6 +18,7 @@ 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;
|
||||
@@ -33,7 +34,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Transistor (TO-220 package)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistors with metal tab for heat sink mounting", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO220Transformer.class)
|
||||
public class TransistorTO220 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package org.diylc.components.transform;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.semiconductors.SIL_IC;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class SIL_ICTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(SIL_IC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(SIL_IC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y);
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point p = new Point(component.getControlPoint(index));
|
||||
rotate.transform(p, p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
|
||||
SIL_IC ic = (SIL_IC) component;
|
||||
Orientation o = ic.getOrientation();
|
||||
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];
|
||||
ic.setOrientation(o);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
SIL_IC ic = (SIL_IC) component;
|
||||
int dx = center.x - ic.getControlPoint(0).x;
|
||||
int dy = center.y - ic.getControlPoint(0).y;
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
Orientation o = ic.getOrientation();
|
||||
switch (o) {
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
break;
|
||||
case _270:
|
||||
o = Orientation._90;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ic.getControlPointCount(); i++) {
|
||||
Point p = ic.getControlPoint(i);
|
||||
ic.setControlPoint(new Point(p.x + 2 * dx, p.y), i);
|
||||
}
|
||||
|
||||
ic.setOrientation(o);
|
||||
} else {
|
||||
Orientation o = ic.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _180:
|
||||
o = Orientation.DEFAULT;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ic.getControlPointCount(); i++) {
|
||||
Point p = ic.getControlPoint(i);
|
||||
ic.setControlPoint(new Point(p.x, p.y + 2 * dy), i);
|
||||
}
|
||||
|
||||
ic.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.diylc.components.transform;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.semiconductors.TransistorTO1;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class TO1Transformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TransistorTO1.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TransistorTO1.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y);
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point p = new Point(component.getControlPoint(index));
|
||||
rotate.transform(p, p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
|
||||
TransistorTO1 transistor = (TransistorTO1) component;
|
||||
Orientation o = transistor.getOrientation();
|
||||
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];
|
||||
transistor.setOrientation(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
TransistorTO1 transistor = (TransistorTO1) component;
|
||||
int dx = center.x - transistor.getControlPoint(0).x;
|
||||
int dy = center.y - transistor.getControlPoint(0).y;
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
Orientation o = transistor.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _90:
|
||||
dx -= (transistor.getControlPoint(1).x - transistor.getControlPoint(0).x);
|
||||
break;
|
||||
case _180:
|
||||
o = Orientation.DEFAULT;
|
||||
break;
|
||||
case _270:
|
||||
dx -= (transistor.getControlPoint(1).x - transistor.getControlPoint(0).x);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < transistor.getControlPointCount(); i++) {
|
||||
Point p = transistor.getControlPoint(i);
|
||||
transistor.setControlPoint(
|
||||
new Point(p.x + 2 * dx, p.y + (transistor.getControlPoint(2).y - transistor.getControlPoint(0).y)), i);
|
||||
}
|
||||
|
||||
transistor.setOrientation(o);
|
||||
} else {
|
||||
Orientation o = transistor.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dy -= (transistor.getControlPoint(1).y - transistor.getControlPoint(0).y);
|
||||
break;
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
break;
|
||||
case _180:
|
||||
dy -= (transistor.getControlPoint(1).y - transistor.getControlPoint(0).y);
|
||||
break;
|
||||
case _270:
|
||||
o = Orientation._90;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < transistor.getControlPointCount(); i++) {
|
||||
Point p = transistor.getControlPoint(i);
|
||||
transistor.setControlPoint(new Point(p.x + (transistor.getControlPoint(2).x - transistor.getControlPoint(0).x),
|
||||
p.y + 2 * dy), i);
|
||||
}
|
||||
|
||||
transistor.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package org.diylc.components.transform;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.semiconductors.TransistorTO220;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class TO220Transformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TransistorTO220.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TransistorTO220.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
||||
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y);
|
||||
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||
Point p = new Point(component.getControlPoint(index));
|
||||
rotate.transform(p, p);
|
||||
component.setControlPoint(p, index);
|
||||
}
|
||||
|
||||
TransistorTO220 transistor = (TransistorTO220) component;
|
||||
Orientation o = transistor.getOrientation();
|
||||
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];
|
||||
transistor.setOrientation(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
TransistorTO220 transistor = (TransistorTO220) component;
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
int dx = 2 * (center.x - transistor.getControlPoint(0).x);
|
||||
int dy = 0;
|
||||
Orientation o = transistor.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
o = Orientation._180;
|
||||
dy -= (transistor.getControlPoint(0).y - transistor.getControlPoint(2).y);
|
||||
break;
|
||||
case _90:
|
||||
dx += (transistor.getControlPoint(0).x - transistor.getControlPoint(2).x);
|
||||
break;
|
||||
case _180:
|
||||
o = Orientation.DEFAULT;
|
||||
dy -= (transistor.getControlPoint(0).y - transistor.getControlPoint(2).y);
|
||||
break;
|
||||
case _270:
|
||||
dx += (transistor.getControlPoint(0).x - transistor.getControlPoint(2).x);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < transistor.getControlPointCount(); i++) {
|
||||
Point p = transistor.getControlPoint(i);
|
||||
transistor.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
transistor.setOrientation(o);
|
||||
} else {
|
||||
int dx = 0;
|
||||
int dy = 2 * (center.y - transistor.getControlPoint(0).y);
|
||||
Orientation o = transistor.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dy += (transistor.getControlPoint(0).y - transistor.getControlPoint(2).y);
|
||||
break;
|
||||
case _90:
|
||||
dx -= (transistor.getControlPoint(0).x - transistor.getControlPoint(2).x);
|
||||
o = Orientation._270;
|
||||
break;
|
||||
case _180:
|
||||
dy += (transistor.getControlPoint(0).y - transistor.getControlPoint(2).y);
|
||||
break;
|
||||
case _270:
|
||||
dx -= (transistor.getControlPoint(0).x - transistor.getControlPoint(2).x);
|
||||
o = Orientation._90;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < transistor.getControlPointCount(); i++) {
|
||||
Point p = transistor.getControlPoint(i);
|
||||
transistor.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
transistor.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user