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