mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
slide switch highlighting
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package org.diylc.core;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class AbstractDynamicPropertyValueSource implements IDynamicPropertySource {
|
||||
|
||||
protected List<PropertyWrapper> properties;
|
||||
protected IDIYComponent<?> component;
|
||||
|
||||
@Override
|
||||
public void setProperties(List<PropertyWrapper> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComponent(IDIYComponent<?> component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayValue(Object value) {
|
||||
if (value == null) {
|
||||
return "None";
|
||||
}
|
||||
if (component instanceof ISwitch sw) {
|
||||
return sw.getPositionName((Integer)value);
|
||||
}
|
||||
return "#" + (((Integer)value) + 1);
|
||||
}
|
||||
}
|
||||
@@ -27,63 +27,68 @@ import java.util.*;
|
||||
|
||||
public class SwitchUtils {
|
||||
|
||||
public static List<Set<Integer>> getConnectedTerminals(ISwitch switchComponent, int numPoints) {
|
||||
List<Set<Integer>> connectedGroups = new ArrayList<>();
|
||||
|
||||
// Only process if we have a selected position and should render connections
|
||||
if (switchComponent.getSelectedPosition() == null || !Boolean.TRUE.equals(switchComponent.getHighlightConnectedTerminals())) {
|
||||
return connectedGroups;
|
||||
}
|
||||
public static List<Set<Integer>> getConnectedTerminals(ISwitch switchComponent, int numPoints) {
|
||||
|
||||
// First, collect all direct connections
|
||||
List<int[]> connections = new ArrayList<>();
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
for (int j = i + 1; j < numPoints; j++) {
|
||||
if (switchComponent.arePointsConnected(i, j, switchComponent.getSelectedPosition())) {
|
||||
connections.add(new int[]{i, j});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a map to track which points are in which group
|
||||
Map<Integer, Set<Integer>> pointToGroup = new HashMap<>();
|
||||
|
||||
// Process each connection
|
||||
for (int[] connection : connections) {
|
||||
int p1 = connection[0];
|
||||
int p2 = connection[1];
|
||||
|
||||
Set<Integer> group1 = pointToGroup.get(p1);
|
||||
Set<Integer> group2 = pointToGroup.get(p2);
|
||||
|
||||
if (group1 == null && group2 == null) {
|
||||
// Create new group
|
||||
Set<Integer> newGroup = new HashSet<>();
|
||||
newGroup.add(p1);
|
||||
newGroup.add(p2);
|
||||
pointToGroup.put(p1, newGroup);
|
||||
pointToGroup.put(p2, newGroup);
|
||||
} else if (group1 == null) {
|
||||
// Add p1 to p2's group
|
||||
group2.add(p1);
|
||||
pointToGroup.put(p1, group2);
|
||||
} else if (group2 == null) {
|
||||
// Add p2 to p1's group
|
||||
group1.add(p2);
|
||||
pointToGroup.put(p2, group1);
|
||||
} else if (group1 != group2) {
|
||||
// Merge groups
|
||||
group1.addAll(group2);
|
||||
for (Integer p : group2) {
|
||||
pointToGroup.put(p, group1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect unique groups
|
||||
Set<Set<Integer>> uniqueGroups = new HashSet<>(pointToGroup.values());
|
||||
connectedGroups.addAll(uniqueGroups);
|
||||
|
||||
return connectedGroups;
|
||||
if (!Boolean.TRUE.equals(switchComponent.getHighlightConnectedTerminals())) {
|
||||
return List.of();
|
||||
}
|
||||
List<Set<Integer>> connectedGroups = new ArrayList<>();
|
||||
|
||||
// Only process if we have a selected position and should render connections
|
||||
if (switchComponent.getSelectedPosition() == null || !Boolean.TRUE.equals(
|
||||
switchComponent.getHighlightConnectedTerminals())) {
|
||||
return connectedGroups;
|
||||
}
|
||||
|
||||
// First, collect all direct connections
|
||||
List<int[]> connections = new ArrayList<>();
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
for (int j = i + 1; j < numPoints; j++) {
|
||||
if (switchComponent.arePointsConnected(i, j, switchComponent.getSelectedPosition())) {
|
||||
connections.add(new int[] {i, j});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a map to track which points are in which group
|
||||
Map<Integer, Set<Integer>> pointToGroup = new HashMap<>();
|
||||
|
||||
// Process each connection
|
||||
for (int[] connection : connections) {
|
||||
int p1 = connection[0];
|
||||
int p2 = connection[1];
|
||||
|
||||
Set<Integer> group1 = pointToGroup.get(p1);
|
||||
Set<Integer> group2 = pointToGroup.get(p2);
|
||||
|
||||
if (group1 == null && group2 == null) {
|
||||
// Create new group
|
||||
Set<Integer> newGroup = new HashSet<>();
|
||||
newGroup.add(p1);
|
||||
newGroup.add(p2);
|
||||
pointToGroup.put(p1, newGroup);
|
||||
pointToGroup.put(p2, newGroup);
|
||||
} else if (group1 == null) {
|
||||
// Add p1 to p2's group
|
||||
group2.add(p1);
|
||||
pointToGroup.put(p1, group2);
|
||||
} else if (group2 == null) {
|
||||
// Add p2 to p1's group
|
||||
group1.add(p2);
|
||||
pointToGroup.put(p2, group1);
|
||||
} else if (group1 != group2) {
|
||||
// Merge groups
|
||||
group1.addAll(group2);
|
||||
for (Integer p : group2) {
|
||||
pointToGroup.put(p, group1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect unique groups
|
||||
Set<Set<Integer>> uniqueGroups = new HashSet<>(pointToGroup.values());
|
||||
connectedGroups.addAll(uniqueGroups);
|
||||
|
||||
return connectedGroups;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user