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.3KB

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