Subversion Repositories wimsdev

Rev

Rev 15111 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include "canvasdraw.h"
  2.  
  3. /* What reply format in read_canvas();
  4.  
  5. note: if userdraw is combined with inputfields...every "userdraw" based answer will append "\n" and  inputfield.value()
  6. 1 = x1,x2,x3,x4....x_n
  7.     y1,y2,y3,y4....y_n
  8.  
  9.     x/y in pixels
  10.  
  11. 2 = x1,x2,x3,x4....x_n
  12.     y1,y2,y3,y4....y_n
  13.     x/y in xrange / yrange coordinate system
  14.  
  15. 3 = x1,x2,x3,x4....x_n
  16.     y1,y2,y3,y4....y_n
  17.     r1,r2,r3,r4....r_n
  18.  
  19.     x/y in pixels
  20.     r in pixels
  21.  
  22. 4 = x1,x2,x3,x4....x_n
  23.     y1,y2,y3,y4....y_n
  24.     r1,r2,r3,r4....r_n
  25.  
  26.     x/y in xrange / yrange coordinate system
  27.     r in pixels
  28.  
  29. 5 = Ax1,Ax2,Ax3,Ax4....Ax_n
  30.     Ay1,Ay2,Ay3,Ay4....Ay_n
  31.     Bx1,Bx2,Bx3,Bx4....Bx_n
  32.     By1,By2,By3,By4....By_n
  33.     Cx1,Cx2,Cx3,Cx4....Cx_n
  34.     Cy1,Cy2,Cy3,Cy4....Cy_n
  35.     ....
  36.     Zx1,Zx2,Zx3,Zx4....Zx_n
  37.     Zy1,Zy2,Zy3,Zy4....Zy_n
  38.  
  39.     x/y in pixels
  40.  
  41. 6 = Ax1,Ax2,Ax3,Ax4....Ax_n
  42.     Ay1,Ay2,Ay3,Ay4....Ay_n
  43.     Bx1,Bx2,Bx3,Bx4....Bx_n
  44.     By1,By2,By3,By4....By_n
  45.     Cx1,Cx2,Cx3,Cx4....Cx_n
  46.     Cy1,Cy2,Cy3,Cy4....Cy_n
  47.     ....
  48.     Zx1,Zx2,Zx3,Zx4....Zx_n
  49.     Zy1,Zy2,Zy3,Zy4....Zy_n
  50.  
  51.     x/y in xrange / yrange coordinate system
  52.  
  53. 7 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  54.  
  55.     x/y in pixels
  56.  
  57. 8 = x1:y1,x2:y2,x3:y3,x4:y4...x_n:y_n
  58.  
  59.     x/y in xrange / yrange coordinate system
  60.  
  61. 9 = x1:y1:r1,x2:y2:r2,x3:y3:r3,x4:y4:r3...x_n:y_n:r_n
  62.  
  63.     x/y in pixels
  64.  
  65. 10 = x1 ; y1 ;r1 \n x2;y2;r2 \n x3;y3;r3 \n ...x_n:y_n:r_n \n
  66.  
  67.     x/y in xrange / yrange coordinate system
  68.     r is userdraw_radius
  69.  
  70. 11 = Ax1,Ay1,Ax2,Ay2
  71.      Bx1,By1,Bx2,By2
  72.      Cx1,Cy1,Cx2,Cy2
  73.      Dx1,Dy1,Dx2,Dy2
  74.      ......
  75.      Zx1,Zy1,Zx2,Zy2
  76.  
  77.     x/y in  xrange / yrange coordinate system
  78.  
  79. 12 = Ax1,Ay1,Ax2,Ay2
  80.      Bx1,By1,Bx2,By2
  81.      Cx1,Cy1,Cx2,Cy2
  82.      Dx1,Dy1,Dx2,Dy2
  83.      ......
  84.      Zx1,Zy1,Zx2,Zy2
  85.  
  86.     x/y in pixels
  87.  
  88. 13 = removed
  89. 14 = Ax1:Ay1:Ax2:Ay2,Bx1:By1:Bx2:By2....Zx1:Zy1:Zx2:Zy2
  90.     x/y in pixels
  91. 15 = reply from inputfields,textareas
  92.     reply1,reply2,reply3,...,reply_n
  93.     only fields set write (e.g. will not read readonly inputfield values.
  94.  
  95. 16 = read mathml inputfields only
  96.  
  97. 17 = read userdraw text only (x1,y1,text1\nx2,y2,text2..\n.x_n,y_n,text_n
  98.  when ready: calculate size_t of string via snprintf(NULL,0,"blah blah...");
  99.  
  100. 18 = read clock(s): H1:M1:S1,H2:M2:S2,...H_n:M_n:S_n
  101. 19 = return clicked object number (analogue to shape-library onclick)
  102. 20 = return x/y-data in x-range/y-range of all ''draggable`` images
  103. 21 = return verbatim coordinates (x1:y1) (x2:y2)...(x_n:y_n)
  104. 22 = array: x1,y1,x2,y2,x3,y3,x4,y4...x_n,y_n
  105.     x/y in xrange / yrange coordinate system
  106. 23 = answertype for a polyline: remove multiple occurences due to reclick on a point to create next polyline segment
  107. 24 = read all inputfield values: even those set <code>readonly</code>
  108. 25 = return all userdrawn arcs in degrees:
  109. 26 = return all userdrawn arcs in radians:
  110. 27 = return (only) userdraw inputfields array: x1,y1,text1 \n x2,y2,text2...
  111. 28 = x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  112.     x/y/r in xrange / yrange coordinate system: may be used to reinput into command
  113.     circles color,x1,y1,r1,x2,y2,r2...x_n,y_n,r_n
  114.     will not return anything else (e.g. no inputfields, text etc)
  115. 29 = mulidraw read:
  116.  
  117. */
  118.  
  119. /*
  120. SCHAERSVOORDE: replyformat 2,7,8,21,22,23,24
  121. USERDRAW DEFAULTS: 2,6,8,10,11,15,16,17,18,19,20,23,24,25,27,29,31
  122. OEF: 22,23,28
  123.  
  124. TO BE REMOVED: 1,3,4,5,9,12,13,14,21
  125. */
  126. void add_read_canvas(int type_reply,int reply_precision){
  127. /* just 1 reply type allowed...except for format 34 !!!  */
  128. fprintf(js_include_file,"\
  129. \n/* set_reply_precision() */\
  130. function set_reply_precision(){\
  131. var len = userdraw_x.length;\
  132. var prec = %d;\
  133. for(var p = 0 ; p < len ; p++ ){\
  134.  userdraw_x[p] = (Math.round(prec*userdraw_x[p]))/prec;\
  135.  userdraw_y[p] = (Math.round(prec*userdraw_y[p]))/prec;\
  136. };\
  137. len = userdraw_radius.length;\
  138. if( len > 0 ){\
  139.  for(var p = 0 ; p < len ; p++ ){\
  140.   userdraw_radius[p] = (Math.round(prec*userdraw_radius[p]))/prec;\
  141.  };\
  142. };\
  143. };",reply_precision);
  144.  
  145. switch(type_reply){
  146. /*
  147. answers may have:
  148. x-values,y-values,r-values,input-fields,mathml-inputfields,text-typed answers
  149. */
  150.     case 1:
  151.      fprintf(js_include_file,"\
  152. \n/* function 1 read_canvas%d() */\
  153. read_canvas%d = function(){\
  154. if( userdraw_x.length == 0){return;}\
  155. return userdraw_x+\"\\n\"+userdraw_y;\
  156. };\
  157. /* end function 1 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  158.     break;
  159.     case 2: fprintf(js_include_file,"\
  160. \n/* function 2 read_canvas%d() */\
  161. read_canvas%d = function(){\
  162. if( userdraw_x.length == 0){return;}\
  163. var reply_x = new Array();var reply_y = new Array();\
  164. var prec = %d;\
  165. var len = userdraw_x.length;\
  166. for(var p = 0;p < len ; p++){\
  167.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  168.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  169. };\
  170. return reply_x+\"\\n\"+reply_y;\
  171. };\
  172. /* end function 2 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  173.     break;
  174.     case 3: fprintf(js_include_file,"\
  175. \n/* function 3 read_canvas%d() */\
  176. read_canvas%d = function(){\
  177. if( userdraw_x.length == 0){return;}\
  178. return userdraw_x+\"\\n\"+userdraw_y+\"\\n\"+userdraw_radius;\
  179. };\
  180. /* end function 3 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  181.     break;
  182.     case 4: fprintf(js_include_file,"\
  183. \n/* function 4 read_canvas%d() */\
  184. read_canvas%d = function(){\
  185. var prec = %d;\
  186. var reply_x = new Array();var reply_y = new Array();\
  187. var len = userdraw_x.length;\
  188. for(var p = 0 ; p>len ;p++){\
  189.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  190.  reply_y[p] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  191. };\
  192. return reply_x+\"\\n\"+reply_y+\"\\n\"+userdraw_radius;\
  193. };\
  194. /* end function 4 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  195.     break;
  196.     case 5: fprintf(js_include_file,"\
  197. \n/* function 5 read_canvas%d() */\
  198. read_canvas%d = function(){\
  199. set_reply_precision();\
  200. var p = 0;\
  201. var reply = \"\";\
  202. for(p = 0; p < userdraw_x.length;p++){\
  203.  if(userdraw_x[p] != null ){\
  204.   reply = reply + userdraw_x[p]+\"\\n\"+userdraw_y[p]+\"\\n\";\
  205.  };\
  206. };\
  207. return reply;\
  208. };\
  209. /* end function 5 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  210.     break;
  211.     case 6: fprintf(js_include_file,"\
  212. \n/* function 6 read_canvas%d() */\
  213. read_canvas%d = function(){\
  214. var reply = \"\";\
  215. var tmp_x = new Array();\
  216. var tmp_y = new Array();\
  217. var prec = %d;\
  218. for(var p = 0 ; p < userdraw_x.length; p++){\
  219.  tmp_x = userdraw_x[p];\
  220.  tmp_y = userdraw_y[p];\
  221.  if(tmp_x != null){\
  222.   for(var i = 0 ; i < tmp_x.length ; i++){\
  223.    tmp_x[i] = (Math.round(prec*(px2x(tmp_x[i]))))/prec;\
  224.    tmp_y[i] = (Math.round(prec*(px2y(tmp_y[i]))))/prec;\
  225.   };\
  226.   reply = reply + tmp_x + \"\\n\" + tmp_y +\"\\n\";\
  227.  };\
  228. };\
  229. return reply;\
  230. };\
  231. /* end function 6 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  232.     break;
  233.     case 7: fprintf(js_include_file,"\
  234. \n/* function 7 read_canvas%d() */\
  235. read_canvas%d = function(){\
  236. set_reply_precision();\
  237. var reply = new Array();\
  238. var len = userdraw_x.length;\
  239. for(var p=0; p< len ;p++){\
  240.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p];\
  241. };\
  242. return reply;\
  243. };\
  244. /* end function 7 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  245.     break;
  246.     case 8: fprintf(js_include_file,"\
  247. \n/* function 8 read_canvas%d() */\
  248. read_canvas%d = function(){\
  249. var reply = new Array();\
  250. var prec = %d;\
  251. var len = userdraw_x.length;\
  252. for(var p=0 ; p < len; p++){\
  253.  reply[p] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\":\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  254. };\
  255. return reply;\
  256. };\
  257. /* end function 8 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  258.     break;
  259.     case 9: fprintf(js_include_file,"\
  260. \n/* function 9 read_canvas%d() */\
  261. read_canvas%d = function(){\
  262. set_reply_precision();\
  263. var reply = new Array();\
  264. var len = userdraw_x.length;\
  265. for(var p=0;p<len;p++){\
  266.  reply[p] = userdraw_x[p] +\":\" + userdraw_y[p] + \":\" + userdraw_radius[p];\
  267.  p++;\
  268. };\
  269. return reply;\
  270. };\
  271. /* end function 9 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  272.     break;
  273.     case 10: fprintf(js_include_file,"\
  274. \n/* function 10 read_canvas%d() */\
  275. read_canvas%d = function(){\
  276. var len = userdraw_x.length;\
  277. var prec = %d;\
  278. var reply = \"\";\
  279. for(var p=0; p<len;p++){\
  280.  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\";\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec + \";\" + (Math.round(prec*userdraw_radius[p]))/prec + \"\\n\";\
  281. };\
  282. return reply;\
  283. };\
  284. /* end function 10 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  285.     break;
  286.     case 11: fprintf(js_include_file,"\
  287. \n/* function 11 read_canvas%d() */\
  288. read_canvas%d = function(){\
  289. var reply = \"\";\
  290. var p = 0;\
  291. var prec = %d;\
  292. var len = userdraw_x.length;\
  293. for(var p=0;p<len;p=p+2){\
  294.  reply = reply + (Math.round(prec*(px2x(userdraw_x[p]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p]))))/prec +\",\" + (Math.round(prec*(px2x(userdraw_x[p+1]))))/prec +\",\" + (Math.round(prec*(px2y(userdraw_y[p+1]))))/prec +\"\\n\" ;\
  295. };\
  296. return reply;\
  297. };\
  298. /* end function 11 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  299.     break;
  300.     case 12: fprintf(js_include_file,"\
  301. \n/* function 12 read_canvas%d() */\
  302. read_canvas%d = function(){\
  303. set_reply_precision();\
  304. var reply = \"\";\
  305. var len = userdraw_x.length;\
  306. for(var p=0;p<len;p = p+2){\
  307.  reply = reply + userdraw_x[p] +\",\" + userdraw_y[p] +\",\" + userdraw_x[p+1] +\",\" + userdraw_y[p+1] +\"\\n\" ;\
  308. };\
  309. return reply;\
  310. };\
  311. /* end function 12 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  312.     break;
  313.     case 13: canvas_error("replyformat 13 has been removed...");
  314.     break;
  315.     case 14:
  316.     canvas_error("replyformat 14 has been removed");
  317.     break;
  318. /*
  319. read_canvas%d = function(){\
  320.  set_reply_precision();\
  321.  var reply = new Array();\
  322.  var p = 0;var i = 0;\
  323.  while(userdraw_x[p+1]){\
  324.   reply[i] = userdraw_x[p] +\":\" + userdraw_y[p] +\":\" + userdraw_x[p+1] +\":\" + userdraw_y[p+1];\
  325.   p = p+2;i++;\
  326.  };\
  327.  return reply;\
  328. };\
  329. */
  330.     break;
  331.     case 15: fprintf(js_include_file,"\
  332. \n/* function 15  read_canvas%d() */\
  333. read_canvas%d = function(){\
  334. var input_reply = new Array();\
  335. var p = 0;\
  336. if( document.getElementById(\"canvas_input0\")){\
  337.  var t = 0;\
  338.  while(document.getElementById(\"canvas_input\"+t)){\
  339.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  340.    input_reply[p] = document.getElementById(\"canvas_input\"+t).value;\
  341.    p++;\
  342.   };\
  343.   t++;\
  344.  };\
  345. };\
  346. return input_reply;\
  347. };\
  348. /* end function 15 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  349.     break;
  350.     case 16: fprintf(js_include_file,"\
  351. \n/* function 16 read_mathml() */\
  352. function read_mathml(){\
  353. var reply = new Array();\
  354. var p = 0;\
  355. if( document.getElementById(\"mathml0\")){\
  356.  while(document.getElementById(\"mathml\"+p)){\
  357.   reply[p] = document.getElementById(\"mathml\"+p).value;\
  358.   p++;\
  359.  };\
  360. };\
  361. return reply;\
  362. };\
  363. this.read_mathml = read_mathml;\n\
  364. /* end function 16 read_mathml() */");
  365.     break;
  366.     case 17:  fprintf(js_include_file,"\
  367. \n/* function 17 read_canvas%d() */\
  368. read_canvas%d = function(){\
  369. var len = userdraw_x.length;\
  370. if( len == 0){return;}\
  371. var rep = px2x(userdraw_x[0])+\",\"+px2y(userdraw_y[0])+\",\"+userdraw_text[0];\
  372. for(var p = 1 ; p < len ; p++){\
  373.  rep = rep + \"\\n\" + px2x(userdraw_x[p]) + \",\" + px2y(userdraw_y[p]) + \",\" + userdraw_text[p];\
  374. };\
  375. return rep;\
  376. };\
  377. /* end function 17 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  378.     break;
  379.     case 18: fprintf(js_include_file,"\
  380. \n/* javascript has no real modulo function */\
  381. function mod(n, m){\
  382. var m = parseInt(((n %% m) + m) %% m);\
  383. return m;\
  384. };\
  385. \n/* function 18 read_canvas%d() */\
  386. read_canvas%d = function(){\
  387. var p = 0;\
  388. var reply = new Array();\
  389. var name;\
  390. var t = true;\
  391. var h;var m;var s;\
  392. while(t){\
  393.  try{\
  394.   name = eval('clocks'+p);\
  395.   h = name.H;m = name.M;s = name.S;\
  396.   h = mod((h+m/60+s/3600),12);m = mod((m + s/60),60);s = mod(s,60);\
  397.   reply[p] = h+\":\"+m+\":\"+s;\
  398.   p++;\
  399.  }catch(e){t=false;};\
  400. };\
  401. if( p == 0 ){return;}\
  402. return reply;\
  403. };\
  404. /* end function 18 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  405.     break;
  406.     case 19: fprintf(js_include_file,"\
  407. \n/* function 19 read_canvas%d() */\
  408. read_canvas%d = function(){\
  409. return reply[0];\
  410. };\
  411. /* end function 19 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  412.     break;
  413.     case 20: fprintf(js_include_file,"\
  414. \n/* function 20 read_canvas%d() */\
  415. read_canvas%d = function(){\
  416. var prec = %d;\
  417. var len  = ext_drag_images.length;\
  418. var reply = new Array(len);\
  419. for(var p = 0 ; p < len ; p++){\
  420.  var img = ext_drag_images[p];\
  421.  reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  422. };\
  423. return reply;\
  424. };\
  425. /* end function 20 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  426.     break;
  427.     case 21: fprintf(js_include_file,"\
  428. \n/* function 21 read_canvas%d() */\
  429. read_canvas%d = function(){\
  430. var len = userdraw_x.length;if(len == 0){return;}\
  431. var reply_coord = new Array();var p = 0;\
  432. var prec = %d;\
  433. for(var p = 0; p < len ; p++){\
  434.  reply_coord[p] = \"(\"+(Math.round(prec*(px2x(userdraw_x[p]))))/prec+\":\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\")\";\
  435. };\
  436. return reply_coord;\
  437. };\
  438. /* end function 21 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  439.     break;
  440.     case 22: fprintf(js_include_file,"\
  441. \n/* function 22 read_canvas%d() */\
  442. read_canvas%d = function(){\
  443. var reply = new Array();\
  444. var lu = userdraw_x.length;\
  445. if(lu == 0){return;};\
  446. var idx = 0;\
  447. var prec = %d;\
  448. for(var p = 0 ; p < lu ; p++){\
  449.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;idx++;\
  450.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;idx++;\
  451. };\
  452. return reply;\
  453. };\
  454. /* end function 22 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  455.     break;
  456.     case 23: fprintf(js_include_file,"\
  457. \n/* function 23 read_canvas%d() default 5 px marge */\
  458. read_canvas%d = function(){\
  459. if( userdraw_x.length < 2){return;}\
  460. var lu = userdraw_x.length;\
  461. if( lu != userdraw_y.length ){return;}\
  462. var reply_x = new Array();var reply_y = new Array();\
  463. var marge = 5;var p = 0;\
  464. var prec = %d;\
  465. for(var i = 0; i < lu - 1 ; i++ ){\
  466.  if( Math.abs(userdraw_x[i] - userdraw_x[i+1]) || Math.abs(userdraw_y[i] - userdraw_y[i+1])){\
  467.   reply_x[p] = (Math.round(prec*(px2x(userdraw_x[i]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[i]))))/prec;\
  468.   if( isNaN(reply_x[p]) || isNaN(reply_y[p]) ){return; };\
  469.   p++;\
  470.  };\
  471.  reply_x[p] = (Math.round(prec*(px2x(userdraw_x[lu-1]))))/prec;reply_y[p] = (Math.round(prec*(px2y(userdraw_y[lu-1]))))/prec;\
  472. };\
  473. return reply_x+\"\\n\"+reply_y;\
  474. };\
  475. /* end function 23 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  476.     break;
  477.     case 24: fprintf(js_include_file,"\n\
  478. /* function 24  read_canvas%d() */\
  479. read_canvas%d = function(){\
  480. var input_reply = new Array();\
  481. var p = 0;\
  482. if( document.getElementById(\"canvas_input0\")){\
  483.  while(document.getElementById(\"canvas_input\"+p)){\
  484.    input_reply[p] = document.getElementById(\"canvas_input\"+p).value;\
  485.    p++;\
  486.  };\
  487.  return input_reply;\
  488. };\
  489. };\
  490. /* end function 24 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  491.     break;
  492.     case 25:
  493.     fprintf(js_include_file,"\n/* function 25 read_canvas%d(): angle(s) in degrees */\
  494. read_canvas%d = function(){\
  495. if( userdraw_radius.length < 1){return;}\
  496. var lu = userdraw_radius.length;\
  497. var prec = %d;\
  498. var angle_reply = new Array(lu);\
  499. for(var p = 0 ; p < lu ; p++){\
  500.  angle_reply[p] = (Math.round(prec*180*(userdraw_radius[p])/Math.PI))/prec;\
  501. };\
  502. return angle_reply;\
  503. };\
  504. /* end function 25 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  505.     break;
  506.     case 26:
  507.     fprintf(js_include_file,"\n/* function 26 read_canvas%d(): angle(s) in radians */\
  508. read_canvas%d = function(){\
  509. if( userdraw_radius.length < 1){return;}\
  510. var lu = userdraw_radius.length;\
  511. var prec = %d;\
  512. var angle_reply = new Array(lu);\
  513. for(var p = 0 ; p < lu ; p++){\
  514.  angle_reply[p] = (Math.round(prec*(userdraw_radius[p])))/prec;\
  515. };\
  516. return angle_reply;\
  517. };\
  518. /* end function 26 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  519.     break;
  520.     case 27:
  521.     fprintf(js_include_file,"\n/* function 27 read_canvas%d(): inputfield(s) location and their values: */\
  522. read_canvas%d = function(){\
  523. var lu = userdraw_x.length;\
  524. if( lu < 1){return;};\
  525. set_reply_precision();\
  526. var prec = %d;var rep = \"\";\
  527. for(var p = 0 ; p < lu ; p++){\
  528.   rep = rep + (Math.round(prec*(px2x(userdraw_x[p]))))/prec+\";\"+(Math.round(prec*(px2y(userdraw_y[p]))))/prec+\";\"+ document.getElementById(\"canvas_input\"+p).value + \"\\n\";\
  529. };\
  530. return rep;\
  531. };\
  532. /* end function 27 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  533.     break;
  534.     case 28:
  535.     fprintf(js_include_file,"\n/* function 28 read_canvas%d() */\
  536. read_canvas%d = function(){\
  537. var prec = %d;var reply = new Array();var p = 0;var idx = 0;\
  538. while(userdraw_x[p]){\
  539.  reply[idx] = (Math.round(prec*(px2x(userdraw_x[p]))))/prec;\
  540.  idx++;\
  541.  reply[idx] = (Math.round(prec*(px2y(userdraw_y[p]))))/prec;\
  542.  idx++;\
  543.  reply[idx] = (Math.round(prec*(px2x(userdraw_radius[p]) - px2x(0))))/prec;\
  544.  idx++;\
  545.  p++;\
  546. };\
  547. return reply;\
  548. };\
  549. /* end function 28 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  550.     break;
  551.     case 29:
  552.     fprintf(js_include_file,"\n/* function 29 [multidraw]read_canvas%d() */\
  553. function x_precision(array_x){\
  554. var len = array_x.length;\
  555. var x_array = new Array(len);\
  556. var prec = %d;\
  557. for(var p = 0 ; p < len ; p++ ){\
  558.  x_array[p] = (Math.round(prec*(px2x(array_x[p]))))/prec;\
  559. };\
  560. return x_array;\
  561. };\
  562. function y_precision(array_y){\
  563. var len = array_y.length;\
  564. var y_array = new Array(len);\
  565. var prec = %d;\
  566. for(var p = 0 ; p < len ; p++ ){\
  567.  y_array[p] = (Math.round(prec*(px2y(array_y[p]))))/prec;\
  568. };\
  569. return y_array;\
  570. };\
  571. function radius_to_x(array_r){\
  572. var len = array_r.length;\
  573. var ff = (xmax - xmin)/xsize;\
  574. var r_array = new Array(len);\
  575. var prec = %d;\
  576. for(var p = 0 ; p < len ; p++ ){\
  577.  r_array[p] = (Math.round(prec*(ff*(array_r[p]))))/prec;\
  578. };\
  579. return r_array;\
  580. };\
  581. read_canvas%d = function(){\
  582. function uniq_fast(arr){\
  583.  var seen = {};\
  584.  var out = [];\
  585.  var len = arr.length;\
  586.  var j = 0;\
  587.  for(var i = 0; i < len; i++){\
  588.   var item = arr[i];\
  589.   if(seen[item] !== 1) {\
  590.    seen[item] = 1;out[j++] = item;\
  591.   };\
  592.  };\
  593.  return out;\
  594. };\
  595. function list_unique(arr1,arr2,arr3){\
  596.  if( typeof( allow_duplicate_answers ) === 'number' ){ return [ x_precision(arr1),y_precision(arr2),arr3 ];};\
  597.  var len1 = arr1.length;\
  598.  if(len1 != arr2.length){return;};\
  599.  var sum = [];var R1=[];var R2=[];\
  600.  arr1 = x_precision(arr1);\
  601.  arr2 = y_precision(arr2);\
  602.  if(arr3 == null){\
  603.   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]; };\
  604.   sum = uniq_fast(sum);var len2=sum.length;\
  605.   for(var p=0;p<len2;p++){\
  606.    var tmp = (sum[p]).split('#');\
  607.    R1[p] = tmp[0];\
  608.    R2[p] = tmp[1];\
  609.   };\
  610.   return [R1,R2];\
  611.  }else{\
  612.   var R3 = [];\
  613.   for(var p=0;p<len1;p++){ sum[p] = arr1[p]+'#'+arr2[p]+'#'+arr3[p];};\
  614.   sum = uniq_fast(sum);var len2=sum.length;\
  615.   for(var p=0;p<len2;p++){\
  616.    var tmp = (sum[p]).split('#');\
  617.    R1[p] = tmp[0];\
  618.    R2[p] = tmp[1];\
  619.    R3[p] = tmp[2];\
  620.   };\
  621.   return [R1,R2,R3];\
  622.  };\
  623. };\
  624. var reply=\" \";\
  625. if(  typeof(points_x) === 'object' && points_x.length > 0 ){var xyz = list_unique(points_x,points_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  626. if(  typeof(circles_x) === 'object' && circles_x.length > 0 ){var xyz = list_unique(circles_x,circles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+radius_to_x(multi_radius)+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  627. if(  typeof(segments_x) === 'object' && segments_x.length > 0 ){ var xyz = list_unique(segments_x,segments_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  628. if(  typeof(arrows_x) === 'object' && arrows_x.length > 0 ){var xyz = list_unique(arrows_x,arrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  629. if(  typeof(lines_x) === 'object' && lines_x.length > 0 ){ var xyz = list_unique(lines_x,lines_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  630. if(  typeof(triangles_x) === 'object' && triangles_x.length > 0){var xyz = list_unique(triangles_x,triangles_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  631. if(  typeof(polys_x) === 'object' && polys_x.length > 0){ var xyz = list_unique(polys_x,polys_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  632. if(  typeof(rects_x) === 'object' && rects_x.length > 0 ){var xyz = list_unique(rects_x,rects_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  633. if(  typeof(closedpoly_x) === 'object' && closedpoly_x.length > 0){ closedpoly_x.pop();closedpoly_y.pop();var xyz = list_unique(closedpoly_x,closedpoly_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  634. if(  typeof(parallelogram_x) === 'object' && parallelogram_x.length > 0){var xyz = list_unique(parallelogram_x,parallelogram_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\"; };\
  635. if(  typeof(text_x) === 'object' && text_x.length > 0){var xyz = list_unique(text_x,text_y,text_abc);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  636. if(  typeof(images_x) === 'object' && images_x.length > 0){var xyz = list_unique(images_x,images_y,images_id);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  637. if(  typeof(curvedarrows_x) === 'object' && curvedarrows_x.length > 0){var xyz = list_unique(curvedarrows_x,curvedarrows_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\
  638. if(  typeof(curvedarrows2_x) === 'object' && curvedarrows2_x.length > 0){var xyz = list_unique(curvedarrows2_x,curvedarrows2_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; }else{ reply = reply + \"\\n\";};\
  639. if(  typeof(crosshairs_x) === 'object' && crosshairs_x.length > 0 ){var xyz = list_unique(crosshairs_x,crosshairs_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\";}else{ reply = reply + \"\\n\"; };\
  640. if(  typeof(userdraw_x) === 'object' && userdraw_radius.x> 0){var xyz = list_unique(userdraw_x,userdraw_y,null);reply = reply + xyz[0] +\";\"+xyz[1]+\"\\n\"; return reply;;};\
  641. if(  typeof(userdraw_radius) === 'object' && userdraw_radius.length > 0){var xyz = list_unique(userdraw_x,userdraw_y,userdraw_radius);reply = reply + xyz[0] +\";\"+xyz[1]+\";\"+xyz[2]+\"\\n\"; return reply;;};\
  642. if( document.getElementById(\"canvas_input0\")){var t = 0;\
  643.  while(document.getElementById(\"canvas_input\"+t)){\
  644.   if( ! document.getElementById(\"canvas_input\"+t).getAttribute(\"readonly\")){\
  645.    reply = reply+document.getElementById(\"canvas_input\"+t).value + \";\";\
  646.   };\
  647.   t++;\
  648.  };\
  649. };\
  650. return reply;\
  651. };\
  652. /* end function 29 read_canvas%d() */",canvas_root_id,reply_precision,reply_precision,reply_precision,canvas_root_id,canvas_root_id);
  653.     break;
  654.     case 30:
  655.     fprintf(js_include_file,"\n/* function 30 read_canvas%d() */\
  656. read_canvas%d = function(){\
  657. var reply = new Array(3);\
  658. var prec = %d;\
  659. reply[0] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  660. reply[1] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  661. reply[2] = (Math.round(prec*(protractor_data[2])))/prec;\
  662. return reply;\
  663. };\
  664. /* end function 30 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  665.     break;
  666.     case 31:
  667.     fprintf(js_include_file,"\n/* function 31 read_canvas%d() */\
  668. read_canvas%d = function(){\
  669. var reply = new Array(3);\
  670. var prec = %d;\
  671. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  672. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  673. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  674. return reply;\
  675. };\
  676. /* end function 31 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  677.     break;
  678.     case 32:
  679.     fprintf(js_include_file,"\n/* function 32 read_canvas%d() */\
  680. read_canvas%d = function(){\
  681. var reply = new Array(6);\
  682. var prec = %d;\
  683. reply[0] = (Math.round(prec*(px2x(ruler_data[0]))))/prec;\
  684. reply[1] = (Math.round(prec*(px2y(ruler_data[1]))))/prec;\
  685. reply[2] = (Math.round(prec*(ruler_data[2])))/prec;\
  686. reply[3] = (Math.round(prec*(px2x(protractor_data[0]))))/prec;\
  687. reply[4] = (Math.round(prec*(px2y(protractor_data[1]))))/prec;\
  688. reply[5] = (Math.round(prec*(protractor_data[2])))/prec;\
  689. return reply;\
  690. };\
  691. /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,reply_precision,canvas_root_id);
  692.     break;
  693.     case 33:
  694.     fprintf(js_include_file,"\n/* function 33 read_canvas%d() */\
  695. read_canvas%d = function(){\
  696. var reply = userdraw_x+'\\n'+userdraw_y;\
  697. return reply;\
  698. };\
  699. /* end function 32 read_canvas%d() */",canvas_root_id,canvas_root_id,canvas_root_id);
  700.     break;
  701.     case 34: fprintf(js_include_file,"\
  702. \n/* special OEF function (replyformat 34) read_canvas_images() \\n note: only suitable for reading a single canvas in exercise page */\
  703. var read_canvas_images = function(){\
  704. var prec = %d;\
  705. var len  = ext_drag_images.length;\
  706. var reply = new Array(len);\
  707. for(var p = 0 ; p < len ; p++){\
  708.    var img = ext_drag_images[p];\
  709.    reply[p] = p+\":\"+(Math.round(prec*(px2x(img[6]))))/prec+\":\"+(Math.round(prec*(px2y(img[7]))))/prec;\
  710. };\
  711. return reply;\
  712. };\
  713. /* end function 20 read_canvas_images() */",reply_precision);
  714.     break;
  715.     case 100:break; /* debug js-object format: see dragstuff.c */
  716.     default: canvas_error("hmmm unknown replyformat...");break;
  717. }
  718.  return;
  719. }
  720.