Пример #1
0
    def test_write_net(self):
        """
        The write_net method creates the correct kicad wires from an
        openjson net.
        """

        net = Net('')
        p1 = NetPoint('p1', 0, 0)
        p2 = NetPoint('p2', 1, 0)
        p3 = NetPoint('p3', 0, 1)

        net.add_point(p1)
        net.add_point(p2)
        net.add_point(p3)

        net.conn_point(p1, p2)
        net.conn_point(p1, p3)

        writer = KiCAD()
        buf = StringIO()
        writer.write_net(buf, net)
        self.assertEqual(
            buf.getvalue(),
            'Wire Wire Line\n\t0 0 0 ' + str(int(-1 / MULT)) + 
            '\nWire Wire Line\n\t0 0 ' + str(int(1 / MULT)) + 
            ' 0\n')
Пример #2
0
 def parse_net_point(self, net_point):
     """ Extract a net point. """
     point_id = net_point.get('point_id')
     x = int(net_point.get('x'))
     y = int(net_point.get('y'))
     npnt = NetPoint(point_id, x, y)
     # Get the connected points
     for point in net_point.get('connected_points'):
         npnt.add_connected_point(point)
     # Get the ConnectedComponents
     for connectedcomponent in net_point.get('connected_components'):
         conn_comp = self.parse_connected_component(connectedcomponent)
         npnt.add_connected_component(conn_comp)
     return npnt
Пример #3
0
 def parse_junc(self, args):
     """ Parses a junction on the net as a NetPoint. """
     x, y, _unknown = args.split()
     # unknown is suspected to be drawing style for the net at this
     # point (right-angle corner? T-section? Solder dot?) ATM not very
     # useful, not really our responsibility.
     return ('netpoint', NetPoint(x + 'x' + y, int(x), int(y)))
Пример #4
0
 def get_point(coord):
     """ Return a new or existing NetPoint for an (x,y) point """
     coord = (int(coord[0]), int(coord[1]))
     if coord not in coord2point:
         coord2point[coord] = NetPoint('%da%d' % coord, coord[0],
                                       coord[1])
     return coord2point[coord]
Пример #5
0
 def test_create_segment(self):
     """ Tests creating segment commands from NetPoint objects. """
     np1 = NetPoint('0a0', 0, 0)
     np2 = NetPoint('0a10', 0, 10)
     self.assertEquals(self.geda_writer._create_segment(np1, np2),
                       ['N 0 0 0 100 4'])
     np1 = NetPoint('100a40', 100, 40)
     np2 = NetPoint('50a40', 50, 40)
     attrs = {'netname': 'test_net'}
     self.assertEquals(
         self.geda_writer._create_segment(np1, np2, attributes=attrs), [
             'N 1000 400 500 400 4',
             '{',
             'T 1100 500 5 10 1 1 0 0 1',
             'netname=test_net',
             '}',
         ])
Пример #6
0
    def test_bounds_simple(self):
        '''Make sure bounds() uses all the included NetPoints'''
        for (x, y) in ((1, 3), (3, 2), (4, 3), (3, 5)):
            net_pt = NetPoint(str((x, y)), x, y)
            self.net.add_point(net_pt)
            # NetPoints don't actually need to be connected to affect bounds()

        top_left, btm_right = self.net.bounds()
        self.assertEqual(top_left.x, 1)
        self.assertEqual(top_left.y, 2)
        self.assertEqual(btm_right.x, 4)
        self.assertEqual(btm_right.y, 5)
Пример #7
0
 def parse_net_point(self, net_point):
     """ Extract a net point. """
     point_id = net_point.get('point_id')
     x = int(net_point.get('x'))
     y = int(net_point.get('y'))
     npnt = NetPoint(point_id, x, y)
     # Get the connected points
     for point in net_point.get('connected_points'):
         npnt.add_connected_point(point)
     # Get the ConnectedComponents
     for connectedcomponent in net_point.get('connected_components'):
         conn_comp = self.parse_connected_component(connectedcomponent)
         npnt.add_connected_component(conn_comp)
     return npnt
Пример #8
0
    def _get_point(self, net_id, point_id, x, y):
        if net_id not in self.nets:
            n = Net(net_id)
            self.design.add_net(n)
            self.nets[n.net_id] = n
        else:
            n = self.nets[net_id]

        key = (x, y)
        if key not in self.net_points:
            if not point_id:
                point_id = str(self._id)
                self._id += 1
            np = NetPoint(net_id + '-' + point_id, x, y)
            n.add_point(np)
            self.net_points[key] = np
        else:
            np = self.net_points[key]

        return np
Пример #9
0
 def test_create_new_net_point(self):
     """ Test the creation of a new empty net point. """
     point = NetPoint('001', 0, 1)
     assert point.point_id == '001'
Пример #10
0
 def get_point(point):
     """ Return a new or existing NetPoint for an (x,y) point """
     point = (make_length(point[0]), make_length(point[1]))
     if point not in points:
         points[point] = NetPoint('%da%d' % point, point[0], point[1])
     return points[point]
 def get_point(connkey):
     """ Return a new or existing NetPoint for an (x,y) coordinate """
     x, y = self.connkey2xy[connkey]
     if (x, y) not in xy2point:
         xy2point[x, y] = NetPoint('%da%d' % (x, y), x, y)
     return xy2point[x, y]
Пример #12
0
 def get_point(x, y):
     """ Return a new or existing NetPoint for an (x,y) point """
     if (x, y) not in points:
         points[x, y] = NetPoint('%da%d' % (x, y), x, y)
         out_net.add_point(points[x, y])
     return points[x, y]
Пример #13
0
 def get_point(point):
     """ Return a new or existing NetPoint for an (x,y) point """
     if point not in points:
         points[point] = NetPoint('%da%d' % point, point[0], point[1])
     return points[point]