mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
trimmer transformation
This commit is contained in:
@@ -35,6 +35,7 @@ import org.diylc.common.Display;
|
|||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
import org.diylc.common.Orientation;
|
import org.diylc.common.Orientation;
|
||||||
|
import org.diylc.components.transform.TrimmerTransformer;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.CreationMethod;
|
import org.diylc.core.CreationMethod;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
@@ -49,7 +50,8 @@ import org.diylc.utils.Constants;
|
|||||||
|
|
||||||
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
|
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
|
||||||
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
|
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 {
|
public class TrimmerPotentiometer extends AbstractPotentiometer {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -1,94 +1,132 @@
|
|||||||
//package org.diylc.components.transform;
|
/*
|
||||||
//
|
|
||||||
//import java.awt.Point;
|
DIY Layout Creator (DIYLC).
|
||||||
//import java.awt.geom.AffineTransform;
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
//
|
|
||||||
//import org.diylc.common.IComponentTransformer;
|
This file is part of DIYLC.
|
||||||
//import org.diylc.common.Orientation;
|
|
||||||
//import org.diylc.components.passive.TrimmerPotentiometer;
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
//import org.diylc.core.IDIYComponent;
|
it under the terms of the GNU General Public License as published by
|
||||||
//
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
//public class TrimmerTransformer implements IComponentTransformer {
|
(at your option) any later version.
|
||||||
//
|
|
||||||
// @Override
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
// public boolean canRotate(IDIYComponent<?> component) {
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// return component.getClass().equals(TrimmerPotentiometer.class);
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// }
|
GNU General Public License for more details.
|
||||||
//
|
|
||||||
// @Override
|
You should have received a copy of the GNU General Public License
|
||||||
// public boolean canMirror(IDIYComponent<?> component) {
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
// return component.getClass().equals(TrimmerPotentiometer.class);
|
|
||||||
// }
|
*/
|
||||||
//
|
package org.diylc.components.transform;
|
||||||
// @Override
|
|
||||||
// public boolean mirroringChangesCircuit() {
|
import java.awt.geom.AffineTransform;
|
||||||
// return true;
|
import java.awt.geom.Point2D;
|
||||||
// }
|
|
||||||
//
|
import org.diylc.common.IComponentTransformer;
|
||||||
// @Override
|
import org.diylc.common.Orientation;
|
||||||
// public void rotate(IDIYComponent<?> component, Point center, int direction) {
|
import org.diylc.components.passive.TrimmerPotentiometer;
|
||||||
// AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.x, center.y);
|
import org.diylc.components.semiconductors.DIL_IC;
|
||||||
// for (int index = 0; index < component.getControlPointCount(); index++) {
|
import org.diylc.core.IDIYComponent;
|
||||||
// Point p = new Point(component.getControlPoint(index));
|
|
||||||
// rotate.transform(p, p);
|
public class TrimmerTransformer implements IComponentTransformer {
|
||||||
// component.setControlPoint(p, index);
|
|
||||||
// }
|
@Override
|
||||||
//
|
public boolean canRotate(IDIYComponent<?> component) {
|
||||||
// TrimmerPotentiometer potentiometer = (TrimmerPotentiometer) component;
|
return component.getClass().equals(TrimmerPotentiometer.class);
|
||||||
// Orientation o = potentiometer.getOrientation();
|
}
|
||||||
// int oValue = o.ordinal();
|
|
||||||
// oValue += direction;
|
@Override
|
||||||
// if (oValue < 0)
|
public boolean canMirror(IDIYComponent<?> component) {
|
||||||
// oValue = Orientation.values().length - 1;
|
return component.getClass().equals(TrimmerPotentiometer.class);
|
||||||
// if (oValue >= Orientation.values().length)
|
}
|
||||||
// oValue = 0;
|
|
||||||
// o = Orientation.values()[oValue];
|
@Override
|
||||||
// potentiometer.setOrientation(o);
|
public boolean mirroringChangesCircuit() {
|
||||||
// }
|
return true;
|
||||||
//
|
}
|
||||||
// @SuppressWarnings("incomplete-switch")
|
|
||||||
// @Override
|
@Override
|
||||||
// public void mirror(IDIYComponent<?> component, Point center, int direction) {
|
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||||
// TrimmerPotentiometer potentiometer = (TrimmerPotentiometer) component;
|
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.getX(), center.getY());
|
||||||
// int dx = center.x - potentiometer.getControlPoint(1).x;
|
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||||
// int dy = center.y - potentiometer.getControlPoint(1).y;
|
Point2D p = new Point2D.Double();
|
||||||
// if (direction == IComponentTransformer.HORIZONTAL) {
|
rotate.transform(component.getControlPoint(index), p);
|
||||||
// Orientation o = potentiometer.getOrientation();
|
component.setControlPoint(p, index);
|
||||||
// switch (o) {
|
}
|
||||||
// case _90:
|
|
||||||
// o = Orientation._270;
|
TrimmerPotentiometer potentiometer = (TrimmerPotentiometer) component;
|
||||||
// break;
|
Orientation o = potentiometer.getOrientation();
|
||||||
// case _270:
|
int oValue = o.ordinal();
|
||||||
// o = Orientation._90;
|
oValue += direction;
|
||||||
// }
|
if (oValue < 0)
|
||||||
//
|
oValue = Orientation.values().length - 1;
|
||||||
// for (int i = 0; i < potentiometer.getControlPointCount(); i++) {
|
if (oValue >= Orientation.values().length)
|
||||||
// Point p = potentiometer.getControlPoint(i);
|
oValue = 0;
|
||||||
// potentiometer
|
o = Orientation.values()[oValue];
|
||||||
// .setControlPoint(
|
potentiometer.setOrientation(o);
|
||||||
// new Point(p.x + 2 * dx, p.y + (potentiometer.getControlPoint(2).y - potentiometer.getControlPoint(0).y)),
|
}
|
||||||
// i);
|
|
||||||
// }
|
@SuppressWarnings("incomplete-switch")
|
||||||
//
|
@Override
|
||||||
// potentiometer.setOrientation(o);
|
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||||
// } else {
|
TrimmerPotentiometer pot = (TrimmerPotentiometer) component;
|
||||||
// Orientation o = potentiometer.getOrientation();
|
|
||||||
// switch (o) {
|
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||||
// case DEFAULT:
|
double dx = 2 * (center.getX() - pot.getControlPoint(0).getX());
|
||||||
// o = Orientation._180;
|
double dy = 0;
|
||||||
// break;
|
Orientation o = pot.getOrientation();
|
||||||
// case _180:
|
switch (o) {
|
||||||
// o = Orientation.DEFAULT;
|
case DEFAULT:
|
||||||
// }
|
o = Orientation._180;
|
||||||
//
|
dy -= pot.getControlPoint(0).getY() - pot.getControlPoint(2).getY();
|
||||||
// for (int i = 0; i < potentiometer.getControlPointCount(); i++) {
|
break;
|
||||||
// Point p = potentiometer.getControlPoint(i);
|
case _90:
|
||||||
// potentiometer
|
dx += (pot.getControlPoint(0).getX() - pot.getControlPoint(2).getX());
|
||||||
// .setControlPoint(new Point(p.x + (potentiometer.getControlPoint(2).x - potentiometer.getControlPoint(0).x),
|
break;
|
||||||
// p.y + 2 * dy), i);
|
case _180:
|
||||||
// }
|
o = Orientation.DEFAULT;
|
||||||
//
|
dy -= pot.getControlPoint(0).getY() - pot.getControlPoint(2).getY();
|
||||||
// potentiometer.setOrientation(o);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user