Subversion Repositories HomeAutomation

Rev

Rev 1523 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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