Rotate commands now apply to "Label" and "PCB Text" components

This commit is contained in:
Branislav Stojkovic
2018-12-25 23:47:44 +01:00
parent ce0ac2460c
commit 1268f83f5e
5 changed files with 95 additions and 5 deletions
@@ -32,6 +32,7 @@ import org.diylc.common.HorizontalAlignment;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment; import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractComponent; import org.diylc.components.AbstractComponent;
import org.diylc.components.transform.TextTransformer;
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;
@@ -43,7 +44,7 @@ import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc", @ComponentDescriptor(name = "Label", author = "Branislav Stojkovic", category = "Misc",
description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true, description = "User defined label", instanceNamePrefix = "L", zOrder = IDIYComponent.TEXT, flexibleZOrder = true,
stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
public class Label extends AbstractComponent<String> { public class Label extends AbstractComponent<String> {
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
@@ -33,6 +33,7 @@ import org.diylc.common.HorizontalAlignment;
import org.diylc.common.Orientation; import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment; import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractComponent; import org.diylc.components.AbstractComponent;
import org.diylc.components.transform.TextTransformer;
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;
@@ -44,7 +45,7 @@ import org.diylc.core.annotations.EditableProperty;
@ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc", @ComponentDescriptor(name = "PCB Text", author = "Branislav Stojkovic", category = "Misc",
description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE, description = "Mirrored text for PCB artwork", instanceNamePrefix = "L", zOrder = IDIYComponent.TRACE,
flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW) flexibleZOrder = false, stretchable = false, bomPolicy = BomPolicy.NEVER_SHOW, transformer = TextTransformer.class)
public class PCBText extends AbstractComponent<Void> { public class PCBText extends AbstractComponent<Void> {
public static String DEFAULT_TEXT = "Double click to edit text"; public static String DEFAULT_TEXT = "Double click to edit text";
@@ -0,0 +1,84 @@
/*
*
* 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.Point;
import java.awt.geom.AffineTransform;
import org.diylc.common.IComponentTransformer;
import org.diylc.common.Orientation;
import org.diylc.components.misc.Label;
import org.diylc.components.misc.PCBText;
import org.diylc.core.IDIYComponent;
public class TextTransformer implements IComponentTransformer {
@Override
public boolean canRotate(IDIYComponent<?> component) {
return component.getClass().equals(Label.class) || component.getClass().equals(PCBText.class);
}
@Override
public boolean canMirror(IDIYComponent<?> component) {
return false;
}
@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);
}
if (component instanceof Label) {
Label snap = (Label) 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);
} else if (component instanceof PCBText) {
PCBText snap = (PCBText) 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) {
throw new RuntimeException("Unexpected call to mirror() in LabelTransformer");
}
}
Binary file not shown.
+5 -1
View File
@@ -2040,7 +2040,7 @@
<changes> <changes>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Vastly improve performance of selection aree calculations, especially with bigger layouts</description> <description>Faster click and popup menu response due to improved performance of selection area calculations, especially with bigger layouts</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
@@ -2050,6 +2050,10 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Better error handing in V2 file importer</description> <description>Better error handing in V2 file importer</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Rotate commands now apply to "Label" and "PCB Text" components</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>Clicking on a building block in the component tree sometimes makes the components go back to the top-left corner of the layout</description> <description>Clicking on a building block in the component tree sometimes makes the components go back to the top-left corner of the layout</description>