示例#1
0
    def position(self):
        # type: () -> Point2D
        """Position of the Module

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetPosition())
示例#2
0
def resize_pads(board, minimal_drill, minimal_annular_ring):
    for module in board.modules:
        print("Resize pads of: {}".format(module))
        for pad in module.pads:
            assert pad.drill_size.x == pad.drill_size.y  # we assume round holes
            if pad.drill_size.x < minimal_drill:
                new_size = Point2D([minimal_drill, minimal_drill])
                size_difference = new_size - pad.drill_size

                print("* modify drill size from {} to {}".format(pad.drill_size, new_size))
                pad.size += size_difference  # modify annular ring
                pad.drill_size = new_size  # set to minimal size

            annular_size = pad.size - pad.drill_size
            if annular_size.x < minimal_annular_ring:
                new_size = pad.size  # currently required because kicad-python cannot do pad.size.x = ...
                new_size.x = pad.drill_size.x + minimal_annular_ring

                print("* modify size (x) from {} to {}".format(pad.size, new_size))
                pad.size = new_size

            if annular_size.y < minimal_annular_ring:
                new_size = pad.size  # currently required because kicad-python cannot do pad.size.x = ...
                new_size.y = pad.drill_size.y + minimal_annular_ring

                print("* modify size (y) from {} to {}".format(pad.size, new_size))
                pad.size = new_size
示例#3
0
    def radius(self):
        """Radius of circle

        :return: ``float``
        """
        end = Point2D.from_wxPoint(self._obj.GetEnd())
        diff = self.center - end
        return max(abs(diff.x), abs(diff.y))
示例#4
0
def place(module, point, orientation):
    global prev_module
    from kicad.util.point import Point2D

    print("Placing module %s at point %f,%f orientation %f" %
          (module.reference, point.x, point.y, orientation))
    module.position = Point2D(point.x, point.y)
    kicad_orientation = orientation
    kicad_orientation *= 180 / pi
    kicad_orientation *= 10  # kicad *shrug*

    module._obj.SetOrientation(kicad_orientation)

    for pad in module._obj.Pads():
        # FIXME: Remove the center pads? esp if soldering by hand?
        # fortunately the corner GND pad always seems to come first in the list

        if pad.GetPadName() == '6':  # GND
            # draw trace outward from ground
            end = Point.fromWxPoint(pad.GetPosition()).polar_translated(
                0.8, -pi / 2 - orientation)
            add_copper_trace(pad.GetPosition(), end.wxPoint(), pad.GetNet())

            # add a via
            # add_via(end.wxPoint(), pad.GetNet())

            break

    # Add tracks from the previous  module, connecting pad 5 to pad 2 and pad 4 to pad 3
    if not args.skip_traces and prev_module is not None:
        pad_map = {"2": "5", "3": "4"}  # connect SCK and SD*
        for prev_pad in prev_module._obj.Pads():
            if prev_pad.GetPadName() in pad_map:
                tracks = board._obj.TracksInNet(prev_pad.GetNet().GetNet())
                if tracks:
                    # skip pad, already has traces
                    if args.verbose:
                        print("Skipping pad, already has tracks: {}".format(
                            prev_pad))
                    continue
                # for net in board._obj.TracksInNet(prev_pad.GetNet().GetNet()):
                # 	board._obj.Delete(t)

                # then connect the two pads
                for pad in module._obj.Pads():
                    if pad.GetPadName() == pad_map[prev_pad.GetPadName()]:
                        start = prev_pad.GetPosition()
                        end = pad.GetPosition()
                        print(
                            "Adding track from module {} pad {} to module {} pad {}"
                            .format(prev_module.reference,
                                    prev_pad.GetPadName(), module.reference,
                                    pad.GetPadName()))
                        add_copper_trace(start, end, pad.GetNet())

                # FIXME: Draw GND and +5V traces for circle

    prev_module = module
示例#5
0
    def test_round_to(self):
        p1 = Point2D([1.234, 5.678]).round_to(0)
        self.assertAlmostEqual(p1.x, 1.234)
        self.assertAlmostEqual(p1.y, 5.678)

        p2 = Point2D([1.234, 5.678]).round_to(0.1)
        self.assertAlmostEqual(p2.x, 1.2)
        self.assertAlmostEqual(p2.y, 5.7)

        p3 = Point2D([1.234, 5.678]).round_to(0.01)
        self.assertAlmostEqual(p3.x, 1.23)
        self.assertAlmostEqual(p3.y, 5.68)

        p4 = Point2D([1.234, 5.678]).round_to(0.001)
        self.assertAlmostEqual(p4.x, 1.234)
        self.assertAlmostEqual(p4.y, 5.678)

        p5 = Point2D([1.234, 5.678]).round_to(0.0001)
        self.assertAlmostEqual(p5.x, 1.234)
        self.assertAlmostEqual(p5.y, 5.678)
示例#6
0
    def grid_origin(self):
        # type: () -> Point2D
        """Grid origin of Board

        :return: :class:`kicad.util.Point2D`

        :Example:

        >>> from kicad.pcbnew import Board
        >>> b = Board()
        >>> b.grid_origin = [1, 2]
        >>> b.grid_origin
        kicad.util.point.Point2D(1.0, 2.0)
        """
        return Point2D.from_wxPoint(self._obj.GetGridOrigin())
示例#7
0
    def test_div(self):
        p1 = Point2D([1, 2])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)

        p2 = p1 / 5
        self.assertEqual(p2.x, 0.2)
        self.assertEqual(p2.y, 0.4)

        p3 = p1 / (-5)
        self.assertEqual(p3.x, -0.2)
        self.assertEqual(p3.y, -0.4)

        p4 = p1 / [4, 5]
        self.assertEqual(p4.x, 0.25)
        self.assertEqual(p4.y, 0.4)

        p5 = p1 / [-5, -2]
        self.assertEqual(p5.x, -0.2)
        self.assertEqual(p5.y, -1)
示例#8
0
    def test_sub(self):
        p1 = Point2D([1, 2])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)

        p2 = p1 - 5
        self.assertEqual(p2.x, -4)
        self.assertEqual(p2.y, -3)

        p3 = p1 - (-5)
        self.assertEqual(p3.x, 6)
        self.assertEqual(p3.y, 7)

        p4 = p1 - [4, 2]
        self.assertEqual(p4.x, -3)
        self.assertEqual(p4.y, 0)

        p5 = p1 - [-5, -3]
        self.assertEqual(p5.x, 6)
        self.assertEqual(p5.y, 5)
示例#9
0
    def test_mul(self):
        p1 = Point2D([1, 2])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)

        p2 = p1 * 5
        self.assertEqual(p2.x, 5)
        self.assertEqual(p2.y, 10)

        p3 = p1 * (-5)
        self.assertEqual(p3.x, -5)
        self.assertEqual(p3.y, -10)

        p4 = p1 * [4, 5]
        self.assertEqual(p4.x, 4)
        self.assertEqual(p4.y, 10)

        p5 = p1 * [-5, -3]
        self.assertEqual(p5.x, -5)
        self.assertEqual(p5.y, -6)
示例#10
0
    def test_add(self):
        p1 = Point2D([1, 2])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)

        p2 = p1 + 5
        self.assertEqual(p2.x, 6)
        self.assertEqual(p2.y, 7)

        p3 = p1 + (-5)
        self.assertEqual(p3.x, -4)
        self.assertEqual(p3.y, -3)

        p4 = p1 + [4, 2]
        self.assertEqual(p4.x, 5)
        self.assertEqual(p4.y, 4)

        p5 = p1 + [-5, -3]
        self.assertEqual(p5.x, -4)
        self.assertEqual(p5.y, -1)
示例#11
0
    def test_init(self):
        p1 = Point2D([1, 2])
        self.assertEqual(p1.x, 1)
        self.assertEqual(p1.y, 2)

        p2 = Point2D((4, 5))
        self.assertEqual(p2.x, 4)
        self.assertEqual(p2.y, 5)

        p3 = Point2D({'x': 7, 'y': 8})
        self.assertEqual(p3.x, 7)
        self.assertEqual(p3.y, 8)

        p3_empty = Point2D({})
        self.assertEqual(p3_empty.x, 0)
        self.assertEqual(p3_empty.y, 0)

        p4 = Point2D(p1)
        self.assertEqual(p4.x, 1)
        self.assertEqual(p4.y, 2)

        p5 = Point2D(1, 2)
        self.assertEqual(p5.x, 1)
        self.assertEqual(p5.y, 2)
示例#12
0
    def size(self):
        """Size of the Pad

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetSize())
示例#13
0
 def size(self, size):
     self._obj.SetSize(Point2D(size).to_wxSize())
示例#14
0
 def position(self, center):
     self._obj.SetPosition(Point2D(center).to_wxPoint())
示例#15
0
    def center(self):
        """Center point of circle

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetCenter())
示例#16
0
    def text_size(self):
        """Text Size

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxSize(self._obj.GetTextSize())
示例#17
0
    def position(self):
        """Position of the Text

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetPosition())
示例#18
0
    def end(self):
        """End of the Track

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetEnd())
示例#19
0
    def end(self):
        """End point of line

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetEnd())
示例#20
0
    def start(self):
        """Start point of line

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetStart())
示例#21
0
 def radius(self, radius):
     point2d_radius = self.center + Point2D(radius, radius)
     self._obj.SetCenter(point2d_radius.to_wxPoint())
示例#22
0
    def start(self):
        """Start of the Track

        :return: :class:`kicad.util.Point2D`
        """
        return Point2D.from_wxPoint(self._obj.GetStart())
示例#23
0
 def start(self, start):
     self._obj.SetStart(Point2D(start).to_wxPoint())
示例#24
0
 def drill_size(self, drill_size):
     self._obj.SetDrillSize(Point2D(drill_size).to_wxSize())
示例#25
0
 def end(self, end):
     self._obj.SetEnd(Point2D(end).to_wxPoint())
示例#26
0
 def test_eq(self):
     p1a = Point2D([1, 2])
     p1b = Point2D([1, 2])
     self.assertEqual(p1a, p1b)
示例#27
0
 def position(self, pos):
     self._obj.SetPosition(Point2D(pos).to_wxPoint())
示例#28
0
 def test_neq(self):
     p1a = Point2D([1, 2])
     p1b = Point2D([2, 1])
     self.assertNotEqual(p1a, p1b)
示例#29
0
 def text_size(self, text_size):
     self._obj.SetTextSize(Point2D(text_size).to_wxSize())
示例#30
0
 def center(self, center):
     self._obj.SetCenter(Point2D(center).to_wxPoint())