merged changes

This commit is contained in:
Bane Stojkovic
2025-03-11 23:42:56 +01:00
parent f966f8873a
commit 6e919714d3
17 changed files with 438 additions and 60 deletions
@@ -35,19 +35,9 @@ public enum Orientation {
}
public double toDegrees() {
switch (this) {
case DEFAULT:
return 0;
case _180:
return 180;
case _270:
return 270;
case _90:
return 90;
default:
break;
}
return 0;
if (this == DEFAULT)
return 0;
return Integer.parseInt(name().replace("_", ""));
}
public double toRadians() {
@@ -0,0 +1,46 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package org.diylc.common;
public enum Orientation45 {
DEFAULT, _45, _90, _135, _180, _225, _270, _315;
@Override
public String toString() {
if (this == DEFAULT) {
return "Default";
} else {
return name().replace("_", "") + " degrees clockwise";
}
}
public double toDegrees() {
if (this == DEFAULT)
return 0;
return Integer.parseInt(name().replace("_", ""));
}
public double toRadians() {
return Math.toRadians(toDegrees());
}
}
@@ -72,7 +72,7 @@ public enum IconLoader {
BufferedImage img = null;
try {
img = ImageIO.read(getClass().getResourceAsStream("/images/" + name));
} catch (IOException e) {
} catch (Exception e) {
Logger.getLogger(IconLoader.class).error("Couldn't find file: " + name);
}
return img;
@@ -27,9 +27,9 @@ import java.util.Set;
import org.diylc.core.IDIYComponent;
public abstract class NetlistAnalyzer {
public abstract class AbstractNetlistAnalyzer {
public NetlistAnalyzer() {
public AbstractNetlistAnalyzer() {
}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput)
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.diylc.core.IDIYComponent;
@@ -59,10 +60,6 @@ public class Netlist implements Comparable<Netlist> {
return switchSetup;
}
public void done() {
Collections.sort(switchSetup);
}
@Override
public int hashCode() {
final int prime = 31;
@@ -88,10 +85,15 @@ public class Netlist implements Comparable<Netlist> {
return true;
}
public String getSwitchSetupString() {
return getSwitchSetup().isEmpty() ? "[ ALL ]" : "[ " +
getSwitchSetup().stream().map(x -> x.toString()).collect(Collectors.joining(",")) + " ]";
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Switch setup: ").append(getSwitchSetup()).append("\n\n");
sb.append("Switch setup: ").append(getSwitchSetupString()).append("\n\n");
List<Group> list = getSortedGroups();
for (Group g : list) {
sb.append("\t").append(g).append("\n");
@@ -19,15 +19,7 @@ package org.diylc.netlist;
import java.awt.geom.Area;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.log4j.Logger;
@@ -191,10 +183,29 @@ public class NetlistBuilder {
// sort everything alphabetically
List<Netlist> netlists = new ArrayList<Netlist>(result.keySet());
Collections.sort(netlists);
netlists.forEach(netlist -> cleanupRedundantSwitches(netlist.getSwitchSetup()));
return netlists;
}
public static void cleanupRedundantSwitches(List<SwitchSetup> switchSetups) {
Map<ISwitch, Set<Integer>> positionCountMap = new HashMap<>();
switchSetups.forEach(s -> s.getPositions().forEach(pos -> {
positionCountMap.computeIfAbsent(pos.getSwitch(), k -> new HashSet<Integer>()).add(pos.getPosition());
}));
// find switches that are here in all the positions, meaning that they don't affect the circuit
Set<ISwitch> switchesToPrune = positionCountMap.entrySet().stream()
.filter(e -> e.getKey().getPositionCount() == e.getValue().size())
.map(x -> x.getKey())
.collect(Collectors.toSet());
switchSetups.forEach(s -> s.getPositions().removeIf(x -> switchesToPrune.contains(x.getSwitch())));
switchSetups.removeIf(x -> x.getPositions().isEmpty());
HashSet<SwitchSetup> uniqueSetups = new HashSet<>(switchSetups);
switchSetups.clear();
switchSetups.addAll(uniqueSetups);
switchSetups.sort(Comparator.comparing(x -> x.toString()));
}
public static Netlist buildNetlist(List<IDIYComponent<?>> components, Collection<Node> nodes,
Collection<ContinuityArea> continuityAreas, Collection<Connection> connections) {
ImmutableGraph<ProjectGraphNode> graph = buildGraph(nodes, continuityAreas, connections);
@@ -172,10 +172,10 @@ public class Tree {
}
public String toAsciiString() {
return String.join("<br>", toAscii());
return String.join("<br>", toAsciiLines());
}
private List<String> toAscii() {
private List<String> toAsciiLines() {
if (leaf != null) {
return Arrays.asList(TreeAsciiUtil.generateString(TreeAsciiUtil.BOXH,
1) + " " + leaf.toHTML() + " " + TreeAsciiUtil.generateString(TreeAsciiUtil.BOXH, 1));
@@ -184,7 +184,7 @@ public class Tree {
List<Tree> children = getOrderedChildren();
List<List<String>> childrenAscii =
children.stream().map(c -> c.toAscii()).collect(Collectors.toList());
children.stream().map(c -> c.toAsciiLines()).collect(Collectors.toList());
if (TreeConnectionType.Series.equals(connectionType)) {
return TreeAsciiUtil.concatenateMultiLineSerial(
@@ -36,11 +36,7 @@ import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.clipboard.ComponentTransferable;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
import org.diylc.common.Orientation;
import org.diylc.common.OrientationHV;
import org.diylc.common.PropertyWrapper;
import org.diylc.common.*;
import org.diylc.core.Angle;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
@@ -437,6 +433,7 @@ public class InstantiationManager {
for (PropertyWrapper propertyWrapper : properties) {
if (propertyWrapper.getType().getName().equals(Orientation.class.getName())
|| propertyWrapper.getType().getName().equals(OrientationHV.class.getName())
|| propertyWrapper.getType().getName().equals(Orientation45.class.getName())
|| propertyWrapper.getName().equalsIgnoreCase("angle")) {
angleProperty = propertyWrapper;
break;
@@ -456,6 +453,9 @@ public class InstantiationManager {
} else if (value instanceof OrientationHV) {
angleProperty.setValue(OrientationHV.values()[(((OrientationHV) value).ordinal() + 1)
% OrientationHV.values().length]);
} else if (value instanceof Orientation45) {
angleProperty.setValue(Orientation45.values()[(((Orientation45) value).ordinal() + 1)
% Orientation45.values().length]);
} else if (value instanceof Angle) {
Angle angle = (Angle) angleProperty.getValue();
Angle newAngle = angle.rotate(1);
@@ -32,7 +32,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -50,7 +49,6 @@ import javax.swing.JOptionPane;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.IConfigListener;
import org.diylc.appframework.miscutils.IConfigurationManager;
import org.diylc.appframework.miscutils.JarScanner;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.appframework.simplemq.MessageDispatcher;
import org.diylc.appframework.update.Version;
@@ -88,7 +86,7 @@ import org.diylc.core.measures.SizeUnit;
import org.diylc.lang.LangUtil;
import org.diylc.netlist.INetlistParser;
import org.diylc.netlist.Netlist;
import org.diylc.netlist.NetlistAnalyzer;
import org.diylc.netlist.AbstractNetlistAnalyzer;
import org.diylc.netlist.NetlistBuilder;
import org.diylc.netlist.NetlistException;
import org.diylc.serialization.ProjectFileManager;
@@ -2030,7 +2028,7 @@ public class Presenter implements IPlugInPort, IConfigListener {
if (netlists == null)
return;
List<Set<IDIYComponent<?>>> allGroups = NetlistAnalyzer.extractComponentGroups(netlists);
List<Set<IDIYComponent<?>>> allGroups = AbstractNetlistAnalyzer.extractComponentGroups(netlists);
// Find control points of all selected components and all types
Set<String> selectedNamePrefixes = new HashSet<String>();
if (expansionMode == ExpansionMode.SAME_TYPE) {
@@ -56,4 +56,15 @@ public class TreeAsciiUtilTest {
// assertEquals("yy-yyy", result.get(1));
// assertEquals("&nbsp;&nbsp;&nbsp;aaa", result.get(2));
}
@Test
public void testSimpleParallel() {
List<String> result = TreeAsciiUtil.concatenateMultiLineParallel(
Arrays.asList(Arrays.asList("xx"), Arrays.asList("yy")));
assertNotNull(result);
assertEquals(3, result.size());
assertEquals("&nbsp;&#x250C;xx&#x2510;&nbsp;", result.get(0));
assertEquals("&#x2500;&#x2524;&nbsp;&nbsp;&#x251C;&#x2500;", result.get(1));
assertEquals("&nbsp;&#x2514;yy&#x2518;&nbsp;", result.get(2));
}
}