mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
transformers for to92, dilIC and pot.
This commit is contained in:
@@ -14,6 +14,7 @@ import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.transform.PotentiometerTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
@@ -28,7 +29,8 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Potentiometer (panel mount)", 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, stretchable = false,
|
||||
transformer = PotentiometerTransformer.class)
|
||||
public class PotentiometerPanel extends AbstractPotentiometer {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.misc.Label;
|
||||
import org.diylc.components.transform.ICTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -34,7 +35,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "DIP IC", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "IC", description = "Dual-in-line package IC", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = ICTransformer.class)
|
||||
public class DIL_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.TO92Transformer;
|
||||
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-92 package)", author = "Branislav Stojkovic", category = "Semiconductors",
|
||||
instanceNamePrefix = "Q", description = "Transistor with small plastic or epoxy body", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = TO92Transformer.class)
|
||||
public class TransistorTO92 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
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.DIL_IC;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class ICTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(DIL_IC.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(DIL_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);
|
||||
}
|
||||
|
||||
DIL_IC ic = (DIL_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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
DIL_IC ic = (DIL_IC) component;
|
||||
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
int dx = 2 * (center.x - ic.getControlPoint(1).x);
|
||||
int dy = 0;
|
||||
Orientation o = ic.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dx += ic.getControlPoint(0).x - ic.getControlPoint(ic.getControlPointCount() - 1).x;
|
||||
break;
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
dx -= 2 * (ic.getControlPoint(0).x - ic.getControlPoint(1).x);
|
||||
dy -= ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 1).y;
|
||||
break;
|
||||
case _180:
|
||||
dx += ic.getControlPoint(0).x - ic.getControlPoint(ic.getControlPointCount() - 1).x;
|
||||
break;
|
||||
case _270:
|
||||
dx -= 2 * (ic.getControlPoint(0).x - ic.getControlPoint(1).x);
|
||||
dy -= ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 1).y;
|
||||
o = Orientation._90;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ic.getControlPointCount(); i++) {
|
||||
Point p = ic.getControlPoint(i);
|
||||
ic.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
ic.setOrientation(o);
|
||||
} else {
|
||||
int dx = 0;
|
||||
int dy = 2 * (center.y - ic.getControlPoint(1).y);
|
||||
Orientation o = ic.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dx -= ic.getControlPoint(0).x - ic.getControlPoint(ic.getControlPointCount() - 1).x;
|
||||
dy -= 2 * (ic.getControlPoint(0).y - ic.getControlPoint(1).y);
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _90:
|
||||
dy += ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 1).y;
|
||||
break;
|
||||
case _180:
|
||||
dx -= ic.getControlPoint(0).x - ic.getControlPoint(ic.getControlPointCount() - 1).x;
|
||||
dy -= 2 * (ic.getControlPoint(0).y - ic.getControlPoint(1).y);
|
||||
o = Orientation.DEFAULT;
|
||||
break;
|
||||
case _270:
|
||||
dy += ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 1).y;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ic.getControlPointCount(); i++) {
|
||||
Point p = ic.getControlPoint(i);
|
||||
ic.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
ic.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
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.passive.PotentiometerPanel;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class PotentiometerTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(PotentiometerPanel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(PotentiometerPanel.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);
|
||||
}
|
||||
|
||||
PotentiometerPanel potentiometer = (PotentiometerPanel) component;
|
||||
Orientation o = potentiometer.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];
|
||||
potentiometer.setOrientation(o);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
PotentiometerPanel potentiometer = (PotentiometerPanel) component;
|
||||
int dx = center.x - potentiometer.getControlPoint(1).x;
|
||||
int dy = center.y - potentiometer.getControlPoint(1).y;
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
Orientation o = potentiometer.getOrientation();
|
||||
switch (o) {
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
break;
|
||||
case _270:
|
||||
o = Orientation._90;
|
||||
}
|
||||
|
||||
for (int i = 0; i < potentiometer.getControlPointCount(); i++) {
|
||||
Point p = potentiometer.getControlPoint(i);
|
||||
potentiometer
|
||||
.setControlPoint(
|
||||
new Point(p.x + 2 * dx, p.y + (potentiometer.getControlPoint(2).y - potentiometer.getControlPoint(0).y)),
|
||||
i);
|
||||
}
|
||||
|
||||
potentiometer.setOrientation(o);
|
||||
} else {
|
||||
Orientation o = potentiometer.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _180:
|
||||
o = Orientation.DEFAULT;
|
||||
}
|
||||
|
||||
for (int i = 0; i < potentiometer.getControlPointCount(); i++) {
|
||||
Point p = potentiometer.getControlPoint(i);
|
||||
potentiometer
|
||||
.setControlPoint(new Point(p.x + (potentiometer.getControlPoint(2).x - potentiometer.getControlPoint(0).x),
|
||||
p.y + 2 * dy), i);
|
||||
}
|
||||
|
||||
potentiometer.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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.TransistorTO92;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class TO92Transformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TransistorTO92.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TransistorTO92.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);
|
||||
}
|
||||
|
||||
TransistorTO92 transistor = (TransistorTO92) 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);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
TransistorTO92 transistor = (TransistorTO92) component;
|
||||
int dx = center.x - transistor.getControlPoint(1).x;
|
||||
int dy = center.y - transistor.getControlPoint(1).y;
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
Orientation o = transistor.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _180:
|
||||
o = Orientation.DEFAULT;
|
||||
}
|
||||
|
||||
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 _90:
|
||||
o = Orientation._270;
|
||||
break;
|
||||
case _270:
|
||||
o = Orientation._90;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user