mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Allow rotate and mirror actions on Pin Header component
This commit is contained in:
@@ -3185,6 +3185,10 @@
|
|||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>On MacOS the app registers to open .DIY files</description>
|
<description>On MacOS the app registers to open .DIY files</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Allow rotate and mirror actions on Pin Header component</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ 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.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
|
import org.diylc.components.transform.PinHeaderTransformer;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.IDrawingObserver;
|
import org.diylc.core.IDrawingObserver;
|
||||||
@@ -50,7 +51,7 @@ import org.diylc.utils.Constants;
|
|||||||
|
|
||||||
@ComponentDescriptor(name = "Pin Header", author = "Branislav Stojkovic", category = "Electro-Mechanical",
|
@ComponentDescriptor(name = "Pin Header", author = "Branislav Stojkovic", category = "Electro-Mechanical",
|
||||||
instanceNamePrefix = "PH", description = "PCB mount male pin header with editable number or pins and pin spacing",
|
instanceNamePrefix = "PH", description = "PCB mount male pin header with editable number or pins and pin spacing",
|
||||||
zOrder = IDIYComponent.COMPONENT, enableCache = true)
|
zOrder = IDIYComponent.COMPONENT, enableCache = true, transformer = PinHeaderTransformer.class)
|
||||||
public class PinHeader extends AbstractTransparentComponent<Void> {
|
public class PinHeader extends AbstractTransparentComponent<Void> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -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.PinHeader;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
|
public class PinHeaderTransformer implements IComponentTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRotate(IDIYComponent<?> component) {
|
||||||
|
return component.getClass().equals(PinHeader.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canMirror(IDIYComponent<?> component) {
|
||||||
|
return component.getClass().equals(PinHeader.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mirroringChangesCircuit() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
PinHeader header = (PinHeader) component;
|
||||||
|
Orientation o = header.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];
|
||||||
|
header.setOrientation(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||||
|
PinHeader header = (PinHeader) component;
|
||||||
|
|
||||||
|
if (direction == IComponentTransformer.HORIZONTAL) {
|
||||||
|
double dx = 2 * (center.getX() - header.getControlPoint(1).getX());
|
||||||
|
double dy = 0;
|
||||||
|
Orientation o = header.getOrientation();
|
||||||
|
switch (o) {
|
||||||
|
case DEFAULT:
|
||||||
|
dx += header.getControlPoint(0).getX() - header.getControlPoint(header.getControlPointCount() - 1).getX();
|
||||||
|
break;
|
||||||
|
case _90:
|
||||||
|
o = Orientation._270;
|
||||||
|
dx -= 2 * (header.getControlPoint(0).getX() - header.getControlPoint(1).getX());
|
||||||
|
dy -= header.getControlPoint(0).getY() - header.getControlPoint(header.getControlPointCount() - 1).getY();
|
||||||
|
break;
|
||||||
|
case _180:
|
||||||
|
dx += header.getControlPoint(0).getX() - header.getControlPoint(header.getControlPointCount() - 1).getX();
|
||||||
|
break;
|
||||||
|
case _270:
|
||||||
|
dx -= 2 * (header.getControlPoint(0).getX() - header.getControlPoint(1).getX());
|
||||||
|
dy -= header.getControlPoint(0).getY() - header.getControlPoint(header.getControlPointCount() - 1).getY();
|
||||||
|
o = Orientation._90;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < header.getControlPointCount(); i++) {
|
||||||
|
Point2D p = header.getControlPoint(i);
|
||||||
|
header.setControlPoint(new Point2D.Double(p.getX() + dx, p.getY() + dy), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
header.setOrientation(o);
|
||||||
|
} else {
|
||||||
|
double dx = 0;
|
||||||
|
double dy = 2 * (center.getY() - header.getControlPoint(1).getY());
|
||||||
|
Orientation o = header.getOrientation();
|
||||||
|
switch (o) {
|
||||||
|
case DEFAULT:
|
||||||
|
dx -= header.getControlPoint(0).getX() - header.getControlPoint(header.getControlPointCount() - 1).getX();
|
||||||
|
dy -= 2 * (header.getControlPoint(0).getY() - header.getControlPoint(1).getY());
|
||||||
|
o = Orientation._180;
|
||||||
|
break;
|
||||||
|
case _90:
|
||||||
|
dy += header.getControlPoint(0).getY() - header.getControlPoint(header.getControlPointCount() - 1).getY();
|
||||||
|
break;
|
||||||
|
case _180:
|
||||||
|
dx -= header.getControlPoint(0).getX() - header.getControlPoint(header.getControlPointCount() - 1).getX();
|
||||||
|
dy -= 2 * (header.getControlPoint(0).getY() - header.getControlPoint(1).getY());
|
||||||
|
o = Orientation.DEFAULT;
|
||||||
|
break;
|
||||||
|
case _270:
|
||||||
|
dy += header.getControlPoint(0).getY() - header.getControlPoint(header.getControlPointCount() - 1).getY();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < header.getControlPointCount(); i++) {
|
||||||
|
Point2D p = header.getControlPoint(i);
|
||||||
|
header.setControlPoint(new Point2D.Double(p.getX() + dx, p.getY() + dy), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
header.setOrientation(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user