Example #1
0
def process_wire_path(board, to_process_set, point_array):
    wire = to_process_set.pop()
    p1 = wire.get_point(0)
    p2 = wire.get_point(1)

    i = 0
    # print p1
    # print p2

    while True:
        # print map(lambda w: list(w.get_points()), to_process)
        # print p1

        #Append first point of init wire
        point_array.append(p1)

        #Use 2nd point as a query to find the next connecting wire
        width = np.array([wire.get_width(), wire.get_width()])
        wires = board.get_overlapping(Rectangle(p2 - width, p2 + width)).\
            with_type(Swoop.Wire).filtered_by(lambda w: w in to_process)

        #If there is no wire, we are back where we started
        if len(wires)==0:
            point_array.append(p2)
            return
        assert len(wires)==1
        wire = wires[0]
        to_process.remove(wire)

        # p1 of the new wire is our query point, p2 is a new point
        if SG.distance(wire.get_point(0), p2) < SG.distance(wire.get_point(1), p2):
            p1, p2 = wire.get_point(0), wire.get_point(1)
        else:
            p2, p1 = wire.get_point(0), wire.get_point(1)
Example #2
0
    def test_bounding_boxes(self):
        board = SwoopGeom.from_file(get_inp("test_saving.brd"))
        rect = board.get_element("R1").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (84.70000, 67.32380), (87.30000, 68.67620)))

        rect = board.get_element("TEST-ARC1").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (104.85650, 75.60080), (114.97665, 87.59554)))

        rect = board.get_element("TEST-ARC2").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (122.93650, 77.73274), (131.06350, 82.06350)))

        rect = SwoopGeom.arc_bounding_box(np.array([-1,2]), np.array([-1,-2]), math.pi)
        self.assertEqual(rect, Rectangle((-3,-2),(-1,2)))

        rect = board.get_element("TEST-ARC3").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (135.93650, 85.93650), (138.06350, 90.06350)))

        rect = board.get_element("TEST-PAD1").get_bounding_box()[0]
        self.assertEqual(rect,Rectangle( (129.50000, 71.50000), (135.50000, 74.50000)))

        rect = board.get_element("TEST-PAD2").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (116.50000, 89.25000), (119.50000, 90.75000)))

        rect = board.get_element("TEST-PAD-SQUARE").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (117.50000, 73.77000), (120.50000, 76.77000)))

        rect = board.get_element("TEST-PAD-ROUND").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (130.25000, 75.25000), (131.75000, 76.75000)))

        rect = board.get_element("TEST-PAD-ROT").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (137.54523, 78.99348), (140.45477, 81.00652)))

        rect = SwoopGeom.arc_bounding_box(np.array([-2,1]), np.array([1,-2]), math.pi)
        self.assertEqual(rect, Rectangle( (-2.62132, -2.62132), (1.00000, 1.00000)))

        rect = board.get_element("TEST-PAD-OCT").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (111.88653, 67.88653), (116.11347, 72.11347)))

        rect = board.get_element("TEST-PAD-OCT2").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (124.00000, 70.00000), (128.00000, 74.00000)))

        rect = board.get_element("TEST-PAD-SQUARE-ROT").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (118.13116, 82.13116), (119.86884, 83.86884)))

        rect= board.get_element("TEST-CIRCLE").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (132.72190, 49.88190), (152.03810, 69.19810)))

        rect = board.get_element("TEST-HOLE").get_bounding_box()[0]
        self.assertEqual(rect, Rectangle( (113.45000, 58.45000), (114.55000, 59.55000)))

        rect = board.get_element("TEST-POLYGON").get_package_moved().\
            get_children().get_bounding_box().reduce(Rectangle.union)
        self.assertEqual(rect, Rectangle( (99.33003, 23.26925), (134.14446, 45.35457)))

        rect = board.get_element("ARDUINO").get_package_moved().\
            get_children().get_bounding_box().reduce(Rectangle.union)
        self.assertEqual(rect, Rectangle( (65.44012, 15.95000), (91.43026, 66.66429)))
Example #3
0
 def get(self, libname):
     path_lib = self._libraries.get(libname)
     if path_lib is None:
         return None
     if path_lib.library is None:
         path_lib.library = SwoopGeom.from_file(path_lib.path).get_library()
     return path_lib.library
Example #4
0
    def test_query(self):
        board = SwoopGeom.from_file(get_inp("test_saving.brd"))
        results = board.get_overlapping(83.51, 63.91, 97.25, 71.85)
        self.assertEqual(len(results), 6)
        self.assertEqual(len(results.with_type(Swoop.Element)), 2)
        self.assertEqual(len(results.with_type(Swoop.Wire)), 4)

        board = SwoopGeom.from_file(get_inp("test_query.brd"))

        result = board.get_overlapping(Rectangle((99,47), (104,53)))
        self.assertEqual(len(result), 1)
        result = board.get_overlapping(Rectangle((100,46), (102,48)))
        self.assertEqual(len(result), 1)
        result = board.get_overlapping(Rectangle((107,52), (109,54)))
        self.assertEqual(len(result), 0)
        result = board.get_overlapping(Rectangle((102,38), (104,40)))
        self.assertEqual(len(result), 1)
Example #5
0
 def test_correct_shape(self):
     board = SwoopGeom.from_file(get_inp("test_saving.brd"))
     polygon = board.get_element_shape("ARDUINO")
     vertices = map(SwoopGeom.cgal2np, polygon.vertices())
     should_be = [np.array([ 82.89493007,  15.0384369 ]),
                  np.array([ 65.25997764,  18.14795481]),
                  np.array([ 73.81652632,  66.67455381]),
                  np.array([ 91.45147876,  63.56503589])]
     for actual,desired in zip(vertices, should_be):
         npt.assert_allclose(actual, desired)
Example #6
0
 def test_bbox_after_filter(self):
     board = SwoopGeom.from_file(get_inp("fp_bbox.brd"))
     bbox = board.get_elements().get_package_moved().get_bounding_box()[0]
     self.assertEqual(bbox, Rectangle( (-17.31000, -39.84350), (31.96520, -21.93650)))
     tface = board.get_elements().\
         get_package_moved().\
         get_children().\
         filtered_by(lambda p: hasattr(p,"layer") and p.layer=="tFaceplate").\
         get_bounding_box()[0]
     self.assertEqual(tface, Rectangle( (-17.00000, -38.00000), (-7.00000, -24.00000)))
Example #7
0
        if i==0:
            print "{0}.penDown();".format(turtle_name)
        i += 1



parser = argparse.ArgumentParser(description="Convert a collection of Eagle paths to laser turtle code.")
parser.add_argument("brdfile",help="Board file with wires drawn as plain elements")
parser.add_argument("--turtle",help="Turtle instance name", default="turtle")
parser.add_argument("--height",help="Height of turtle world", type=int, default=1000)
parser.add_argument("--width",help="Width of turtle world", type=int, default=1000)
parser.add_argument("--scale",help="Scale your drawing", type=float, default=1.0)
parser.add_argument("--center",action="store_true",help="Place drawing in the center of the world")
args = parser.parse_args()

board = SG.from_file(args.brdfile)

to_process = set(board.get_plain_elements().with_type(Swoop.Wire))

to_process |= set(board.get_signals().get_wires().with_type(Swoop.Wire))

paths = []

while len(to_process) > 0:
    points = []
    print "Path: "
    process_wire_path(board, to_process, points)
    for p in points:
        print p
    paths.append(points)
Example #8
0
        yield rect2scad(rect, cut_through_roof, mirrored=mirrored) #top
        padded_cut = rect.copy().pad(1.0)
        if not container_rect.encloses(padded_cut):  #faceplate sticks out the side
            # print "side cut {0}".format(rect.eagle_code())
            cut = make_cutout_rect(container_rect, padded_cut, CASE_THICKNESS)
            if cut is not None:
                yield rect2scad(cut, space_top, mirrored=mirrored)

parser = argparse.ArgumentParser(description="Make 3D printed cases for your gadgets")
parser.add_argument("brdfile", help="Board file to make a case from")
parser.add_argument("-f","--file", help="SCAD output file", default="out.scad")
parser.add_argument("-g","--gspec",help="gspec file containing height information")
parser.add_argument("--open", action="store_true", help="The top of the case is open")
args = parser.parse_args()

board = SwoopGeom.from_file(args.brdfile)

#Find the bounding box of the board
board_box = board.get_bounding_box()

top = 15.0
bottom = 15.0

if args.gspec is not None:
    gspec = ET.parse(args.gspec)
    for option in gspec.findall("option"):
        if option.get("name")=="front-standoff-height":
            top = float(option.attrib["value"])
        elif option.get("name")=="back-standoff-height":
            bottom = float(option.attrib["value"])
Example #9
0
            continue

        artwork_svg_file = join(catalog_dir, svg)
        component_ok = component_ok and check_artwork_against_package(artwork_svg_file, package, placed_parts[0])
        ARE_WE_GOOD = ARE_WE_GOOD and component_ok


    # Pull the package from the schematic
    # Either there is no <eagledevice> or there are multiple artwork files
    if component.find("schematic") is not None:
        has_eagle_device=True
        dir = join(components_dir, "Catalog", component.find("homedirectory").text)
        schematic_file = join(dir, component.find("schematic").get("filename"))
        if not os.path.isfile(schematic_file):
            sys.exit(keyname)
        schematic = SwoopGeom.from_file(schematic_file)

        for placedpart in placed_parts:
            refdes = placedpart.get("refdes")
            if refdes is None:
                missing_tag(keyname, placedpart, "refdes")
                ARE_WE_GOOD=False
                continue
            part = schematic.get_part(refdes)
            if len(part)==0:
                sys.stderr.write("refdes '{0}' of {1} refers to a nonexistent schematic part. "
                                 "Schematic file: {2}\n".
                                 format(placedpart.get("refdes"),keyname,schematic_file))
                ARE_WE_GOOD=False
                continue