mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Rotating 'Neutrik Jack' produces rendering issues
This commit is contained in:
@@ -41,7 +41,7 @@ import org.diylc.common.ObjectCache;
|
||||
import org.diylc.common.Orientation;
|
||||
import org.diylc.common.VerticalAlignment;
|
||||
import org.diylc.components.AbstractMultiPartComponent;
|
||||
import org.diylc.components.transform.CliffJackTransformer;
|
||||
import org.diylc.components.transform.NeutrikJack1_4Transformer;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -56,7 +56,7 @@ import org.diylc.utils.Constants;
|
||||
|
||||
@ComponentDescriptor(name = "Neutrik 1/4\" Jack", category = "Electro-Mechanical", author = "Branislav Stojkovic",
|
||||
description = "1/4\" mono/stereo phono jack based on Neutrik NMJx series, PCB or Panel-mount",
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = CliffJackTransformer.class,
|
||||
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "J", autoEdit = false, transformer = NeutrikJack1_4Transformer.class,
|
||||
enableCache = true)
|
||||
public class NeutrikJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
|
||||
@@ -144,9 +144,11 @@ public class NeutrikJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
// Create body.
|
||||
int bodyLength = (int) BODY_LENGTH.convertToPixels();
|
||||
int bodyWidth = (int) BODY_WIDTH.convertToPixels();
|
||||
int offset = (int)(type == JackType.MONO ? PIN_OFFSET_MONO : PIN_OFFSET_STEREO).convertToPixels();
|
||||
double centerX = controlPoints[3].getX() + offset;
|
||||
double centerY = (controlPoints[0].getY() + controlPoints[3].getY()) / 2;
|
||||
int offset = (int)(type == JackType.MONO ? PIN_OFFSET_MONO : PIN_OFFSET_STEREO).convertToPixels();
|
||||
int xSpacing = (int) X_SPACING.convertToPixels();
|
||||
int ySpacing = (int) Y_SPACING.convertToPixels();
|
||||
double centerX = controlPoints[0].getX() + 2 * xSpacing + offset;
|
||||
double centerY = controlPoints[0].getY() + ySpacing / 2;
|
||||
body[0] = new Area(new Rectangle2D.Double(centerX - bodyLength / 2, centerY - bodyWidth / 2, bodyLength, bodyWidth));
|
||||
|
||||
int tailLength = (int) TAIL_LENGTH.convertToPixels();
|
||||
@@ -167,7 +169,7 @@ public class NeutrikJack1_4 extends AbstractMultiPartComponent<String> {
|
||||
// Apply rotation if necessary
|
||||
double angle = getAngle();
|
||||
if (angle != 0) {
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(angle, centerX, centerY);
|
||||
AffineTransform rotation = AffineTransform.getRotateInstance(angle, controlPoints[0].getX(), controlPoints[0].getY());
|
||||
for (int i = 0; i < body.length; i++) {
|
||||
if (body[i] != null) {
|
||||
Area area = new Area(body[i]);
|
||||
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
|
||||
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.electromechanical.NeutrikJack1_4;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class NeutrikJack1_4Transformer implements IComponentTransformer {
|
||||
|
||||
@Override
|
||||
public boolean canRotate(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(NeutrikJack1_4.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMirror(IDIYComponent<?> component) {
|
||||
return component.getClass().equals(NeutrikJack1_4.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);
|
||||
}
|
||||
|
||||
NeutrikJack1_4 jack = (NeutrikJack1_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, Point2D center, int direction) {
|
||||
NeutrikJack1_4 ic = (NeutrikJack1_4) component;
|
||||
|
||||
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||
double dx = 2 * (center.getX() - ic.getControlPoint(1).getX());
|
||||
double dy = 0;
|
||||
|
||||
Orientation o = ic.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
dy += (ic.getControlPoint(0).getY() - ic.getControlPoint(ic.getControlPointCount() - 1).getY());
|
||||
o = Orientation._180;
|
||||
break;
|
||||
case _90:
|
||||
// dy += ic.getControlPoint(0).getY() - ic.getControlPoint(ic.getControlPointCount() - 1).getY();
|
||||
break;
|
||||
case _180:
|
||||
dy += (ic.getControlPoint(0).getY() - ic.getControlPoint(ic.getControlPointCount() - 1).getY());
|
||||
o = Orientation.DEFAULT;
|
||||
break;
|
||||
case _270:
|
||||
// dy += ic.getControlPoint(0).getY() - ic.getControlPoint(ic.getControlPointCount() - 1).getY();
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ic.getControlPointCount(); i++) {
|
||||
Point2D p = ic.getControlPoint(i);
|
||||
ic.setControlPoint(new Point2D.Double(p.getX() + dx, p.getY() + dy), i);
|
||||
}
|
||||
|
||||
ic.setOrientation(o);
|
||||
} else {
|
||||
double dx = 0;
|
||||
double dy = 2 * (center.getY() - ic.getControlPoint(1).getY());
|
||||
|
||||
Orientation o = ic.getOrientation();
|
||||
switch (o) {
|
||||
case DEFAULT:
|
||||
// dx += ic.getControlPoint(0).getX() - ic.getControlPoint(ic.getControlPointCount() - 1).getX();
|
||||
break;
|
||||
case _90:
|
||||
o = Orientation._270;
|
||||
// dx -= 2 * (ic.getControlPoint(0).getX() - ic.getControlPoint(1).getX());
|
||||
// dy -= ic.getControlPoint(0).getY() - ic.getControlPoint(ic.getControlPointCount() - 1).getY();
|
||||
break;
|
||||
case _180:
|
||||
// dx += ic.getControlPoint(0).getX() - ic.getControlPoint(ic.getControlPointCount() - 1).getX();
|
||||
break;
|
||||
case _270:
|
||||
// dx -= 2 * (ic.getControlPoint(0).getX() - ic.getControlPoint(1).getX());
|
||||
// dy -= ic.getControlPoint(0).getY() - ic.getControlPoint(ic.getControlPointCount() - 1).getY();
|
||||
o = Orientation._90;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ic.getControlPointCount(); i++) {
|
||||
Point2D p = ic.getControlPoint(i);
|
||||
ic.setControlPoint(new Point2D.Double(p.getX() + dx, p.getY() + dy), i);
|
||||
}
|
||||
|
||||
ic.setOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user