minor progress
This commit is contained in:
parent
b93f0ac559
commit
82e93a2d57
|
@ -0,0 +1,6 @@
|
|||
package com.rusefi.pcb;
|
||||
|
||||
public enum PcbNodeType {
|
||||
PAD,
|
||||
NET
|
||||
}
|
|
@ -1,20 +1,18 @@
|
|||
package com.rusefi.pcb.nodes;
|
||||
|
||||
import com.rusefi.pcb.nodes.PcbNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Andrey Belomutskiy
|
||||
* 1/21/14
|
||||
* 1/21/14
|
||||
*/
|
||||
public class NetNode extends PcbNode {
|
||||
public final String id;
|
||||
final String name;
|
||||
private String name;
|
||||
public static int GND_NET_ID;
|
||||
|
||||
public NetNode(String nodeName, int i, List<Object> children) {
|
||||
super(nodeName, i, children);
|
||||
public NetNode(int i, List<Object> children) {
|
||||
super(TOKEN_NET, i, children);
|
||||
id = getChild(0);
|
||||
name = children.size() > 1 ? getChild(1) : null;
|
||||
if (name != null)
|
||||
|
|
|
@ -16,8 +16,8 @@ import java.util.List;
|
|||
*/
|
||||
public class PcbNode {
|
||||
public static final String TOKEN_SEGMENT = "segment";
|
||||
public static final String TOKEN_PAD = "pad";
|
||||
public static final String TOKEN_NET = "net";
|
||||
public static final String TOKEN_PAD = PcbNodeType.PAD.name().toLowerCase();
|
||||
public static final String TOKEN_NET = PcbNodeType.NET.name().toLowerCase();
|
||||
public static final String TOKEN_GR_LINE = "gr_line";
|
||||
public static final String TOKEN_ZONE = "zone";
|
||||
public static final String TOKEN_VIA = "via";
|
||||
|
@ -91,7 +91,7 @@ public class PcbNode {
|
|||
} else if (TOKEN_PAD.equals(nodeName)) {
|
||||
return PadNode.parse(nodeName, index + 1, children);
|
||||
} else if (TOKEN_NET.equals(nodeName)) {
|
||||
return new NetNode(nodeName, index + 1, children);
|
||||
return new NetNode(index + 1, children);
|
||||
} else if ("add_net".equals(nodeName)) {
|
||||
return new AddNetNode(nodeName, index + 1, children);
|
||||
} else if (TOKEN_GR_LINE.equals(nodeName)) {
|
||||
|
@ -226,6 +226,9 @@ public class PcbNode {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return children of specified type, without recursion
|
||||
*/
|
||||
public <T extends PcbNode> List<T> iterate(String key) {
|
||||
List<T> result = new ArrayList<T>();
|
||||
for (PcbNode p : nodes()) {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package com.rusefi.pcb.nodes;
|
||||
|
||||
import com.rusefi.pcb.nodes.LayerNode;
|
||||
import com.rusefi.pcb.nodes.PcbNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +11,7 @@ public class ZoneNode extends PcbNode {
|
|||
|
||||
public ZoneNode(String nodeName, int i, List<Object> children) {
|
||||
super(nodeName, i, children);
|
||||
layerNode = (LayerNode) find("layer");
|
||||
layerNode = find("layer");
|
||||
}
|
||||
|
||||
public LayerNode getLayerNode() {
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package com.rusefi.pcb;
|
||||
|
||||
import com.rusefi.pcb.nodes.ModuleNode;
|
||||
import com.rusefi.pcb.nodes.PcbNode;
|
||||
import com.rusefi.pcb.nodes.SegmentNode;
|
||||
import com.rusefi.pcb.nodes.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -42,6 +41,20 @@ public class PcbNodeTest {
|
|||
")\r\n", n.pack());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFind() {
|
||||
|
||||
NetNode net1 = new NetNode(-1, Collections.singletonList("1"));
|
||||
NetNode net2 = new NetNode(-1, Collections.singletonList("2"));
|
||||
|
||||
LayerNode childZone = new LayerNode("z", -1, Arrays.asList("z", net2));
|
||||
|
||||
LayerNode parentZone = new LayerNode("parent", 2, Arrays.asList("z2", net1, childZone));
|
||||
|
||||
List<NetNode> nets = parentZone.iterate(PcbNode.TOKEN_NET);
|
||||
assertEquals(1, nets.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseModule() {
|
||||
ModuleNode module = (ModuleNode) PcbNode.parse("(module SM0805 (layer F.Cu) (tedit 52BF06CE) (tstamp 52A5B5B5)\n" +
|
||||
|
|
Loading…
Reference in New Issue