/gist:76569d745033eac7e3b3 Secret
Created
June 28, 2015 06:17
Star
You must be signed in to star a gist
ugly code that causes the problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl6 | |
| my $FILENAME = 'pins.ASC'; | |
| my $WIDTH = 500; | |
| my $HEIGHT = 500; | |
| my @parts; | |
| my ($xMin, $yMin, $xMax, $yMax); | |
| sub MAIN($filename, Str $layer where /^[T|B]$/ = 'T') { | |
| @parts = gather { | |
| ($xMin, $yMin, $xMax, $yMax) = process $filename; | |
| }; | |
| say “<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| <svg | |
| xmlns:dc="http://purl.org/dc/elements/1.1/" | |
| xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
| xmlns:svg="http://www.w3.org/2000/svg" | |
| xmlns="http://www.w3.org/2000/svg" | |
| width="500" | |
| height="500" | |
| id="svg2" | |
| version="1.1">”; | |
| printPart $_ for grep { .part<layer> eq $layer }, @parts; | |
| say ‘</svg>’; | |
| } | |
| class Part { | |
| has Match $.part; | |
| has Match @.pins; | |
| } | |
| sub process($filename) { | |
| my $fh = open $filename, :r; | |
| my $part; | |
| my ($xMin, $yMin, $xMax, $yMax); | |
| for $fh.lines { | |
| if /:r ^ Part \s+ $<name>=[\w+] \s+ '(' $<layer>=[T | B] ')' $/ { | |
| $part = Part.new(part => $/); | |
| take $part; | |
| next; | |
| } | |
| next unless $part; | |
| if /:r ^ | |
| \s* $<pin>=[\d+] | |
| \s+ $<name>=[\w+] | |
| \s+ $<x>=[\d*'.'\d+] | |
| \s+ $<y>=[\d*'.'\d+] | |
| \s+ $<layer>=[\d] | |
| \s+ $<net>=[\w+] | |
| \s+ $<nail>=[\d+] | |
| $/ { | |
| $xMin min= +$<x>; | |
| $yMin min= +$<y>; | |
| $xMax max= +$<x>; | |
| $yMax max= +$<y>; | |
| $part.pins.push: $/; | |
| $*ERR.print: '.'; | |
| } | |
| } | |
| return $xMin, $yMin, $xMax, $yMax; | |
| } | |
| sub getColor($) is cached { | |
| use Digest::SHA; | |
| return '#' ~ [~] (sha256 "hello".encode: 'ascii').list[^3]».fmt: '%02x' | |
| } | |
| sub printPart($part) { | |
| for $part.pins { | |
| say “ <circle cx="{(.<x> - $xMin)/($xMax - $xMin) * $WIDTH}" cy="{(.<y> - $yMin)/($yMax - $yMin) * $HEIGHT}" r="1" fill="{getColor(.<net>)}" />” | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment