From 86acda3f46faf3b94a4cdac6985f36ccfe3804fe Mon Sep 17 00:00:00 2001 From: Bane Stojkovic Date: Sun, 30 Oct 2022 23:04:54 +0100 Subject: [PATCH] Added switch (latching) symbol --- .../src/org/diylc/presenter/update.xml | 22 ++++++-- .../SwitchLatchingSymbol.java | 28 ++++++---- .../diylc/netlist/SwitchLatchingTests.java | 55 +++++++++++++++++++ 3 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 diylc/diylc-library/test/org/diylc/netlist/SwitchLatchingTests.java diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml index 159b7936..6e4bed16 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/update.xml +++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml @@ -4061,19 +4061,31 @@ 2022-10-23 00:00:00.000 CET - + + + NEW_FEATURE + Added "Switch (Latching)" schematic symbol with many variations + NEW_FEATURE Added "Common Node" component that ties all nodes with the same label together, e.g. B+, V+, GND, etc - - NEW_FEATURE - Ground symbol ties all grounded points together for circuit analysis - IMPROVEMENT "Snap to Components" features now works when creating new components as well as when moving existing ones + + IMPROVEMENT + Increase the opacity of locked components + + + IMPROVEMENT + Improved ground symbol mouse selection tracking and added stroke width as a parameter + + + BUG_FIX + Ground symbol ties all grounded points together for circuit analysis + BUG_FIX Printed projects are sometimes missing parts of components or text diff --git a/diylc/diylc-library/src/org/diylc/components/electromechanical/SwitchLatchingSymbol.java b/diylc/diylc-library/src/org/diylc/components/electromechanical/SwitchLatchingSymbol.java index c44ec464..c4e1ed35 100644 --- a/diylc/diylc-library/src/org/diylc/components/electromechanical/SwitchLatchingSymbol.java +++ b/diylc/diylc-library/src/org/diylc/components/electromechanical/SwitchLatchingSymbol.java @@ -39,7 +39,6 @@ import org.diylc.core.annotations.EditableProperty; import org.diylc.core.annotations.KeywordPolicy; import org.diylc.core.measures.Size; import org.diylc.core.measures.SizeUnit; -import org.diylc.utils.Constants; @ComponentDescriptor(name = "Switch (Latching)", author = "Branislav Stojkovic", category = "Schematic Symbols", instanceNamePrefix = "SW", @@ -55,7 +54,7 @@ public class SwitchLatchingSymbol public static Size SIZE = new Size(0.15d, SizeUnit.in); public static Size THROW_SPACING = new Size(0.1d, SizeUnit.in); public static Size SPACING = new Size(0.3d, SizeUnit.in); - public static Size TERMINAL_SIZE = new Size(0.05d, SizeUnit.in); + public static Size TERMINAL_SIZE = new Size(0.04d, SizeUnit.in); public static int ARC_ANGLE = 24; private Orientation orientation = Orientation.DEFAULT; @@ -77,20 +76,19 @@ public class SwitchLatchingSymbol g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke((float) (terminalSize / 4))); + drawingObserver.startTrackingContinuityArea(true); for (int i = 0; i < controlPoints.length; i++) { Ellipse2D.Double terminal = new Ellipse2D.Double(controlPoints[i].getX() - terminalSize / 2, controlPoints[i].getY() - terminalSize / 2, terminalSize, terminalSize); - g2d.setColor(Constants.TRANSPARENT_COLOR); - g2d.fill(terminal); - g2d.setColor( componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : COLOR); - g2d.draw(terminal); + g2d.fill(terminal); } + drawingObserver.stopTrackingContinuityArea(); double theta = orientation.toRadians(); @@ -276,17 +274,27 @@ public class SwitchLatchingSymbol @Override public String getPositionName(int position) { - return Integer.toString(position); + return Integer.toString(position + 1); } @Override public boolean arePointsConnected(int index1, int index2, int position) { - // TODO Auto-generated method stub - return false; + if ("OFF".equals(configuration.getInBetween())) { + if (position % 2 == 1) + return false; + + return index1 % (configuration.getThrowCount() + 1) == 0 && index2 == index1 + position / 2 + 1; + } else if ("SHORT".equals(configuration.getInBetween())) { + if (position % 2 == 1) + return index1 % (configuration.getThrowCount() + 1) == 0 && (index2 == index1 + position / 2 + 1 || index2 == index1 + position / 2 + 2); + + return index1 % (configuration.getThrowCount() + 1) == 0 && index2 == index1 + position / 2 + 1; + } + return index1 % (configuration.getThrowCount() + 1) == 0 && index2 == index1 + position + 1; } public static enum SwitchConfiguration { - _1x1, _2x2, _2x3xOFF, _3x3, _3x5xSHORT, _4x4, _5x5, _6x6, _7x7, _8x8, _9x9, _10x10, _11x11, _12x12; + _1x2, _2x2, _2x3xOFF, _3x3, _3x5xSHORT, _4x4, _5x5, _6x6, _7x7, _8x8, _9x9, _10x10, _11x11, _12x12; private int throwCount; private int positionCount; diff --git a/diylc/diylc-library/test/org/diylc/netlist/SwitchLatchingTests.java b/diylc/diylc-library/test/org/diylc/netlist/SwitchLatchingTests.java new file mode 100644 index 00000000..14152a6e --- /dev/null +++ b/diylc/diylc-library/test/org/diylc/netlist/SwitchLatchingTests.java @@ -0,0 +1,55 @@ +package org.diylc.netlist; + +import org.diylc.components.electromechanical.SwitchLatchingSymbol; +import org.diylc.components.electromechanical.SwitchLatchingSymbol.PoleCount; +import org.junit.Test; + +public class SwitchLatchingTests extends AbstractSwitchTests { + + @Test + public void testSPSTSwitch() { + SwitchLatchingSymbol sw = new SwitchLatchingSymbol(); + + String[] validCombinations = + new String[] {"0,0,1"}; + + sw.setValue(SwitchLatchingSymbol.SwitchConfiguration._1x2); + sw.setPoleCount(PoleCount.ONE); + testSwitch(sw, validCombinations); + } + + @Test + public void test3PDTSwitch() { + SwitchLatchingSymbol sw = new SwitchLatchingSymbol(); + + String[] validCombinations = + new String[] {"0,0,1", "0,4,5", "0,8,9", "1,0,2", "1,4,6", "1,8,10", "2,0,3", "2,4,7", "2,8,11"}; + + sw.setValue(SwitchLatchingSymbol.SwitchConfiguration._3x3); + sw.setPoleCount(PoleCount.THREE); + testSwitch(sw, validCombinations); + } + + @Test + public void testStratSwitch() { + SwitchLatchingSymbol sw = new SwitchLatchingSymbol(); + + String[] validCombinations = new String[] {"0,0,1", "0,4,5", "1,0,1", "1,4,5", "1,0,2", "1,4,6", + "2,0,2", "2,4,6", "3,0,2", "3,0,3", "3,4,6", "3,4,7", "4,0,3", "4,4,7"}; + + sw.setValue(SwitchLatchingSymbol.SwitchConfiguration._3x5xSHORT); + sw.setPoleCount(PoleCount.TWO); + testSwitch(sw, validCombinations); + } + + @Test + public void testON_OFF_ON() { + SwitchLatchingSymbol sw = new SwitchLatchingSymbol(); + + String[] validCombinations = new String[] {"0,0,1", "0,3,4", "2,0,2", "2,3,5"}; + + sw.setValue(SwitchLatchingSymbol.SwitchConfiguration._2x3xOFF); + sw.setPoleCount(PoleCount.TWO); + testSwitch(sw, validCombinations); + } +}