コード例 #1
0
    def test_from_string_part_placement(self):
        s = """%,Head,Stack,X,Y,R,H,skip,Ref,Comment,
1,1,1,4,22,-45,1,0,LED7,-LED-805
2,2,1,4,19,-45,1,0,LED8,-LED-805
3,1,1,4,16,-45,1,0,LED9,-LED-805"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(s, p.to_csv())
コード例 #2
0
    def test_from_string_only_comments(self):
        s = """%This is the first comment.
%This is the second comment."""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(2, len(p.instructions))
        self.assertEqual("This is the first comment.",
                         p.instructions[0].comment)
        self.assertEqual("This is the second comment.",
                         p.instructions[1].comment)
コード例 #3
0
    def test_from_string_stack_offset_no_comment(self):
        s = """%,StackOffsetCommand,Stack,X,Y,Comment
65535,1,0,0,0
65535,1,1,-0.04,-0.1"""

        normalized = """%,StackOffsetCommand,Stack,X,Y,Comment
65535,1,0,0,0,
65535,1,1,-0.04,-0.1,"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(normalized, p.to_csv())
コード例 #4
0
    def test_copies(self):
        s = """65535,0,0,0,,
65535,1,1,0,0.05,0402
65535,2,1,2,
0,1,1,141.73,-64.52,-90,0,0,,
1,1,1,156.59,-77.98,-90,0,0,,
2,1,1,144.78,-64.52,90,0,0,,
3,1,1,135.38,-64.52,0,0,0,,"""

        f = StringIO(s)
        p = PlacementInstructions.from_file(f)
        self.assertEqual(p.get_copies(), [])
コード例 #5
0
    def generate_instructions(self):
        logging.info("Generating instructions.")
        instructions = PlacementInstructions()
        logging.info("Adding offset instruction.")
        instructions.instructions.append(
            OriginOffsetInstruction(x=self.offset_x, y=self.offset_y))

        for x_offset, y_offset in self.copies:
            logging.info("Adding copy at ({0}, {1})".format(
                x_offset, y_offset))
            instructions.instructions.append(
                PanelizedBoardInstruction(x=x_offset, y=y_offset))

        for reel_number in sorted(self.reels.keys()):
            reel = self.reels[reel_number]
            logging.info(
                "Setting stack offset for Reel {0}".format(reel_number))
            instructions.instructions.append(
                StackOffsetInstruction(stack=reel.reel_number,
                                       x=reel.stack_x_offset,
                                       y=reel.stack_y_offset,
                                       comment=reel.comment))
            logging.info(
                "Setting feed spacing for Reel {0}".format(reel_number))
            instructions.instructions.append(
                FeedSpacingInstruction(stack=reel.reel_number,
                                       feed_spacing=reel.feed_spacing))

        logging.info("Collecting all parts.")
        all_parts = []
        for reel_number in sorted(self.parts.keys()):
            for part in self.parts[reel_number]:
                if part.reel != reel_number:
                    logging.warning(
                        "Part reel number doesn't match the Reel reel number.")
                all_parts.append(part)

        for index, part in enumerate(all_parts):
            logging.info("Processing Part {0}".format(part.reference))
            total_rotation = part.rotation + self.get_reel_for_part(
                part).rotation
            instructions.instructions.append(
                PartPlacementInstruction(
                    part_number=index + 1,
                    pickup_head=part.head,
                    rotation=total_rotation,
                    stack=part.reel,
                    x=part.x,
                    y=part.y,
                    height=self.get_reel_for_part(part).height))
        return instructions
コード例 #6
0
    def test_from_file_parse_error(self):
        s = """%,Head,Stack,X,Y,R,H,skip,Ref,Comment,
1,1,1,4,22,-45,1,0,LED7,-LED-805
2,2,1,4,19,-45,1,0,LED8,-LED-805
PARSE ERROR NOT IN YOUR FAVOR"""
        f = StringIO(s)

        with LogCapture() as logs:
            try:
                p = PlacementInstructions.from_file(f)
            except:
                pass
            else:
                self.fail()

            logs.check(('root', 'ERROR',
                        "Error parsing line: PARSE ERROR NOT IN YOUR FAVOR"))
コード例 #7
0
ファイル: kicad_import.py プロジェクト: zdeniz/tm2x0
def main():
    logging.basicConfig(stream=sys.stderr,
                        level=logging.DEBUG,
                        format='(%(levelname)s): %(message)s')
    try:
        arguments = parse_command_line(sys.argv)
        with open(arguments.kicad_file) as kicad_handle:
            if arguments.csv_file:
                try:
                    csv_handle = open(arguments.csv_file)
                    instructions = PlacementInstructions.from_file(csv_handle)
                    p = Placement.from_instructions(instructions)
                    csv_handle.close()
                except IOError:
                    raise
            else:
                p = Placement()

            kicad_parts = KicadPartPositions.from_file(kicad_handle)

            if arguments.side == "front":
                side = "Front"
            elif arguments.side == "back":
                side = "Back"
            else:
                raise Exception("Unknown side")

            p.clear_parts()

            cli = PlacementCLI(placement=p,
                               unassigned_parts=kicad_parts.instructions[side],
                               output_filename=arguments.output_filename)
            cli.run()

    finally:
        logging.shutdown()
コード例 #8
0
    def test_from_string_panelized_boards(self):
        s = """%,JointedBoardCommand,X,Y
65535,3,1,0,0,0,0,0,"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(s, p.to_csv())
コード例 #9
0
    def test_from_string_feed_spacing(self):
        s = """%,FeedSpacingCommand,Stack,FeedSpacing,
65535,2,0,18,
65535,2,1,4,"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(s, p.to_csv())
コード例 #10
0
    def test_from_string_stack_offset(self):
        s = """%,StackOffsetCommand,Stack,X,Y,Comment
65535,1,0,0,0,
65535,1,1,-0.04,-0.1,0603"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(s, p.to_csv())
コード例 #11
0
    def test_from_string_blank_line(self):
        s = """
"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(s, p.to_csv())
コード例 #12
0
    def test_from_string_origin_offset(self):
        s = """%,OriginOffsetCommand,X,Y,,
65535,0,0,0,,"""
        p = PlacementInstructions.from_string(s)
        self.assertEqual(s, p.to_csv())
コード例 #13
0
 def test_add_to_string(self):
     with self.assertRaises(NotImplementedError):
         pi = PlacementInstructions.from_string("655535,69,69,69,69")