primitives.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893
  1. goog.require('Blockly.Blocks');
  2. //goog.require('Blockly.MutatorPlus');
  3. Blockly.Blocks['sphere'] = {
  4. init: function() {
  5. this.category = 'PRIMITIVE_CSG'
  6. this.setHelpUrl('http://www.example.com/');
  7. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  8. this.appendDummyInput()
  9. .appendField(Blockscad.Msg.SPHERE + " ");
  10. this.appendValueInput("RAD")
  11. .setCheck("Number")
  12. .appendField(Blockscad.Msg.RADIUS)
  13. .setAlign(Blockly.ALIGN_RIGHT);
  14. this.setInputsInline(true);
  15. this.setPreviousStatement(true, 'CSG');
  16. this.setTooltip(Blockscad.Msg.SPHERE_TOOLTIP);
  17. }//,
  18. // onchange: function() {
  19. // if (!this.workspace) {
  20. // // Block has been deleted.
  21. // return;
  22. // }
  23. // // if one of the value fields is missing, I want to pop up a warning.
  24. // var val = this.getInput("RAD").connection;
  25. // if (!val.targetConnection)
  26. // this.setWarningText("Sphere requires a radius to be set");
  27. // else this.setWarningText(null);
  28. // }
  29. };
  30. // Blockly.Blocks['sphere'] = {
  31. // init: function() {
  32. // this.category = 'PRIMITIVE_CSG'
  33. // this.setHelpUrl('http://www.example.com/');
  34. // this.setColourHex(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  35. // this.appendDummyInput()
  36. // .appendField(Blockscad.Msg.SPHERE + " ");
  37. // this.appendValueInput("RAD")
  38. // .setCheck("Number")
  39. // .appendField(Blockscad.Msg.RADIUS)
  40. // .setAlign(Blockly.ALIGN_RIGHT);
  41. // this.setInputsInline(true);
  42. // this.setPreviousStatement(true, 'CSG');
  43. // this.setTooltip(Blockscad.Msg.SPHERE_TOOLTIP);
  44. // }//,
  45. // };
  46. Blockly.Blocks['cylinder'] = {
  47. init: function() {
  48. this.category = 'PRIMITIVE_CSG';
  49. this.prevR1 = null;
  50. this.prevR2 = null;
  51. this.pR1id = null;
  52. this.pR2id = null;
  53. this.setHelpUrl('http://www.example.com/');
  54. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  55. this.appendDummyInput()
  56. .appendField(Blockscad.Msg.CYLINDER + ' ');
  57. this.appendValueInput('RAD1')
  58. .setCheck('Number')
  59. .appendField(Blockscad.Msg.RADIUS + '1')
  60. .setAlign(Blockly.ALIGN_RIGHT);
  61. // handle backwards compatibility for cylinders created before locking.
  62. if (Blockscad.inputVersion == null || Blockscad.inputVersion == "1.0.0"
  63. || Blockscad.inputVersion == "1.0.1" || Blockscad.inputVersion == "1.1.0") {
  64. this.appendDummyInput()
  65. .setAlign(Blockly.ALIGN_RIGHT)
  66. .appendField(new Blockly.FieldCheckbox("FALSE", null,
  67. "imgs/lock_icon.png","imgs/unlock_icon.png"), "LOCKED");
  68. }
  69. else {
  70. this.appendDummyInput()
  71. .setAlign(Blockly.ALIGN_RIGHT)
  72. .appendField(new Blockly.FieldCheckbox("TRUE", null,
  73. "imgs/lock_icon.png","imgs/unlock_icon.png"), "LOCKED") ;
  74. }
  75. // this.appendDummyInput()
  76. // .setAlign(Blockly.ALIGN_RIGHT)
  77. // .appendField(new Blockly.FieldCheckbox("TRUE", null), "CHECK") ;
  78. this.appendValueInput('RAD2')
  79. .setCheck('Number')
  80. .appendField(Blockscad.Msg.RADIUS + '2')
  81. .setAlign(Blockly.ALIGN_RIGHT);
  82. this.appendValueInput('HEIGHT')
  83. .setCheck('Number')
  84. .appendField(Blockscad.Msg.HEIGHT)
  85. .setAlign(Blockly.ALIGN_RIGHT);
  86. this.appendDummyInput()
  87. .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
  88. this.setInputsInline(true);
  89. this.setPreviousStatement(true, 'CSG');
  90. this.setTooltip(Blockscad.Msg.CYLINDER_TOOLTIP);
  91. },
  92. updateRadii: function() {
  93. if (!this.workspace) {
  94. // Block has been deleted.
  95. return;
  96. }
  97. // console.log('in updateRadii');
  98. var locked = this.getField("LOCKED").getValue();
  99. if (locked == 'FALSE') {
  100. return;
  101. }
  102. var R1 = null;
  103. var R2 = null;
  104. // get the values (if any) attached to the two radius inputs.
  105. if (this.getInput('RAD1').connection.targetConnection &&
  106. this.getInput('RAD1').connection.targetConnection.sourceBlock_.type == "math_number") {
  107. R1 = this.getInput('RAD1').connection.targetConnection.sourceBlock_.getField('NUM').getValue();
  108. }
  109. if (this.getInput('RAD2').connection.targetConnection &&
  110. this.getInput('RAD2').connection.targetConnection.sourceBlock_.type == "math_number") {
  111. R2 = this.getInput('RAD2').connection.targetConnection.sourceBlock_.getField('NUM').getValue();
  112. }
  113. if (locked == 'TRUE' && R1 && R2 && R1 != R2) {
  114. if (R1 != this.prevR1) {
  115. this.getInput('RAD2').connection.targetConnection.sourceBlock_.getField('NUM').setValue(R1,true);
  116. }
  117. else if (R2 != this.prevR2) {
  118. this.getInput('RAD1').connection.targetConnection.sourceBlock_.getField('NUM').setValue(R2,true);
  119. }
  120. // if you set locking on two different radii, do you want them to both take the value of R1?
  121. // else if (R1 != R2) this.getInput('RAD2').connection.targetConnection.sourceBlock_.getField('NUM').setValue(R1);
  122. }
  123. this.prevR1 = R1;
  124. this.prevR2 = R2;
  125. // console.log("in cylinder onchange. R1 R2 pR1 pR2", R1, R2, this.prevR1, this.prevR2);
  126. }
  127. };
  128. // planning not to use this.
  129. Blockly.Blocks['simple_cylinder'] = {
  130. init: function() {
  131. this.category = 'PRIMITIVE_CSG'
  132. this.setHelpUrl('http://www.example.com/');
  133. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  134. this.appendDummyInput()
  135. .appendField(Blockscad.Msg.CYLINDER + ' ');
  136. this.appendValueInput('RAD1')
  137. .setCheck('Number')
  138. .appendField(Blockscad.Msg.RADIUS)
  139. .setAlign(Blockly.ALIGN_RIGHT);
  140. this.appendValueInput('HEIGHT')
  141. .setCheck('Number')
  142. .appendField(Blockscad.Msg.HEIGHT)
  143. .setAlign(Blockly.ALIGN_RIGHT);
  144. this.appendDummyInput()
  145. .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
  146. this.setInputsInline(true);
  147. this.setPreviousStatement(true, 'CSG');
  148. this.setTooltip('Creates a cylinder with a specified radius and height. It may optionally be centered at the origin.');
  149. }//,
  150. };
  151. Blockly.Blocks['cube'] = {
  152. init: function() {
  153. this.category = 'PRIMITIVE_CSG'
  154. this.setHelpUrl('http://www.example.com/');
  155. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  156. this.appendDummyInput()
  157. .appendField(Blockscad.Msg.CUBE + ' ');
  158. this.appendValueInput('XVAL')
  159. .setCheck('Number')
  160. .appendField('X')
  161. .setAlign(Blockly.ALIGN_RIGHT);
  162. this.appendValueInput('YVAL')
  163. .setCheck('Number')
  164. .appendField('Y')
  165. .setAlign(Blockly.ALIGN_RIGHT);
  166. this.appendValueInput('ZVAL')
  167. .setCheck('Number')
  168. .appendField('Z')
  169. .setAlign(Blockly.ALIGN_RIGHT);
  170. this.appendDummyInput()
  171. .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
  172. this.setInputsInline(true);
  173. this.setPreviousStatement(true, 'CSG');
  174. //this.setNextStatement(true, 'CSG');
  175. this.setTooltip(Blockscad.Msg.CUBE_TOOLTIP);
  176. }//,
  177. // onchange: function() {
  178. // if (!this.workspace) {
  179. // // Block has been deleted.
  180. // return;
  181. // }
  182. // // if one of the value fields is missing, I want to pop up a warning.
  183. // var val1 = this.getInput("XVAL").connection;
  184. // var val2 = this.getInput("YVAL").connection;
  185. // var val3 = this.getInput("ZVAL").connection;
  186. // if (val1.targetConnection && val2.targetConnection && val3.targetConnection)
  187. // this.setWarningText(null);
  188. // else this.setWarningText("Cube needs all paramaters to have number values");
  189. // }
  190. };
  191. Blockly.Blocks['torus'] = {
  192. init: function() {
  193. this.category = 'PRIMITIVE_CSG'
  194. this.setHelpUrl('http://www.example.com/');
  195. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  196. this.appendDummyInput()
  197. .appendField(Blockscad.Msg.TORUS + ' ');
  198. this.appendValueInput('RAD1')
  199. .setCheck('Number')
  200. .appendField( Blockscad.Msg.RADIUS + '1')
  201. .setAlign(Blockly.ALIGN_RIGHT);
  202. this.appendValueInput('RAD2')
  203. .setCheck('Number')
  204. .appendField(Blockscad.Msg.RADIUS + '2')
  205. .setAlign(Blockly.ALIGN_RIGHT);
  206. this.appendValueInput('SIDES')
  207. .setCheck('Number')
  208. .appendField(Blockscad.Msg.SIDES)
  209. .setAlign(Blockly.ALIGN_RIGHT);
  210. this.appendValueInput('FACES')
  211. .setCheck('Number')
  212. .appendField(Blockscad.Msg.FACES)
  213. .setAlign(Blockly.ALIGN_RIGHT);
  214. this.setInputsInline(true);
  215. this.setPreviousStatement(true, 'CSG');
  216. this.setTooltip(Blockscad.Msg.TORUS_TOOLTIP);
  217. }//,
  218. // onchange: function() {
  219. // if (!this.workspace) {
  220. // // Block has been deleted.
  221. // return;
  222. // }
  223. // // if one of the value fields is missing, I want to pop up a warning.
  224. // var val1 = this.getInput("RAD1").connection;
  225. // var val2 = this.getInput("RAD2").connection;
  226. // var val3 = this.getInput("SIDES").connection;
  227. // var val4 = this.getInput("FACES").connection;
  228. // if (val1.targetConnection && val2.targetConnection && val3.targetConnection
  229. // && val4.targetConnection)
  230. // this.setWarningText(null);
  231. // else this.setWarningText("Torus needs all paramaters to have number values");
  232. // }
  233. };
  234. Blockly.Blocks['twistytorus'] = {
  235. init: function() {
  236. this.category = 'PRIMITIVE_CSG'
  237. this.setHelpUrl('http://www.example.com/');
  238. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  239. this.appendDummyInput()
  240. .appendField('Twisty Torus ');
  241. this.appendValueInput('RAD1')
  242. .setCheck('Number')
  243. .appendField('ring radius')
  244. .setAlign(Blockly.ALIGN_RIGHT);
  245. this.appendValueInput('RAD2')
  246. .setCheck('Number')
  247. .appendField('cross-section radius')
  248. .setAlign(Blockly.ALIGN_RIGHT);
  249. this.appendValueInput('SIDES')
  250. .setCheck('Number')
  251. .appendField('ring sides')
  252. .setAlign(Blockly.ALIGN_RIGHT);
  253. this.appendValueInput('FACES')
  254. .setCheck('Number')
  255. .appendField('cross section faces')
  256. .setAlign(Blockly.ALIGN_RIGHT);
  257. this.appendValueInput('TWIST')
  258. .setCheck('Number')
  259. .appendField('twist (degrees)')
  260. .setAlign(Blockly.ALIGN_RIGHT);
  261. this.setInputsInline(true);
  262. this.setPreviousStatement(true, 'CSG');
  263. this.setTooltip('Creates a torus with a ring of specified distance on-center from the origin (radius1), with a specified radius (radius2), a specified number of sides and faces. The "twist" is in degrees, and should be used with caution');
  264. }//,
  265. // onchange: function() {
  266. // if (!this.workspace) {
  267. // // Block has been deleted.
  268. // return;
  269. // }
  270. // // if one of the value fields is missing, I want to pop up a warning.
  271. // var val1 = this.getInput("RAD1").connection;
  272. // var val2 = this.getInput("RAD2").connection;
  273. // var val3 = this.getInput("SIDES").connection;
  274. // var val4 = this.getInput("FACES").connection;
  275. // if (val1.targetConnection && val2.targetConnection && val3.targetConnection
  276. // && val4.targetConnection)
  277. // this.setWarningText(null);
  278. // else this.setWarningText("Torus needs all paramaters to have number values");
  279. // }
  280. };
  281. Blockly.Blocks['circle'] = {
  282. init: function() {
  283. this.category = 'PRIMITIVE_CAG'
  284. this.setHelpUrl('http://www.example.com/');
  285. this.setColour(Blockscad.Toolbox.HEX_2D_PRIMITIVE);
  286. this.appendDummyInput()
  287. .appendField(Blockscad.Msg.CIRCLE + ' ');
  288. this.appendValueInput('RAD')
  289. .setCheck('Number')
  290. .appendField(Blockscad.Msg.RADIUS)
  291. .setAlign(Blockly.ALIGN_RIGHT);
  292. this.setInputsInline(true);
  293. this.setPreviousStatement(true, 'CAG');
  294. this.setTooltip(Blockscad.Msg.CIRCLE_TOOLTIP);
  295. }//,
  296. // onchange: function() {
  297. // if (!this.workspace) {
  298. // // Block has been deleted.
  299. // return;
  300. // }
  301. // // if one of the value fields is missing, I want to pop up a warning.
  302. // var val = this.getInput("RAD").connection;
  303. // if (!val.targetConnection)
  304. // this.setWarningText("Circle requires a radius to be set");
  305. // else this.setWarningText(null);
  306. // }
  307. };
  308. Blockly.Blocks['square'] = {
  309. init: function() {
  310. this.category = 'PRIMITIVE_CAG'
  311. this.setHelpUrl('http://www.example.com/');
  312. this.setColour(Blockscad.Toolbox.HEX_2D_PRIMITIVE);
  313. this.appendDummyInput()
  314. .appendField(Blockscad.Msg.SQUARE + ' ');
  315. this.appendValueInput('XVAL')
  316. .setCheck('Number')
  317. .appendField('X')
  318. .setAlign(Blockly.ALIGN_RIGHT);
  319. this.appendValueInput('YVAL')
  320. .setCheck('Number')
  321. .appendField('Y')
  322. .setAlign(Blockly.ALIGN_RIGHT);
  323. this.appendDummyInput()
  324. .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
  325. this.setInputsInline(true);
  326. this.setPreviousStatement(true, 'CAG');
  327. this.setTooltip(Blockscad.Msg.SQUARE_TOOLTIP);
  328. }//,
  329. // onchange: function() {
  330. // if (!this.workspace) {
  331. // // Block has been deleted.
  332. // return;
  333. // }
  334. // // if one of the value fields is missing, I want to pop up a warning.
  335. // var val1 = this.getInput("XVAL").connection;
  336. // var val2 = this.getInput("YVAL").connection;
  337. // if (val1.targetConnection && val2.targetConnection)
  338. // this.setWarningText(null);
  339. // else this.setWarningText("Square needs all paramaters to have number values");
  340. // }
  341. };
  342. Blockly.Blocks['translate'] = {
  343. init: function() {
  344. this.category = 'TRANSFORM';
  345. this.setHelpUrl('http://www.example.com/');
  346. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  347. this.appendDummyInput()
  348. .appendField(Blockscad.Msg.TRANSLATE);
  349. this.appendValueInput('XVAL')
  350. .setCheck('Number')
  351. .appendField('X')
  352. .setAlign(Blockly.ALIGN_RIGHT);
  353. this.appendValueInput('YVAL')
  354. .setCheck('Number')
  355. .appendField('Y')
  356. .setAlign(Blockly.ALIGN_RIGHT);
  357. this.appendValueInput('ZVAL')
  358. .setCheck('Number')
  359. .appendField('Z')
  360. .setAlign(Blockly.ALIGN_RIGHT);
  361. this.appendStatementInput('A')
  362. .setCheck(['CSG','CAG']);
  363. this.setInputsInline(true);
  364. this.setPreviousStatement(true, ['CSG','CAG']);
  365. this.setTooltip(Blockscad.Msg.TRANSLATE_TOOLTIP);
  366. // try to set up a mutator - Jennie
  367. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  368. this.plusCount_ = 0;
  369. },
  370. mutationToDom: function() {
  371. if (!this.plusCount_) {
  372. return null;
  373. }
  374. var container = document.createElement('mutation');
  375. if (this.plusCount_) {
  376. container.setAttribute('plus',this.plusCount_);
  377. }
  378. return container;
  379. },
  380. domToMutation: function(xmlElement) {
  381. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  382. var mytype = this.getInput('A').connection.check_;
  383. for (var x = 1; x <= this.plusCount_; x++) {
  384. this.appendStatementInput('PLUS' + x)
  385. .setCheck(mytype);
  386. }
  387. if (this.plusCount_ >= 1) {
  388. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  389. }
  390. },
  391. updateShape_ : function(num) {
  392. if (num == 1) {
  393. this.plusCount_++;
  394. var mytype = this.getInput('A').connection.check_;
  395. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  396. .setCheck(mytype);
  397. } else if (num == -1) {
  398. this.removeInput('PLUS' + this.plusCount_);
  399. this.plusCount_--;
  400. }
  401. if (this.plusCount_ >= 1) {
  402. if (this.plusCount_ == 1) {
  403. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  404. this.render();
  405. }
  406. } else {
  407. this.mutatorMinus.dispose();
  408. this.mutatorMinus = null;
  409. this.render();
  410. }
  411. },
  412. /**
  413. * If our parent or child is CSG or CAG, that sets our output type
  414. * and whether ZVAL field exists.
  415. * only call the drawing routines if the type is actually changing.
  416. * @this Blockly.Block
  417. */
  418. setType: function(type,drawMe) {
  419. if (!this.workspace) {
  420. // Block has been deleted.
  421. return;
  422. }
  423. if (!goog.isArray(type))
  424. type = [type];
  425. var zval = this.getInput('ZVAL');
  426. var next = this.getInput('A');
  427. var myType = this.previousConnection.check_;
  428. this.previousConnection.setCheck(type);
  429. next.connection.setCheck(type);
  430. for (var i = 1; i <= this.plusCount_; i++) {
  431. this.getInput('PLUS' + i).connection.setCheck(type);
  432. }
  433. if (type[0] == 'CAG' && myType[0] == 'CSG') {
  434. hideMyInput(zval,drawMe);
  435. }
  436. else if (type[0] == 'CSG' && myType[0] == 'CAG') {
  437. showMyInput(zval,drawMe);
  438. }
  439. // console.log("translate type has become",this.previousConnection.check_);
  440. //console.log(this.getInput('A').connection.check_);
  441. }
  442. };
  443. Blockly.Blocks['scale'] = {
  444. init: function() {
  445. this.category = 'TRANSFORM';
  446. this.setHelpUrl('http://www.example.com/');
  447. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  448. this.appendDummyInput()
  449. .appendField(Blockscad.Msg.SCALE);
  450. this.appendValueInput('XVAL')
  451. .setCheck('Number')
  452. .appendField('X')
  453. .setAlign(Blockly.ALIGN_RIGHT);
  454. this.appendValueInput('YVAL')
  455. .setCheck('Number')
  456. .appendField('Y')
  457. .setAlign(Blockly.ALIGN_RIGHT);
  458. this.appendValueInput('ZVAL')
  459. .setCheck('Number')
  460. .appendField('Z')
  461. .setAlign(Blockly.ALIGN_RIGHT);
  462. this.appendStatementInput('A')
  463. .setCheck(['CSG','CAG']);
  464. this.setInputsInline(true);
  465. this.setPreviousStatement(true, ['CSG','CAG']);
  466. this.setTooltip(Blockscad.Msg.SCALE_TOOLTIP);
  467. // try to set up a mutator - Jennie
  468. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  469. this.plusCount_ = 0;
  470. },
  471. mutationToDom: function() {
  472. if (!this.plusCount_) {
  473. return null;
  474. }
  475. var container = document.createElement('mutation');
  476. if (this.plusCount_) {
  477. container.setAttribute('plus',this.plusCount_);
  478. }
  479. return container;
  480. },
  481. domToMutation: function(xmlElement) {
  482. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  483. var mytype = this.getInput('A').connection.check_;
  484. for (var x = 1; x <= this.plusCount_; x++) {
  485. this.appendStatementInput('PLUS' + x)
  486. .setCheck(mytype);
  487. }
  488. if (this.plusCount_ >= 1) {
  489. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  490. }
  491. },
  492. updateShape_ : function(num) {
  493. if (num == 1) {
  494. this.plusCount_++;
  495. var mytype = this.getInput('A').connection.check_;
  496. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  497. .setCheck(mytype);
  498. } else if (num == -1) {
  499. this.removeInput('PLUS' + this.plusCount_);
  500. this.plusCount_--;
  501. }
  502. if (this.plusCount_ >= 1) {
  503. if (this.plusCount_ == 1) {
  504. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  505. this.render();
  506. }
  507. } else {
  508. this.mutatorMinus.dispose();
  509. this.mutatorMinus = null;
  510. this.render();
  511. }
  512. },
  513. /**
  514. * If our parent or child is CSG or CAG, that sets our output type
  515. * and whether ZVAL field exists.
  516. * @this Blockly.Block
  517. */
  518. setType: function(type,drawMe) {
  519. if (!this.workspace) {
  520. // Block has been deleted.
  521. return;
  522. }
  523. if (!goog.isArray(type))
  524. type = [type];
  525. var zval = this.getInput('ZVAL');
  526. var next = this.getInput('A');
  527. var myType = this.previousConnection.check_;
  528. this.previousConnection.setCheck(type);
  529. next.connection.setCheck(type);
  530. for (var i = 1; i <= this.plusCount_; i++) {
  531. this.getInput('PLUS' + i).connection.setCheck(type);
  532. }
  533. if (type[0] == 'CAG' && myType[0] == 'CSG') {
  534. hideMyInput(zval,drawMe);
  535. }
  536. else if (type[0] == 'CSG' && myType[0] == 'CAG') {
  537. showMyInput(zval,drawMe);
  538. }
  539. }
  540. };
  541. // Blockly.Blocks['resize'] = {
  542. // init: function() {
  543. // this.category = 'TRANSFORM';
  544. // this.setHelpUrl('http://www.example.com/');
  545. // this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  546. // this.appendDummyInput()
  547. // .appendField('Resize');
  548. // this.appendDummyInput()
  549. // .appendField('X');
  550. // this.appendValueInput('XVAL')
  551. // .setCheck('Number');
  552. // this.appendDummyInput()
  553. // .appendField('Y');
  554. // this.appendValueInput('YVAL')
  555. // .setCheck('Number');
  556. // this.appendDummyInput()
  557. // .appendField('Z');
  558. // this.appendValueInput('ZVAL')
  559. // .setCheck('Number');
  560. // this.appendStatementInput('A')
  561. // .setCheck('CSG');
  562. // this.setInputsInline(true);
  563. // this.setPreviousStatement(true, 'CSG');
  564. // this.setTooltip('');
  565. // }
  566. // };
  567. Blockly.Blocks['fancymirror'] = {
  568. init: function() {
  569. this.category = 'TRANSFORM';
  570. this.setHelpUrl('http://www.example.com/');
  571. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  572. this.appendDummyInput()
  573. .appendField(Blockscad.Msg.MIRROR_ADVANCED);
  574. this.appendValueInput('XVAL')
  575. .setCheck('Number')
  576. .appendField('X')
  577. .setAlign(Blockly.ALIGN_RIGHT);
  578. this.appendValueInput('YVAL')
  579. .setCheck('Number')
  580. .appendField('Y')
  581. .setAlign(Blockly.ALIGN_RIGHT);
  582. this.appendValueInput('ZVAL')
  583. .setCheck('Number')
  584. .appendField('Z')
  585. .setAlign(Blockly.ALIGN_RIGHT);
  586. this.appendStatementInput('A')
  587. .setCheck(['CSG','CAG']);
  588. this.setInputsInline(true);
  589. this.setPreviousStatement(true, ['CSG','CAG']);
  590. this.setTooltip(Blockscad.Msg.FANCYMIRROR_TOOLTIP);
  591. // try to set up a mutator - Jennie
  592. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  593. this.plusCount_ = 0;
  594. },
  595. mutationToDom: function() {
  596. if (!this.plusCount_) {
  597. return null;
  598. }
  599. var container = document.createElement('mutation');
  600. if (this.plusCount_) {
  601. container.setAttribute('plus',this.plusCount_);
  602. }
  603. return container;
  604. },
  605. domToMutation: function(xmlElement) {
  606. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  607. var mytype = this.getInput('A').connection.check_;
  608. for (var x = 1; x <= this.plusCount_; x++) {
  609. this.appendStatementInput('PLUS' + x)
  610. .setCheck(mytype);
  611. }
  612. if (this.plusCount_ >= 1) {
  613. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  614. }
  615. },
  616. updateShape_ : function(num) {
  617. if (num == 1) {
  618. this.plusCount_++;
  619. var mytype = this.getInput('A').connection.check_;
  620. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  621. .setCheck(mytype);
  622. } else if (num == -1) {
  623. this.removeInput('PLUS' + this.plusCount_);
  624. this.plusCount_--;
  625. }
  626. if (this.plusCount_ >= 1) {
  627. if (this.plusCount_ == 1) {
  628. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  629. this.render();
  630. }
  631. } else {
  632. this.mutatorMinus.dispose();
  633. this.mutatorMinus = null;
  634. this.render();
  635. }
  636. },
  637. setType: function(type,drawMe) {
  638. if (!this.workspace) {
  639. // Block has been deleted.
  640. return;
  641. }
  642. var zval = this.getInput('ZVAL');
  643. this.previousConnection.setCheck(type);
  644. this.getInput('A').connection.setCheck(type);
  645. for (var i = 1; i <= this.plusCount_; i++) {
  646. this.getInput('PLUS' + i).connection.setCheck(type);
  647. }
  648. }
  649. };
  650. Blockly.Blocks['simplemirror'] = {
  651. init: function() {
  652. this.category = 'TRANSFORM';
  653. this.setHelpUrl('http://www.example.com/');
  654. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  655. this.appendDummyInput()
  656. .appendField('Simple Mirror');
  657. this.appendDummyInput()
  658. .appendField('across')
  659. .appendField(new Blockly.FieldDropdown([['+', 'pos'], ['-', 'neg']]), 'sign')
  660. .appendField(new Blockly.FieldDropdown([['XY', 'XY'], ['YZ', 'YZ'], ['XZ', 'XZ']]), 'mirrorplane');
  661. this.appendStatementInput('A')
  662. .setCheck('CSG');
  663. this.setInputsInline(true);
  664. this.setPreviousStatement(true, 'CSG');
  665. this.setTooltip(Blockscad.Msg.SIMPLEMIRROR_TOOLTIP);
  666. },
  667. /**
  668. * If our parent or child is CSG or CAG, that sets our output type
  669. * @this Blockly.Block
  670. */
  671. setType: function(type,drawMe) {
  672. if (!this.workspace) {
  673. // Block has been deleted.
  674. return;
  675. }
  676. var next = this.getInput('A');
  677. this.previousConnection.setCheck(type);
  678. next.connection.setCheck(type);
  679. }
  680. };
  681. Blockly.Blocks['simplemirror_new'] = {
  682. init: function() {
  683. this.category = 'TRANSFORM';
  684. this.setHelpUrl('http://www.example.com/');
  685. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  686. this.appendDummyInput()
  687. .appendField(Blockscad.Msg.MIRROR);
  688. this.appendDummyInput('3D')
  689. .appendField(Blockscad.Msg.ACROSS)
  690. .appendField(new Blockly.FieldDropdown([['XY', 'XY'], ['YZ', 'YZ'], ['XZ', 'XZ']]), 'mirrorplane');
  691. this.appendDummyInput('2D')
  692. .appendField(Blockscad.Msg.ACROSS)
  693. .appendField(new Blockly.FieldDropdown([['YZ', 'YZ'], ['XZ', 'XZ']]), 'mirrorplane_cag')
  694. .setVisible(false);
  695. this.appendStatementInput('A')
  696. .setCheck(['CSG','CAG']);
  697. this.setInputsInline(true);
  698. this.setPreviousStatement(true, ['CSG','CAG']);
  699. this.setTooltip(Blockscad.Msg.SIMPLEMIRROR_TOOLTIP);
  700. // try to set up a mutator - Jennie
  701. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  702. this.plusCount_ = 0;
  703. },
  704. mutationToDom: function() {
  705. if (!this.plusCount_) {
  706. return null;
  707. }
  708. var container = document.createElement('mutation');
  709. if (this.plusCount_) {
  710. container.setAttribute('plus',this.plusCount_);
  711. }
  712. return container;
  713. },
  714. domToMutation: function(xmlElement) {
  715. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  716. var mytype = this.getInput('A').connection.check_;
  717. for (var x = 1; x <= this.plusCount_; x++) {
  718. this.appendStatementInput('PLUS' + x)
  719. .setCheck(mytype);
  720. }
  721. if (this.plusCount_ >= 1) {
  722. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  723. }
  724. },
  725. updateShape_ : function(num) {
  726. if (num == 1) {
  727. this.plusCount_++;
  728. var mytype = this.getInput('A').connection.check_;
  729. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  730. .setCheck(mytype);
  731. } else if (num == -1) {
  732. this.removeInput('PLUS' + this.plusCount_);
  733. this.plusCount_--;
  734. }
  735. if (this.plusCount_ >= 1) {
  736. if (this.plusCount_ == 1) {
  737. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  738. this.render();
  739. }
  740. } else {
  741. this.mutatorMinus.dispose();
  742. this.mutatorMinus = null;
  743. this.render();
  744. }
  745. },
  746. /**
  747. * If our parent or child is CSG or CAG, that sets our output type
  748. * and whether ZVAL field exists.
  749. * @this Blockly.Block
  750. */
  751. setType: function(type,drawMe) {
  752. if (!this.workspace) {
  753. // Block has been deleted.
  754. return;
  755. }
  756. if (!goog.isArray(type))
  757. type = [type];
  758. // var csg = this.getField_('mirrorplane');
  759. // var cag = this.getField_('mirrorplane_cag');
  760. var csg = this.getInput('3D');
  761. var cag = this.getInput('2D');
  762. var next = this.getInput('A');
  763. var myType = this.previousConnection.check_;
  764. this.previousConnection.setCheck(type);
  765. next.connection.setCheck(type);
  766. for (var i = 1; i <= this.plusCount_; i++) {
  767. this.getInput('PLUS' + i).connection.setCheck(type);
  768. }
  769. if (type[0] == 'CAG' && myType[0] == 'CSG') {
  770. hideMyInput(csg,drawMe);
  771. showMyInput(cag,drawMe);
  772. }
  773. else if (type[0] == 'CSG' && myType[0] == 'CAG') {
  774. hideMyInput(cag,drawMe);
  775. showMyInput(csg,drawMe);
  776. }
  777. }
  778. };
  779. Blockly.Blocks['taper'] = {
  780. init: function() {
  781. this.category = 'TRANSFORM';
  782. this.setHelpUrl('http://www.example.com/');
  783. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  784. this.appendDummyInput()
  785. .appendField(Blockscad.Msg.TAPER);
  786. this.appendDummyInput('3D')
  787. .appendField(Blockscad.Msg.ALONG + ' ')
  788. .appendField(new Blockly.FieldDropdown([['X', 'X'], ['Y', 'Y'], ['Z', 'Z']]), 'taperaxis')
  789. .appendField(Blockscad.Msg.AXIS);
  790. this.appendDummyInput('2D')
  791. .appendField(Blockscad.Msg.ALONG + ' ')
  792. .appendField(new Blockly.FieldDropdown([['X', 'X'], ['Y', 'Y']]), 'taperaxis_cag')
  793. .appendField(Blockscad.Msg.AXIS)
  794. .setVisible(false);
  795. this.appendValueInput('FACTOR')
  796. .setCheck('Number')
  797. .appendField(Blockscad.Msg.SCALE)
  798. .setAlign(Blockly.ALIGN_RIGHT);
  799. this.appendStatementInput('A')
  800. .setCheck(['CSG','CAG']);
  801. this.setInputsInline(true);
  802. this.setPreviousStatement(true, ['CSG','CAG']);
  803. this.setTooltip(Blockscad.Msg.TAPER_TOOLTIP);
  804. this.setWarningText(Blockscad.Msg.NOT_COMPATIBLE_WITH_OPENSCAD);
  805. // try to set up a mutator - Jennie
  806. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  807. this.plusCount_ = 0;
  808. },
  809. mutationToDom: function() {
  810. if (!this.plusCount_) {
  811. return null;
  812. }
  813. var container = document.createElement('mutation');
  814. if (this.plusCount_) {
  815. container.setAttribute('plus',this.plusCount_);
  816. }
  817. return container;
  818. },
  819. domToMutation: function(xmlElement) {
  820. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  821. var mytype = this.getInput('A').connection.check_;
  822. for (var x = 1; x <= this.plusCount_; x++) {
  823. this.appendStatementInput('PLUS' + x)
  824. .setCheck(mytype);
  825. }
  826. if (this.plusCount_ >= 1) {
  827. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  828. }
  829. },
  830. updateShape_ : function(num) {
  831. if (num == 1) {
  832. this.plusCount_++;
  833. var mytype = this.getInput('A').connection.check_;
  834. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  835. .setCheck(mytype);
  836. } else if (num == -1) {
  837. this.removeInput('PLUS' + this.plusCount_);
  838. this.plusCount_--;
  839. }
  840. if (this.plusCount_ >= 1) {
  841. if (this.plusCount_ == 1) {
  842. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  843. this.render();
  844. }
  845. } else {
  846. this.mutatorMinus.dispose();
  847. this.mutatorMinus = null;
  848. this.render();
  849. }
  850. },
  851. /**
  852. * If our parent or child is CSG or CAG, that sets our output type
  853. * and whether ZVAL field exists.
  854. * @this Blockly.Block
  855. */
  856. setType: function(type,drawMe) {
  857. if (!this.workspace) {
  858. // Block has been deleted.
  859. return;
  860. }
  861. if (!goog.isArray(type))
  862. type = [type];
  863. var csg = this.getInput('3D');
  864. var cag = this.getInput('2D');
  865. var next = this.getInput('A');
  866. var myType = this.previousConnection.check_;
  867. this.previousConnection.setCheck(type);
  868. next.connection.setCheck(type);
  869. for (var i = 1; i <= this.plusCount_; i++) {
  870. this.getInput('PLUS' + i).connection.setCheck(type);
  871. }
  872. if (type[0] == 'CAG' && myType[0] == 'CSG') {
  873. hideMyInput(csg,drawMe);
  874. showMyInput(cag,drawMe);
  875. }
  876. else if (type[0] == 'CSG' && myType[0] == 'CAG') {
  877. hideMyInput(cag,drawMe);
  878. showMyInput(csg,drawMe);
  879. if (drawMe) this.render();
  880. }
  881. }
  882. };
  883. Blockly.Blocks['simplerotate'] = {
  884. init: function() {
  885. this.category = 'TRANSFORM';
  886. this.setHelpUrl('http://www.example.com/');
  887. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  888. this.appendDummyInput()
  889. .appendField(Blockscad.Msg.ROTATE);
  890. this.appendValueInput('XVAL')
  891. .setCheck('Number')
  892. .appendField('X')
  893. .setAlign(Blockly.ALIGN_RIGHT);
  894. this.appendValueInput('YVAL')
  895. .setCheck('Number')
  896. .appendField('Y')
  897. .setAlign(Blockly.ALIGN_RIGHT);
  898. this.appendValueInput('ZVAL')
  899. .setCheck('Number')
  900. .appendField('Z')
  901. .setAlign(Blockly.ALIGN_RIGHT);
  902. this.appendStatementInput('A')
  903. .setCheck(['CSG','CAG']);
  904. this.setInputsInline(true);
  905. this.setPreviousStatement(true, ['CSG','CAG']);
  906. this.setTooltip(Blockscad.Msg.SIMPLEROTATE_TOOLTIP);
  907. // try to set up a mutator - Jennie
  908. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  909. this.plusCount_ = 0;
  910. },
  911. mutationToDom: function() {
  912. if (!this.plusCount_) {
  913. return null;
  914. }
  915. var container = document.createElement('mutation');
  916. if (this.plusCount_) {
  917. container.setAttribute('plus',this.plusCount_);
  918. }
  919. return container;
  920. },
  921. domToMutation: function(xmlElement) {
  922. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  923. var mytype = this.getInput('A').connection.check_;
  924. for (var x = 1; x <= this.plusCount_; x++) {
  925. this.appendStatementInput('PLUS' + x)
  926. .setCheck(mytype);
  927. }
  928. if (this.plusCount_ >= 1) {
  929. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  930. }
  931. },
  932. updateShape_ : function(num) {
  933. if (num == 1) {
  934. this.plusCount_++;
  935. var mytype = this.getInput('A').connection.check_;
  936. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  937. .setCheck(mytype);
  938. } else if (num == -1) {
  939. this.removeInput('PLUS' + this.plusCount_);
  940. this.plusCount_--;
  941. }
  942. if (this.plusCount_ >= 1) {
  943. if (this.plusCount_ == 1) {
  944. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  945. this.render();
  946. }
  947. } else {
  948. this.mutatorMinus.dispose();
  949. this.mutatorMinus = null;
  950. this.render();
  951. }
  952. },
  953. /**
  954. * If our parent or child is CSG or CAG, that sets our output type
  955. * and whether ZVAL field exists.
  956. * @this Blockly.Block
  957. */
  958. setType: function(type,drawMe) {
  959. if (!this.workspace) {
  960. // Block has been deleted.
  961. return;
  962. }
  963. // don't hide x and y axes for rotation - openscad creates a projection.
  964. // var xval = this.getInput('XVAL');
  965. // var yval = this.getInput('YVAL');
  966. var next = this.getInput('A');
  967. // if (type == 'CAG') { // parent wants a 2D shape
  968. // hideMyInput(xval,drawMe);
  969. // hideMyInput(yval,drawMe);
  970. // if (drawMe) this.render();
  971. // }
  972. // else { // parent wants 3D or doesn't care
  973. // showMyInput(xval,drawMe);
  974. // showMyInput(yval,drawMe);
  975. // if (drawMe) this.render();
  976. // }
  977. this.previousConnection.setCheck(type);
  978. next.connection.setCheck(type);
  979. for (var i = 1; i <= this.plusCount_; i++) {
  980. this.getInput('PLUS' + i).connection.setCheck(type);
  981. }
  982. }
  983. };
  984. Blockly.Blocks['fancyrotate'] = {
  985. init: function() {
  986. this.category = 'TRANSFORM';
  987. this.setHelpUrl('http://www.example.com/');
  988. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  989. this.appendDummyInput()
  990. .appendField(Blockscad.Msg.ROTATE_ADVANCED);
  991. this.appendValueInput('AVAL')
  992. .setCheck('Number');
  993. this.appendValueInput('XVAL')
  994. .setCheck('Number')
  995. .appendField(Blockscad.Msg.AROUND + ' X')
  996. .setAlign(Blockly.ALIGN_RIGHT);
  997. this.appendValueInput('YVAL')
  998. .setCheck('Number')
  999. .appendField('Y')
  1000. .setAlign(Blockly.ALIGN_RIGHT);
  1001. this.appendValueInput('ZVAL')
  1002. .setCheck('Number')
  1003. .appendField('Z')
  1004. .setAlign(Blockly.ALIGN_RIGHT);
  1005. this.appendStatementInput('A')
  1006. .setCheck(['CSG','CAG']);
  1007. this.setInputsInline(true);
  1008. this.setPreviousStatement(true, ['CSG','CAG']);
  1009. this.setTooltip(Blockscad.Msg.FANCYROTATE_TOOLTIP);
  1010. // try to set up a mutator - Jennie
  1011. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1012. this.plusCount_ = 0;
  1013. },
  1014. mutationToDom: function() {
  1015. if (!this.plusCount_) {
  1016. return null;
  1017. }
  1018. var container = document.createElement('mutation');
  1019. if (this.plusCount_) {
  1020. container.setAttribute('plus',this.plusCount_);
  1021. }
  1022. return container;
  1023. },
  1024. domToMutation: function(xmlElement) {
  1025. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1026. var mytype = this.getInput('A').connection.check_;
  1027. for (var x = 1; x <= this.plusCount_; x++) {
  1028. this.appendStatementInput('PLUS' + x)
  1029. .setCheck(mytype);
  1030. }
  1031. if (this.plusCount_ >= 1) {
  1032. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1033. }
  1034. },
  1035. updateShape_ : function(num) {
  1036. if (num == 1) {
  1037. this.plusCount_++;
  1038. var mytype = this.getInput('A').connection.check_;
  1039. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1040. .setCheck(mytype);
  1041. } else if (num == -1) {
  1042. this.removeInput('PLUS' + this.plusCount_);
  1043. this.plusCount_--;
  1044. }
  1045. if (this.plusCount_ >= 1) {
  1046. if (this.plusCount_ == 1) {
  1047. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1048. this.render();
  1049. }
  1050. } else {
  1051. this.mutatorMinus.dispose();
  1052. this.mutatorMinus = null;
  1053. this.render();
  1054. }
  1055. },
  1056. /**
  1057. * If our parent or child is CSG or CAG, that sets our output type
  1058. * and whether ZVAL field exists.
  1059. * @this Blockly.Block
  1060. */
  1061. setType: function(type,drawMe) {
  1062. if (!this.workspace) {
  1063. // Block has been deleted.
  1064. return;
  1065. }
  1066. if (!goog.isArray(type))
  1067. type = [type];
  1068. var zval = this.getInput('ZVAL');
  1069. var xval = this.getInput('XVAL');
  1070. var yval = this.getInput('YVAL');
  1071. var next = this.getInput('A');
  1072. var myType = this.previousConnection.check_;
  1073. this.previousConnection.setCheck(type);
  1074. next.connection.setCheck(type);
  1075. for (var i = 1; i <= this.plusCount_; i++) {
  1076. this.getInput('PLUS' + i).connection.setCheck(type);
  1077. }
  1078. if (type[0] == 'CAG' && myType[0] == 'CSG') {
  1079. hideMyInput(xval,drawMe);
  1080. hideMyInput(yval,drawMe);
  1081. hideMyInput(zval,drawMe);
  1082. }
  1083. else if (type[0] == 'CSG' && myType[0] == 'CAG') {
  1084. showMyInput(xval,drawMe);
  1085. showMyInput(yval,drawMe);
  1086. showMyInput(zval,drawMe);
  1087. }
  1088. }
  1089. };
  1090. Blockly.Blocks['color'] = {
  1091. init: function() {
  1092. this.category = 'COLOR';
  1093. this.setHelpUrl('http://www.example.com/');
  1094. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1095. this.appendDummyInput()
  1096. .appendField(Blockscad.Msg.COLOR);
  1097. this.appendValueInput('COLOR')
  1098. .setCheck('Colour');
  1099. this.appendStatementInput('A')
  1100. .setCheck('CSG');
  1101. this.setInputsInline(true);
  1102. this.setPreviousStatement(true, 'CSG');
  1103. this.setTooltip(Blockscad.Msg.COLOR_TOOLTIP);
  1104. // try to set up a mutator - Jennie
  1105. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1106. this.plusCount_ = 0;
  1107. },
  1108. mutationToDom: function() {
  1109. if (!this.plusCount_) {
  1110. return null;
  1111. }
  1112. var container = document.createElement('mutation');
  1113. if (this.plusCount_) {
  1114. container.setAttribute('plus',this.plusCount_);
  1115. }
  1116. return container;
  1117. },
  1118. domToMutation: function(xmlElement) {
  1119. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1120. var mytype = this.getInput('A').connection.check_;
  1121. for (var x = 1; x <= this.plusCount_; x++) {
  1122. this.appendStatementInput('PLUS' + x)
  1123. .setCheck(mytype);
  1124. }
  1125. if (this.plusCount_ >= 1) {
  1126. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1127. }
  1128. },
  1129. updateShape_ : function(num) {
  1130. if (num == 1) {
  1131. this.plusCount_++;
  1132. var mytype = this.getInput('A').connection.check_;
  1133. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1134. .setCheck(mytype);
  1135. } else if (num == -1) {
  1136. this.removeInput('PLUS' + this.plusCount_);
  1137. this.plusCount_--;
  1138. }
  1139. if (this.plusCount_ >= 1) {
  1140. if (this.plusCount_ == 1) {
  1141. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1142. this.render();
  1143. }
  1144. } else {
  1145. this.mutatorMinus.dispose();
  1146. this.mutatorMinus = null;
  1147. this.render();
  1148. }
  1149. }
  1150. };
  1151. Blockly.Blocks['color_rgb'] = {
  1152. init: function() {
  1153. this.category = 'COLOR';
  1154. this.setHelpUrl('http://www.example.com/');
  1155. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1156. this.appendDummyInput()
  1157. .appendField(Blockscad.Msg.COLOR + ' ');
  1158. var dropdown = new Blockly.FieldDropdown([[Blockscad.Msg.HSV_COLOR_MODEL, 'HSV'],[Blockscad.Msg.RGB_COLOR_MODEL, 'RGB']], function(option) {
  1159. var isRGB = (option == 'RGB');
  1160. this.sourceBlock_.optUpdateShape_(isRGB);
  1161. });
  1162. this.appendDummyInput()
  1163. .appendField(dropdown, 'SCHEME')
  1164. .setAlign(Blockly.ALIGN_RIGHT);
  1165. this.appendValueInput('RED')
  1166. .setCheck('Number')
  1167. .appendField(Blockscad.Msg.COLOR_HUE, '1')
  1168. .setAlign(Blockly.ALIGN_RIGHT);
  1169. this.appendValueInput('GREEN')
  1170. .setCheck('Number')
  1171. .appendField(Blockscad.Msg.COLOR_SATURATION, '2')
  1172. .setAlign(Blockly.ALIGN_RIGHT);
  1173. this.appendValueInput('BLUE')
  1174. .setCheck('Number')
  1175. .appendField(Blockscad.Msg.COLOR_VALUE,'3')
  1176. .setAlign(Blockly.ALIGN_RIGHT);
  1177. this.appendStatementInput('A')
  1178. .setCheck('CSG');
  1179. this.setInputsInline(true);
  1180. this.setPreviousStatement(true, 'CSG');
  1181. var thisBlock = this;
  1182. this.setTooltip(function() {
  1183. var mode = thisBlock.getFieldValue('SCHEME');
  1184. var TOOLTIPS = {
  1185. 'RGB': Blockscad.Msg.COLOR_RGB_TOOLTIP,
  1186. 'HSV': Blockscad.Msg.COLOR_HSV_TOOLTIP
  1187. };
  1188. return TOOLTIPS[mode];
  1189. });
  1190. // try to set up a mutator - Jennie
  1191. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1192. this.plusCount_ = 0;
  1193. },
  1194. mutationToDom: function() {
  1195. // if (!this.plusCount_) {
  1196. // return null;
  1197. // }
  1198. var container = document.createElement('mutation');
  1199. if (this.plusCount_) {
  1200. container.setAttribute('plus',this.plusCount_);
  1201. }
  1202. else container.setAttribute('plus', 0);
  1203. var isRGB = (this.getFieldValue('SCHEME') == 'RGB');
  1204. container.setAttribute('isrgb', isRGB);
  1205. return container;
  1206. },
  1207. domToMutation: function(xmlElement) {
  1208. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1209. var mytype = this.getInput('A').connection.check_;
  1210. for (var x = 1; x <= this.plusCount_; x++) {
  1211. this.appendStatementInput('PLUS' + x)
  1212. .setCheck(mytype);
  1213. }
  1214. if (this.plusCount_ >= 1) {
  1215. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1216. }
  1217. var isRGB = (xmlElement.getAttribute('isrgb') == 'true');
  1218. this.optUpdateShape_(isRGB);
  1219. },
  1220. updateShape_ : function(num) {
  1221. if (num == 1) {
  1222. this.plusCount_++;
  1223. var mytype = this.getInput('A').connection.check_;
  1224. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1225. .setCheck(mytype);
  1226. } else if (num == -1) {
  1227. this.removeInput('PLUS' + this.plusCount_);
  1228. this.plusCount_--;
  1229. }
  1230. if (this.plusCount_ >= 1) {
  1231. if (this.plusCount_ == 1) {
  1232. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1233. this.render();
  1234. }
  1235. } else {
  1236. if (this.mutatorMinus) this.mutatorMinus.dispose();
  1237. this.mutatorMinus = null;
  1238. this.render();
  1239. }
  1240. } ,
  1241. // if change the labels on the value inputs based on if this is RGB or HSV
  1242. optUpdateShape_: function(isRGB) {
  1243. // make labels match the color schema (RGB or HSV)
  1244. var one = this.getField('1');
  1245. var two = this.getField('2');
  1246. var three = this.getField('3');
  1247. if (isRGB) {
  1248. one.setText(Blockly.Msg.COLOUR_RGB_RED);
  1249. two.setText(Blockly.Msg.COLOUR_RGB_GREEN);
  1250. three.setText(Blockly.Msg.COLOUR_RGB_BLUE);
  1251. }
  1252. else {
  1253. one.setText(Blockscad.Msg.COLOR_HUE);
  1254. two.setText(Blockscad.Msg.COLOR_SATURATION);
  1255. three.setText(Blockscad.Msg.COLOR_VALUE);
  1256. }
  1257. }
  1258. };
  1259. Blockly.Blocks['$fn'] = {
  1260. init: function() {
  1261. this.category = 'TRANSFORM';
  1262. this.setHelpUrl('http://www.example.com/');
  1263. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1264. this.appendValueInput('SIDES')
  1265. .setCheck('Number')
  1266. .appendField(Blockscad.Msg.SIDES);
  1267. this.appendStatementInput('A')
  1268. .setCheck(['CSG','CAG']);
  1269. this.setInputsInline(true);
  1270. this.setPreviousStatement(true, ['CSG','CAG']);
  1271. this.setTooltip(Blockscad.Msg.FN_TOOLTIP);
  1272. // try to set up a mutator - Jennie
  1273. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1274. this.plusCount_ = 0;
  1275. },
  1276. mutationToDom: function() {
  1277. if (!this.plusCount_) {
  1278. return null;
  1279. }
  1280. var container = document.createElement('mutation');
  1281. if (this.plusCount_) {
  1282. container.setAttribute('plus',this.plusCount_);
  1283. }
  1284. return container;
  1285. },
  1286. domToMutation: function(xmlElement) {
  1287. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1288. var mytype = this.getInput('A').connection.check_;
  1289. for (var x = 1; x <= this.plusCount_; x++) {
  1290. this.appendStatementInput('PLUS' + x)
  1291. .setCheck(mytype);
  1292. }
  1293. if (this.plusCount_ >= 1) {
  1294. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1295. }
  1296. },
  1297. updateShape_ : function(num) {
  1298. if (num == 1) {
  1299. this.plusCount_++;
  1300. var mytype = this.getInput('A').connection.check_;
  1301. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1302. .setCheck(mytype);
  1303. } else if (num == -1) {
  1304. this.removeInput('PLUS' + this.plusCount_);
  1305. this.plusCount_--;
  1306. }
  1307. if (this.plusCount_ >= 1) {
  1308. if (this.plusCount_ == 1) {
  1309. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1310. this.render();
  1311. }
  1312. } else {
  1313. this.mutatorMinus.dispose();
  1314. this.mutatorMinus = null;
  1315. this.render();
  1316. }
  1317. },
  1318. setType: function(type) {
  1319. if (!this.workspace) {
  1320. // Block has been deleted.
  1321. return;
  1322. }
  1323. //console.log("setting union type to",type);
  1324. this.previousConnection.setCheck(type);
  1325. this.getInput('A').connection.setCheck(type);
  1326. for (var i = 1; i <= this.plusCount_; i++) {
  1327. this.getInput('PLUS' + i).connection.setCheck(type);
  1328. }
  1329. }
  1330. };
  1331. Blockly.Blocks['assign'] = {
  1332. init: function() {
  1333. this.category = 'TRANSFORM';
  1334. this.setHelpUrl('http://www.example.com/');
  1335. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1336. this.appendValueInput('NAME')
  1337. .appendField("set ")
  1338. // .setCheck('String')
  1339. .setAlign(Blockly.ALIGN_RIGHT);
  1340. this.appendValueInput('VALUE')
  1341. .setCheck('Number')
  1342. .appendField(' = ');
  1343. this.appendStatementInput('A')
  1344. .setCheck(['CSG','CAG']);
  1345. this.setInputsInline(true);
  1346. this.setPreviousStatement(true, ['CSG','CAG']);
  1347. this.setTooltip(Blockscad.Msg.FN_TOOLTIP);
  1348. // try to set up a mutator - Jennie
  1349. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1350. this.plusCount_ = 0;
  1351. },
  1352. mutationToDom: function() {
  1353. if (!this.plusCount_) {
  1354. return null;
  1355. }
  1356. var container = document.createElement('mutation');
  1357. if (this.plusCount_) {
  1358. container.setAttribute('plus',this.plusCount_);
  1359. }
  1360. return container;
  1361. },
  1362. domToMutation: function(xmlElement) {
  1363. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1364. var mytype = this.getInput('A').connection.check_;
  1365. for (var x = 1; x <= this.plusCount_; x++) {
  1366. this.appendStatementInput('PLUS' + x)
  1367. .setCheck(mytype);
  1368. }
  1369. if (this.plusCount_ >= 1) {
  1370. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1371. }
  1372. },
  1373. updateShape_ : function(num) {
  1374. if (num == 1) {
  1375. this.plusCount_++;
  1376. var mytype = this.getInput('A').connection.check_;
  1377. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1378. .setCheck(mytype);
  1379. } else if (num == -1) {
  1380. this.removeInput('PLUS' + this.plusCount_);
  1381. this.plusCount_--;
  1382. }
  1383. if (this.plusCount_ >= 1) {
  1384. if (this.plusCount_ == 1) {
  1385. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1386. this.render();
  1387. }
  1388. } else {
  1389. this.mutatorMinus.dispose();
  1390. this.mutatorMinus = null;
  1391. this.render();
  1392. }
  1393. },
  1394. setType: function(type) {
  1395. if (!this.workspace) {
  1396. // Block has been deleted.
  1397. return;
  1398. }
  1399. //console.log("setting union type to",type);
  1400. this.previousConnection.setCheck(type);
  1401. this.getInput('A').connection.setCheck(type);
  1402. for (var i = 1; i <= this.plusCount_; i++) {
  1403. this.getInput('PLUS' + i).connection.setCheck(type);
  1404. }
  1405. }
  1406. };
  1407. Blockly.Blocks['linearextrude'] = {
  1408. init: function() {
  1409. this.category = 'EXTRUDE';
  1410. this.setHelpUrl('http://www.example.com/');
  1411. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1412. this.appendDummyInput()
  1413. .appendField(Blockscad.Msg.LINEAR_EXTRUDE + ' ');
  1414. this.appendValueInput('HEIGHT')
  1415. .setCheck('Number')
  1416. .appendField(Blockscad.Msg.HEIGHT)
  1417. .setAlign(Blockly.ALIGN_RIGHT);
  1418. this.appendValueInput('TWIST')
  1419. .setCheck('Number')
  1420. .appendField(Blockscad.Msg.TWIST)
  1421. .setAlign(Blockly.ALIGN_RIGHT);
  1422. // this.appendDummyInput()
  1423. // .appendField('scale: ')
  1424. // .setAlign(Blockly.ALIGN_RIGHT);
  1425. this.appendValueInput('XSCALE')
  1426. .setCheck('Number')
  1427. .appendField(Blockscad.Msg.SCALE + ': x')
  1428. .setAlign(Blockly.ALIGN_RIGHT);
  1429. this.appendValueInput('YSCALE')
  1430. .setCheck('Number')
  1431. .appendField('y')
  1432. .setAlign(Blockly.ALIGN_RIGHT);
  1433. this.appendDummyInput()
  1434. .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN')
  1435. .setAlign(Blockly.ALIGN_RIGHT);
  1436. this.appendStatementInput('A')
  1437. .setCheck('CAG');
  1438. this.setInputsInline(true);
  1439. this.setPreviousStatement(true, 'CSG');
  1440. this.setTooltip(Blockscad.Msg.LINEAREXTRUDE_TOOLTIP);
  1441. // try to set up a mutator - Jennie
  1442. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1443. this.plusCount_ = 0;
  1444. },
  1445. mutationToDom: function() {
  1446. if (!this.plusCount_) {
  1447. return null;
  1448. }
  1449. var container = document.createElement('mutation');
  1450. if (this.plusCount_) {
  1451. container.setAttribute('plus',this.plusCount_);
  1452. }
  1453. return container;
  1454. },
  1455. domToMutation: function(xmlElement) {
  1456. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1457. var mytype = this.getInput('A').connection.check_;
  1458. for (var x = 1; x <= this.plusCount_; x++) {
  1459. this.appendStatementInput('PLUS' + x)
  1460. .setCheck(mytype);
  1461. }
  1462. if (this.plusCount_ >= 1) {
  1463. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1464. }
  1465. },
  1466. updateShape_ : function(num) {
  1467. if (num == 1) {
  1468. this.plusCount_++;
  1469. var mytype = this.getInput('A').connection.check_;
  1470. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1471. .setCheck(mytype);
  1472. } else if (num == -1) {
  1473. this.removeInput('PLUS' + this.plusCount_);
  1474. this.plusCount_--;
  1475. }
  1476. if (this.plusCount_ >= 1) {
  1477. if (this.plusCount_ == 1) {
  1478. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1479. this.render();
  1480. }
  1481. } else {
  1482. this.mutatorMinus.dispose();
  1483. this.mutatorMinus = null;
  1484. this.render();
  1485. }
  1486. }
  1487. };
  1488. Blockly.Blocks['rotateextrude'] = {
  1489. init: function() {
  1490. this.category = 'EXTRUDE';
  1491. this.setHelpUrl('http://www.example.com/');
  1492. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1493. this.appendDummyInput()
  1494. .appendField(Blockscad.Msg.ROTATE_EXTRUDE + ' ');
  1495. this.appendValueInput('FACES')
  1496. .setCheck('Number')
  1497. .appendField(Blockscad.Msg.SIDES)
  1498. .setAlign(Blockly.ALIGN_RIGHT);
  1499. this.appendStatementInput('A')
  1500. .setCheck('CAG');
  1501. this.setInputsInline(true);
  1502. this.setPreviousStatement(true, 'CSG');
  1503. this.setTooltip(Blockscad.Msg.ROTATEEXTRUDE_TOOLTIP);
  1504. // try to set up a mutator - Jennie
  1505. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1506. this.plusCount_ = 0;
  1507. },
  1508. mutationToDom: function() {
  1509. if (!this.plusCount_) {
  1510. return null;
  1511. }
  1512. var container = document.createElement('mutation');
  1513. if (this.plusCount_) {
  1514. container.setAttribute('plus',this.plusCount_);
  1515. }
  1516. return container;
  1517. },
  1518. domToMutation: function(xmlElement) {
  1519. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1520. var mytype = this.getInput('A').connection.check_;
  1521. for (var x = 1; x <= this.plusCount_; x++) {
  1522. this.appendStatementInput('PLUS' + x)
  1523. .setCheck(mytype);
  1524. }
  1525. if (this.plusCount_ >= 1) {
  1526. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1527. }
  1528. },
  1529. updateShape_ : function(num) {
  1530. if (num == 1) {
  1531. this.plusCount_++;
  1532. var mytype = this.getInput('A').connection.check_;
  1533. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1534. .setCheck(mytype);
  1535. } else if (num == -1) {
  1536. this.removeInput('PLUS' + this.plusCount_);
  1537. this.plusCount_--;
  1538. }
  1539. if (this.plusCount_ >= 1) {
  1540. if (this.plusCount_ == 1) {
  1541. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1542. this.render();
  1543. }
  1544. } else {
  1545. this.mutatorMinus.dispose();
  1546. this.mutatorMinus = null;
  1547. this.render();
  1548. }
  1549. }
  1550. };
  1551. Blockly.Blocks['rotateextrudetwist'] = {
  1552. init: function() {
  1553. this.category = 'EXTRUDE';
  1554. this.setHelpUrl('http://www.example.com/');
  1555. this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
  1556. this.appendDummyInput()
  1557. .appendField('Rotate Extrude Twist ');
  1558. this.appendValueInput('RAD')
  1559. .setCheck('Number')
  1560. .appendField('R')
  1561. .setAlign(Blockly.ALIGN_RIGHT);
  1562. this.appendValueInput('FACES')
  1563. .setCheck('Number')
  1564. .appendField('Sides')
  1565. .setAlign(Blockly.ALIGN_RIGHT);
  1566. this.appendValueInput('TWIST')
  1567. .setCheck('Number')
  1568. .appendField('Twist')
  1569. .setAlign(Blockly.ALIGN_RIGHT);
  1570. this.appendValueInput('TSTEPS')
  1571. .setCheck('Number')
  1572. .appendField('Twist-steps')
  1573. .setAlign(Blockly.ALIGN_RIGHT);
  1574. this.appendStatementInput('A')
  1575. .setCheck('CAG');
  1576. this.setInputsInline(true);
  1577. this.setPreviousStatement(true, 'CSG');
  1578. this.setTooltip('Rotate extrudes shape translated by radius around the Z axis with a specified number of sides. ');
  1579. // try to set up a mutator - Jennie
  1580. this.setMutatorPlus(new Blockly.MutatorPlus(this));
  1581. this.plusCount_ = 0;
  1582. },
  1583. mutationToDom: function() {
  1584. if (!this.plusCount_) {
  1585. return null;
  1586. }
  1587. var container = document.createElement('mutation');
  1588. if (this.plusCount_) {
  1589. container.setAttribute('plus',this.plusCount_);
  1590. }
  1591. return container;
  1592. },
  1593. domToMutation: function(xmlElement) {
  1594. this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
  1595. var mytype = this.getInput('A').connection.check_;
  1596. for (var x = 1; x <= this.plusCount_; x++) {
  1597. this.appendStatementInput('PLUS' + x)
  1598. .setCheck(mytype);
  1599. }
  1600. if (this.plusCount_ >= 1) {
  1601. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1602. }
  1603. },
  1604. updateShape_ : function(num) {
  1605. if (num == 1) {
  1606. this.plusCount_++;
  1607. var mytype = this.getInput('A').connection.check_;
  1608. var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
  1609. .setCheck(mytype);
  1610. } else if (num == -1) {
  1611. this.removeInput('PLUS' + this.plusCount_);
  1612. this.plusCount_--;
  1613. }
  1614. if (this.plusCount_ >= 1) {
  1615. if (this.plusCount_ == 1) {
  1616. this.setMutatorMinus(new Blockly.MutatorMinus(this));
  1617. this.render();
  1618. }
  1619. } else {
  1620. this.mutatorMinus.dispose();
  1621. this.mutatorMinus = null;
  1622. this.render();
  1623. }
  1624. }
  1625. };
  1626. // math_angle block added for BlocksCAD - Jennie jayod
  1627. Blockly.Blocks['math_angle'] = {
  1628. // Numeric value, but in an angle field.
  1629. init: function() {
  1630. //this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);
  1631. this.setColour(Blockscad.Toolbox.HEX_MATH);
  1632. this.appendDummyInput()
  1633. .appendField(new Blockly.FieldAngle('0'), 'NUM');
  1634. this.setOutput(true, 'Number');
  1635. //this.setTooltip(Blockly.Msg.MATH_NUMBER_TOOLTIP);
  1636. }
  1637. };
  1638. // this is just like the blockly math constant block, but with no infinity constant.
  1639. // I moved it here and renamed it so we don't have to change it with every Blockly sync.
  1640. Blockly.Blocks['math_constant_bs'] = {
  1641. /**
  1642. * Block for constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2)
  1643. * @this Blockly.Block
  1644. */
  1645. init: function() {
  1646. var CONSTANTS =
  1647. [['\u03c0', 'PI'],
  1648. ['e', 'E'],
  1649. ['\u03c6', 'GOLDEN_RATIO'],
  1650. ['sqrt(2)', 'SQRT2'],
  1651. ['sqrt(\u00bd)', 'SQRT1_2']];
  1652. this.setHelpUrl(Blockly.Msg.MATH_CONSTANT_HELPURL);
  1653. this.setColour(Blockscad.Toolbox.HEX_MATH);
  1654. this.setOutput(true, 'Number');
  1655. this.appendDummyInput()
  1656. .appendField(new Blockly.FieldDropdown(CONSTANTS), 'CONSTANT');
  1657. this.setTooltip(Blockly.Msg.MATH_CONSTANT_TOOLTIP);
  1658. }
  1659. };
  1660. // I want a block for stl import (file).
  1661. Blockly.Blocks['stl_import'] = {
  1662. init: function() {
  1663. this.category = 'PRIMITIVE_CSG'
  1664. this.appendDummyInput()
  1665. .appendField(Blockscad.Msg.IMPORT_STL);
  1666. this.appendDummyInput('')
  1667. .setAlign(Blockly.ALIGN_RIGHT)
  1668. .appendField(new Blockly.FieldLabel(""),'STL_FILENAME');
  1669. this.appendDummyInput('')
  1670. .setAlign(Blockly.ALIGN_RIGHT)
  1671. .appendField(new Blockly.FieldButton(Blockscad.Msg.BROWSE),'STL_BUTTON');
  1672. this.appendDummyInput('C')
  1673. .appendField(new Blockly.FieldLabel(""),'STL_CONTENTS')
  1674. .setVisible(false);
  1675. this.setInputsInline(true);
  1676. this.setPreviousStatement(true);
  1677. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  1678. this.setTooltip('');
  1679. this.setWarningText(Blockscad.Msg.STL_IMPORT_WARNING);
  1680. this.setHelpUrl('http://www.example.com/');
  1681. },
  1682. onchange: function() {
  1683. if (!this.workspace) {
  1684. // Block has been deleted.
  1685. return;
  1686. }
  1687. // if one of the value fields is missing, I want to pop up a warning.
  1688. var fn = this.getField('STL_FILENAME').getText();
  1689. var contents = this.getField('STL_CONTENTS').getText();
  1690. if (fn.length > 0) {
  1691. this.getField('STL_BUTTON').setVisible(false);
  1692. this.setCommentText(fn + '\ncenter: (' + Blockscad.csg_center[contents] + ')');
  1693. }
  1694. this.getField('STL_CONTENTS').setVisible(false);
  1695. // this.render();
  1696. }
  1697. };
  1698. // the original text block, in amazing 2D (CAG)
  1699. Blockly.Blocks['bs_text'] = {
  1700. /**
  1701. * Block for text value.
  1702. * @this Blockly.Block
  1703. */
  1704. init: function() {
  1705. // load up the font names and positions
  1706. var CONSTANTS = [];
  1707. for (var i=0; i<Blockscad.fontName.length; i++) {
  1708. CONSTANTS.push([Blockscad.fontName[i],i.toString()]);
  1709. }
  1710. this.category = 'PRIMITIVE_CAG'
  1711. this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);
  1712. this.appendValueInput('TEXT')
  1713. .appendField(Blockscad.Msg.BLOCK_TEXT_2D)
  1714. // .setCheck('String')
  1715. .setAlign(Blockly.ALIGN_RIGHT);
  1716. this.appendValueInput("SIZE")
  1717. .setCheck("Number")
  1718. .appendField(" " + Blockscad.Msg.FONT_SIZE)
  1719. .setAlign(Blockly.ALIGN_RIGHT);
  1720. this.appendDummyInput()
  1721. .appendField(" " + Blockscad.Msg.FONT_NAME)
  1722. .appendField(new Blockly.FieldDropdown(CONSTANTS), 'FONT');
  1723. this.setInputsInline(true);
  1724. this.setPreviousStatement(true, 'CAG');
  1725. this.setColour(Blockscad.Toolbox.HEX_2D_PRIMITIVE);
  1726. this.setTooltip(Blockscad.Msg.BS_TEXT_TOOLTIP);
  1727. },
  1728. /**
  1729. * Create an image of an open or closed quote.
  1730. * @param {boolean} open True if open quote, false if closed.
  1731. * @return {!Blockly.FieldImage} The field image of the quote.
  1732. * @this Blockly.Block
  1733. * @private
  1734. */
  1735. newQuote_: function(open) {
  1736. if (open == this.RTL) {
  1737. var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
  1738. } else {
  1739. var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
  1740. }
  1741. return new Blockly.FieldImage(file, 12, 12, '"');
  1742. }
  1743. };
  1744. // a 3D text block.
  1745. Blockly.Blocks['bs_3dtext'] = {
  1746. /**
  1747. * Block for text value.
  1748. * @this Blockly.Block
  1749. */
  1750. init: function() {
  1751. // load up the font names and positions
  1752. var CONSTANTS = [];
  1753. for (var i=0; i<Blockscad.fontName.length; i++) {
  1754. CONSTANTS.push([Blockscad.fontName[i],i.toString()]);
  1755. }
  1756. this.category = 'PRIMITIVE_CSG'
  1757. this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);
  1758. this.appendValueInput('TEXT')
  1759. .appendField(Blockscad.Msg.BLOCK_TEXT_3D)
  1760. // .setCheck('String')
  1761. .setAlign(Blockly.ALIGN_RIGHT);
  1762. this.appendValueInput("SIZE")
  1763. .setCheck("Number")
  1764. .appendField(" " + Blockscad.Msg.FONT_SIZE)
  1765. .setAlign(Blockly.ALIGN_RIGHT);
  1766. this.appendDummyInput()
  1767. .appendField(" " + Blockscad.Msg.FONT_NAME)
  1768. .appendField(new Blockly.FieldDropdown(CONSTANTS), 'FONT');
  1769. this.appendValueInput('THICKNESS')
  1770. .appendField(" " + Blockscad.Msg.TEXT_THICKNESS)
  1771. .setCheck('Number')
  1772. .setAlign(Blockly.ALIGN_RIGHT);
  1773. this.setInputsInline(true);
  1774. this.setPreviousStatement(true, 'CSG');
  1775. this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
  1776. this.setTooltip(Blockscad.Msg.BS_3DTEXT_TOOLTIP);
  1777. },
  1778. /**
  1779. * Create an image of an open or closed quote.
  1780. * @param {boolean} open True if open quote, false if closed.
  1781. * @return {!Blockly.FieldImage} The field image of the quote.
  1782. * @this Blockly.Block
  1783. * @private
  1784. */
  1785. newQuote_: function(open) {
  1786. if (open == this.RTL) {
  1787. var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
  1788. } else {
  1789. var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
  1790. }
  1791. return new Blockly.FieldImage(file, 12, 12, '"');
  1792. }
  1793. };
  1794. function hideMyInput(value,drawMe) {
  1795. if (drawMe) {
  1796. Blockscad.executeAfterDrag_(function() {
  1797. if (value.isVisible()) {
  1798. //console.log("trying to hide input",value);
  1799. value.setVisible(false);
  1800. }
  1801. value.sourceBlock_.render();
  1802. }, value);
  1803. }
  1804. }
  1805. function showMyInput(value,drawMe) {
  1806. if (!value.isVisible() && drawMe) {
  1807. Blockscad.executeAfterDrag_(function() {
  1808. // console.log(value);
  1809. var blocks_to_render = value.setVisible(true);
  1810. if (blocks_to_render.length > 0)
  1811. blocks_to_render[0].render();
  1812. }, value);
  1813. }
  1814. }
  1815. Blockly.Blocks['bs_text_length'] = {
  1816. /**
  1817. * Block for string length.
  1818. * @this Blockly.Block
  1819. */
  1820. init: function() {
  1821. this.setHelpUrl(Blockly.Msg.TEXT_LENGTH_HELPURL);
  1822. this.setColour(Blockscad.Toolbox.HEX_TEXT);
  1823. this.interpolateMsg(Blockly.Msg.TEXT_LENGTH_TITLE,
  1824. ['VALUE', ['String', 'Array'], Blockly.ALIGN_RIGHT],
  1825. Blockly.ALIGN_RIGHT);
  1826. this.setOutput(true, 'Number');
  1827. this.setTooltip(Blockly.Msg.TEXT_LENGTH_TOOLTIP);
  1828. }
  1829. };