diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/SlideSwitch.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/SlideSwitch.java
new file mode 100644
index 00000000..d20fc4ff
--- /dev/null
+++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/SlideSwitch.java
@@ -0,0 +1,473 @@
+/*
+ *
+ * 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
+ * .
+ *
+ */
+package org.diylc.components.electromechanical;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Composite;
+import java.awt.Graphics2D;
+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 org.diylc.appframework.miscutils.ConfigurationManager;
+import org.diylc.common.IPlugInPort;
+import org.diylc.common.ObjectCache;
+import org.diylc.common.OrientationHV;
+import org.diylc.components.AbstractTransparentComponent;
+import org.diylc.components.transform.MiniToggleSwitchTransformer;
+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.PositiveNonZeroMeasureValidator;
+import org.diylc.core.measures.Size;
+import org.diylc.core.measures.SizeUnit;
+import org.diylc.utils.Constants;
+
+@ComponentDescriptor(name = "Slide Switch", category = "Electro-Mechanical",
+ author = "Branislav Stojkovic", description = "Panel mounted slide switch",
+ zOrder = IDIYComponent.COMPONENT, instanceNamePrefix = "SW", autoEdit = false,
+ enableCache = true, transformer = MiniToggleSwitchTransformer.class)
+public class SlideSwitch extends AbstractTransparentComponent implements ISwitch {
+
+ private static final long serialVersionUID = 1L;
+
+ private static Size ROW_SPACING = new Size(0.25d, SizeUnit.in);
+ private static Size COLUMN_SPACING = new Size(0.2d, SizeUnit.in);
+ private static Size MARGIN = new Size(0.08d, SizeUnit.in);
+ private static Size LUG_WIDTH = new Size(0.020d, SizeUnit.in);
+ private static Size LUG_THICKNESS = new Size(0.1d, SizeUnit.in);
+ private static Size HOLE_DIAMETER = new Size(3d, SizeUnit.mm);
+
+ private static Color BODY_COLOR = Color.decode("#CD8500");
+ private static Color BORDER_COLOR = Color.gray;
+ public static Color TERMINAL_COLOR = METAL_COLOR;
+ public static Color LABEL_COLOR = Color.white;
+ public static Color BRACKET_COLOR = Color.lightGray;
+
+ protected Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
+ transient protected Shape[] body;
+ protected SlideSwitchType switchType = SlideSwitchType.DP3T;
+ private OrientationHV orientation = OrientationHV.VERTICAL;
+ private Size rowSpacing = ROW_SPACING;
+ private Size columnSpacing = COLUMN_SPACING;
+
+ private Color bodyColor = BODY_COLOR;
+ private Color borderColor = BORDER_COLOR;
+ private Color labelColor = LABEL_COLOR;
+ private Color bracketColor = BRACKET_COLOR;
+ private Boolean showBracket = true;
+
+ public SlideSwitch() {
+ super();
+ updateControlPoints();
+ }
+
+ private void updateControlPoints() {
+ Point2D firstPoint = controlPoints[0];
+ int rowSpacing = (int) getRowSpacing().convertToPixels();
+ int columnSpacing = (int) getColumnSpacing().convertToPixels();
+ switch (switchType) {
+ case SPDT:
+ controlPoints = new Point2D[] {firstPoint,
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + rowSpacing),
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + 2 * rowSpacing)};
+ break;
+ case DPDT:
+ controlPoints = new Point2D[] {firstPoint,
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + rowSpacing),
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + 2 * rowSpacing),
+ new Point2D.Double(firstPoint.getX() + columnSpacing, firstPoint.getY()),
+ new Point2D.Double(firstPoint.getX() + columnSpacing, firstPoint.getY() + rowSpacing),
+ new Point2D.Double(firstPoint.getX() + columnSpacing,
+ firstPoint.getY() + 2 * rowSpacing)};
+ break;
+ case DP3T:
+ controlPoints = new Point2D[] {firstPoint,
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + rowSpacing),
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + 2 * rowSpacing),
+ new Point2D.Double(firstPoint.getX(), firstPoint.getY() + 3 * rowSpacing),
+ new Point2D.Double(firstPoint.getX() + columnSpacing, firstPoint.getY()),
+ new Point2D.Double(firstPoint.getX() + columnSpacing, firstPoint.getY() + rowSpacing),
+ new Point2D.Double(firstPoint.getX() + columnSpacing,
+ firstPoint.getY() + 2 * rowSpacing),
+ new Point2D.Double(firstPoint.getX() + columnSpacing,
+ firstPoint.getY() + 3 * rowSpacing)};
+ break;
+ }
+ AffineTransform xform =
+ AffineTransform.getRotateInstance(-Math.PI / 2, firstPoint.getX(), firstPoint.getY());
+ if (getOrientation() == OrientationHV.HORIZONTAL) {
+ for (int i = 1; i < controlPoints.length; i++) {
+ xform.transform(controlPoints[i], controlPoints[i]);
+ }
+ }
+ }
+
+ @Override
+ public Point2D getControlPoint(int index) {
+ return controlPoints[index];
+ }
+
+ @Override
+ public boolean isControlPointSticky(int index) {
+ return true;
+ }
+
+ @Override
+ public VisibilityPolicy getControlPointVisibilityPolicy(int index) {
+ return VisibilityPolicy.NEVER;
+ }
+
+ @Override
+ public int getControlPointCount() {
+ return controlPoints.length;
+ }
+
+ @Override
+ public void setControlPoint(Point2D point, int index) {
+ controlPoints[index].setLocation(point);
+ // Reset body shape.
+ body = null;
+ }
+
+ @EditableProperty(name = "Type")
+ @Override
+ public SlideSwitchType getValue() {
+ return switchType;
+ }
+
+ @Override
+ public void setValue(SlideSwitchType value) {
+ this.switchType = value;
+ updateControlPoints();
+ // Reset body shape.
+ body = null;
+ }
+
+ @EditableProperty
+ public OrientationHV getOrientation() {
+ if (orientation == null) {
+ orientation = OrientationHV.VERTICAL;
+ }
+ return orientation;
+ }
+
+ public void setOrientation(OrientationHV orientation) {
+ this.orientation = orientation;
+ updateControlPoints();
+ // Reset body shape.
+ body = null;
+ }
+
+ @EditableProperty(name = "Row Spacing", validatorClass = PositiveNonZeroMeasureValidator.class)
+ public Size getRowSpacing() {
+ return rowSpacing;
+ }
+
+ public void setRowSpacing(Size rowSpacing) {
+ this.rowSpacing = rowSpacing;
+ updateControlPoints();
+ // Reset body shape.
+ body = null;
+ }
+
+ @EditableProperty(name = "Column Spacing", validatorClass = PositiveNonZeroMeasureValidator.class)
+ public Size getColumnSpacing() {
+ return columnSpacing;
+ }
+
+ public void setColumnSpacing(Size columnSpacing) {
+ this.columnSpacing = columnSpacing;
+ updateControlPoints();
+ // Reset body shape.
+ body = null;
+ }
+
+ @Override
+ public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode,
+ Project project, IDrawingObserver drawingObserver) {
+ if (checkPointsClipped(g2d.getClip())) {
+ return;
+ }
+ Shape[] body = getBody();
+ Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
+ Constants.DEFAULT_THEME);
+ // Draw body if available.
+ if (body != null) {
+ Composite oldComposite = g2d.getComposite();
+ if (alpha < MAX_ALPHA) {
+ g2d.setComposite(
+ AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
+ }
+
+ if (getShowBracket()) {
+ g2d.setColor(getBracketColor());
+ g2d.fill(body[1]);
+ }
+
+ g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor());
+ g2d.fill(body[0]);
+
+ g2d.setComposite(oldComposite);
+ g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
+ Color finalBorderColor;
+ if (outlineMode) {
+ finalBorderColor =
+ componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
+ ? SELECTION_COLOR
+ : theme.getOutlineColor();
+ } else {
+ finalBorderColor =
+ componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
+ ? SELECTION_COLOR
+ : getBorderColor();
+ }
+
+ g2d.setColor(finalBorderColor);
+ if (getShowBracket()) {
+ g2d.draw(body[1]);
+ }
+ g2d.draw(body[0]);
+ }
+ // Do not track these changes because the whole switch has been tracked
+ // so far.
+ drawingObserver.stopTracking();
+ // Draw lugs.
+
+ int lugWidth;
+ int lugHeight;
+
+ if (getOrientation() == OrientationHV.HORIZONTAL) {
+ lugHeight = getClosestOdd((int) LUG_WIDTH.convertToPixels());
+ lugWidth = getClosestOdd((int) LUG_THICKNESS.convertToPixels());
+ } else {
+ lugWidth = getClosestOdd((int) LUG_WIDTH.convertToPixels());
+ lugHeight = getClosestOdd((int) LUG_THICKNESS.convertToPixels());
+ }
+
+ g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
+ for (Point2D p : controlPoints) {
+ if (outlineMode) {
+ g2d.setColor(theme.getOutlineColor());
+ g2d.drawRect((int) (p.getX() - lugWidth / 2), (int) (p.getY() - lugHeight / 2), lugWidth,
+ lugHeight);
+ } else {
+ g2d.setColor(TERMINAL_COLOR);
+ g2d.fillRect((int) (p.getX() - lugWidth / 2), (int) (p.getY() - lugHeight / 2), lugWidth,
+ lugHeight);
+ g2d.setColor(TERMINAL_COLOR.darker());
+ g2d.drawRect((int) (p.getX() - lugWidth / 2), (int) (p.getY() - lugHeight / 2), lugWidth,
+ lugHeight);
+ }
+ }
+
+// g2d.setFont(project.getFont());
+// g2d.setColor(getLabelColor());
+//
+// double labelOffsetX = 0;
+// double labelOffsetY = 0;
+// if (getValue() == SlideSwitchType.SPDT) {
+// int rowSpacing = (int) getRowSpacing().convertToPixels();
+// if (getOrientation() == OrientationHV.VERTICAL) {
+// labelOffsetY = -rowSpacing / 2;
+// } else {
+// labelOffsetX = -rowSpacing / 2;
+// }
+// }
+//
+// Rectangle bounds = body[0].getBounds();
+// StringUtils.drawCenteredText(g2d, getName(), bounds.getCenterX() + labelOffsetX,
+// bounds.getCenterY() + labelOffsetY, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
+ }
+
+ public Shape[] getBody() {
+ if (body == null) {
+ Point2D firstPoint = controlPoints[0];
+ int margin = (int) MARGIN.convertToPixels();
+ int rowSpacing = (int) getRowSpacing().convertToPixels();
+ int columnSpacing = (int) getColumnSpacing().convertToPixels();
+ int holeDiameter = (int) HOLE_DIAMETER.convertToPixels();
+ double width = 0;
+ double height = 0;
+ switch (switchType) {
+ case SPDT:
+ width = 2 * margin;
+ height = 2 * margin + 2 * rowSpacing;
+ break;
+ case DPDT:
+ width = 2 * margin + columnSpacing;
+ height = 2 * margin + 2 * rowSpacing;
+ break;
+ case DP3T:
+ width = 2 * margin + columnSpacing;
+ height = 2 * margin + 3 * rowSpacing;
+ break;
+ }
+
+ Area mainBody = new Area(new Rectangle2D.Double(firstPoint.getX() - margin,
+ firstPoint.getY() - margin, width, height));
+ Area bracket = new Area(new RoundRectangle2D.Double(firstPoint.getX() - margin,
+ firstPoint.getY() - margin - holeDiameter * 2, width, height + holeDiameter * 4,
+ holeDiameter / 2, holeDiameter / 2));
+ bracket.subtract(
+ new Area(new Ellipse2D.Double(firstPoint.getX() - margin + width / 2 - holeDiameter / 2,
+ firstPoint.getY() - margin - holeDiameter * 3 / 2, holeDiameter, holeDiameter)));
+ bracket.subtract(
+ new Area(new Ellipse2D.Double(firstPoint.getX() - margin + width / 2 - holeDiameter / 2,
+ firstPoint.getY() - margin + height + holeDiameter / 2, holeDiameter, holeDiameter)));
+ bracket.subtract(mainBody);
+
+ if (getOrientation() == OrientationHV.HORIZONTAL) {
+ AffineTransform xform =
+ AffineTransform.getRotateInstance(-Math.PI / 2, firstPoint.getX(), firstPoint.getY());
+ mainBody.transform(xform);
+ bracket.transform(xform);
+ }
+
+ body = new Shape[] {mainBody, bracket};
+ }
+ return body;
+ }
+
+ @Override
+ public void drawIcon(Graphics2D g2d, int width, int height) {
+ int circleSize = (int) (5f * width / 32);
+ g2d.setColor(BODY_COLOR);
+ g2d.fillRect(width / 8, 1, width * 6 / 8, height - 2);
+ g2d.setColor(BORDER_COLOR);
+ g2d.drawRect(width / 8, 1, width * 6 / 8, height - 2);
+ g2d.setColor(TERMINAL_COLOR);
+ g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(2f * width / 32));
+ for (int i = 1; i <= 3; i++) {
+ g2d.drawLine(width / 4, i * height / 4 - circleSize / 2 - 1, width / 4,
+ i * height / 4 + circleSize / 2 - 1);
+ g2d.drawLine(width * 3 / 4, i * height / 4 - circleSize / 2 - 1, width * 3 / 4,
+ i * height / 4 + circleSize / 2 - 1);
+ }
+ }
+
+ @EditableProperty(name = "Body")
+ public Color getBodyColor() {
+ if (bodyColor == null)
+ bodyColor = BODY_COLOR;
+ return bodyColor;
+ }
+
+ public void setBodyColor(Color bodyColor) {
+ this.bodyColor = bodyColor;
+ }
+
+ @EditableProperty(name = "Border")
+ public Color getBorderColor() {
+ if (borderColor == null)
+ borderColor = BORDER_COLOR;
+ return borderColor;
+ }
+
+ public void setBorderColor(Color borderColor) {
+ this.borderColor = borderColor;
+ }
+
+ // switch stuff
+ //
+ // @Override
+ // public String getControlPointNodeName(int index) {
+ // // we don't want the switch to produce any nodes, it just makes connections
+ // return null;
+ // }
+
+ @Override
+ public boolean canPointMoveFreely(int pointIndex) {
+ return false;
+ }
+
+ @Override
+ public int getPositionCount() {
+ switch (switchType) {
+ case SPDT:
+ case DPDT:
+ return 2;
+ case DP3T:
+ return 3;
+ }
+ return 2;
+ }
+
+ @Override
+ public String getPositionName(int position) {
+ return "ON" + Integer.toString(position + 1);
+ }
+
+ @Override
+ public boolean arePointsConnected(int index1, int index2, int position) {
+ switch (switchType) {
+ case SPDT:
+ return (index1 == position) && (index2 - index1 == 1);
+ case DPDT:
+ case DP3T:
+ return (index1 == position * 2 || index1 == position * 2 + 1) && (index2 - index1 == 2);
+ }
+ return false;
+ }
+
+ @EditableProperty(name = "Label")
+ public Color getLabelColor() {
+ return labelColor;
+ }
+
+ public void setLabelColor(Color labelColor) {
+ this.labelColor = labelColor;
+ }
+
+ @EditableProperty(name = "Show Bracket")
+ public Boolean getShowBracket() {
+ return showBracket;
+ }
+
+ public void setShowBracket(Boolean showBracket) {
+ this.showBracket = showBracket;
+ }
+
+ @EditableProperty(name = "Bracket")
+ public Color getBracketColor() {
+ return bracketColor;
+ }
+
+ public void setBracketColor(Color bracketColor) {
+ this.bracketColor = bracketColor;
+ }
+
+ @Override
+ public Rectangle2D getCachingBounds() {
+ int margin = 20;
+ Rectangle2D bounds = getBody()[1].getBounds2D();
+ return new Rectangle2D.Double(bounds.getX() - margin, bounds.getY() - margin,
+ bounds.getWidth() + 2 * margin, bounds.getHeight() + 2 * margin);
+ }
+}
diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/SlideSwitchType.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/SlideSwitchType.java
new file mode 100644
index 00000000..61f93018
--- /dev/null
+++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/SlideSwitchType.java
@@ -0,0 +1,17 @@
+package org.diylc.components.electromechanical;
+
+public enum SlideSwitchType {
+
+ SPDT, DPDT, DP3T;
+
+ @Override
+ public String toString() {
+ String name = name();
+ if (name.startsWith("_"))
+ name = name.substring(1);
+ name = name.replace("_", " ");
+ name = name.replace("mustang", "");
+ name = name.replace("off", " (Center OFF)");
+ return name;
+ }
+}
\ No newline at end of file
diff --git a/diylc/diylc-library/test/org/diylc/netlist/GuitarNetlistAnalyzerTests.java b/diylc/diylc-library/test/org/diylc/netlist/GuitarNetlistAnalyzerTests.java
index fb0f06d5..71efc93c 100644
--- a/diylc/diylc-library/test/org/diylc/netlist/GuitarNetlistAnalyzerTests.java
+++ b/diylc/diylc-library/test/org/diylc/netlist/GuitarNetlistAnalyzerTests.java
@@ -1,36 +1,27 @@
/*
-
- 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 .
-
-*/
+ *
+ * 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
+ * .
+ *
+ */
package org.diylc.netlist;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
import java.util.Arrays;
-
import org.diylc.components.electromechanical.OpenJack1_4;
import org.diylc.components.guitar.HumbuckerPickup;
-import org.diylc.components.guitar.LPSwitch;
-import org.diylc.components.guitar.LeverSwitch;
-import org.diylc.components.guitar.LeverSwitch.LeverSwitchType;
import org.diylc.components.guitar.SingleCoilPickup;
import org.diylc.components.passive.PotentiometerPanel;
import org.diylc.components.passive.RadialCeramicDiskCapacitor;
@@ -51,7 +42,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup.North<-))", s);
}
-
+
@Test
public void testOneSinglePickupVolPot() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -68,7 +59,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Volume.1-2 + Pickup.North<-) || (Volume.2-3))", s);
}
-
+
@Test
public void testOneSinglePickupVolTonePot() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -83,14 +74,15 @@ public class GuitarNetlistAnalyzerTests {
Netlist netlist = new Netlist(Arrays.asList(jack, pickup, vol, tone, cap));
Group hotGroup = new Group().connect(pickup, 1).connect(vol, 0).connect(tone, 2);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
- Group sleeveGroup = new Group().connect(jack, 1).connect(pickup, 2).connect(vol, 2).connect(cap, 0);
+ Group sleeveGroup =
+ new Group().connect(jack, 1).connect(pickup, 2).connect(vol, 2).connect(cap, 0);
Group toneGroup = new Group().connect(tone, 1).connect(cap, 1);
netlist.add(tipGroup).add(tipGroup).add(sleeveGroup).add(hotGroup).add(toneGroup);
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
String s = tree.toString();
assertEquals("(((Volume.1-2) + ((Pickup.North<-) || (Tone.2-3 + Cap))) || (Volume.2-3))", s);
}
-
+
@Test
public void testTwoSinglePickupsMasterVolSeparateTone() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -108,18 +100,24 @@ public class GuitarNetlistAnalyzerTests {
cap1.setName("Cap1");
RadialCeramicDiskCapacitor cap2 = new RadialCeramicDiskCapacitor();
cap2.setName("Cap2");
- Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
- Group hotGroup = new Group().connect(pickup1, 1).connect(vol, 0).connect(tone1, 2).connect(pickup2, 1).connect(tone2, 2);
+ Netlist netlist =
+ new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
+ Group hotGroup = new Group().connect(pickup1, 1).connect(vol, 0).connect(tone1, 2)
+ .connect(pickup2, 1).connect(tone2, 2);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
- Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 2).connect(pickup2, 2).connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
+ Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 2).connect(pickup2, 2)
+ .connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
Group tone1Group = new Group().connect(tone1, 1).connect(cap1, 1);
Group tone2Group = new Group().connect(tone2, 1).connect(cap2, 1);
- netlist.add(tipGroup).add(tipGroup).add(sleeveGroup).add(hotGroup).add(tone1Group).add(tone2Group);
+ netlist.add(tipGroup).add(tipGroup).add(sleeveGroup).add(hotGroup).add(tone1Group)
+ .add(tone2Group);
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
String s = tree.toString();
- assertEquals("(((Volume.1-2) + ((Pickup1.North<-) || (Pickup2.North<-) || (Tone1.2-3 + Cap1) || (Tone2.2-3 + Cap2))) || (Volume.2-3))", s);
+ assertEquals(
+ "(((Volume.1-2) + ((Pickup1.North<-) || (Pickup2.North<-) || (Tone1.2-3 + Cap1) || (Tone2.2-3 + Cap2))) || (Volume.2-3))",
+ s);
}
-
+
@Test
public void testOneSinglePickupReverse() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -133,7 +131,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup.North->))", s);
}
-
+
@Test
public void testOneHumbuckerSeries() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -148,7 +146,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup.North<- + Pickup.South<-))", s);
}
-
+
@Test
public void testOneHumbuckerSeriesReverse() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -163,7 +161,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup.South-> + Pickup.North->))", s);
}
-
+
@Test
public void testOneHumbuckerParallel() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -177,7 +175,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup.North<-) || (Pickup.South<-))", s);
}
-
+
@Test
public void testOneHumbuckerParallelOutOfPhase() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -191,7 +189,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup.North<-) || (Pickup.South->))", s);
}
-
+
@Test
public void testTwoHumbuckersSeries() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -210,7 +208,7 @@ public class GuitarNetlistAnalyzerTests {
String s = tree.toString();
assertEquals("((Pickup1.North<- + Pickup1.South<- + Pickup2.North<- + Pickup2.South<-))", s);
}
-
+
@Test
public void testTwoHumbuckersParallel() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -221,14 +219,14 @@ public class GuitarNetlistAnalyzerTests {
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0).connect(pickup2, 0);
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
- Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
+ Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 3).connect(pickup2, 3);
netlist.add(tipGroup).add(coilTapGroup1).add(coilTapGroup2).add(sleeveGroup);
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
String s = tree.toString();
assertEquals("((Pickup1.North<- + Pickup1.South<-) || (Pickup2.North<- + Pickup2.South<-))", s);
}
-
+
@Test
public void testTwoHumbuckersParallelOutOfPhase() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -239,14 +237,14 @@ public class GuitarNetlistAnalyzerTests {
Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2));
Group tipGroup = new Group().connect(jack, 0).connect(pickup1, 0).connect(pickup2, 3);
Group coilTapGroup1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
- Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
+ Group coilTapGroup2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 3).connect(pickup2, 0);
netlist.add(tipGroup).add(coilTapGroup1).add(coilTapGroup2).add(sleeveGroup);
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
String s = tree.toString();
assertEquals("((Pickup1.North<- + Pickup1.South<-) || (Pickup2.South-> + Pickup2.North->))", s);
}
-
+
@Test
public void testTwoHumbuckersMasterVolSeparateTone() throws TreeException {
OpenJack1_4 jack = new OpenJack1_4();
@@ -264,73 +262,23 @@ public class GuitarNetlistAnalyzerTests {
cap1.setName("Cap1");
RadialCeramicDiskCapacitor cap2 = new RadialCeramicDiskCapacitor();
cap2.setName("Cap2");
- Netlist netlist = new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
- Group hotGroup = new Group().connect(pickup1, 0).connect(vol, 0).connect(tone1, 2).connect(pickup2, 0).connect(tone2, 2);
+ Netlist netlist =
+ new Netlist(Arrays.asList(jack, pickup1, pickup2, vol, tone1, tone2, cap1, cap2));
+ Group hotGroup = new Group().connect(pickup1, 0).connect(vol, 0).connect(tone1, 2)
+ .connect(pickup2, 0).connect(tone2, 2);
Group tipGroup = new Group().connect(jack, 0).connect(vol, 1);
- Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 3).connect(pickup2, 3).connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
+ Group sleeveGroup = new Group().connect(jack, 1).connect(pickup1, 3).connect(pickup2, 3)
+ .connect(vol, 2).connect(cap1, 0).connect(cap2, 0);
Group tone1Group = new Group().connect(tone1, 1).connect(cap1, 1);
Group tone2Group = new Group().connect(tone2, 1).connect(cap2, 1);
Group coilTap1 = new Group().connect(pickup1, 1).connect(pickup1, 2);
Group coilTap2 = new Group().connect(pickup2, 1).connect(pickup2, 2);
- netlist.add(tipGroup).add(tipGroup).add(sleeveGroup).add(hotGroup).add(tone1Group).add(tone2Group).add(coilTap1).add(coilTap2);
+ netlist.add(tipGroup).add(tipGroup).add(sleeveGroup).add(hotGroup).add(tone1Group)
+ .add(tone2Group).add(coilTap1).add(coilTap2);
Tree tree = new GuitarDiagramAnalyzer().constructTree(netlist);
String s = tree.toString();
- assertEquals("(((Volume.1-2) + ((Pickup1.North<- + Pickup1.South<-) || (Pickup2.North<- + Pickup2.South<-) || (Tone1.2-3 + Cap1) || (Tone2.2-3 + Cap2))) || (Volume.2-3))", s);
- }
-
- @Test
- public void testLeverSwitch() {
- LeverSwitch leverSwitch = new LeverSwitch();
-
- leverSwitch.setType(LeverSwitchType.DP5T);
- String[] validCombinations = new String[]{
- "0,0,1", "0,6,11", "0,12,13", "0,18,23",
- "1,0,2", "1,7,11", "1,12,14", "1,19,23",
- "2,0,3", "2,8,11", "2,12,15", "2,20,23",
- "3,0,4", "3,9,11", "3,12,16", "3,21,23",
- "4,0,5", "4,10,11", "4,12,17", "4,22,23"};
- Arrays.sort(validCombinations);
- for (int p = 0; p < leverSwitch.getPositionCount(); p++)
- for (int i = 0; i < leverSwitch.getControlPointCount(); i++)
- for (int j = 0; j < leverSwitch.getControlPointCount(); j++) {
- String test = p + "," + i + "," + j;
- boolean isConnected = leverSwitch.arePointsConnected(i, j, p);
- boolean isOk = (isConnected && Arrays.binarySearch(validCombinations, test) >= 0) ||
- !isConnected && Arrays.binarySearch(validCombinations, test) < 0;
- if (!isOk)
- fail("Bad connection for p=" + p + ", i=" + i + ",j=" + j);
- }
-
- leverSwitch.setType(LeverSwitchType._4P5T);
- Arrays.sort(validCombinations);
- for (int p = 0; p < leverSwitch.getPositionCount(); p++)
- for (int i = 0; i < leverSwitch.getControlPointCount(); i++)
- for (int j = 0; j < leverSwitch.getControlPointCount(); j++) {
- String test = p + "," + i + "," + j;
- boolean isConnected = leverSwitch.arePointsConnected(i, j, p);
- boolean isOk = (isConnected && Arrays.binarySearch(validCombinations, test) >= 0) ||
- !isConnected && Arrays.binarySearch(validCombinations, test) < 0;
- if (!isOk)
- fail("Bad connection for p=" + p + ", i=" + i + ",j=" + j);
- }
- }
-
- @Test
- public void testLPSwitch() {
- LPSwitch lpSwitch = new LPSwitch();
- String[] validCombinations = new String[] {
- "0,1,2", "1,1,2", "1,2,3", "1,1,3", "2,2,3"
- };
- Arrays.sort(validCombinations);
- for (int p = 0; p < lpSwitch.getPositionCount(); p++)
- for (int i = 0; i < lpSwitch.getControlPointCount(); i++)
- for (int j = 0; j < lpSwitch.getControlPointCount(); j++) {
- String test = p + "," + i + "," + j;
- boolean isConnected = lpSwitch.arePointsConnected(i, j, p);
- boolean isOk = (isConnected && Arrays.binarySearch(validCombinations, test) >= 0) ||
- !isConnected && Arrays.binarySearch(validCombinations, test) < 0;
- if (!isOk)
- fail("Bad connection for p=" + p + ", i=" + i + ",j=" + j);
- }
- }
+ assertEquals(
+ "(((Volume.1-2) + ((Pickup1.North<- + Pickup1.South<-) || (Pickup2.North<- + Pickup2.South<-) || (Tone1.2-3 + Cap1) || (Tone2.2-3 + Cap2))) || (Volume.2-3))",
+ s);
+ }
}
diff --git a/diylc/diylc-library/test/org/diylc/netlist/SwitchTests.java b/diylc/diylc-library/test/org/diylc/netlist/SwitchTests.java
new file mode 100644
index 00000000..37a21e4f
--- /dev/null
+++ b/diylc/diylc-library/test/org/diylc/netlist/SwitchTests.java
@@ -0,0 +1,87 @@
+package org.diylc.netlist;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import java.util.Arrays;
+import org.diylc.components.electromechanical.SlideSwitch;
+import org.diylc.components.electromechanical.SlideSwitchType;
+import org.diylc.components.guitar.LPSwitch;
+import org.diylc.components.guitar.LeverSwitch;
+import org.diylc.components.guitar.LeverSwitch.LeverSwitchType;
+import org.diylc.core.IDIYComponent;
+import org.diylc.core.ISwitch;
+import org.junit.Test;
+
+public class SwitchTests {
+
+ @Test
+ public void testLeverSwitchDP5T() {
+ LeverSwitch leverSwitch = new LeverSwitch();
+
+ leverSwitch.setType(LeverSwitchType.DP5T);
+ String[] validCombinations = new String[] {"0,0,1", "0,6,11", "1,0,2", "1,7,11", "2,0,3",
+ "2,8,11", "3,0,4", "3,9,11", "4,0,5", "4,10,11"};
+
+ testSwitch(leverSwitch, validCombinations);
+ }
+
+ @Test
+ public void testLeverSwitch4P5T() {
+ LeverSwitch leverSwitch = new LeverSwitch();
+
+ String[] validCombinations = new String[] {"0,0,1", "0,6,11", "0,12,13", "0,18,23", "1,0,2",
+ "1,7,11", "1,12,14", "1,19,23", "2,0,3", "2,8,11", "2,12,15", "2,20,23", "3,0,4", "3,9,11",
+ "3,12,16", "3,21,23", "4,0,5", "4,10,11", "4,12,17", "4,22,23"};
+ leverSwitch.setType(LeverSwitchType._4P5T);
+ testSwitch(leverSwitch, validCombinations);
+ }
+
+ @Test
+ public void testLPSwitch() {
+ LPSwitch lpSwitch = new LPSwitch();
+ String[] validCombinations = new String[] {"0,1,2", "1,1,2", "1,2,3", "1,1,3", "2,2,3"};
+ testSwitch(lpSwitch, validCombinations);
+ }
+
+ @Test
+ public void testSlideSwitchSPDT() {
+ SlideSwitch slideSwitch = new SlideSwitch();
+ slideSwitch.setValue(SlideSwitchType.SPDT);
+ String[] validCombinations = new String[] {"0,0,1", "1,1,2"};
+ testSwitch(slideSwitch, validCombinations);
+ }
+
+ @Test
+ public void testSlideSwitchDPDT() {
+ SlideSwitch slideSwitch = new SlideSwitch();
+ slideSwitch.setValue(SlideSwitchType.DPDT);
+ String[] validCombinations = new String[] {"0,0,2", "0,1,3", "1,2,4", "1,3,5"};
+ testSwitch(slideSwitch, validCombinations);
+ }
+
+ @Test
+ public void testSlideSwitchDP3T() {
+ SlideSwitch slideSwitch = new SlideSwitch();
+ slideSwitch.setValue(SlideSwitchType.DP3T);
+ String[] validCombinations = new String[] {"0,0,2", "0,1,3", "1,2,4", "1,3,5", "2,4,6", "2,5,7"};
+ testSwitch(slideSwitch, validCombinations);
+ }
+
+ private void testSwitch(ISwitch sw, String[] validCombinations) {
+ Arrays.sort(validCombinations);
+ int count = 0;
+ for (int p = 0; p < sw.getPositionCount(); p++)
+ for (int i = 0; i < ((IDIYComponent>) sw).getControlPointCount(); i++)
+ for (int j = 0; j < ((IDIYComponent>) sw).getControlPointCount(); j++) {
+ String test = p + "," + i + "," + j;
+ boolean isConnected = sw.arePointsConnected(i, j, p);
+ if (isConnected)
+ count++;
+ boolean isOk = (isConnected && Arrays.binarySearch(validCombinations, test) >= 0)
+ || !isConnected && Arrays.binarySearch(validCombinations, test) < 0;
+ if (!isOk)
+ fail("Bad connection for p=" + p + ", i=" + i + ",j=" + j);
+ }
+ assertEquals(validCombinations.length, count);
+ }
+}
diff --git a/diylc/diylc-swing/build.xml b/diylc/diylc-swing/build.xml
index d1ef2420..7d26cae6 100644
--- a/diylc/diylc-swing/build.xml
+++ b/diylc/diylc-swing/build.xml
@@ -10,7 +10,7 @@
-
+
@@ -139,6 +139,9 @@
+
+
+
+
diff --git a/diylc/diylc-swing/test/org/diylc/RegressionTestRunner.java b/diylc/diylc-swing/test/org/diylc/RegressionTestRunner.java
index cb6cd1c6..0a28d769 100644
--- a/diylc/diylc-swing/test/org/diylc/RegressionTestRunner.java
+++ b/diylc/diylc-swing/test/org/diylc/RegressionTestRunner.java
@@ -3,16 +3,13 @@ package org.diylc;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDateTime;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -23,12 +20,9 @@ import java.util.stream.Stream;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.InMemoryConfigurationManager;
import org.diylc.appframework.update.VersionNumber;
-import org.diylc.common.INetlistAnalyzer;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IView;
import org.diylc.netlist.Netlist;
-import org.diylc.netlist.Summary;
-import org.diylc.netlist.TreeException;
import org.diylc.presenter.Presenter;
import org.diylc.swing.plugins.file.ProjectDrawingProvider;
import org.diylc.swingframework.export.DrawingExporter;
@@ -232,62 +226,105 @@ public class RegressionTestRunner {
return res.failed("Images do not match!");
}
- List summarizers = presenter.getNetlistAnalyzers();
- if (summarizers != null) {
- List netlists = presenter.extractNetlists(true);
+ List netlists = presenter.extractNetlists(true);
+ File netlistOutputDir = new File(
+ file.getParentFile().getParentFile().getAbsolutePath() + File.separator + "netlist");
+ File netlistOutputFile = new File(netlistOutputDir.getAbsolutePath() + File.separator
+ + file.getName().replace(".diy", ".txt"));
+ File netlistInputFile = new File(inputDir.getAbsolutePath() + File.separator + "netlist"
+ + File.separator + (file.getName().replace(".diy", ".txt")));
- for (INetlistAnalyzer summarizer : summarizers) {
- File summaryOutputDir =
- new File(outputDir.getAbsolutePath() + File.separator + summarizer.getShortName());
- File summaryOutputFile = new File(summaryOutputDir.getAbsolutePath() + File.separator
- + file.getName().replace(".diy", ".txt"));
- summaryOutputDir.mkdirs();
- if (summaryOutputFile.exists()) {
- summaryOutputFile.delete();
+ netlistOutputDir.mkdirs();
+ try {
+ if (netlistOutputFile.exists()) {
+ netlistOutputFile.delete();
+ }
+ try {
+ try (BufferedWriter writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(netlistOutputFile, true), "UTF-8"))) {
+ for (Netlist netlist : netlists) {
+ writer.write(netlist.toString());
+ writer.newLine();
+ }
}
-
- File summaryInputDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
- + File.separator + summarizer.getShortName());
- File summaryInputFile = new File(summaryInputDir.getAbsolutePath() + File.separator
- + file.getName().replace(".diy", ".txt"));
-
- if (!summaryInputFile.exists()) {
- return res.failed("Summary input file not found for: " + summarizer.getShortName());
- }
-
- try {
- List outputLines = new ArrayList();
- try {
- writeSummariesToFile(netlists, summarizer, summaryOutputFile);
- outputLines = Files.readAllLines(Paths.get(summaryOutputFile.getAbsolutePath()));
- } catch (Exception e) {
- try (BufferedWriter writer = new BufferedWriter(
- new OutputStreamWriter(new FileOutputStream(summaryOutputFile, true), "UTF-8"))) {
- String line = e.getClass().getCanonicalName() + ": " + e.getMessage();
- writer.write(line);
- outputLines.add(line);
- }
- }
-
- List inputLines =
- Files.readAllLines(Paths.get(summaryInputFile.getAbsolutePath()));
-
- if (inputLines.size() != outputLines.size()) {
- return res.failed(
- "Summary input and output files do not match for: " + summarizer.getShortName());
- }
- for (int i = 0; i < inputLines.size(); i++) {
- if (!inputLines.get(i).equals(outputLines.get(i))) {
- return res.failed(
- "Summary input and output files do not match for: " + summarizer.getShortName());
- }
- }
- } catch (Exception e) {
- return res.failed(e.getMessage());
+ } catch (Exception e) {
+ try (BufferedWriter writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(netlistOutputFile, true), "UTF-8"))) {
+ writer.write(e.getClass().getCanonicalName() + ": " + e.getMessage());
}
}
+
+ List inputLines = Files.readAllLines(Paths.get(netlistInputFile.getAbsolutePath()));
+ List outputLines = Files.readAllLines(Paths.get(netlistOutputFile.getAbsolutePath()));
+
+ if (inputLines.size() != outputLines.size()) {
+ return res.failed("Netlists do not match");
+ }
+ for (int i = 0; i < inputLines.size(); i++) {
+ if (!inputLines.get(i).equals(outputLines.get(i))) {
+ return res.failed("Netlists do not match");
+ }
+ }
+ } catch (IOException e) {
+ return res.failed(e.getMessage());
}
+ // List summarizers = presenter.getNetlistAnalyzers();
+ // if (summarizers != null) {
+ // List netlists = presenter.extractNetlists(true);
+ //
+ // for (INetlistAnalyzer summarizer : summarizers) {
+ // File summaryOutputDir =
+ // new File(outputDir.getAbsolutePath() + File.separator + summarizer.getShortName());
+ // File summaryOutputFile = new File(summaryOutputDir.getAbsolutePath() + File.separator
+ // + file.getName().replace(".diy", ".txt"));
+ // summaryOutputDir.mkdirs();
+ // if (summaryOutputFile.exists()) {
+ // summaryOutputFile.delete();
+ // }
+ //
+ // File summaryInputDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
+ // + File.separator + summarizer.getShortName());
+ // File summaryInputFile = new File(summaryInputDir.getAbsolutePath() + File.separator
+ // + file.getName().replace(".diy", ".txt"));
+ //
+ // if (!summaryInputFile.exists()) {
+ // return res.failed("Summary input file not found for: " + summarizer.getShortName());
+ // }
+ //
+ // try {
+ // List outputLines = new ArrayList();
+ // try {
+ // writeSummariesToFile(netlists, summarizer, summaryOutputFile);
+ // outputLines = Files.readAllLines(Paths.get(summaryOutputFile.getAbsolutePath()));
+ // } catch (Exception e) {
+ // try (BufferedWriter writer = new BufferedWriter(
+ // new OutputStreamWriter(new FileOutputStream(summaryOutputFile, true), "UTF-8"))) {
+ // String line = e.getClass().getCanonicalName() + ": " + e.getMessage();
+ // writer.write(line);
+ // outputLines.add(line);
+ // }
+ // }
+ //
+ // List inputLines =
+ // Files.readAllLines(Paths.get(summaryInputFile.getAbsolutePath()));
+ //
+ // if (inputLines.size() != outputLines.size()) {
+ // return res.failed(
+ // "Summary input and output files do not match for: " + summarizer.getShortName());
+ // }
+ // for (int i = 0; i < inputLines.size(); i++) {
+ // if (!inputLines.get(i).equals(outputLines.get(i))) {
+ // return res.failed(
+ // "Summary input and output files do not match for: " + summarizer.getShortName());
+ // }
+ // }
+ // } catch (Exception e) {
+ // return res.failed(e.getMessage());
+ // }
+ // }
+ // }
+
String message = null;
if (!view.getMessages().isEmpty()) {
message = view.getMessages().entrySet().stream().flatMap(x -> x.getValue().stream())
@@ -310,51 +347,75 @@ public class RegressionTestRunner {
// always export image to ensure that rendering is done and continuity areas are populated
DrawingExporter.getInstance().exportPNG(drawingProvider, pngFile);
- List summarizers = plugInPort.getNetlistAnalyzers();
- if (summarizers != null) {
- List netlists = plugInPort.extractNetlists(true);
+ List netlists = plugInPort.extractNetlists(true);
+ File netlistDir = new File(
+ file.getParentFile().getParentFile().getAbsolutePath() + File.separator + "netlist");
+ File netlistFile = new File(
+ netlistDir.getAbsolutePath() + File.separator + file.getName().replace(".diy", ".txt"));
- for (INetlistAnalyzer summarizer : summarizers) {
- File summaryDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
- + File.separator + summarizer.getShortName());
- File summaryFile = new File(summaryDir.getAbsolutePath() + File.separator
- + file.getName().replace(".diy", ".txt"));
- summaryDir.mkdirs();
- if (!summaryFile.exists()) {
- try {
- writeSummariesToFile(netlists, summarizer, summaryFile);
-
- } catch (Exception e) {
- try (BufferedWriter writer = new BufferedWriter(
- new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
- writer.write(e.getClass().getCanonicalName() + ": " + e.getMessage());
- }
+ netlistDir.mkdirs();
+ if (!netlistFile.exists()) {
+ try {
+ try (BufferedWriter writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(netlistFile, true), "UTF-8"))) {
+ for (Netlist netlist : netlists) {
+ writer.write(netlist.toString());
+ writer.newLine();
}
}
+ } catch (Exception e) {
+ try (BufferedWriter writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(netlistFile, true), "UTF-8"))) {
+ writer.write(e.getClass().getCanonicalName() + ": " + e.getMessage());
+ }
}
}
+
+ // List summarizers = plugInPort.getNetlistAnalyzers();
+ // if (summarizers != null) {
+ //
+ //
+ // for (INetlistAnalyzer summarizer : summarizers) {
+ // summaryDir = new File(file.getParentFile().getParentFile().getAbsolutePath()
+ // + File.separator + summarizer.getShortName());
+ // summaryFile = new File(summaryDir.getAbsolutePath() + File.separator
+ // + file.getName().replace(".diy", ".txt"));
+ // summaryDir.mkdirs();
+ // if (!summaryFile.exists()) {
+ // try {
+ // writeSummariesToFile(netlists, summarizer, summaryFile);
+ //
+ // } catch (Exception e) {
+ // try (BufferedWriter writer = new BufferedWriter(
+ // new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
+ // writer.write(e.getClass().getCanonicalName() + ": " + e.getMessage());
+ // }
+ // }
+ // }
+ // }
+ // }
} catch (Exception e) {
return res.failed(e.getMessage());
}
return res.succedded();
}
- private static void writeSummariesToFile(List netlists, INetlistAnalyzer summarizer,
- File summaryFile)
- throws TreeException, IOException, UnsupportedEncodingException, FileNotFoundException {
- List summaries = summarizer.summarize(netlists, null);
-
- try (BufferedWriter writer = new BufferedWriter(
- new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
- for (Summary summary : summaries) {
- writer.write("Switch configuration: ");
- writer.write(summary.getNetlist().getSwitchSetup().toString());
- writer.write("
");
- writer.write(summary.getSummary());
- writer.newLine();
- }
- }
- }
+// private static void writeSummariesToFile(List netlists, INetlistAnalyzer summarizer,
+// File summaryFile)
+// throws TreeException, IOException, UnsupportedEncodingException, FileNotFoundException {
+// List summaries = summarizer.summarize(netlists, null);
+//
+// try (BufferedWriter writer = new BufferedWriter(
+// new OutputStreamWriter(new FileOutputStream(summaryFile, true), "UTF-8"))) {
+// for (Summary summary : summaries) {
+// writer.write("Switch configuration: ");
+// writer.write(summary.getNetlist().getSwitchSetup().toString());
+// writer.write("
");
+// writer.write(summary.getSummary());
+// writer.newLine();
+// }
+// }
+// }
static class RegressionTestResult {
boolean ok;