trimmer transformation

This commit is contained in:
bancika
2020-12-11 13:52:22 +01:00
parent 77ab989334
commit 59620a6692
2 changed files with 135 additions and 95 deletions
@@ -35,6 +35,7 @@ import org.diylc.common.Display;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.components.transform.TrimmerTransformer;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
@@ -49,7 +50,8 @@ import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT)
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT,
transformer = TrimmerTransformer.class)
public class TrimmerPotentiometer extends AbstractPotentiometer {
private static final long serialVersionUID = 1L;
@@ -1,94 +1,132 @@
//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.TrimmerPotentiometer;
//import org.diylc.core.IDIYComponent;
//
//public class TrimmerTransformer implements IComponentTransformer {
//
// @Override
// public boolean canRotate(IDIYComponent<?> component) {
// return component.getClass().equals(TrimmerPotentiometer.class);
// }
//
// @Override
// public boolean canMirror(IDIYComponent<?> component) {
// return component.getClass().equals(TrimmerPotentiometer.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);
// }
//
// TrimmerPotentiometer potentiometer = (TrimmerPotentiometer) 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) {
// TrimmerPotentiometer potentiometer = (TrimmerPotentiometer) 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);
// }
// }
//}
/*
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.transform;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import org.diylc.common.IComponentTransformer;
import org.diylc.common.Orientation;
import org.diylc.components.passive.TrimmerPotentiometer;
import org.diylc.components.semiconductors.DIL_IC;
import org.diylc.core.IDIYComponent;
public class TrimmerTransformer implements IComponentTransformer {
@Override
public boolean canRotate(IDIYComponent<?> component) {
return component.getClass().equals(TrimmerPotentiometer.class);
}
@Override
public boolean canMirror(IDIYComponent<?> component) {
return component.getClass().equals(TrimmerPotentiometer.class);
}
@Override
public boolean mirroringChangesCircuit() {
return true;
}
@Override
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
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);
}
TrimmerPotentiometer potentiometer = (TrimmerPotentiometer) 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, Point2D center, int direction) {
TrimmerPotentiometer pot = (TrimmerPotentiometer) component;
if (direction == IComponentTransformer.HORIZONTAL) {
double dx = 2 * (center.getX() - pot.getControlPoint(0).getX());
double dy = 0;
Orientation o = pot.getOrientation();
switch (o) {
case DEFAULT:
o = Orientation._180;
dy -= pot.getControlPoint(0).getY() - pot.getControlPoint(2).getY();
break;
case _90:
dx += (pot.getControlPoint(0).getX() - pot.getControlPoint(2).getX());
break;
case _180:
o = Orientation.DEFAULT;
dy -= pot.getControlPoint(0).getY() - pot.getControlPoint(2).getY();
break;
case _270:
dx += (pot.getControlPoint(0).getX() - pot.getControlPoint(2).getX());
break;
}
for (int i = 0; i < pot.getControlPointCount(); i++) {
Point2D p = pot.getControlPoint(i);
pot.setControlPoint(new Point2D.Double(p.getX() + dx, p.getY() + dy), i);
}
pot.setOrientation(o);
} else {
double dx = 0;
double dy = 2 * (center.getY() - pot.getControlPoint(0).getY());
Orientation o = pot.getOrientation();
switch (o) {
case DEFAULT:
dy += pot.getControlPoint(0).getY() - pot.getControlPoint(2).getY();
break;
case _90:
dx -= (pot.getControlPoint(0).getX() - pot.getControlPoint(2).getX());
o = Orientation._270;
break;
case _180:
dy += pot.getControlPoint(0).getY() - pot.getControlPoint(2).getY();
break;
case _270:
dx -= (pot.getControlPoint(0).getX() - pot.getControlPoint(2).getX());
o = Orientation._90;
break;
}
for (int i = 0; i < pot.getControlPointCount(); i++) {
Point2D p = pot.getControlPoint(i);
pot.setControlPoint(new Point2D.Double(p.getX() + dx, p.getY() + dy), i);
}
pot.setOrientation(o);
}
}
}