mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added transformers
don't apply template points
This commit is contained in:
@@ -14,6 +14,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.TerminalStripTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -29,7 +30,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Terminal Strip", author = "Branislav Stojkovic", category = "Boards",
|
||||
instanceNamePrefix = "TS", description = "Row of terminals for point-to-point construction", stretchable = false,
|
||||
zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME)
|
||||
zOrder = IDIYComponent.BOARD, keywordPolicy = KeywordPolicy.SHOW_TYPE_NAME, transformer = TerminalStripTransformer.class)
|
||||
public class TerminalStrip extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -17,6 +17,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.BatterySnapTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -31,7 +32,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "9V Battery Snap", category = "Electromechanical", author = "Branislav Stojkovic",
|
||||
description = "", stretchable = false, zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "BTR",
|
||||
autoEdit = false)
|
||||
autoEdit = false, transformer = BatterySnapTransformer.class)
|
||||
public class BatterySnap9V extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.CliffJackTransformer;
|
||||
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 = "Cliff 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
|
||||
description = "Cliff-style closed panel mount 1/4\" phono jack", stretchable = false,
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false)
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class)
|
||||
public class CliffJack1_4 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.components.transform.ClosedJackTransformer;
|
||||
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 = "Closed 1/4\" Jack", category = "Electromechanical", author = "Branislav Stojkovic",
|
||||
description = "Enclosed panel mount 1/4\" phono jack", stretchable = false, zOrder = IDIYComponent.COMPONENT,
|
||||
instanceNamePrefix = "J", autoEdit = false)
|
||||
instanceNamePrefix = "J", autoEdit = false, transformer = ClosedJackTransformer.class)
|
||||
public class ClosedJack1_4 extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -19,7 +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.components.transform.DIL_ICTransformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -35,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, transformer = ICTransformer.class)
|
||||
zOrder = IDIYComponent.COMPONENT, keywordPolicy = KeywordPolicy.SHOW_VALUE, transformer = DIL_ICTransformer.class)
|
||||
public class DIL_IC extends AbstractTransparentComponent<String> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
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.electromechanical.BatterySnap9V;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class BatterySnapTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(BatterySnap9V.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(BatterySnap9V.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
BatterySnap9V snap = (BatterySnap9V) component;
|
||||
Orientation o = snap.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];
|
||||
snap.setOrientation(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
BatterySnap9V snap = (BatterySnap9V) component;
|
||||
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
int dx = 2 * (center.x - snap.getControlPoint(0).x);
|
||||
int dy = 0;
|
||||
Orientation o = snap.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _90:
|
||||
break;
|
||||
case _180:
|
||||
o = Orientation.DEFAULT;
|
||||
break;
|
||||
case _270:
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < snap.getControlPointCount(); i++) {
|
||||
Point p = snap.getControlPoint(i);
|
||||
snap.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
snap.setOrientation(o);
|
||||
} else {
|
||||
int dx = 0;
|
||||
int dy = 2 * (center.y - snap.getControlPoint(1).y);
|
||||
Orientation o = snap.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
break;
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
break;
|
||||
case _180:
|
||||
break;
|
||||
case _270:
|
||||
o = Orientation._90;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < snap.getControlPointCount(); i++) {
|
||||
Point p = snap.getControlPoint(i);
|
||||
snap.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
snap.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.electromechanical.CliffJack1_4;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class CliffJackTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(CliffJack1_4.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(CliffJack1_4.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);
|
||||
}
|
||||
|
||||
CliffJack1_4 jack = (CliffJack1_4) component;
|
||||
Orientation o = jack.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];
|
||||
jack.setOrientation(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
CliffJack1_4 ic = (CliffJack1_4) 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:
|
||||
dy += (ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 1).y);
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _90:
|
||||
// dy += ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 1).y;
|
||||
break;
|
||||
case _180:
|
||||
dy += (ic.getControlPoint(0).y - ic.getControlPoint(ic.getControlPointCount() - 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);
|
||||
} 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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ import org.diylc.common.Orientation;
|
||||
import org.diylc.components.semiconductors.DIL_IC;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class ICTransformer implements IComponentTransformer {
|
||||
public class DIL_ICTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
@@ -22,7 +22,7 @@ public class SIL_ICTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.boards.TerminalStrip;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class TerminalStripTransformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TerminalStrip.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(TerminalStrip.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mirroringChangesCircuit() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
TerminalStrip strip = (TerminalStrip) component;
|
||||
Orientation o = strip.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];
|
||||
strip.setOrientation(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
||||
TerminalStrip strip = (TerminalStrip) component;
|
||||
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
int dx = 2 * (center.x - strip.getControlPoint(1).x);
|
||||
int dy = 0;
|
||||
Orientation o = strip.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dx += strip.getControlPoint(0).x - strip.getControlPoint(strip.getControlPointCount() - 1).x;
|
||||
break;
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
dx -= 2 * (strip.getControlPoint(0).x - strip.getControlPoint(1).x);
|
||||
dy -= strip.getControlPoint(0).y - strip.getControlPoint(strip.getControlPointCount() - 1).y;
|
||||
break;
|
||||
case _180:
|
||||
dx += strip.getControlPoint(0).x - strip.getControlPoint(strip.getControlPointCount() - 1).x;
|
||||
break;
|
||||
case _270:
|
||||
dx -= 2 * (strip.getControlPoint(0).x - strip.getControlPoint(1).x);
|
||||
dy -= strip.getControlPoint(0).y - strip.getControlPoint(strip.getControlPointCount() - 1).y;
|
||||
o = Orientation._90;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < strip.getControlPointCount(); i++) {
|
||||
Point p = strip.getControlPoint(i);
|
||||
strip.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
strip.setOrientation(o);
|
||||
} else {
|
||||
int dx = 0;
|
||||
int dy = 2 * (center.y - strip.getControlPoint(1).y);
|
||||
Orientation o = strip.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dx -= strip.getControlPoint(0).x - strip.getControlPoint(strip.getControlPointCount() - 1).x;
|
||||
dy -= 2 * (strip.getControlPoint(0).y - strip.getControlPoint(1).y);
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _90:
|
||||
dy += strip.getControlPoint(0).y - strip.getControlPoint(strip.getControlPointCount() - 1).y;
|
||||
break;
|
||||
case _180:
|
||||
dx -= strip.getControlPoint(0).x - strip.getControlPoint(strip.getControlPointCount() - 1).x;
|
||||
dy -= 2 * (strip.getControlPoint(0).y - strip.getControlPoint(1).y);
|
||||
o = Orientation.DEFAULT;
|
||||
break;
|
||||
case _270:
|
||||
dy += strip.getControlPoint(0).y - strip.getControlPoint(strip.getControlPointCount() - 1).y;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < strip.getControlPointCount(); i++) {
|
||||
Point p = strip.getControlPoint(i);
|
||||
strip.setControlPoint(new Point(p.x + dx, p.y + dy), i);
|
||||
}
|
||||
|
||||
strip.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user