BlinkenArea - GitList
Repositories
Blog
Wiki
partlib
Code
Commits
Branches
Tags
Search
Tree:
cd92b87
Branches
Tags
master
stefan.experimental
partlib
pcb_stuff
pcb_text2lines.pl
move scripts into own subdir
Stefan Schuermans
commited
cd92b87
at 2014-01-11 13:44:27
pcb_text2lines.pl
Blame
History
Raw
#! /usr/bin/perl use strict; my $mode = ''; my $symbol; my $symbols = {}; my $layer = 0; while( my $line = <STDIN> ) { chomp( $line ); chomp( $line ); if( $line =~ /^Symbol\('(.)' ([0-9]+)\)$/ ) { $mode = 'symbol'; $symbol = {}; $symbol->{CHAR} = $1; $symbol->{WIDTH} = $2; $symbol->{LINES}; } elsif( $mode eq 'symbol' && $line =~ /^\($/ ) { $mode = 'symbol('; } elsif( $mode eq 'symbol' && $line =~ /^[A-Za-z]/ ) { $mode = ''; $symbol = undef; } elsif( $mode eq 'symbol(' && $line =~ /^\)$/ ) { $mode = ''; $symbols->{$symbol->{CHAR}} = $symbol; $symbol = undef; } elsif( $mode eq 'symbol(' && $line =~ /\tSymbolLine\(([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)\)$/ ) { my $s_line = {}; $s_line->{X1} = $1; $s_line->{Y1} = $2; $s_line->{X2} = $3; $s_line->{Y2} = $4; $s_line->{WIDTH} = $5; push( @{$symbol->{LINES}}, $s_line ); } elsif( $line =~ /^Layer\(([0-9]+) "(.*)"\)$/ ) { $layer = $1; } elsif( $line =~ /^\tText\[([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) "(.*)" "(.*)"\]$/ ) { my $x = $1; my $y = $2; my $angle = $3; my $size = $4; my $text = $5; my $flags = $6; for( my $i = 0; $i < length( $text ); $i++ ) { my $chr = substr( $text, $i, 1 ); my $char = $symbols->{$chr}; if( $char ) { my $width = $char->{WIDTH}; my $x_min = 0; my $y_min = 0; my $x_max = 0; my $y_max = 0; foreach my $s_line (@{$char->{LINES}}) { my $x1 = $s_line->{X1}; my $y1 = $s_line->{Y1}; my $x2 = $s_line->{X2}; my $y2 = $s_line->{Y2}; my $width = $s_line->{WIDTH}; if( $layer == 2 ) { if( $angle == 1 || $angle == 3 ) { $x1 = -$x1; $x2 = -$x2; } else { $y1 = -$y1; $y2 = -$y2; } } if( $angle == 1 ) { my $t = $x1; $x1 = $y1; $y1 = -$t; $t = $x2; $x2 = $y2; $y2 = -$t; } elsif( $angle == 2 ) { $x1 = -$x1; $y1 = -$y1; $x2 = -$x2; $y2 = -$y2; } elsif( $angle == 3 ) { my $t = $x1; $x1 = -$y1; $y1 = $t; $t = $x2; $x2 = -$y2; $y2 = $t; } $x_min = $x1 if( $x1 < $x_min ); $y_min = $y1 if( $y1 < $y_min ); $x_min = $x2 if( $x2 < $x_min ); $y_min = $y2 if( $y2 < $y_min ); $x_max = $x1 if( $x1 > $x_max ); $y_max = $y1 if( $y1 > $y_max ); $x_max = $x2 if( $x2 > $x_max ); $y_max = $y2 if( $y2 > $y_max ); printf( "\tLine[%d %d %d %d %d %d \"clearline%s\"]\n", $x + $x1 * $size, $y + $y1 * $size, $x + $x2 * $size, $y + $y2 * $size, $width * $size, 2 * $width * $size, ($flags ne '' ? ',' : '') . $flags ); } if( $angle == 0 ) { $x += ($x_max + $width) * $size; } elsif( $angle == 1 ) { if( $layer == 2 ) { $y += ($y_max + $width) * $size; } else { $y += ($y_min - $width) * $size; } } elsif( $angle == 2 ) { $x += ($x_min - $width) * $size; } elsif( $angle == 3 ) { if( $layer == 2 ) { $y += ($y_min - $width) * $size; } else { $y += ($y_max + $width) * $size; } } } } } print( $line . "\n" ); }