Ability to rotate 'Lever Switch' and 'Schaller Megaswitch' by any angle

This commit is contained in:
Bane Stojkovic
2022-10-08 20:41:47 +02:00
parent 50d4c1dec1
commit 7878c1fc71
13 changed files with 154 additions and 294 deletions
@@ -0,0 +1,67 @@
/*
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;
import java.awt.Shape;
import org.diylc.common.Orientation;
import org.diylc.core.Angle;
import org.diylc.core.annotations.EditableProperty;
public abstract class AbstractAngledComponent<T> extends AbstractTransparentComponent<T> {
private static final long serialVersionUID = 1L;
@Deprecated
protected transient Orientation orientation;
protected int angle;
transient protected Shape[] body;
protected abstract void updateControlPoints();
@EditableProperty
@SuppressWarnings("incomplete-switch")
public Angle getAngle() {
if (orientation != null) {
switch (orientation) {
case _90:
angle = 90;
break;
case _180:
angle = 180;
break;
case _270:
angle = 270;
break;
}
orientation = null;
}
return Angle.of(angle);
}
public void setAngle(Angle angle) {
this.angle = angle.getValue();
updateControlPoints();
// Reset body shape
body = null;
}
}
+12 -2
View File
@@ -46,7 +46,17 @@ public class Angle {
private static Map<Integer, Angle> valueCache = new HashMap<Integer, Angle>();
public synchronized static Angle of(int angle) {
valueCache.computeIfAbsent(angle, (value) -> new Angle(value));
return valueCache.get(angle);
int newValue = angle;
while (newValue < 0)
newValue += 360;
while (newValue >= 360)
newValue -= 360;
valueCache.computeIfAbsent(newValue, (value) -> new Angle(value));
return valueCache.get(newValue);
}
public Angle rotate(int direction) {
int newValue = value + direction * 90;
return Angle.of(newValue);
}
}
@@ -38,6 +38,7 @@ import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation;
import org.diylc.common.OrientationHV;
import org.diylc.common.PropertyWrapper;
import org.diylc.core.Angle;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
@@ -432,12 +433,10 @@ public class InstantiationManager {
} else if (value instanceof OrientationHV) {
angleProperty.setValue(OrientationHV.values()[(((OrientationHV) value).ordinal() + 1)
% OrientationHV.values().length]);
} else if (angleProperty.getName().equalsIgnoreCase("angle")) {
int angle = (Integer) angleProperty.getValue();
angle += 90;
if (angle >= 360)
angle -= 360;
angleProperty.setValue(angle);
} else if (value instanceof Angle) {
Angle angle = (Angle) angleProperty.getValue();
Angle newAngle = angle.rotate(1);
angleProperty.setValue(newAngle);
}
angleProperty.writeTo(component);
}
@@ -4010,6 +4010,10 @@
<changeType>NEW_FEATURE</changeType>
<description>Added 'DP4T (6-Position Oak Grigsby)' as a new type of Lever Switch component</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Ability to rotate 'Lever Switch' and 'Schaller Megaswitch' by any angle</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Ability to rotate all guitar/bass pickups through the 'Transform Selection' feature or keyboard shortcut</description>