aboutsummaryrefslogtreecommitdiff
path: root/convert.sh
blob: 9a8f6395c4129ee8b0967d369630f83aab7b9cb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#
# This script runs the conversion from Altium to KiCad. It expects the
# Altium project in ../../../hardware/cad/rev03/ and the altium2kicad
# source in ../altium2kicad
#

set -e

# this facilitates reproducible conversions, making all timestamps the same for consecutive runs
export A2K_STARTTIME="1476542686"

altiumdir="rev03-Altium"
kicaddir="rev03-KiCad"

#test -d altium2kicad || git clone https://github.com/thesourcerer8/altium2kicad
# We currently need some Cryptech hacks to this script, so get it from fredrikt's fork instead.
test -d altium2kicad || git clone -b ft-2017-09-cryptech_mods https://github.com/fredrikt/altium2kicad

rm -rf ${altiumdir}
test -d hardware || git clone https://git.cryptech.is/hardware.git
cp -rp hardware/cad/rev03 ${altiumdir}

cd ${altiumdir}

# make sheet numbers in filenames two digits to have them sort properly
rename 's/rev02_/rev02_0/' rev02_?.*

../altium2kicad/unpack.pl
# Create WRL files using FreeCAD, unless wrl-files.tar.gz already exists
# (and I've checked that file into the repository so that you do not have
# to install FreeCAD).
# Something is not 100% working in the step2wrl.FCMacro file, so you have
# to close all the FreeCAD windows that are opened after they finish executing
# the macro.
test -f ../wrl-files.tar.gz || ../make-wrl-files.sh
tar zxf ../wrl-files.tar.gz

time ../altium2kicad/convertschema.pl
time ../altium2kicad/convertpcb.pl

cd ..

rm -rf "${kicaddir}"
mkdir "${kicaddir}"
cp ${altiumdir}/*.{sch,lib} "${kicaddir}"/
rm ${kicaddir}/rev02*-cache.lib
cp ${altiumdir}/CrypTech-PcbDoc.kicad_pcb "${kicaddir}/Cryptech Alpha.kicad_pcb"
cp -rp ${altiumdir}/wrlshp ${kicaddir}/wrlshp
# Install prepared KiCAD project file and top-level schematic sheet.
cp "Cryptech Alpha.pro.template" "${kicaddir}/Cryptech Alpha.pro"
cp "Cryptech Alpha.sch.template" "${kicaddir}/Cryptech Alpha.sch"

# Fix wrl paths - XXX should be made relative paths
wrlpath=$(readlink -f ${altiumdir}/wrlshp)
sed -i -e "s!${wrlpath}!wrlshp!g" ${kicaddir}/rev02_*

cd ${kicaddir}

# Change to more sensible filenames
rename 's/-SchDoc//' rev02_*
sed -i -e 's/-SchDoc//g' *.{sch,lib}

# Change some PCB parameters
sed -i -e 's/trace_min 0.254/trace_min 0.15/g' "Cryptech Alpha.kicad_pcb"
# show ratsnest
sed -i -e 's/visible_elements 7FFFF77F/visible_elements 7FFFFF7F/g' "Cryptech Alpha.kicad_pcb"
# Power layers
for l in 1 3 4 6; do
    sed -i -e "s/${l} In${l}.Cu signal/${l} In${l}.Cu power/g" "Cryptech Alpha.kicad_pcb"
done
# Mixed layers
for l in 2 5; do
    sed -i -e "s/${l} In${l}.Cu signal/${l} In${l}.Cu mixed/g" "Cryptech Alpha.kicad_pcb"
done

# Sheet number fixups. This hides all the hierarchical sub-sheets from the project view.
num_sheets=$(ls Cryptech\ Alpha.sch rev02*sch | wc -l)
num=1
ls Cryptech\ Alpha.sch rev02*sch | while read file; do
    sed -i -e "s/^Sheet .*/Sheet ${num} ${num_sheets}/g" "${file}"
    num=$[$num + 1]
done

# Make further modifications to the layout using KiCAD's Python bindings
mkdir ../tmp
cp "Cryptech Alpha.kicad_pcb" "../tmp/Cryptech Alpha.kicad_pcb.a2k-out"
../fix-pcb.py "Cryptech Alpha.kicad_pcb" "Cryptech Alpha.kicad_pcb"
mv "Cryptech Alpha.kicad_pcb.before-fix-pcb" ../tmp
diff -u "../Cryptech Alpha.kicad_pcb.before-fix-pcb" "Cryptech Alpha.kicad_pcb" || true

echo ""
echo "Done. The leftovers from conversion is in ${altiumdir}, and you can start KiCad like this:"
echo ""
echo "  kicad \"${kicaddir}/Cryptech Alpha.pro\""
echo ""