show_image_old_working.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!doctype html>
  2. <head>
  3. <title>Dimension Extraction</title>
  4. <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
  5. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  6. <script src="https://unpkg.com/pdfjs-dist@latest/build/pdf.min.js"></script>
  7. </head>
  8. <body>
  9. <!--<div class="split left">-->
  10. <div class="container">
  11. <div class="column column-one">
  12. <h1>Drawing</h1>
  13. <p> <a href="http://localhost:5000/"> Upload another drawing </a> </p>
  14. {% if filename %}
  15. <div class="images">
  16. <img id="drawing" src="{{ url_for('send_file', filename=filename) }}">
  17. </div>
  18. <!-- <input type="file" id="pdf-upload"/>
  19. <hr/>
  20. <canvas class="frame"></canvas>-->
  21. {% else %}
  22. <h1>no image for whatever reason</h1>
  23. {% endif %}
  24. </div>
  25. <!--<div class="split middle">-->
  26. <div class="column column-two" id="measurements">
  27. <h1>Extracted Measurements</h1>
  28. <font size="3" face="Courier New" >
  29. <form>
  30. <table>
  31. <tr>
  32. <td style="text-align:center"><h3>Key Value</h3></td>
  33. <td style="text-align:center"><h3>Target Value</h3></td>
  34. <td style="text-align:center"><h3>Actual Value</h3></td>
  35. <td style="text-align:center"><h3>Relevant Isos</h3></td>
  36. </tr>
  37. {{ text | safe}}
  38. <!-- {% for key in dims %}
  39. <td><h4> {{key}} </h4></td>
  40. {% for d in dims[key] %}
  41. <tr>
  42. <td style="text-align:center"><input type="checkbox" name="relevant[]" value="checked"></td>
  43. <td style="text-align:center"> {{ d }}</td>
  44. <td style="text-align:center"><input type="text" name="{{ d }}" size="10"></td>
  45. </tr>
  46. {% endfor %}
  47. {% endfor %}-->
  48. </table>
  49. </form>
  50. </font>
  51. <div id="result">Result {{ number }}</div>
  52. </div>
  53. <!--<div class="split right">-->
  54. <div class="column column-three">
  55. <h1>Additional Infos</h1>
  56. <table>
  57. {% for link in links %}
  58. <tr>
  59. {% set l=links[link] %}
  60. <td> <h3> <a href=" {{ url_for('static', filename=l) }}" > {{ link }} </a> </h3> </td>
  61. </tr>
  62. {% endfor %}
  63. </table>
  64. </div>
  65. </div>
  66. <script>
  67. function set_redis(key, value) {
  68. $.ajax({
  69. type: "POST",
  70. url: "/redis/set/" + key,
  71. data: JSON.stringify({ value: value }),
  72. dataType: "json",
  73. contentType: "json",
  74. success: function(data)
  75. {
  76. (data.GET);
  77. }
  78. });
  79. }
  80. function get_redis(key) {
  81. $.ajax({
  82. type: "GET",
  83. url: "redis/get/" + key,
  84. data: "format=json",
  85. dataType: "text",
  86. success: function(data)
  87. {
  88. $("#result").text(data.GET);
  89. }
  90. });
  91. function split_string(string) {
  92. var string = str.split(" ",2);
  93. return string;
  94. });
  95. </script>
  96. <script>
  97. $(document).ready(function(){
  98. $("input[type=number]").on("change keyup input", function(){
  99. var array_value = [];
  100. array_value[0] = $(this).attr('name');
  101. array_value[1] = $(this).val();
  102. var key = 'last' + "_" +'{{og_filename}}';
  103. //console.log({{ dim }});
  104. set_redis(key, array_value);
  105. });
  106. $("input[type=checkbox]").change(function(){
  107. // Print entered value in a div box
  108. $("#result").text($(this).attr('name'));
  109. var key1 = 'last' + "_" +'{{og_filename}}';
  110. var array_value1 = [];
  111. if ($(this).is(':checked')) {
  112. console.log($(this).attr('name') + ' is now checked');
  113. array_value1[0] = 'relevant.' + $(this).attr('name');
  114. array_value1[1] = true;
  115. } else {
  116. console.log($(this).attr('name') + ' is now unchecked');
  117. array_value1[0] = $(this).attr('name');
  118. array_value1[1] = false;
  119. }
  120. set_redis(key1, array_value1);
  121. });
  122. $("input[type=number]").focus(function(){
  123. // highlight values, does not work so far
  124. var number = $(this).attr('name');
  125. var coords = $(this).attr('data-coords');
  126. highlight_areas(coords, "red");
  127. var detail = $(this).attr('data-details');
  128. console.log(detail, "green");
  129. highlight_details(detail, "green");
  130. });
  131. $("input[type=number]").blur(function(){
  132. $("div").removeClass("red");
  133. $("div").removeClass("green");
  134. });
  135. function highlight_areas(coords, color){
  136. let w = {{w}}
  137. let h = {{h}}
  138. let pos = $("#drawing").position();
  139. let drawing_x = pos.left;
  140. let drawing_y = pos.top;
  141. let array_coords = coords.split(",");
  142. let coords_x = parseFloat(array_coords[0]);
  143. let coords_xmax = parseFloat(array_coords[2]);
  144. let coords_y = parseFloat(array_coords[1]);
  145. let coords_ymax = parseFloat(array_coords[3]);
  146. let coords_width = (coords_xmax - coords_x);
  147. let coords_height = (coords_ymax - coords_y);
  148. let width = $("#drawing").width();
  149. let height = $("#drawing").height();
  150. let rel_width = coords_width/h*width*1.4;
  151. let rel_height = coords_height/w*height*1.4;
  152. let x = width*(coords_x*height/width/w);
  153. let y = height*(coords_y*width/height/h);
  154. console.log(w, h, rel_width, rel_height,x,y);
  155. let $point1 = jQuery("<div class="+color+"/>").css({top: (drawing_y + y -5) + 'px', left: (drawing_x + x-5) + 'px', width: rel_width , height: rel_height});
  156. $(".images").append($point1);
  157. };
  158. function highlight_details(coords, color){
  159. let w = {{w}}
  160. let h = {{h}}
  161. let pos = $("#drawing").position();
  162. let drawing_x = pos.left;
  163. let drawing_y = pos.top;
  164. let array_coords = coords.split(",");
  165. let coords_x = parseFloat(array_coords[0]);
  166. let coords_y = parseFloat(array_coords[1]);
  167. let width_div = (parseFloat(array_coords[2]) - parseFloat(array_coords[0]));
  168. let height_div = (parseFloat(array_coords[3]) - parseFloat(array_coords[1]));
  169. let width = $("#drawing").width();
  170. let rel_width = width_div/h*width;
  171. let height = $("#drawing").height();
  172. let rel_height = height*height_div/w;
  173. let x = width*(coords_x*height/width/w);
  174. let y= height*(coords_y*width/height/h);
  175. console.log(rel_width, rel_height);
  176. if (array_coords[3] > 10000) {
  177. rel_height = height - y;
  178. }
  179. let $point = jQuery("<div class="+color+"/>").css({top: (drawing_y + y) + 'px', left: (drawing_x + x) + 'px', width: (rel_width) + 'px', height: (rel_height) + 'px'});
  180. $(".images").append($point);
  181. };
  182. });
  183. </script>
  184. </body>