mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
add highlighting for open rotary switch
This commit is contained in:
+52
-1
@@ -32,6 +32,9 @@ import java.awt.geom.Rectangle2D;
|
|||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||||
|
|
||||||
import org.diylc.awt.StringUtils;
|
import org.diylc.awt.StringUtils;
|
||||||
@@ -41,6 +44,7 @@ import org.diylc.common.IPlugInPort;
|
|||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
import org.diylc.common.VerticalAlignment;
|
import org.diylc.common.VerticalAlignment;
|
||||||
import org.diylc.components.AbstractAngledComponent;
|
import org.diylc.components.AbstractAngledComponent;
|
||||||
|
import org.diylc.components.guitar.RotarySwitchOpenPositionPropertyValueSource;
|
||||||
import org.diylc.components.transform.AngledComponentTransformer;
|
import org.diylc.components.transform.AngledComponentTransformer;
|
||||||
import org.diylc.core.Angle;
|
import org.diylc.core.Angle;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
@@ -51,6 +55,7 @@ import org.diylc.core.Project;
|
|||||||
import org.diylc.core.Theme;
|
import org.diylc.core.Theme;
|
||||||
import org.diylc.core.VisibilityPolicy;
|
import org.diylc.core.VisibilityPolicy;
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
|
import org.diylc.core.annotations.DynamicEditableProperty;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
import org.diylc.core.annotations.KeywordPolicy;
|
import org.diylc.core.annotations.KeywordPolicy;
|
||||||
import org.diylc.core.gerber.IGerberComponentSimple;
|
import org.diylc.core.gerber.IGerberComponentSimple;
|
||||||
@@ -59,6 +64,8 @@ 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 static org.diylc.utils.SwitchUtils.getConnectedTerminals;
|
||||||
|
|
||||||
@ComponentDescriptor(name = "Rotary Switch (Open)", author = "Branislav Stojkovic",
|
@ComponentDescriptor(name = "Rotary Switch (Open)", author = "Branislav Stojkovic",
|
||||||
category = "Electro-Mechanical", instanceNamePrefix = "SW",
|
category = "Electro-Mechanical", instanceNamePrefix = "SW",
|
||||||
description = "Open rotary switch in several different switching configurations",
|
description = "Open rotary switch in several different switching configurations",
|
||||||
@@ -99,6 +106,9 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
private Point2D[] controlPoints = new Point2D[] {new Point2D.Double(0, 0)};
|
||||||
private double[] pointAngles;
|
private double[] pointAngles;
|
||||||
|
|
||||||
|
private Integer selectedPosition;
|
||||||
|
private Boolean highlightConnectedTerminals;
|
||||||
|
|
||||||
public RotarySwitchOpen() {
|
public RotarySwitchOpen() {
|
||||||
super();
|
super();
|
||||||
updateControlPoints();
|
updateControlPoints();
|
||||||
@@ -246,7 +256,6 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
|
|
||||||
bodyList.add(bodyArea);
|
bodyList.add(bodyArea);
|
||||||
|
|
||||||
|
|
||||||
int pinWidth = getClosestOdd(PIN_WIDTH.convertToPixels());
|
int pinWidth = getClosestOdd(PIN_WIDTH.convertToPixels());
|
||||||
int pinThickness = getClosestOdd(PIN_THICKNESS.convertToPixels());
|
int pinThickness = getClosestOdd(PIN_THICKNESS.convertToPixels());
|
||||||
|
|
||||||
@@ -350,11 +359,21 @@ 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;
|
||||||
|
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);
|
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]);
|
||||||
@@ -376,7 +395,15 @@ 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;
|
||||||
|
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);
|
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) {
|
||||||
@@ -562,6 +589,30 @@ public class RotarySwitchOpen extends AbstractAngledComponent<RotarySwitchOpenTy
|
|||||||
body = null;
|
body = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DynamicEditableProperty(source = RotarySwitchOpenPositionPropertyValueSource.class)
|
||||||
|
@EditableProperty(name = "Selected Position")
|
||||||
|
@Override
|
||||||
|
public Integer getSelectedPosition() {
|
||||||
|
return selectedPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedPosition(Integer selectedPosition) {
|
||||||
|
this.selectedPosition = selectedPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EditableProperty(name = "Highlight Connected")
|
||||||
|
@Override
|
||||||
|
public Boolean getHighlightConnectedTerminals() {
|
||||||
|
if (highlightConnectedTerminals == null) {
|
||||||
|
highlightConnectedTerminals = false;
|
||||||
|
}
|
||||||
|
return highlightConnectedTerminals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHighlightConnectedTerminals(Boolean highlightConnectedTerminals) {
|
||||||
|
this.highlightConnectedTerminals = highlightConnectedTerminals;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rectangle2D getCachingBounds() {
|
public Rectangle2D getCachingBounds() {
|
||||||
Shape[] body = getBody();
|
Shape[] body = getBody();
|
||||||
|
|||||||
+3
-7
@@ -291,7 +291,7 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
Point2D p = controlPoints[i];
|
Point2D p = controlPoints[i];
|
||||||
if (outlineMode) {
|
if (outlineMode) {
|
||||||
g2d.setColor(theme.getOutlineColor());
|
g2d.setColor(theme.getOutlineColor());
|
||||||
g2d.drawRect((int) (p.getX() - lugWidth / 2), (int) (p.getY() - lugHeight / 2), lugWidth,
|
g2d.drawRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
||||||
lugHeight);
|
lugHeight);
|
||||||
} else {
|
} else {
|
||||||
int finalI = i;
|
int finalI = i;
|
||||||
@@ -303,14 +303,10 @@ public class SlideSwitch extends AbstractTransparentComponent<SlideSwitchType> i
|
|||||||
} else {
|
} else {
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
|
g2d.setColor(ISwitch.POLE_COLORS[groupIndex]);
|
||||||
}
|
}
|
||||||
g2d.fillRect((int) (p.getX() - lugWidth / 2), (int) (p.getY() - lugHeight / 2), lugWidth,
|
g2d.fillRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
||||||
lugHeight);
|
lugHeight);
|
||||||
if (groupIndex < 0) {
|
|
||||||
g2d.setColor(TERMINAL_COLOR.darker());
|
g2d.setColor(TERMINAL_COLOR.darker());
|
||||||
} else {
|
g2d.drawRect((int) (p.getX() - lugWidth / 2d), (int) (p.getY() - lugHeight / 2d), lugWidth,
|
||||||
g2d.setColor(ISwitch.POLE_COLORS[groupIndex].darker());
|
|
||||||
}
|
|
||||||
g2d.drawRect((int) (p.getX() - lugWidth / 2), (int) (p.getY() - lugHeight / 2), lugWidth,
|
|
||||||
lugHeight);
|
lugHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package org.diylc.components.guitar;
|
||||||
|
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
|
import org.diylc.components.electromechanical.RotarySwitchOpenType;
|
||||||
|
import org.diylc.components.electromechanical.ToggleSwitchType;
|
||||||
|
import org.diylc.core.AbstractDynamicPropertyValueSource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class RotarySwitchOpenPositionPropertyValueSource extends AbstractDynamicPropertyValueSource {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Object> getAvailableValues() {
|
||||||
|
if (properties == null) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
Optional<PropertyWrapper> optionalPropertyWrapper = this.properties.stream().filter(p -> {
|
||||||
|
try {
|
||||||
|
return p.getGetter().getName().equals("getValue");
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).findFirst();
|
||||||
|
if (optionalPropertyWrapper.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
RotarySwitchOpenType
|
||||||
|
switchType = (RotarySwitchOpenType) optionalPropertyWrapper.get().getValue();
|
||||||
|
int positionCount = switchType.getPositionCount();
|
||||||
|
List<Object> res = new ArrayList<>();
|
||||||
|
res.add(null);
|
||||||
|
for (int i = 0; i < positionCount; i++) {
|
||||||
|
res.add(i);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user