Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate_docs.sh 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/bin/bash
  2. # SPDX-FileCopyrightText: 2024 Thomas Buck <thomas@xythobuz.de>
  3. # SPDX-License-Identifier: CERN-OHL-S-2.0+
  4. #
  5. # ------------------------------------------------------------------------------
  6. # | Copyright (c) 2024 Thomas Buck <thomas@xythobuz.de> |
  7. # | |
  8. # | This source describes Open Hardware and is licensed under the CERN-OHL-S v2 |
  9. # | or any later version. |
  10. # | |
  11. # | You may redistribute and modify this source and make products using it under |
  12. # | the terms of the CERN-OHL-S v2 (https://ohwr.org/cern_ohl_s_v2.txt) |
  13. # | or any later version. |
  14. # | |
  15. # | This source is distributed WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, |
  16. # | INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A |
  17. # | PARTICULAR PURPOSE. Please see the CERN-OHL-S v2 (or any later version) |
  18. # | for applicable conditions. |
  19. # | |
  20. # | Source location: https://git.xythobuz.de/thomas/drumkit |
  21. # | |
  22. # | As per CERN-OHL-S v2 section 4, should You produce hardware based on this |
  23. # | source, You must where practicable maintain the Source Location visible |
  24. # | on the external case of the Gizmo or other products you make using this |
  25. # | source. |
  26. # ------------------------------------------------------------------------------
  27. INSCH="../pcb/drumkit.kicad_sch ../pcb2/lars2.kicad_sch"
  28. INPCB="../pcb/drumkit.kicad_pcb ../pcb2/lars2.kicad_pcb"
  29. cd "$(dirname "$0")"
  30. if [ "$1" = "build" ] ; then
  31. echo "Generating plots"
  32. ../pcb/generate_plot.sh
  33. echo
  34. echo "Generating fab"
  35. ../pcb/generate_fab.sh
  36. echo
  37. echo "Generating plots 2"
  38. ../pcb2/generate_plot.sh
  39. echo
  40. echo "Generating fab 2"
  41. ../pcb2/generate_fab.sh
  42. echo
  43. echo "Generating stls"
  44. ../3dprint/generate_stls.sh
  45. echo
  46. fi
  47. rm -rf src/plot
  48. cp -r ../pcb/plot src
  49. cp -r ../pcb2/plot/* src/plot/
  50. cp ../pcb/fab.zip src/plot/fab_pcb.zip
  51. cp ../pcb2/fab.zip src/plot/fab_pcb2.zip
  52. rm -rf src/stl
  53. cp -r ../3dprint/stl src
  54. INSTL=`ls ../3dprint/stl/*.stl`
  55. for path in $INSCH
  56. do
  57. IN=`echo $path | sed "s:../pcb.\\?/::g"`
  58. o="src/inc_$IN.md"
  59. echo "Include for $IN at $o"
  60. rm -rf $o
  61. echo "<script src=\"js/svg-pan-zoom.js\" charset=\"UTF-8\"></script>" >> $o
  62. for f in `ls src/plot/$IN.svg/*.svg | sort -r`; do
  63. file=`echo $f | sed 's:src/:./:g'`
  64. name=`echo $f | sed "s:src/plot/$IN.svg/::g" | sed 's:.svg::g'`
  65. echo "Sheet at $name"
  66. echo "<h2>$name</h2>" >> $o
  67. echo "<div style=\"background-color: white; border: 1px solid black;\">" >> $o
  68. echo "<embed type=\"image/svg+xml\" src=\"$file\" id=\"pz_$name\" style=\"width:100%;\"/>" >> $o
  69. echo "<script>" >> $o
  70. echo "document.getElementById('pz_$name').addEventListener('load', function(){" >> $o
  71. echo "svgPanZoom(document.getElementById('pz_$name'), {controlIconsEnabled: true, minZoom: 1.0});" >> $o
  72. echo "})" >> $o
  73. echo "</script>" >> $o
  74. echo "</div>" >> $o
  75. echo >> $o
  76. echo "[Direct link to \`$name\`]($file)." >> $o
  77. echo >> $o
  78. done
  79. echo
  80. done
  81. plot_3d() {
  82. echo '<script type="importmap">' >> $1
  83. echo ' {' >> $1
  84. echo ' "imports": {' >> $1
  85. echo ' "three": "https://cdn.jsdelivr.net/npm/three@0.163.0/build/three.module.js",' >> $1
  86. echo ' "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.163.0/examples/jsm/"' >> $1
  87. echo ' }' >> $1
  88. echo ' }' >> $1
  89. echo '</script>' >> $1
  90. echo "<p>Status: \"<span id=\"3d_info_$2\">Preparing 3D model...</span>\"</p>" >> $1
  91. echo "<div id=\"3d_viewer_$2\" style=\"width: 100%; height: 100%; background-color: white; border: 1px solid black; position: relative;\"></div>" >> $1
  92. echo '<script type="module">' >> $1
  93. echo " var info = document.getElementById(\"3d_info_$2\");" >> $1
  94. echo " var view = document.getElementById(\"3d_viewer_$2\");" >> $1
  95. echo ' view.style.height = Math.floor(view.clientWidth * 0.707) + "px";' >> $1
  96. echo ' import { init_3d } from "./js/3d.js";' >> $1
  97. echo " init_3d(\"$3\", view, info, view.clientWidth, view.clientHeight);" >> $1
  98. echo '</script>' >> $1
  99. }
  100. for path in $INPCB
  101. do
  102. IN=`echo $path | sed "s:../pcb.\\?/::g"`
  103. o="src/inc_$IN.md"
  104. file="plot/$IN.wrl"
  105. name=`echo $file | sed "s:plot/::g" | sed 's:.wrl::g'`
  106. echo "Include for $IN at $o, $file, $name"
  107. rm -rf $o
  108. plot_3d $o $name $file
  109. done
  110. echo
  111. for IN in $INSTL
  112. do
  113. o=`echo $IN | sed "s:../3dprint/stl/:src/inc_:g" | sed "s:.stl:.stl.md:g"`
  114. file=`echo $IN | sed "s:../3dprint/::g"`
  115. name=`echo $file | sed "s:stl/::g" | sed 's:.stl::g'`
  116. echo "Include for $IN at $o, $file, $name"
  117. rm -rf $o
  118. plot_3d $o $name $file
  119. done
  120. echo
  121. echo "Generating docs"
  122. if [ "$1" = "serve" ] ; then
  123. mdbook serve --open
  124. elif [ "$1" = "build" ] ; then
  125. mdbook build
  126. else
  127. echo "Invalid command. 'build' or 'serve'."
  128. fi