def setUp(self): world = Project() for i in range(4): world.stackup.add_layer(Layer("l%d" % i, None)) world.stackup.add_via_pair( ViaPair(world.stackup.layers[0], world.stackup.layers[1])) world.stackup.add_via_pair( ViaPair(world.stackup.layers[2], world.stackup.layers[3])) world.stackup.add_via_pair( ViaPair(world.stackup.layers[0], world.stackup.layers[3])) world.stackup.add_via_pair( ViaPair(world.stackup.layers[1], world.stackup.layers[2])) # 0 1 2 3 # 0 x x x # 1 x x x # 2 x x x x # 3 x x x x n1 = Net() n2 = Net() world.nets.add_net(n1) world.nets.add_net(n2) self.v1 = Via(Point2(3, 3), world.stackup.via_pairs[0], 2, n1) world.artwork.add_artwork(self.v1) self.v2 = Via(Point2(11, 11), world.stackup.via_pairs[1], 2, n2) world.artwork.add_artwork(self.v2) self.world = world
def __setup_via_pairs_layers(self): p = self.__setup_layers(4) l0, l1, l2, l3 = p.stackup.layers vp1 = ViaPair(l0, l3) vp2 = ViaPair(l1, l2) p.stackup.add_via_pair(vp1) p.stackup.add_via_pair(vp2) return p
def deserialize(self, msg): self.__layers.clear() for i in msg.layers: self.__layers.append(Layer.deserialize(self.__project, i)) self.__via_pairs.clear() for i in msg.viapairs: self.__via_pairs.append(ViaPair.deserialize(self.__project, i))
def setup2Layer(obj): obj.p = Project() obj.top_layer = Layer("top", (1, 0, 0)) obj.bottom_layer = Layer("bottom", (0, 0, 1)) obj.p.stackup.add_layer(obj.top_layer) obj.p.stackup.add_layer(obj.bottom_layer) obj.via_pair = ViaPair(obj.top_layer, obj.bottom_layer) obj.p.stackup.add_via_pair(obj.via_pair)
def deserialize(self, msg: ser.Stackup) -> None: self.__layers.clear() for i in msg.layers: self.__layers.append(Layer.deserialize(self.__project, i)) self.__via_pairs.clear() for i in msg.viapairs: self.__via_pairs.append(ViaPair.deserialize(self.__project, i)) self.__renumber_layers()
def test_point_insert(self): p = Project() l1 = Layer("l1", None) l2 = Layer("l2", None) p.stackup.add_layer(l1) p.stackup.add_layer(l2) vp = ViaPair(l1, l2) p.stackup.add_via_pair(vp) t1 = Trace(Point2(200, 1000), Point2(2000, 1000), 10, l1) p.artwork.merge_artwork(t1) t2 = Trace(Point2(400, 0), Point2(400, 2000), 10, l2) p.artwork.merge_artwork(t2) # Should be two objects, not connected self.assertIsNotNone(t1.net) self.assertIsNotNone(t2.net) self.assertNotEqual(t1.net, t2.net) # Add two more traces, make sure they're connected to nets t3 = Trace(Point2(2000, 1001), Point2(2000, 3000), 10, l1) p.artwork.merge_artwork(t3) self.assertEqual(t1.net, t3.net) t4 = Trace(Point2(401, -1), Point2(-1000, -1000), 10, l2) p.artwork.merge_artwork(t4) self.assertEqual(t2.net, t4.net) # Now put a via between the two v = Via(Point2(400, 1000), vp, 10) p.artwork.merge_artwork(v) # Make sure net is not none self.assertIsNotNone(v.net) # Make sure net is all the same self.assertEqual(v.net, t1.net) self.assertEqual(v.net, t2.net) self.assertEqual(v.net, t3.net) self.assertEqual(v.net, t4.net) # Should only be one net in the project now, and it should be v.net self.assertEqual(len(p.nets.nets), 1) self.assertEqual(p.nets.nets[0], v.net) # Ok, now remove the via from the artwork. # via should then have no net, and the traces on each layer should split off p.artwork.remove_artwork(v) # We should now have two nets on separate layers self.assertEqual(len(p.nets.nets), 2) self.assertEqual(t1.net, t3.net) self.assertEqual(t2.net, t4.net) self.assertNotEqual(t1.net, t2.net)
def update(self) -> None: to_remove = set(self.p.stackup.layers) for i in self.layers: # If there's an existing layer if i.ref is not None: # Then we don't remove it to_remove.remove(i.ref) else: # Otherwise add a new layer i.ref = Layer(self.p, name=i.name, color=i.color) self.p.stackup.add_layer(i.ref) i.ref.name = i.name i.ref.color = i.color # Remove all the layers we didn't find for i_ in to_remove: self.p.stackup.remove_layer(i_) # now, walking from first to last layer, update the layer ordering # re-enumerate to ensure order is gapless for n, j in enumerate(sorted(self.layers, key=lambda x: x.index)): assert j.ref is not None self.p.stackup.set_layer_order(j.ref, n) # Now update all the viapairs to_remove_vp = set(self.p.stackup.via_pairs) for vp in self.via_pairs: if vp.ref is None: assert vp.startLayer.ref is not None assert vp.endLayer.ref is not None new_layer = ViaPair(self.p, vp.startLayer.ref, vp.endLayer.ref) self.p.stackup.add_via_pair(new_layer) else: assert vp.startLayer.ref is not None assert vp.endLayer.ref is not None vp.ref.layers = vp.startLayer.ref, vp.endLayer.ref to_remove_vp.remove(vp.ref) for l in to_remove_vp: self.p.stackup.remove_via_pair(l)
def setUp(self): self.p = Project.create() l1 = Layer(name="Top", color=(0, 0, 0)) l2 = Layer(name="Bot", color=(0, 0, 1)) vp = ViaPair(l1, l2) self.net0 = Net() self.net1 = Net() self.v1 = Via(Point2(0, 0), r=1, viapair=vp, net=self.net0) self.v2 = Via(Point2(0, 0), r=1, viapair=vp, net=self.net1) self.p.stackup.add_layer(l1) self.p.stackup.add_layer(l2) self.p.stackup.add_via_pair(vp) self.p.nets.add_net(self.net0) self.p.nets.add_net(self.net1) self.p.artwork.add_artwork(self.v1) self.p.artwork.add_artwork(self.v2)