Reworked for more comprehensive range of plots - now does all layers

including two inner copper layers. Very easy to add more layers.
Also early version of text diff - this is surprisingly difficult to
implement as the s-expressions really need to be parsed in blocks.

New css based system and some initial work at putting some board stats on
the front page. Presently have to copy .css manually.
This commit is contained in:
John Pateman 2017-08-23 23:08:21 +01:00
parent db2ab46be8
commit 8fc8442fc1
1 changed files with 212 additions and 51 deletions

View File

@ -4,20 +4,17 @@
# If only one ref specified, generates a diff from that file
# If no refs specified, assumes CURRENT
# TODO Consider moving all formatting to a single, external css file and putting all
# created web content into a 'web' directory.
# TODO Improve 3-pane layout - possible two side by side and comparison image underneath?
# TODO Improve 3-pane layout - possible two side by side and comparison image underneath? id:16
# TODO Improve diff text parser. Currently difficult to diff as modules have multiple
# entries on different layers - need to identify graphic change with
# TODO Consider removing filename from display format i.e 'filename-F_Cu' becomes 'F_Cu' id:13
# TODO Add command line quality option - Quality is dpi. 100 is fast but low quality id:4
# 600 is very detailed. 300 is a good compromise.
# TODO Remove filename from display format i.e 'filename-F_Cu' becomes 'F_Cu'
qual="300"
qual="100"
# TODO Add command line quality option - Quality is dpi. 100 is fast but low quality
# 600 is very detailed. 300 is a good compromise.
# TODO Add recolour option
# 952927
# convert F_Cu.png -fill "#952927" -fuzz 75% -opaque "#ffffff" test2.png
# TODO Command line options for selecting which plots id:8
# Remove old plot files
rm -r /tmp/svg
@ -27,7 +24,7 @@ OUTPUT_DIR="./plots"
rm -r $OUTPUT_DIR
mkdir $OUTPUT_DIR
# TODO Have added this temporarily to simply remove all the plots prior to generating files.
# TODO Have added this temporarily to simply remove all the plots prior to generating files. id:12
# Theoretically the script could check if the files have already been generated and then only generate the
# missing files. This would permit multiple diff compares and you could also use an external diff tool like p4merge
# but the disadvantage is that the resoultions have to match. It is also more complicated to script
@ -38,18 +35,21 @@ mkdir $OUTPUT_DIR
# looked at using a graphical diff viewer like p4merge.
# Set directory for web backend
WEB_DIR="/web"
WEB_DIR="web"
mkdir $OUTPUT_DIR/$WEB_DIR
cp ~/Kicad/KiCad-Diff/style.css $WEB_DIR/
cp ~/Kicad/KiCad-Diff/style.css $OUTPUT_DIR/$WEB_DIR/
# TODO Might need to use a more complex strategy to cope with spaces in filename
# TODO Might need to use a more complex strategy to cope with spaces in filename id:17
# using some varient of 'find . -name "*.pro" -print0 | xargs -0'
#################################
# Colours to substitute per layer
#
# Additionally need to add vias, and internal layers.
# TODO Parse the pcbnew file to determine which layers are active.
# TODO Parse the pcbnew file to determine which layers are active. id:14
# TODO Sort these so that they make sense i.e all B together, all F etc id:5
# Presently these sort alphabetically - thus Cmts/Dwgs/Edge * ECO come between B & F Cu.
F_Cu="#952927"
B_Cu="#359632"
@ -60,14 +60,19 @@ B_SilkS="#481649"
B_Mask="#943197"
F_Mask="#943197"
Edge_Cuts="#C9C83B"
Margin="#D357D2"
In1_Cu="#C2C200"
In2_Cu="#C200C2"
User_Dwgs="#C2C2C2"
User_Cmts="#000085"
User_Eco1="#008500"
User_Eco2="#C2C200"
Dwgs_User="#0364D3"
Cmts_User="#000085"
Eco1_User="#008500"
Eco2_User="#C2C200"
B_Fab="#858585"
F_Fab="#C2C200"
B_Adhes="#3545A8"
F_Adhes="#A74AA8"
B_CrtYd="#D3D04B"
F_CrtYd="#A7A7A7"
# These are the colour definitions for the 'solarised' theme from pcbnew.
@ -137,6 +142,7 @@ if [ $# -eq 0 ]; then
for k in $CHANGED_KICAD_FILES; do
mkdir -p "$OUTPUT_DIR/$DIFF_1"
cp "$k" $OUTPUT_DIR/current
fossil info $DIFF_1 > "$OUTPUT_DIR/current/info.txt"
done
# Copy the specified Fossil commit kicad_file to $OUTPUT_DIR/$(Fossil ref)
@ -145,6 +151,7 @@ if [ $# -eq 0 ]; then
mkdir -p "$OUTPUT_DIR/$DIFF_2"
echo "Copying $DIFF_2:$k to $OUTPUT_DIR/$DIFF_2/$k"
fossil cat $k -r $DIFF_2 > "$OUTPUT_DIR/$DIFF_2/$(basename $k)"
fossil info $DIFF_2 > "$OUTPUT_DIR/$DIFF_2/info.txt"
done
# 2. User supplied 2 Fossil references to compare
@ -160,6 +167,7 @@ if [ $# -eq 0 ]; then
for k in $CHANGED_KICAD_FILES; do
mkdir -p "$OUTPUT_DIR/$DIFF_1"
fossil cat $k -r $DIFF_1 > "$OUTPUT_DIR/$DIFF_1/$(basename $k)"
fossil info $DIFF_1 > "$OUTPUT_DIR/$DIFF_1/info.txt"
done
# Copy the specified Fossil commit kicad_file to $OUTPUT_DIR/Fossil uuid
@ -168,9 +176,9 @@ if [ $# -eq 0 ]; then
mkdir -p "$OUTPUT_DIR/$DIFF_2"
echo "Copying $DIFF_2:$k to $OUTPUT_DIR/$DIFF_2/$k"
fossil cat $k -r $DIFF_2 > "$OUTPUT_DIR/$DIFF_2/$(basename $k)"
fossil info $DIFF_2 > "$OUTPUT_DIR/$DIFF_2/info.txt"
done
# 3. User provided too many references
else
@ -218,8 +226,6 @@ for p in /tmp/svg/$DIFF_1/*.svg; do
convert "$OUTPUT_DIR/$DIFF_1/${d%%.*}.png" -negate "$OUTPUT_DIR/$DIFF_1/${d%%.*}.png"
done
for p in /tmp/svg/$DIFF_2/*.svg; do
d=$(basename $p)
echo "Converting $p to .png"
@ -258,7 +264,6 @@ for p in $OUTPUT_DIR/$DIFF_1/*.png; do
convert "$OUTPUT_DIR/$DIFF_1/${d%%.*}.png" -fill ${!layerName} -fuzz 75% -opaque "#ffffff" "$OUTPUT_DIR/$DIFF_1/${d%%.*}.png"
done
for p in $OUTPUT_DIR/$DIFF_2/*.png; do
d=$(basename $p)
y=${d%.png}
@ -272,48 +277,188 @@ done
######################################
#
# Remove index.html prior to streaming new data
# TODO Would be neater to put thumbs, tryptych, index and any .css sheet in a 'web' directory
# TODO Would be neater to put thumbs, tryptych, index and any .css sheet in a 'web' directory id:9
#
if [ -e $OUTPUT_DIR/index.html ]
then rm $OUTPUT_DIR/index.html
if [ -e $OUTPUT_DIR/$WEB_DIR/index.html ]
then rm $OUTPUT_DIR/$WEB_DIR/index.html
fi
if [ -d thumbs ]
then echo "'thumbs' directory found"
else mkdir $OUTPUT_DIR/thumbs && echo "'thumbs' directory created"
else mkdir $OUTPUT_DIR/$WEB_DIR/thumbs && echo "'thumbs' directory created"
fi
if [ -d tryptych ]
then echo "'tryptych' directory found"
else mkdir $OUTPUT_DIR/tryptych && echo "'tryptych' directory created"
else mkdir $OUTPUT_DIR/$WEB_DIR/tryptych && echo "'tryptych' directory created"
fi
# Stream HTML <head> and <style> to index.html
##############################################
#
# It would make more sense to stream this to $OUTPUT_DIR/web/style.css
# and reuse it in the 'tryptich' section.
# and reuse it in the 'tryptych' section.
cat >> $OUTPUT_DIR/index.html <<HEAD
DIFF_1_DATE=$(fossil info $DIFF_1 | grep uuid: | awk -F' ' '{ print $3 }')
DIFF_1_TIME=$(fossil info $DIFF_1 | grep uuid: | awk -F' ' '{ print $4 }')
DIFF_2_DATE=$(fossil info $DIFF_2 | grep uuid: | awk -F' ' '{ print $3 }')
DIFF_2_TIME=$(fossil info $DIFF_2 | grep uuid: | awk -F' ' '{ print $4 }')
THICK1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | head -n 10 | grep thickness | sed 's/(thickness //g' | sed 's/)//g')
DRAWINGS1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | head -n 10 | grep drawings | sed 's/(drawings //g' | sed 's/)//g')
TRACKS1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | head -n 10 | grep tracks | sed 's/(tracks //g' | sed 's/)//g')
ZONES1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | head -n 10 | grep zones | sed 's/(zones //g' | sed 's/)//g')
MODULES1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | head -n 10 | grep modules | sed 's/(modules //g' | sed 's/)//g')
NETS1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | head -n 10 | grep nets | sed 's/(nets //g' | sed 's/)//g')
TITLE1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | grep title | sed 's/(title_block (title "//g' | sed 's/")//g')
DATE1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | grep date | sed 's/(date //g' | sed 's/)//g')
COMPANY1=$(cat $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | grep company | sed 's/(company "//g' | sed 's/")//g')
THICK2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | head -n 10 | grep thickness | sed 's/(thickness //g' | sed 's/)//g')
DRAWINGS2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | head -n 10 | grep drawings | sed 's/(drawings //g' | sed 's/)//g')
TRACKS2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | head -n 10 | grep tracks | sed 's/(tracks //g' | sed 's/)//g')
ZONES2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | head -n 10 | grep zones | sed 's/(zones //g' | sed 's/)//g')
MODULES2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | head -n 10 | grep modules | sed 's/(modules //g' | sed 's/)//g')
NETS2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | head -n 10 | grep nets | sed 's/(nets //g' | sed 's/)//g')
TITLE2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | grep title | sed 's/(title_block (title "//g' | sed 's/")//g')
DATE2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | grep date | sed 's/(date //g' | sed 's/)//g')
COMPANY2=$(cat $OUTPUT_DIR/$DIFF_2/*.kicad_pcb | grep company | sed 's/(company "//g' | sed 's/")//g')
#sed 's/(/<td><div class="th">/g' | sed 's/)/<\/td>/g')
cat >> $OUTPUT_DIR/$WEB_DIR/index.html <<HTML
<!DOCTYPE HTML>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="web/style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>
<div class="title">
PCBnew Graphical Diff</div>
<div class="box green"></div><div class="subtitle"><b>ADDED</b> i.e. in <b>$DIFF_1</b> and not in <b>$DIFF_2</b></div>
<div class="box red"></div><div class="subtitle"><b>REMOVED</b> i.e. in <b>$DIFF_2</b> and not in <b>$DIFF_1</b></div>
HEAD
<table style="border-color: #aaaaaa; width: 100%; height: 2px;" border="2px" cellspacing="2px" cellpadding="3px">
<tbody>
<tr>
<td colspan="3" width="261">
<div class="title">$CHANGED_KICAD_FILES</div>
<div class="th">$TITLE</div>
<div class="th">$DATE</div>
<div class="th">$COMPANY</div>
</td>
<td colspan="2" width="165">
<div class="th">Parameters</div>
</td>
</tr>
<tr>
<td width="83">
<p<div class="th">Version</div>
</td>
<td width="89">
<div class="th green">$DIFF_1</div>
</td>
<td width="89">
<div class="th red">$DIFF_2</div>
</td>
<td width="84">
<div class="td">Thickness (mm)</div>
</td>
<td width="40">
<div class="td">$THICK1 </div>
</td>
<td width="41">
<div class="td">$THICK2 </div>
</td>
</tr>
<tr>
<td width="83">
<div class="td"><strong>Date</div>
</td>
<td width="89">
<div class="td">$DIFF_1_DATE</div>
</td>
<td width="89">
<div class="td">$DIFF_2_DATE</div>
</td>
<td width="84">
<div class="td">Drawings</div>
</td>
<td width="40">
<div class="td">$DRAWINGS1</div>
</td>
<td width="41">
<div class="td">$DRAWINGS2</div>
</td>
</tr>
<tr>
<td width="83">
<div class="td"><strong>Time</div>
</td>
<td width="89">
<div class="td">$DIFF_1_TIME</div>
</td>
<td width="89">
<div class="td">$DIFF_2_TIME</div>
</td>
<td width="84">
<div class="td">Tracks</div>
</td>
<td width="40">
<div class="td">$TRACKS1</div>
</td>
<td width="41">
<div class="td">$TRACKS2</div>
</td>
</tr>
<tr>
<td colspan="3" rowspan="3" width="261">
</td>
<td width="84">
<div class="td">Zones</div>
</td>
<td width="40">
<div class="td">$ZONES1</div>
</td>
<td width="41">
<div class="td">$ZONES2</div>
</td>
</tr>
<tr>
<td width="84">
<div class="td">Modules</div>
</td>
<td width="40">
<div class="td">$MODULES1</div>
</td>
<td width="41">
<div class="td">$MODULES2</div>
</td>
</tr>
<tr>
<td width="84">
<div class="td">Nets</div>
</td>
<td width="40">
<div class="td">$NETS1</div>
</td>
<td width="41">
<div class="td">$NETS2</div>
</td>
</tr>
</tbody>
</table>
HTML
#cat ThermocoupleLogger.kicad_pcb grep $mod | head -n 10 | sed 's/(/<td><div class="th">/g' | sed 's/)/<\/td>/g'
for g in $OUTPUT_DIR/diff-$DIFF_1-$DIFF_2/*.png; do
convert $g -resize 300x245 ./plots/thumbs/th_$(basename $g)
# Attempt to force to same size to prevent gaps in page.
convert $g -resize 300x245 $OUTPUT_DIR/$WEB_DIR/thumbs/th_$(basename $g)
#cp $g ./plots/thumbs/th_$(basename $g)
# Attempt toforce to same size to prevent gaps in page.
route=$g
file=${route##*/}
@ -321,11 +466,11 @@ convert $g -resize 300x245 ./plots/thumbs/th_$(basename $g)
# dir=$(dirname $g)
# echo $dir
cat >> $OUTPUT_DIR/index.html <<HTML
cat >> $OUTPUT_DIR/$WEB_DIR/index.html <<HTML
<div class="responsive">
<div class="gallery">
<a target="_blank" href = tryptych/$(basename $g).html>
<img src = thumbs/th_$(basename $g) width="300" height="200">
<img src = thumbs/th_$(basename $g) width="200" height="150">
</a>
<div class="desc">$base</div>
</div>
@ -333,11 +478,11 @@ cat >> $OUTPUT_DIR/index.html <<HTML
HTML
cat >> $OUTPUT_DIR/tryptych/$(basename $g).html <<HTML
cat >>$OUTPUT_DIR/$WEB_DIR/tryptych/$(basename $g).html<<HTML
<!DOCTYPE HTML>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="../web/style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
<style>
div.responsive {
padding: 0 6px;
@ -353,7 +498,7 @@ div.responsive {
<div class="responsive">
<div class="gallery">
<a target="_blank" href = $(basename $g).html>
<a href= ../$DIFF_1/$(basename $g)><img src = "../$DIFF_1/$(basename $g)" width=500></a>
<a href= ../../$DIFF_1/$(basename $g)><img src = ../../$DIFF_1/$(basename $g) width=500></a>
</a>
<div class="desc green">$DIFF_1</div>
</div>
@ -361,8 +506,8 @@ div.responsive {
<div class="responsive">
<div class="gallery">
<a target="_blank" href = $(basename $g).html>
<a href = ../diff-$DIFF_1-$DIFF_2/$(basename $g) ><img src = ../diff-$DIFF_1-$DIFF_2/$(basename $g) width=500></a>
<a target="_blank" href = $OUTPUT_DIR/$(basename $g).html>
<a href = ../../diff-$DIFF_1-$DIFF_2/$(basename $g) ><img src = ../../diff-$DIFF_1-$DIFF_2/$(basename $g) width=500></a>
</a>
<div class="desc white">Composite</div>
</div>
@ -371,19 +516,35 @@ div.responsive {
<div class="responsive">
<div class="gallery">
<a target="_blank" href = $(basename $g).html>
<a href= ../$DIFF_2/$(basename $g)> <img src = "../$DIFF_2/$(basename $g)" width=500></a>
<a href= ../../$DIFF_2/$(basename $g)> <img src = ../../$DIFF_2/$(basename $g) width=500></a>
</a>
<div class="desc red">$DIFF_2</div>
</div>
</div>
<div class="title"><br>Differences</div>
HTML
d=$(basename $g)
y=${d%.png}
layerName=${y##*-}
mod=${layerName//[_]/.}
echo $mod
diff $OUTPUT_DIR/$DIFF_2/*.kicad_pcb $OUTPUT_DIR/$DIFF_1/*.kicad_pcb >> $OUTPUT_DIR/diff-$DIFF_1-$DIFF_2/diff.txt
diff $OUTPUT_DIR/$DIFF_2/*.kicad_pcb $OUTPUT_DIR/$DIFF_1/*.kicad_pcb | grep $mod | sed 's/> /<\/div><div class="details added">/g' | sed 's/< /<\/div><div class="details removed">/g' | sed 's/\/n/<\/div>/g' >> $OUTPUT_DIR/$WEB_DIR/tryptych/$(basename $g).html
done
cat >>$OUTPUT_DIR/index.html<<FOOT
# grep $mod | grep 'module' | sed 's/> /<div class="details">/g' | sed 's/< /<div class="details">/g' | sed 's/))/)<\/div>/g' >> $OUTPUT_DIR/$WEB_DIR/tryptych/$(basename $g).html
cat >>$OUTPUT_DIR/$WEB_DIR/tryptych/$(basename $g).html<<FOOT
<div class="clearfix"></div>
<div style="padding:6px;">
</div>
FOOT
done
cat >>$OUTPUT_DIR/$WEB_DIR/index.html<<FOOT
<div class="clearfix"></div>
<div style="padding:6px;">
</div>
FOOT
echo "HTML created and written to index.html"
open $OUTPUT_DIR/index.html
open $OUTPUT_DIR/$WEB_DIR/index.html