editor.dev.js 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427
  1. "use strict";
  2. /**
  3. * An object that manages the various editors, where users can edit their program. Also manages the
  4. * movement between editors.
  5. * There are currently four editors:
  6. * - Blocks: A Blockly instance
  7. * - Text: A CodeMirror instance
  8. * - Instructor: Features for changing the assignment and environment settings
  9. *
  10. * @constructor
  11. * @this {BlockPyEditor}
  12. * @param {Object} main - The main BlockPy instance
  13. * @param {HTMLElement} tag - The HTML object this is attached to.
  14. */
  15. function BlockPyEditor(main, tag) {
  16. this.main = main;
  17. this.tag = tag; // This tool is what actually converts text to blocks!
  18. this.converter = new PythonToBlocks(); // HTML DOM accessors
  19. this.blockTag = tag.find('.blockpy-blocks');
  20. this.blocklyDiv = this.blockTag.find('.blockly-div');
  21. this.textTag = tag.find('.blockpy-text');
  22. this.instructorTag = tag.find('.blockpy-instructor');
  23. this.textSidebarTag = this.textTag.find(".blockpy-text-sidebar"); // Blockly and CodeMirror instances
  24. this.blockly = null;
  25. this.codeMirror = null; // The updateStack keeps track of whether an update is percolating, to prevent duplicate update events.
  26. this.silenceBlock = false;
  27. this.silenceBlockTimer = null;
  28. this.silenceText = false;
  29. this.silenceModel = 0;
  30. this.blocksFailed = false;
  31. this.blocksFailedTimeout = null; // Hack to prevent chrome errors. Forces audio to load on demand.
  32. // See: https://github.com/google/blockly/issues/299
  33. Blockly.WorkspaceSvg.prototype.preloadAudio_ = function () {}; // Keep track of the toolbox width
  34. this.blocklyToolboxWidth = 0; // Initialize subcomponents
  35. this.initText();
  36. this.initBlockly();
  37. this.initInstructor();
  38. this.triggerOnChange = null;
  39. var editor = this;
  40. var firstEdit = true;
  41. this.main.model.program.subscribe(function () {
  42. editor.updateBlocksFromModel();
  43. editor.updateTextFromModel();
  44. if (editor.main.model.settings.filename() == "__main__" && !firstEdit) {
  45. if (editor.triggerOnChange) {
  46. clearTimeout(editor.triggerOnChange);
  47. }
  48. var engine = editor.main.components.engine;
  49. editor.triggerOnChange = setTimeout(engine.on_change.bind(engine), 1000);
  50. }
  51. firstEdit = false;
  52. }); // Handle mode switching
  53. var settings = this.main.model.settings;
  54. settings.editor.subscribe(function () {
  55. editor.setMode();
  56. });
  57. var updateReadOnly = function updateReadOnly() {
  58. var newValue = !!(settings.read_only() && !settings.instructor()); //editor.codeMirror.setOption('readOnly', newValue);
  59. tag.toggleClass("blockpy-read-only", newValue);
  60. };
  61. settings.read_only.subscribe(updateReadOnly);
  62. settings.instructor.subscribe(updateReadOnly); // Handle filename switching
  63. this.main.model.settings.filename.subscribe(function (name) {
  64. if (name == 'give_feedback') {
  65. editor.setMode('Text');
  66. }
  67. }); // Handle Upload mode turned on
  68. this.main.model.assignment.upload.subscribe(function (uploadsMode) {
  69. if (uploadsMode) {
  70. editor.setMode('Text');
  71. }
  72. }); // Have to force a manual block update
  73. //this.updateText();
  74. this.updateBlocksFromModel();
  75. this.updateTextFromModel();
  76. }
  77. /**
  78. * Initializes the Blockly instance (handles all the blocks). This includes
  79. * attaching a number of ChangeListeners that can keep the internal code
  80. * representation updated and enforce type checking.
  81. */
  82. BlockPyEditor.prototype.initBlockly = function () {
  83. this.blockly = Blockly.inject(this.blocklyDiv[0], {
  84. path: this.main.model.constants.blocklyPath,
  85. scrollbars: this.main.model.constants.blocklyScrollbars,
  86. readOnly: this.main.model.settings.read_only(),
  87. //"nocursor", //
  88. oneBasedIndex: false,
  89. comments: false,
  90. toolbox: this.updateToolbox(false),
  91. collapse: true,
  92. css: true,
  93. disable: true,
  94. grid: false,
  95. maxBlocks: Infinity,
  96. //media: blocklyPath + '/media/',
  97. rtl: false,
  98. sounds: true,
  99. trashcan: true,
  100. zoom: {
  101. controls: true,
  102. wheel: false,
  103. startScale: 1.0,
  104. maxScale: 2,
  105. minScale: 0.2,
  106. scaleSpeed: 1.2
  107. }
  108. }); // Register model changer
  109. var editor = this;
  110. this.blockly.addChangeListener(function (evt) {
  111. //editor.main.components.feedback.clearEditorErrors();
  112. editor.blockly.highlightBlock(null);
  113. editor.updateBlocks();
  114. });
  115. this.main.model.settings.filename.subscribe(function () {
  116. /*if (editor.main.model.settings.editor() == "Blocks") {
  117. editor.updateBlocksFromModel()
  118. }*/
  119. });
  120. this.main.model.assignment.modules.subscribe(function () {
  121. editor.updateToolbox(true);
  122. }); // Force the proper window size
  123. this.blockly.resize(); // Keep the toolbox width set
  124. this.blocklyToolboxWidth = this.getToolbarWidth();
  125. Blockly.captureDialog_ = this.copyImage.bind(this); // Enable static type checking!
  126. /*
  127. this.blockly.addChangeListener(function() {
  128. if (!editor.main.model.settings.disable_variable_types()) {
  129. var variables = editor.main.components.engine.analyzeVariables()
  130. editor.blockly.getAllBlocks().filter(function(r) {return r.type == 'variables_get'}).forEach(function(block) {
  131. var name = block.inputList[0].fieldRow[0].value_;
  132. if (name in variables) {
  133. var type = variables[name];
  134. if (type.type == "Num") {
  135. block.setOutput(true, "Number");
  136. } else if (type.type == "List") {
  137. block.setOutput(true, "Array");
  138. } else if (type.type == "Str") {
  139. block.setOutput(true, "String");
  140. } else {
  141. block.setOutput(true, null);
  142. }
  143. }
  144. })
  145. }
  146. });
  147. */
  148. };
  149. /**
  150. * Retrieves the current width of the Blockly Toolbox, unless
  151. * we're in read-only mode (when there is no toolbox).
  152. * @returns {Number} The current width of the toolbox.
  153. */
  154. BlockPyEditor.prototype.getToolbarWidth = function () {
  155. if (this.main.model.settings.read_only()) {
  156. return 0;
  157. } else if (this.blockly.toolbox_) {
  158. return this.blockly.toolbox_.width;
  159. } else {
  160. return 0;
  161. }
  162. };
  163. /**
  164. * Initializes the CodeMirror instance. This handles text editing (with syntax highlighting)
  165. * and also attaches a listener for change events to update the internal code represntation.
  166. */
  167. BlockPyEditor.prototype.initText = function () {
  168. var codeMirrorDiv = this.textTag.find('.codemirror-div')[0];
  169. this.codeMirror = CodeMirror.fromTextArea(codeMirrorDiv, {
  170. mode: {
  171. name: "python",
  172. version: 3,
  173. singleLineStringErrors: false
  174. },
  175. readOnly: this.main.model.settings.read_only(),
  176. //"nocursor", //
  177. showCursorWhenSelecting: true,
  178. lineNumbers: true,
  179. firstLineNumber: 1,
  180. indentUnit: 4,
  181. tabSize: 4,
  182. indentWithTabs: false,
  183. matchBrackets: true,
  184. extraKeys: {
  185. "Tab": "indentMore",
  186. "Shift-Tab": "indentLess"
  187. }
  188. }); // Register model changer
  189. var editor = this;
  190. this.codeMirror.on("change", function () {
  191. //editor.main.components.feedback.clearEditorErrors();
  192. editor.updateText();
  193. editor.unhighlightLines();
  194. }); // Ensure that it fills the editor area
  195. this.codeMirror.setSize(null, "100%");
  196. };
  197. BlockPyEditor.prototype.reloadIntroduction = function () {
  198. var introductionEditor = this.tag.find('.blockpy-presentation-body-editor');
  199. var model = this.main.model;
  200. introductionEditor.code(model.assignment.introduction());
  201. };
  202. /**
  203. * Initializes the Instructor tab, which has a number of buttons and menus for
  204. * manipulating assignments and the environment. One important job is to register the
  205. * SummerNote instance used for editing the Introduction of the assignment.
  206. */
  207. BlockPyEditor.prototype.initInstructor = function () {
  208. var introductionEditor = this.tag.find('.blockpy-presentation-body-editor');
  209. var model = this.main.model;
  210. introductionEditor.summernote({
  211. codemirror: {
  212. // codemirror options
  213. theme: 'monokai'
  214. },
  215. onChange: model.assignment.introduction,
  216. toolbar: [['style', ['bold', 'italic', 'underline', 'clear']], ['font', ['fontname', 'fontsize']], ['insert', ['link', 'table', 'ul', 'ol', 'image']], ['misc', ['codeview', 'help']]]
  217. });
  218. this.reloadIntroduction();
  219. this.availableModules = this.tag.find('.blockpy-available-modules');
  220. this.availableModules.multiSelect({
  221. selectableOptgroup: true
  222. });
  223. };
  224. /**
  225. * Makes the module available in the availableModules multi-select menu by adding
  226. * it to the list.
  227. *
  228. * @param {String} name - The name of the module (human-friendly version, as opposed to the slug) to be added.
  229. */
  230. BlockPyEditor.prototype.addAvailableModule = function (name) {
  231. this.availableModules.multiSelect('addOption', {
  232. 'value': name,
  233. 'text': name
  234. });
  235. this.availableModules.multiSelect('select', name);
  236. };
  237. /**
  238. * Hides the Text tab, which involves shrinking it and hiding its CodeMirror too.
  239. */
  240. BlockPyEditor.prototype.hideSplitMenu = function () {
  241. this.hideTextMenu();
  242. this.hideBlockMenu();
  243. };
  244. /**
  245. * Shows the Text tab, which requires restoring its height, showing AND refreshing
  246. * the CodeMirror instance.
  247. */
  248. BlockPyEditor.prototype.showSplitMenu = function () {
  249. this.showBlockMenu();
  250. this.showTextMenu();
  251. this.textTag.css('width', '100%');
  252. this.blockTag.css('width', '100%');
  253. this.textSidebarTag.css('width', '0px'); // this.textTag.addClass('col-md-12');
  254. // this.blockTag.addClass('col-md-12');
  255. Blockly.svgResize(this.blockly);
  256. };
  257. /**
  258. * Hides the Text tab, which involves shrinking it and hiding its CodeMirror too.
  259. */
  260. BlockPyEditor.prototype.hideTextMenu = function () {
  261. this.textTag.css('height', '0%');
  262. $(this.codeMirror.getWrapperElement()).hide();
  263. this.textSidebarTag.hide();
  264. this.textTag.hide();
  265. };
  266. /**
  267. * Shows the Text tab, which requires restoring its height, showing AND refreshing
  268. * the CodeMirror instance.
  269. */
  270. BlockPyEditor.prototype.showTextMenu = function () {
  271. this.textTag.show(); // Adjust height
  272. this.textTag.css('height', '100%');
  273. this.textTag.css('width', '100%'); // Show CodeMirror
  274. $(this.codeMirror.getWrapperElement()).show(); // CodeMirror doesn't know its changed size
  275. this.codeMirror.refresh(); // Resize sidebar
  276. var codemirrorGutterWidth = $('.CodeMirror-gutters').width();
  277. var sideBarWidth = this.blocklyToolboxWidth - codemirrorGutterWidth - 2;
  278. this.textSidebarTag.css('width', sideBarWidth + 'px');
  279. this.textSidebarTag.show(); // this.textTag.removeClass('col-md-6');
  280. };
  281. /**
  282. * Hides the Block tab, which involves shrinking it and hiding the Blockly instance.
  283. */
  284. BlockPyEditor.prototype.hideBlockMenu = function () {
  285. this.blocklyToolboxWidth = this.getToolbarWidth();
  286. this.blockTag.css('height', '0%');
  287. this.blocklyDiv.css("width", "0");
  288. this.blockly.setVisible(false);
  289. };
  290. /**
  291. * Shows the Block tab, which involves restoring its height and showing the Blockly instance.
  292. */
  293. BlockPyEditor.prototype.showBlockMenu = function () {
  294. this.blockTag.css('height', '100%');
  295. this.blockTag.css('width', '100%');
  296. this.blocklyDiv.css("width", "100%");
  297. this.blockly.resize();
  298. this.blockly.setVisible(true);
  299. this.blockTag.removeClass('col-md-6');
  300. Blockly.svgResize(this.blockly);
  301. };
  302. /**
  303. * Hides the Instructor tab, which shrinking it.
  304. */
  305. BlockPyEditor.prototype.hideInstructorMenu = function () {
  306. this.instructorTag.hide();
  307. this.instructorTag.css('height', '0%');
  308. };
  309. /**
  310. * Shows the Instructor tab, which involves restoring its height.
  311. */
  312. BlockPyEditor.prototype.showInstructorMenu = function () {
  313. this.instructorTag.css('height', '100%');
  314. this.instructorTag.show();
  315. };
  316. /**
  317. * Sets the current editor mode to Text, hiding the other menus.
  318. * Also forces the text side to update.
  319. */
  320. BlockPyEditor.prototype.setModeToText = function () {
  321. this.hideBlockMenu();
  322. this.hideInstructorMenu();
  323. this.showTextMenu(); // Update the text model from the blocks
  324. };
  325. /**
  326. * Sets the current editor mode to Blocks, hiding the other menus.
  327. * Also forces the block side to update.
  328. * There is a chance this could fail, if the text side is irredeemably
  329. * awful. So then the editor bounces back to the text side.
  330. */
  331. BlockPyEditor.prototype.setModeToBlocks = function () {
  332. this.hideTextMenu();
  333. this.hideInstructorMenu();
  334. this.showBlockMenu();
  335. if (this.blocksFailed !== false) {
  336. this.showConversionError();
  337. var main = this.main;
  338. main.model.settings.editor("Text");
  339. setTimeout(function () {
  340. main.components.toolbar.tags.mode_set_text.click();
  341. }, 0);
  342. } // Update the blocks model from the text
  343. /*
  344. success = this.updateBlocksFromModel();
  345. if (!success) {
  346. var main = this.main;
  347. main.components.editor.updateTextFromModel();
  348. main.model.settings.editor("Text");
  349. setTimeout(function() {
  350. main.components.toolbar.tags.mode_set_text.click();
  351. }, 0);
  352. }*/
  353. };
  354. /**
  355. * Sets the current editor mode to Split mode, hiding the other menus.
  356. */
  357. BlockPyEditor.prototype.setModeToSplit = function () {
  358. this.hideTextMenu();
  359. this.hideInstructorMenu();
  360. this.hideBlockMenu();
  361. this.showSplitMenu();
  362. if (this.blocksFailed !== false) {
  363. this.showConversionError();
  364. }
  365. };
  366. /**
  367. * Sets the current editor mode to the Instructor mode, hiding the other menus.
  368. */
  369. BlockPyEditor.prototype.setModeToInstructor = function () {
  370. this.hideTextMenu();
  371. this.hideBlockMenu();
  372. this.showInstructorMenu(); //TODO: finish upload mode
  373. //this.main.reportError("editor", "Instructor mode has not been implemented");
  374. };
  375. BlockPyEditor.prototype.changeMode = function () {
  376. if (main.model.settings.editor() == "Blocks") {
  377. main.model.settings.editor("Text");
  378. } else {
  379. main.model.settings.editor("Blocks");
  380. }
  381. };
  382. /**
  383. * Dispatch method to set the mode to the given argument.
  384. * If the mode is invalid, an editor error is reported. If the
  385. *
  386. * @param {String} mode - The new mode to set to ("Blocks", "Text", or "Instructor")
  387. */
  388. BlockPyEditor.prototype.setMode = function (mode) {
  389. // Either update the model, or go with the model's
  390. if (mode === undefined) {
  391. mode = this.main.model.settings.editor();
  392. } else {
  393. this.main.model.settings.editor(mode);
  394. } // Dispatch according to new mode
  395. if (mode == 'Blocks') {
  396. this.setModeToBlocks();
  397. } else if (mode == 'Text') {
  398. this.setModeToText();
  399. } else if (mode == 'Split') {
  400. this.setModeToSplit();
  401. } else if (mode == 'Instructor') {
  402. this.setModeToInstructor();
  403. } else if (mode == 'Upload') {
  404. this.setModeToText();
  405. } else {
  406. this.main.components.feedback.internalError("" + mode, "Invalid Mode", "The editor attempted to change to an invalid mode.");
  407. }
  408. };
  409. /**
  410. * Actually changes the value of the CodeMirror instance
  411. *
  412. * @param {String} code - The new code for the CodeMirror
  413. */
  414. BlockPyEditor.prototype.setText = function (code) {
  415. if (code == undefined || code.trim() == "") {
  416. this.codeMirror.setValue("\n");
  417. } else {
  418. this.codeMirror.setValue(code);
  419. } // Ensure that we maintain proper highlighting
  420. this.refreshHighlight();
  421. };
  422. BlockPyEditor.prototype.showConversionError = function () {
  423. var error = this.blocksFailed;
  424. this.main.components.feedback.convertSkulptSyntax(error);
  425. };
  426. BlockPyEditor.prototype.setBlocks = function (python_code) {
  427. if (!(!this.main.model.assignment.upload() && (this.main.model.settings.filename() == "__main__" || this.main.model.settings.filename() == "starting_code"))) {
  428. return false;
  429. }
  430. var xml_code = "";
  431. if (python_code !== '' && python_code !== undefined && python_code.trim().charAt(0) !== '<') {
  432. var result = this.converter.convertSource(python_code);
  433. xml_code = result.xml;
  434. window.clearTimeout(this.blocksFailedTimeout);
  435. if (result.error !== null) {
  436. this.blocksFailed = result.error;
  437. var editor = this;
  438. this.blocksFailedTimeout = window.setTimeout(function () {
  439. if (editor.main.model.settings.editor() != 'Text') {
  440. editor.showConversionError();
  441. }
  442. }, 500);
  443. } else {
  444. this.blocksFailed = false;
  445. this.main.components.feedback.clearEditorErrors();
  446. }
  447. }
  448. var error_code = this.converter.convertSourceToCodeBlock(python_code);
  449. var errorXml = Blockly.Xml.textToDom(error_code);
  450. if (python_code == '' || python_code == undefined || python_code.trim() == '') {
  451. this.blockly.clear();
  452. } else if (xml_code !== '' && xml_code !== undefined) {
  453. var blocklyXml = Blockly.Xml.textToDom(xml_code);
  454. try {
  455. this.setBlocksFromXml(blocklyXml);
  456. pythonnewcode = python_code;
  457. } catch (e) {
  458. console.error(e);
  459. this.setBlocksFromXml(errorXml);
  460. }
  461. } else {
  462. this.setBlocksFromXml(errorXml);
  463. }
  464. Blockly.Events.disable();
  465. /*
  466. // Parsons shuffling
  467. if (this.main.model.assignment.parsons()) {
  468. this.blockly.shuffle();
  469. } else {
  470. this.blockly.align();
  471. }
  472. */
  473. Blockly.Events.enable();
  474. if (this.previousLine !== null) {
  475. this.refreshBlockHighlight(this.previousLine);
  476. }
  477. };
  478. BlockPyEditor.prototype.clearDeadBlocks = function () {
  479. var all_blocks = this.blockly.getAllBlocks();
  480. all_blocks.forEach(function (elem) {
  481. if (!Blockly.Python[elem.type]) {
  482. elem.dispose(true);
  483. }
  484. });
  485. };
  486. /**
  487. * Attempts to update the model for the current code file from the
  488. * block workspace. Might be prevented if an update event was already
  489. * percolating.
  490. */
  491. BlockPyEditor.prototype.updateBlocks = function () {
  492. if (!this.silenceBlock) {
  493. try {
  494. var newCode = Blockly.Python.workspaceToCode(this.blockly);
  495. pythonnewcode = newCode;
  496. } catch (e) {
  497. this.clearDeadBlocks();
  498. this.main.components.feedback.editorError("Unknown Block", "It looks like you attempted to paste or load some blocks that were not known. Typically, this is because you failed to load in the dataset before trying to paste in a data block. If there are any black blocks on the canvas, delete them before continuing.", "Unknown Block");
  499. } // Update Model
  500. this.silenceModel = 2;
  501. var changed = this.main.setCode(newCode);
  502. if (!changed) {
  503. this.silenceModel = 0;
  504. } else {
  505. // Update Text
  506. this.silenceText = true;
  507. this.setText(newCode);
  508. }
  509. }
  510. };
  511. /**
  512. * Attempts to update the model for the current code file from the
  513. * text editor. Might be prevented if an update event was already
  514. * percolating. Also unhighlights any lines.
  515. */
  516. var timerGuard = null;
  517. BlockPyEditor.prototype.updateText = function (code) {
  518. if (!this.silenceText) {
  519. var newCode = code || this.codeMirror.getValue(); // Update Model
  520. this.silenceModel = 2;
  521. this.main.setCode(newCode); // Update Blocks
  522. this.silenceBlock = true;
  523. this.setBlocks(newCode);
  524. this.unhighlightLines();
  525. this.resetBlockSilence();
  526. }
  527. this.silenceText = false;
  528. };
  529. /**
  530. * Resets the silenceBlock after a short delay
  531. */
  532. BlockPyEditor.prototype.resetBlockSilence = function () {
  533. var editor = this;
  534. if (editor.silenceBlockTimer != null) {
  535. clearTimeout(editor.silenceBlockTimer);
  536. }
  537. this.silenceBlockTimer = window.setTimeout(function () {
  538. editor.silenceBlock = false;
  539. editor.silenceBlockTimer = null;
  540. }, 40);
  541. };
  542. /**
  543. * Updates the text editor from the current code file in the
  544. * model. Might be prevented if an update event was already
  545. * percolating.
  546. */
  547. BlockPyEditor.prototype.updateTextFromModel = function () {
  548. if (this.silenceModel == 0) {
  549. var code = this.main.model.program();
  550. this.silenceText = true;
  551. this.setText(code);
  552. } else {
  553. this.silenceModel -= 1;
  554. }
  555. };
  556. /**
  557. * Updates the block editor from the current code file in the
  558. * model. Might be prevented if an update event was already
  559. * percolating. This can also report an error if one occurs.
  560. *
  561. * @returns {Boolean} Returns true upon success.
  562. */
  563. BlockPyEditor.prototype.updateBlocksFromModel = function () {
  564. if (this.silenceModel == 0) {
  565. var code = this.main.model.program().trim();
  566. this.silenceBlock = true;
  567. this.setBlocks(code);
  568. this.resetBlockSilence();
  569. } else {
  570. this.silenceModel -= 1;
  571. }
  572. };
  573. /**
  574. * Helper function for retrieving the current Blockly workspace as
  575. * an XML DOM object.
  576. *
  577. * @returns {XMLDom} The blocks in the current workspace.
  578. */
  579. BlockPyEditor.prototype.getBlocksFromXml = function () {
  580. return Blockly.Xml.workspaceToDom(this.blockly);
  581. };
  582. /**
  583. * Helper function for setting the current Blockly workspace to
  584. * whatever XML DOM is given. This clears out any existing blocks.
  585. */
  586. BlockPyEditor.prototype.setBlocksFromXml = function (xml) {
  587. //this.blockly.clear();
  588. Blockly.Xml.domToWorkspaceDestructive(xml, this.blockly); //console.log(this.blockly.getAllBlocks());
  589. };
  590. BlockPyEditor.prototype.clearBlocksFromXml = function () {
  591. this.blockly.clear();
  592. };
  593. /**
  594. * @property {Number} previousLine - Keeps track of the previously highlighted line.
  595. */
  596. BlockPyEditor.prototype.previousLine = null;
  597. /**
  598. * Assuming that a line has been highlighted previously, this will set the
  599. * line to be highlighted again. Used when we need to restore a highlight.
  600. */
  601. BlockPyEditor.prototype.refreshHighlight = function () {
  602. if (this.previousLine !== null) {
  603. if (this.previousLine < this.codeMirror.lineCount()) {
  604. this.codeMirror.addLineClass(this.previousLine, 'text', 'editor-error-line');
  605. }
  606. } // TODO: Shouldn't this refresh the highlight in the block side too?
  607. };
  608. /**
  609. * Highlights a line of code in the CodeMirror instance. This applies the "active" style
  610. * which is meant to bring attention to a line, but not suggest it is wrong.
  611. *
  612. * @param {Number} line - The line of code to highlight. I think this is zero indexed?
  613. */
  614. BlockPyEditor.prototype.highlightLine = function (line) {
  615. if (this.previousLine !== null) {
  616. if (this.previousLine < this.codeMirror.lineCount()) {
  617. this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-active-line');
  618. this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-error-line');
  619. }
  620. }
  621. if (line < this.codeMirror.lineCount()) {
  622. this.codeMirror.addLineClass(line, 'text', 'editor-active-line');
  623. }
  624. this.previousLine = line;
  625. };
  626. /**
  627. * Highlights a line of code in the CodeMirror instance. This applies the "error" style
  628. * which is meant to suggest that a line is wrong.
  629. *
  630. * @param {Number} line - The line of code to highlight. I think this is zero indexed?
  631. */
  632. BlockPyEditor.prototype.highlightError = function (line) {
  633. if (this.previousLine !== null) {
  634. if (this.previousLine < this.codeMirror.lineCount()) {
  635. this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-active-line');
  636. this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-error-line');
  637. }
  638. }
  639. if (line < this.codeMirror.lineCount()) {
  640. this.codeMirror.addLineClass(line, 'text', 'editor-error-line');
  641. }
  642. this.refreshBlockHighlight(line);
  643. this.previousLine = line;
  644. };
  645. /**
  646. * Highlights a block in Blockly. Unfortunately, this is the same as selecting it.
  647. *
  648. * @param {Number} block - The ID of the block object to highlight.
  649. */
  650. BlockPyEditor.prototype.highlightBlock = function (block) {} //this.blockly.highlightBlock(block);
  651. /**
  652. * Used to restore a block's highlight when travelling from the code tab. This
  653. * uses a mapping between the blocks and text that is generated from the parser.
  654. * The parser has stored the relevant line numbers for each block in the XML of the
  655. * block. Very sophisticated, and sadly fairly fragile.
  656. * TODO: I believe there's some kind of off-by-one error here...
  657. *
  658. * @param {Number} line - The line of code to highlight. I think this is zero indexed?
  659. */
  660. ;
  661. BlockPyEditor.prototype.refreshBlockHighlight = function (line) {
  662. if (this.blocksFailed) {
  663. this.blocksFailed = false;
  664. return;
  665. }
  666. if (this.main.model.settings.editor() != "Blocks" && this.main.model.settings.editor() != "Split") {
  667. return;
  668. }
  669. var all_blocks = this.blockly.getAllBlocks(); //console.log(all_blocks.map(function(e) { return e.lineNumber }));
  670. var blockMap = {};
  671. all_blocks.forEach(function (elem) {
  672. var lineNumber = parseInt(elem.lineNumber, 10);
  673. if (lineNumber in blockMap) {
  674. blockMap[lineNumber].push(elem);
  675. } else {
  676. blockMap[lineNumber] = [elem];
  677. }
  678. });
  679. if (1 + line in blockMap) {
  680. var hblocks = blockMap[1 + line];
  681. var blockly = this.blockly;
  682. hblocks.forEach(function (elem) {
  683. //elem.addSelect();
  684. blockly.highlightBlock(elem.id, true);
  685. });
  686. /*if (hblocks.length > 0) {
  687. this.blockly.highlightBlock(hblocks[0].id, true);
  688. }*/
  689. }
  690. };
  691. /**
  692. * Removes the outline around a block. Currently unused.
  693. */
  694. BlockPyEditor.prototype.unhighlightBlock = function () {} // TODO:
  695. /**
  696. * Removes any highlight in the text code editor.
  697. *
  698. */
  699. ;
  700. BlockPyEditor.prototype.unhighlightLines = function () {
  701. if (this.previousLine !== null) {
  702. if (this.previousLine < this.codeMirror.lineCount()) {
  703. this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-active-line');
  704. this.codeMirror.removeLineClass(this.previousLine, 'text', 'editor-error-line');
  705. }
  706. }
  707. this.previousLine = null;
  708. };
  709. /**
  710. * Removes any highlight in the text code editor.
  711. *
  712. */
  713. BlockPyEditor.prototype.unhighlightAllLines = function () {
  714. var editor = this.codeMirror;
  715. var count = editor.lineCount(),
  716. i;
  717. for (i = 0; i < count; i++) {
  718. editor.removeLineClass(i, 'text', 'editor-error-line');
  719. }
  720. };
  721. /**
  722. * DEPRECATED, thankfully
  723. * Builds up an array indicating the relevant block ID for a given step.
  724. * Operates on the current this.blockly instance
  725. * It works by injecting __HIGHLIGHT__(id); at the start of every line of code
  726. * and then extracting that with regular expressions. This makes it vulnerable
  727. * if someone decides to use __HIGHLIGHT__ in their code. I'm betting on that
  728. * never being a problem, though. Still, this was a miserable way of accomplishing
  729. * the desired behavior.
  730. */
  731. BlockPyEditor.prototype.getHighlightMap = function () {
  732. // Protect the current STATEMENT_PREFIX
  733. var backup = Blockly.Python.STATEMENT_PREFIX;
  734. Blockly.Python.STATEMENT_PREFIX = '__HIGHLIGHT__(%1);';
  735. Blockly.Python.addReservedWords('__HIGHLIGHT__'); // Get the source code, injected with __HIGHLIGHT__(id)
  736. var highlightedCode = Blockly.Python.workspaceToCode(this.blockly);
  737. Blockly.Python.STATEMENT_PREFIX = backup; // Build up the array by processing the highlighted code line-by-line
  738. var highlightMap = [];
  739. var lines = highlightedCode.split("\n");
  740. for (var i = 0; i < lines.length; i++) {
  741. // Get the block ID from the line
  742. var id = lines[i].match(/\W*__HIGHLIGHT__\(\'(.+?)\'\)/);
  743. if (id !== null) {
  744. // Convert it into a base-10 number, because JavaScript.
  745. highlightMap[i] = parseInt(id[1], 10);
  746. }
  747. }
  748. return highlightMap;
  749. };
  750. /**
  751. * Updates the current file being edited in the editors.
  752. * This appears to be deprecated.
  753. *
  754. * @param {String} name - The name of the file being edited (e.g, "__main__", "starting_code")
  755. */
  756. /*
  757. BlockPyEditor.prototype.changeProgram = function(name) {
  758. console.log("TEST")
  759. this.silentChange_ = true;
  760. if (name == 'give_feedback') {
  761. this.setMode('Text');
  762. }
  763. this.model.settings.filename = name;
  764. this.editor.setPython(this.model.programs[name]);
  765. this.toolbar.elements.programs.find("[data-name="+name+"]").click();
  766. }*/
  767. /**
  768. * Eventually will be used to update "levels" of sophistication of the code interface.
  769. * Currently unimplemented and unused.
  770. */
  771. BlockPyEditor.prototype.setLevel = function () {
  772. var level = this.main.model.settings.level();
  773. };
  774. /**
  775. * Maps short category names in the toolbox to the full XML used to
  776. * represent that category as usual. This is kind of a clunky mechanism
  777. * for managing the different categories, and doesn't allow us to specify
  778. * individual blocks.
  779. */
  780. BlockPyEditor.CATEGORY_MAP = {
  781. 'Decisions': '<category id="catLogic" name="Logic" colour="#4c97ff">' + '<block type="controls_if"></block>' + // '<block type="controls_if"><mutation else="1"></mutation></block>' +
  782. '<block type="logic_compare">' + //'<value name="B"><block type="math_number"><field name="NUM">0</field></block></value>' +
  783. '</block>' + '<block type="logic_operation"></block>' + '<block type="logic_negate"></block>' + '<block type="logic_boolean"></block>' + '<block type="logic_null"></block>' + '<block type="logic_ternary"></block>' + '<block type="CocoRobo_return"></block>' + '<block type="CocoRobo_try_except"></block>' + '<block type="CocoRobo_try_except_finally"></block>' + '<block type="CocoRobo_type"></block>' + '<block type="CocoRobo_type_is"></block>' + '<block type="CocoRobo_eval"></block>' + '</category>',
  784. 'Iteration': '<category id="catLoops" name="Loops" colour="#9d64fd">' + // ' <block type="controls_repeatFovrerDo"></block>' +
  785. // ' <block type="controls_repeat_ext">' +
  786. // ' <value name="TIMES">' +
  787. // ' <block type="math_number">' +
  788. // ' <field name="NUM">10</field>' +
  789. // ' </block>' +
  790. // ' </value>' +
  791. // ' </block>' +
  792. // ' <block type="controls_whileUntil"></block>' +
  793. // ' <block type="controls_for">' +
  794. // ' <value name="FROM">' +
  795. // ' <block type="math_number">' +
  796. // ' <field name="NUM">1</field>' +
  797. // ' </block>' +
  798. // ' </value>' +
  799. // ' <value name="TO">' +
  800. // ' <block type="math_number">' +
  801. // ' <field name="NUM">10</field>' +
  802. // ' </block>' +
  803. // ' </value>' +
  804. // ' <value name="BY">' +
  805. // ' <block type="math_number">' +
  806. // ' <field name="NUM">1</field>' +
  807. // ' </block>' +
  808. // ' </value>' +
  809. // ' </block>' +
  810. // ' <block type="controls_forEach"></block>' +
  811. // ' <block type="controls_flow_statements"></block>' +
  812. '<block type="controls_repeat_forever"></block>' + '<block type="controls_repeat_ext">' + '<value name="TIMES">' + '<shadow type="math_number">' + ' <field name="NUM">10</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="controls_whileUntil"></block>' + '<block type="controls_for">' + '<value name="FROM">' + '<shadow type="math_number">' + '<field name="NUM">1</field>' + '</shadow>' + '</value>' + '<value name="TO">' + '<shadow type="math_number">' + '<field name="NUM">10</field>' + '</shadow>' + '</value>' + '<value name="BY">' + '<shadow type="math_number">' + '<field name="NUM">1</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="controls_forEach"></block>' + '<block type="controls_flow_statements"></block>' + '</category>',
  813. 'Calculation': '<category id="catMath" name="Math" colour="#5472ea">' + // '<block type="math_number"></block>' +
  814. // //'<block type="raw_table"></block>'+
  815. // '<block type="math_arithmetic"></block>' +
  816. // // '<block type="type_check"></block>'+
  817. // //'<block type="raw_empty"></block>'+
  818. // '<block type="math_single"></block>' +
  819. // '<block type="math_trigonometricFunction"></block>' +
  820. // '<block type="math_specialNumber"></block>' +
  821. // '<block type="math_number_property"></block>' +
  822. // '<block type="math_round"></block>' +
  823. // '<block type="math_rounds"></block>' +
  824. // '<block type="math_sum_list"></block>' +
  825. // '<block type="math_remainder"></block>' +
  826. // '<block type="math_integer"></block>' +
  827. // '<block type="math_constrain"></block>' +
  828. // '<block type="math_map"></block>' +
  829. // '<block type="math_random"></block>' +
  830. // '<block type="math_randoms"></block>' +
  831. // '<block type="math_numberType"></block>' +
  832. // '<block type="math_numberBoolean"></block>' +
  833. // '<block type="math_invert"></block>' +
  834. // '<block type="math_decimal"></block>' +
  835. // '<block type="math_stringconverted"></block>' +
  836. // '<block type="math_decimalBytes"></block>' +
  837. // '<block type="math_shaping"></block>' +
  838. // '<block type="math_character"></block>' +
  839. // '<block type="math_stringBytes"></block>' +
  840. // '<block type="math_hex"></block>' +
  841. // '<block type="math_encoding"></block>' +
  842. // '<block type="math_deconding"></block>' +
  843. // // '<block type="math_sum_values"></block>' +
  844. // // '<block type="math_sum_common"></block>' +
  845. '<block type="math_number" gap="32"></block>' + '<block type="math_arithmetic">' + ' <value name="A">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '<value name="B">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_degrad"></block>' + '<block type="math_single">' + '<value name="NUM">' + '<shadow type="math_number">' + ' <field name="NUM">9</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_trig">' + '<value name="NUM">' + '<shadow type="math_angle">' + ' <field name="angle">45</field>' + '</shadow>' + '</value>' + '</block>' + '<!--block type="math_trig">' + ' <value name="NUM">' + '<shadow type="math_number">' + ' <field name="NUM">45</field>' + '</shadow>' + '</value>' + '</block-->' + '<block type="math_constant"></block>' + '<block type="math_number_property">' + '<value name="NUMBER_TO_CHECK">' + '<shadow type="math_number">' + ' <field name="NUM">0</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_round">' + '<value name="NUM">' + ' <shadow type="math_number">' + ' <field name="NUM">3.1</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_keep_decimal">' + '<value name="NUM">' + ' <shadow type="math_number">' + ' <field name="NUM">3.1415926</field>' + '</shadow>' + '</value>' + '<value name="PLACE">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_on_list"></block>' + '<block type="math_modulo">' + '<value name="DIVIDEND">' + '<shadow type="math_number">' + ' <field name="NUM">64</field>' + '</shadow>' + '</value>' + ' <value name="DIVISOR">' + '<shadow type="math_number">' + ' <field name="NUM">10</field>' + '</shadow>' + '</value>' + ' </block>' + '<block type="math_division_consult">' + ' <value name="DIVIDEND">' + '<shadow type="math_number">' + ' <field name="NUM">64</field>' + '</shadow>' + '</value>' + '<value name="DIVISOR">' + '<shadow type="math_number">' + ' <field name="NUM">10</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_constrain">' + ' <value name="VALUE">' + '<shadow type="math_number">' + ' <field name="NUM">50</field>' + '</shadow>' + '</value>' + '<value name="LOW">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + ' <value name="HIGH">' + '<shadow type="math_number">' + ' <field name="NUM">100</field>' + '</shadow>' + ' </value>' + '</block>' + ' <block type="labplus_mapping">' + '<value name="inputNum"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' + '<value name="bMin"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + '<value name="bMax"><shadow type="math_number"><field name="NUM">100</field></shadow></value>' + '<value name="cMin"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + '<value name="cMax"><shadow type="math_number"><field name="NUM">200</field></shadow></value>' + '</block>' + '<block type="math_random_int">' + '<value name="FROM">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '<value name="TO">' + '<shadow type="math_number">' + ' <field name="NUM">100</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="math_random_randrange">' + '<value name="start"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' <value name="stop"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' + '<value name="step"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' + '</block>' + '<block type="math_random_float"></block>' + '<block type="math_convert"></block>' + '<block type="math_number_bits_ops">' + '<value name="A">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '<value name="B">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="bit_inversion">' + '<value name="data"><shadow type="math_number"><field name="NUM">60</field></shadow></value>' + '</block>' + '<block type="CocoRobo_ten_convert_to">' + ' <value name="int_num"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' + '</block>' + '<block type="CocoRobo_convert_to_ten">' + ' <value name="convert_str"><shadow type="text"><field name="TEXT">11</field></shadow></value>' + '</block>' + '<block type="CocoRobo_ten_converted_to_bytes">' + ' <value name="convert_num"><shadow type="math_number"><field name="NUM">11</field></shadow></value>' + '</block>' + '<block type="CocoRobo_int_to_chr">' + ' <value name="convert_num"><shadow type="math_number"><field name="NUM">97</field></shadow></value>' + '</block>' + '<block type="CocoRobo_chr_to_int">' + ' <value name="convert_chr"><shadow type="text"><field name="TEXT">a</field></shadow></value>' + ' </block>' + ' <block type="CocoRobo_str_to_hex">' + '<value name="convert_chr"><shadow type="text"><field name="TEXT">abcdfg</field></shadow></value>' + '</block>' + '<block type="CocoRobo_hex_to_bin_str">' + '<value name="convert_chr"><shadow type="text"><field name="TEXT">313233</field></shadow></value>' + ' </block>' + '<block type="CocoRobo_data_to_base64">' + ' <value name="data"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' + '</block>' + '<block type="CocoRobo_base64_to_data">' + ' <value name="data"><shadow type="text"><field name="TEXT">bXB5dGhvbg==</field></shadow></value>' + '</block>' + '</category>',
  846. 'Variables': '<category id="catVariables" name="Variables" custom="VARIABLE" colour="#ffab2f">' + '</category>',
  847. 'Lists': '<category id="catLists" name="Lists" colour="#40bfe4">' + // '<block type="list_creatEmptyList"></block>' +
  848. // '<block type="list_creatEmptyWith"></block>' +
  849. // '<block type="list_creatList"></block>' +
  850. // '<block type="list_define"></block>' +
  851. // '<block type="list_listItem"></block>' +
  852. // '<block type="list_addItem"></block>' +
  853. // '<block type="list_listInclude"></block>' +
  854. // '<block type="list_listAppend"></block>' +
  855. // '<block type="list_clearList"></block>' +
  856. // '<block type="list_creatListTimes"></block>' +
  857. // '<block type="list_lengthOf"></block>' +
  858. // '<block type="list_empty"></block>' +
  859. // '<block type="list_location"></block>' +
  860. // '<block type="list_setList"></block>' +
  861. // '<block type="list_insertList"></block>' +
  862. // '<block type="list_returnList"></block>' +
  863. // '<block type="list_inList"></block>' +
  864. // '<block type="list_inLists"></block>' +
  865. // '<block type="list_make"></block>' +
  866. // '<block type="list_sort"></block>' +
  867. '<block type="lists_create_with"><mutation items="0"></mutation></block>' + '<block type="lists_create_with"></block>' + ' <block type="text_list"><field name="TEXT">0, 0, 0</field></block>' + ' <!--block type="file_to_list">' + ' <value name="file_path"><shadow type="text"><field name="TEXT">1.txt</field></shadow></value>' + ' </block-->' + ' <block type="CocoRobo_return_list">' + ' <value name="list_name"><block type="variables_get"><field name="VAR">my_list</field></block></value>' + ' <value name="list_items"><shadow type="text_list"><field name="TEXT">0, 0, 0</field></shadow></value>' + ' </block>' + ' <block type="list_order_item">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' <value name="list_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' </block>' + ' <block type="lists_append">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' </block>' + ' <block type="list_item_exist">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' <value name="list_item"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' + ' </block>' + ' <block type="lists_extend">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' <value name="extend_list"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' </block>' + ' <block type="lists_clear">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' </block>' + ' <block type="lists_repeat">' + '<value name="NUM">' + ' <shadow type="math_number">' + ' <field name="NUM">5</field>' + ' </shadow>' + '</value>' + ' </block>' + ' <block type="lists_length"></block>' + ' <block type="lists_isEmpty"></block>' + ' <block type="list_first_index">' + ' <value name="elem"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' + ' <value name="my_list"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' </block>' + ' <block type="set_list_order_item">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' <value name="list_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' <value name="set_value"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' </block>' + ' <block type="insert_list_order_item">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' <value name="list_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' <value name="set_value"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' </block>' + ' <block type="parts_of_list">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + ' <value name="start_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' <value name="end_item"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' + ' </block>' + '<block type="lists_getIndex">' + ' <mutation statement="true" at="true"></mutation>' + ' <field name="MODE">REMOVE</field>' + ' <field name="WHERE">FROM_START</field>' + ' <value name="VALUE">' + ' <shadow type="text_list"><field name="TEXT"></field></shadow>' + ' </value>' + '</block>' + '<block type="lists_getIndex">' + ' <mutation statement="false" at="true"></mutation>' + ' <field name="MODE">GET_REMOVE</field>' + ' <field name="WHERE">FROM_START</field>' + ' <value name="VALUE">' + ' <shadow type="text_list"><field name="TEXT"></field></shadow>' + ' </value>' + '</block>' + ' <block type="lists_split">' + ' <value name="DELIM"><shadow type="text"><field name="TEXT">,</field></shadow></value>' + ' </block>' + ' <block type="lists_sort"></block>' + '</category>',
  868. 'Dictionary': '<category id="catDictionary" name="Dictionary" colour="32">' + // '<block type="dictionary_creatDictionary"></block>' +
  869. // '<block type="dictionary_creatDictionarys"></block>' +
  870. // '<block type="dictionary_define"></block>' +
  871. // '<block type="dictionary_addKey"></block>' +
  872. // '<block type="dictionary_valueOf"></block>' +
  873. // '<block type="dictionary_lengthOf"></block>' +
  874. // '<block type="dictionary_dictionaryInclude"></block>' +
  875. // '<block type="dictionary_listOf"></block>' +
  876. ' <block type="dict_create_with_items_insert"></block>' + ' <block type="text_dict"><field name="TEXT">"Age":8</field></block>' + ' <block type="dict_create_with">' + ' <value name="dict_name"><block type="variables_get"><field name="VAR">my_dict</field></block></value>' + ' <value name="dict_items"><shadow type="text_dict"><field name="TEXT">"Age":8</field></shadow></value>' + ' </block>' + ' <block type="add_dict_key_value">' + ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' + ' <value name="dict_items"><shadow type="text"><field name="TEXT">Age</field></shadow></value>' + ' <value name="add_value"><shadow type="math_number"><field name="NUM">10</field></shadow></value>' + ' </block>' + ' <block type="dict_key_value">' + ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' + ' <value name="dict_items"><shadow type="text"><field name="TEXT">Age</field></shadow></value>' + ' </block>' + ' <block type="dict_length">' + ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' + ' </block>' + ' <block type="dict_key_exist">' + ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' + ' <value name="dict_items"><shadow type="text"><field name="TEXT">Age</field></shadow></value>' + ' </block>' + ' <block type="dict_key_or_val_list">' + ' <value name="dict_name"><shadow type="text_dict"><field name="TEXT"></field></shadow></value>' + ' </block>' + '</category>',
  877. // 'Tuples': '<category id="catTuples" name="Tuples" colour="#0090d1">' +
  878. // '</category>',
  879. 'Tuples': '<category id="catTuples" name="Tuples" colour="192">' + // '<block type="tuple_createTuple"></block>' +
  880. // '<block type="tuple_createTuples"></block>' +
  881. // '<block type="tuple_defineTuple"></block>' +
  882. // '<block type="tuple_tupleItem"></block>' +
  883. // '<block type="tuple_tupleValue"></block>' +
  884. // '<block type="tuple_tupleinclude"></block>' +
  885. // '<block type="tuple_returnTupleItem"></block>' +
  886. // '<block type="tuple_returnTupleItems"></block>' +
  887. // '<block type="tuple_listTuple"></block>' +
  888. // // '<block type="tuple_create"></block>' +
  889. ' <block type="tuple_create_with_items_insert"></block>' + '<block type="text_tuple"><field name="TEXT">"cocorobo",</field></block>' + '<block type="tuple_create_with">' + ' <value name="tuple_name"><block type="variables_get"><field name="VAR">my_tuple</field></block></value>' + ' <value name="tuple_items"><shadow type="text_tuple"><field name="TEXT">"cocorobo",</field></shadow></value>' + ' </block>' + ' <block type="tuple_order_item">' + ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' + ' <value name="tuple_order_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + '</block>' + '<block type="tuple_min_max_len">' + ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' + ' </block>' + '<block type="tuple_item_exist">' + ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' + ' <value name="tuple_item"><shadow type="text"><field name="TEXT">cocorobo</field></shadow></value>' + '</block>' + '<block type="parts_of_tuple">' + ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' + ' <value name="tuple_item"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' + '</block>' + ' <block type="parts_of_tuple2">' + ' <value name="tuple_name"><shadow type="text_tuple"><field name="TEXT"></field></shadow></value>' + ' <value name="start_item"><shadow type="math_number"><field name="NUM">0</field></shadow></value>' + ' <value name="end_item"><shadow type="math_number"><field name="NUM">2</field></shadow></value>' + '</block>' + '<block type="list_to_tuple">' + ' <value name="list_name"><shadow type="text_list"><field name="TEXT"></field></shadow></value>' + '</block>' + '</category>',
  890. 'Set': '<category id="catSet" name="Set" colour="160">' + // '<block type="set_creatSets"></block>' +
  891. // '<block type="set_creatSet"></block>' +
  892. // '<block type="set_defineSet"></block>' +
  893. // '<block type="set_updateSet"></block>' +
  894. // '<block type="set_updateSets"></block>' +
  895. // '<block type="set_setSet"></block>' +
  896. // '<block type="set_intersectionSet"></block>' +
  897. // '<block type="set_lengthOf"></block>' +
  898. // '<block type="set_returnSet"></block>' +
  899. '<block type="set_create_with_items_insert"></block>' + ' <block type="text_set"><field name="TEXT">"string", 0.9, ("tuple",)</field></block>' + ' <block type="set_create_with">' + ' <value name="set_name"><block type="variables_get"><field name="VAR">my_set</field></block></value>' + ' <value name="set_items"><shadow type="text_set"></shadow></value>' + ' </block>' + ' <block type="sets_update_ways">' + ' <value name="set_name"><block type="variables_get"><field name="VAR">my_set</field></block></value>' + ' <value name="set_1_name"><shadow type="text_set"></shadow></value>' + ' </block>' + ' <block type="set_update_with">' + ' <value name="set_name"><shadow type="text_set"></shadow></value>' + ' <value name="set_items"></value>' + ' </block>' + ' <block type="set_subset_superset">' + ' <value name="set_name"><shadow type="text_set"></shadow></value>' + ' <value name="set_1_name"><shadow type="text_set"></shadow></value>' + ' </block>' + ' <block type="intersection_of_sets">' + ' <value name="set_name"><shadow type="text_set"></shadow></value>' + ' <value name="set_1_name"><shadow type="text_set"></shadow></value>' + ' </block>' + ' <block type="len_of_sets">' + ' <value name="set_name"><shadow type="text_set"></shadow></value>' + '</block>' + ' <block type="get_sets_pop">' + ' <value name="set_name"><shadow type="text_set"></shadow></value>' + '</block>' + '</category>',
  900. 'Functionsa': '<category id="catFunctions" name="Functions" custom="PROCEDURE" colour="#ff6381">' + '</category>',
  901. // 'Classes': '<category name="Classes" colour="210">' +
  902. // '<block type="class_creation"></block>' +
  903. // // '<block type="class_creation">'+
  904. // // '<mutation value="k"></mutation>'+
  905. // // '</block>'+
  906. // '</category>',
  907. 'Python': '<category name="Python" colour="180">' + '<block type="raw_block"></block>' + '<block type="raw_expression"></block>' + '</category>',
  908. 'Output': '<category id="catOutput" name="Output" colour="#ff8b2c">' + '<block type="esp32_main_controller_io_from_digital_pin">' + ' <value name="digital_pin_input">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="esp32_main_controller_io_set_digital_pin">' + ' <value name="digital_pin_input">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + ' <value name="high_low">' + '<shadow type="esp32_main_controller_io_high_low">' + '</shadow>' + '</value>' + '</block>' + '<block type="esp32_main_controller_io_from_analog_pin">' + ' <value name="analog_pin_input">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="esp32_main_controller_io_set_analog_pin">' + ' <value name="analog_pin_input">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + ' <value name="pwm">' + '<shadow type="math_number">' + ' <field name="NUM">600</field>' + '</shadow>' + '</value>' + ' <value name="frequency">' + '<shadow type="math_number">' + ' <field name="NUM">1000</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="ai_main_controller_io_set_analog_pin">' + ' <value name="analog_pin_input">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + ' <value name="pwm">' + '<shadow type="math_number">' + ' <field name="NUM">600</field>' + '</shadow>' + '</value>' + ' <value name="frequency">' + '<shadow type="math_number">' + ' <field name="NUM">1000</field>' + '</shadow>' + '</value>' + ' <value name="timer">' + '<shadow type="math_number">' + ' <field name="NUM">1</field>' + '</shadow>' + '</value>' + ' <value name="channel">' + '<shadow type="math_number">' + ' <field name="NUM">0</field>' + '</shadow>' + '</value>' + '</block>' + '<block type="esp32_main_controller_io_high_low"></block>' + '</category>',
  909. 'Files': '<category id="catFiles" name="Files" colour="32">' + '<block type="iot_system_run">' + ' <value name="PATH">' + ' <shadow type="text">' + ' <field name="TEXT">/your_python_code.py</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_system_create">' + ' <value name="PATH">' + ' <shadow type="text">' + ' <field name="TEXT">/cocorobo.txt</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_system_write">' + ' <value name="PATH">' + ' <shadow type="text">' + ' <field name="TEXT">/cocorobo.txt</field>' + ' </shadow>' + ' </value>' + ' <value name="WPATH">' + ' <shadow type="text">' + ' <field name="TEXT"></field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_system_input">' + ' <value name="PATH">' + ' <shadow type="text">' + ' <field name="TEXT">/cocorobo.txt</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>',
  910. 'Time': '<category id="catTime" name="Time" colour="#fabe23">' + ' <block type="time_delay">' + ' <value name="DELAY_TIME_MILI">' + ' <block type="math_number">' + ' <field name="NUM">1000</field>' + ' </block>' + ' </value>' + ' </block>' + ' <block type="time_delaymicros">' + ' <value name="DELAY_TIME_MICRO">' + ' <block type="math_number">' + ' <field name="NUM">100</field>' + ' </block>' + ' </value>' + ' </block>' + ' <block type="time_millis"></block>' + ' <block type="time_micros"></block>' + ' <block type="esp32_get_current_date"></block>' + ' <block type="esp32_main_controller_time_timer_init"></block>' + ' <block type="esp32_main_controller_time_timer_get_current"></block>' + ' <block type="esp32_main_controller_time_timer_clear"></block>' + ' <block type="esp32_main_controller_time_period_timer"></block>' + ' <block type="esp32_main_controller_time_period_timer_clear"></block>' + '</category>',
  911. 'Serial Comm.': '<category id="catSerialComm" name="SerialComm" colour="#22b845">' + '<block type="serial_comm_print">' + ' <value name="serial_comm_input">' + ' <shadow type="text">' + ' <field name="TEXT">Hello World!</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="serial_write_data">' + ' <value name="ADD0">' + ' <shadow type="text">' + ' <field name="TEXT">Data</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="serial_send_data_to_microbit">' + '</block>' + // '<block type="ai_serialport_printall">' +
  912. // '</block>' +
  913. '</category>',
  914. 'MainBoard': '<category id="catMainBoard" name="Main Board" colour="#3163ed">' + '<category id="catBasics" name="Basics" colour="#e8795b">' + '<block type="esp32_main_controller_button_read_pressed"></block>' + '<block type="esp32_main_controller_button_read_released"></block>' + '<block type="esp32_main_controller_button_read_value"></block>' + // '<block type="esp32_main_controller_dial_switch_read_pressed"></block>' +
  915. // '<block type="esp32_main_controller_dial_switch_read_released"></block>' +
  916. '<block type="esp32_main_controller_touch_read_touched"></block>' + '<block type="esp32_main_controller_touch_read_untouched"></block>' + '<block type="esp32_main_controller_touch_read_value"></block>' + '<block type="esp32_main_controller_set_led_turnon">' + ' <value name="led_type">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_set_led_turnoff">' + ' <value name="led_type">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_set_led_drawpixel_on">' + ' <value name="x">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="y">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_set_led_drawpixel_off">' + ' <value name="x">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="y">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' +
  917. /*
  918. '<block type="esp32_main_controller_set_led_turnon"></block>' +
  919. '<block type="esp32_main_controller_set_led_turnoff"></block>' +
  920. */
  921. '<block type="esp32_main_controller_set_buzzer">' + ' <value name="esp32_var_num">' + ' <shadow type="math_number">' + ' <field name="NUM">31</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_turn_off_buzzer"></block>' + '<block type="esp32_main_controller_get_environmental_value"></block>' + //'<block type="esp32_main_controller_motion_init"></block>' +
  922. //'<block type="esp32_main_controller_motion_when_shaking"></block>' +
  923. '<block type="esp32_main_controller_motion_when_shaking_STATEMENT"></block>' + //'<block type="esp32_main_controller_motion_when_tilting"></block>' +
  924. '<block type="esp32_main_controller_motion_when_tilting_STATEMENT"></block>' + '<block type="esp32_main_controller_motion_acceleration"></block>' + '<block type="esp32_main_controller_motion_tilt_angle"></block>' + '<block type="esp32_main_controller_get_light"></block>' + '</category>' +
  925. /*
  926. '<category id="catDisplay" name="Display" colour="#5bb2d6">' +
  927. '<block type="CocoRobo_display_fill"></block>' +
  928. '<block type="esp32_main_controller_lcd_rotation"></block>' +
  929. '<block type="botbit_Steering_XY">' +
  930. ' <value name="A">' +
  931. ' <shadow type="math_number">' +
  932. ' <field name="NUM">0</field>' +
  933. ' </shadow>' +
  934. ' </value>' +
  935. ' <value name="B">' +
  936. ' <shadow type="math_number">' +
  937. ' <field name="NUM">0</field>' +
  938. ' </shadow>' +
  939. ' </value>' +
  940. '</block>' +
  941. '<block type="botbit_Steering_WH">' +
  942. ' <value name="A">' +
  943. ' <shadow type="math_number">' +
  944. ' <field name="NUM">0</field>' +
  945. ' </shadow>' +
  946. ' </value>' +
  947. ' <value name="B">' +
  948. ' <shadow type="math_number">' +
  949. ' <field name="NUM">0</field>' +
  950. ' </shadow>' +
  951. ' </value>' +
  952. '</block>' +
  953. '<block type="esp32_main_controller_lcd_color_hex_to_rgb"></block>' +
  954. '<block type="esp32_main_controller_rgb_value">' +
  955. ' <value name="rgb_value_r">' +
  956. ' <shadow type="math_number">' +
  957. ' <field name="NUM">255</field>' +
  958. ' </shadow>' +
  959. ' </value>' +
  960. ' <value name="rgb_value_g">' +
  961. ' <shadow type="math_number">' +
  962. ' <field name="NUM">0</field>' +
  963. ' </shadow>' +
  964. ' </value>' +
  965. ' <value name="rgb_value_b">' +
  966. ' <shadow type="math_number">' +
  967. ' <field name="NUM">0</field>' +
  968. ' </shadow>' +
  969. ' </value>' +
  970. '</block>' +
  971. '<block type="esp32_main_controller_lcd_screen_fill">' +
  972. ' <value name="COLOR">' +
  973. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  974. ' </shadow>' +
  975. ' </value>' +
  976. '</block>' +
  977. '<block type="esp32_main_controller_clear_screen"></block>' +
  978. ' <block type="esp32_main_controller_lcd_drawpixel">' +
  979. ' <value name="COLOR">' +
  980. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  981. ' </shadow>' +
  982. ' </value>' +
  983. ' <value name="POS">' +
  984. ' <block type="lcd_set_position">' +
  985. ' <value name="POSX">' +
  986. ' <shadow type="math_number">' +
  987. ' <field name="NUM">0</field>' +
  988. ' </shadow>' +
  989. ' </value>' +
  990. ' <value name="POSY">' +
  991. ' <shadow type="math_number">' +
  992. ' <field name="NUM">0</field>' +
  993. ' </shadow>' +
  994. ' </value>' +
  995. ' </block>' +
  996. ' </value>' +
  997. ' </block>' +
  998. ' <block type="esp32_main_controller_lcd_drawline">' +
  999. ' <value name="COLOR">' +
  1000. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  1001. ' </shadow>' +
  1002. ' </value>' +
  1003. ' <value name="POSA">' +
  1004. ' <block type="lcd_set_position">' +
  1005. ' <value name="POSX">' +
  1006. ' <shadow type="math_number">' +
  1007. ' <field name="NUM">0</field>' +
  1008. ' </shadow>' +
  1009. ' </value>' +
  1010. ' <value name="POSY">' +
  1011. ' <shadow type="math_number">' +
  1012. ' <field name="NUM">0</field>' +
  1013. ' </shadow>' +
  1014. ' </value>' +
  1015. ' </block>' +
  1016. ' </value>' +
  1017. ' <value name="POSB">' +
  1018. ' <block type="lcd_set_position">' +
  1019. ' <value name="POSX">' +
  1020. ' <shadow type="math_number">' +
  1021. ' <field name="NUM">50</field>' +
  1022. ' </shadow>' +
  1023. ' </value>' +
  1024. ' <value name="POSY">' +
  1025. ' <shadow type="math_number">' +
  1026. ' <field name="NUM">50</field>' +
  1027. ' </shadow>' +
  1028. ' </value>' +
  1029. ' </block>' +
  1030. ' </value>' +
  1031. ' </block>' +
  1032. ' <block type="esp32_main_controller_lcd_drawlinelen">' +
  1033. ' <value name="COLOR">' +
  1034. ' <block type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  1035. ' </block>' +
  1036. ' </value>' +
  1037. ' <value name="POS">' +
  1038. ' <block type="lcd_set_position">' +
  1039. ' <value name="POSX">' +
  1040. ' <shadow type="math_number">' +
  1041. ' <field name="NUM">0</field>' +
  1042. ' </shadow>' +
  1043. ' </value>' +
  1044. ' <value name="POSY">' +
  1045. ' <shadow type="math_number">' +
  1046. ' <field name="NUM">0</field>' +
  1047. ' </shadow>' +
  1048. ' </value>' +
  1049. ' </block>' +
  1050. ' </value>' +
  1051. ' <value name="LENGTH">' +
  1052. ' <shadow type="math_number">' +
  1053. ' <field name="NUM">0</field>' +
  1054. ' </shadow>' +
  1055. ' </value>' +
  1056. ' </block>' +
  1057. ' <block type="esp32_main_controller_lcd_drawrect">' +
  1058. ' <value name="COLOR">' +
  1059. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  1060. ' </shadow>' +
  1061. ' </value>' +
  1062. ' <value name="POSA">' +
  1063. ' <block type="lcd_set_position">' +
  1064. ' <value name="POSX">' +
  1065. ' <shadow type="math_number">' +
  1066. ' <field name="NUM">0</field>' +
  1067. ' </shadow>' +
  1068. ' </value>' +
  1069. ' <value name="POSY">' +
  1070. ' <shadow type="math_number">' +
  1071. ' <field name="NUM">0</field>' +
  1072. ' </shadow>' +
  1073. ' </value>' +
  1074. ' </block>' +
  1075. ' </value>' +
  1076. ' <value name="POSB">' +
  1077. ' <block type="lcd_set_width_height">' +
  1078. ' <value name="WIDTH">' +
  1079. ' <shadow type="math_number">' +
  1080. ' <field name="NUM">0</field>' +
  1081. ' </shadow>' +
  1082. ' </value>' +
  1083. ' <value name="HEIGHT">' +
  1084. ' <shadow type="math_number">' +
  1085. ' <field name="NUM">0</field>' +
  1086. ' </shadow>' +
  1087. ' </value>' +
  1088. ' </block>' +
  1089. ' </value>' +
  1090. ' </block>' +
  1091. ' <block type="esp32_main_controller_lcd_drawcircle">' +
  1092. ' <value name="COLOR">' +
  1093. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  1094. ' </shadow>' +
  1095. ' </value>' +
  1096. ' <value name="POSA">' +
  1097. ' <block type="lcd_set_position">' +
  1098. ' <value name="POSX">' +
  1099. ' <shadow type="math_number">' +
  1100. ' <field name="NUM">0</field>' +
  1101. ' </shadow>' +
  1102. ' </value>' +
  1103. ' <value name="POSY">' +
  1104. ' <shadow type="math_number">' +
  1105. ' <field name="NUM">0</field>' +
  1106. ' </shadow>' +
  1107. ' </value>' +
  1108. ' </block>' +
  1109. ' </value>' +
  1110. ' <value name="RADIUS">' +
  1111. ' <shadow type="math_number">' +
  1112. ' <field name="NUM">30</field>' +
  1113. ' </shadow>' +
  1114. ' </value>' +
  1115. ' </block>' +
  1116. ' <block type="esp32_main_controller_lcd_drawqrcode">' +
  1117. ' <value name="POSA">' +
  1118. ' <block type="lcd_set_position">' +
  1119. ' <value name="POSX">' +
  1120. ' <shadow type="math_number">' +
  1121. ' <field name="NUM">0</field>' +
  1122. ' </shadow>' +
  1123. ' </value>' +
  1124. ' <value name="POSY">' +
  1125. ' <shadow type="math_number">' +
  1126. ' <field name="NUM">0</field>' +
  1127. ' </shadow>' +
  1128. ' </value>' +
  1129. ' </block>' +
  1130. ' </value>' +
  1131. ' <value name="CONTENT">' +
  1132. ' <shadow type="text">' +
  1133. ' <field name="TEXT"></field>' +
  1134. ' </shadow>' +
  1135. ' </value>' +
  1136. ' <value name="WIDTH">' +
  1137. ' <shadow type="math_number">' +
  1138. ' <field name="NUM">2</field>' +
  1139. ' </shadow>' +
  1140. ' </value>' +
  1141. ' </block>' +
  1142. ' <block type="esp32_main_controller_lcd_drawtext">' +
  1143. ' <value name="COLOR">' +
  1144. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  1145. ' </shadow>' +
  1146. ' </value>' +
  1147. ' <value name="POSA">' +
  1148. ' <block type="lcd_set_position">' +
  1149. ' <value name="POSX">' +
  1150. ' <shadow type="math_number">' +
  1151. ' <field name="NUM">0</field>' +
  1152. ' </shadow>' +
  1153. ' </value>' +
  1154. ' <value name="POSY">' +
  1155. ' <shadow type="math_number">' +
  1156. ' <field name="NUM">0</field>' +
  1157. ' </shadow>' +
  1158. ' </value>' +
  1159. ' </block>' +
  1160. ' </value>' +
  1161. ' <value name="CONTENT">' +
  1162. ' <shadow type="text">' +
  1163. ' <field name="TEXT"></field>' +
  1164. ' </shadow>' +
  1165. ' </value>' +
  1166. ' <value name="SIZE">' +
  1167. ' <shadow type="math_number">' +
  1168. ' <field name="NUM">1</field>' +
  1169. ' </shadow>' +
  1170. ' </value>' +
  1171. ' </block>' +
  1172. '</category>' +
  1173. */
  1174. '<category id="catMainWifi" name="Wi-Fi" colour="#386dc8">' + '<block type="esp32_main_controller_wifi_connect_internet">' + ' <value name="ssid">' + ' <shadow type="text">' + ' <field name="TEXT">CocoRobo</field>' + ' </shadow>' + ' </value>' + ' <value name="password">' + ' <shadow type="text">' + ' <field name="TEXT">cocorobo</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_get_wifi_connection_status"></block>' + '<block type="controls_if">' + ' <value name="IF0">' + ' <block type="logic_compare">' + ' <value name="A">' + ' <block type="esp32_main_controller_get_wifi_connection_status">' + ' </block>' + ' </value>' + ' <value name="B">' + '<block type="logic_boolean"></block>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_wifi_get_info"></block>' + '<block type="esp32_main_controller_wifi_ntptime"></block>' + '<block type="esp32_main_controller_wifi_disconnect"></block>' + '<block type="esp32_main_controller_wifi_enable_hotspot_mode">' + ' <value name="SSID">' + ' <shadow type="text">' + ' <field name="TEXT">CocoRobo_AP</field>' + ' </shadow>' + ' </value>' + ' <value name="PASSWORD">' + ' <shadow type="text">' + ' <field name="TEXT">cocorobo</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_wifi_get_info"></block>' + '<block type="esp32_main_controller_wifi_acquiring_equipment"></block>' + '<block type="esp32_main_controller_get_wifi_devices_number"></block>' + '<block type="esp32_main_controller_wifi_close"></block>' + '</category>' + '<category id="catWeb" name="Web" colour="#183895">' + '<block type="esp32_network_http_get">' + ' <value name="http_get_url">' + ' <shadow type="text">' + ' <field name="TEXT">HTTP://ENTER_AN_URL</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_network_http_post">' + ' <value name="http_post_url">' + ' <shadow type="text">' + ' <field name="TEXT">HTTP://ENTER_AN_URL</field>' + ' </shadow>' + ' </value>' + ' <value name="data">' + ' <shadow type="dict_create_with_items_insert"></shadow>' + ' </value>' + '</block>' + '<block type="CocoRobo_get"></block>' + '<block type="esp32_network_http_get_data_from_local_server"></block>' + '<block type="esp32_network_http_server_setup"></block>' + '<block type="esp32_network_http_server_route"></block>' + '<block type="esp32_network_http_server_route_respond">' + ' <value name="exec">' + ' <shadow type="text">' + ' <field name="TEXT">OK</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_network_http_server_get_data"></block>' + '<block type="esp32_web_ws_setup_send"></block>' + '<block type="esp32_web_ws_send">' + ' <value name="command">' + ' <shadow type="text">' + ' <field name="TEXT">Hello</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_web_ws_setup_receive"></block>' + '<block type="esp32_web_ws_receive_statement"></block>' + '<block type="esp32_web_ws_receive_get_data"></block>' +
  1175. /*
  1176. '<block type="CocoRobo_set_max"></block>' +
  1177. '<block type="CocoRobo_get_source"></block>' +
  1178. */
  1179. '</category>' + '<category id="catIoTService" name="IoT Service" colour="#3c7683">' + '<block type="iot_service_cococloud">' + ' <value name="ADD0">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_service_cococloud_read"></block>' + '<block type="iot_service_cococloud_read_data">' + ' <value name="property">' + ' <shadow type="text">' + ' <field name="TEXT">property</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_ifttt_send_data">' + ' <value name="ifttt_data_1">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="ifttt_data_2">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="ifttt_data_3">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_main_controller_ifttt_touched"></block>' + '<block type="iot_service_thingspeak">' + ' <value name="ADD0">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_service_thingspeak_read"></block>' + '<block type="iot_service_thingspeak_read_total"></block>' + '<block type="iot_service_thingspeak_read_specific">' + ' <value name="entry">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="field">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' +
  1180. /* '<category id="catNBIOT" name="NB-IoT" colour="#629978">' +
  1181. '<block type="esp32_nbiot_setup"></block>' +
  1182. '<block type="esp32_nbiot_get_power_status"></block>' +
  1183. '<block type="esp32_nbiot_get_network_status"></block>' +
  1184. '<block type="esp32_nbiot_get_network_ip"></block>' +
  1185. '<block type="esp32_nbiot_onenet_init">' +
  1186. ' <value name="product_id">' +
  1187. ' <shadow type="text">' +
  1188. ' <field name="TEXT">320012</field>' +
  1189. ' </shadow>' +
  1190. ' </value>' +
  1191. ' <value name="device_id">' +
  1192. ' <shadow type="text">' +
  1193. ' <field name="TEXT">585407311</field>' +
  1194. ' </shadow>' +
  1195. ' </value>' +
  1196. ' <value name="device_apikey">' +
  1197. ' <shadow type="text">' +
  1198. ' <field name="TEXT">jiv4F3zcLS8X=i9=Fyry93wCt6s=</field>' +
  1199. ' </shadow>' +
  1200. ' </value>' +
  1201. '</block>' +
  1202. '<block type="esp32_nbiot_onenet_connection_status"></block>' +
  1203. '<block type="iot_service_nbiot_onenet">' +
  1204. ' <value name="ADD0">' +
  1205. ' <shadow type="math_number">' +
  1206. ' <field name="NUM">0</field>' +
  1207. ' </shadow>' +
  1208. ' </value>' +
  1209. '</block>' +
  1210. '<block type="esp32_nbiot_onenet_read_value"></block>' +
  1211. '<block type="iot_service_nbiot_onenet_read">' +
  1212. ' <value name="message">' +
  1213. ' <shadow type="text">' +
  1214. ' <field name="TEXT">hello</field>' +
  1215. ' </shadow>' +
  1216. ' </value>' +
  1217. '</block>' +
  1218. '<block type="iot_service_nbiot_cococloud">' +
  1219. ' <value name="ADD0">' +
  1220. ' <shadow type="math_number">' +
  1221. ' <field name="NUM">0</field>' +
  1222. ' </shadow>' +
  1223. ' </value>' +
  1224. '</block>' +
  1225. '</category>' +
  1226. */
  1227. '<category id="catSystem" name="System" colour="#22398e">' + '<block type="iot_system_restart"></block>' + '<block type="iot_system_get"></block>' + '<block type="iot_system_mac"></block>' + '<block type="iot_system_get_cocorobo_id"></block>' + '</category>' + '</category>',
  1228. 'ExtendedFunction': '<category id="ExtendedFunction" name="Extended Function" colour="#2fc67b">' + // '<category id="catServo" name="Servo" colour="#3c62e2">' +
  1229. // '</category>' +
  1230. '<category id="EFLEDLS" name="LED Light Screen" colour="#e8795b">' + '<block type="iot_led_matrix_setup"></block>' + '<block type="iot_led_matrix_xy">' + ' <value name="x">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="y">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_led_matrix_wh">' + ' <value name="w">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="h">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="iot_led_matrix_color_picker"></block>' + '<block type="iot_led_matrix_draw_pixel">' + ' <value name="color">' + ' <block type="iot_led_matrix_color_picker">' + ' </block>' + ' </value>' + ' <value name="coordinate">' + ' <block type="iot_led_matrix_xy">' + ' <value name="x">' + ' <block type="math_number">' + ' <field name="NUM">1</field>' + ' </block>' + ' </value>' + ' <value name="y">' + ' <block type="math_number">' + ' <field name="NUM">1</field>' + ' </block>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="iot_led_matrix_show_above"></block>' + '</category>' + '<category id="EFMotor" name="Motor" colour="#5bb2d6">' + '<block type="esp32_motor_setup"></block>' + '<block type="esp32_motor_run">' + ' <value name="speed">' + ' <shadow type="math_number">' + ' <field name="NUM">2000</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' + '<category id="EFSG" name="Steering Gear" colour="#386dc8">' + '<block type="esp32_main_controller_servo_setup"></block>' + '<block type="esp32_main_controller_servo_set">' + ' <value name="pin_select">' + ' <shadow type="math_number">' + ' <field name="NUM">19</field>' + ' </shadow>' + ' </value>' + ' <value name="degree">' + ' <shadow type="math_number">' + ' <field name="NUM">90</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' +
  1231. /*'<category id="catLEDStrip" name="LED Strip" colour="#3dade2">' +
  1232. '<block type="esp32_main_controller_led_strip_setup">' +
  1233. ' <value name="io">' +
  1234. ' <shadow type="math_number">' +
  1235. ' <field name="NUM">15</field>' +
  1236. ' </shadow>' +
  1237. ' </value>' +
  1238. ' <value name="count">' +
  1239. ' <shadow type="math_number">' +
  1240. ' <field name="NUM">8</field>' +
  1241. ' </shadow>' +
  1242. ' </value>' +
  1243. '</block>' +
  1244. '<block type="esp32_main_controller_led_strip_set">' +
  1245. ' <value name="location">' +
  1246. ' <shadow type="math_number">' +
  1247. ' <field name="NUM">0</field>' +
  1248. ' </shadow>' +
  1249. ' </value>' +
  1250. ' <value name="color">' +
  1251. ' <shadow type="esp32_main_controller_lcd_color_hex_to_rgb">' +
  1252. ' </shadow>' +
  1253. ' </value>' +
  1254. '</block>' +
  1255. '</category>' +*/
  1256. '<category id="EFGH" name="Game Handle" colour="#183895">' + '<block type="x_iot_read_gamepad_button_pressed"></block>' + '<block type="x_iot_read_gamepad_button_released"></block>' + '<block type="x_iot_read_gamepad_button_x-r"></block>' + '<block type="x_iot_read_gamepad_joystick_check"></block>' + '<block type="x_iot_read_gamepad_joystick"></block>' + '</category>' + '<category id="EFNI" name="NB-IoT" colour="#3c7683">' + '<block type="esp32_nbiot_setup"></block>' + '<block type="esp32_nbiot_get_power_status"></block>' + '<block type="esp32_nbiot_get_network_status"></block>' + '<block type="esp32_nbiot_get_network_ip"></block>' + '<block type="iot_service_nbiot_cococloud">' + ' <value name="ADD0">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_nbiot_onenet_init">' + ' <value name="product_id">' + ' <shadow type="text">' + ' <field name="TEXT">320012</field>' + ' </shadow>' + ' </value>' + ' <value name="device_id">' + ' <shadow type="text">' + ' <field name="TEXT">585407311</field>' + ' </shadow>' + ' </value>' + ' <value name="device_apikey">' + ' <shadow type="text">' + ' <field name="TEXT">jiv4F3zcLS8X=i9=Fyry93wCt6s=</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_nbiot_onenet_connection_status"></block>' + '<block type="iot_service_nbiot_onenet">' + ' <value name="ADD0">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_nbiot_onenet_read_value"></block>' + '<block type="iot_service_nbiot_onenet_read">' + ' <value name="message">' + ' <shadow type="text">' + ' <field name="TEXT">hello</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' + '<category id="EFBluetooth" name="Bluetooth" colour="#629978">' + '</category>' + '</category>',
  1257. 'A.I.Board': '<category id="catAI" name="A.I. Board" colour="#f76734">' +
  1258. /*
  1259. _ ___ ____ _
  1260. / \ |_ _| | __ ) __ _ ___(_) ___
  1261. / _ \ | | | _ \ / _` / __| |/ __|
  1262. / ___ \ | | | |_) | (_| \__ \ | (__
  1263. /_/ \_\___| |____/ \__,_|___/_|\___|
  1264. */
  1265. '<category id="catAIBasic" name="Basic" colour="#d42b03">' + //基础
  1266. '<block type="ai_k210_button_read_pressed"></block>' + '<block type="ai_k210_button_read_released"></block>' + '<block type="ai_k210_led_light_up"></block>' + '<block type="ai_k210_led_light_off"></block>' + '<block type="ai_system_restart"></block>' + '<block type="ai_system_gc"></block>' + '<block type="ai_system_run">' + ' <value name="PATH">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/your_python_code.py</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' +
  1267. /*
  1268. _ ___ ____
  1269. / \ |_ _| / ___| ___ _ __ ___ ___ _ __
  1270. / _ \ | | \___ \ / __| '__/ _ \/ _ \ '_ \
  1271. / ___ \ _ | | _ ___) | (__| | | __/ __/ | | |
  1272. /_/ \_(_)___(_) |____/ \___|_| \___|\___|_| |_|
  1273. */
  1274. '<category id="catAIScreen" name="Screen" colour="#5cb2d6">' + '<block type="ai_lcd_screeninit"></block>' + '<block type="ai_lcd_rotation"></block>' + '<block type="ai_lcd_filp"></block>' + '<block type="ai_lcd_screen"></block>' + '<block type="ai_lcd_fill_screen_with_rgb">' + ' <value name="rgb_value">' + ' <block type="ai_lcd_rgb_value_input">' + ' <value name="rgb_value_r">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="rgb_value_g">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="rgb_value_b">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_lcd_clear"></block>' + '<block type="ai_lcd_rgb_value_input">' + ' <value name="rgb_value_r">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="rgb_value_g">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="rgb_value_b">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_lcd_XY">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_lcd_WH">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + // ' <block type="ai_lcd_colortext">' +
  1275. // ' <value name="POSA">' +
  1276. // ' <block type="lcd_set_position">' +
  1277. // ' <value name="POSX">' +
  1278. // ' <shadow type="math_number">' +
  1279. // ' <field name="NUM">0</field>' +
  1280. // ' </shadow>' +
  1281. // ' </value>' +
  1282. // ' <value name="POSY">' +
  1283. // ' <shadow type="math_number">' +
  1284. // ' <field name="NUM">0</field>' +
  1285. // ' </shadow>' +
  1286. // ' </value>' +
  1287. // ' </block>' +
  1288. // ' </value>' +
  1289. // ' <value name="CONTENT">' +
  1290. // ' <shadow type="text">' +
  1291. // ' <field name="TEXT"></field>' +
  1292. // ' </shadow>' +
  1293. // ' </value>' +
  1294. // ' </block>' +
  1295. '<block type="ai_lcd_createnonecarvas">' + ' <value name="wh">' + ' <block type="lcd_set_width_height">' + ' <value name="WIDTH">' + ' <shadow type="math_number">' + ' <field name="NUM">240</field>' + ' </shadow>' + ' </value>' + ' <value name="HEIGHT">' + ' <shadow type="math_number">' + ' <field name="NUM">240</field>' + ' </shadow>' + ' </value>' + '</block>' + ' </value>' + '</block>' + '<block type="ai_lcd_fillcanvas">' + ' <value name="color">' + ' <block type="ai_lcd_rgb_value_input">' + ' <value name="rgb_value_r">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="rgb_value_g">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="rgb_value_b">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_lcd_createcarvas"></block>' + '<block type="ai_lcd_showcarvas_set_cord">' + ' <value name="xy">' + ' <block type="ai_lcd_XY">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + ' <block type="ai_lcd_textcarvas">' + ' <value name="POSA">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="CONTENT">' + ' <shadow type="text">' + ' <field name="TEXT"></field>' + ' </shadow>' + ' </value>' + ' <value name="COLOR">' + ' <block type="lcd_set_color">' + ' </block>' + ' </value>' + ' <value name="Scale">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + // ' <value name="POSC">' +
  1296. // ' <block type="lcd_set_bool">' +
  1297. // ' </block>' +
  1298. // ' </value>' +
  1299. '</block>' + ' <block type="ai_lcd_linecarvas">' + ' <value name="POSA">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="POSB">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="COLOR">' + ' <block type="lcd_set_color">' + ' </block>' + ' </value>' + ' <value name="Scale">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="ai_lcd_ractanglecarvas">' + ' <value name="POSA">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="POSB">' + ' <block type="lcd_set_width_height">' + ' <value name="WIDTH">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="HEIGHT">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="COLOR">' + ' <block type="lcd_set_color">' + ' </block>' + ' </value>' + ' <value name="Scale">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="ai_lcd_drawcirclecarvas">' + ' <value name="POSA">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="Scale">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + ' </shadow>' + ' </value>' + ' <value name="COLOR">' + ' <block type="lcd_set_color">' + ' </block>' + ' </value>' + ' <value name="Scale_0">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="ai_lcd_draw_cross_sign">' + ' <value name="xy">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="color">' + ' <block type="lcd_set_color">' + ' </block>' + ' </value>' + ' <value name="size">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="thickness">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="ai_lcd_draw_arrow_sign">' + ' <value name="xy1">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="xy2">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">120</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">120</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="color">' + ' <block type="lcd_set_color">' + ' </block>' + ' </value>' + ' <value name="thickness">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="ai_lcd_draw_image_on_canvas">' + ' <value name="image_path">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/preset/images/arrow_up_filled.jpg</field>' + ' </shadow>' + ' </value>' + ' <value name="xy">' + ' <block type="lcd_set_position">' + ' <value name="POSX">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="POSY">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="scale_x">' + ' <shadow type="math_number">' + ' <field name="NUM">1.5</field>' + ' </shadow>' + ' </value>' + ' <value name="scale_y">' + ' <shadow type="math_number">' + ' <field name="NUM">1.5</field>' + ' </shadow>' + ' </value>' + ' </block>' + '<block type="ai_lcd_showcarvas_set_display">' + '</block>' +
  1300. /*
  1301. '<block type="ai_lcd_showcarvas">' +
  1302. ' <value name="xy">' +
  1303. ' <block type="ai_lcd_XY">' +
  1304. ' <value name="A">' +
  1305. ' <shadow type="math_number">' +
  1306. ' <field name="NUM">0</field>' +
  1307. ' </shadow>' +
  1308. ' </value>' +
  1309. ' <value name="B">' +
  1310. ' <shadow type="math_number">' +
  1311. ' <field name="NUM">0</field>' +
  1312. ' </shadow>' +
  1313. ' </value>' +
  1314. ' </block>' +
  1315. ' </value>' +
  1316. '</block>' +
  1317. */
  1318. '<block type="ai_lcd_clearcanvas"></block>' + '</category>' +
  1319. /*
  1320. '<category id="catVision" name="Vision" colour="#f2a247">' +//视觉 -- 屏幕
  1321. '<block type="ai_vision_color_analyze">' +
  1322. ' <value name="xy">' +
  1323. ' <block type="ai_lcd_XY_vision">' +
  1324. ' <value name="A">' +
  1325. ' <shadow type="math_number">' +
  1326. ' <field name="NUM">0</field>' +
  1327. ' </shadow>' +
  1328. ' </value>' +
  1329. ' <value name="B">' +
  1330. ' <shadow type="math_number">' +
  1331. ' <field name="NUM">0</field>' +
  1332. ' </shadow>' +
  1333. ' </value>' +
  1334. ' </block>' +
  1335. ' </value>' +
  1336. ' <value name="wh">' +
  1337. ' <block type="ai_lcd_WH_vision">' +
  1338. ' <value name="A">' +
  1339. ' <shadow type="math_number">' +
  1340. ' <field name="NUM">0</field>' +
  1341. ' </shadow>' +
  1342. ' </value>' +
  1343. ' <value name="B">' +
  1344. ' <shadow type="math_number">' +
  1345. ' <field name="NUM">0</field>' +
  1346. ' </shadow>' +
  1347. ' </value>' +
  1348. ' </block>' +
  1349. ' </value>' +
  1350. '</block>' +
  1351. '<block type="ai_vision_find_blobs">' +
  1352. ' <value name="color_threshold">' +
  1353. '<shadow type="tuple_create_with_items_insert"></shadow>' +
  1354. ' </value>' +
  1355. ' <value name="xy">' +
  1356. ' <block type="ai_lcd_XY_vision">' +
  1357. ' <value name="A">' +
  1358. ' <shadow type="math_number">' +
  1359. ' <field name="NUM">0</field>' +
  1360. ' </shadow>' +
  1361. ' </value>' +
  1362. ' <value name="B">' +
  1363. ' <shadow type="math_number">' +
  1364. ' <field name="NUM">0</field>' +
  1365. ' </shadow>' +
  1366. ' </value>' +
  1367. ' </block>' +
  1368. ' </value>' +
  1369. ' <value name="wh">' +
  1370. ' <block type="ai_lcd_WH_vision">' +
  1371. ' <value name="A">' +
  1372. ' <shadow type="math_number">' +
  1373. ' <field name="NUM">0</field>' +
  1374. ' </shadow>' +
  1375. ' </value>' +
  1376. ' <value name="B">' +
  1377. ' <shadow type="math_number">' +
  1378. ' <field name="NUM">0</field>' +
  1379. ' </shadow>' +
  1380. ' </value>' +
  1381. ' </block>' +
  1382. ' </value>' +
  1383. ' <value name="area_threshold">' +
  1384. ' <shadow type="math_number">' +
  1385. ' <field name="NUM">10</field>' +
  1386. ' </shadow>' +
  1387. ' </value>' +
  1388. ' <value name="pixels_threshold">' +
  1389. ' <shadow type="math_number">' +
  1390. ' <field name="NUM">10</field>' +
  1391. ' </shadow>' +
  1392. ' </value>' +
  1393. '</block>' +
  1394. '<block type="ai_vision_get_blobs"></block>' +
  1395. '<block type="ai_vision_find_qrcode"></block>' +
  1396. '<block type="ai_vision_qrcode_get_info"></block>' +
  1397. '<block type="ai_vision_find_apriltag"></block>' +
  1398. '<block type="ai_vision_apriltag_get_info"></block>' +
  1399. '<block type="ai_vision_find_datamatrices"></block>' +
  1400. '<block type="ai_vision_datamatrices_get_info"></block>' +
  1401. '<block type="ai_vision_find_barcodes"></block>' +
  1402. '<block type="ai_vision_barcodes_get_info"></block>' +
  1403. '<block type="ai_vision_find_circles">' +
  1404. ' <value name="xy">' +
  1405. ' <block type="ai_lcd_XY_vision">' +
  1406. ' <value name="A">' +
  1407. ' <shadow type="math_number">' +
  1408. ' <field name="NUM">0</field>' +
  1409. ' </shadow>' +
  1410. ' </value>' +
  1411. ' <value name="B">' +
  1412. ' <shadow type="math_number">' +
  1413. ' <field name="NUM">0</field>' +
  1414. ' </shadow>' +
  1415. ' </value>' +
  1416. ' </block>' +
  1417. ' </value>' +
  1418. ' <value name="wh">' +
  1419. ' <block type="ai_lcd_WH_vision">' +
  1420. ' <value name="A">' +
  1421. ' <shadow type="math_number">' +
  1422. ' <field name="NUM">0</field>' +
  1423. ' </shadow>' +
  1424. ' </value>' +
  1425. ' <value name="B">' +
  1426. ' <shadow type="math_number">' +
  1427. ' <field name="NUM">0</field>' +
  1428. ' </shadow>' +
  1429. ' </value>' +
  1430. ' </block>' +
  1431. ' </value>' +
  1432. ' <value name="threshold">' +
  1433. ' <shadow type="math_number">' +
  1434. ' <field name="NUM">2000</field>' +
  1435. ' </shadow>' +
  1436. ' </value>' +
  1437. ' <value name="x_margin">' +
  1438. ' <shadow type="math_number">' +
  1439. ' <field name="NUM">10</field>' +
  1440. ' </shadow>' +
  1441. ' </value>' +
  1442. ' <value name="y_margin">' +
  1443. ' <shadow type="math_number">' +
  1444. ' <field name="NUM">10</field>' +
  1445. ' </shadow>' +
  1446. ' </value>' +
  1447. ' <value name="r_margin">' +
  1448. ' <shadow type="math_number">' +
  1449. ' <field name="NUM">10</field>' +
  1450. ' </shadow>' +
  1451. ' </value>' +
  1452. ' <value name="r_min">' +
  1453. ' <shadow type="math_number">' +
  1454. ' <field name="NUM">2</field>' +
  1455. ' </shadow>' +
  1456. ' </value>' +
  1457. ' <value name="r_max">' +
  1458. ' <shadow type="math_number">' +
  1459. ' <field name="NUM">100</field>' +
  1460. ' </shadow>' +
  1461. ' </value>' +
  1462. ' <value name="r_step">' +
  1463. ' <shadow type="math_number">' +
  1464. ' <field name="NUM">2</field>' +
  1465. ' </shadow>' +
  1466. ' </value>' +
  1467. '</block>' +
  1468. '<block type="ai_vision_get_circles">' +
  1469. '</block>' +
  1470. '<block type="ai_vision_find_lines">' +
  1471. ' <value name="xy">' +
  1472. ' <block type="ai_lcd_XY_vision">' +
  1473. ' <value name="A">' +
  1474. ' <shadow type="math_number">' +
  1475. ' <field name="NUM">0</field>' +
  1476. ' </shadow>' +
  1477. ' </value>' +
  1478. ' <value name="B">' +
  1479. ' <shadow type="math_number">' +
  1480. ' <field name="NUM">0</field>' +
  1481. ' </shadow>' +
  1482. ' </value>' +
  1483. ' </block>' +
  1484. ' </value>' +
  1485. ' <value name="wh">' +
  1486. ' <block type="ai_lcd_WH_vision">' +
  1487. ' <value name="A">' +
  1488. ' <shadow type="math_number">' +
  1489. ' <field name="NUM">0</field>' +
  1490. ' </shadow>' +
  1491. ' </value>' +
  1492. ' <value name="B">' +
  1493. ' <shadow type="math_number">' +
  1494. ' <field name="NUM">0</field>' +
  1495. ' </shadow>' +
  1496. ' </value>' +
  1497. ' </block>' +
  1498. ' </value>' +
  1499. ' <value name="threshold">' +
  1500. ' <shadow type="math_number">' +
  1501. ' <field name="NUM">1000</field>' +
  1502. ' </shadow>' +
  1503. ' </value>' +
  1504. ' <value name="theta_margin">' +
  1505. ' <shadow type="math_number">' +
  1506. ' <field name="NUM">25</field>' +
  1507. ' </shadow>' +
  1508. ' </value>' +
  1509. ' <value name="rho_margin">' +
  1510. ' <shadow type="math_number">' +
  1511. ' <field name="NUM">25</field>' +
  1512. ' </shadow>' +
  1513. ' </value>' +
  1514. '</block>' +
  1515. '<block type="ai_vision_get_lines">' +
  1516. '</block>' +
  1517. '<block type="ai_vision_find_rects">' +
  1518. ' <value name="xy">' +
  1519. ' <block type="ai_lcd_XY_vision">' +
  1520. ' <value name="A">' +
  1521. ' <shadow type="math_number">' +
  1522. ' <field name="NUM">0</field>' +
  1523. ' </shadow>' +
  1524. ' </value>' +
  1525. ' <value name="B">' +
  1526. ' <shadow type="math_number">' +
  1527. ' <field name="NUM">0</field>' +
  1528. ' </shadow>' +
  1529. ' </value>' +
  1530. ' </block>' +
  1531. ' </value>' +
  1532. ' <value name="wh">' +
  1533. ' <block type="ai_lcd_WH_vision">' +
  1534. ' <value name="A">' +
  1535. ' <shadow type="math_number">' +
  1536. ' <field name="NUM">0</field>' +
  1537. ' </shadow>' +
  1538. ' </value>' +
  1539. ' <value name="B">' +
  1540. ' <shadow type="math_number">' +
  1541. ' <field name="NUM">0</field>' +
  1542. ' </shadow>' +
  1543. ' </value>' +
  1544. ' </block>' +
  1545. ' </value>' +
  1546. ' <value name="threshold">' +
  1547. ' <shadow type="math_number">' +
  1548. ' <field name="NUM">10000</field>' +
  1549. ' </shadow>' +
  1550. ' </value>' +
  1551. '</block>' +
  1552. '<block type="ai_vision_get_rects">' +
  1553. '</block>' +
  1554. '</category>' +
  1555. ' <block type="ai_lcd_ractanglecarvas">' +
  1556. ' <value name="POSA">' +
  1557. ' <block type="lcd_set_position">' +
  1558. ' <value name="POSX">' +
  1559. ' <shadow type="math_number">' +
  1560. ' <field name="NUM">0</field>' +
  1561. ' </shadow>' +
  1562. ' </value>' +
  1563. ' <value name="POSY">' +
  1564. ' <shadow type="math_number">' +
  1565. ' <field name="NUM">0</field>' +
  1566. ' </shadow>' +
  1567. ' </value>' +
  1568. ' </block>' +
  1569. ' </value>' +
  1570. ' <value name="POSB">' +
  1571. ' <block type="lcd_set_width_height">' +
  1572. ' <value name="WIDTH">' +
  1573. ' <shadow type="math_number">' +
  1574. ' <field name="NUM">0</field>' +
  1575. ' </shadow>' +
  1576. ' </value>' +
  1577. ' <value name="HEIGHT">' +
  1578. ' <shadow type="math_number">' +
  1579. ' <field name="NUM">0</field>' +
  1580. ' </shadow>' +
  1581. ' </value>' +
  1582. ' </block>' +
  1583. ' </value>' +
  1584. ' <value name="COLOR">' +
  1585. ' <block type="lcd_set_color">' +
  1586. ' </block>' +
  1587. ' </value>' +
  1588. ' <value name="Scale">' +
  1589. ' <shadow type="math_number">' +
  1590. ' <field name="NUM">1</field>' +
  1591. ' </shadow>' +
  1592. ' </value>' +
  1593. ' </block>' +
  1594. ' <block type="ai_lcd_drawcirclecarvas">' +
  1595. ' <value name="POSA">' +
  1596. ' <block type="lcd_set_position">' +
  1597. ' <value name="POSX">' +
  1598. ' <shadow type="math_number">' +
  1599. ' <field name="NUM">0</field>' +
  1600. ' </shadow>' +
  1601. ' </value>' +
  1602. ' <value name="POSY">' +
  1603. ' <shadow type="math_number">' +
  1604. ' <field name="NUM">0</field>' +
  1605. ' </shadow>' +
  1606. ' </value>' +
  1607. ' </block>' +
  1608. ' </value>' +
  1609. ' <value name="Scale">' +
  1610. ' <shadow type="math_number">' +
  1611. ' <field name="NUM">2</field>' +
  1612. ' </shadow>' +
  1613. ' </value>' +
  1614. ' <value name="COLOR">' +
  1615. ' <block type="lcd_set_color">' +
  1616. ' </block>' +
  1617. ' </value>' +
  1618. ' <value name="Scale_0">' +
  1619. ' <shadow type="math_number">' +
  1620. ' <field name="NUM">1</field>' +
  1621. ' </shadow>' +
  1622. ' </value>' +
  1623. ' </block>' +
  1624. ' <block type="ai_lcd_draw_cross_sign">' +
  1625. ' <value name="xy">' +
  1626. ' <block type="lcd_set_position">' +
  1627. ' <value name="POSX">' +
  1628. ' <shadow type="math_number">' +
  1629. ' <field name="NUM">2</field>' +
  1630. ' </shadow>' +
  1631. ' </value>' +
  1632. ' <value name="POSY">' +
  1633. ' <shadow type="math_number">' +
  1634. ' <field name="NUM">2</field>' +
  1635. ' </shadow>' +
  1636. ' </value>' +
  1637. ' </block>' +
  1638. ' </value>' +
  1639. ' <value name="color">' +
  1640. ' <block type="lcd_set_color">' +
  1641. ' </block>' +
  1642. ' </value>' +
  1643. ' <value name="size">' +
  1644. ' <shadow type="math_number">' +
  1645. ' <field name="NUM">0</field>' +
  1646. ' </shadow>' +
  1647. ' </value>' +
  1648. ' <value name="thickness">' +
  1649. ' <shadow type="math_number">' +
  1650. ' <field name="NUM">0</field>' +
  1651. ' </shadow>' +
  1652. ' </value>' +
  1653. ' </block>' +
  1654. ' <block type="ai_lcd_draw_arrow_sign">' +
  1655. ' <value name="xy1">' +
  1656. ' <block type="lcd_set_position">' +
  1657. ' <value name="POSX">' +
  1658. ' <shadow type="math_number">' +
  1659. ' <field name="NUM">0</field>' +
  1660. ' </shadow>' +
  1661. ' </value>' +
  1662. ' <value name="POSY">' +
  1663. ' <shadow type="math_number">' +
  1664. ' <field name="NUM">0</field>' +
  1665. ' </shadow>' +
  1666. ' </value>' +
  1667. ' </block>' +
  1668. ' </value>' +
  1669. ' <value name="xy2">' +
  1670. ' <block type="lcd_set_position">' +
  1671. ' <value name="POSX">' +
  1672. ' <shadow type="math_number">' +
  1673. ' <field name="NUM">120</field>' +
  1674. ' </shadow>' +
  1675. ' </value>' +
  1676. ' <value name="POSY">' +
  1677. ' <shadow type="math_number">' +
  1678. ' <field name="NUM">120</field>' +
  1679. ' </shadow>' +
  1680. ' </value>' +
  1681. ' </block>' +
  1682. ' </value>' +
  1683. ' <value name="color">' +
  1684. ' <block type="lcd_set_color">' +
  1685. ' </block>' +
  1686. ' </value>' +
  1687. ' <value name="thickness">' +
  1688. ' <shadow type="math_number">' +
  1689. ' <field name="NUM">2</field>' +
  1690. ' </shadow>' +
  1691. ' </value>' +
  1692. ' </block>' +
  1693. '</category>' +
  1694. */
  1695. /*
  1696. _ ___ ____ _
  1697. / \ |_ _| / ___| _ __ ___ __ _| | _____ _ __
  1698. / _ \ | | \___ \| '_ \ / _ \/ _` | |/ / _ \ '__|
  1699. / ___ \ _ | | _ ___) | |_) | __/ (_| | < __/ |
  1700. /_/ \_(_)___(_) |____/| .__/ \___|\__,_|_|\_\___|_|
  1701. |_|
  1702. */
  1703. '<category id="catAISpeaker" name="Speaker" colour="#5f7fc1">' + '<block type="ai_audio_init_speaker"></block>' + '<block type="ai_audio_play_song_speaker">' + ' <value name="path">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/preset/songs/luckystar.wav</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_audio_play_state_speaker"></block>' + '<block type="ai_audio_play_finish_speaker"></block>' + '<block type="ai_audio_set_speaker">' + ' <value name="Num">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' +
  1704. /*
  1705. _ ___ ____
  1706. / \ |_ _| / ___|__ _ _ __ ___ ___ _ __ __ _
  1707. / _ \ | | | | / _` | '_ ` _ \ / _ \ '__/ _` |
  1708. / ___ \ | | | |__| (_| | | | | | | __/ | | (_| |
  1709. /_/ \_\___| \____\__,_|_| |_| |_|\___|_| \__,_|
  1710. */
  1711. '<category id="catCamera" name="Camera" colour="#60c1bb">' + '<block type="ai_camera_init"></block>' + '<block type="ai_camera_windows">' + '</block>' + '<block type="ai_camera_snapshot"></block>' + '<block type="ai_camera_lens_corr">' + ' <value name="lens_corr">' + ' <block type="ai_camera_snapshot"></block>' + ' </value>' + '</block>' + '<block type="ai_camera_image_property_change"></block>' + // '<block type="ai_camera_vflip"></block>' +
  1712. // '<block type="ai_camera_hmirror"></block>' +
  1713. // '<block type="ai_camera_auto_whitebal">' +
  1714. // '</block>' +
  1715. // '<block type="ai_camera_auto_gain"></block>' +
  1716. // '<block type="ai_camera_auto_exposure"></block>' +
  1717. '<block type="ai_camera_bcs_operation">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_video_record_setup">' + ' <value name="save_path">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/user/record.avi</field>' + ' </shadow>' + ' </value>' + ' <value name="w">' + ' <shadow type="math_number">' + ' <field name="NUM">320</field>' + ' </shadow>' + ' </value>' + ' <value name="h">' + ' <shadow type="math_number">' + ' <field name="NUM">240</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_video_get"></block>' + '<block type="ai_video_stop"></block>' + '</category>' +
  1718. /*
  1719. _ ___ __ __ _ _
  1720. / \ |_ _| | \/ (_) ___ _ __ ___ _ __ | |__ ___ _ __ ___
  1721. / _ \ | | | |\/| | |/ __| '__/ _ \| '_ \| '_ \ / _ \| '_ \ / _ \
  1722. / ___ \ | | | | | | | (__| | | (_) | |_) | | | | (_) | | | | __/
  1723. /_/ \_\___| |_| |_|_|\___|_| \___/| .__/|_| |_|\___/|_| |_|\___|
  1724. |_|
  1725. */
  1726. '<category id="catMicrophone" name="Microphone" colour="#5fcd8e">' + '<block type="ai_mphone_init"></block>' + '<block type="mphone_audio_spectrum_init"></block>' + '<block type="ai_mphone_read_sound_sensitivity"></block>' + '</category>' +
  1727. /*
  1728. _ ___ __ ___ _
  1729. / \ |_ _| \ \ / (_)___(_) ___ _ __
  1730. / _ \ | | \ \ / /| / __| |/ _ \| '_ \
  1731. / ___ \ | | \ V / | \__ \ | (_) | | | |
  1732. /_/ \_\___| \_/ |_|___/_|\___/|_| |_|
  1733. */
  1734. '<category id="catVision" name="Vision" colour="#f2a247">' + '<block type="ai_img_save">' + ' <value name="save_path">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/user/saved.jpg</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_lcd_invert_color"></block>' + '<block type="ai_lcd_resizecanvas">' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_lcd_color_scheme"></block>' + //'<block type="ai_lcd_ai_pix"></block>' +
  1735. '<block type="ai_lcd_img_cut">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_vision_get_statistics">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="bins">' + ' <shadow type="math_number">' + ' <field name="NUM">8</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_get_histogram">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_vision_get_histogram_percentile">' + ' <value name="perc">' + ' <shadow type="math_number">' + ' <field name="NUM">0.2</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_get_histogram_percentile_detail">' + ' <value name="perc">' + ' <shadow type="math_number">' + ' <field name="NUM">0.2</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_lab_rgb_conversion">' + ' <value name="color_tuple">' + '<shadow type="tuple_create_with_items_insert"></shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_rgb_grayscale_conversion">' + ' <value name="color_tuple">' + ' <shadow type="math_number">' + ' <field name="NUM">255</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_color_analyze">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_vision_find_blobs">' + ' <value name="color_threshold">' + '<shadow type="tuple_create_with_items_insert"></shadow>' + ' </value>' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="area_threshold">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + ' <value name="pixels_threshold">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + ' <value name="margin">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_get_blobs"></block>' + '<block type="ai_vision_find_qrcode"></block>' + '<block type="ai_vision_qrcode_get_info"></block>' + '<block type="ai_vision_find_apriltag"></block>' + '<block type="ai_vision_apriltag_get_info"></block>' + '<block type="ai_vision_find_datamatrices"></block>' + '<block type="ai_vision_datamatrices_get_info"></block>' + '<block type="ai_vision_find_barcodes"></block>' + '<block type="ai_vision_barcodes_get_info"></block>' + '<block type="ai_vision_find_circles">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="threshold">' + ' <shadow type="math_number">' + ' <field name="NUM">2000</field>' + ' </shadow>' + ' </value>' + ' <value name="x_margin">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + ' <value name="y_margin">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + ' <value name="r_margin">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + ' <value name="r_min">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + ' </shadow>' + ' </value>' + ' <value name="r_max">' + ' <shadow type="math_number">' + ' <field name="NUM">100</field>' + ' </shadow>' + ' </value>' + ' <value name="r_step">' + ' <shadow type="math_number">' + ' <field name="NUM">2</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_get_circles">' + '</block>' + '<block type="ai_vision_find_rects">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_vision_get_rects">' + '</block>' + '<block type="ai_vision_find_lines">' + ' <value name="xy">' + ' <block type="ai_lcd_XY_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="wh">' + ' <block type="ai_lcd_WH_vision">' + ' <value name="A">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' <value name="B">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' </value>' + ' <value name="threshold">' + ' <shadow type="math_number">' + ' <field name="NUM">1000</field>' + ' </shadow>' + ' </value>' + ' <value name="theta_margin">' + ' <shadow type="math_number">' + ' <field name="NUM">25</field>' + ' </shadow>' + ' </value>' + ' <value name="rho_margin">' + ' <shadow type="math_number">' + ' <field name="NUM">25</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_vision_get_lines">' + '</block>' + '</category>' +
  1736. /*
  1737. _ ___ __ ___ _
  1738. / \ |_ _| \ \ / (_) __| | ___ ___
  1739. / _ \ | | \ \ / /| |/ _` |/ _ \/ _ \
  1740. / ___ \ | | \ V / | | (_| | __/ (_) |
  1741. /_/ \_\___| \_/ |_|\__,_|\___|\___/
  1742. */
  1743. '<category id="catIV" name="Video" colour="#4d9994">' + '<block type="ai_video_set">' + ' <value name="path">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/user/record.avi</field>' + ' </shadow>' + ' </value>' + '</block>' + // '<block type="ai_video_num"></block>' +
  1744. '<block type="ai_video_status"></block>' + '<block type="ai_video_stop_play"></block>' + '</category>' +
  1745. /*
  1746. _ ___ _ _ _
  1747. / \ |_ _| / \ _ _ __| (_) ___
  1748. / _ \ | | / _ \| | | |/ _` | |/ _ \
  1749. / ___ \ | | / ___ \ |_| | (_| | | (_) |
  1750. /_/ \_\___| /_/ \_\__,_|\__,_|_|\___/
  1751. */
  1752. '<category id="catAudio" name="Audio" colour="#603ea0">' + '<block type="ai_audio_init"></block>' + '<block type="ai_audio_play_song">' + ' <value name="path">' + ' <shadow type="text">' + ' <field name="TEXT">/sd/preset/songs/luckystar.wav</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_audio_play_state"></block>' + '<block type="ai_audio_play_finish"></block>' + '<block type="ai_audio_set">' + ' <value name="Num">' + ' <shadow type="math_number">' + ' <field name="NUM">10</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_audio_voice_recognition_setup"></block>' + // '<block type="ai_audio_voice_recognition_get_status"></block>' +
  1753. '<block type="ai_audio_voice_recognition_start_record"></block>' + '<block type="ai_audio_voice_recognition_start_recognizing">' + ' <value name="frm_num_set">' + ' <shadow type="lists_create_with">' + ' <value name="ADD0">' + ' <shadow type="lists_create_with">' + ' <value name="ADD0">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' <value name="ADD1">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' <value name="ADD2">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' </shadow>' + ' </value>' + ' <value name="ADD1">' + ' <shadow type="lists_create_with">' + ' <value name="ADD0">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' <value name="ADD1">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' <value name="ADD2">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' </shadow>' + ' </value>' + ' <value name="ADD2">' + ' <shadow type="lists_create_with">' + ' <value name="ADD0">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' <value name="ADD1">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' <value name="ADD2">' + ' <shadow type="math_number"><field name="NUM">0</field></shadow>' + ' </value>' + ' </shadow>' + ' </value>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_audio_voice_recognition_get_any_result"></block>' + '<block type="ai_audio_voice_recognition_get_result"></block>' + '</category>' +
  1754. /*
  1755. _ ___ _____ _ ____
  1756. / \ |_ _| |_ _|____ _| |_ | _ \ _ __ ___ ___ ___ ___ ___
  1757. / _ \ | | | |/ _ \ \/ / __| | |_) | '__/ _ \ / __/ _ \/ __/ __|
  1758. / ___ \ _ | | _ | | __/> <| |_ | __/| | | (_) | (_| __/\__ \__ \
  1759. /_/ \_(_)___(_) |_|\___/_/\_\\__| |_| |_| \___/ \___\___||___/___/
  1760. */
  1761. // '<category id="catTextProcess" name="Text Process" colour="#3e55a0">' +
  1762. // '<block type="ai_system_create">' +
  1763. // ' <value name="PATH">' +
  1764. // ' <shadow type="text">' +
  1765. // ' <field name="TEXT">/sd/cocorobo.txt</field>' +
  1766. // ' </shadow>' +
  1767. // ' </value>' +
  1768. // '</block>' +
  1769. // '<block type="ai_system_write">' +
  1770. // ' <value name="PATH">' +
  1771. // ' <shadow type="text">' +
  1772. // ' <field name="TEXT">cocorobo.txt</field>' +
  1773. // ' </shadow>' +
  1774. // ' </value>' +
  1775. // ' <value name="WPATH">' +
  1776. // ' <shadow type="text">' +
  1777. // ' <field name="TEXT"></field>' +
  1778. // ' </shadow>' +
  1779. // ' </value>' +
  1780. // '</block>' +
  1781. // '<block type="ai_system_input">' +
  1782. // ' <value name="PATH">' +
  1783. // ' <shadow type="text">' +
  1784. // ' <field name="TEXT">/sd/cocorobo.txt</field>' +
  1785. // ' </shadow>' +
  1786. // ' </value>' +
  1787. // '</block>' +
  1788. // '</category>' +
  1789. /*
  1790. _ ___ __ __ _ _
  1791. / \ |_ _| | \/ | ___ __| | ___| |___
  1792. / _ \ | | | |\/| |/ _ \ / _` |/ _ \ / __|
  1793. / ___ \ | | | | | | (_) | (_| | __/ \__ \
  1794. /_/ \_\___| |_| |_|\___/ \__,_|\___|_|___/
  1795. */
  1796. '<category id="catModels" name="Models" colour="#ee783a">' + //模型
  1797. '<block type="ai_model_allinit"></block>' + '<block type="ai_model_index_mnist"></block>' + '<block type="ai_model_look"></block>' + '<block type="ai_model_get"></block>' + '<block type="ai_model_face"></block>' + '<block type="ai_model_xy"></block>' + '<block type="ai_model_customized_init_setup">' + ' <value name="class_input">' + ' <block type="lists_create_with">' + ' <value name="ADD0">' + ' <block type="text"><field name="TEXT">Object 1 Name</field></block>' + ' </value>' + ' <value name="ADD1">' + ' <block type="text"><field name="TEXT">Object 2 Name</field></block>' + ' </value>' + ' <value name="ADD2">' + ' <block type="text"><field name="TEXT">Object 3 Name</field></block>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_model_customized_if_got"></block>' + '<block type="ai_model_customized_get_result">' + '</block>' + '</category>' +
  1798. /*
  1799. _ ___ __ ___ _____ _
  1800. / \ |_ _| \ \ / (_) ___(_)
  1801. / _ \ | | \ \ /\ / /| | |_ | |
  1802. / ___ \ _ | | _ \ V V / | | _| | |
  1803. /_/ \_(_)___(_) \_/\_/ |_|_| |_|
  1804. */
  1805. '<category id="catAIWifi" name="WiFi" colour="#23a9ea">' + '</category>' +
  1806. /*
  1807. _ ___ ____ _
  1808. / \ |_ _| / ___| _ _ ___| |_ ___ _ __ ___
  1809. / _ \ | | \___ \| | | / __| __/ _ \ '_ ` _ \
  1810. / ___ \ | | ___) | |_| \__ \ || __/ | | | | |
  1811. /_/ \_\___| |____/ \__, |___/\__\___|_| |_| |_|
  1812. |___/
  1813. */
  1814. /*
  1815. '<category id="catSystem" name="System" colour="#1e3283">' +
  1816. '</category>' +
  1817. */
  1818. '</category>',
  1819. //'Screen':"",
  1820. // 'Turtles': '<category name="Turtles" colour="#5B5FA6">' +
  1821. // '<block type="turtle_create"></block>' +
  1822. // '<block type="turtle_forward">' +
  1823. // '<value name="DISTANCE">' +
  1824. // '<block type="math_number">' +
  1825. // '<field name="NUM">50</field>' +
  1826. // '</block>' +
  1827. // '</value>' +
  1828. // '</block>' +
  1829. // '<block type="turtle_backward">' +
  1830. // '<value name="DISTANCE">' +
  1831. // '<block type="math_number">' +
  1832. // '<field name="NUM">50</field>' +
  1833. // '</block>' +
  1834. // '</value>' +
  1835. // '</block>' +
  1836. // '<block type="turtle_left">' +
  1837. // '<value name="ANGLE">' +
  1838. // '<block type="math_number">' +
  1839. // '<field name="NUM">50</field>' +
  1840. // '</block>' +
  1841. // '</value>' +
  1842. // '</block>' +
  1843. // '<block type="turtle_right">' +
  1844. // '<value name="ANGLE">' +
  1845. // '<block type="math_number">' +
  1846. // '<field name="NUM">50</field>' +
  1847. // '</block>' +
  1848. // '</value>' +
  1849. // '</block>' +
  1850. // '<block type="turtle_color">' +
  1851. // '<value name="COLOR">' +
  1852. // '<block type="colour_picker"></block>' +
  1853. // '</value>' +
  1854. // '</block>' +
  1855. // '<block type="turtle_shape"></block>' +
  1856. // '<block type="turtle_pen"></block>' +
  1857. // '<block type="turtle_circle">' +
  1858. // '<value name="RADIUS">' +
  1859. // '<block type="math_number">' +
  1860. // '<field name="NUM">50</field>' +
  1861. // '</block>' +
  1862. // '</value>' +
  1863. // '</block>' +
  1864. // '<block type="turtle_goto">' +
  1865. // '<value name="X">' +
  1866. // '<block type="math_number">' +
  1867. // '<field name="NUM">0</field>' +
  1868. // '</block>' +
  1869. // '</value>' +
  1870. // '<value name="Y">' +
  1871. // '<block type="math_number">' +
  1872. // '<field name="NUM">0</field>' +
  1873. // '</block>' +
  1874. // '</value>' +
  1875. // '</block>' +
  1876. // //'<block type="attribute_access">'+
  1877. // //'<value name="NAME">'+
  1878. // '<block type="turtle_pos"></block>' +
  1879. // //'</value>'+
  1880. // //'</block>'+
  1881. // '<block type="turtle_stamp"></block>' +
  1882. // '<block type="turtle_begin_fill"></block>' +
  1883. // '<block type="turtle_end_fill"></block>' +
  1884. // '<block type="turtle_speed">' +
  1885. // '<value name="SPEED">' +
  1886. // '<block type="math_number">' +
  1887. // '<field name="NUM">50</field>' +
  1888. // '</block>' +
  1889. // '</value>' +
  1890. // '</block>' +
  1891. // '</category>',
  1892. 'Values': '<category id="catText" name="Text" colour="#33cc99">' + '<block type="esp32_main_controller_text_print">' + '<value name="TEXT">' + '<shadow type="esp32_main_controller_text">' + '<field name="TEXT"></field>' + '</shadow>' + ' </value>' + '</block>' + ' <block type="text"><field name="TEXT"></field></block>' + // '<block type="esp32_main_controller_text"></block>' +
  1893. '<block type="text_join"><mutation items="1"></mutation></block>' + ' <block type="text_join"></block>' + ' <block type="text_format">' + ' <value name="FORMAT">' + ' <shadow type="text"><field name="TEXT">Value: %.2f</field></shadow>' + ' </value>' + ' <value name="CONTENT">' + ' <block type="tuple_create_with_items_insert">' + ' <mutation items="1"></mutation>' + ' <value name="ADD0">' + ' <block type="math_number">' + ' <field name="NUM">3.1415926</field>' + ' </block>' + ' </value>' + ' </block>' + ' </value>' + ' </block>' + ' <block type="text_format2">' + ' <value name="FORMAT">' + ' <shadow type="text"><field name="TEXT">Value: {:.3}</field></shadow>' + ' </value>' + ' <value name="CONTENT">' + ' <block type="tuple_create_with_items_insert">' + ' <mutation items="1"></mutation>' + ' <value name="ADD0">' + ' <block type="math_number">' + ' <field name="NUM">3.1415926</field>' + ' </block>' + ' </value>' + '</block>' + '</value>' + ' </block>' + '<block type="CocoRobo_text_ESC">' + '</block>' + '<block type="text_append_text">' + '<value name="text_abc"><shadow type="text"><field name="TEXT">abc</field></shadow></value>' + '<value name="append_text"><shadow type="text"><field name="TEXT">def</field></shadow></value>' + '</block>' + '<block type="text_is_number">' + '<value name="TEXT">' + ' <shadow type="text">' + '<field name="TEXT"></field>' + '</shadow>' + '</value>' + '</block>' + '<block type="text_length">' + '<value name="VALUE">' + '<shadow type="text">' + ' <field name="TEXT"></field>' + '</shadow>' + '</value>' + '</block>' + '<block type="text_isEmpty">' + '<value name="VALUE">' + '<shadow type="text">' + ' <field name="TEXT"></field>' + '</shadow>' + '</value>' + '</block>' + '<block type="text_indexOf">' + '<value name="VALUE">' + ' <shadow type="text">' + '<field name="TEXT">abc</field>' + '</shadow>' + '</value>' + '<value name="FIND">' + ' <shadow type="text">' + '<field name="TEXT">b</field>' + ' </shadow>' + '</value>' + '</block>' + '<block type="text_charAt">' + '<value name="VALUE">' + '<shadow type="text">' + '<field name="TEXT">abc</field>' + ' </shadow>' + '</value>' + ' </block>' + ' <block type="text_getSubstring">' + '<value name="STRING">' + ' <shadow type="text">' + '<field name="TEXT">abc</field>' + ' </shadow>' + '</value>' + ' </block>' + ' <block type="text_changeCase">' + '<value name="TEXT">' + ' <shadow type="text">' + ' <field name="TEXT"></field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="text_trim">' + ' <value name="TEXT">' + ' <shadow type="text">' + ' <field name="TEXT"></field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="text_to_byte">' + ' <value name="TEXT">' + ' <shadow type="text">' + ' <field name="TEXT">abc</field>' + ' </shadow>' + ' </value>' + ' </block>' + ' <block type="CocoRobo_bytes_decode">' + ' <value name="bytes_decode"></value>' + '</block>' + '<block type="CocoRobo_ujson_dumps">' + ' <value name="data"><shadow type="text_dict"><field name="TEXT">"Age":8</field></shadow></value>' + '</block>' + '<block type="CocoRobo_ujson_loads">' + '<value name="data"><shadow type="text"><field name="TEXT">{"Age":8}</field></shadow></value>' + '</block>' + '</category>',
  1894. 'ExtendedFunctions': '<category id="ExtendedFunction" name="Extended Function" colour="#2fc67b">' + // '<category id="catServo" name="Servo" colour="#3c62e2">' +
  1895. // '</category>' +
  1896. '<category id="EFLEDLS" name="LED Light Screen" colour="#e8795b">' + '<block type="ai_led_matrix_setup"></block>' + '<block type="ai_led_matrix_xy">' + ' <value name="x">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="y">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_led_matrix_wh">' + ' <value name="w">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + ' <value name="h">' + ' <shadow type="math_number">' + ' <field name="NUM">1</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="ai_led_matrix_color_picker"></block>' + '<block type="ai_led_matrix_draw_pixel">' + ' <value name="color">' + ' <block type="ai_led_matrix_color_picker">' + ' </block>' + ' </value>' + ' <value name="coordinate">' + ' <block type="ai_led_matrix_xy">' + ' <value name="x">' + ' <block type="math_number">' + ' <field name="NUM">1</field>' + ' </block>' + ' </value>' + ' <value name="y">' + ' <block type="math_number">' + ' <field name="NUM">1</field>' + ' </block>' + ' </value>' + ' </block>' + ' </value>' + '</block>' + '<block type="ai_led_matrix_show_above"></block>' + '</category>' + '<category id="EFMotor" name="Motor" colour="#5bb2d6">' + '<block type="ai_motor_setup"></block>' + '<block type="ai_motor_run">' + ' <value name="speed">' + ' <shadow type="math_number">' + ' <field name="NUM">150</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' + '<category id="EFSG" name="Steering Gear" colour="#386dc8">' + '<block type="extension_servo_setup_on_ai"></block>' + '<block type="extension_servo_write_on_ai">' + ' <value name="degree">' + ' <shadow type="math_number">' + ' <field name="NUM">90</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' +
  1897. /*'<category id="catLEDStrip" name="LED Strip" colour="#3dade2">' +
  1898. '</category>' +*/
  1899. '<category id="EFGH" name="Game Handle" colour="#183895">' + '<block type="x_ai_read_gamepad_button_pressed"></block>' + '<block type="x_ai_read_gamepad_button_released"></block>' + '<block type="x_ai_read_gamepad_button_x-r"></block>' + '<block type="x_ai_read_gamepad_joystick_check"></block>' + '<block type="x_ai_read_gamepad_joystick"></block>' + '</category>' + '<category id="EFNI" name="NB-IoT" colour="#3c7683">' + '<block type="esp32_nbiot_setup"></block>' + '<block type="esp32_nbiot_get_power_status"></block>' + '<block type="esp32_nbiot_get_network_status"></block>' + '<block type="esp32_nbiot_get_network_ip"></block>' + '<block type="iot_service_nbiot_cococloud">' + ' <value name="ADD0">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_nbiot_onenet_init">' + ' <value name="product_id">' + ' <shadow type="text">' + ' <field name="TEXT">320012</field>' + ' </shadow>' + ' </value>' + ' <value name="device_id">' + ' <shadow type="text">' + ' <field name="TEXT">585407311</field>' + ' </shadow>' + ' </value>' + ' <value name="device_apikey">' + ' <shadow type="text">' + ' <field name="TEXT">jiv4F3zcLS8X=i9=Fyry93wCt6s=</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_nbiot_onenet_connection_status"></block>' + '<block type="iot_service_nbiot_onenet">' + ' <value name="ADD0">' + ' <shadow type="math_number">' + ' <field name="NUM">0</field>' + ' </shadow>' + ' </value>' + '</block>' + '<block type="esp32_nbiot_onenet_read_value"></block>' + '<block type="iot_service_nbiot_onenet_read">' + ' <value name="message">' + ' <shadow type="text">' + ' <field name="TEXT">hello</field>' + ' </shadow>' + ' </value>' + '</block>' + '</category>' + '<category id="EFBluetooth" name="Bluetooth" colour="#629978">' + '</category>' + '</category>',
  1900. 'Third_party_Sensor': '<category id="Third_party_Sensor" name="Third_party_Sensor" colour="#7e3cca">' + '<category id="Ultrasonic" name="LED Light Screen" colour="#e55ce6">' + '</category>' + '<category id="PS2_Gamepad" name="LED Light Screen" colour="#9f5fd6">' + '</category>' + '</category>' // 'Tuples': '<category name="Tuples" colour="40">' +
  1901. // '<block type="tuple_create"></block>' +
  1902. // '</category>',
  1903. // 'Lists': '<category name="Lists" colour="#40bfe4">' +
  1904. // //'<block type="lists_create"></block>'+
  1905. // '<block type="lists_create_with">' +
  1906. // '<value name="ADD0">' +
  1907. // '<block type="math_number"><field name="NUM">0</field></block>' +
  1908. // '</value>' +
  1909. // '<value name="ADD1">' +
  1910. // '<block type="math_number"><field name="NUM">0</field></block>' +
  1911. // '</value>' +
  1912. // '<value name="ADD2">' +
  1913. // '<block type="math_number"><field name="NUM">0</field></block>' +
  1914. // '</value>' +
  1915. // '</block>' +
  1916. // // '<block type="lists_create_with"></block>'+
  1917. // '<block type="lists_create_empty"></block>' +
  1918. // '<block type="lists_append"></block>' +
  1919. // '<block type="lists_length"></block>' +
  1920. // '<block type="lists_index">' +
  1921. // '<value name="ITEM">' +
  1922. // '<shadow type="math_number">' +
  1923. // '<field name="NUM">0</field>' +
  1924. // '</shadow>' +
  1925. // '</value>' +
  1926. // '</block>' +
  1927. // '</category>',
  1928. // 'Dictionaries': '<category name="Dictionaries" colour="0">' +
  1929. // '<block type="dicts_create_with"></block>' +
  1930. // '<block type="dict_get_literal"></block>' +
  1931. // //'<block type="dict_keys"></block>'+
  1932. // '</category>',
  1933. // 'Data - Weather': '<category name="Data - Weather" colour="70">' +
  1934. // '<block type="weather_temperature_get"></block>' +
  1935. // '<block type="weather_report"></block>' +
  1936. // // '<block type="weather_forecasts"></block>'+
  1937. // // '<block type="weather_report_forecasts"></block>'+
  1938. // // '<block type="weather_all_forecasts"></block>'+
  1939. // // '<block type="weather_highs_lows"></block>'+
  1940. // '</category>',
  1941. // 'Data - Stocks': '<category name="Data - Stock" colour="65">' +
  1942. // '<block type="stocks_current"></block>' +
  1943. // '<block type="stocks_past"></block>' +
  1944. // '</category>',
  1945. // 'Data - Earthquakes': '<category name="Data - Earthquakes" colour="60">' +
  1946. // '<block type="earthquake_get"></block>' +
  1947. // '<block type="earthquake_both"></block>' +
  1948. // '<block type="earthquake_all"></block>' +
  1949. // '</category>',
  1950. // 'Data - Crime': '<category name="Data - Crime" colour="55">' +
  1951. // '<block type="crime_state"></block>' +
  1952. // '<block type="crime_year"></block>' +
  1953. // '<block type="crime_all"></block>' +
  1954. // '</category>',
  1955. // 'Data - Books': '<category name="Data - Books" colour="50">' +
  1956. // '<block type="books_get"></block>' +
  1957. // '</category>',
  1958. // 'Data - Parking': '<category name="Data - Parking" colour="45">' +
  1959. // '<block type="datetime_day"></block>' +
  1960. // '<block type="datetime_time"></block>' +
  1961. // '<block type="logic_compare">' +
  1962. // '<field name="OP">EQ</field>' +
  1963. // '<value name="A">' +
  1964. // '<block type="datetime_time">' +
  1965. // '<mutation isNow="1"></mutation>' +
  1966. // '<field name="HOUR">1</field>' +
  1967. // '<field name="MINUTE">00</field>' +
  1968. // '<field name="MERIDIAN">PM</field>' +
  1969. // '</block>' +
  1970. // '</value>' +
  1971. // '</block>' +
  1972. // '<block type="logic_compare">' +
  1973. // '<field name="OP">EQ</field>' +
  1974. // '<value name="A">' +
  1975. // '<block type="datetime_day">' +
  1976. // '<field name="DAY">Monday</field>' +
  1977. // '</block>' +
  1978. // '</value>' +
  1979. // '</block>' +
  1980. // //'<block type="datetime_check_day"></block>'+
  1981. // //'<block type="datetime_check_time"></block>'+
  1982. // '</category>',
  1983. // 'Separator': '<sep></sep>',
  1984. // //add new session and block for test
  1985. // 'Request': '<category name="Request" colour="#ff8b2c">' +
  1986. // '<block type="request_import"></block>' +
  1987. // '<block type="request_post"></block>' +
  1988. // '</category>',
  1989. // 'Camera': '<category name="Camera" colour="#ff6381">' +
  1990. // '<block type="camera_import"></block>' +
  1991. // '<block type="camera_use"></block>' +
  1992. // '<block type="camera_enable"></block>' +
  1993. // '<block type="camera_set_bounding"></block>' +
  1994. // '</category>',
  1995. // 'VisionKit': '<category name="Vision Kit" colour="230">' +
  1996. // // '<block type="voicekit_setup"></block>'+
  1997. // // '<block type="voicekit_demo"></block>'+
  1998. // // '<block type="visionkit_setup"></block>'+
  1999. // // '<block type="visionkit_demo"></block>'+
  2000. // // '<block type="visionkit_import"></block>'+
  2001. // // '<block type="visionkit_import_annotator"></block>'+
  2002. // // '<block type="visionkit_import_models"></block>'+
  2003. // // '<block type="visionkit_import_inference"></block>'+
  2004. // // '<block type="visionkit_cameraInference"></block>'+
  2005. // // '<block type="visionkit_runInference"></block>'+
  2006. // // '<block type="visionkit_GetInference"></block>'+
  2007. // // '<block type="visionkit_faceDetection_operation"></block>'+
  2008. // // '<block type="visionkit_model_get"></block>'+
  2009. // // '<block type="visionkit_Use_Annotator"></block>'+
  2010. // // '<block type="visionkit_Use_Annotator_output"></block>'+
  2011. // // '<block type="visionkit_Annotator_operation"></block>'+
  2012. // // '<block type="visionkit_Annotator_Bounding"></block>'+
  2013. // // '<block type="visionkit_myAssistant"></block>'+
  2014. // '<block type="visionkit_import_aiy"></block>' +
  2015. // '<block type="visionkit_avg_joy_score"></block>' +
  2016. // '<block type="visionkit_annotator_camera"></block>' +
  2017. // '<block type="visionkit_transform_boundingBox"></block>' +
  2018. // '<block type="visionkit_CameraInference"></block>' +
  2019. // '<block type="visionkit_avg_joy_score_num"></block>' +
  2020. // '<block type="visionkit_face"></block>' +
  2021. // '</category>',
  2022. // 'VoiceKit': '<category name="Voice Kit" colour="#3382f5">' +
  2023. // // '<block type="voicekit_from"></block>'+
  2024. // // '<block type="voicekit_import"></block>'+
  2025. // // '<block type="voicekit_import_tts"></block>'+
  2026. // // '<block type="voicekit_set_credential"></block>'+
  2027. // // '<block type="voicekit_get_credential"></block>'+
  2028. // // '<block type="voicekit_import_assistant"></block>'+
  2029. // // '<block type="voicekit_assistant_preNext"></block>'+
  2030. // // '<block type="voicekit_assistant_output"></block>'+
  2031. // // '<block type="voicekit_EventType_import"></block>'+
  2032. // // '<block type="voicekit_EventType_assistant"></block>'+
  2033. // // '<block type="voicekit_event_of"></block>'+
  2034. // // '<block type="voicekit_event_args"></block>'+
  2035. // // '<block type="voicekit_event_args_of"></block>'+
  2036. // // '<block type="voicekit_run_task"></block>'+
  2037. // // '<block type="voicekit_process_event"></block>'+
  2038. // // '<block type="voicekit_assistant_start_conversation"></block>'+
  2039. // // '<block type="voicekit_send_instructions"></block>'+
  2040. // // '<block type="voicekit_on_button_pressed"></block>'+
  2041. // '<block type="voicekit_import_aiy"></block>' +
  2042. // '<block type="voicekit_init"></block>' +
  2043. // '<block type="voicekit_task"></block>' +
  2044. // '<block type="voicekit_can_start"></block>' +
  2045. // '<block type="voicekit_asssistant"></block>' +
  2046. // '<block type="voicekit_start_thread"></block>' +
  2047. // '<block type="voicekit_runTask"></block>' +
  2048. // '<block type="voicekit_tts_say"></block>' +
  2049. // '<block type="voicekit_logging_config"></block>' +
  2050. // '<block type="voicekit_myassistant_start"></block>' +
  2051. // '<block type="voicekit_process_event"></block>' +
  2052. // '<block type="voicekit_process_eventType"></block>' +
  2053. // '<block type="voicekit_EventType_select"></block>' +
  2054. // '<block type="voicekit_can_start_conversation_self"></block>' +
  2055. // '<block type="voicekit_can_start_conversation"></block>' +
  2056. // '<block type="voicekit_assistant_conversation"></block>' +
  2057. // '<block type="voicekit_event_args"></block>' +
  2058. // '<block type="voicekit_event_args_of"></block>' +
  2059. // '</category>',
  2060. // 'AIY Board': '<category name="AIY Board" colour="#6844d1">' +
  2061. // '<block type="AIYBoard_from"></block>' +
  2062. // '<block type="AIYBoard_import"></block>' +
  2063. // '<block type="AIYBoard_Board"></block>' +
  2064. // // '<block type="AIYBoard_LED_state"></block>'+
  2065. // // '<block type="AIYBoard_LED_status"></block>'+
  2066. // '<block type="AIYBoard_LED_setting"></block>' +
  2067. // '<block type="AIYBoard_board"></block>' +
  2068. // '<block type="AIYBoard_button"></block>' +
  2069. // '<block type="AIYBoard_button_press"></block>' +
  2070. // '<block type="AIYBoard_board_led_status"></block>' +
  2071. // '<block type="AIYBoard_board_led_state"></block>' +
  2072. // '</category>',
  2073. // 'System': '<category name="System" colour="#6cb7b3">' +
  2074. // '<block type="System_import"></block>' +
  2075. // '<block type="System_exit"></block>' +
  2076. // '<block type="Platform_import"></block>' +
  2077. // '<block type="Thread_import"></block>' +
  2078. // '<block type="Thread_start_output"></block>' +
  2079. // '<block type="Thread_start_preNext"></block>' +
  2080. // '<block type="Thread_set_target"></block>' +
  2081. // '<block type="System_dot"></block>' +
  2082. // '</category>',
  2083. };
  2084. /**
  2085. * Creates an updated representation of the Toolboxes XML as currently specified in the
  2086. * model, using whatever modules have been added or removed. This method can either set it
  2087. * or just retrieve it for future use.
  2088. *
  2089. * @param {Boolean} only_set - Whether to return the XML string or to actually set the XML. False means that it will not update the toolbox!
  2090. * @returns {String?} Possibly returns the XML of the toolbox as a string.
  2091. */
  2092. BlockPyEditor.prototype.updateToolbox = function (only_set) {
  2093. // let blocklyXml = Blockly.Xml.textToDom(BlockPyEditor.CATEGORY_MAP)
  2094. // var categoryNodes = blocklyXml.getElementsByTagName('category');
  2095. // for (var i = 0, cat; cat = categoryNodes[i]; i++) {
  2096. // var catId = cat.getAttribute('id');
  2097. // var catText = Ardublockly.getLocalStr(catId);
  2098. // if (catText) {
  2099. // cat.setAttribute('name', catText);
  2100. // }
  2101. // }
  2102. var xml = '<xml id="toolbox" style="display: none">';
  2103. var modules = this.main.model.assignment.modules();
  2104. var started_misc = false,
  2105. started_values = false,
  2106. started_data = false;
  2107. for (var i = 0, length = modules.length; i < length; i = i + 1) {
  2108. var module = modules[i];
  2109. if (!started_misc && ['Calculation', 'Output', 'Python'].indexOf(module) != -1) {
  2110. started_misc = true; // xml += BlockPyEditor.CATEGORY_MAP['Separator'];
  2111. }
  2112. if (!started_values && ['Values', 'Lists', 'Dictionaries'].indexOf(module) != -1) {
  2113. started_values = true; // xml += BlockPyEditor.CATEGORY_MAP['Separator'];
  2114. }
  2115. if (!started_data && module.slice(0, 6) == 'Data -') {
  2116. started_data = true; // xml += BlockPyEditor.CATEGORY_MAP['Separator'];
  2117. }
  2118. if (typeof module == 'string') {
  2119. xml += BlockPyEditor.CATEGORY_MAP[module];
  2120. } else {
  2121. var category = '<category name="' + module.name + '" colour="' + module.color + '">';
  2122. for (var j = 0; category_length = module.blocks.length; j = j + 1) {
  2123. var block = module.blocks[j];
  2124. category += '<block type="' + block + '"></block>';
  2125. }
  2126. category += '</category>';
  2127. } //'<sep></sep>'+
  2128. }
  2129. xml += '</xml>';
  2130. Ardublockly.initLanguage();
  2131. Ardublockly.updateToolboxLanguage(xml);
  2132. xml = Ardublockly.xmlTree;
  2133. if (only_set && !this.main.model.settings.read_only()) {
  2134. this.blockly.updateToolbox(xml);
  2135. this.blockly.resize();
  2136. } else {
  2137. return xml;
  2138. }
  2139. };
  2140. BlockPyEditor.prototype.DOCTYPE = '<?xml version="1.0" standalone="no"?>' + '<' + '!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
  2141. BlockPyEditor.prototype.cssData = null;
  2142. BlockPyEditor.prototype.loadCss = function () {
  2143. if (this.cssData == null) {
  2144. var txt = '.blocklyDraggable {}\n';
  2145. txt += Blockly.Css.CONTENT.join('\n');
  2146. if (Blockly.FieldDate) {
  2147. txt += Blockly.FieldDate.CSS.join('\n');
  2148. } // Strip off any trailing slash (either Unix or Windows).
  2149. this.cssData = txt.replace(/<<<PATH>>>/g, Blockly.Css.mediaPath_);
  2150. }
  2151. };
  2152. /**
  2153. * Generates a PNG version of the current workspace. This PNG is stored in a Base-64 encoded
  2154. * string as part of a data URL (e.g., "data:image/png;base64,...").
  2155. * TODO: There seems to be some problems capturing blocks that don't start with
  2156. * statement level blocks (e.g., expression blocks).
  2157. *
  2158. * @param {Function} callback - A function to be called with the results. This function should take two parameters, the URL (as a string) of the generated base64-encoded PNG and the IMG tag.
  2159. */
  2160. BlockPyEditor.prototype.getPngFromBlocks = function (callback) {
  2161. this.loadCss();
  2162. try {
  2163. // Retreive the entire canvas, strip some unnecessary tags
  2164. var blocks = this.blockly.svgBlockCanvas_.cloneNode(true);
  2165. blocks.removeAttribute("width");
  2166. blocks.removeAttribute("height"); // Ensure that we have some content
  2167. if (blocks.childNodes[0] !== undefined) {
  2168. // Remove tags that offset
  2169. blocks.removeAttribute("transform");
  2170. blocks.childNodes[0].removeAttribute("transform");
  2171. blocks.childNodes[0].childNodes[0].removeAttribute("transform"); // Add in styles
  2172. var linkElm = document.createElementNS("http://www.w3.org/1999/xhtml", "style");
  2173. linkElm.textContent = this.cssData + '\n\n';
  2174. blocks.insertBefore(linkElm, blocks.firstChild); // Get the bounding box
  2175. var bbox = document.getElementsByClassName("blocklyBlockCanvas")[0].getBBox(); // Create the XML representation of the SVG
  2176. var xml = new XMLSerializer().serializeToString(blocks);
  2177. xml = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' + bbox.width + '" height="' + bbox.height + '" viewBox="0 0 ' + bbox.width + ' ' + bbox.height + '"><rect width="100%" height="100%" fill="white"></rect>' + xml + '</svg>'; // create a file blob of our SVG.
  2178. // Unfortunately, this crashes modern chrome for unknown reasons.
  2179. //var blob = new Blob([ this.DOCTYPE + xml], { type: 'image/svg+xml' });
  2180. //var url = window.URL.createObjectURL(blob);
  2181. // Old method: this failed on IE
  2182. var url = "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(xml))); // Create an IMG tag to hold the new element
  2183. var img = document.createElement("img");
  2184. img.style.display = 'block';
  2185. img.onload = function () {
  2186. var canvas = document.createElement('canvas');
  2187. canvas.width = bbox.width;
  2188. canvas.height = bbox.height;
  2189. var ctx = canvas.getContext('2d');
  2190. ctx.drawImage(img, 0, 0);
  2191. var canvasUrl;
  2192. try {
  2193. canvasUrl = canvas.toDataURL("image/png");
  2194. } catch (e) {
  2195. canvasUrl = url;
  2196. }
  2197. img.onload = null;
  2198. callback(canvasUrl, img);
  2199. };
  2200. img.onerror = function () {
  2201. callback("", img);
  2202. };
  2203. img.setAttribute('src', url);
  2204. } else {
  2205. callback("", document.createElement("img"));
  2206. }
  2207. } catch (e) {
  2208. callback("", document.createElement("img"));
  2209. console.error("PNG image creation not supported!", e);
  2210. }
  2211. };
  2212. /**
  2213. * Shows a dialog window with the current block workspace encoded as a
  2214. * downloadable PNG image.
  2215. */
  2216. BlockPyEditor.prototype.copyImage = function () {
  2217. var dialog = this.main.components.dialog;
  2218. this.getPngFromBlocks(function (canvasUrl, img) {
  2219. img.onload = function () {
  2220. var p = document.createElement('p');
  2221. p.textContent = "Right click the image below and choose to copy or save it.";
  2222. var div = document.createElement('div');
  2223. div.appendChild(p);
  2224. div.appendChild(img);
  2225. dialog.show("Save Blocks As Image", div);
  2226. };
  2227. img.src = canvasUrl;
  2228. });
  2229. };