示例#1
0
    def setUp(self):
        self.p = Project()
        self.l1 = Layer("l1", None)
        self.l2 = Layer("l2", None)

        self.p.stackup.add_layer(self.l1)
        self.p.stackup.add_layer(self.l2)
示例#2
0
文件: common.py 项目: pcbre/pcbre
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)
示例#3
0
    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)
示例#4
0
    def setUp(self):
        self.p = Project()
        self.l1 = Layer("l1", None)
        self.l2 = Layer("l2", None)

        self.p.stackup.add_layer(self.l1)
        self.p.stackup.add_layer(self.l2)

        self.ext1 = [Point2(0, 0), Point2(1, 0), Point2(1, 1), Point2(0, 1)]
        self.ext2 = [Point2(1, 0), Point2(2, 0), Point2(2, 1), Point2(1, 1)]
        self.ext3 = [Point2(2, 0), Point2(3, 0), Point2(3, 1), Point2(2, 1)]
示例#5
0
    def test_sorted_query_regression(self):
        # Attempt to
        p = Project()

        l = Layer("t1", (1, 1, 1))

        p.stackup.add_layer(l)

        cx = Point2(30000, 30000)
        ts = []
        for i in range(100):
            r = 5000 - 40 * i
            r1 = 5000 - 40 * (i + 1)

            t = math.radians(30 * i)
            t1 = math.radians(30 * (i + 1))

            v = Point2(math.cos(t) * r, math.sin(t) * r)
            v1 = Point2(math.cos(t1) * r1, math.sin(t1) * r1)

            t1 = Trace(v + cx, v1 + cx, 100, l)
            t1.STUFFED_ID = i
            p.artwork.merge_artwork(t1)
            ts.append(t1)

        t0 = ts[0]
        for n, a in enumerate(ts[1:], start=1):
            self.assertEqual(t0.net, a.net, "mismatch on %d" % n)

        self.assertIsNotNone(t0.net)

        p.save('/tmp/wtf.pcbre', False)
示例#6
0
    def test_save_smd(self):
        p = Project()
        l = Layer("test", [1,1,1])
        p.stackup.add_layer(l)
        d = SMD4Component(Point2(64, 54), 33.5, SIDE.Top, p,
                          32, 46,17,55, 801,914,3232, 604, 123, 456, 17)
                          
        d.refdes = "UFOO"

        p.artwork.merge_component(d)

        p_new = self.__saverestore(p)
        
        self.assertEqual(len(p_new.artwork.components), 1)
        c = next(iter(p_new.artwork.components))

        self.assertEqual(d.side_pins, c.side_pins)

        self.assertEqual(d.dim_1_body, c.dim_1_body)
        self.assertEqual(d.dim_1_pincenter, c.dim_1_pincenter)
        self.assertEqual(d.dim_2_body, c.dim_2_body)
        self.assertEqual(d.dim_2_pincenter, c.dim_2_pincenter)

        self.assertEqual(d.pin_contact_length, c.pin_contact_length)
        self.assertEqual(d.pin_contact_width, c.pin_contact_width)
        self.assertEqual(d.pin_spacing, c.pin_spacing)
示例#7
0
    def test_save_pin_names_nets(self):
        p = Project()
        l = Layer("test", [1,1,1])
        p.stackup.add_layer(l)
        d = DIPComponent(Point2(64, 54), 33.5, SIDE.Top, p, 12, 512, 640, 1111)
        d.refdes = "UFOO"
        d.partno = "BLAH"


        pads = d.get_pads()
        pads[0].pad_name = "NAME1"
        pads[1].pad_name = "NAME2"
        p.artwork.merge_component(d)

        p_new = self.__saverestore(p)


        self.assertEqual(len(p_new.artwork.components), 1)
        c = next(iter(p_new.artwork.components))

        self.assertEqual(d.refdes, c.refdes)
        self.assertEqual(d.partno, c.partno)

        pads_new = c.get_pads()

        for p_old, p_new in zip(pads, pads_new):
            self.assertEqual(p_old.net.name, p_new.net.name)

        self.assertEqual(pads_new[0].pad_name, "NAME1")
        self.assertEqual(pads_new[1].pad_name, "NAME2")
示例#8
0
    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
示例#9
0
    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))
示例#10
0
文件: project.py 项目: balr0g/pcbre
    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))
示例#11
0
    def test_basic(self):
        layer = Layer("foo", (1, 1, 1))
        self.p.stackup.add_layer(layer)

        self.assertIn(layer, self.p.stackup.layers)

        self.p.stackup.remove_layer(layer)

        self.assertNotIn(layer, self.p.stackup.layers)
示例#12
0
    def __setup_layers(self, n):
        names = ["foo","bar","quux", "sed","a"] + list("abcdefghijklmnop")
        p = Project.create()
        for i, name in zip(range(n), names):
            color = (random.random(), random.random(), random.random())
            l0 = Layer(name, color)
            p.stackup.add_layer(l0)

        return p
示例#13
0
文件: project.py 项目: pcbre/pcbre
    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()
示例#14
0
    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)
示例#15
0
    def setUp(self):
        self.p = p = Project()
        l = Layer("foo", [])
        p.stackup.add_layer(l)

        self.l1 = Trace(Point2(-5, 0), Point2(-1, 0), thickness=1, layer=l)
        self.l2 = Trace(Point2(1, 0), Point2(5, 0), thickness=1, layer=l)
        p.artwork.merge_artwork(self.l1)
        p.artwork.merge_artwork(self.l2)

        self.assertIsNotNone(self.l1.net)
        self.assertIsNotNone(self.l2.net)
        self.assertNotEqual(self.l1.net, self.l2.net)

        class Dummy(Component):
            pass

        cmp = Dummy(Point2(0,0), 0, SIDE.Top, side_layer_oracle=p)
        self.pad = Pad(cmp, 0, Point2(0, 0), 0, 3, 3, th_diam=1)
示例#16
0
    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)
示例#17
0
    def test_callback_called_on_add_del(self):
        layer = Layer("foo", (1, 1, 1))

        call_me = Mock()

        self.p.stackup.changed.connect(call_me)
        self.p.stackup.add_layer(layer)

        self.assertTrue(call_me.called)
        ((model_change, ), _) = call_me.call_args
        self.assertEqual(model_change.container, self.p.stackup.layers)
        self.assertEqual(model_change.what, layer)
        self.assertEqual(model_change.reason, ChangeType.ADD)

        call_me.reset_mock()
        self.p.stackup.remove_layer(layer)

        self.assertTrue(call_me.called)
        ((model_change, ), _) = call_me.call_args
        self.assertEqual(model_change.container, self.p.stackup.layers)
        self.assertEqual(model_change.what, layer)
        self.assertEqual(model_change.reason, ChangeType.REMOVE)
示例#18
0
    def test_save_dip(self):
        p = Project()
        l = Layer("test", [1,1,1])
        p.stackup.add_layer(l)
        d = DIPComponent(Point2(64, 54), 33.5, SIDE.Top, p, 12, 512, 640, 1111)
        d.refdes = "UFOO"

        p.artwork.merge_component(d)

        p_new = self.__saverestore(p)

        self.assertEqual(len(p_new.artwork.components), 1)
        c = next(iter(p_new.artwork.components))
        
        self.assertIsInstance(c, DIPComponent)
        self.assertEqual(d.body_length(), c.body_length())
        self.assertEqual(d.body_width(), c.body_width())
        self.assertEqual(d.pin_count, c.pin_count)
        self.assertEqual(d.pin_space, c.pin_space)
        self.assertEqual(d.pin_width, c.pin_width)
        self.assertEqual(d.pad_size, c.pad_size)
        self.assertEqual(d.theta, c.theta)
        self.assertEqual(d.refdes, c.refdes)
示例#19
0
    def test_fixup_broken_nets(self):
        p = Project()

        l = Layer("t1", (1, 1, 1))

        p.stackup.add_layer(l)

        n1 = p.nets.new()
        n2 = p.nets.new()
        n3 = p.nets.new()

        # T1 and T2 should be joined
        # T2 and T3 should be split
        # T4 should stay the same

        t1 = Trace(Point2(0, 0), Point2(100, 100), 10, l, n1)
        t2 = Trace(Point2(200, 200), Point2(100, 100), 10, l, n2)
        t3 = Trace(Point2(400, 400), Point2(500, 500), 10, l, n2)
        t4 = Trace(Point2(600, 600), Point2(700, 700), 10, l, n3)

        p.artwork.add_artwork(t1)
        p.artwork.add_artwork(t2)
        p.artwork.add_artwork(t3)
        p.artwork.add_artwork(t4)

        self.assertNotEqual(t1.net, t2.net)
        p.artwork.rebuild_connectivity()
        self.assertEqual(t1.net, t2.net)
        self.assertNotEqual(t2.net, t3.net)
        self.assertEqual(t4.net, n3)

        # And all objects must have nets
        self.assertIsNotNone(t1.net)
        self.assertIsNotNone(t2.net)
        self.assertIsNotNone(t3.net)
        self.assertIsNotNone(t4.net)