123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893 |
- goog.require('Blockly.Blocks');
- //goog.require('Blockly.MutatorPlus');
- Blockly.Blocks['sphere'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.SPHERE + " ");
- this.appendValueInput("RAD")
- .setCheck("Number")
- .appendField(Blockscad.Msg.RADIUS)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.SPHERE_TOOLTIP);
- }//,
- // onchange: function() {
- // if (!this.workspace) {
- // // Block has been deleted.
- // return;
- // }
- // // if one of the value fields is missing, I want to pop up a warning.
- // var val = this.getInput("RAD").connection;
- // if (!val.targetConnection)
- // this.setWarningText("Sphere requires a radius to be set");
- // else this.setWarningText(null);
- // }
- };
- // Blockly.Blocks['sphere'] = {
- // init: function() {
- // this.category = 'PRIMITIVE_CSG'
- // this.setHelpUrl('http://www.example.com/');
- // this.setColourHex(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- // this.appendDummyInput()
- // .appendField(Blockscad.Msg.SPHERE + " ");
- // this.appendValueInput("RAD")
- // .setCheck("Number")
- // .appendField(Blockscad.Msg.RADIUS)
- // .setAlign(Blockly.ALIGN_RIGHT);
- // this.setInputsInline(true);
- // this.setPreviousStatement(true, 'CSG');
- // this.setTooltip(Blockscad.Msg.SPHERE_TOOLTIP);
- // }//,
- // };
- Blockly.Blocks['cylinder'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG';
- this.prevR1 = null;
- this.prevR2 = null;
- this.pR1id = null;
- this.pR2id = null;
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.CYLINDER + ' ');
- this.appendValueInput('RAD1')
- .setCheck('Number')
- .appendField(Blockscad.Msg.RADIUS + '1')
- .setAlign(Blockly.ALIGN_RIGHT);
- // handle backwards compatibility for cylinders created before locking.
- if (Blockscad.inputVersion == null || Blockscad.inputVersion == "1.0.0"
- || Blockscad.inputVersion == "1.0.1" || Blockscad.inputVersion == "1.1.0") {
- this.appendDummyInput()
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(new Blockly.FieldCheckbox("FALSE", null,
- "imgs/lock_icon.png","imgs/unlock_icon.png"), "LOCKED");
- }
- else {
- this.appendDummyInput()
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(new Blockly.FieldCheckbox("TRUE", null,
- "imgs/lock_icon.png","imgs/unlock_icon.png"), "LOCKED") ;
- }
- // this.appendDummyInput()
- // .setAlign(Blockly.ALIGN_RIGHT)
- // .appendField(new Blockly.FieldCheckbox("TRUE", null), "CHECK") ;
- this.appendValueInput('RAD2')
- .setCheck('Number')
- .appendField(Blockscad.Msg.RADIUS + '2')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('HEIGHT')
- .setCheck('Number')
- .appendField(Blockscad.Msg.HEIGHT)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.CYLINDER_TOOLTIP);
- },
- updateRadii: function() {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- // console.log('in updateRadii');
- var locked = this.getField("LOCKED").getValue();
- if (locked == 'FALSE') {
- return;
- }
- var R1 = null;
- var R2 = null;
- // get the values (if any) attached to the two radius inputs.
- if (this.getInput('RAD1').connection.targetConnection &&
- this.getInput('RAD1').connection.targetConnection.sourceBlock_.type == "math_number") {
- R1 = this.getInput('RAD1').connection.targetConnection.sourceBlock_.getField('NUM').getValue();
- }
- if (this.getInput('RAD2').connection.targetConnection &&
- this.getInput('RAD2').connection.targetConnection.sourceBlock_.type == "math_number") {
- R2 = this.getInput('RAD2').connection.targetConnection.sourceBlock_.getField('NUM').getValue();
- }
- if (locked == 'TRUE' && R1 && R2 && R1 != R2) {
- if (R1 != this.prevR1) {
- this.getInput('RAD2').connection.targetConnection.sourceBlock_.getField('NUM').setValue(R1,true);
- }
- else if (R2 != this.prevR2) {
- this.getInput('RAD1').connection.targetConnection.sourceBlock_.getField('NUM').setValue(R2,true);
- }
- // if you set locking on two different radii, do you want them to both take the value of R1?
- // else if (R1 != R2) this.getInput('RAD2').connection.targetConnection.sourceBlock_.getField('NUM').setValue(R1);
- }
- this.prevR1 = R1;
- this.prevR2 = R2;
- // console.log("in cylinder onchange. R1 R2 pR1 pR2", R1, R2, this.prevR1, this.prevR2);
- }
- };
- // planning not to use this.
- Blockly.Blocks['simple_cylinder'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.CYLINDER + ' ');
- this.appendValueInput('RAD1')
- .setCheck('Number')
- .appendField(Blockscad.Msg.RADIUS)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('HEIGHT')
- .setCheck('Number')
- .appendField(Blockscad.Msg.HEIGHT)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip('Creates a cylinder with a specified radius and height. It may optionally be centered at the origin.');
- }//,
- };
- Blockly.Blocks['cube'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.CUBE + ' ');
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField('X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('ZVAL')
- .setCheck('Number')
- .appendField('Z')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- //this.setNextStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.CUBE_TOOLTIP);
- }//,
- // onchange: function() {
- // if (!this.workspace) {
- // // Block has been deleted.
- // return;
- // }
- // // if one of the value fields is missing, I want to pop up a warning.
- // var val1 = this.getInput("XVAL").connection;
- // var val2 = this.getInput("YVAL").connection;
- // var val3 = this.getInput("ZVAL").connection;
- // if (val1.targetConnection && val2.targetConnection && val3.targetConnection)
- // this.setWarningText(null);
- // else this.setWarningText("Cube needs all paramaters to have number values");
- // }
- };
- Blockly.Blocks['torus'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.TORUS + ' ');
- this.appendValueInput('RAD1')
- .setCheck('Number')
- .appendField( Blockscad.Msg.RADIUS + '1')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('RAD2')
- .setCheck('Number')
- .appendField(Blockscad.Msg.RADIUS + '2')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('SIDES')
- .setCheck('Number')
- .appendField(Blockscad.Msg.SIDES)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('FACES')
- .setCheck('Number')
- .appendField(Blockscad.Msg.FACES)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.TORUS_TOOLTIP);
- }//,
- // onchange: function() {
- // if (!this.workspace) {
- // // Block has been deleted.
- // return;
- // }
- // // if one of the value fields is missing, I want to pop up a warning.
- // var val1 = this.getInput("RAD1").connection;
- // var val2 = this.getInput("RAD2").connection;
- // var val3 = this.getInput("SIDES").connection;
- // var val4 = this.getInput("FACES").connection;
- // if (val1.targetConnection && val2.targetConnection && val3.targetConnection
- // && val4.targetConnection)
- // this.setWarningText(null);
- // else this.setWarningText("Torus needs all paramaters to have number values");
- // }
- };
- Blockly.Blocks['twistytorus'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.appendDummyInput()
- .appendField('Twisty Torus ');
- this.appendValueInput('RAD1')
- .setCheck('Number')
- .appendField('ring radius')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('RAD2')
- .setCheck('Number')
- .appendField('cross-section radius')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('SIDES')
- .setCheck('Number')
- .appendField('ring sides')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('FACES')
- .setCheck('Number')
- .appendField('cross section faces')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('TWIST')
- .setCheck('Number')
- .appendField('twist (degrees)')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- 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');
- }//,
- // onchange: function() {
- // if (!this.workspace) {
- // // Block has been deleted.
- // return;
- // }
- // // if one of the value fields is missing, I want to pop up a warning.
- // var val1 = this.getInput("RAD1").connection;
- // var val2 = this.getInput("RAD2").connection;
- // var val3 = this.getInput("SIDES").connection;
- // var val4 = this.getInput("FACES").connection;
- // if (val1.targetConnection && val2.targetConnection && val3.targetConnection
- // && val4.targetConnection)
- // this.setWarningText(null);
- // else this.setWarningText("Torus needs all paramaters to have number values");
- // }
- };
- Blockly.Blocks['circle'] = {
- init: function() {
- this.category = 'PRIMITIVE_CAG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_2D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.CIRCLE + ' ');
- this.appendValueInput('RAD')
- .setCheck('Number')
- .appendField(Blockscad.Msg.RADIUS)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CAG');
- this.setTooltip(Blockscad.Msg.CIRCLE_TOOLTIP);
- }//,
- // onchange: function() {
- // if (!this.workspace) {
- // // Block has been deleted.
- // return;
- // }
- // // if one of the value fields is missing, I want to pop up a warning.
- // var val = this.getInput("RAD").connection;
- // if (!val.targetConnection)
- // this.setWarningText("Circle requires a radius to be set");
- // else this.setWarningText(null);
- // }
- };
- Blockly.Blocks['square'] = {
- init: function() {
- this.category = 'PRIMITIVE_CAG'
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_2D_PRIMITIVE);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.SQUARE + ' ');
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField('X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CAG');
- this.setTooltip(Blockscad.Msg.SQUARE_TOOLTIP);
- }//,
- // onchange: function() {
- // if (!this.workspace) {
- // // Block has been deleted.
- // return;
- // }
- // // if one of the value fields is missing, I want to pop up a warning.
- // var val1 = this.getInput("XVAL").connection;
- // var val2 = this.getInput("YVAL").connection;
- // if (val1.targetConnection && val2.targetConnection)
- // this.setWarningText(null);
- // else this.setWarningText("Square needs all paramaters to have number values");
- // }
- };
- Blockly.Blocks['translate'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.TRANSLATE);
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField('X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('ZVAL')
- .setCheck('Number')
- .appendField('Z')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.TRANSLATE_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * and whether ZVAL field exists.
- * only call the drawing routines if the type is actually changing.
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- if (!goog.isArray(type))
- type = [type];
- var zval = this.getInput('ZVAL');
- var next = this.getInput('A');
- var myType = this.previousConnection.check_;
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- if (type[0] == 'CAG' && myType[0] == 'CSG') {
- hideMyInput(zval,drawMe);
- }
- else if (type[0] == 'CSG' && myType[0] == 'CAG') {
- showMyInput(zval,drawMe);
- }
- // console.log("translate type has become",this.previousConnection.check_);
- //console.log(this.getInput('A').connection.check_);
- }
- };
- Blockly.Blocks['scale'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.SCALE);
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField('X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('ZVAL')
- .setCheck('Number')
- .appendField('Z')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.SCALE_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * and whether ZVAL field exists.
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- if (!goog.isArray(type))
- type = [type];
- var zval = this.getInput('ZVAL');
- var next = this.getInput('A');
- var myType = this.previousConnection.check_;
-
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- if (type[0] == 'CAG' && myType[0] == 'CSG') {
- hideMyInput(zval,drawMe);
- }
- else if (type[0] == 'CSG' && myType[0] == 'CAG') {
- showMyInput(zval,drawMe);
- }
- }
- };
- // Blockly.Blocks['resize'] = {
- // init: function() {
- // this.category = 'TRANSFORM';
- // this.setHelpUrl('http://www.example.com/');
- // this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- // this.appendDummyInput()
- // .appendField('Resize');
- // this.appendDummyInput()
- // .appendField('X');
- // this.appendValueInput('XVAL')
- // .setCheck('Number');
- // this.appendDummyInput()
- // .appendField('Y');
- // this.appendValueInput('YVAL')
- // .setCheck('Number');
- // this.appendDummyInput()
- // .appendField('Z');
- // this.appendValueInput('ZVAL')
- // .setCheck('Number');
- // this.appendStatementInput('A')
- // .setCheck('CSG');
- // this.setInputsInline(true);
- // this.setPreviousStatement(true, 'CSG');
- // this.setTooltip('');
- // }
- // };
- Blockly.Blocks['fancymirror'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.MIRROR_ADVANCED);
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField('X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('ZVAL')
- .setCheck('Number')
- .appendField('Z')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.FANCYMIRROR_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- var zval = this.getInput('ZVAL');
- this.previousConnection.setCheck(type);
- this.getInput('A').connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- }
- };
- Blockly.Blocks['simplemirror'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField('Simple Mirror');
- this.appendDummyInput()
- .appendField('across')
- .appendField(new Blockly.FieldDropdown([['+', 'pos'], ['-', 'neg']]), 'sign')
- .appendField(new Blockly.FieldDropdown([['XY', 'XY'], ['YZ', 'YZ'], ['XZ', 'XZ']]), 'mirrorplane');
- this.appendStatementInput('A')
- .setCheck('CSG');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.SIMPLEMIRROR_TOOLTIP);
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- var next = this.getInput('A');
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- }
- };
- Blockly.Blocks['simplemirror_new'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.MIRROR);
- this.appendDummyInput('3D')
- .appendField(Blockscad.Msg.ACROSS)
- .appendField(new Blockly.FieldDropdown([['XY', 'XY'], ['YZ', 'YZ'], ['XZ', 'XZ']]), 'mirrorplane');
- this.appendDummyInput('2D')
- .appendField(Blockscad.Msg.ACROSS)
- .appendField(new Blockly.FieldDropdown([['YZ', 'YZ'], ['XZ', 'XZ']]), 'mirrorplane_cag')
- .setVisible(false);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.SIMPLEMIRROR_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * and whether ZVAL field exists.
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- if (!goog.isArray(type))
- type = [type];
- // var csg = this.getField_('mirrorplane');
- // var cag = this.getField_('mirrorplane_cag');
- var csg = this.getInput('3D');
- var cag = this.getInput('2D');
- var next = this.getInput('A');
- var myType = this.previousConnection.check_;
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- if (type[0] == 'CAG' && myType[0] == 'CSG') {
- hideMyInput(csg,drawMe);
- showMyInput(cag,drawMe);
- }
- else if (type[0] == 'CSG' && myType[0] == 'CAG') {
- hideMyInput(cag,drawMe);
- showMyInput(csg,drawMe);
- }
- }
- };
- Blockly.Blocks['taper'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.TAPER);
- this.appendDummyInput('3D')
- .appendField(Blockscad.Msg.ALONG + ' ')
- .appendField(new Blockly.FieldDropdown([['X', 'X'], ['Y', 'Y'], ['Z', 'Z']]), 'taperaxis')
- .appendField(Blockscad.Msg.AXIS);
- this.appendDummyInput('2D')
- .appendField(Blockscad.Msg.ALONG + ' ')
- .appendField(new Blockly.FieldDropdown([['X', 'X'], ['Y', 'Y']]), 'taperaxis_cag')
- .appendField(Blockscad.Msg.AXIS)
- .setVisible(false);
- this.appendValueInput('FACTOR')
- .setCheck('Number')
- .appendField(Blockscad.Msg.SCALE)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.TAPER_TOOLTIP);
- this.setWarningText(Blockscad.Msg.NOT_COMPATIBLE_WITH_OPENSCAD);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * and whether ZVAL field exists.
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- if (!goog.isArray(type))
- type = [type];
- var csg = this.getInput('3D');
- var cag = this.getInput('2D');
- var next = this.getInput('A');
- var myType = this.previousConnection.check_;
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- if (type[0] == 'CAG' && myType[0] == 'CSG') {
- hideMyInput(csg,drawMe);
- showMyInput(cag,drawMe);
- }
- else if (type[0] == 'CSG' && myType[0] == 'CAG') {
- hideMyInput(cag,drawMe);
- showMyInput(csg,drawMe);
- if (drawMe) this.render();
- }
- }
- };
- Blockly.Blocks['simplerotate'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.ROTATE);
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField('X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('ZVAL')
- .setCheck('Number')
- .appendField('Z')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.SIMPLEROTATE_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * and whether ZVAL field exists.
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- // don't hide x and y axes for rotation - openscad creates a projection.
- // var xval = this.getInput('XVAL');
- // var yval = this.getInput('YVAL');
- var next = this.getInput('A');
- // if (type == 'CAG') { // parent wants a 2D shape
- // hideMyInput(xval,drawMe);
- // hideMyInput(yval,drawMe);
- // if (drawMe) this.render();
- // }
- // else { // parent wants 3D or doesn't care
- // showMyInput(xval,drawMe);
- // showMyInput(yval,drawMe);
- // if (drawMe) this.render();
- // }
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- }
- };
- Blockly.Blocks['fancyrotate'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.ROTATE_ADVANCED);
- this.appendValueInput('AVAL')
- .setCheck('Number');
- this.appendValueInput('XVAL')
- .setCheck('Number')
- .appendField(Blockscad.Msg.AROUND + ' X')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YVAL')
- .setCheck('Number')
- .appendField('Y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('ZVAL')
- .setCheck('Number')
- .appendField('Z')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.FANCYROTATE_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- /**
- * If our parent or child is CSG or CAG, that sets our output type
- * and whether ZVAL field exists.
- * @this Blockly.Block
- */
- setType: function(type,drawMe) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- if (!goog.isArray(type))
- type = [type];
- var zval = this.getInput('ZVAL');
- var xval = this.getInput('XVAL');
- var yval = this.getInput('YVAL');
- var next = this.getInput('A');
- var myType = this.previousConnection.check_;
- this.previousConnection.setCheck(type);
- next.connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- if (type[0] == 'CAG' && myType[0] == 'CSG') {
- hideMyInput(xval,drawMe);
- hideMyInput(yval,drawMe);
- hideMyInput(zval,drawMe);
- }
- else if (type[0] == 'CSG' && myType[0] == 'CAG') {
- showMyInput(xval,drawMe);
- showMyInput(yval,drawMe);
- showMyInput(zval,drawMe);
- }
- }
- };
- Blockly.Blocks['color'] = {
- init: function() {
- this.category = 'COLOR';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.COLOR);
- this.appendValueInput('COLOR')
- .setCheck('Colour');
- this.appendStatementInput('A')
- .setCheck('CSG');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.COLOR_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- }
- };
- Blockly.Blocks['color_rgb'] = {
- init: function() {
- this.category = 'COLOR';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.COLOR + ' ');
- var dropdown = new Blockly.FieldDropdown([[Blockscad.Msg.HSV_COLOR_MODEL, 'HSV'],[Blockscad.Msg.RGB_COLOR_MODEL, 'RGB']], function(option) {
- var isRGB = (option == 'RGB');
- this.sourceBlock_.optUpdateShape_(isRGB);
- });
- this.appendDummyInput()
- .appendField(dropdown, 'SCHEME')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('RED')
- .setCheck('Number')
- .appendField(Blockscad.Msg.COLOR_HUE, '1')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('GREEN')
- .setCheck('Number')
- .appendField(Blockscad.Msg.COLOR_SATURATION, '2')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('BLUE')
- .setCheck('Number')
- .appendField(Blockscad.Msg.COLOR_VALUE,'3')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck('CSG');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- var thisBlock = this;
- this.setTooltip(function() {
- var mode = thisBlock.getFieldValue('SCHEME');
- var TOOLTIPS = {
- 'RGB': Blockscad.Msg.COLOR_RGB_TOOLTIP,
- 'HSV': Blockscad.Msg.COLOR_HSV_TOOLTIP
- };
- return TOOLTIPS[mode];
- });
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- // if (!this.plusCount_) {
- // return null;
- // }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- else container.setAttribute('plus', 0);
- var isRGB = (this.getFieldValue('SCHEME') == 'RGB');
- container.setAttribute('isrgb', isRGB);
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- var isRGB = (xmlElement.getAttribute('isrgb') == 'true');
- this.optUpdateShape_(isRGB);
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- if (this.mutatorMinus) this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- } ,
- // if change the labels on the value inputs based on if this is RGB or HSV
- optUpdateShape_: function(isRGB) {
- // make labels match the color schema (RGB or HSV)
- var one = this.getField('1');
- var two = this.getField('2');
- var three = this.getField('3');
- if (isRGB) {
- one.setText(Blockly.Msg.COLOUR_RGB_RED);
- two.setText(Blockly.Msg.COLOUR_RGB_GREEN);
- three.setText(Blockly.Msg.COLOUR_RGB_BLUE);
- }
- else {
- one.setText(Blockscad.Msg.COLOR_HUE);
- two.setText(Blockscad.Msg.COLOR_SATURATION);
- three.setText(Blockscad.Msg.COLOR_VALUE);
- }
- }
- };
- Blockly.Blocks['$fn'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendValueInput('SIDES')
- .setCheck('Number')
- .appendField(Blockscad.Msg.SIDES);
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.FN_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- setType: function(type) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- //console.log("setting union type to",type);
- this.previousConnection.setCheck(type);
- this.getInput('A').connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- }
- };
- Blockly.Blocks['assign'] = {
- init: function() {
- this.category = 'TRANSFORM';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendValueInput('NAME')
- .appendField("set ")
- // .setCheck('String')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('VALUE')
- .setCheck('Number')
- .appendField(' = ');
- this.appendStatementInput('A')
- .setCheck(['CSG','CAG']);
- this.setInputsInline(true);
- this.setPreviousStatement(true, ['CSG','CAG']);
- this.setTooltip(Blockscad.Msg.FN_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- },
- setType: function(type) {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- //console.log("setting union type to",type);
- this.previousConnection.setCheck(type);
- this.getInput('A').connection.setCheck(type);
- for (var i = 1; i <= this.plusCount_; i++) {
- this.getInput('PLUS' + i).connection.setCheck(type);
- }
- }
- };
- Blockly.Blocks['linearextrude'] = {
- init: function() {
- this.category = 'EXTRUDE';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.LINEAR_EXTRUDE + ' ');
- this.appendValueInput('HEIGHT')
- .setCheck('Number')
- .appendField(Blockscad.Msg.HEIGHT)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('TWIST')
- .setCheck('Number')
- .appendField(Blockscad.Msg.TWIST)
- .setAlign(Blockly.ALIGN_RIGHT);
- // this.appendDummyInput()
- // .appendField('scale: ')
- // .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('XSCALE')
- .setCheck('Number')
- .appendField(Blockscad.Msg.SCALE + ': x')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('YSCALE')
- .setCheck('Number')
- .appendField('y')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown([[Blockscad.Msg.NOT_CENTERED, 'false'], [Blockscad.Msg.CENTERED, 'true']]), 'CENTERDROPDOWN')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck('CAG');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.LINEAREXTRUDE_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- }
- };
- Blockly.Blocks['rotateextrude'] = {
- init: function() {
- this.category = 'EXTRUDE';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField(Blockscad.Msg.ROTATE_EXTRUDE + ' ');
- this.appendValueInput('FACES')
- .setCheck('Number')
- .appendField(Blockscad.Msg.SIDES)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck('CAG');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip(Blockscad.Msg.ROTATEEXTRUDE_TOOLTIP);
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- }
- };
- Blockly.Blocks['rotateextrudetwist'] = {
- init: function() {
- this.category = 'EXTRUDE';
- this.setHelpUrl('http://www.example.com/');
- this.setColour(Blockscad.Toolbox.HEX_TRANSFORM);
- this.appendDummyInput()
- .appendField('Rotate Extrude Twist ');
- this.appendValueInput('RAD')
- .setCheck('Number')
- .appendField('R')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('FACES')
- .setCheck('Number')
- .appendField('Sides')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('TWIST')
- .setCheck('Number')
- .appendField('Twist')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput('TSTEPS')
- .setCheck('Number')
- .appendField('Twist-steps')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendStatementInput('A')
- .setCheck('CAG');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setTooltip('Rotate extrudes shape translated by radius around the Z axis with a specified number of sides. ');
- // try to set up a mutator - Jennie
- this.setMutatorPlus(new Blockly.MutatorPlus(this));
- this.plusCount_ = 0;
- },
- mutationToDom: function() {
- if (!this.plusCount_) {
- return null;
- }
- var container = document.createElement('mutation');
- if (this.plusCount_) {
- container.setAttribute('plus',this.plusCount_);
- }
- return container;
- },
- domToMutation: function(xmlElement) {
- this.plusCount_ = parseInt(xmlElement.getAttribute('plus'), 10);
- var mytype = this.getInput('A').connection.check_;
- for (var x = 1; x <= this.plusCount_; x++) {
- this.appendStatementInput('PLUS' + x)
- .setCheck(mytype);
- }
- if (this.plusCount_ >= 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- }
- },
- updateShape_ : function(num) {
- if (num == 1) {
- this.plusCount_++;
- var mytype = this.getInput('A').connection.check_;
- var plusInput = this.appendStatementInput('PLUS' + this.plusCount_)
- .setCheck(mytype);
- } else if (num == -1) {
- this.removeInput('PLUS' + this.plusCount_);
- this.plusCount_--;
- }
- if (this.plusCount_ >= 1) {
- if (this.plusCount_ == 1) {
- this.setMutatorMinus(new Blockly.MutatorMinus(this));
- this.render();
- }
- } else {
- this.mutatorMinus.dispose();
- this.mutatorMinus = null;
- this.render();
- }
- }
- };
- // math_angle block added for BlocksCAD - Jennie jayod
- Blockly.Blocks['math_angle'] = {
- // Numeric value, but in an angle field.
- init: function() {
- //this.setHelpUrl(Blockly.Msg.MATH_NUMBER_HELPURL);
- this.setColour(Blockscad.Toolbox.HEX_MATH);
- this.appendDummyInput()
- .appendField(new Blockly.FieldAngle('0'), 'NUM');
- this.setOutput(true, 'Number');
- //this.setTooltip(Blockly.Msg.MATH_NUMBER_TOOLTIP);
- }
- };
- // this is just like the blockly math constant block, but with no infinity constant.
- // I moved it here and renamed it so we don't have to change it with every Blockly sync.
- Blockly.Blocks['math_constant_bs'] = {
- /**
- * Block for constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2)
- * @this Blockly.Block
- */
- init: function() {
- var CONSTANTS =
- [['\u03c0', 'PI'],
- ['e', 'E'],
- ['\u03c6', 'GOLDEN_RATIO'],
- ['sqrt(2)', 'SQRT2'],
- ['sqrt(\u00bd)', 'SQRT1_2']];
- this.setHelpUrl(Blockly.Msg.MATH_CONSTANT_HELPURL);
- this.setColour(Blockscad.Toolbox.HEX_MATH);
- this.setOutput(true, 'Number');
- this.appendDummyInput()
- .appendField(new Blockly.FieldDropdown(CONSTANTS), 'CONSTANT');
- this.setTooltip(Blockly.Msg.MATH_CONSTANT_TOOLTIP);
- }
- };
- // I want a block for stl import (file).
- Blockly.Blocks['stl_import'] = {
- init: function() {
- this.category = 'PRIMITIVE_CSG'
- this.appendDummyInput()
- .appendField(Blockscad.Msg.IMPORT_STL);
- this.appendDummyInput('')
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(new Blockly.FieldLabel(""),'STL_FILENAME');
- this.appendDummyInput('')
- .setAlign(Blockly.ALIGN_RIGHT)
- .appendField(new Blockly.FieldButton(Blockscad.Msg.BROWSE),'STL_BUTTON');
- this.appendDummyInput('C')
- .appendField(new Blockly.FieldLabel(""),'STL_CONTENTS')
- .setVisible(false);
- this.setInputsInline(true);
- this.setPreviousStatement(true);
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.setTooltip('');
- this.setWarningText(Blockscad.Msg.STL_IMPORT_WARNING);
- this.setHelpUrl('http://www.example.com/');
- },
- onchange: function() {
- if (!this.workspace) {
- // Block has been deleted.
- return;
- }
- // if one of the value fields is missing, I want to pop up a warning.
- var fn = this.getField('STL_FILENAME').getText();
- var contents = this.getField('STL_CONTENTS').getText();
- if (fn.length > 0) {
- this.getField('STL_BUTTON').setVisible(false);
- this.setCommentText(fn + '\ncenter: (' + Blockscad.csg_center[contents] + ')');
- }
- this.getField('STL_CONTENTS').setVisible(false);
- // this.render();
- }
- };
- // the original text block, in amazing 2D (CAG)
- Blockly.Blocks['bs_text'] = {
- /**
- * Block for text value.
- * @this Blockly.Block
- */
- init: function() {
- // load up the font names and positions
- var CONSTANTS = [];
- for (var i=0; i<Blockscad.fontName.length; i++) {
- CONSTANTS.push([Blockscad.fontName[i],i.toString()]);
- }
- this.category = 'PRIMITIVE_CAG'
- this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);
- this.appendValueInput('TEXT')
- .appendField(Blockscad.Msg.BLOCK_TEXT_2D)
- // .setCheck('String')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput("SIZE")
- .setCheck("Number")
- .appendField(" " + Blockscad.Msg.FONT_SIZE)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(" " + Blockscad.Msg.FONT_NAME)
- .appendField(new Blockly.FieldDropdown(CONSTANTS), 'FONT');
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CAG');
- this.setColour(Blockscad.Toolbox.HEX_2D_PRIMITIVE);
- this.setTooltip(Blockscad.Msg.BS_TEXT_TOOLTIP);
- },
- /**
- * Create an image of an open or closed quote.
- * @param {boolean} open True if open quote, false if closed.
- * @return {!Blockly.FieldImage} The field image of the quote.
- * @this Blockly.Block
- * @private
- */
- newQuote_: function(open) {
- if (open == this.RTL) {
- var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
- } else {
- var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
- }
- return new Blockly.FieldImage(file, 12, 12, '"');
- }
- };
- // a 3D text block.
- Blockly.Blocks['bs_3dtext'] = {
- /**
- * Block for text value.
- * @this Blockly.Block
- */
- init: function() {
- // load up the font names and positions
- var CONSTANTS = [];
- for (var i=0; i<Blockscad.fontName.length; i++) {
- CONSTANTS.push([Blockscad.fontName[i],i.toString()]);
- }
- this.category = 'PRIMITIVE_CSG'
- this.setHelpUrl(Blockly.Msg.TEXT_TEXT_HELPURL);
- this.appendValueInput('TEXT')
- .appendField(Blockscad.Msg.BLOCK_TEXT_3D)
- // .setCheck('String')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendValueInput("SIZE")
- .setCheck("Number")
- .appendField(" " + Blockscad.Msg.FONT_SIZE)
- .setAlign(Blockly.ALIGN_RIGHT);
- this.appendDummyInput()
- .appendField(" " + Blockscad.Msg.FONT_NAME)
- .appendField(new Blockly.FieldDropdown(CONSTANTS), 'FONT');
- this.appendValueInput('THICKNESS')
- .appendField(" " + Blockscad.Msg.TEXT_THICKNESS)
- .setCheck('Number')
- .setAlign(Blockly.ALIGN_RIGHT);
- this.setInputsInline(true);
- this.setPreviousStatement(true, 'CSG');
- this.setColour(Blockscad.Toolbox.HEX_3D_PRIMITIVE);
- this.setTooltip(Blockscad.Msg.BS_3DTEXT_TOOLTIP);
- },
- /**
- * Create an image of an open or closed quote.
- * @param {boolean} open True if open quote, false if closed.
- * @return {!Blockly.FieldImage} The field image of the quote.
- * @this Blockly.Block
- * @private
- */
- newQuote_: function(open) {
- if (open == this.RTL) {
- var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
- } else {
- var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
- }
- return new Blockly.FieldImage(file, 12, 12, '"');
- }
- };
- function hideMyInput(value,drawMe) {
- if (drawMe) {
- Blockscad.executeAfterDrag_(function() {
- if (value.isVisible()) {
- //console.log("trying to hide input",value);
- value.setVisible(false);
- }
- value.sourceBlock_.render();
- }, value);
- }
- }
- function showMyInput(value,drawMe) {
- if (!value.isVisible() && drawMe) {
- Blockscad.executeAfterDrag_(function() {
- // console.log(value);
- var blocks_to_render = value.setVisible(true);
- if (blocks_to_render.length > 0)
- blocks_to_render[0].render();
- }, value);
- }
- }
- Blockly.Blocks['bs_text_length'] = {
- /**
- * Block for string length.
- * @this Blockly.Block
- */
- init: function() {
- this.setHelpUrl(Blockly.Msg.TEXT_LENGTH_HELPURL);
- this.setColour(Blockscad.Toolbox.HEX_TEXT);
- this.interpolateMsg(Blockly.Msg.TEXT_LENGTH_TITLE,
- ['VALUE', ['String', 'Array'], Blockly.ALIGN_RIGHT],
- Blockly.ALIGN_RIGHT);
- this.setOutput(true, 'Number');
- this.setTooltip(Blockly.Msg.TEXT_LENGTH_TOOLTIP);
- }
- };
|