mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
show markers for rotary switch
This commit is contained in:
@@ -83,6 +83,4 @@ public interface ISwitch extends IContinuity {
|
|||||||
}
|
}
|
||||||
return arePointsConnected(index1, index2, getSelectedPosition());
|
return arePointsConnected(index1, index2, getSelectedPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> getCommonPoints();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,24 +27,48 @@ import java.util.*;
|
|||||||
|
|
||||||
public class SwitchUtils {
|
public class SwitchUtils {
|
||||||
|
|
||||||
public static Map<Integer, List<List<Integer>>> getSwitchingMatrix(ISwitch switchComponent, int numPoints) {
|
public static String[] getSwitchingMarkers(ISwitch switchComponent, int numPoints, boolean verbose) {
|
||||||
Map<Integer, List<List<Integer>>> result = new HashMap<>();
|
String[] markers = new String[numPoints];
|
||||||
|
List<List<Set<Integer>>> switchingMatrix = new ArrayList<>();
|
||||||
for (Integer commonPoint : switchComponent.getCommonPoints()) {
|
for (int p = 0; p < switchComponent.getPositionCount(); p++) {
|
||||||
List<List<Integer>> connectedPoints = new ArrayList<>();
|
List<Set<Integer>> connectedPoints = new ArrayList<>();
|
||||||
result.put(commonPoint, connectedPoints);
|
switchingMatrix.add(connectedPoints);
|
||||||
for (int i = 0; i < switchComponent.getPositionCount(); i++) {
|
for (int i = 0; i < numPoints - 1; i++) {
|
||||||
List<Integer> positionPoints = new ArrayList<>();
|
for (int j = i + 1; j < numPoints; j++) {
|
||||||
for (int j = 0; j < numPoints; j++) {
|
if (switchComponent.arePointsConnected(i, j, p)) {
|
||||||
if (commonPoint != j && switchComponent.arePointsConnected(commonPoint, j, i)) {
|
connectedPoints.add(Set.of(i, j));
|
||||||
positionPoints.add(j);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connectedPoints.add(positionPoints);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<Integer> commonPoints = new ArrayList<>();
|
||||||
return result;
|
for (int i = 0; i < numPoints; i++) {
|
||||||
|
final int finalI = i;
|
||||||
|
if (switchingMatrix.stream().allMatch(
|
||||||
|
l -> l.stream().anyMatch(
|
||||||
|
s -> s.contains(finalI)))) {
|
||||||
|
markers[i] = String.valueOf((char)((int)'A' + commonPoints.size()));
|
||||||
|
commonPoints.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int p = 0; p < switchComponent.getPositionCount(); p++) {
|
||||||
|
for (int c : commonPoints) {
|
||||||
|
for (int i = 0; i < numPoints; i++) {
|
||||||
|
if (commonPoints.contains(i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (switchComponent.arePointsConnected(Math.min(c, i), Math.max(c, i), p)) {
|
||||||
|
String marker = verbose ? markers[c] + (p + 1) : Integer.toString(p + 1);
|
||||||
|
if (markers[i] == null) {
|
||||||
|
markers[i] = marker;
|
||||||
|
} else {
|
||||||
|
markers[i] += "," + marker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return markers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Set<Integer>> getConnectedTerminals(ISwitch switchComponent, int numPoints) {
|
public static List<Set<Integer>> getConnectedTerminals(ISwitch switchComponent, int numPoints) {
|
||||||
|
|||||||
+10
-78
@@ -63,6 +63,7 @@ import org.diylc.core.measures.Size;
|
|||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.presenter.AreaUtils;
|
import org.diylc.presenter.AreaUtils;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
import org.diylc.utils.SwitchUtils;
|
||||||
|
|
||||||
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
import static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
||||||
|
|
||||||
@@ -358,21 +359,11 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
int commonPinCount = 2;
|
int commonPinCount = 2;
|
||||||
int secondLevelStart = 2 * configuration.getPositionCount() + commonPinCount;
|
int secondLevelStart = 2 * configuration.getPositionCount() + commonPinCount;
|
||||||
|
|
||||||
List<Set<Integer>> connectedTerminals = getConnectedTerminals(this, controlPoints.length);
|
|
||||||
|
|
||||||
// Draw outer pins
|
// Draw outer pins
|
||||||
if (configuration.getNeedsSecondLevel()) {
|
if (configuration.getNeedsSecondLevel()) {
|
||||||
drawingObserver.startTrackingContinuityArea(true);
|
drawingObserver.startTrackingContinuityArea(true);
|
||||||
for (int i = secondLevelStart; i < body.length; i++) {
|
for (int i = secondLevelStart; i < body.length; i++) {
|
||||||
int finalI = i;
|
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : pinColor);
|
||||||
int groupIndex = IntStream.range(0, connectedTerminals.size())
|
|
||||||
.filter(j -> connectedTerminals.get(j).contains(finalI))
|
|
||||||
.findFirst().orElse(-1);
|
|
||||||
if (groupIndex < 0) {
|
|
||||||
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : pinColor);
|
|
||||||
} else {
|
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
|
|
||||||
}
|
|
||||||
g2d.fill(body[i]);
|
g2d.fill(body[i]);
|
||||||
g2d.setColor(outlineMode ? finalBorderColor : pinColor.darker());
|
g2d.setColor(outlineMode ? finalBorderColor : pinColor.darker());
|
||||||
g2d.draw(body[i]);
|
g2d.draw(body[i]);
|
||||||
@@ -394,15 +385,7 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
// Draw pins
|
// Draw pins
|
||||||
for (int i = 1; i <= secondLevelStart; i++) {
|
for (int i = 1; i <= secondLevelStart; i++) {
|
||||||
drawingObserver.startTrackingContinuityArea(true);
|
drawingObserver.startTrackingContinuityArea(true);
|
||||||
int finalI = i;
|
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : pinColor);
|
||||||
int groupIndex = IntStream.range(0, connectedTerminals.size())
|
|
||||||
.filter(j -> connectedTerminals.get(j).contains(finalI))
|
|
||||||
.findFirst().orElse(-1);
|
|
||||||
if (groupIndex < 0) {
|
|
||||||
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : pinColor);
|
|
||||||
} else {
|
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
|
|
||||||
}
|
|
||||||
g2d.fill(body[i]);
|
g2d.fill(body[i]);
|
||||||
drawingObserver.stopTrackingContinuityArea();
|
drawingObserver.stopTrackingContinuityArea();
|
||||||
if (!outlineMode) {
|
if (!outlineMode) {
|
||||||
@@ -417,6 +400,9 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
// StringUtils.drawCenteredText(g2d, name, controlPoints[0].getX(), controlPoints[0].getY(),
|
// StringUtils.drawCenteredText(g2d, name, controlPoints[0].getX(), controlPoints[0].getY(),
|
||||||
// HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
// HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
|
|
||||||
|
String[] switchingMarkers =
|
||||||
|
SwitchUtils.getSwitchingMarkers(this, this.getControlPointCount(), false);
|
||||||
|
|
||||||
if (showMarkers) {
|
if (showMarkers) {
|
||||||
g2d.setColor(labelColor);
|
g2d.setColor(labelColor);
|
||||||
int innerPinSpacing = getClosestOdd(INNER_PIN_SPACING.convertToPixels());
|
int innerPinSpacing = getClosestOdd(INNER_PIN_SPACING.convertToPixels());
|
||||||
@@ -429,7 +415,7 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
+ Math.cos(pointAngles[i + 1]) * relativeLabelLocation * innerPinSpacing / 2);
|
+ Math.cos(pointAngles[i + 1]) * relativeLabelLocation * innerPinSpacing / 2);
|
||||||
int y = (int) (firstPoint.getY()
|
int y = (int) (firstPoint.getY()
|
||||||
+ Math.sin(pointAngles[i + 1]) * relativeLabelLocation * innerPinSpacing / 2);
|
+ Math.sin(pointAngles[i + 1]) * relativeLabelLocation * innerPinSpacing / 2);
|
||||||
StringUtils.drawCenteredText(g2d, getControlPointNodeNameForRender(i + 1), x, y,
|
StringUtils.drawCenteredText(g2d, switchingMarkers[i + 1], x, y,
|
||||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
}
|
}
|
||||||
relativeLabelLocation = 0.65;
|
relativeLabelLocation = 0.65;
|
||||||
@@ -438,7 +424,7 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
* relativeLabelLocation * innerCommonPinSpacing / 2);
|
* relativeLabelLocation * innerCommonPinSpacing / 2);
|
||||||
int y = (int) (firstPoint.getY() + Math.sin(pointAngles[i + outerPinCount + 1])
|
int y = (int) (firstPoint.getY() + Math.sin(pointAngles[i + outerPinCount + 1])
|
||||||
* relativeLabelLocation * innerCommonPinSpacing / 2);
|
* relativeLabelLocation * innerCommonPinSpacing / 2);
|
||||||
StringUtils.drawCenteredText(g2d, getControlPointNodeNameForRender(i + outerPinCount + 1),
|
StringUtils.drawCenteredText(g2d, switchingMarkers[i + outerPinCount + 1],
|
||||||
x, y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
x, y, HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +439,7 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
int y = (int) (firstPoint.getY() + Math.sin(pointAngles[i + 1 + secondLevelStart])
|
int y = (int) (firstPoint.getY() + Math.sin(pointAngles[i + 1 + secondLevelStart])
|
||||||
* relativeLabelLocation * outerPinSpacing / 2);
|
* relativeLabelLocation * outerPinSpacing / 2);
|
||||||
StringUtils.drawCenteredText(g2d,
|
StringUtils.drawCenteredText(g2d,
|
||||||
getControlPointNodeNameForRender(i + 1 + secondLevelStart), x, y,
|
switchingMarkers[i + secondLevelStart + 1], x, y,
|
||||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
}
|
}
|
||||||
// relativeLabelLocation = 0.90;
|
// relativeLabelLocation = 0.90;
|
||||||
@@ -465,7 +451,7 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
+ Math.sin(pointAngles[i + outerPinCount + 1 + secondLevelStart])
|
+ Math.sin(pointAngles[i + outerPinCount + 1 + secondLevelStart])
|
||||||
* relativeLabelLocation * outerCommonPinSpacing / 2);
|
* relativeLabelLocation * outerCommonPinSpacing / 2);
|
||||||
StringUtils.drawCenteredText(g2d,
|
StringUtils.drawCenteredText(g2d,
|
||||||
getControlPointNodeNameForRender(i + outerPinCount + 1 + secondLevelStart), x, y,
|
switchingMarkers[i + outerPinCount + secondLevelStart + 1], x, y,
|
||||||
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -644,60 +630,6 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
return Integer.toString(position + 1);
|
return Integer.toString(position + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getControlPointNodeNameForRender(int index) {
|
|
||||||
int commonPinCount = 2;
|
|
||||||
int positionCount = configuration.getPositionCount();
|
|
||||||
|
|
||||||
if (index <= positionCount) {
|
|
||||||
return Integer.toString(positionCount + 1 - index);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount) {
|
|
||||||
return Integer.toString(2 * positionCount + 1 - index);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount + commonPinCount) {
|
|
||||||
return Character.toString((char) ('A' + (index - 2 * positionCount - 1)));
|
|
||||||
}
|
|
||||||
int secondLevelStart = 2 * positionCount + commonPinCount;
|
|
||||||
if (index <= positionCount + secondLevelStart) {
|
|
||||||
return Integer.toString(positionCount + 1 - index + secondLevelStart);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount + secondLevelStart) {
|
|
||||||
return Integer.toString(2 * positionCount + 1 - index + secondLevelStart);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount + commonPinCount + secondLevelStart) {
|
|
||||||
return Character.toString((char) ('C' + (index - 2 * positionCount - 1 - secondLevelStart)));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getControlPointNodeName(int index) {
|
|
||||||
int commonPinCount = 2;
|
|
||||||
int positionCount = configuration.getPositionCount();
|
|
||||||
|
|
||||||
if (index <= positionCount) {
|
|
||||||
return "A" + (positionCount + 1 - index);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount) {
|
|
||||||
return "B" + (2 * positionCount + 1 - index);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount + commonPinCount) {
|
|
||||||
return Character.toString((char) ('A' + (index - 2 * positionCount - 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
int secondLevelStart = 2 * positionCount + commonPinCount;
|
|
||||||
if (index <= positionCount + secondLevelStart) {
|
|
||||||
return "C" + (positionCount + 1 - index + secondLevelStart);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount + secondLevelStart) {
|
|
||||||
return "D" + (2 * positionCount + 1 - index + secondLevelStart);
|
|
||||||
}
|
|
||||||
if (index <= 2 * positionCount + commonPinCount + secondLevelStart) {
|
|
||||||
return Character.toString((char) ('C' + (index - 2 * positionCount - 1 - secondLevelStart)));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean arePointsConnected(int index1, int index2, int position) {
|
public boolean arePointsConnected(int index1, int index2, int position) {
|
||||||
if (index1 == 0)
|
if (index1 == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user