Added Schaller Megaswitch, standardized colors of FR4

This commit is contained in:
Bane Stojkovic
2022-10-04 13:44:48 +02:00
parent ad8c624efb
commit 40e1935e3f
11 changed files with 850 additions and 5 deletions
@@ -57,8 +57,11 @@ public abstract class AbstractComponent<T> implements IDIYComponent<T> {
public static Font LABEL_FONT = new Font("Square721 BT", Font.PLAIN, 14);
public static Color METAL_COLOR = Color.decode("#759DAF");
public static Color LIGHT_METAL_COLOR = Color.decode("#EEEEEE");
public static Color COPPER_COLOR = Color.decode("#DA8A67");
public static Color COPPER_COLOR = Color.decode("#DA8A67");
public static Color GOLD_COLOR = Color.decode("#DAA520");
public static Color FR4_COLOR = Color.decode("#6B9B6B");
public static Color FR4_LIGHT_COLOR = Color.decode("#BABE71");
@EditableProperty(defaultable = false)
@Override
public String getName() {
@@ -48,7 +48,7 @@ public enum IconLoader {
"plugin.png"), Manual("manual.png"), Donate("donate.png"), Bug("bug.png"), IconLarge("icon_large.png"), IconMedium(
"icon_medium.png"), IconSmall("icon_small.png"), DocumentEdit("document_edit.png"), EditComponent(
"edit_component.png"), Size("size.png"), Front("front.png"), Back("back.png"), Pens("pens.png"), Sort("sort.png"), ElementsSelection(
"elements_selection.png");
"elements_selection.png"), Schaller("schaller.png");
protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

@@ -3965,5 +3965,25 @@
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>4</major>
<minor>29</minor>
<build>0</build>
</versionNumber>
<releaseDate>2022-09-25 00:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added 6 variations of Schaller Megaswitch</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Added 'DP3T (Import 5-Position Strat)' type of lever switch</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a>
</java.util.Arrays_-ArrayList>
Binary file not shown.
@@ -58,7 +58,7 @@ public class EurorackStripboard extends AbstractProtoBoard {
private static final long serialVersionUID = 1L;
public static Color FILL_COLOR = Color.decode("#6B9B6B");
public static Color FILL_COLOR = FR4_COLOR;
public static Size SPACING = new Size(0.1d, SizeUnit.in);
public static Size CORNER_RADIUS = new Size(0.1d, SizeUnit.in);
public static Color SELECTION_COLOR = Color.red;
@@ -47,7 +47,7 @@ public class EyeletBoard extends AbstractBoard {
private static final long serialVersionUID = 1L;
public static Color BOARD_COLOR = Color.decode("#E3EAB4");
public static Color BOARD_COLOR = FR4_LIGHT_COLOR;
public static Color BORDER_COLOR = BOARD_COLOR.darker();
public static Color EYELET_COLOR = Color.decode("#C3E4ED");
@@ -0,0 +1,740 @@
/*
*
* 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.guitar;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.util.Arrays;
import java.util.List;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.awt.StringUtils;
import org.diylc.common.HorizontalAlignment;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.common.VerticalAlignment;
import org.diylc.components.AbstractTransparentComponent;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.ISwitch;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.KeywordPolicy;
import org.diylc.core.images.IconLoader;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
@ComponentDescriptor(name = "Schaller Megaswitch", category = "Guitar",
author = "Branislav Stojkovic", description = "Several variations of Schaller Megaswitch",
zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW",
keywordPolicy = KeywordPolicy.SHOW_TAG, keywordTag = "Guitar Wiring Diagram")
public class SchallerMegaSwitch extends AbstractTransparentComponent<String> implements ISwitch {
private static final long serialVersionUID = 1L;
private static Color BASE_COLOR = Color.lightGray;
private static Color WAFER_COLOR = FR4_LIGHT_COLOR;
private static Color LUG_COLOR = GOLD_COLOR;
private static Size BASE_WIDTH = new Size(10d, SizeUnit.mm);
private static Size BASE_LENGTH = new Size(47.5d, SizeUnit.mm);
private static Size WAFER_LENGTH = new Size(40d, SizeUnit.mm);
private static Size WAFER_THICKNESS = new Size(1.27d, SizeUnit.mm);
private static Size HOLE_SIZE = new Size(2d, SizeUnit.mm);
private static Size HOLE_SPACING = new Size(41.2d, SizeUnit.mm);
private static Size TERMINAL_WIDTH = new Size(2d, SizeUnit.mm);
// private static Size TERMINAL_LENGTH = new Size(2d, SizeUnit.mm);
private static Size TERMINAL_SPACING = new Size(0.1d, SizeUnit.in);
// public static float LABEL_FONT_SIZE = 10f;
public static Size LABEL_OFFSET = new Size(0.1d, SizeUnit.in);
private String value = "";
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
transient Shape[] body;
private Orientation orientation = Orientation.DEFAULT;
private MegaSwitchType type = MegaSwitchType.E;
private Color labelColor = Color.gray;
private transient Double labelDx = null;
private transient Double labelDy = null;
public SchallerMegaSwitch() {
super();
updateControlPoints();
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
Project project, IDrawingObserver drawingObserver) {
Shape[] body = getBody();
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
if (componentState != ComponentState.DRAGGING) {
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BASE_COLOR);
g2d.fill(body[0]);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : WAFER_COLOR);
g2d.fill(body[1]);
g2d.setComposite(oldComposite);
}
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: BASE_COLOR.darker();
}
g2d.setColor(finalBorderColor);
g2d.draw(body[0]);
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: theme.getOutlineColor();
} else {
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? SELECTION_COLOR
: WAFER_COLOR.darker();
}
g2d.draw(body[1]);
g2d.setColor(LUG_COLOR);
g2d.fill(body[2]);
g2d.setColor(LUG_COLOR.darker());
g2d.draw(body[2]);
// g2d.setColor(Color.black);
// for(int i = 0; i < getControlPointCount(); i++) {
// g2d.drawString(i + "", controlPoints[i].getX(), controlPoints[i].getY());
// }
g2d.setColor(labelColor);
// g2d.setFont(project.getFont().deriveFont(LABEL_FONT_SIZE));
if (type == MegaSwitchType.M) {
for (int i = 0; i < controlPoints.length; i++) {
double dx = getLabelDx();
double dy = getLabelDy();
if (i >= controlPoints.length / 2) {
dx = -dx;
dy = -dy;
}
StringUtils.drawCenteredText(g2d, getControlPointNodeName(i), controlPoints[i].getX() + dx,
controlPoints[i].getY() + dy, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
}
} else {
for (int i = 0; i < controlPoints.length; i++) {
StringUtils.drawCenteredText(g2d, getControlPointNodeName(i),
controlPoints[i].getX() + getLabelDx(), controlPoints[i].getY() + getLabelDy(),
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
}
}
int lastPointIdx =
type == MegaSwitchType.M ? controlPoints.length / 2 - 1 : controlPoints.length - 1;
double x =
(controlPoints[0].getX() + controlPoints[lastPointIdx].getX()) / 2 + getLabelDx() * 2.25;
double y =
(controlPoints[0].getY() + controlPoints[lastPointIdx].getY()) / 2 + getLabelDy() * 2.25;
double theta = 0;
switch (orientation) {
case DEFAULT:
case _180:
theta = -Math.PI / 2;
break;
case _90:
case _270:
theta = 0;
break;
}
g2d.rotate(theta, x, y);
g2d.setFont(project.getFont().deriveFont((float) (project.getFont().getSize2D() * 1.25)));
StringUtils.drawCenteredText(g2d, "Schaller Megaswitch® " + type.toString(), x, y,
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
}
@SuppressWarnings("incomplete-switch")
public Shape[] getBody() {
if (body == null) {
body = new Shape[4];
int lastPointIdx =
type == MegaSwitchType.M ? controlPoints.length / 2 - 1 : controlPoints.length - 1;
double x = (controlPoints[0].getX() + controlPoints[lastPointIdx].getX()) / 2;
double y = (controlPoints[0].getY() + controlPoints[lastPointIdx].getY()) / 2;
int baseWidth = (int) BASE_WIDTH.convertToPixels();
int baseLength = (int) BASE_LENGTH.convertToPixels();
int holeSize = getClosestOdd(HOLE_SIZE.convertToPixels());
int holeSpacing = (int) HOLE_SPACING.convertToPixels();
int waferLength = (int) WAFER_LENGTH.convertToPixels();
int waferThickness = (int) WAFER_THICKNESS.convertToPixels();
int terminalSize = getClosestOdd(TERMINAL_WIDTH.convertToPixels());
int yOffset = controlPoints.length;
if (yOffset > 12) {
yOffset /= 2;
}
int xOffset = 0;
if (type == MegaSwitchType.M) {
xOffset = terminalSize + waferThickness / 4;
}
double baseX = x - terminalSize / 2 - baseWidth + waferThickness / 2 + xOffset;
double baseY = y - baseLength / 2;
Area baseArea = new Area(new Rectangle2D.Double(baseX, baseY, baseWidth, baseLength));
baseArea.subtract(new Area(new Ellipse2D.Double(baseX + baseWidth / 2 - holeSize / 2,
baseY + (baseLength - holeSpacing) / 2 - holeSize / 2, holeSize, holeSize)));
baseArea.subtract(new Area(new Ellipse2D.Double(baseX + baseWidth / 2 - holeSize / 2,
baseY + (baseLength - holeSpacing) / 2 - holeSize / 2 + holeSpacing, holeSize,
holeSize)));
body[0] = baseArea;
double waferX = x + xOffset - terminalSize / 2 - waferThickness / 2;
double waferY = y - waferLength / 2;
Area waferArea =
new Area(new Rectangle2D.Double(waferX, waferY, waferThickness, waferLength));
body[1] = waferArea;
double theta = 0;
// Rotate if needed
if (orientation != Orientation.DEFAULT) {
switch (orientation) {
case _90:
theta = Math.PI / 2;
break;
case _180:
theta = Math.PI;
break;
case _270:
theta = Math.PI * 3 / 2;
break;
}
}
Area terminalArea = new Area();
for (int i = 0; i < controlPoints.length; i++) {
Point2D point = controlPoints[i];
Area terminal = new Area(new RoundRectangle2D.Double(point.getX() - terminalSize / 2,
point.getY() - terminalSize / 2, terminalSize, terminalSize, terminalSize / 2,
terminalSize / 2));
terminal.subtract(new Area(new RoundRectangle2D.Double(point.getX() - terminalSize / 4,
point.getY() - terminalSize / 4, terminalSize / 2, terminalSize / 2, terminalSize / 2,
terminalSize / 2)));
terminalArea.add(terminal);
}
body[2] = terminalArea;
// Rotate if needed
if (theta != 0) {
// Skip the last two because terminals are already rotated
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
for (int i = 0; i < body.length - 2; i++) {
Shape shape = body[i];
Area area = (Area) shape;
area.transform(rotation);
}
}
}
return body;
}
@SuppressWarnings("incomplete-switch")
private void updateControlPoints() {
double x = controlPoints[0].getX();
double y = controlPoints[0].getY();
double terminalSpacing = TERMINAL_SPACING.convertToPixels();
double terminalWidth = TERMINAL_WIDTH.convertToPixels();
int waferThickness = (int) WAFER_THICKNESS.convertToPixels();
int pointCount = 0;
switch (type) {
case E:
case P:
pointCount = 7;
break;
case E_PLUS:
pointCount = 9;
break;
case S:
case T:
pointCount = 8;
break;
case M:
pointCount = 24;
break;
}
controlPoints = new Point2D[pointCount];
if (pointCount < 12) {
terminalSpacing *= 1.5;
for (int i = 0; i < controlPoints.length; i++) {
controlPoints[i] = new Point2D.Double(x, y - i * terminalSpacing);;
}
} else {
for (int i = 0; i < controlPoints.length / 2; i++) {
controlPoints[i] = new Point2D.Double(x, y - i * terminalSpacing);
controlPoints[controlPoints.length - i - 1] =
new Point2D.Double(x + terminalWidth + waferThickness / 2, y - i * terminalSpacing);
}
}
// Rotate if needed
if (orientation != Orientation.DEFAULT) {
double theta = 0;
switch (orientation) {
case _90:
theta = Math.PI / 2;
break;
case _180:
theta = Math.PI;
break;
case _270:
theta = Math.PI * 3 / 2;
break;
}
AffineTransform rotation = AffineTransform.getRotateInstance(theta, x, y);
for (Point2D point : controlPoints) {
rotation.transform(point, point);
}
}
}
private void updateLabelPositions() {
double labelOffset = LABEL_OFFSET.convertToPixels();
switch (orientation) {
case DEFAULT:
labelDx = -labelOffset;
labelDy = 0d;
break;
case _90:
labelDx = 0d;
labelDy = -labelOffset;
break;
case _180:
labelDx = labelOffset;
labelDy = 0d;
break;
case _270:
labelDx = 0d;
labelDy = labelOffset;
break;
}
}
private double getLabelDx() {
if (labelDx == null) {
updateLabelPositions();
}
return labelDx;
}
public double getLabelDy() {
if (labelDy == null ) {
updateLabelPositions();
}
return labelDy;
}
@Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setClip(width / 32, width / 32, width, height);
g2d.setColor(BASE_COLOR);
g2d.fillRect(0, 0, width * 3 / 4, height);
g2d.setColor(BASE_COLOR.darker());
g2d.drawRect(0, 0, width * 3 / 4, height);
g2d.setColor(WAFER_COLOR);
g2d.fillRect(width / 8 * 4, 0, width / 8, height);
g2d.setColor(WAFER_COLOR.darker());
g2d.drawRect(width / 8 * 4, 0, width / 8, height);
Area terminals = new Area();
int terminalLength = getClosestOdd(7 * width / 32);
int terminalWidth = getClosestOdd(7 * width / 32);
Area terminal = new Area(new RoundRectangle2D.Double(width / 16 * 9, 4 * width / 32,
terminalLength, terminalWidth, terminalWidth / 2, terminalWidth / 2));
terminal.subtract(new Area(new RoundRectangle2D.Double(width / 16 * 9 + terminalLength / 4 + 1,
4 * width / 32 + terminalWidth / 4 + 1, terminalLength / 2, terminalWidth / 2,
terminalWidth / 4, terminalWidth / 4)));
terminals.add(terminal);
terminal = new Area(terminal);
terminal.transform(AffineTransform.getTranslateInstance(0, terminalWidth + 2 * width / 32));
terminals.add(terminal);
terminal = new Area(terminal);
terminal.transform(AffineTransform.getTranslateInstance(0, terminalWidth + 2 * width / 32));
terminals.add(terminal);
g2d.setColor(LUG_COLOR);
g2d.fill(terminals);
g2d.setColor(LUG_COLOR.darker());
g2d.draw(terminals);
Image logo = IconLoader.Schaller.getImage();
g2d.drawImage(logo, 2, (int) (6.0 * width / 32), null);
}
@Override
public int getControlPointCount() {
return controlPoints.length;
}
@Override
public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
return VisibilityPolicy.NEVER;
}
@Override
public boolean isControlPointSticky(int index) {
return true;
}
@Override
public Point2D getControlPoint(int index) {
return controlPoints[index];
}
@Override
public void setControlPoint(Point2D point, int index) {
this.controlPoints[index].setLocation(point);
// Invalidate the body
body = null;
}
@Override
public String getValue() {
return value;
}
@Override
public void setValue(String value) {
this.value = value;
}
// @EditableProperty(name = "Label")
public Color getLabelColor() {
return labelColor;
}
public void setLabelColor(Color labelColor) {
this.labelColor = labelColor;
}
@EditableProperty
public Orientation getOrientation() {
return orientation;
}
@EditableProperty
public MegaSwitchType getType() {
return type;
}
public void setType(MegaSwitchType type) {
this.type = type;
updateControlPoints();
// Invalidate body
this.body = null;
}
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
updateControlPoints();
updateLabelPositions();
// Invalidate the body
body = null;
}
public enum MegaSwitchType {
E("E"), E_PLUS("E+"), M("M"), P("P"), S("S"), T("T");
private String title;
private MegaSwitchType(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}
// @Override
// public String getControlPointNodeName(int index) {
// // we don't want the switch to produce any nodes, it just makes connections
// return null;
// }
// switch stuff
@Override
public int getPositionCount() {
if (type == MegaSwitchType.T) {
return 3;
}
return 5;
}
@Override
public String getPositionName(int position) {
return Integer.toString(position + 1);
}
@Override
public boolean arePointsConnected(int index1, int index2, int position) {
List<List<int[]>> connections = null;
switch (type) {
case E:
connections = E_CONNECTIONS;
break;
case E_PLUS:
connections = E_PLUS_CONNECTIONS;
break;
case S:
connections = S_CONNECTIONS;
break;
case P:
connections = P_CONNECTIONS;
break;
case T:
connections = T_CONNECTIONS;
break;
case M:
connections = M_CONNECTIONS;
break;
}
if (connections != null) {
List<int[]> positionConnections = connections.get(position);
for (int[] arr : positionConnections) {
if (arr[0] == index1 && arr[1] == index2) {
return true;
}
}
}
return false;
}
@Override
public String getControlPointNodeName(int index) {
if (type == MegaSwitchType.M) {
return String.valueOf((char) (index + 'A'));
}
return Integer.toString(index + 1);
}
@Override
public boolean canPointMoveFreely(int pointIndex) {
return false;
}
private static final List<List<int[]>> E_CONNECTIONS = Arrays.asList(
Arrays.asList(
new int[] { 2, 6 }
), // position 1
Arrays.asList(
new int[] { 0, 2 },
new int[] { 2, 6 },
new int[] { 3, 5 }
), // position 2
Arrays.asList(
new int[] { 3, 4 },
new int[] { 1, 2 },
new int[] { 2, 5 }
), // position 3
Arrays.asList(
new int[] { 3, 4 },
new int[] { 0, 2 },
new int[] { 1, 2 }
), // position 4
Arrays.asList(
new int[] { 1, 2 }
) // position 5
);
private static final List<List<int[]>> E_PLUS_CONNECTIONS = Arrays.asList(
Arrays.asList(
new int[] { 2, 8 }
), // position 1
Arrays.asList(
new int[] { 3, 6 },
new int[] { 2, 8 },
new int[] { 0, 2 }
), // position 2
Arrays.asList(
new int[] { 3, 5 },
new int[] { 2, 7 },
new int[] { 1, 2 }
), // position 3
Arrays.asList(
new int[] { 3, 4 },
new int[] { 0, 2 },
new int[] { 1, 2 }
), // position 4
Arrays.asList(
new int[] { 1, 2 }
) // position 5
);
private static final List<List<int[]>> S_CONNECTIONS = Arrays.asList(
Arrays.asList(
new int[] { 2, 3 },
new int[] { 6, 7 }
), // position 1
Arrays.asList(
new int[] { 2, 3 },
new int[] { 0, 3 },
new int[] { 6, 7 },
new int[] { 4, 7 }
), // position 2
Arrays.asList(
new int[] { 0, 3 },
new int[] { 4, 7 }
), // position 3
Arrays.asList(
new int[] { 1, 3 },
new int[] { 0, 3 },
new int[] { 5, 7 },
new int[] { 4, 7 }
), // position 4
Arrays.asList(
new int[] { 1, 3 },
new int[] { 5, 7 }
) // position 5
);
private static final List<List<int[]>> P_CONNECTIONS = Arrays.asList(
Arrays.asList(
new int[] { 1, 6 },
new int[] { 3, 4 }
), // position 1
Arrays.asList(
new int[] { 1, 5 },
new int[] { 0, 4 },
new int[] { 1, 2 },
new int[] { 3, 4 }
), // position 2
Arrays.asList(
new int[] { 1, 6 },
new int[] { 0, 2 }
), // position 3
Arrays.asList(
new int[] { 1, 6 },
new int[] { 0, 1 },
new int[] { 2, 4 },
new int[] { 3, 4 }
), // position 4
Arrays.asList(
new int[] { 1, 5 }
) // position 5
);
private static final List<List<int[]>> T_CONNECTIONS = Arrays.asList(
Arrays.asList(
new int[] { 2, 3 },
new int[] { 6, 7 }
), // position 1
Arrays.asList(
new int[] { 0, 3 },
new int[] { 4, 7 }
), // position 2
Arrays.asList(
new int[] { 1, 3 },
new int[] { 5, 7 }
) // position 3
);
private static final List<List<int[]>> M_CONNECTIONS = Arrays.asList(
Arrays.asList(
new int[] { 4, 5 },
new int[] { 10, 11 },
new int[] { 16, 17 },
new int[] { 22, 23 }
), // position 1
Arrays.asList(
new int[] { 3, 5 },
new int[] { 9, 11 },
new int[] { 15, 17 },
new int[] { 21, 23 }
), // position 2
Arrays.asList(
new int[] { 2, 5 },
new int[] { 8, 11 },
new int[] { 14, 17 },
new int[] { 20, 23 }
), // position 3
Arrays.asList(
new int[] { 1, 5 },
new int[] { 7, 11 },
new int[] { 13, 17 },
new int[] { 19, 23 }
), // position 4
Arrays.asList(
new int[] { 0, 5 },
new int[] { 6, 11 },
new int[] { 12, 17 },
new int[] { 18, 23 }
) // position 5
);
}
@@ -10,6 +10,8 @@ import org.diylc.components.electromechanical.ToggleSwitchType;
import org.diylc.components.guitar.LPSwitch;
import org.diylc.components.guitar.LeverSwitch;
import org.diylc.components.guitar.LeverSwitch.LeverSwitchType;
import org.diylc.components.guitar.SchallerMegaSwitch;
import org.diylc.components.guitar.SchallerMegaSwitch.MegaSwitchType;
import org.diylc.core.IDIYComponent;
import org.diylc.core.ISwitch;
import org.junit.Test;
@@ -37,6 +39,17 @@ public class SwitchTests {
leverSwitch.setType(LeverSwitchType._4P5T);
testSwitch(leverSwitch, validCombinations);
}
@Test
public void testLeverSwitchImport() {
LeverSwitch leverSwitch = new LeverSwitch();
String[] validCombinations = new String[] {"0,0,3", "0,4,5", "1,0,3", "1,4,5", "1,1,3",
"1,4,6", "2,1,3", "2,4,6", "3,1,3", "3,2,3", "3,4,6", "3,4,7", "4,2,3", "4,4,7"};
leverSwitch.setType(LeverSwitchType.DP3T_5pos_Import);
testSwitch(leverSwitch, validCombinations);
}
@Test
public void testLPSwitch() {
@@ -84,6 +97,75 @@ public class SwitchTests {
String[] validCombinations = new String[] {"0,0,1", "0,3,4", "1,1,2", "1,3,4", "2,1,2", "2,4,5"};
testSwitch(toggleSwitch, validCombinations);
}
@Test
public void testMegaSwitchE() {
SchallerMegaSwitch sw = new SchallerMegaSwitch();
sw.setType(MegaSwitchType.E);
String[] validCombinations = new String[] {"0,2,6", "1,3,5", "1,2,6", "1,0,2", "2,3,4",
"2,2,5", "2,1,2", "3,3,4", "3,0,2", "3,1,2", "4,1,2"};
testSwitch(sw, validCombinations);
}
@Test
public void testMegaSwitchEPlus() {
SchallerMegaSwitch sw = new SchallerMegaSwitch();
sw.setType(MegaSwitchType.E_PLUS);
String[] validCombinations = new String[] {"0,2,8", "1,3,6", "1,2,8", "1,0,2", "2,3,5",
"2,2,7", "2,1,2", "3,3,4", "3,0,2", "3,1,2", "4,1,2"};
testSwitch(sw, validCombinations);
}
@Test
public void testMegaSwitchP() {
SchallerMegaSwitch sw = new SchallerMegaSwitch();
sw.setType(MegaSwitchType.P);
String[] validCombinations = new String[] {"0,3,4", "0,1,6", "1,3,4", "1,1,2", "1,0,4", "1,1,5",
"2,0,2", "2,1,6", "3,0,1", "3,3,4", "3,2,4", "3,1,6", "4,1,5"};
testSwitch(sw, validCombinations);
}
@Test
public void testMegaSwitchS() {
SchallerMegaSwitch sw = new SchallerMegaSwitch();
sw.setType(MegaSwitchType.S);
String[] validCombinations = new String[] {"0,6,7", "0,2,3", "1,4,7", "1,6,7", "1,0,3", "1,2,3",
"2,4,7", "2,0,3", "3,4,7", "3,5,7", "3,0,3", "3,1,3", "4,5,7", "4,1,3"};
testSwitch(sw, validCombinations);
}
@Test
public void testMegaSwitchM() {
SchallerMegaSwitch sw = new SchallerMegaSwitch();
sw.setType(MegaSwitchType.M);
String[] validCombinations = new String[] {"0,4,5", "0,10,11", "0,16,17", "0,22,23",
"1,3,5", "1,9,11", "1,15,17", "1,21,23",
"2,2,5", "2,8,11", "2,14,17", "2,20,23",
"3,1,5", "3,7,11", "3,13,17", "3,19,23",
"4,0,5", "4,6,11", "4,12,17", "4,18,23"};
testSwitch(sw, validCombinations);
}
@Test
public void testMegaSwitchT() {
SchallerMegaSwitch sw = new SchallerMegaSwitch();
sw.setType(MegaSwitchType.T);
String[] validCombinations = new String[] {"0,6,7", "0,2,3", "1,4,7", "1,0,3",
"2,5,7", "2,1,3"};
testSwitch(sw, validCombinations);
}
private void testSwitch(ISwitch sw, String[] validCombinations) {
Arrays.sort(validCombinations);
Binary file not shown.
Binary file not shown.