Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

generate_docs.sh 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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="drumkit.kicad_sch"
  28. INPCB="drumkit.kicad_pcb"
  29. cd "$(dirname "$0")"
  30. #echo "Generating plots"
  31. rm -rf src/plot
  32. #../pcb/generate_plot.sh
  33. cp -r ../pcb/plot src
  34. #echo
  35. #echo "Generating stls"
  36. rm -rf src/stl
  37. #../3dprint/generate_stls.sh
  38. cp -r ../3dprint/stl src
  39. #echo
  40. INSTL=`ls ../3dprint/stl/*.stl`
  41. for IN in $INSCH
  42. do
  43. o="src/inc_$IN.md"
  44. echo "Include for $IN at $o"
  45. rm -rf $o
  46. echo "<script src=\"js/svg-pan-zoom.js\" charset=\"UTF-8\"></script>" >> $o
  47. for f in `ls src/plot/$IN.svg/*.svg | sort -r`; do
  48. file=`echo $f | sed 's:src/:./:g'`
  49. name=`echo $f | sed "s:src/plot/$IN.svg/::g" | sed 's:.svg::g'`
  50. echo "Sheet at $name"
  51. echo "<h2>$name</h2>" >> $o
  52. echo "<div style=\"background-color: white; border: 1px solid black;\">" >> $o
  53. echo "<embed type=\"image/svg+xml\" src=\"$file\" id=\"pz_$name\" style=\"width:100%;\"/>" >> $o
  54. echo "<script>" >> $o
  55. echo "document.getElementById('pz_$name').addEventListener('load', function(){" >> $o
  56. echo "svgPanZoom(document.getElementById('pz_$name'), {controlIconsEnabled: true, minZoom: 1.0});" >> $o
  57. echo "})" >> $o
  58. echo "</script>" >> $o
  59. echo "</div>" >> $o
  60. echo >> $o
  61. echo "[Direct link to \`$name\`]($file)." >> $o
  62. echo >> $o
  63. done
  64. echo
  65. done
  66. plot_3d() {
  67. echo '<script type="importmap">' >> $1
  68. echo ' {' >> $1
  69. echo ' "imports": {' >> $1
  70. echo ' "three": "https://cdn.jsdelivr.net/npm/three@0.163.0/build/three.module.js",' >> $1
  71. echo ' "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.163.0/examples/jsm/"' >> $1
  72. echo ' }' >> $1
  73. echo ' }' >> $1
  74. echo '</script>' >> $1
  75. echo "<p>Status: \"<span id=\"3d_info_$2\">Preparing 3D model...</span>\"</p>" >> $1
  76. echo "<div id=\"3d_viewer_$2\" style=\"width: 100%; height: 100%; background-color: white; border: 1px solid black; position: relative;\"></div>" >> $1
  77. echo '<script type="module">' >> $1
  78. echo " var info = document.getElementById(\"3d_info_$2\");" >> $1
  79. echo " var view = document.getElementById(\"3d_viewer_$2\");" >> $1
  80. echo ' view.style.height = Math.floor(view.clientWidth * 0.707) + "px";' >> $1
  81. echo ' import { init_3d } from "./js/3d.js";' >> $1
  82. echo " init_3d(\"$3\", view, info, view.clientWidth, view.clientHeight);" >> $1
  83. echo '</script>' >> $1
  84. }
  85. for IN in $INPCB
  86. do
  87. o="src/inc_$IN.md"
  88. file="plot/$IN.wrl"
  89. name=`echo $file | sed "s:plot/::g" | sed 's:.wrl::g'`
  90. echo "Include for $IN at $o, $file, $name"
  91. rm -rf $o
  92. plot_3d $o $name $file
  93. echo
  94. done
  95. for IN in $INSTL
  96. do
  97. o=`echo $IN | sed "s:../3dprint/stl/:src/inc_:g" | sed "s:.stl:.stl.md:g"`
  98. file=`echo $IN | sed "s:../3dprint/::g"`
  99. name=`echo $file | sed "s:stl/::g" | sed 's:.stl::g'`
  100. echo "Include for $IN at $o, $file, $name"
  101. rm -rf $o
  102. plot_3d $o $name $file
  103. echo
  104. done
  105. echo "Generating docs"
  106. if [ "$1" = "serve" ] ; then
  107. mdbook serve --open
  108. elif [ "$1" = "build" ] ; then
  109. mdbook build
  110. else
  111. echo "Invalid command. 'build' or 'serve'."
  112. fi