Split trace layer

This commit is contained in:
Bane Stojkovic
2026-11-12 13:42:04 +01:00
parent 4aab04f751
commit 6e3f72dfb6
26 changed files with 684 additions and 83 deletions
@@ -37,6 +37,7 @@ import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.core.LayerIds;
import org.diylc.swing.ISwingUI;
public class LayersMenuPlugin implements IPlugIn {
@@ -53,14 +54,14 @@ public class LayersMenuPlugin implements IPlugIn {
visibleActionMap = new HashMap<Layer, Action>();
selectAllActionMap = new HashMap<Integer, Action>();
for (Layer layer : Layer.values()) {
final int zOrder = layer.getZOrder();
final int layerId = layer.getLayerId();
AbstractAction lockAction = new AbstractAction("Lock") {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
LayersMenuPlugin.this.plugInPort.setLayerLocked(zOrder, (Boolean) getValue(Action.SELECTED_KEY));
LayersMenuPlugin.this.plugInPort.setLayerLocked(layerId, (Boolean) getValue(Action.SELECTED_KEY));
// selectAllActionMap.get(zOrder).setEnabled(!(Boolean) getValue(Action.SELECTED_KEY));
}
};
@@ -73,13 +74,15 @@ public class LayersMenuPlugin implements IPlugIn {
@Override
public void actionPerformed(ActionEvent e) {
LayersMenuPlugin.this.plugInPort.setLayerVisibility(zOrder, getValue(Action.SELECTED_KEY) == null ? true : (Boolean) getValue(Action.SELECTED_KEY));
LayersMenuPlugin.this.plugInPort.setLayerVisibility(layerId, getValue(Action.SELECTED_KEY) == null ? true : (Boolean) getValue(Action.SELECTED_KEY));
// selectAllActionMap.get(zOrder).setEnabled(!(Boolean) getValue(Action.SELECTED_KEY));
}
};
visibleAction.putValue(IView.CHECK_BOX_MENU_ITEM, true);
visibleAction.putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_0 + zOrder,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
// the shortcuts follow the menu order, Ctrl+1 for the first layer
visibleAction.putValue(AbstractAction.ACCELERATOR_KEY,
KeyStroke.getKeyStroke(KeyEvent.VK_1 + layer.ordinal(),
Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
visibleActionMap.put(layer, visibleAction);
AbstractAction selectAllAction = new AbstractAction("Select All") {
@@ -88,10 +91,10 @@ public class LayersMenuPlugin implements IPlugIn {
@Override
public void actionPerformed(ActionEvent e) {
LayersMenuPlugin.this.plugInPort.selectAll(zOrder);
LayersMenuPlugin.this.plugInPort.selectAll(layerId);
}
};
selectAllActionMap.put(zOrder, selectAllAction);
selectAllActionMap.put(layerId, selectAllAction);
swingUI.injectSubmenu(layer.title, null, LOCK_LAYERS_TITLE);
swingUI.injectMenuAction(visibleAction, layer.title);
@@ -116,34 +119,38 @@ public class LayersMenuPlugin implements IPlugIn {
if (eventType == EventType.LAYER_STATE_CHANGED) {
Set<Integer> lockedLayers = (Set<Integer>) params[0];
for (Layer layer : Layer.values()) {
lockActionMap.get(layer).putValue(Action.SELECTED_KEY, lockedLayers.contains(layer.getZOrder()));
lockActionMap.get(layer).putValue(Action.SELECTED_KEY, lockedLayers.contains(layer.getLayerId()));
}
} else if (eventType == EventType.LAYER_VISIBILITY_CHANGED) {
Set<Integer> hiddenLayers = (Set<Integer>) params[0];
for (Layer layer : Layer.values()) {
visibleActionMap.get(layer).putValue(Action.SELECTED_KEY, !hiddenLayers.contains(layer.getZOrder()));
visibleActionMap.get(layer).putValue(Action.SELECTED_KEY, !hiddenLayers.contains(layer.getLayerId()));
}
}
}
// in menu order, which also gives the shortcuts
static enum Layer {
CHASSIS("Chassis", IDIYComponent.CHASSIS), BOARD("Board", IDIYComponent.BOARD), TRACE("Trace", IDIYComponent.TRACE), COMPONENT(
"Component", IDIYComponent.COMPONENT), WIRING("Wiring", IDIYComponent.WIRING), TEXT("Text", IDIYComponent.TEXT);
CHASSIS("Chassis", IDIYComponent.CHASSIS), BOARD("Board", IDIYComponent.BOARD),
BOTTOM_TRACES("Bottom Traces", LayerIds.BOTTOM_TRACES),
TOP_TRACES("Top Traces", LayerIds.TOP_TRACES),
COMPONENT("Component", IDIYComponent.COMPONENT), WIRING("Wiring", IDIYComponent.WIRING),
TEXT("Text", IDIYComponent.TEXT);
String title;
int zOrder;
int layerId;
private Layer(String title, int order) {
private Layer(String title, int layerId) {
this.title = title;
zOrder = order;
this.layerId = layerId;
}
public String getTitle() {
return title;
}
public int getZOrder() {
return zOrder;
public int getLayerId() {
return layerId;
}
}
}
@@ -734,3 +734,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Dezimal (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Kupfer unter der Platine abblenden
Board Side|Platinenseite
Bottom Traces|Leiterbahnen unten
Top Traces|Leiterbahnen oben
@@ -727,3 +727,5 @@ Decimal (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)
Fade Copper Under Board
Board Side
Bottom Traces
Top Traces
@@ -730,3 +730,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Decimal (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Atenuar cobre bajo la placa
Board Side|Lado de la placa
Bottom Traces|Trazos inferiores
Top Traces|Trazos superiores
@@ -729,3 +729,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Décimale (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Estomper le cuivre sous la carte
Board Side|Côté de la carte
Bottom Traces|Pistes du dessous
Top Traces|Pistes du dessus
@@ -731,3 +731,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Decimale (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Attenua il rame sotto la scheda
Board Side|Lato della scheda
Bottom Traces|Tracce inferiori
Top Traces|Tracce superiori
@@ -735,3 +735,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Decimaal (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Koper onder de print vervagen
Board Side|Printzijde
Bottom Traces|Sporen onderkant
Top Traces|Sporen bovenkant
@@ -730,3 +730,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Decimal (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Esmaecer cobre sob a placa
Board Side|Lado da placa
Bottom Traces|Traçados inferiores
Top Traces|Traçados superiores
@@ -726,3 +726,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|Decimalni (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|Prigušen Bakar Ispod Ploče
Board Side|Strana Ploče
Bottom Traces|Donji Vodovi
Top Traces|Gornji Vodovi
@@ -728,3 +728,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|दशमलव (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|बोर्ड के नीचे तांबा धुंधला करें
Board Side|बोर्ड का पक्ष
Bottom Traces|नीचे के ट्रेस
Top Traces|ऊपर के ट्रेस
@@ -728,3 +728,5 @@ Decimal (4.7K, 0.22uF, 6.3V)|小数 (4.7K, 0.22uF, 6.3V)
RKM (4K7, 0u22, 6V3)|RKM (4K7, 0u22, 6V3)
Fade Copper Under Board|淡化板下铜箔
Board Side|板面
Bottom Traces|底层走线
Top Traces|顶层走线
@@ -0,0 +1,116 @@
/*
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2025 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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.diylc.common.PCBLayer;
import org.diylc.common.PropertyWrapper;
import org.diylc.components.connectivity.CopperTrace;
import org.diylc.components.connectivity.Jumper;
import org.diylc.components.connectivity.Via;
import org.diylc.core.LayerIds;
import org.diylc.core.Project;
import org.junit.Before;
import org.junit.Test;
public class TraceLayerTests extends TestBase {
private CopperTrace bottomTrace;
private CopperTrace topTrace;
private Via via;
private Jumper jumper;
@Before
public void setUp() {
bottomTrace = trace(PCBLayer._1);
topTrace = trace(PCBLayer._2);
via = new Via();
jumper = new Jumper();
presenter.getCurrentProject().getComponents()
.addAll(Arrays.asList(bottomTrace, topTrace, via, jumper));
}
@Test
public void testSelectAllOfATraceLayer() {
presenter.selectAll(LayerIds.BOTTOM_TRACES);
assertEquals(new HashSet<Object>(Arrays.asList(bottomTrace, via)),
new HashSet<Object>(presenter.getSelectedComponents()));
presenter.selectAll(LayerIds.TOP_TRACES);
assertEquals(new HashSet<Object>(Arrays.asList(topTrace, via, jumper)),
new HashSet<Object>(presenter.getSelectedComponents()));
}
@Test
public void testLockingBottomTracesLocksTheViaButNotTheTopSide() {
presenter.setLayerLocked(LayerIds.BOTTOM_TRACES, true);
presenter.selectAll(0);
assertEquals(new HashSet<Object>(Arrays.asList(topTrace, jumper)),
new HashSet<Object>(presenter.getSelectedComponents()));
assertEquals(new HashSet<Integer>(Arrays.asList(LayerIds.BOTTOM_TRACES)),
presenter.getCurrentProject().getLockedLayers());
}
@Test
public void testBothSidesKeepTheLegacyLayerForOlderVersions() {
Project project = presenter.getCurrentProject();
presenter.setLayerVisibility(LayerIds.BOTTOM_TRACES, false);
presenter.setLayerVisibility(LayerIds.TOP_TRACES, false);
assertTrue(project.getHiddenLayers().contains(LayerIds.LEGACY_TRACES));
presenter.setLayerVisibility(LayerIds.TOP_TRACES, true);
assertEquals(new HashSet<Integer>(Arrays.asList(LayerIds.BOTTOM_TRACES)),
project.getHiddenLayers());
}
@Test
public void testTraceMovedToALockedSideIsLocked() {
presenter.setLayerLocked(LayerIds.BOTTOM_TRACES, true);
presenter.selectAll(0);
assertTrue(presenter.getSelectedComponents().contains(topTrace));
List<PropertyWrapper> properties = presenter.getProperties(topTrace);
for (PropertyWrapper property : properties) {
if (property.getName().equals("Layer")) {
property.setValue(PCBLayer._1);
}
}
presenter.applyProperties(topTrace, properties);
presenter.selectAll(0);
assertFalse(presenter.getSelectedComponents().contains(topTrace));
}
private static CopperTrace trace(PCBLayer layer) {
CopperTrace trace = new CopperTrace();
trace.setLayer(layer);
return trace;
}
}