Rev 1522 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1522 | arune | 1 | #!/usr/bin/perl |
| 1523 | arune | 2 | ########################################################### |
| 3 | # Eagle diff script |
||
| 4 | # Author: Anders Runeson, 2010-07-18, arune @ EFnet |
||
| 5 | ########################################################### |
||
| 1522 | arune | 6 | |
| 1523 | arune | 7 | |
| 1522 | arune | 8 | use File::Basename; |
| 9 | use File::Copy; |
||
| 10 | |||
| 11 | #setup |
||
| 12 | #location of imagemagick compare binary |
||
| 13 | my $compare = "/usr/bin/compare"; |
||
| 14 | #location of eagle binary |
||
| 15 | my $eagle = "/usr/bin/eagle"; |
||
| 16 | #where to store temporary files |
||
| 17 | my $tmpdir = "/tmp"; |
||
| 18 | #the dpi parameter to send to eagle for generating images |
||
| 19 | my $brdresolution = 1000; |
||
| 20 | my $schresolution = 200; |
||
| 21 | #store the resulting images at the path of argument 1 or 2 |
||
| 22 | my $storeresult=2; |
||
| 23 | |||
| 24 | #name of eagle script file, will be created |
||
| 25 | my $eaglecommands=$tmpdir."/eaglecmd"; |
||
| 26 | |||
| 27 | #check number of arguments, must be 2 |
||
| 28 | my $argcount = @ARGV; |
||
| 29 | unless ($argcount eq "2") { |
||
| 30 | print "Syntax: perl eagle-compare <file1> <file2>\n"; |
||
| 31 | exit; |
||
| 32 | } |
||
| 33 | |||
| 34 | #read arguments and find file suffix |
||
| 35 | my $file1 = $ARGV[0]; |
||
| 36 | my $file2 = $ARGV[1]; |
||
| 37 | my(undef, undef, $suffix1) = fileparse($file1,qr"\..*"); |
||
| 38 | my(undef, undef, $suffix2) = fileparse($file2,qr"\..*"); |
||
| 39 | |||
| 40 | #check that files exists |
||
| 41 | unless (-e $file1) |
||
| 42 | { |
||
| 43 | print "File '$file1' does not exist.\n"; |
||
| 44 | exit; |
||
| 45 | } |
||
| 46 | unless (-e $file2) |
||
| 47 | { |
||
| 48 | print "File '$file2' does not exist.\n"; |
||
| 49 | exit; |
||
| 50 | } |
||
| 51 | #check that both files have the same suffix |
||
| 52 | unless ($suffix1 eq $suffix2) |
||
| 53 | { |
||
| 54 | print "File '$file1' does not have the same file type as '$file2'.\n"; |
||
| 55 | exit; |
||
| 56 | } |
||
| 57 | #check that suffix is a supported one |
||
| 58 | unless (($suffix1 eq ".brd") || ($suffix1 eq ".sch")) |
||
| 59 | { |
||
| 60 | print "Only .brd and .sch are supported.\n"; |
||
| 61 | exit; |
||
| 62 | } |
||
| 63 | |||
| 64 | my $storedir=$tmpdir; |
||
| 65 | if ($storeresult == 1) |
||
| 66 | { |
||
| 67 | $storedir = dirname($file1); |
||
| 68 | } |
||
| 69 | if ($storeresult == 2) |
||
| 70 | { |
||
| 71 | $storedir = dirname($file2); |
||
| 72 | } |
||
| 73 | |||
| 74 | #create a file name random, the file names will be too long if they are created with the path |
||
| 75 | $file1unique = $tmpdir."/".generate_random_string(8).$suffix1; |
||
| 76 | $file2unique = $tmpdir."/".generate_random_string(8).$suffix1; |
||
| 77 | |||
| 78 | #copy files to temp area |
||
| 79 | copy($file1, $file1unique); |
||
| 80 | copy($file2, $file2unique); |
||
| 81 | |||
| 82 | #if suffix is a layout file |
||
| 83 | if ($suffix1 eq ".brd") |
||
| 84 | { |
||
| 85 | #create eagle script file for first file argument |
||
| 86 | open (MYFILE,">".$eaglecommands); |
||
| 87 | print MYFILE "SET VECTOR_FONT ON\n"; |
||
| 88 | print MYFILE "DISPLAY ALL\n"; |
||
| 89 | print MYFILE "RIPUP @\n"; |
||
| 90 | print MYFILE "DISPLAY NONE 17 18 ?? 1\n"; |
||
| 91 | print MYFILE "EXPORT IMAGE ".$file1unique.".1.png ".$brdresolution."\n"; |
||
| 92 | print MYFILE "DISPLAY NONE 17 18 ?? 2\n"; |
||
| 93 | print MYFILE "EXPORT IMAGE ".$file1unique.".2.png ".$brdresolution."\n"; |
||
| 94 | print MYFILE "DISPLAY NONE 17 18 ?? 15\n"; |
||
| 95 | print MYFILE "EXPORT IMAGE ".$file1unique.".15.png ".$brdresolution."\n"; |
||
| 96 | print MYFILE "DISPLAY NONE 17 18 ?? 16\n"; |
||
| 97 | print MYFILE "EXPORT IMAGE ".$file1unique.".16.png ".$brdresolution."\n"; |
||
| 98 | print MYFILE "QUIT\n"; |
||
| 99 | close (MYFILE); |
||
| 100 | |||
| 101 | #run eagle with the first layout file and the created script file as arguments |
||
| 102 | #this will create 4 png files in the temp dir |
||
| 103 | system ($eagle, $file1unique, "-S", $eaglecommands); |
||
| 104 | |||
| 105 | #create eagle script file for second file argument |
||
| 106 | open (MYFILE,">".$eaglecommands); |
||
| 107 | print MYFILE "SET VECTOR_FONT ON\n"; |
||
| 108 | print MYFILE "DISPLAY ALL\n"; |
||
| 109 | print MYFILE "RIPUP @\n"; |
||
| 110 | print MYFILE "DISPLAY NONE 17 18 ?? 1\n"; |
||
| 111 | print MYFILE "EXPORT IMAGE ".$file2unique.".1.png ".$brdresolution."\n"; |
||
| 112 | print MYFILE "DISPLAY NONE 17 18 ?? 2\n"; |
||
| 113 | print MYFILE "EXPORT IMAGE ".$file2unique.".2.png ".$brdresolution."\n"; |
||
| 114 | print MYFILE "DISPLAY NONE 17 18 ?? 15\n"; |
||
| 115 | print MYFILE "EXPORT IMAGE ".$file2unique.".15.png ".$brdresolution."\n"; |
||
| 116 | print MYFILE "DISPLAY NONE 17 18 ?? 16\n"; |
||
| 117 | print MYFILE "EXPORT IMAGE ".$file2unique.".16.png ".$brdresolution."\n"; |
||
| 118 | print MYFILE "QUIT\n"; |
||
| 119 | close (MYFILE); |
||
| 120 | |||
| 121 | #run eagle with the second layout file and the created script file as arguments |
||
| 122 | #this will create 4 png files in the temp dir |
||
| 123 | system ($eagle, $file2unique, "-S", $eaglecommands); |
||
| 124 | |||
| 125 | #compare each png file for the first file argument and the second file argument |
||
| 126 | #the resulting compared images will be stored from where the script is run |
||
| 127 | system ($compare, $file1unique.".1.png", $file2unique.".1.png", $storedir."/eagle-diff-brd-layer1.png"); |
||
| 128 | system ($compare, $file1unique.".2.png", $file2unique.".2.png", $storedir."/eagle-diff-brd-layer2.png"); |
||
| 129 | system ($compare, $file1unique.".15.png", $file2unique.".15.png", $storedir."/eagle-diff-brd-layer15.png"); |
||
| 130 | system ($compare, $file1unique.".16.png", $file2unique.".16.png", $storedir."/eagle-diff-brd-layer16.png"); |
||
| 131 | |||
| 132 | #remove all intermediate files |
||
| 133 | unlink($file1unique.".1.png"); |
||
| 134 | unlink($file1unique.".2.png"); |
||
| 135 | unlink($file1unique.".15.png"); |
||
| 136 | unlink($file1unique.".16.png"); |
||
| 137 | unlink($file2unique.".1.png"); |
||
| 138 | unlink($file2unique.".2.png"); |
||
| 139 | unlink($file2unique.".15.png"); |
||
| 140 | unlink($file2unique.".16.png"); |
||
| 141 | unlink($eaglecommands); |
||
| 142 | } |
||
| 143 | |||
| 144 | |||
| 145 | if ($suffix1 eq ".sch") |
||
| 146 | { |
||
| 147 | #create eagle script file for first file argument |
||
| 148 | open (MYFILE,">".$eaglecommands); |
||
| 149 | #print MYFILE "SET VECTOR_FONT ON\n"; # causes a save-dialog-box if not already persistent in this drawing |
||
| 150 | print MYFILE "DISPLAY NONE 91 92 94 95 96 97 98\n"; |
||
| 151 | print MYFILE "EXPORT IMAGE ".$file1unique.".png ".$schresolution."\n"; |
||
| 152 | print MYFILE "QUIT\n"; |
||
| 153 | close (MYFILE); |
||
| 154 | |||
| 155 | #run eagle with the first schematic file and the created script file as arguments |
||
| 156 | #this will create one png file in the temp dir |
||
| 157 | system ($eagle, $file1unique, "-S", $eaglecommands); |
||
| 158 | |||
| 159 | #create eagle script file for second file argument |
||
| 160 | open (MYFILE,">".$eaglecommands); |
||
| 161 | #print MYFILE "SET VECTOR_FONT ON\n"; # causes a save-dialog-box if not already persistent in this drawing |
||
| 162 | print MYFILE "DISPLAY NONE 91 92 94 95 96 97 98\n"; |
||
| 163 | print MYFILE "EXPORT IMAGE ".$file2unique.".png ".$schresolution."\n"; |
||
| 164 | print MYFILE "QUIT\n"; |
||
| 165 | close (MYFILE); |
||
| 166 | |||
| 167 | #run eagle with the second schematic file and the created script file as arguments |
||
| 168 | #this will create one png file in the temp dir |
||
| 169 | system ($eagle, $file2unique, "-S", $eaglecommands); |
||
| 170 | |||
| 171 | #compare png file for the first file argument and the second file argument |
||
| 172 | #the resulting compared image will be stored from where the script is run |
||
| 173 | system ($compare, $file1unique.".png", $file2unique.".png", $storedir."/eagle-diff-sch.png"); |
||
| 174 | |||
| 175 | #remove all intermediate files |
||
| 176 | unlink($file1unique.".png"); |
||
| 177 | unlink($file2unique.".png"); |
||
| 178 | unlink($eaglecommands); |
||
| 179 | |||
| 180 | } |
||
| 181 | |||
| 182 | unlink($file1unique); |
||
| 183 | unlink($file2unique); |
||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | # This function generates random strings of a given length |
||
| 188 | sub generate_random_string |
||
| 189 | { |
||
| 190 | my $length_of_randomstring=shift;# the length of |
||
| 191 | # the random string to generate |
||
| 192 | |||
| 193 | my @chars=('a'..'z','A'..'Z','0'..'9','_'); |
||
| 194 | my $random_string; |
||
| 195 | foreach (1..$length_of_randomstring) |
||
| 196 | { |
||
| 197 | # rand @chars will generate a random |
||
| 198 | # number between 0 and scalar @chars |
||
| 199 | $random_string.=$chars[rand @chars]; |
||
| 200 | } |
||
| 201 | return $random_string; |
||
| 202 | } |
||
| 203 |