Best JavaScript code snippet using playwright-internal
nodefigure.js
Source:nodefigure.js
1/**2 * Author : Harshal Chaudhari3 *4 * Nov 1-20125 */6/* Todo:7 * create draw2d.Node() and in that create HTML element.8 * It create a draw2d.Node() object */9//define(['buttonDelete', 'outputPort', 'inputPort', 'JSONReader', 'JSONWriter'], function() {10 draw2d.node = function() {11 this.cornerWidth = 15;12 this.cornerHeight = 15;13 this.outputPort = null;14 this.inputPort = null;15 this.disable = false;16 draw2d.Node.call(this);17 this.setDimension(150, 180);18 this.originalHeight = -1;19 this.setResizeable(false);20 };21 draw2d.node.prototype = new draw2d.Node();22 draw2d.node.prototype.type = "draw2d.Node";23 draw2d.node.prototype.setLineWidth = 2;24 draw2d.node.prototype.setColor = "#B9D3F6"25 /* Create HTML element add them on workspace*/26 draw2d.node.prototype.createHTMLElement = function() {27 var item = document.createElement("div");28 item.onmouseover = function() {29 item.style.shadowBlur = 100;30 item.style.shadowColor = "#FFE873";31 }32 $(item).addClass("createElement");33 item.id = this.id;34 $(item).css({35 left : this.x,36 top : this.y,37 height : this.height,38 width : this.width,39 zIndex : draw2d.Figure.ZOrderBaseIndex40 });41 this.top_right = document.createElement("div");42 $(this.top_right).addClass("topright");43 $(this.top_right).css({44 width : this.cornerWidth + 9,45 height : this.cornerHeight + 546 });47 this.tagname = document.createElement("div");48 $(this.tagname).addClass("label");49 $(this.tagname).css({50 height : this.cornerHeight + 651 });52 //this.tagname.innerHTML = "TagName:?";53 this.header = document.createElement("div");54 $(this.header).addClass("header");55 $(this.header).css({56 height : this.cornerHeight + 557 });58 this.textarea = document.createElement("div");59 $(this.textarea).addClass("textarea");60 $(this.textarea).css({61 top : this.cornerHeight + 3162 });63 this.footer = document.createElement("div");64 $(this.footer).addClass("footer");65 $(this.footer).css({66 height : this.cornerHeight + 567 });68 this.btnReset = document.createElement('input');69 $(this.btnReset).attr('type', 'reset');70 $(this.btnReset).attr('name', 'btnreset');71 $(this.btnReset).attr('value', 'Reset');72 item.appendChild(this.top_right);73 item.appendChild(this.header);74 item.appendChild(this.tagname);75 item.appendChild(this.textarea);76 item.appendChild(this.footer);77 item.appendChild(this.btnReset);78 return item;79 };80 /*Todo: set dimension for all html element created in above function. */81 draw2d.node.prototype.setDimension = function(w, h) {82 draw2d.Node.prototype.setDimension.call(this, w, h);83 $(this.top_right).css({84 left : Math.max(1, (this.width - this.cornerWidth - 8))85 });86 //if(this.getnodeName() == "PID" || this.getnodeName() == "AND" || this.getnodeName() == "OR" || this.getnodeName() == "ADD" || this.getnodeName() == "SUB" || this.getnodeName() == "MUL" || this.getnodeName() == "DIV"){87 $(this.textarea).css({88 width : Math.max(1, (this.width - 1)),89 height : Math.max(1, (this.height - this.cornerHeight * 2) - 40)90 });91 $(this.header).css({92 width : Math.max(1, (this.width))93 });94 $(this.tagname).css({95 width : Math.max(1, (this.width))96 });97 $(this.footer).css({98 width : Math.max(1, (this.width)),99 top : Math.max(1, (this.height - this.cornerHeight) - 5)100 });101 $(this.btnReset).css({102 top : Math.max(1, (this.height - this.cornerHeight) + 17)103 });104 if(this.ports.data[1] !== undefined && this.ports.data[1] !== null) {105 this.ports.data[1].setPosition(this.width + 5, (this.height / 2) + 3);106 }107 if(this.ports.data[0] !== undefined) {108 if(this.ports.data[0].name.split("-")[0] == "output") {109 this.ports.data[0].setPosition(this.width + 5, (this.height / 2) + 3);110 } else {111 this.ports.data[0].setPosition(-5, (this.height / 2) + 3);112 }113 }114 };115 /* Add a html button element in draw2d.node object */116 draw2d.node.prototype.addButton = function(id) {117 oThis = this;118 if(id === "counter") {119 $(this.btnReset).addClass("btnreset");120 this.btnReset.style.display = "block";121 }122 };123 draw2d.node.prototype.setheader = function(header) {124 this.header.innerHTML = header;125 };126 draw2d.node.prototype.getheader = function() {127 return $(this.header).text();128 };129 draw2d.node.prototype.setSequenceNo = function(no) {130 this.sequenceNo = no;131 };132 draw2d.node.prototype.getSequenceNo = function() {133 return this.sequenceNo;134 };135 /* Set Title of Node object */136 draw2d.node.prototype.setTagName = function(title) {137 this.tagname.innerHTML = title;138 };139 /* Method to get name of node object */140 draw2d.node.prototype.getTagName = function(title) {141 return $(this.tagname).text();142 };143 /* set totel count of node object */144 draw2d.node.prototype.setFooter = function(title) {145 this.footer.innerHTML = title;146 };147 /* set inner content of node object */148 draw2d.node.prototype.setContent = function(_2bc9) {149 this.textarea.innerHTML = _2bc9;150 };151 draw2d.node.prototype.setLabel = function(name) {152 this.name = name;153 }154 draw2d.node.prototype.getLabel = function() {155 return this.name;156 }157 draw2d.node.prototype.isDisable = function() {158 return this.disable;159 }160 draw2d.node.prototype.getnodeName = function() {161 return this.getheader().split("-")[0];162 };163 draw2d.node.prototype.onDragstart = function(x, y) {164 var flag = draw2d.Node.prototype.onDragstart.call(this, x, y);165 if(this.header === null) {166 return false;167 }168 if(y < this.cornerHeight && x < this.width && x > (this.width - this.cornerWidth)) {169 /* check if Node object is Logic control & PID block and sets toggle functionality.170 Logic control & PID block does not have toggle functionality*/171 if(this.getnodeName() === "AND" || this.getnodeName() === "OR" || this.getnodeName() === "PID" || this.getnodeName() === "ADD" || this.getnodeName() === "SUB" || this.getnodeName() === "MUL" || this.getnodeName() === "DIV" || this.getnodeName() === "LIM" || this.getnodeName() === "CMP" || this.getnodeName() === "DC") {172 this.top_right.style.display = "none";173 } else {174 this.top_right.style.display = "block";175 this.toggle();176 }177 return false;178 }179 if(this.originalHeight == -1) {180 if(this.canDrag === true && x < parseInt(this.width) && y < parseInt(this.height)) {181 return true;182 }183 } else {184 return flag;185 }186 };187 draw2d.node.prototype.setCanDrag = function(flag) {188 draw2d.Node.prototype.setCanDrag.call(this, flag);189 this.html.style.cursor = "";190 if(this.header === null) {191 return;192 }193 if(flag) {194 this.header.style.cursor = "move";195 } else {196 this.header.style.cursor = "defalut";197 }198 };199 //------------------------------Set workspace for elements----------------------------200 draw2d.node.prototype.setWorkflow = function(workspace) {201 draw2d.Node.prototype.setWorkflow.call(this, workspace);202 if(workspace !== null && this.inputPort === null) {203 this.CreatePorts(this, workspace, this.getnodeName());204 }205 };206 //-------------------Create IO Ports----------------------------------------------------207 var cnt = 1;208 draw2d.node.prototype.CreatePorts = function(oThis, workspace, nodeId) {209 switch(nodeId) {210 case "ADD" :211 case "SUB" :212 case "MUL" :213 case "DIV" :214 case "AND" :215 case "OR" :216 oThis.inputPort = oThis.InputPort(workspace);217 oThis.outputPort = oThis.OutputPort(workspace);218 oThis.addPort(oThis.inputPort, -2, 50);219 oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 2);220 break;221 case "AI":222 case "DI":223 oThis.OutputPort(workspace);224 oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 1.8);225 break;226 case "PID" :227 oThis.inputPort = oThis.InputPort(workspace);228 oThis.outputPort = oThis.OutputPort(workspace);229 oThis.addPort(oThis.inputPort, -2, oThis.height / 2);230 oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 2);231 //oThis.LoopInputPort = oThis.InputPort(workspace);232 //oThis.LoopOutputPort = oThis.OutputPort(workspace);233 //oThis.addPort(oThis.LoopInputPort, oThis.width / 2, 0);234 //oThis.addPort(oThis.LoopOutputPort, oThis.width + 2, oThis.height / 2.7);235 break;236 case "LIM" :237 oThis.LowinputPort = oThis.InputPort(workspace);238 oThis.LowinputPort.setName("Low");239 oThis.addPort(oThis.LowinputPort, -2, oThis.height / 2.8);240 oThis.ActualinputPort = oThis.InputPort(workspace);241 oThis.addPort(oThis.ActualinputPort, -2, oThis.height / 1.8);242 oThis.ActualinputPort.setName("Actual");243 oThis.HighinputPort = oThis.InputPort(workspace);244 oThis.addPort(oThis.HighinputPort, -2, oThis.height / 1.3);245 oThis.HighinputPort.setName("High");246 oThis.outputPort = oThis.OutputPort(workspace);247 oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 2);248 break;249 case "CMP" :250 oThis.LowinputPort = oThis.InputPort(workspace);251 oThis.addPort(oThis.LowinputPort, -2, oThis.height / 2.8);252 oThis.LowinputPort.setName("Low");253 oThis.ActualinputPort = oThis.InputPort(workspace);254 oThis.addPort(oThis.ActualinputPort, -2, oThis.height / 1.8);255 oThis.ActualinputPort.setName("Actual");256 oThis.HighinputPort = oThis.InputPort(workspace);257 oThis.addPort(oThis.HighinputPort, -2, oThis.height / 1.3);258 oThis.HighinputPort.setName("High");259 oThis.LToutputPort = oThis.OutputPort(workspace);260 oThis.addPort(oThis.LToutputPort, oThis.width + 2, oThis.height / 3.1);261 oThis.LToutputPort.setName("LT");262 oThis.GToutputPort = oThis.OutputPort(workspace);263 oThis.addPort(oThis.GToutputPort, oThis.width + 2, oThis.height / 2.3);264 oThis.GToutputPort.setName("GT");265 oThis.EQLoutputPort = oThis.OutputPort(workspace);266 oThis.addPort(oThis.EQLoutputPort, oThis.width + 2, oThis.height / 1.45);267 oThis.EQLoutputPort.setName("NEQL");268 oThis.NEQLoutputPort = oThis.OutputPort(workspace);269 oThis.addPort(oThis.NEQLoutputPort, oThis.width + 2, oThis.height / 1.2);270 oThis.NEQLoutputPort.setName("Inrange");271 oThis.InRangeoutputPort = oThis.OutputPort(workspace);272 oThis.addPort(oThis.InRangeoutputPort, oThis.width + 2, oThis.height / 1.8);273 oThis.InRangeoutputPort.setName("EQL");274 break;275 case "DC":276 oThis.LatchInputPort = oThis.InputPort(workspace);277 oThis.addPort(oThis.LatchInputPort, -2, oThis.height / 2.5);278 oThis.UnlatchInputPort = oThis.InputPort(workspace);279 oThis.addPort(oThis.UnlatchInputPort, -2, oThis.height / 1.3);280 oThis.outputPort = oThis.OutputPort(workspace);281 oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 2);282 break;283 case "AO":284 case "DO":285 case "RESET":286 oThis.inputPort = oThis.InputPort(workspace);287 //oThis.outputPort = oThis.OutputPort(workspace);288 oThis.addPort(oThis.inputPort, -2, oThis.height / 2);289 //oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 2);290 break;291 default :292 oThis.inputPort = oThis.InputPort(workspace);293 oThis.outputPort = oThis.OutputPort(workspace);294 oThis.addPort(oThis.inputPort, -2, oThis.height / 2);295 oThis.addPort(oThis.outputPort, oThis.width + 2, oThis.height / 2);296 break;297 }298 };299 draw2d.node.prototype.InputPort = function(workspace) {300 var ip = new draw2d.InputPort();301 var DCSSPACEIP = new DCSSPACE.inputs.MyInputPort(ip);302 this.inputPort = DCSSPACEIP.input;303 this.inputPort.setWorkflow(workspace);304 this.inputPort.setName("input-" + (cnt));305 this.inputPort.setBackgroundColor(new draw2d.Color(247, 98, 98));306 return this.inputPort;307 }308 draw2d.node.prototype.OutputPort = function(workspace) {309 this.outputPort = new draw2d.MyOutputPort();310 //oThis.outputPort.setMaxFanOut(5);311 this.outputPort.setWorkflow(workspace);312 this.outputPort.setName("output-" + (cnt++));313 this.outputPort.setBackgroundColor(new draw2d.Color(24, 195, 41));314 return this.outputPort;315 }316 //-----------------------------add ports at runtime----------------------------------------317 draw2d.node.prototype.addPortsatRuntime = function(oThis, workspace, objId, targetport) {318 var hpos;319 //find index of target port if it is 0 then set hpos value oThis.ports.data[0].originY otherwisw set hpos value oThis.ports.data[oThis.ports.size - 1].originY320 var index = oThis.ports.data.indexOf(targetport);321 // get position of last port bcaz each time we need to add port at end322 if(index == 0 && oThis.ports.size <= 2) {// oThis.ports.size <= 2 bcaz always at initial 2 ports are persent on oThis object323 for(var i = 0; i < oThis.ports.size; i++) {324 if(oThis.ports.data[i].name.split("-")[0] != "output") {// bcaz oThis.ports.data[1] is for Output Port325 if(oThis.ports.data[i].originY >= 50)326 hpos = oThis.ports.data[0].originY;327 }328 }329 } else {330 hpos = oThis.ports.data[oThis.ports.size - 1].originY;331 // set y position of last port to hpos332 }333 if(hpos + 15 >= oThis.height - 15) {334 this.setDimensionAfterAddPort(oThis.width, oThis.height + 20);335 }336 oThis.inputPort = oThis.InputPort(workspace);337 if(objId === "AND" || objId === "OR" || objId === "ADD" || objId === "SUB" || objId === "MUL" || objId === "DIV") {338 oThis.addPort(oThis.inputPort, -2, hpos + 15);339 oThis.paint();340 }341 }342 // Remove ports at runtime343 draw2d.node.prototype.removePortsatRuntime = function(oThis, objId, targetPort) {344 var removedInputPort;345 if(oThis.getHeight() > 170) {346 oThis.setDimensionAfterAddPort(oThis.width, oThis.height - 10);347 }348 if(objId === "AND" || objId === "OR" || objId === "ADD" || objId === "SUB" || objId === "MUL" || objId === "DIV") {349 var index = oThis.ports.data.indexOf(targetPort)350 if(index != -1) {351 for(var i = 0; i < oThis.ports.size; i++) {352 if(oThis.ports.data[i].name.split("-")[0] != "output") {// bcaz oThis.ports.data[1] is for Output Port353 if(oThis.ports.data[i].getConnections().data[0] == undefined) {354 removedInputPort = oThis.ports.data[i];355 oThis.removePort(oThis.ports.data[i]);356 oThis.paint();357 }358 }359 }360 }361 }362 return removedInputPort;363 }364 draw2d.node.prototype.setDimensionAfterAddPort = function(w, h) {365 draw2d.Node.prototype.setDimension.call(this, w, h);366 $(this.top_right).css({367 left : Math.max(1, (this.width - this.cornerWidth - 8))368 });369 $(this.textarea).css({370 width : Math.max(1, (this.width - 2)),371 height : Math.max(1, (this.height - this.cornerHeight * 2) - 40)372 });373 $(this.header).css({374 width : Math.max(1, (this.width))375 });376 $(this.tagname).css({377 width : Math.max(1, (this.width))378 });379 $(this.description).css({380 width : Math.max(1, (this.width))381 });382 $(this.footer).css({383 width : Math.max(1, (this.width)),384 top : Math.max(1, (this.height - this.cornerHeight) - 5)385 });386 $(this.btnReset).css({387 top : Math.max(1, (this.height - this.cornerHeight) + 17)388 });389 if(this.ports.data[1].name.split("-")[0] == "output") {390 this.ports.data[1].setPosition(this.width + 5, (this.height / 2));391 }392 };393 /* Node object toggle functionality */394 draw2d.node.prototype.toggle = function() {395 if(this.originalHeight == -1) {396 this.originalHeight = this.height;397 this.setDimension(this.width, this.cornerHeight * 2 + 40);398 if(this.getnodeName() == "CPT"|| this.getnodeName() == "NOT" || this.getnodeName() === "UPCTR" || this.getnodeName() === "DWCTR" || this.getnodeName() === "OND" || this.getnodeName() === "OFFD" || this.getnodeName() === "RTO") {399 this.btnReset.style.display = 'none';400 this.setDimension(this.width, this.cornerHeight * 2 + 41);401 this.footer.style.top = "51px";402 }403 } else {404 this.setDimension(this.width, this.originalHeight);405 if(this.getnodeName() == "CPT" || this.getnodeName() == "NOT" || this.getnodeName() === "UPCTR" || this.getnodeName() === "DWCTR" || this.getnodeName() === "OND" || this.getnodeName() === "OFFD" || this.getnodeName() === "RTO") {406 this.btnReset.style.display = 'block';407 this.textarea.style.height = "121px";408 }409 this.originalHeight = -1;410 }411 };412 //....................Design Right click menu......................413 draw2d.node.prototype.getContextMenu = function() {414 var menu = new draw2d.Menu();415 menu.parent = this;416 var oThis = this;417 if($("#btnRunmode").val() == "OffMode" && DCSSPACE.workflow.isEnabled()) {418 menu.appendMenuItem(new draw2d.MenuItem("Delete", "/DCS_Draw2d/assert/images/ButtonDelete.jpeg", function() {419 var ans = confirm("Do you want to delete " + oThis.getnodeName() + " block");420 if(ans) {421 oThis.model = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId());422 // add model into node object to retrive model at undo/redo423 DCSSPACE.view.blockView.prototype.ReduceSequenceNo(oThis.getSequenceNo() + 1);424 // Update Sequence Number of block425 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId()));426 //remove a model from collection427 oThis.workflow.getCommandStack().execute(new draw2d.CommandDelete(oThis));428 // remove current figure429 //console.log(DCSSPACE.collection.toJSON());430 }431 }));432 if(oThis.disable == false) {433 menu.appendMenuItem(new draw2d.MenuItem("Disable", null, function() {434 oThis.disable = true;435 oThis.setAlpha(0.4);436 oThis.alphaBeforeOnDrag = oThis.getAlpha();437 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId()).set({438 "isEnable" : !(oThis.disable)439 });440 //oThis.workflow.getCommandStack().execute(new draw2d.commandDisablesBlock(oThis.workflow, oThis));441 //console.log(DCSSPACE.collection.get(tab_id).toJSON());442 }));443 } else {444 menu.appendMenuItem(new draw2d.MenuItem("Enable", null, function() {445 oThis.disable = false;446 oThis.setAlpha(1);447 oThis.alphaBeforeOnDrag = oThis.getAlpha();448 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId()).set({449 "isEnable" : !(oThis.disable)450 });451 //oThis.workflow.getCommandStack().execute(new draw2d.commandDisablesBlock(oThis.workflow, oThis));452 //console.log(DCSSPACE.collection.get(tab_id).toJSON());453 }));454 }455 }456 if(($("#btnRunmode").val() == "OffMode" || ($("#btnRunmode").val() == "RunMode" && oThis.getnodeName() == "PID")) && DCSSPACE.workflow.isEnabled()) {457 menu.appendMenuItem(new draw2d.MenuItem("Configure", "", function() {458 if(oThis.getnodeName() === "PID") {459 DCSSPACE.view.blockView.prototype.PIDBlockConfig(oThis.getId());460 } else if(oThis.getnodeName() === "AI" || oThis.getnodeName() === "AO" || oThis.getnodeName() === "DI" || oThis.getnodeName() === "DO") {461 if(oThis.getnodeName() === "AI") {462 $("#ddltagname").html("<option value='none'>None</option>");463 } else if(oThis.getnodeName() === "AO") {464 $("#ddltagname").html("<option value='none'>None</option>");465 } else if(oThis.getnodeName() === "DI") {466 $("#ddltagname").html("<option value='none'>None</option>");467 } else if(oThis.getnodeName() === "DO") {468 $("#ddltagname").html("<option value='none'>None</option>");469 }470 DCSSPACE.view.blockView.prototype.IOBloackConfig(oThis.getId());471 } else if(oThis.getnodeName() === "OND" || oThis.getnodeName() === "OFFD" || oThis.getnodeName() === "RTO" || oThis.getnodeName() === "UPCTR" || oThis.getnodeName() === "DWCTR") {472 DCSSPACE.view.blockView.prototype.TimerAndCntBlockConfig(oThis.getId());473 } else if(oThis.getnodeName() === "CPT") {474 var CPTModel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId());475 $("#CPTConfig").tabs({//create tabs476 collapsible : true,477 });478 var labeltxt = CPTModel.get("label") != undefined ? CPTModel.get("label") : "";479 $("#txtCPTlabel").val(labeltxt);480 CPTModel.get("description") != "" ? $("#lblCPTDesc").val(CPTModel.get("description")) : $("#lblCPTDesc").val('');481 // set labels on blocks connected to CPT block482 if(CPTModel.get("source") != null) {483 var CPTsrcstring = "";484 var CPTsrc = CPTModel.get("source");485 for(var i = 0; i < CPTsrc.length; i++) {486 if(CPTsrc != null || CPTsrc.length <= 0) {487 CPTsrcstring = CPTsrcstring + CPTsrc[i];488 CPTsrcstring = CPTsrcstring + ", ";489 }490 }491 $("#lblavlsrc").html(CPTsrcstring);492 } else {493 $("#lblavlsrc").text("No Source connection");494 }495 $("#CPTConfig").css({496 "display" : "block"497 }).dialog({498 title : 'Configuration',499 height : 580,500 width : 390,501 draggable : false,502 show : {503 effect : "drop",504 direction : "up"505 },506 hide : {507 effect : "drop",508 direction : "down"509 },510 modal : true,511 resizable : false,512 buttons : [{513 text : "Submit",514 click : function() {515 // Validate & Submit CPT block details in CPT model516 if($("#txtCPTlabel").val() != '') {517 if(CPTModel.get("label") != txtlabel) {518 if(!DCSSPACE.view.blockView.prototype.checkForUniqueLabel(txtlabel)) {519 oThis.setLabel($("#txtCPTlabel").val());520 oThis.showToolTip($("#lblCPTDesc").val());521 CPTModel.set({522 "label" : $("#txtCPTlabel").val(),523 "description" : $("#lblCPTDesc").val()524 });525 $("#txtCPTlabel").focus();526 if($("#ddlStatement").val() != 'select') {527 if($("#txtCondition").val() != '') {528 if($("#txrExperssion1").val() != '') {529 CPTModel.set({530 "Statement" : $("#ddlStatement").val(),531 "Condition" : $("#txtCondition").val(),532 "Experssion1" : $("#txrExperssion1").val(),533 "Experssion2" : $("#txrExperssion2").val(),534 });535 //console.log(DCSSPACE.collection.toJSON());536 $(this).dialog("close");537 } else {538 alert("Please enter experssion1")539 $("#txrExperssion1").focus();540 }541 } else {542 alert("Please enter condition")543 $("#txtCondition").focus();544 }545 } else {546 $(this).dialog("close");547 // if user want to set only Label not condition.548 }549 } else {550 alert("Label already exist");551 $("#txtCPTlabel").val('').focus();552 }553 }else{554 oThis.setLabel($("#txtCPTlabel").val());555 oThis.showToolTip($("#lblCPTDesc").val());556 CPTModel.set({557 "label" : $("#txtCPTlabel").val(),558 "description" : $("#lblCPTDesc").val()559 }); 560 if($("#ddlStatement").val() != 'select') {561 if($("#txtCondition").val() != '') {562 if($("#txrExperssion1").val() != '') {563 CPTModel.set({564 "Statement" : $("#ddlStatement").val(),565 "Condition" : $("#txtCondition").val(),566 "Experssion1" : $("#txrExperssion1").val(),567 "Experssion2" : $("#txrExperssion2").val(),568 });569 //console.log(DCSSPACE.collection.toJSON());570 $(this).dialog("close");571 } else {572 alert("Please enter experssion1")573 $("#txrExperssion1").focus();574 }575 } else {576 alert("Please enter condition")577 $("#txtCondition").focus();578 }579 } else {580 $(this).dialog("close");581 // if user want to set only Label not condition.582 }583 }584 } else {585 alert("Please enter Label")586 $("#txtCPTlabel").focus();587 }588 }589 }, {590 text : "Close",591 click : function() {592 $("#TimerConfig").css({593 "display" : "none"594 });595 $(this).dialog("close");596 }597 }],598 });599 } else if(oThis.getnodeName() === "ADD" || oThis.getnodeName() === "SUB" || oThis.getnodeName() === "MUL" || oThis.getnodeName() === "DIV" || oThis.getnodeName() === "CMP" || oThis.getnodeName() === "LIM" || oThis.getnodeName() === "AND" || oThis.getnodeName() === "OR" || oThis.getnodeName() === "NOT" || oThis.getnodeName() === "DC") {600 DCSSPACE.view.blockView.prototype.LabelChangeConfig(oThis.getId());601 } else if(oThis.getnodeName() == "RESET") {602 oThis.getCounterForReset();603 // set ddlrstSelectCounterName604 DCSSPACE.view.blockView.prototype.resetBlockConfig(oThis.getId());605 }606 }));607 }608 if($("#btnRunmode").val() == "RunMode" && DCSSPACE.workflow.isEnabled()) {609 if(oThis.getnodeName() == "AI") {610 menu.appendMenuItem(new draw2d.MenuItem("Edit", "ButtonDelete.jpeg", function() {611 DCSSPACE.view.blockView.prototype.SettingInputvalues(oThis.getId());612 }));613 }614 if(oThis.getnodeName() == "DI") {615 menu.appendMenuItem(new draw2d.MenuItem("Toggle", "", function() {616 var DImodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId());617 var currentValue = DImodel.get("Output") === "" ? 0 : parseInt(DImodel.get("Output"));618 if(currentValue === 0) {619 currentValue = 1;620 DImodel.set({621 "Output" : currentValue622 });623 //currentIOInput = currentValue;624 } else {625 currentValue = 0;626 DImodel.set({627 "Output" : currentValue628 });629 //currentIOInput = currentValue;630 }631 DCSSPACE.view.blockView.prototype.setConfigureCall(currentValue,DImodel,oThis);632 $("#information").html(DCSSPACE.view.blockView.prototype.informationBlock(DImodel));633 DCSSPACE.view.blockView.prototype.blocksetContent(DImodel);634 }));635 }636 }637 return menu;638 };639 draw2d.node.prototype.getCounterForReset = function() {640 //var models = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").models;641 $("#ddlrstSelectCounterName").html("");642 var UPCTRmodels = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").where({643 "blockid" : "UPCTR"644 });645 var DWCTRmodels = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").where({646 "blockid" : "DWCTR"647 });648 var RTOmodels = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").where({649 "blockid" : "RTO"650 });651 if(UPCTRmodels != null || DWCTRmodels != null || RTOmodels != null) {652 DCSSPACE.view.blockView.prototype.modelsIterator(UPCTRmodels);653 DCSSPACE.view.blockView.prototype.modelsIterator(DWCTRmodels);654 DCSSPACE.view.blockView.prototype.modelsIterator(RTOmodels);655 }656}657 //----------------------Desing object flow Menu................//658 draw2d.FlowMenu = function(workspace) {659 this.actionDelete = new draw2d.ButtonDelete(this);660 draw2d.ToolPalette.call(this);661 this.setDropShadow(0);662 this.setDimension(0, 0);663 this.currentFigure = null;664 this.myworkflow = workspace;665 this.workflow = workspace;666 this.added = false;667 this.setDeleteable(false);668 this.setCanDrag(false);669 this.setResizeable(false);670 this.setSelectable(false);671 this.setColor(null);672 this.scrollarea.style.borderBottom = "0px";673 this.actionDelete.setPosition(0, 0);674 this.addChild(this.actionDelete);675 };676 draw2d.FlowMenu.prototype = new draw2d.ToolPalette();677 draw2d.FlowMenu.prototype.type = "draw2d.FlowMenu";678 draw2d.FlowMenu.prototype.setAlpha = function(alphaval) {679 draw2d.Figure.prototype.setAlpha.call(this, alphaval);680 };681 draw2d.FlowMenu.prototype.hasTitleBar = function() {682 return false;683 };684 draw2d.FlowMenu.prototype.onSelectionChanged = function(obj) {685 if(obj == this.currentFigure) {686 return;687 }688 if( obj instanceof draw2d.Line) {689 return;690 }691 if(this.added == true) {692 this.myworkflow.removeFigure(this);693 this.added = false;694 }695 if(obj !== null && this.added == false) {696 if(this.myworkflow.getEnableSmoothFigureHandling() == true) {697 this.setAlpha(0.01);698 }699 this.myworkflow.addFigure(this, 100, 100);700 this.added = true;701 }702 if(this.currentFigure !== null) {703 this.currentFigure.detachMoveListener(this);704 }705 this.currentFigure = obj;706 if(this.currentFigure !== null) {707 this.currentFigure.attachMoveListener(this);708 this.onOtherFigureMoved(this.currentFigure);709 }710 };711 draw2d.FlowMenu.prototype.setWorkflow = function(workspace) {712 draw2d.Figure.prototype.setWorkflow.call(this, workspace);713 };714 draw2d.FlowMenu.prototype.onOtherFigureMoved = function(obj) {715 var pos = obj.getPosition();716 this.setPosition(pos.x + obj.getWidth() + 7, pos.y - 16);717 };718 /*719 * Function to call Undo/Redo stack720 */721 draw2d.node.prototype.onKeyDown = function(ASCIIval, ctrl) {722 if($("#btnRunmode").val() == "OffMode") {723 if(ASCIIval == 46) {724 var id = this.getheader() +"-" + this.getSequenceNo();725 var oThis = this;726 $("#delete-confirm").html('Are you sure you want to remove block ' + id + '?').dialog({727 resizable : false,728 title : 'Confirm Deletion',729 height : 120,730 width : 330,731 modal : true,732 draggable : false,733 buttons : {734 "Delete" : function() {735 this.model = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId());736 DCSSPACE.view.blockView.prototype.ReduceSequenceNo(oThis.getSequenceNo() + 1);737 var sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId());738 var sourceNode = sourcemodel.get("blockid").split("-")[0];739 var CurrentNodeLabel = sourcemodel.get("label");740 if(sourcemodel != null) {741 var models = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").models;742 $.each(models, function(j){743 var source = models[j].get("source");744 var target = models[j].get("target");745 var blockid = models[j].get("blockid");746 var block = models[j].get("block");747 if(source != null){748 for(var k=0; k< source.length; k++){749 if(blockid == "CMP" || blockid == "LIM"){750 if(source[k].split("-")[0] == CurrentNodeLabel){751 source.splice(k,1);752 k=k-1;753 }754 }else{755 if(CurrentNodeLabel.split("#")[0] == "CMP" || CurrentNodeLabel.split("#")[0] == "LIM"){756 if(source[k].split("-")[0] == CurrentNodeLabel){757 source.splice(k,1);758 k=k-1;759 if(blockid == "ADD" || blockid == "SUB" || blockid == "MUL" || blockid == "DIV" || blockid == "AND" || blockid == "OR"){760 removedInputPort =block.removePortsatRuntime(block, blockid, block.outputPort);761 }762 }763 }else{764 if(source[k] == CurrentNodeLabel){765 source.splice(k,1);766 if(blockid == "ADD" || blockid == "SUB" || blockid == "MUL" || blockid == "DIV" || blockid == "AND" || blockid == "OR"){767 removedInputPort =block.removePortsatRuntime(block, blockid, block.outputPort);768 }769 }770 }771 }772 }773 }774 if(target != null){775 for(var x=0; x< target.length; x++){776 if(blockid == "CMP" || blockid == "LIM"){777 if(target[x].split("-")[0] == CurrentNodeLabel){778 target.splice(x,1);779 }780 }else{781 if(CurrentNodeLabel.split("#")[0] == "CMP" || CurrentNodeLabel.split("#")[0] == "LIM"){782 if(target[x].split("-")[0] == CurrentNodeLabel){783 target.splice(x,1);784 x=x-1;785 }786 }else{787 if(target[x] == CurrentNodeLabel){788 target.splice(x,1);789 }790 }791 792 }793 }794 }795 models[j].set({796 "target" : target797 });798 models[j].set({799 "source" : source800 });801 802 });803 }804 805 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(oThis.getId());806 // remove model from collection807 oThis.workflow.getCommandStack().execute(new draw2d.CommandDelete(oThis));808 // remove current figure809 $(this).dialog("close");810 },811 Cancel : function() {812 $(this).dialog("close");813 }814 }815 });816 /*817 var txt = 'Are you sure you want to remove block '+ id + '?';818 $.prompt(txt, {819 buttons : {820 Delete : true,821 Cancel : false822 },823 callback : function(e, v, m, f) {824 if(v) {825 this.model = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.getId());826 // add model into node object to retrive model at undo/redo827 DCSSPACE.view.blockView.prototype.ReduceSequenceNo(oThis.getSequenceNo() + 1);828 // Update Sequence Number of block829 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(oThis.getId());830 // remove model from collection831 oThis.workflow.getCommandStack().execute(new draw2d.CommandDelete(oThis));832 // remove current figure833 } 834 }835 });*/836 837 } else if(ASCIIval === 90 && ctrl) {838 if(this.workflow.commandStack.getUndoLabel() === "delete figure") {839 var len = this.workflow.commandStack.undostack.length;840 if(this.workflow.commandStack.undostack[len - 1].figure.type == "draw2d.Node") {841 DCSSPACE.view.blockView.prototype.ExtendSequenceNo(this.workflow.currentSelection.getSequenceNo());842 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").add(this.workflow.currentSelection.model);843 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").sort();844 var SortedCollection = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").sortAsc(DCSSPACE.collection.get(tab_id).get("functionBlockCollection"));845 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").models = SortedCollection;846 } else if(this.workflow.commandStack.undostack[len - 1].figure.type == "draw2d.nodeConnetion") {847 //get Sourcemodel and set target attribute848 var Sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.getCommandStack().undostack[len - 1].figure.sourcePort.parentNode.getId());849 var connectionsrc = Sourcemodel.get("target");850 connectionsrc.push(this.workflow.commandStack.undostack[len - 1].figure.getTarget().parentNode.getLabel());851 Sourcemodel.set({852 "target" : connectionsrc853 })854 //get Targetmodel and set source attribute855 var Targetemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.undostack[len - 1].figure.targetPort.parentNode.getId());856 var connectiontarget = Targetemodel.get("source");857 connectiontarget.push(this.workflow.commandStack.undostack[len - 1].figure.getSource().parentNode.getLabel());858 Targetemodel.set({859 "source" : connectiontarget860 });861 var node = this.workflow.commandStack.undostack[len - 1].figure.targetPort.parentNode;862 if(node.getnodeName() == "ADD" || node.getnodeName() == "SUB" || node.getnodeName() == "MUL" || node.getnodeName() == "DIV" || node.getnodeName() == "AND" || node.getnodeName() == "OR") {863 node.addPort(this.workflow.commandStack.undostack[len - 1].figure.removedInputPort, this.workflow.commandStack.undostack[len - 1].figure.removedInputPort.originX, this.workflow.commandStack.undostack[len - 1].figure.removedInputPort.originY);864 }865 }866 this.workflow.commandStack.undo();867 //console.log(DCSSPACE.collection.toJSON());868 } else if(this.workflow.commandStack.getUndoLabel() === "create connection") {869 var len = this.workflow.commandStack.undostack.length;870 var srcmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.undostack[len - 1].source.parentNode.getId());871 //get source model872 var targetmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.undostack[len - 1].target.parentNode.getId());873 //get target model874 var srcarray = srcmodel.get('target');875 var tararray = targetmodel.get('source');876 if(this.workflow.commandStack.undostack[len - 1].source.parentNode.getnodeName() == "CMP") {877 var index = srcarray.indexOf(this.workflow.commandStack.undostack[len - 1].target.parentNode.getLabel() + "-" + this.workflow.commandStack.undostack[len - 1].source.name);878 var indx = tararray.indexOf(this.workflow.commandStack.undostack[len - 1].source.parentNode.getLabel() + "-" + this.workflow.commandStack.undostack[len - 1].source.name)879 } else if(this.workflow.commandStack.undostack[len - 1].target.parentNode.getnodeName() == "CMP" || this.workflow.commandStack.undostack[len - 1].target.parentNode.getnodeName() == "LIM") {880 var index = srcarray.indexOf(this.workflow.commandStack.undostack[len - 1].target.parentNode.getLabel() + "-" + this.workflow.commandStack.undostack[len - 1].target.name);881 var indx = tararray.indexOf(this.workflow.commandStack.undostack[len - 1].source.parentNode.getLabel() + "-" + this.workflow.commandStack.undostack[len - 1].target.name)882 } else {883 var index = srcarray.indexOf(this.workflow.commandStack.undostack[len - 1].target.parentNode.getLabel());884 var indx = tararray.indexOf(this.workflow.commandStack.undostack[len - 1].source.parentNode.getLabel())885 }886 if(index != -1)887 srcarray.splice(index, 1);888 if(indx != -1)889 tararray.splice(indx, 1);890 srcmodel.set({891 "target" : srcarray892 });893 targetmodel.set({894 "source" : tararray895 });896 var target = this.workflow.commandStack.undostack[len - 1].target.parentNode;897 if(target.getnodeName() == "ADD" || target.getnodeName() == "SUB" || target.getnodeName() == "MUL" || target.getnodeName() == "DIV" || target.getnodeName() == "AND" || target.getnodeName() == "OR") {898 this.workflow.commandStack.undostack[len - 1].connection.removedInputPort = target.removePortsatRuntime(target, target.getnodeName(), this.workflow.commandStack.undostack[len - 1].target);899 }900 //set new updated source attribute of target model901 this.workflow.commandStack.undo();902 //console.log(DCSSPACE.collection.toJSON());903 } else if(this.workflow.commandStack.getUndoLabel() === "add figure") {904 var len = this.workflow.commandStack.undostack.length;905 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(this.workflow.commandStack.undostack[len - 1].figure.model);906 this.workflow.commandStack.undo();907 //console.log(DCSSPACE.collection.toJSON());908 } else {909 this.workflow.commandStack.undo();910 }911 } else if(ASCIIval === 89 && ctrl) {912 if(this.workflow.commandStack.getRedoLabel() === "delete figure") {913 var len = this.workflow.commandStack.redostack.length;914 if(this.workflow.commandStack.redostack[len - 1].figure.type == "draw2d.Node") {915 this.workflow.commandStack.redostack[len - 1].figure.model = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.redostack[len - 1].figure.getId());916 // add model to current figure to retrive at undo operation917 DCSSPACE.view.blockView.prototype.ReduceSequenceNo(this.workflow.commandStack.redostack[len - 1].figure.getSequenceNo() + 1)// Update Sequence Number of block918 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(this.workflow.commandStack.redostack[len - 1].figure.getId());919 // remove model from collection920 } else if(this.workflow.commandStack.redostack[len - 1].figure.type == "draw2d.nodeConnetion") {921 //get Sourcemodel and set target attribute922 var Sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.getCommandStack().redostack[len - 1].figure.sourcePort.parentNode.getId());923 var connectionsrc = Sourcemodel.get("target");924 //connectionsrc.push(this.commandStack.redostack[len - 1].figure.getTarget().parentNode.getTagname());925 var index = connectionsrc.indexOf(this.workflow.commandStack.redostack[len - 1].figure.getTarget().parentNode.getLabel())926 // if element exist then remove927 if(index != -1) {928 connectionsrc.splice(index, 1);929 }930 Sourcemodel.set({931 "target" : connectionsrc932 })933 //get Targetmodel and set source attribute934 var Targetemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.redostack[len - 1].figure.targetPort.parentNode.getId());935 var connectiontarget = Targetemodel.get("source");936 var indx = connectiontarget.indexOf(this.workflow.commandStack.redostack[len - 1].figure.getSource().parentNode.getLabel())937 // if element exist then remove938 if(indx != -1) {939 connectiontarget.splice(indx, 1);940 }941 Targetemodel.set({942 "source" : connectiontarget943 });944 var targetNode = this.workflow.commandStack.redostack[len - 1].figure.targetPort.parentNode;945 if(targetNode.getnodeName() == "ADD" || targetNode.getnodeName() == "SUB" || targetNode.getnodeName() == "MUL" || targetNode.getnodeName() == "DIV" || targetNode.getnodeName() == "AND" || targetNode.getnodeName() == "OR") {946 this.workflow.commandStack.redostack[len - 1].figure.removedInputPort = targetNode.removePortsatRuntime(targetNode, targetNode.getnodeName(), this.workflow.commandStack.redostack[len - 1].figure.targetPort);947 }948 }949 this.workflow.getCommandStack().redo();950 //console.log(DCSSPACE.DCSSPACE.collection.toJSON());951 } else if(this.workflow.commandStack.getRedoLabel() === "create connection") {952 var len = this.workflow.commandStack.redostack.length;953 var srcmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.redostack[len - 1].source.parentNode.getId());954 //get source model955 var tarmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.workflow.commandStack.redostack[len - 1].target.parentNode.getId());956 //get target model957 var srcarray = srcmodel.get("target");958 //get source model target attribute to remove target959 var tararray = tarmodel.get("source");960 // get target model ssource attribute to remove source961 if(this.workflow.commandStack.redostack[len - 1].source.parentNode.getnodeName() == "CMP") {962 srcarray.push(this.workflow.commandStack.redostack[len - 1].target.parentNode.getLabel() + "-" + this.workflow.commandStack.redostack[len - 1].source.name);963 tararray.push(this.workflow.commandStack.redostack[len - 1].source.parentNode.getLabel() + "-" + this.workflow.commandStack.redostack[len - 1].source.name)964 } else if(this.workflow.commandStack.redostack[len - 1].target.parentNode.getnodeName() == "CMP" || this.workflow.commandStack.redostack[len - 1].target.parentNode.getnodeName() == "LIM") {965 srcarray.push(this.workflow.commandStack.redostack[len - 1].target.parentNode.getLabel() + "-" + this.workflow.commandStack.redostack[len - 1].target.name);966 tararray.push(this.workflow.commandStack.redostack[len - 1].source.parentNode.getLabel() + "-" + this.workflow.commandStack.redostack[len - 1].target.name)967 } else {968 srcarray.push(this.workflow.commandStack.redostack[len - 1].target.parentNode.getLabel());969 //Push target attrubute name in sourcearray970 tararray.push(this.workflow.commandStack.redostack[len - 1].source.parentNode.getLabel());971 //Push source attrubute name in targetarray972 }973 srcmodel.set({974 "target" : srcarray975 });976 tarmodel.set({977 "source" : tararray978 });979 var targetNode = this.workflow.commandStack.redostack[len - 1].target.parentNode;980 if(targetNode.getnodeName() == "ADD" || targetNode.getnodeName() == "SUB" || targetNode.getnodeName() == "MUL" || targetNode.getnodeName() == "DIV" || targetNode.getnodeName() == "AND" || targetNode.getnodeName() == "OR") {981 targetNode.addPort(this.workflow.commandStack.redostack[len - 1].connection.removedInputPort, this.workflow.commandStack.redostack[len - 1].connection.removedInputPort.originX, this.workflow.commandStack.redostack[len - 1].connection.removedInputPort.originY);982 }983 this.workflow.commandStack.redo();984 //console.log(DCSSPACE.collection.toJSON());985 } else if(this.workflow.commandStack.getRedoLabel() === "add figure") {986 var len = this.workflow.commandStack.redostack.length;987 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").add(this.workflow.commandStack.redostack[len - 1].figure.model);988 this.workflow.commandStack.redo();989 //console.log(DCSSPACE.collection.toJSON());990 } else {991 this.workflow.getCommandStack().redo();992 }993 }994 }995 }996 draw2d.node.prototype.CommandAdd = function(canvas, figure, x, y, parent) {997 this.workflow.getCommandStack().execute(new draw2d.CommandAdd(canvas, figure, x, y, parent));998 };999 draw2d.node.prototype.getModelAttrubutes = function() {1000 var TagName;1001 if(this.getnodeName() == "AI" || this.getnodeName() == "AO" || this.getnodeName() == "DI" || this.getnodeName() == "DO") 1002 return {1003 id : this.id,1004 //x : this.x,1005 //y : this.y,1006 //width : this.width,1007 //height : this.height,1008 blockType : this.getnodeName(),1009 //Name : this.model.get("Name"),1010 label : this.model.get("label"),1011 tagName : this.model.get("Tag-name"),1012 //MappingAddress : this.model.get("Map-Address"),1013 sequenceNumber : parseInt(this.model.get("sequenceNo")),1014 //Input : this.model.get("Input"),1015 //Output : this.model.get("Output"),1016 source : this.model.get("source"),1017 target : this.model.get("target"),1018 isEnable : this.model.get("isEnable")1019 }1020 else1021 return {1022 id : this.model.get("id"),1023 blockType : this.getnodeName(),1024 label : this.model.get("label"),1025 sequenceNumber : parseInt(this.model.get("sequenceNo")),1026 source : this.model.get("source"),1027 target : this.model.get("target"),1028 isEnable : this.model.get("isEnable")1029 }1030 1031 }1032 draw2d.node.prototype.getPIDAttrubutes = function() {1033 return {1034 mode : this.model.get("Mode"),1035 actionType : this.model.get("Action Type"),1036 controllerType : this.model.get("Controller Type"),1037 derivativeGain : this.model.get("Derivative Gain"),1038 integralGain : this.model.get("Integral Gain"),1039 intialOutput : this.model.get("Intial Output"),1040 maxValue : this.model.get("Max Value"),1041 minValue : this.model.get("Min Value"),1042 PIDType : this.model.get("PID Type"),1043 propertionalGain : this.model.get("Propertional Gain"),1044 proportionalBias : this.model.get("Proportional Bias"),1045 rate : this.model.get("Rate"),1046 setPoint : this.model.get("Set Point")1047 }1048 }1049 draw2d.node.prototype.getCPTAttrubutes = function() {1050 var experssion_2;1051 var flag = this.model.get("Experssion2") != undefined || this.model.get("Experssion2") != null ? experssion_2 = this.model.get("Experssion2") : experssion_2 = null1052 return {1053 statement : this.model.get("Statement"),1054 condition : this.model.get("Condition"),1055 experssion1 : this.model.get("Experssion1"),1056 experssion2 : experssion_2,1057 }1058 }1059 draw2d.node.prototype.getTimerAndCounterAttrubutes = function() {1060 return {1061 presetValue : this.model.get("Preset")1062 }1063 }1064 draw2d.node.prototype.showToolTip = function(tooltip){1065 $("#"+this.html.id).attr("title", tooltip);1066 }...
behaviorTrees.js
Source:behaviorTrees.js
...251 }252 };253 254 TreeView.prototype.filter = function(type) {255 var id = shorthand.treeData.getNodeName(type.split('.').pop() + 'Type', {256 prefix: this.pre257 });258 this.generateNodes(id);259 var tree = jQuery.jstree._reference(this.tree),260 nodes = tree._get_children(-1),261 mainNode = tree._get_node('#' + id);262 263 nodes.hide();264 if (mainNode) {265 mainNode.show().addClass('jstree-last');266 }267 else {268 throw type + " can't be found";269 }270 271 this.filterId = id;272 };273 TreeView.prototype.generateNodes = function(nodeName, closePath) {274 var paths = shorthand.treeData.getNodePath(nodeName),275 toClose = [];276 277 for (var i = 0; i < paths.length; ++i) {278 var node = jQuery('#' + paths[i], this.tree);279 280 if (closePath && this.tree.jstree('is_closed', node)) {281 toClose.unshift(node);282 }283 284 this.tree.jstree('open_node', node, false, true);285 }286 287 for (var i = 0; i < toClose.length; ++i) {288 this.tree.jstree('close_node', toClose[i], true);289 }290 };291 292 TreeView.prototype.notify = function(eventType, value) {293 if (eventType === shorthand.events.CitizenAdded) {294 var citizen = value.citizen, 295 createType = value.createType;296 297 switch (this.type) {298 case CITIZEN_PREFIX:299 addCitizen.call(this, citizen, createType);300 break;301 case TRIGGER_PREFIX:302 addTrigger.call(this, citizen, createType);303 break;304 case ACTION_PREFIX:305 addAction.call(this, citizen, createType);306 break;307 }308 }309 else if (eventType === shorthand.events.CitizenRemoved) {310 var citizen = value.citizen, 311 removeType = value.removeType;312 313 switch (this.type) {314 case CITIZEN_PREFIX:315 removeCitizen.call(this, citizen, removeType);316 break;317 case TRIGGER_PREFIX:318 removeTrigger.call(this, citizen, removeType);319 break;320 case ACTION_PREFIX:321 removeAction.call(this, citizen, removeType);322 break;323 }324 }325 else if (eventType === shorthand.events.CitizenUpdated) {326 this.update(value);327 328 if (this.type === TRIGGER_PREFIX) {329 updateTrigger.call(this, value);330 }331 }332 };333 334 TreeView.prototype.restrictSelection = function(citizen, options) {335 var id = citizen._getId ? citizen._getId() : null,336 nodeName = shorthand.treeData.getNodeName(citizen, {337 prefix: this.pre338 });339 340 this.generateNodes(nodeName, false);341 var node = jQuery('#' + nodeName, this.tree);342 this.tree.jstree('open_node', node, false, true);343 this.tree.addClass('restricted');344 345 for (var ndx = 0, len = options.length; ndx < len; ndx++) {346 var option = options[ndx],347 config = {348 prefix: this.pre349 },350 cit = citizen;351 if (option instanceof hemi.Viewpoint) {352 config.parent = citizen;353 cit = option;354 } else {355 config.option = option;356 }357 nodeName = shorthand.treeData.getNodeName(cit, config);358 359 node = jQuery('#' + nodeName, this.tree);360 node.find('a').addClass('restrictedSelectable');361 }362 };363 364 TreeView.prototype.select = function(citizen, option) {365 if (citizen === null || option === null) {366 this.tree.jstree('deselect_all');367 } else {368 var nodeName = shorthand.treeData.getNodeName(citizen, {369 option: option,370 prefix: this.pre371 });372 373 this.generateNodes(nodeName, false);374 var node = jQuery('#' + nodeName);375 376 if (this.tree.jstree('is_leaf', node)) {377 this.tree.jstree('select_node', node, true);378 } else {379 this.tree.jstree('open_node', node, false, true);380 }381 382 this.tree.parent().scrollTo(node, 400);383 }384 };385 386 TreeView.prototype.unrestrictSelection = function(citizen, msgs) {387 var id = citizen._getId ? citizen._getId() : null;388 this.tree.removeClass('restricted');389 390 for (var ndx = 0, len = msgs.length; ndx < len; ndx++) {391 var nodeName = shorthand.treeData.getNodeName(citizen, {392 option: msgs[ndx],393 prefix: this.pre394 }),395 node = jQuery('#' + nodeName, this.tree);396 397 node.find('a').removeClass('restrictedSelectable');398 }399 };400 401 TreeView.prototype.update = function(citizen) {402 var nodeName = shorthand.treeData.getNodeName(citizen, {403 prefix: this.pre404 });405 406 this.generateNodes(nodeName, true);407 var node = jQuery('#' + nodeName, this.tree);408 this.tree.jstree('rename_node', node, citizen.name);409 410 // shape case411 412 // camera move case413 };414 415////////////////////////////////////////////////////////////////////////////////////////////////////416// Tree View Private Methods //417////////////////////////////////////////////////////////////////////////////////////////////////////418 419 function addAction(citizen, createType) {420 if (createType) {421 addActionType.call(this, citizen);422 }423 424 var actionNode = shorthand.treeData.createActionJson(citizen, this.pre),425 type = citizen._octaneType.split('.').pop() + 'Type';426 427 if (citizen instanceof hemi.Model) {428 shorthand.treeData.createModelTransformActionJson(citizen, actionNode, this.pre);429 } else if (citizen instanceof hemi.Shape) {430 shorthand.treeData.createShapeTransformActionJson(citizen, actionNode, this.pre);431 }432 433 this.tree.jstree('create_node', '#' + this.pre + type, 'inside', {434 json_data: actionNode435 });436 for (var propName in citizen) {437 var prop = citizen[propName];438 439 if (jQuery.isFunction(prop)) {440 addToolTip.call(this, citizen, propName);441 }442 }443 };444 445 function addActionType(citizen) {446 var json = shorthand.treeData.createOctaneTypeJson(citizen, this.pre);447 448 this.tree.jstree('create_node', -1, 'last', {449 json_data: json450 });451 452 addToolTip.call(this, citizen);453 };454 455 function addCitizen(citizen, createType) {456 if (createType) {457 addOctaneType.call(this, citizen);458 }459 460 var citizenNode = shorthand.treeData.createCitizenJson(citizen, 461 this.pre),462 type = citizen._octaneType.split('.').pop() + 'Type';463 464 this.tree.jstree('create_node', '#' + this.pre + type, 'inside', {465 json_data: citizenNode466 });467 }; 468 469 function addOctaneType(citizen) {470 var json = shorthand.treeData.createOctaneTypeJson(citizen, this.pre);471 472 this.tree.jstree('create_node', -1, 'last', {473 json_data: json474 });475 };476 477 function addToolTip(citizen, opt_func) {478 var nodeId = shorthand.treeData.getNodeName(citizen, {479 prefix: this.pre,480 option: opt_func481 }),482 type = citizen._octaneType,483 desc;484 485 if (opt_func) {486 desc = editor.data.getMetaData().getDescription(type, opt_func);487 } else if (type === shorthand.constants.SHAPE_PICK) {488 desc = 'A Picked Shape is triggered when the user clicks on a shape that is part of a Model.';489 } else if (type === shorthand.constants.CAM_MOVE) {490 desc = 'A Camera Move is triggered when a Camera arrives at a Viewpoint.';491 } else {492 desc = editor.data.getMetaData().getDescription(type);493 }494 495 if (desc != null) {496 this.tooltips.put(nodeId, desc);497 }498 };499 500 function addTrigger(citizen, createType) {501 if (createType) {502 addTriggerType.call(this, citizen);503 }504 505 var triggerNode = shorthand.treeData.createTriggerJson(citizen, 506 this.pre),507 type = citizen._octaneType.split('.').pop(),508 msgSent = citizen._msgSent,509 name = shorthand.treeData.getNodeName(citizen, {510 option: shorthand.treeData.MSG_WILDCARD,511 prefix: this.pre512 });513 514 this.tooltips.put(name, 'any of the triggers for the ' + type);515 516 if (citizen instanceof hemi.Model) {517 shorthand.treeData.createModelPickJson(citizen, triggerNode, this.pre);518 shorthand.treeData.createModelTransformTriggerJson(citizen, triggerNode, this.pre);519 } else if (citizen instanceof hemi.Shape) {520 shorthand.treeData.createShapePickJson(citizen, triggerNode, this.pre);521 shorthand.treeData.createShapeTransformTriggerJson(citizen, triggerNode, this.pre);522 } else if (citizen instanceof hemi.Camera) {523 var cmc = shorthand.treeData.createCamMoveCitizen(citizen),524 cmcTriggerNode = shorthand.treeData.createCamMoveJson(cmc, this.pre),525 cmcType = cmc._octaneType.split('.').pop();526 527 this.tree.jstree('create_node', '#' + this.pre + cmcType, 'inside', {528 json_data: cmcTriggerNode529 });530 } else if (citizen instanceof hemi.Viewpoint) {531 // In future if we support multiple cameras, this will need to532 // be updated533 var cmc = shorthand.treeData.createCamMoveCitizen(editor.client.camera),534 nodeName = shorthand.treeData.getNodeName(cmc, {535 prefix: this.pre536 }),537 node = jQuery('#' + nodeName);538 539 if (node.length > 0) {540 triggerNode = shorthand.treeData.createViewpointJson(cmc, 541 citizen, this.pre);542 543 this.tree.jstree('create_node', node, 'inside', {544 json_data: triggerNode545 });546 }547 }548 this.tree.jstree('create_node', '#' + this.pre + type + 'Type', 'inside', {549 json_data: triggerNode550 });551 552 for (var i = 0, il = msgSent ? msgSent.length : 0; i < il; ++i) {553 addTriggerToolTip.call(this, citizen, citizen._msgSent[i]);554 }555 };556 557 function addTriggerToolTip(citizen, msg) {558 var nodeId = shorthand.treeData.getNodeName(citizen, {559 prefix: this.pre,560 option: msg561 });562 563 msg = msg.split('.').pop();564 var desc = editor.data.getMetaData().getMsgDescription(citizen._octaneType, msg);565 566 if (desc != null) {567 this.tooltips.put(nodeId, desc);568 }569 };570 571 function addTriggerType(citizen) {572 var json = shorthand.treeData.createOctaneTypeJson(citizen, this.pre);573 574 this.tree.jstree('create_node', -1, 'last', {575 json_data: json576 });577 578 addToolTip.call(this, citizen);579 580 if (citizen instanceof hemi.Camera) {581 var cmc = shorthand.treeData.createCamMoveCitizen(citizen);582 json = shorthand.treeData.createCamMoveTypeJson(cmc, this.pre);583 584 this.tree.jstree('create_node', -1, 'last', {585 json_data: json586 });587 588 addToolTip.call(this, cmc);589 }590 };591 592 function createActionTree(json) {593 this.tree = jQuery('<div class="sharedTree"></div>');594 this.container = this.tree;595 596 this.tree.jstree({597 'json_data': {598 'data': json,599 'progressive_render': true600 },601 'types': {602 'types': {603 'method': {604 'icon': {605 'image': 'images/treeSprite.png',606 'position': '-80px 0'607 }608 },609 'citizen': {610 'icon': {611 'image': 'images/treeSprite.png',612 'position': '-48px 0'613 }614 },615 'citType': {616 'icon': {617 'image': 'images/treeSprite.png',618 'position': '-64px 0'619 }620 },621 'other': {}622 }623 },624 'themes': {625 'dots': false626 },627 'ui': {628 'select_limit': 1,629 'selected_parent_close': 'false'630 },631 'plugins': ['json_data', 'sort', 'themes', 'types', 'ui']632 });633 };634 635 function createCitizenTree(json) {636 this.tree = jQuery('<div></div>');637 this.container = this.tree;638 639 this.tree.jstree({640 'json_data': {641 'data': json,642 'progressive_render': true643 },644 'types': {645 'types': {646 'citizen': {647 'icon': {648 'image': 'images/treeSprite.png',649 'position': '-48px 0'650 }651 },652 'citType': {653 'icon': {654 'image': 'images/treeSprite.png',655 'position': '-64px 0'656 }657 }658 }659 },660 'themes': {661 'dots': false662 },663 'ui': {664 'select_limit': 1,665 'selected_parent_close': 'false'666 },667 'plugins': ['json_data', 'sort', 'themes', 'types', 'ui']668 });669 };670 671 function createTriggerTree(json) {672 var wildcardTrigger = shorthand.treeData.createWildcardJson(this.pre);673 674 json.unshift(wildcardTrigger);675 this.tree = jQuery('<div class="sharedTree"></div>');676 this.container = this.tree;677 678 this.tree.jstree({679 'json_data': {680 'data': json,681 'progressive_render': true682 },683 'types': {684 'types': {685 'message': {686 'icon': {687 'image': 'images/treeSprite.png',688 'position': '-80px 0'689 }690 },691 'citizen': {692 'icon': {693 'image': 'images/treeSprite.png',694 'position': '-48px 0'695 }696 },697 'citType': {698 'icon': {699 'image': 'images/treeSprite.png',700 'position': '-64px 0'701 }702 }703 }704 },705 'themes': {706 'dots': false707 },708 'ui': {709 'select_limit': 1,710 'selected_parent_close': 'false'711 },712 'plugins': ['json_data', 'sort', 'themes', 'types', 'ui']713 });714 715 var wildcard = shorthand.treeData.MSG_WILDCARD,716 name = shorthand.treeData.getNodeName(wildcard, {717 option: wildcard,718 prefix: this.pre719 });720 721 this.tooltips.put(name, 'any trigger from any source');722 723 name = shorthand.treeData.getNodeName(wildcard, {724 prefix: this.pre725 });726 727 this.tooltips.put(name, 'a trigger from any source');728 };729 730 function deselectAction(data) {731 var citizen = data.citizen, 732 method = data.method,733 nodeName = shorthand.treeData.getNodeName(citizen, {734 option: method,735 prefix: this.pre736 }),737 node = jQuery('#' + nodeName),738 actionText = jQuery('#msgEdtEffectTxt');739 740 this.tree.jstree('deselect_node', node);741 actionText.text('');742 };743 744 function deselectTrigger(data) {745 var citizen = data.citizen, 746 message = data.message,747 nodeName = shorthand.treeData.getNodeName(citizen, {748 option: message,749 prefix: this.pre750 }),751 node = jQuery('#' + nodeName),752 triggerText = jQuery('#msgEdtCauseTxt');753 754 this.tree.jstree('deselect_node', node);755 triggerText.text('');756 };757 758 function removeAction(citizen, removeType) {759 var id = citizen._getId ? citizen._getId() : null,760 nodeName = shorthand.treeData.getNodeName(citizen, {761 prefix: this.pre762 });763 764 var node = jQuery('#' + nodeName);765 this.tree.jstree('delete_node', node);766 if (citizen instanceof hemi.Model || citizen instanceof hemi.Shape) {767 var spc = shorthand.treeData.createShapePickCitizen(citizen),768 tc = shorthand.treeData.createTransformCitizen(citizen);769 nodeName = shorthand.treeData.getNodeName(spc, {770 prefix: this.pre771 });772 this.tree.jstree('delete_node', jQuery('#' + nodeName));773 774 nodeName = shorthand.treeData.getNodeName(tc, {775 prefix: this.pre776 });777 this.tree.jstree('delete_node', jQuery('#' + nodeName));778 }779 780 if (removeType) {781 removeActionType.call(this, citizen);782 }783 };784 785 function removeActionType(citizen) {786 var nodeName = shorthand.treeData.getNodeName(citizen._octaneType.split('.').pop() + 787 'Type', { prefix: this.pre });788 789 var node = jQuery('#' + nodeName);790 this.tree.jstree('delete_node', node);791 if (citizen instanceof hemi.Model || citizen instanceof hemi.Shape) {792 nodeName = shorthand.treeData.getNodeName(shorthand.constants.TRANSFORM, {793 prefix: this.pre794 });795 796 node = jQuery('#' + nodeName);797 var nodeJson = this.tree.jstree('get_json', node);798 799 if (!nodeJson[0].children) {800 this.tree.jstree('delete_node', node);801 }802 }803 };804 805 function removeCitizen(citizen, removeType) {806 var nodeName = shorthand.treeData.getNodeName(citizen, {807 prefix: this.pre808 });809 810 var node = jQuery('#' + nodeName);811 this.tree.jstree('delete_node', node);812 813 if (removeType) {814 removeOctaneType.call(this, citizen);815 }816 };817 818 function removeOctaneType(citizen) {819 var nodeName = shorthand.treeData.getNodeName(citizen._octaneType.split('.').pop(), {820 prefix: this.pre821 });822 823 var node = jQuery('#' + nodeName);824 this.tree.jstree('delete_node', node);825 };826 827 function removeTrigger(citizen, removeType) {828 var id = citizen._getId ? citizen._getId() : null,829 nodeName = shorthand.treeData.getNodeName(citizen, {830 prefix: this.pre831 });832 833 var node = jQuery('#' + nodeName);834 this.tree.jstree('delete_node', node);835 836 if (citizen instanceof hemi.Model || citizen instanceof hemi.Shape) {837 var spc = shorthand.treeData.createShapePickCitizen(citizen),838 tc = shorthand.treeData.createTransformCitizen(citizen);839 nodeName = shorthand.treeData.getNodeName(spc, {840 prefix: this.pre841 });842 this.tree.jstree('delete_node', jQuery('#' + nodeName));843 844 nodeName = shorthand.treeData.getNodeName(tc, {845 prefix: this.pre846 });847 this.tree.jstree('delete_node', jQuery('#' + nodeName));848 } else if (citizen instanceof hemi.Camera) {849 var cmc = shorthand.treeData.createCamMoveCitizen(citizen);850 nodeName = shorthand.treeData.getNodeName(cmc, {851 prefix: this.pre852 });853 854 node = jQuery('#' + nodeName);855 this.tree.jstree('delete_node', node);856 } else if (citizen instanceof hemi.Viewpoint) {857 // In future if we support multiple cameras, this will need to858 // be updated859 var cmc = shorthand.treeData.createCamMoveCitizen(editor.client.camera);860 nodeName = shorthand.treeData.getNodeName(citizen, {861 prefix: this.pre,862 parent: cmc863 });864 865 node = jQuery('#' + nodeName);866 this.tree.jstree('delete_node', node);867 }868 869 if (removeType) {870 removeTriggerType.call(this, citizen);871 }872 };873 874 function removeTriggerType(citizen) {875 var nodeName = shorthand.treeData.getNodeName(citizen._octaneType.split('.').pop() + 'Type', {876 prefix: this.pre877 });878 879 var node = jQuery('#' + nodeName);880 this.tree.jstree('delete_node', node);881 882 if (citizen instanceof hemi.Model || citizen instanceof hemi.Shape) {883 nodeName = shorthand.treeData.getNodeName(shorthand.constants.SHAPE_PICK, {884 prefix: this.pre885 });886 887 node = jQuery('#' + nodeName);888 var nodeJson = this.tree.jstree('get_json', node);889 890 if (!nodeJson[0].children) {891 this.tree.jstree('delete_node', node);892 }893 nodeName = shorthand.treeData.getNodeName(shorthand.constants.TRANSFORM, {894 prefix: this.pre895 });896 897 node = jQuery('#' + nodeName);898 nodeJson = this.tree.jstree('get_json', node);899 900 if (!nodeJson[0].children) {901 this.tree.jstree('delete_node', node);902 }903 } else if (citizen instanceof hemi.Camera) {904 nodeName = shorthand.treeData.getNodeName(shorthand.constants.CAM_MOVE, {905 prefix: this.pre906 });907 908 node = jQuery('#' + nodeName);909 this.tree.jstree('delete_node', node);910 }911 };912 913 function updateTrigger(citizen) {914 if (citizen instanceof hemi.Shape) {915 var nodeName = shorthand.treeData.getNodeName(citizen, {916 prefix: this.pre917 }),918 type = citizen._octaneType.split('.').pop() + 'Type',919 node = shorthand.treeData.createTriggerJson(citizen, 920 this.pre);921 922 shorthand.treeData.createShapePickJson(citizen, node, this.pre);923 shorthand.treeData.createShapeTransformTriggerJson(citizen, node, this.pre);924 this.tree.jstree('delete_node', '#' + nodeName); 925 this.tree.jstree('create_node', '#' + this.pre + type, 'inside', {926 json_data: node927 });928 } else if (citizen instanceof hemi.Viewpoint) {929 // In future if we support multiple cameras, this will need to930 // be updated931 var cmc = shorthand.treeData.createCamMoveCitizen(editor.client.camera),932 nodeName = shorthand.treeData.getNodeName(citizen, {933 prefix: this.pre,934 parent: cmc935 });936 937 this.generateNodes(nodeName, false);938 this.tree.jstree('rename_node', '#' + nodeName, citizen.name);939 }940 941 // TODO: now update valuecheck behaviors to show the updated name942 };943 944////////////////////////////////////////////////////////////////////////////////////////////////////945// Helper Methods //946////////////////////////////////////////////////////////////////////////////////////////////////////...
e1_J.js
Source:e1_J.js
...16 var vWI = displaystyle == "true";17 if (vlE == vWI) n.remove(com.wiris.e1_J.vVI);18 else vlE = vWI;19 };20 if (n.getNodeName() == "mfrac") vlE = false;21 };22 var childs = n.iterator();23 while (childs.hasNext()) this.vUI(childs.next(), vlE);24 if (n.nodeType == Xml.Element) {25 var displaystyle;26 childs = n.elements();27 if (com.wiris.e1_J.vXI.indexOf("@" + n.getNodeName() + "@1@") >= 0 && childs.hasNext() && (displaystyle = childs.next().get(com.wiris.e1_J.vVI)) != null && !(n.getNodeName() == "math")) {28 var common = n.get(com.wiris.e1_J.vVI) == null || n.get(com.wiris.e1_J.vVI) == displaystyle;29 var count = 1;30 while (common && childs.hasNext()) {31 common = displaystyle == childs.next().get(com.wiris.e1_J.vVI);32 count++;33 };34 if (common && count >= 2) {35 childs = n.elements();36 while (childs.hasNext()) childs.next().remove(com.wiris.e1_J.vVI);37 n.set(com.wiris.e1_J.vVI, displaystyle);38 }39 }40 }41 }42 },43 vYI: function(name) {44 return name == "mn" || name == "mi" || name == "mo" || name == "mtext";45 },46 vZI: function(n, pos) {47 if (n.nodeType == Xml.Document || n.nodeType == Xml.Element) {48 var childs;49 if (n.nodeType == Xml.Element) {50 var mathvariant = n.get("mathvariant");51 var mathsize = n.get("mathsize");52 if (com.wiris.e1_J.vaI.indexOf(n.getNodeName()) == -1 && !(n.getNodeName() == "math") && (mathvariant != null || mathsize != null)) {53 childs = n.iterator();54 while (childs.hasNext()) {55 var c = childs.next();56 if (c.nodeType == Xml.Element) {57 if (mathvariant != null) c.set("mathvariant", mathvariant);58 if (mathsize != null) c.set("mathsize", mathsize);59 }60 };61 n.remove("mathvariant");62 n.remove("mathsize");63 }64 };65 childs = n.iterator();66 var i = 0;67 while (childs.hasNext()) this.vZI(childs.next(), i++);68 // TUDO: è¿åå¯ä»¥å°è¯ä¼å69 if (n.nodeType == Xml.Element && !(n.getNodeName() == "__document")) {70 var p = n.getParent();71 if (n.getNodeName() == "mrow" && n.firstElement() != null) {72 var c;73 var it = n.iterator();74 var k = 0;75 while (it.hasNext()) {76 var m = it.next();77 if (com.wiris.e1_J.subs.indexOf("@" + m.getNodeName() + "@") != -1) {78 var vbI = Xml.createElement("m" + m.getNodeName());79 this.vTI(vbI, m);80 var vcI = null;81 childs = n.iterator();82 var vH4;83 var vc1 = 0;84 while (vc1 < k) {85 var vdI = vc1++;86 c = childs.next();87 if (c.nodeType == Xml.Element) vcI = c;88 };89 if (vcI != null) n.removeChild(vcI);90 else vcI = Xml.createElement("mrow");91 vbI.addChild(vcI);92 while ((c = m.firstChild()) != null) {93 m.removeChild(c);94 vbI.addChild(c);95 };96 n.removeChild(m);97 n.insertChild(vbI, k - 1);98 it = n.iterator();99 k = 0;100 } else if (com.wiris.e1_J.veI.indexOf("@" + m.getNodeName() + "@") != -1) {101 var mmultiscripts = Xml.createElement("mmultiscripts");102 this.vTI(mmultiscripts, m);103 var vfI = null;104 while (it.hasNext()) {105 c = it.next();106 if (c.nodeType == Xml.Element) {107 vfI = c;108 break;109 }110 };111 var next = null;112 while (it.hasNext()) {113 c = it.next();114 if (c.nodeType == Xml.Element) {115 next = c;116 break;117 }118 };119 if (vfI != null) n.removeChild(vfI);120 else vfI = Xml.createElement("mrow");121 mmultiscripts.addChild(vfI);122 if (next != null && com.wiris.e1_J.subs.indexOf("@" + next.getNodeName() + "@") != -1) {123 n.removeChild(next);124 if (next.getNodeName() == "sup") mmultiscripts.addChild(Xml.createElement("none"));125 while ((c = next.firstChild()) != null) {126 next.removeChild(c);127 mmultiscripts.addChild(c);128 };129 if (next.getNodeName() == "sub") mmultiscripts.addChild(Xml.createElement("none"));130 };131 mmultiscripts.addChild(Xml.createElement("mprescripts"));132 if (m.getNodeName() == "presup") mmultiscripts.addChild(Xml.createElement("none"));133 while ((c = m.firstChild()) != null) {134 m.removeChild(c);135 mmultiscripts.addChild(c);136 };137 if (m.getNodeName() == "presub") mmultiscripts.addChild(Xml.createElement("none"));138 n.removeChild(m);139 n.insertChild(mmultiscripts, k);140 it = n.iterator();141 k = 0;142 } else k++;143 };144 childs = n.elements();145 c = childs.next();146 if (!childs.hasNext() && n.get(com.wiris.e1_J.vgI) == null) {147 p.removeChild(n);148 p.insertChild(c, pos);149 this.vTI(c, n);150 n = c;151 }152 };153 var displaystyle = n.get(com.wiris.e1_J.vVI);154 if (!(n.getNodeName() == "mstyle") && displaystyle != null) {155 var m = Xml.createElement("mstyle");156 m.set(com.wiris.e1_J.vVI, displaystyle);157 n.remove(com.wiris.e1_J.vVI);158 p.removeChild(n);159 m.addChild(n);160 p.insertChild(m, pos);161 n = m;162 };163 var indentalign = n.get(com.wiris.e1_J.vhI);164 if (!(n.getNodeName() == "mstyle") && !(n.getNodeName() == "math") && indentalign != null) {165 var m = Xml.createElement("mstyle");166 m.set(com.wiris.e1_J.vhI, indentalign);167 n.remove(com.wiris.e1_J.vhI);168 p.removeChild(n);169 m.addChild(n);170 p.insertChild(m, pos);171 n = m;172 };173 var mathsize = n.get(com.wiris.e1_J.viI);174 if (n.getNodeName() == "math" && mathsize != null) {175 var m = Xml.createElement("mstyle");176 m.set(com.wiris.e1_J.viI, mathsize);177 n.remove(com.wiris.e1_J.viI);178 var vH4 = n.iterator();179 while (vH4.hasNext()) {180 var vTB = vH4.next();181 n.removeChild(vTB);182 m.addChild(vTB);183 };184 n.addChild(m);185 };186 if (com.wiris.e1_J.vXI.indexOf("@" + n.getNodeName() + "@1@") != -1) {187 childs = n.iterator();188 var m = Xml.createElement(n.getNodeName());189 this.vTI(m, n);190 var c;191 while ((c = n.firstChild()) != null)192 if (c.nodeType == Xml.Element && c.getNodeName() == "mrow" && !c.attributes().hasNext()) {193 n.removeChild(c);194 var vr8;195 while ((vr8 = c.firstChild()) != null) {196 c.removeChild(vr8);197 m.addChild(vr8);198 }199 } else {200 n.removeChild(c);201 m.addChild(c);202 };203 p.removeChild(n);204 p.insertChild(m, pos);205 n = m;206 };207 if (n.getNodeName() == "mfenced") {208 this.vjI(n, "open", com.wiris.e1_J.vkI, true);209 this.vjI(n, "close", com.wiris.e1_J.vkI, true);210 };211 if (this.vYI(n.getNodeName())) {212 var text = com.wiris.util.xml.WXmlUtils.getNodeValue(n.firstChild());213 if (text.length == 1) {214 var vlI = HxOverrides.cca(text, 0);215 if (vlI == 10) {216 var m = Xml.createElement("mspace");217 m.set("linebreak", "newline");218 p.insertChild(m, pos);219 p.removeChild(n);220 n = m;221 } else if (vlI == com.wiris.editor.formula.WCharacter.vu9) {222 var m = Xml.createElement("mspace");223 m.set("width", "-0.2em");224 p.insertChild(m, pos);225 p.removeChild(n);226 n = m;227 }228 }229 };230 if (n.getNodeName() == "mo") this.vmI(n, com.wiris.e1_J.vnI, true, null);231 if (n.getNodeName() == "math") {232 if ("ltr" == n.get("dir")) n.remove("dir");233 }234 }235 }236 },237 vnH: function(vc3, rule, r) {238 var v5G = new StringBuf();239 var i;240 var vd1 = 0,241 vc1 = vc3.length;242 while (vd1 < vc1) {243 var vW9 = vd1++;244 if (vW9 > 0) v5G.b += Std.string("-");245 v5G.b += Std.string(HxOverrides.cca(vc3, vW9));246 };247 var vJ1 = (r ? "$" : "@") + v5G.b + (r ? "@" : "$");248 var index = rule.indexOf(vJ1);249 if (index != -1) {250 var start;251 if (r) start = rule.lastIndexOf("@", index) + 1;252 else {253 start = index + vJ1.length;254 index = rule.indexOf("@", start);255 };256 var voI = HxOverrides.substr(rule, start, index - start).split("-");257 var vpI = new StringBuf();258 var vd1 = 0,259 vc1 = voI.length;260 while (vd1 < vc1) {261 var vW9 = vd1++;262 vpI.b += Std.string(com.wiris.e1_61.v12(Std.parseInt(voI[vW9])));263 };264 vc3 = vpI.b;265 };266 return vc3;267 },268 vjI: function(node, name, rule, vqI) {269 var value = com.wiris.util.xml.WXmlUtils.getAttribute(node, name);270 if (value != null) {271 var vrI = this.vnH(value, rule, vqI);272 if (value != vrI) com.wiris.util.xml.WXmlUtils.setAttribute(node, name, vrI);273 }274 },275 vmI: function(node, rule, vqI, ve3) {276 var c = node.firstChild();277 if (c != null && (c.nodeType == Xml.PCData || c.nodeType == Xml.CData)) {278 var vFH = com.wiris.util.xml.WXmlUtils.getNodeValue(c);279 var vsI = this.vnH(vFH, rule, vqI);280 if (vFH != vsI) {281 node.removeChild(c);282 node.insertChild(com.wiris.util.xml.WXmlUtils.createPCData(node, vsI), 0);283 if (ve3 != null) {284 var keys = ve3.keys();285 while (keys.hasNext()) {286 var name = keys.next();287 node.set(name, ve3.get(name));288 }289 }290 }291 }292 },293 vtI: function(n, sub, sup, pre) {294 var script = null;295 var prefix = pre ? "pre" : "";296 var vuI = sub == null || sub.getNodeName() == "none";297 var vvI = sup == null || sup.getNodeName() == "none";298 if (vuI && !vvI) {299 script = Xml.createElement(prefix + "sup");300 n.removeChild(sup);301 script.addChild(sup);302 } else if (!vuI && vvI) {303 script = Xml.createElement(prefix + "sub");304 n.removeChild(sub);305 script.addChild(sub);306 } else if (!vuI && !vvI) {307 script = Xml.createElement(prefix + "subsup");308 n.removeChild(sub);309 n.removeChild(sup);310 script.addChild(sub);311 script.addChild(sup);312 };313 return script;314 },315 vwI: function(n, pos) {316 var p = n.getParent();317 if (n.getNodeName() == "mtable" && p != null && p.nodeType == Xml.Element && p.getNodeName() == "math" && "left" == n.get("columnalign") && "0" == n.get("rowspacing")) {318 var m = Xml.createElement("mrow");319 if (n.get("dir") != null) m.set("dir", n.get("dir"));320 var vxI = n.iterator();321 var first = true;322 while (vxI.hasNext()) {323 var mtr = vxI.next();324 if (mtr.nodeType == Xml.Element && mtr.getNodeName() == "mtr") {325 if (!first) {326 var vvG = Xml.createElement("mspace");327 vvG.set("linebreak", "newline");328 m.addChild(vvG);329 };330 var cols = mtr.iterator();331 while (cols.hasNext()) {332 var mtd = cols.next();333 if (mtd.nodeType == Xml.Element && mtd.getNodeName() == "mtd") {334 var c;335 while ((c = mtd.firstChild()) != null) {336 mtd.removeChild(c);337 m.addChild(c);338 }339 }340 };341 first = false;342 }343 };344 p.insertChild(m, pos);345 p.removeChild(n);346 n = m;347 };348 if (n.getNodeName() == "csymbol") {349 var m = Xml.createElement("mrow");350 if (n.get("dir") != null) m.set("dir", n.get("dir"));351 var c;352 while ((c = n.firstChild()) != null)353 if (c.nodeType == Xml.Element) {354 n.removeChild(c);355 m.addChild(c);356 } else357 if (c.nodeType == Xml.PCData || c.nodeType == Xml.CData) {358 var mo = Xml.createElement("mo");359 n.removeChild(c);360 mo.addChild(c);361 m.addChild(mo);362 };363 var childs = m.iterator();364 if (childs.hasNext() && childs.next() != null && !childs.hasNext()) m = m.firstChild();365 p.insertChild(m, pos);366 p.removeChild(n);367 n = m;368 };369 if (n.getNodeName() == "template") {370 var m = Xml.createElement("maction");371 if (n.get("dir") != null) m.set("dir", n.get("dir"));372 m.set("actiontype", "argument");373 m.addChild(Xml.createElement("mrow"));374 p.insertChild(m, pos);375 p.removeChild(n);376 n = m;377 };378 return n;379 },380 vyI: function(table) {381 var vzI = 0;382 var v0J = new Array();383 var rows = table.iterator();384 while (rows.hasNext()) {385 var vq7 = rows.next();386 if (vq7.nodeType == Xml.Element && "mtr" == vq7.getNodeName()) {387 var cols = vq7.iterator();388 var v1J = 0;389 while (cols.hasNext()) {390 var v2J = cols.next();391 if (v2J.nodeType == Xml.Element && "mtd" == v2J.getNodeName()) v1J++;392 };393 v0J.push(v1J);394 vzI = com.wiris.editor.formula.IntegerTools.max(vzI, v1J);395 }396 };397 rows = table.iterator();398 var i = 0;399 while (rows.hasNext()) {400 var vq7 = rows.next();401 if (vq7.nodeType == Xml.Element && "mtr" == vq7.getNodeName()) {402 var vH4;403 var vd1 = 0,404 vc1 = vzI - v0J[i];405 while (vd1 < vc1) {406 var vdI = vd1++;407 var m = Xml.createElement("mtd");408 if (vq7.get("dir") != null) m.set("dir", vq7.get("dir"));409 var c = Xml.createElement("mspace");410 m.addChild(c);411 vq7.addChild(m);412 };413 i++;414 }415 }416 },417 v3J: function(n, pos) {418 if (n.nodeType == Xml.Element || n.nodeType == Xml.Document) {419 if (n.nodeType == Xml.Element) n = this.vwI(n, pos);420 var c;421 var childs;422 childs = n.iterator();423 while (childs.hasNext()) {424 c = childs.next();425 if (c.nodeType == Xml.Element && this.v4J(c.getNodeName())) {426 n.removeChild(c);427 childs = n.iterator();428 }429 };430 childs = n.iterator();431 var i = 0;432 while (childs.hasNext()) this.v3J(childs.next(), i++);433 if (n.nodeType == Xml.Element) {434 var p = n.getParent();435 childs = n.elements();436 if (com.wiris.e1_J.vXI.indexOf("@" + n.getNodeName() + "@1@") > 0 && (!childs.hasNext() || childs.hasNext() && childs.next() != null && childs.hasNext())) {437 var v5J = Xml.createElement("mrow");438 if (n.get("dir") != null) v5J.set("dir", n.get("dir"));439 while ((c = n.firstChild()) != null) {440 n.removeChild(c);441 v5J.addChild(c);442 };443 n.addChild(v5J);444 };445 if (com.wiris.e1_J.vXI.indexOf("@" + n.getNodeName() + "@") > 0) {446 childs = n.iterator();447 var vH4 = 0;448 while (childs.hasNext()) {449 c = childs.next();450 if (c.nodeType == Xml.Element && !(c.getNodeName() == "mrow")) {451 var v5J = Xml.createElement("mrow");452 if (n.get("dir") != null) v5J.set("dir", n.get("dir"));453 c.getParent().removeChild(c);454 v5J.addChild(c);455 n.insertChild(v5J, vH4);456 };457 vH4++;458 }459 };460 if (com.wiris.e1_J.v6J.indexOf("@" + n.getNodeName() + "@") != -1) {461 var m = Xml.createElement("mrow");462 if (n.get("dir") != null) m.set("dir", n.get("dir"));463 c = n.firstChild();464 while (c.nodeType != Xml.Element) {465 n.removeChild(c);466 m.addChild(c);467 c = n.firstChild();468 };469 n.removeChild(c);470 m.addChild(c);471 n.removeChild(c);472 var sub = Xml.createElement(HxOverrides.substr(n.getNodeName(), 1, null));473 this.vTI(sub, n);474 while ((c = n.firstChild()) != null) {475 n.removeChild(c);476 sub.addChild(c);477 };478 m.addChild(sub);479 p.removeChild(n);480 p.insertChild(m, pos);481 n = m;482 };483 if (n.getNodeName() == "mmultiscripts") {484 var m = Xml.createElement("mrow");485 if (n.get("dir") != null) m.set("dir", n.get("dir"));486 c = n.firstChild();487 while (c.nodeType != Xml.Element) {488 n.removeChild(c);489 m.addChild(c);490 c = n.firstChild();491 };492 n.removeChild(c);493 m.addChild(c);494 var vlB = null;495 var v7J = null;496 childs = n.iterator();497 while (childs.hasNext()) {498 c = childs.next();499 if (c.nodeType == Xml.Element) {500 if (c.getNodeName() == "mprescripts") break;501 if (vlB == null) vlB = c;502 else if (v7J == null) v7J = c;503 }504 };505 var vmB = null;506 var v8J = null;507 while (childs.hasNext()) {508 c = childs.next();509 if (c.nodeType == Xml.Element) {510 if (vmB == null) vmB = c;511 else if (v8J == null) v8J = c;512 }513 };514 var v9J = this.vtI(n, vlB, v7J, false);515 var pre = this.vtI(n, vmB, v8J, true);516 if (pre != null) m.insertChild(pre, 0);517 if (v9J != null) m.addChild(v9J);518 p.removeChild(n);519 p.insertChild(m, pos);520 n = m;521 };522 if (n.getNodeName() == "semantics") {523 var m = Xml.createElement("mrow");524 if (n.get("dir") != null) m.set("dir", n.get("dir"));525 while ((c = n.firstChild()) != null)526 if (c.nodeType != Xml.Element || c.getNodeName() == "annotation" || c.getNodeName() == "annotation-xml") n.removeChild(c);527 else528 if (!(c.getNodeName() == "mrow")) {529 n.removeChild(c);530 m.addChild(c);531 } else {532 n.removeChild(c);533 var d;534 while ((d = c.firstChild()) != null) {535 c.removeChild(d);536 m.addChild(d);537 }538 };539 p.removeChild(n);540 p.insertChild(m, pos);541 n = m;542 };543 if (n.getNodeName() == "mfenced") {544 this.vjI(n, "open", com.wiris.e1_J.vkI, false);545 this.vjI(n, "close", com.wiris.e1_J.vkI, false);546 };547 if (n.getNodeName() == "mo") {548 c = n.firstChild();549 if (c != null) {550 var text = com.wiris.util.xml.WXmlUtils.getNodeValue(c);551 if (text.length > 1) {552 var vAJ = StringTools.trim(text);553 if (vAJ.length < text.length) {554 n.removeChild(c);555 n.insertChild(com.wiris.util.xml.WXmlUtils.createPCData(n, vAJ), 0);556 }557 }558 };559 this.vmI(n, com.wiris.e1_J.vnI, false, null);560 this.vmI(n, com.wiris.e1_J.vBJ, false, null);561 var vCJ = new HaxeHash();562 vCJ.set("largeop", "true");563 this.vmI(n, com.wiris.e1_J.vDJ, false, vCJ);564 };565 if (n.getNodeName() == "mspace") {566 if ("newline" == n.get("linebreak")) {567 var m = Xml.createElement("mo");568 if (n.get("dir") != null) m.set("dir", n.get("dir"));569 c = com.wiris.util.xml.WXmlUtils.createPCData(m, com.wiris.e1_61.v12(10));570 m.addChild(c);571 p.insertChild(m, pos);572 p.removeChild(n);573 n = m;574 }575 };576 if (n.getNodeName() == "mtable") this.vyI(n);577 }578 }579 },580 vEJ: function(n, pos, vt9) {581 var vi1;582 if (n.nodeType == Xml.Element) {583 var ve3 = n.attributes();584 while (ve3.hasNext()) {585 var name = ve3.next();586 if (StringTools.startsWith(name, "xmlns")) {587 vi1 = "";588 if (name.length > 5) vi1 = HxOverrides.substr(name, 6, null);589 var url = n.get(name);590 vt9.set(vi1, url);591 if (url == com.wiris.e1_i.vFJ) {592 n.remove(name);593 n.set("xmlns", com.wiris.e1_i.vFJ);594 }595 }596 }597 };598 var childs = n.iterator();599 var i = 0;600 while (childs.hasNext()) {601 var c = childs.next();602 if (c.nodeType == Xml.Element) this.vEJ(c, i, vt9);603 i++;604 };605 if (n.nodeType == Xml.Element) {606 var index;607 if ((index = n.getNodeName().indexOf(":")) != -1) {608 vi1 = HxOverrides.substr(n.getNodeName(), 0, index);609 if (!vt9.exists(vi1) || vt9.get(vi1) == com.wiris.e1_i.vFJ) {610 var name = HxOverrides.substr(n.getNodeName(), index + 1, null);611 var m = Xml.createElement(name);612 this.vTI(m, n);613 var c;614 while ((c = n.firstChild()) != null) {615 n.removeChild(c);616 m.addChild(c);617 };618 var p = n.getParent();619 if (p != null) {620 p.removeChild(n);621 p.insertChild(m, pos);622 }623 }624 }625 }626 },627 v4J: function(tag) {628 return tag == "maligngroup" || tag == "malignmark";629 },630 vGJ: function(node) {631 if (node.nodeType != Xml.Element) return false;632 if (StringTools.startsWith(node.getNodeName(), "wrs:")) return true;633 var i = node.attributes();634 while (i.hasNext()) {635 var vC5 = i.next();636 if (StringTools.startsWith(vC5, "wrs:")) return true;637 };638 var vH4 = node.iterator();639 while (vH4.hasNext())640 if (this.vGJ(vH4.next())) return true;641 return false;642 },643 formulaToStandard: function(n, vlE) {644 this.vUI(n, vlE);645 this.vZI(n, 0);646 if (this.vGJ(n.firstChild())) com.wiris.util.xml.WXmlUtils.setAttribute(n.firstChild(), "xmlns:wrs", com.wiris.e1_J.vHJ);...
treeData.js
Source:treeData.js
...118////////////////////////////////////////////////////////////////////////////////////////////////////119// Methods120////////////////////////////////////////////////////////////////////////////////////////////////////121 function createCitizenJson(citizen, prefix, opt_parent) {122 var name = getNodeName(citizen, {123 option: null,124 prefix: prefix125 });126 127 return {128 data: citizen.name || '',129 attr: {130 id: name,131 rel: 'citizen'132 },133 metadata: {134 type: 'citizen',135 citizen: citizen136 }137 };138 }139 140 function createModelTransformJson(model, node, prefix, method) {141 var list = [],142 transforms = [],143 hash = new Hashtable(),144 nodeJson;145 owners.put(model.root, model);146 nodeJson = shorthand.treeData[method](model.root, prefix);147 hash.put(model.root, nodeJson);148 149 traverseHierarchy(model.root, function(transform, parent) {150 owners.put(transform, model);151 var n = shorthand.treeData[method](transform, prefix);152 hash.put(transform, n);153 hash.get(parent).children.push(n);154 });155 156 node.children.push({157 data: 'transforms',158 attr: {159 id: getNodeName(model, {160 option: shorthand.constants.TRANSFORM,161 prefix: prefix162 }),163 rel: 'other'164 },165 children: [nodeJson],166 state: 'closed',167 metadata: {168 type: 'set'169 }170 });171 }172 173 function createShapeTransformJson(shape, node, prefix, method) {174 owners.put(shape.mesh, shape);175 176 node.children.push({177 data: 'transforms',178 attr: {179 id: getNodeName(shape, {180 option: shorthand.constants.TRANSFORM,181 prefix: prefix182 }),183 rel: 'other'184 },185 children: [shorthand.treeData[method](shape.mesh, prefix)],186 state: 'closed',187 metadata: {188 type: 'set'189 }190 });191 }192 193 function getNodeName(citizen, config) {194 var nodeName = config.prefix;195 196 if (citizen === null) {197 return null;198 } else if (citizen === MSG_WILDCARD) {199 nodeName += citizen;200 } else if (citizen._octaneType !== undefined) {201 var type = citizen._octaneType.split('.').pop(),202 path = type + 'Type' + '_',203 id = citizen._getId(),204 cit;205 // determine paths206 if ((citizen instanceof hemi.Transform || citizen instanceof hemi.Mesh)) {207 cit = owners.get(citizen);208 var citType = cit._octaneType.split('.').pop(),209 parPath = getTransformPath(citizen);210 path = citType + 'Type_' + citType + '-' + cit._getId() + '_' 211 + shorthand.constants.TRANSFORM + parPath;212 } else if (citizen instanceof hemi.Viewpoint && config.parent) {213 cit = config.parent.citizen;214 path = config.parent._octaneType.split('.').pop() + '_' + 215 cit._octaneType.split('.').pop() + '-' + cit._getId() + '_';216 } else if (citizen._octaneType === shorthand.constants.CAM_MOVE ||217 citizen._octaneType === shorthand.constants.SHAPE_PICK ||218 citizen._octaneType === shorthand.constants.TRANSFORM) {219 cit = citizen.citizen;220 path = citizen._octaneType.split('.').pop() + '_';221 type = cit._octaneType.split('.').pop();222 id = cit._getId();223 } 224 nodeName += (path !== null ? path : '') + type + (id !== null ? '-' + id : '');225 } else if ((typeof citizen) === 'string') {226 nodeName += citizen;227 }228 229 if (config.option != null) {230 nodeName += '_' + config.option;231 }232 233 return nodeName.replace(' ', '-').replace('.', '-');234 }235 236 function getNodePath(nodeName) {237 var ndx = nodeName.indexOf('_'),238 names = [];239 240 ndx = nodeName.indexOf('_', ndx + 1);241 242 while (ndx > -1) {243 names.push(nodeName.substr(0, ndx));244 ndx = nodeName.indexOf('_', ndx + 1);245 }246 247 return names;248 }249 250 251 function getTransformPath(transform) {252 var path = '_',253 parent = transform.parent;254 255 if (parent != editor.client.scene) {256 path = parent._octaneType.split('.').pop() + '-' + parent._getId() + path;257 path = getTransformPath(parent) + path;258 }259 260 return path;261 }262 function isCommon(citizen, method) {263 var type = citizen._octaneType ? citizen._octaneType : citizen.name,264 methList = commonMethods[type],265 common = false;266 267 if (citizen.parent != null) {268 common = isCommon(citizen.parent, method);269 }270 271 if (!common && methList != null) {272 common = methList.indexOf(method) !== -1;273 }274 275 return common;276 }277 function traverseHierarchy(root, callback) {278 var n, i, l = root.children.length;279 for (i = 0; i < l; i++) {280 n = root.children[ i ];281 callback(n, root);282 traverseHierarchy(n, callback);283 }284 }285 286 shorthand.treeData.getNodeName = getNodeName;287 shorthand.treeData.getNodePath = getNodePath;288 shorthand.treeData.createCitizenJson = createCitizenJson;289 shorthand.treeData.isCommon = isCommon;290 shorthand.treeData.cleanup = function() {291 owners.clear();292 };293 294 shorthand.treeData.createActionJson = function(citizen, prefix) {295 var id = citizen._getId(),296 fcnPre = shorthand.constants.FUNCTIONS,297 fcnMorePre = shorthand.constants.FUNCTIONS_MORE,298 functions = {299 data: 'functions',300 attr: {301 id: getNodeName(citizen, {302 option: fcnPre,303 prefix: prefix304 }),305 rel: 'other'306 },307 metadata: {308 type: 'set'309 }310 },311 methods = [],312 moreMethods = [],313 node;314 315 for (var propName in citizen) {316 var prop = citizen[propName];317 318 if (jQuery.isFunction(prop) && methodsToRemove.indexOf(propName) === -1) {319 var common = isCommon(citizen, propName),320 name = getNodeName(citizen, {321 option: common ? fcnPre + '_' + propName : fcnMorePre + 322 propName,323 prefix: prefix324 });325 node = {326 data: propName,327 attr: {328 id: name,329 rel: 'method'330 },331 metadata: {332 type: 'method',333 parent: citizen334 }335 };336 337 if (common) {338 methods.push(node);339 } else {340 moreMethods.push(node);341 }342 }343 }344 345 if (methods.length > 0) {346 var moreName = getNodeName(citizen, {347 option: fcnMorePre,348 prefix: prefix349 });350 var moreNode = {351 data: 'More...',352 attr: {353 id: moreName,354 rel: 'other'355 },356 state: 'closed',357 children: moreMethods,358 metadata: {359 type: 'citType'360 }361 };362 methods.push(moreNode);363 } else {364 methods = moreMethods;365 for (var i = 0, il = methods.length; i < il; i++) {366 var temp = methods[i];367 temp.attr.id = temp.attr.id.replace('MORE_', '');368 }369 }370 371 functions.children = methods;372 node = createCitizenJson(citizen, prefix);373 node.children = [functions];374 node.state = 'closed';375 return node;376 };377 378 379 shorthand.treeData.createCamMoveCitizen = function(camera) {380 return {381 camMove: true,382 name: 'Camera Move:',383 citizen: camera,384 _octaneType: shorthand.constants.CAM_MOVE,385 _getId: function() {386 return this.citizen._getId();387 }388 };389 };390 391 shorthand.treeData.createCamMoveJson = function(cmCit, prefix) {392 var camera = cmCit.citizen,393 viewpoints = hemi.world.getViewpoints(),394 nodes = [];395 396 for (var ndx = 0, len = viewpoints.length; ndx < len; ndx++) {397 var node = shorthand.treeData.createViewpointJson(cmCit,398 viewpoints[ndx], prefix);399 nodes.push(node);400 }401 402 var name = getNodeName(cmCit, {403 option: null,404 prefix: prefix405 });406 407 return {408 data: camera.name || '',409 attr: {410 id: name,411 rel: 'citizen'412 },413 children: nodes,414 state: 'closed',415 metadata: {416 type: 'citizen',417 citizen: cmCit418 }419 };420 };421 422 shorthand.treeData.createCamMoveTypeJson = function(cmCit, prefix) {423 var name = getNodeName(cmCit._octaneType, {424 option: null,425 prefix: prefix426 });427 428 return {429 data: 'Camera Move',430 attr: {431 id: name,432 rel: 'citType'433 },434 state: 'closed',435 children: [],436 metadata: {437 type: 'citType'438 }439 };440 };441 442 shorthand.treeData.createModelPickJson = function(model, node, prefix) {443 var spCit = shorthand.treeData.createShapePickCitizen(model),444 id = model._getId(),445 meshes = [],446 meshJson = [],447 pre = shorthand.constants.SHAPE_PICK,448 name;449 findMeshes(model.root, meshes);450 for (var i = 0, il = meshes.length; i < il; ++i) {451 var mesh = meshes[i];452 name = getNodeName(model, {453 option: pre + '_' + mesh.name.replace(/_/g, '-') || '',454 prefix: prefix455 });456 meshJson.push({457 data: mesh.name || '',458 attr: {459 id: name,460 rel: 'message'461 },462 metadata: {463 type: 'message',464 parent: spCit,465 msg: mesh.name || ''466 }467 });468 }469 node.children.push({470 data: 'pickable shapes',471 attr: {472 id: getNodeName(model, {473 option: pre,474 prefix: prefix475 }),476 rel: 'other'477 },478 metadata: {479 type: 'set'480 },481 children: meshJson482 });483 };484 485 shorthand.treeData.createModelTransformTriggerJson = function(model, node, prefix) {486 return createModelTransformJson(model, node, prefix, 'createTriggerJson');487 };488 489 shorthand.treeData.createModelTransformActionJson = function(model, node, prefix) {490 return createModelTransformJson(model, node, prefix, 'createActionJson');491 };492 493 shorthand.treeData.createOctaneTypeJson = function(citizen, prefix) {494 var type = citizen._octaneType.split('.').pop(),495 name = getNodeName(type + 'Type', {496 option: null,497 prefix: prefix498 });499 500 return {501 data: type,502 attr: {503 id: name,504 rel: 'citType'505 },506 state: 'closed',507 children: [],508 metadata: {509 type: 'citType'510 }511 };512 };513 514 shorthand.treeData.createShapePickCitizen = function(model) {515 return {516 shapePick: true,517 name: 'Picked Shape:',518 citizen: model,519 _octaneType: shorthand.constants.SHAPE_PICK,520 _getId: function() {521 return this.citizen._getId();522 }523 };524 };525 526 shorthand.treeData.createShapePickJson = function(shape, node, prefix) {527 var spCit = shorthand.treeData.createShapePickCitizen(shape),528 id = shape._getId(),529 pre = shorthand.constants.SHAPE_PICK,530 children = [{531 data: shape.name || '',532 attr: {533 id: getNodeName(shape, {534 option: pre + '_' + shape.name.replace(/_/g, '-') || '',535 prefix: prefix536 }),537 rel: 'message'538 },539 metadata: {540 type: 'message',541 parent: spCit,542 msg: shape.mesh.name || ''543 }544 }];545 546 node.children.push({547 data: 'pickable shapes',548 attr: {549 id: getNodeName(shape, {550 option: pre,551 prefix: prefix552 }),553 rel: 'other'554 },555 metadata: {556 type: 'set'557 },558 children: children559 });560 };561 562 shorthand.treeData.createShapePickTypeJson = function(spCit, prefix) {563 var name = getNodeName(spCit._octaneType, {564 option: null,565 prefix: prefix566 });567 568 return {569 data: 'Picked Shape',570 attr: {571 id: name,572 rel: 'citType'573 },574 state: 'closed',575 children: [],576 metadata: {577 type: 'citType'578 }579 };580 };581 582 shorthand.treeData.createShapeTransformTriggerJson = function(shape, node, prefix) {583 return createShapeTransformJson(shape, node, prefix, 'createTriggerJson');584 };585 586 shorthand.treeData.createShapeTransformActionJson = function(shape, node, prefix) {587 return createShapeTransformJson(shape, node, prefix, 'createActionJson');588 };589 590 shorthand.treeData.createTransformTypeJson = function(tCit, prefix) {591 var name = getNodeName(tCit._octaneType, {592 option: null,593 prefix: prefix594 });595 596 return {597 data: 'Transforms',598 attr: {599 id: name,600 rel: 'citType'601 },602 state: 'closed',603 children: [],604 metadata: {605 type: 'citType'606 }607 };608 };609 610 shorthand.treeData.createTransformCitizen = function(model) {611 return {612 isTransform: true,613 name: 'Transforms',614 citizen: model,615 _octaneType: shorthand.constants.TRANSFORM,616 _getId: function() {617 return this.citizen._getId();618 }619 };620 };621 622 shorthand.treeData.createTriggerJson = function(citizen, prefix) {623 var id = citizen._getId(),624 pre = shorthand.constants.MESSAGES,625 name = getNodeName(citizen, {626 option: MSG_WILDCARD,627 prefix: prefix628 }),629 msgs = [{630 data: '[any trigger]',631 attr: {632 id: name,633 rel: 'message'634 },635 metadata: {636 type: 'message',637 parent: citizen,638 msg: MSG_WILDCARD639 }640 }],641 children = [{642 data: 'messages',643 attr: {644 id: getNodeName(citizen, {645 option: pre,646 prefix: prefix647 }),648 rel: 'other'649 },650 metadata: {651 type: 'set'652 },653 children: msgs654 }],655 msgSent = citizen._msgSent;656 657 for (var ndx = 0, len = msgSent ? msgSent.length : 0; ndx < len; ndx++) {658 var msg = msgSent[ndx];659 name = getNodeName(citizen, {660 option: pre + '_' + msg,661 prefix: prefix662 });663 664 msgs.push({665 data: msg.split('.').pop(),666 attr: {667 id: name,668 rel: 'message'669 },670 metadata: {671 type: 'message',672 parent: citizen,673 msg: msg674 }675 });676 }677 678 var node = createCitizenJson(citizen, prefix);679 node.children = children;680 node.state = 'closed';681 return node;682 };683 684 shorthand.treeData.createViewpointJson = function(cmCit, viewpoint, prefix) {685 var name = getNodeName(viewpoint, {686 prefix: prefix,687 parent: cmCit688 });689 690 return {691 data: viewpoint.name || '',692 attr: {693 id: name,694 rel: 'message'695 },696 metadata: {697 type: 'message',698 parent: cmCit,699 msg: viewpoint._getId()700 }701 };702 };703 704 shorthand.treeData.createWildcardJson = function(prefix) {705 var name = getNodeName(MSG_WILDCARD, {706 option: MSG_WILDCARD,707 prefix: prefix708 }),709 msgs = [{710 data: '[any trigger]',711 attr: {712 id: name,713 rel: 'message'714 },715 metadata: {716 type: 'message',717 parent: MSG_WILDCARD,718 msg: MSG_WILDCARD719 }720 }];721 722 for (var ndx in hemi.msg) {723 var msg = hemi.msg[ndx];724 725 if (!jQuery.isFunction(msg)) {726 name = getNodeName(MSG_WILDCARD, {727 option: msg,728 prefix: prefix729 });730 731 msgs.push({732 data: msg.split('.').pop(),733 attr: {734 id: name,735 rel: 'message'736 },737 metadata: {738 type: 'message',739 parent: MSG_WILDCARD,740 msg: msg741 }742 });743 }744 }745 746 name = getNodeName(MSG_WILDCARD, {747 option: null,748 prefix: prefix749 });750 751 return {752 data: '[Any source]',753 attr: {754 id: name,755 rel: 'citizen'756 },757 state: 'closed',758 children: msgs,759 metadata: {760 type: 'citizen',...
parser.js
Source:parser.js
...60 // get the direct children61 var attributeNodes = rootNode.getChildNodes();62 for (var temp = 0; temp < attributeNodes.getLength(); temp++) {63 var attributeNode = attributeNodes.item(temp);64 var nodeName = attributeNode.getNodeName();65 66 if (targetNode.equals(nodeName)) {67 library.addElement(parseTargetNode(attributeNode)); 68 } else if (propertyNode.equals(nodeName)) {69 library.addElement(parsePropertyNode(attributeNode)); 70 } else if (macroNode.equals(nodeName)) {71 library.addElement(parseMacroNode(attributeNode)); 72 } else if (scriptNode.equals(nodeName)) {73 library.addElement(parseScriptNode(attributeNode)); 74 }75 }76 77 return library;78 }79}80// function to parse a comment81var parseComment = function(textComment) {82 var comment = new Comment();83 84 if (textComment instanceof org.w3c.dom.Node) {85 if (textComment.getNodeType() != org.w3c.dom.Node.COMMENT_NODE) {86 textComment = findCommentNode(textComment);87 }88 89 // get the content of the textComment90 textComment = textComment == null ? null : textComment.getNodeValue();91 }92 93 // make sure we have a textComment94 if (textComment != null && !"".equals(textComment.trim())) {95 textComment = textComment.trim();96 97 // the markers used in the comment98 var validMarker = "@param|@fails|@author|@since";99 100 // get the description101 var descRegEx = "^\\s*((?:(?!^\\s*(?:" + validMarker + ")).)*)";102 var descPattern = java.util.regex.Pattern.compile(descRegEx, java.util.regex.Pattern.DOTALL + java.util.regex.Pattern.MULTILINE);103 var descMatcher = descPattern.matcher(textComment);104 if (descMatcher.find()) {105 comment.setDescription(descMatcher.group(1).trim());106 }107 108 // get the markers109 var markerRegEx = "^\\s*(" + validMarker + ")((?:(?!^\\s*(?:" + validMarker + ")).)*)";110 var markerPattern = java.util.regex.Pattern.compile(markerRegEx, java.util.regex.Pattern.DOTALL + java.util.regex.Pattern.MULTILINE);111 var markerMatcher = markerPattern.matcher(textComment);112 113 // check the marker114 while (markerMatcher.find()) {115 var marker = markerMatcher.group(1).trim();116 var value = markerMatcher.group(2).trim();117 if ("@param".equals(marker)) {118 if (comment.hasParam(value)) {119 echo("The parameter '" + value + "' is defined multiple times in '" + textComment + "'", "error");120 } else {121 comment.addParam(value);122 }123 } else if ("@fails".equals(marker)) {124 comment.setFails(value);125 } else if ("@author".equals(marker)) {126 comment.setAuthor(value);127 } else if ("@since".equals(marker)) {128 comment.setSince(value);129 }130 }131 }132 133 return comment;134}135// function to parse a parameter, i.e. <parameter> <parameterdescription>136var parseParameter = function(textParameter) {137 var parameter = null;138 var paramRegEx = "^([^\\s\\[\\]]+)(?:\\[([^\\s\\[\\]]*)\\])?\\s*(.*)$";139 var paramPattern = java.util.regex.Pattern.compile(paramRegEx, java.util.regex.Pattern.DOTALL);140 var paramMatcher = paramPattern.matcher(textParameter);141 142 // check if there is really a parameter143 if (paramMatcher.find()) {144 parameter = new Parameter();145 parameter.setName(paramMatcher.group(1));146 parameter.setDefault(paramMatcher.group(2));147 parameter.setDescription(paramMatcher.group(3));148 }149 150 return parameter;151}152var parseNodeContent = function(node) {153 // remove all the whitespaces to ensure nice indent154 removeWhiteSpacesInXml(node);155 156 // now use the transformer to format157 var transformer = javax.xml.transform.TransformerFactory.newInstance().newTransformer();158 transformer.setOutputProperty(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");159 transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");160 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");161 var xmlOutput = new javax.xml.transform.stream.StreamResult(new java.io.StringWriter());162 transformer.transform(new javax.xml.transform.dom.DOMSource(node), xmlOutput);163 164 return xmlOutput.getWriter().toString();165}166// function to find the first comment placed before a node167var findCommentNode = function(node) {168 var commentNode;169 // make sure we have an element node to be checked170 if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {171 172 // look for the elements first none text node173 var prevNode = node.getPreviousSibling();174 while (prevNode != null && prevNode.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {175 prevNode = prevNode.getPreviousSibling();176 }177 178 // check if the node is a comment-node, if so we found it179 commentNode = prevNode != null && prevNode.getNodeType() == org.w3c.dom.Node.COMMENT_NODE ? prevNode : null;180 } else {181 commentNode = null;182 }183 184 return commentNode;185}186// function to parse the information provided for a target node187var parseTargetNode = function(node) {188 var name = node.getAttribute("name");189 var description = node.hasAttribute("description") ? node.getAttribute("description") : null;190 var comment = parseComment(node);191 var content = parseNodeContent(node);192 193 // get the element194 var element = new Element("target", name, comment, content);195 196 // validate the description197 if (description != null && element.comment.description != null) {198 echo("The " + node.getNodeName() + " '" + element.name + "' has two descriptions defined:", "warn");199 echo("- one via the comment ('" + element.comment.description + "') and", "warn");200 echo("- one via the attribute ('" + description + "').", "warn");201 echo("The one of the comment will be used!", "warn");202 } else if (description != null && element.comment.description == null) {203 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined via a comment, the one of the attribute will be used.", "info");204 element.comment.setDescription(description);205 } else if (element.comment.description != null && description == null) {206 // nicely done207 } else {208 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined, please do so via a comment.", "warn");209 }210 211 // validate the parameters212 if (element.comment.params.length > 0) {213 echo("The " + node.getNodeName() + " '" + element.name + "' has parameters defined which is invalid for targets.", "warn");214 }215 216 return element;217};218// function to parse the information provided for a property node219var parsePropertyNode = function(node) {220 var name = node.getAttribute("name");221 var description = node.hasAttribute("description") ? node.getAttribute("description") : null;222 var value = node.getAttribute("value");223 var location = node.getAttribute("location");224 var comment = parseComment(node);225 var content = parseNodeContent(node);226 // get the element227 var element = new Element("property", name, comment, content);228 229 // validate the name230 if (element.name == null) {231 // skip232 return null;233 }234 235 // add an extra value to this element236 element["value"] = node.hasAttribute("value") ? value : location;237 238 // validate the description239 if (description != null && element.comment.description != null) {240 echo("The " + node.getNodeName() + " '" + element.name + "' has two descriptions defined:");241 echo("- one via the comment ('" + element.comment.description + "') and");242 echo("- one via the attribute ('" + description + "').");243 echo("The one of the description will be used!", "warn");244 element.comment.setDescription(description);245 } else if (description != null && element.comment.description == null) {246 if (checkEmpty(description) == null) {247 echo("The " + node.getNodeName() + " '" + element.name + "' has an empty description defined!", "warn");248 } else {249 element.comment.setDescription(description);250 }251 } else if (element.comment.description != null && description == null) {252 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined via the attribute, the one of the comment will be used.", "info");253 } else {254 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined, please do so via the attribute!", "warn");255 }256 257 // return258 return element;259};260// function to parse the information provided for a macro node261var parseMacroNode = function(node) {262 var name = node.getAttribute("name");263 var description = node.hasAttribute("description") ? node.getAttribute("description") : null;264 var comment = parseComment(node);265 var content = parseNodeContent(node);266 267 // get the element268 var element = new Element("task", name, comment, content);269 270 // validate the name271 if (element.name == null) {272 // skip273 return null;274 } 275 276 // validate the description277 if (description != null && element.comment.description != null) {278 echo("The " + node.getNodeName() + " '" + element.name + "' has two descriptions defined:", "warn");279 echo("- one via the comment ('" + element.comment.description + "') and", "warn");280 echo("- one via the attribute ('" + description + "').", "warn");281 echo("The one of the comment will be used!", "warn");282 } else if (description != null && element.comment.description == null) {283 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined via a comment, the one of the attribute will be used.", "info");284 element.comment.setDescription(description);285 } else if (element.comment.description != null && description == null) {286 // nicely done287 } else {288 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined, please do so via a comment", "warn");289 }290 291 // validate the attributes292 var definedAttributes = new java.util.HashSet();293 var attributeNodes = node.getChildNodes();294 for (var temp = 0; temp < attributeNodes.getLength(); temp++) {295 var attributeNode = attributeNodes.item(temp);296 if (!"attribute".equals(attributeNode.getNodeName())) continue;297 298 // get the values of the attribute299 var attrName = attributeNode.getAttribute("name");300 var attrDescription = attributeNode.hasAttribute("description") ? attributeNode.getAttribute("description") : null;301 var attrDef = attributeNode.hasAttribute("default") ? attributeNode.getAttribute("default") : null;302 303 // make sure there is a name and add it for checking later304 if (checkEmpty(attrName) == null) continue;305 definedAttributes.add(attrName);306 307 // check the values of the attribute308 if (element.comment.hasParam(attrName)) {309 var param = element.comment.getParam(attrName);310 311 // validate the description312 if (attrDescription != null && param.description != null) {313 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' has two descriptions defined:", "warn");314 echo("- one via the comment ('" + param.description + "') and", "warn");315 echo("- one via the attribute ('" + attrDescription + "').", "warn");316 echo("The one of the comment will be used!", "warn");317 } else if (attrDescription != null && param.description == null) {318 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' has no description defined via a comment, the one of the attribute will be used.", "info");319 param.setDescription(attrDescription);320 } else if (param.description != null && attrDescription == null) {321 // nicely done322 } else {323 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' has no description defined, please do so via a comment", "warn");324 }325 326 // validate the default-value327 if (attrDef != null && param.def != null) {328 329 if (!attrDef.equals(param.def)) {330 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' has two different defaults defined:", "warn");331 echo("- one via the comment ('" + param.def + "') and", "warn");332 echo("- one via the attribute ('" + attrDef + "').", "warn");333 echo("The one of the attribute will be used!", "warn");334 param.setDefault(attrDef);335 } else {336 // just fine337 }338 } else if (attrDef != null && param.def == null) {339 // thats just ok, lets set it340 param.setDefault(attrDef);341 } else if (param.def != null && attrDef == null) {342 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' has a default ('" + param.def + "') documented but not defined.", "warn");343 } else {344 // both have none, thats fine345 }346 } else {347 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' is not recognized in the comment, please specify it, until then the values of the definition will be used!", "warn");348 element.comment.addParam(new Parameter(attrName, attrDescription, attrDef));349 }350 }351 for (var i = 0; i < element.comment.params; i++) {352 var param = element.comment.params[i];353 if (!definedAttributes.contains(param.name)) {354 echo("The attribute '" + param.name + "' of element '" + element.name + "' is not defined and only documented, please remove it from the comment!", "warn");355 }356 }357 358 // return359 return element;360};361// function to parse the information provided for a macro node362var parseScriptNode = function(node) {363 var name = node.getAttribute("name");364 var comment = parseComment(node);365 var content = parseNodeContent(node);366 367 // get the element368 var element = new Element("task", name, comment, content);369 370 // validate371 if (element.name == null) {372 // skip373 return null;374 } 375 376 // validate the description377 if (element.comment.description == null) {378 echo("The " + node.getNodeName() + " '" + element.name + "' has no description defined, please do so via a comment", "warn");379 } else {380 // nicely done381 }382 383 // validate the attributes384 var definedAttributes = new java.util.HashSet();385 var attributeNodes = node.getChildNodes();386 for (var temp = 0; temp < attributeNodes.getLength(); temp++) {387 var attributeNode = attributeNodes.item(temp);388 if (!"attribute".equals(attributeNode.getNodeName())) continue;389 390 // get the values of the attribute391 var attrName = attributeNode.getAttribute("name");392 // make sure there is a name and add it for checking later393 if (checkEmpty(attrName) == null) continue;394 definedAttributes.add(attrName);395 396 // check the values of the attribute397 if (element.comment.hasParam(attrName)) {398 // just fine399 } else {400 echo("The " + attributeNode.getNodeName() + " '" + attrName + "' of element '" + element.name + "' is not recognized in the comment, please specify it, until then the values of the definition will be used!", "warn");401 element.comment.addParam(new Parameter(attrName));402 }403 }404 for (var i = 0; i < element.comment.params; i++) {405 var param = element.comment.params[i];406 if (!definedAttributes.contains(param.name)) {407 echo("The attribute '" + param.name + "' of element '" + element.name + "' is not defined and only documented, please remove it from the comment!", "warn");408 } else if (param.description == null) {409 echo("The attribute '" + param.name + "' of element '" + element.name + "' has no description specified, please do so in the comment!", "warn");410 }411 }412 413 // return414 return element;...
workflow.js
Source:workflow.js
1/**2 * Author : Harshal Chaudhari3 *4 * Nov 1-20125 */6//define(['jquery', 'draw2d'], function() {7 draw2d.workflow = function(id) {8 draw2d.Workflow.call(this, id);9 this.enabled = true;10 };11 draw2d.workflow.prototype = new draw2d.Workflow();12 draw2d.workflow.prototype.type = "Workflow";13 draw2d.workflow.prototype.onKeyDown = function(_27aa, ctrl) {14 if($("#btnRunmode").val() == "OffMode") {15 if(_27aa == 46 && this.currentSelection !== null) {16 var labelInSourceNode, labelInTargetnode, index, indx;17 var SourceNodeName = this.currentSelection.parent.getheader() + "-" + this.currentSelection.parent.getSequenceNo();18 var TargetNodeName = this.currentSelection.targetPort.parentNode.getheader() + "-" + this.currentSelection.targetPort.parentNode.getSequenceNo();19 var oThis = this;20 $("#delete-confirm").html('Do you want to remove connection from ' + SourceNodeName + ' to ' + TargetNodeName + '?').dialog({21 resizable : false,22 title : 'Confirm Deletion',23 height : 150,24 width : 350,25 modal : true,26 draggable : false,27 buttons : {28 "Delete" : function() {29 var sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.currentSelection.parent.getId());30 //get source model31 var targetmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(oThis.currentSelection.targetPort.parentNode.getId());32 // get target model33 // get type of object34 var sourceNode = sourcemodel.get("blockid").split("-")[0];35 var targetNode = targetmodel.get("blockid").split("-")[0];36 var src = sourcemodel.get("target");37 // get source array of source node model38 var tar = targetmodel.get("source");39 // get target array of target node model40 if(sourcemodel != null && targetmodel != null) {41 if(sourceNode == "CMP") {42 labelInSourceNode = oThis.currentSelection.targetPort.parentNode.getLabel() + "-" + oThis.currentSelection.sourcePort.name;43 //get label from source node44 labelInTargetnode = oThis.currentSelection.sourcePort.parentNode.getLabel() + "-" + oThis.currentSelection.sourcePort.name// get label from target node45 } else if(targetNode == "CMP" || targetNode == "LIM") {46 labelInSourceNode = oThis.currentSelection.targetPort.parentNode.getLabel() + "-" + oThis.currentSelection.targetPort.name;47 labelInTargetnode = oThis.currentSelection.sourcePort.parentNode.getLabel() + "-" + oThis.currentSelection.targetPort.name;48 } else {49 labelInSourceNode = oThis.currentSelection.targetPort.parentNode.getLabel();50 labelInTargetnode = oThis.currentSelection.sourcePort.parentNode.getLabel();51 }52 index = src.indexOf(labelInSourceNode);53 // get index if label is already exist in source array54 indx = tar.indexOf(labelInTargetnode);55 //get index if label is already exist in target array56 src.splice(index, 1);57 tar.splice(indx, 1);58 sourcemodel.set({// set source model target attribute59 "target" : src60 });61 targetmodel.set({62 "source" : tar63 });64 }65 /*66 * call removePort(), pass parameter as NodeObj name if name is ADD, SUB, MUL, DIV, AND, OR then remove port.67 */68 oThis.currentSelection.removePort(sourceNode);69 oThis.currentSelection.removePort(targetNode);70 oThis.commandStack.execute(oThis.currentSelection.createCommand(new draw2d.EditPolicy(draw2d.EditPolicy.DELETE)));71 $(this).dialog("close");72 },73 Cancel : function() {74 $(this).dialog("close");75 }76 }77 });78 } else {79 if(_27aa == 90 && ctrl) {80 if(this.commandStack.undostack.length > 0) {81 if(this.commandStack.getUndoLabel() === "delete figure") {82 var len = this.commandStack.undostack.length;83 if(this.commandStack.undostack[len - 1].figure.type == "draw2d.Node") {84 DCSSPACE.view.blockView.prototype.ExtendSequenceNo(this.commandStack.undostack[len - 1].figure.getSequenceNo());85 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").add(this.commandStack.undostack[len - 1].figure.model);86 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").sort();87 var SortedCollection = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").sortAsc(DCSSPACE.collection.get(tab_id).get("functionBlockCollection"));88 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").models = SortedCollection;89 } else if(this.commandStack.undostack[len - 1].figure.type == "draw2d.nodeConnetion") {90 //get Sourcemodel and set target attribute91 var Sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.getCommandStack().undostack[len - 1].figure.sourcePort.parentNode.getId());92 var connectionsrc = Sourcemodel.get("target");93 connectionsrc.push(this.commandStack.undostack[len - 1].figure.getTarget().parentNode.getLabel());94 Sourcemodel.set({95 "target" : connectionsrc96 })97 //get Targetmodel and set source attribute98 var Targetemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.undostack[len - 1].figure.targetPort.parentNode.getId());99 var connectiontarget = Targetemodel.get("source");100 connectiontarget.push(this.commandStack.undostack[len - 1].figure.getSource().parentNode.getLabel());101 Targetemodel.set({102 "source" : connectiontarget103 });104 var node = this.commandStack.undostack[len - 1].figure.targetPort.parentNode;105 if(node.getnodeName() == "ADD" || node.getnodeName() == "SUB" || node.getnodeName() == "MUL" || node.getnodeName() == "DIV" || node.getnodeName() == "AND" || node.getnodeName() == "OR") {106 node.addPort(this.commandStack.undostack[len - 1].figure.removedInputPort, this.commandStack.undostack[len - 1].figure.removedInputPort.originX, this.commandStack.undostack[len - 1].figure.removedInputPort.originY);107 }108 }109 this.commandStack.undo();110 //console.log(DCSSPACE.collection.toJSON());111 } else if(this.commandStack.getUndoLabel() === "create connection") {112 var len = this.commandStack.undostack.length;113 var srcmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.undostack[len - 1].source.parentNode.getId());114 //get source model115 var targetmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.undostack[len - 1].target.parentNode.getId());116 //get target model117 var srcarray = srcmodel.get('target');118 //get source model target attribute to remove target119 var tararray = targetmodel.get('source');120 // get target model source attribute to remove source121 if(this.commandStack.undostack[len - 1].source.parentNode.getnodeName() == "CMP") {122 var index = srcarray.indexOf(this.commandStack.undostack[len - 1].target.parentNode.getLabel() + "-" + this.commandStack.undostack[len - 1].source.name);123 var indx = tararray.indexOf(this.commandStack.undostack[len - 1].source.parentNode.getLabel() + "-" + this.commandStack.undostack[len - 1].source.name)124 } else if(this.commandStack.undostack[len - 1].target.parentNode.getnodeName() == "CMP" || this.commandStack.undostack[len - 1].target.parentNode.getnodeName() == "LIM") {125 var index = srcarray.indexOf(this.commandStack.undostack[len - 1].target.parentNode.getLabel() + "-" + this.commandStack.undostack[len - 1].target.name);126 var indx = tararray.indexOf(this.commandStack.undostack[len - 1].source.parentNode.getLabel() + "-" + this.commandStack.undostack[len - 1].target.name)127 } else {128 var index = srcarray.indexOf(this.commandStack.undostack[len - 1].target.parentNode.getLabel());129 var indx = tararray.indexOf(this.commandStack.undostack[len - 1].source.parentNode.getLabel())130 }131 if(index != -1)132 srcarray.splice(index, 1);133 if(indx != -1)134 tararray.splice(indx, 1);135 136 srcmodel.set({137 target : srcarray138 });139 //set new updated target attribute of source model140 targetmodel.set({141 source : tararray142 });143 //set new updated source attribute of target model144 var target = this.commandStack.undostack[len - 1].target.parentNode;145 if(target.getnodeName() == "ADD" || target.getnodeName() == "SUB" || target.getnodeName() == "MUL" || target.getnodeName() == "DIV" || target.getnodeName() == "AND" || target.getnodeName() == "OR") {146 this.commandStack.undostack[len - 1].connection.removedInputPort = target.removePortsatRuntime(target, target.getnodeName(), this.commandStack.undostack[len - 1].target);147 }148 this.commandStack.undo();149 //console.log(DCSSPACE.collection.toJSON());150 } else if(this.commandStack.getUndoLabel() === "add figure") {151 var len = this.commandStack.undostack.length;152 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(this.commandStack.undostack[len - 1].figure.model);153 this.commandStack.undo();154 ///console.log(DCSSPACE.collection.toJSON());155 } else {156 this.commandStack.undo();157 }158 }159 } else {160 if(_27aa == 89 && ctrl) {161 if(this.commandStack.redostack.length > 0) {162 if(this.commandStack.getRedoLabel() === "delete figure") {163 var len = this.commandStack.redostack.length;164 if(this.commandStack.redostack[len - 1].figure.type == "draw2d.Node") {165 this.commandStack.redostack[len - 1].figure.model = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.redostack[len - 1].figure.getId());166 // add model to current figure to retrive at undo operation167 DCSSPACE.view.blockView.prototype.ReduceSequenceNo(this.commandStack.redostack[len - 1].figure.getSequenceNo() + 1)// Update Sequence Number of block168 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(this.commandStack.redostack[len - 1].figure.getId());169 // remove model from collection170 } else if(this.commandStack.redostack[len - 1].figure.type == "draw2d.nodeConnetion") {171 //get Sourcemodel and set target attribute172 var Sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.getCommandStack().redostack[len - 1].figure.sourcePort.parentNode.getId());173 var connectionsrc = Sourcemodel.get("target");174 //connectionsrc.push(this.commandStack.redostack[len - 1].figure.getTarget().parentNode.getheader());175 var index = connectionsrc.indexOf(this.commandStack.redostack[len - 1].figure.getTarget().parentNode.getLabel())176 // if element exist then remove177 if(index != -1) {178 connectionsrc.splice(index, 1);179 }180 Sourcemodel.set({181 "target" : connectionsrc182 })183 //get Targetmodel and set source attribute184 var Targetemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.redostack[len - 1].figure.targetPort.parentNode.getId());185 var connectiontarget = Targetemodel.get("source");186 var indx = connectiontarget.indexOf(this.commandStack.redostack[len - 1].figure.getSource().parentNode.getLabel())187 // if element exist then remove188 if(indx != -1) {189 connectiontarget.splice(indx, 1);190 }191 Targetemodel.set({192 "source" : connectiontarget193 });194 var targetNode = this.commandStack.redostack[len - 1].figure.targetPort.parentNode;195 if(targetNode.getnodeName() == "ADD" || targetNode.getnodeName() == "SUB" || targetNode.getnodeName() == "MUL" || targetNode.getnodeName() == "DIV" || targetNode.getnodeName() == "AND" || targetNode.getnodeName() == "OR") {196 this.commandStack.redostack[len - 1].figure.removedInputPort = targetNode.removePortsatRuntime(targetNode, targetNode.getnodeName(), this.commandStack.redostack[len - 1].figure.targetPort);197 }198 }199 this.commandStack.redo();200 //console.log(DCSSPACE.collection.toJSON());201 } else if(this.commandStack.getRedoLabel() === "create connection") {202 var len = this.commandStack.redostack.length;203 var srcmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.redostack[len - 1].source.parentNode.getId());204 //get source model205 var tarmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.commandStack.redostack[len - 1].target.parentNode.getId());206 //get target model207 var srcarray = srcmodel.get("target");208 //get source model target attribute to remove target209 var tararray = tarmodel.get("source");210 // get target model ssource attribute to remove source211 if(this.commandStack.redostack[len - 1].source.parentNode.getnodeName() == "CMP") {212 srcarray.push(this.commandStack.redostack[len - 1].target.parentNode.getLabel() + "-" + this.commandStack.redostack[len - 1].source.name);213 tararray.push(this.commandStack.redostack[len - 1].source.parentNode.getLabel() + "-" + this.commandStack.redostack[len - 1].source.name)214 }else if(this.commandStack.redostack[len - 1].target.parentNode.getnodeName() == "CMP" || this.commandStack.redostack[len - 1].target.parentNode.getnodeName() == "LIM") {215 srcarray.push(this.commandStack.redostack[len - 1].target.parentNode.getLabel() + "-" + this.commandStack.redostack[len - 1].target.name);216 tararray.push(this.commandStack.redostack[len - 1].source.parentNode.getLabel() + "-" + this.commandStack.redostack[len - 1].target.name)217 } else {218 srcarray.push(this.commandStack.redostack[len - 1].target.parentNode.getLabel());219 //Push target attrubute name in sourcearray220 tararray.push(this.commandStack.redostack[len - 1].source.parentNode.getLabel());221 //Push source attrubute name in targetarray222 }223 srcmodel.set({224 "target" : srcarray225 });226 tarmodel.set({227 "source" : tararray228 });229 var targetNode = this.commandStack.redostack[len - 1].target.parentNode;230 if(targetNode.getnodeName() == "ADD" || targetNode.getnodeName() == "SUB" || targetNode.getnodeName() == "MUL" || targetNode.getnodeName() == "DIV" || targetNode.getnodeName() == "AND" || targetNode.getnodeName() == "OR") {231 targetNode.addPort(this.commandStack.redostack[len - 1].connection.removedInputPort, this.commandStack.redostack[len - 1].connection.removedInputPort.originX, this.commandStack.redostack[len - 1].connection.removedInputPort.originY);232 }233 this.commandStack.redo();234 //console.log(DCSSPACE.collection.toJSON());235 } else if(this.commandStack.getRedoLabel() === "add figure") {236 var len = this.commandStack.redostack.length;237 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").add(this.commandStack.redostack[len - 1].figure.model);238 this.commandStack.redo();239 //console.log(DCSSPACE.collection.toJSON());240 } else {241 this.commandStack.redo();242 }243 }244 }245 }246 }247 }248 };249 draw2d.workflow.prototype.getHTMLId = function() {250 return {251 id : this.html.id,252 iEnable : this.enabled253 }254 }255 draw2d.workflow.prototype.isEnabled = function() {256 return this.enabled;257 }...
undoredo.js
Source:undoredo.js
1/**2 * Author : Harshal Chaudhari3 * 4 * Nov 1-2012 5 */6draw2d.Toolundo = function(obj) {7 draw2d.Button.call(this, obj);8 this.setDimension(26, 25);9 this.setTooltip("undo");10};11draw2d.Toolundo.prototype = new draw2d.Button();12draw2d.Toolundo.prototype.type = "undo";13draw2d.Toolundo.prototype.url = "assert/images/undo";14draw2d.Toolundo.prototype.execute = function() {15 if($("#btnRunmode").val() == "OffMode") {16 if(this.palette.workflow.commandStack.getUndoLabel() === "delete figure") {17 var len = this.palette.workflow.commandStack.undostack.length;18 if(this.palette.workflow.commandStack.undostack[len - 1].figure.type == "draw2d.Node") {19 DCSSPACE.view.blockView.prototype.ExtendSequenceNo(this.palette.workflow.commandStack.undostack[len - 1].figure.getSequenceNo());20 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").add(this.palette.workflow.commandStack.undostack[len - 1].figure.model);21 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").sort();22 var SortedCollection = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").sortAsc(DCSSPACE.collection.get(tab_id).get("functionBlockCollection"));23 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").models = SortedCollection;24 } else if(this.palette.workflow.commandStack.undostack[len - 1].figure.type == "draw2d.nodeConnetion") {25 var Sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.getCommandStack().undostack[len - 1].figure.sourcePort.parentNode.getId());26 var connectionsrc = Sourcemodel.get("target");27 connectionsrc.push(this.palette.workflow.commandStack.undostack[len - 1].figure.getTarget().parentNode.getLabel());28 Sourcemodel.set({29 "target" : connectionsrc30 })31 //get Targetmodel and set source attribute32 var Targetemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.commandStack.undostack[len - 1].figure.targetPort.parentNode.getId());33 var connectiontarget = Targetemodel.get("source");34 connectiontarget.push(this.palette.workflow.commandStack.undostack[len - 1].figure.getSource().parentNode.getLabel());35 Targetemodel.set({36 "source" : connectiontarget37 });38 var node = this.palette.workflow.commandStack.undostack[len - 1].figure.targetPort.parentNode;39 if(node.getnodeName() == "ADD" || node.getnodeName() == "SUB" || node.getnodeName() == "MUL" || node.getnodeName() == "DIV" || node.getnodeName() == "AND" || node.getnodeName() == "OR") {40 node.addPort(this.palette.workflow.commandStack.undostack[len - 1].figure.removedInputPort, this.palette.workflow.commandStack.undostack[len - 1].figure.removedInputPort.originX, this.palette.workflow.commandStack.undostack[len - 1].figure.removedInputPort.originY);41 }42 }43 this.palette.workflow.commandStack.undo();44 //console.log(DCSSPACE.collection.toJSON());45 } else if(this.palette.workflow.commandStack.getUndoLabel() === "create connection") {46 var len = this.palette.workflow.commandStack.undostack.length;47 var srcmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.commandStack.undostack[len - 1].source.parentNode.getId());48 //get source model49 var targetmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.commandStack.undostack[len - 1].target.parentNode.getId());50 //get target model51 var srcarray = srcmodel.get('target');52 //get source model target attribute to remove target53 var tararray = targetmodel.get('source');54 // get target model source attribute to remove source55 if(this.palette.workflow.commandStack.undostack[len - 1].source.parentNode.getnodeName() == "CMP") {56 var index = srcarray.indexOf(this.palette.workflow.commandStack.undostack[len - 1].target.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.undostack[len - 1].source.name);57 var indx = tararray.indexOf(this.palette.workflow.commandStack.undostack[len - 1].source.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.undostack[len - 1].source.name)58 } else if(this.palette.workflow.commandStack.undostack[len - 1].target.parentNode.getnodeName() == "CMP" || this.palette.workflow.commandStack.undostack[len - 1].target.parentNode.getnodeName() == "LIM") {59 var index = srcarray.indexOf(this.palette.workflow.commandStack.undostack[len - 1].target.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.undostack[len - 1].target.name);60 var indx = tararray.indexOf(this.palette.workflow.commandStack.undostack[len - 1].source.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.undostack[len - 1].target.name)61 } else {62 var index = srcarray.indexOf(this.palette.workflow.commandStack.undostack[len - 1].target.parentNode.getLabel());63 var indx = tararray.indexOf(this.palette.workflow.commandStack.undostack[len - 1].source.parentNode.getLabel())64 }65 //iterate through source array to remove target66 /*for( i = 0; i < srcarray.length; i++) {67 if(srcarray[i] === targetmodel.get('id')) {//check if target model id is present in source model target attributeSSSSSSSS68 srcarray.splice(i, 1);69 //remove matching element from array70 }71 }72 //iterate through target array to remove source73 for( j = 0; j < tararray.length; j++) {74 if(tararray[j] === srcmodel.get('id')) {//check if source model id is present in target model source attribute75 tararray.splice(j, 1);76 //remove matching element from array77 }78 }*/79 if(index != -1)80 srcarray.splice(index, 1);81 if(indx != -1)82 tararray.splice(indx, 1);83 srcmodel.set({84 target : srcarray85 });86 //set new updated target attribute of source model87 targetmodel.set({88 source : tararray89 });90 //set new updated source attribute of target model91 var target = this.palette.workflow.commandStack.undostack[len - 1].target.parentNode;92 if(target.getnodeName() == "ADD" || target.getnodeName() == "SUB" || target.getnodeName() == "MUL" || target.getnodeName() == "DIV" || target.getnodeName() == "AND" || target.getnodeName() == "OR") {93 this.palette.workflow.commandStack.undostack[len - 1].connection.removedInputPort = target.removePortsatRuntime(target, target.getnodeName(), this.palette.workflow.commandStack.undostack[len - 1].target);94 }95 //set new updated source attribute of target model96 this.palette.workflow.commandStack.undo();97 //console.log(DCSSPACE.collection.toJSON());98 } else if(this.palette.workflow.commandStack.getUndoLabel() === "add figure") {99 var len = this.palette.workflow.commandStack.undostack.length;100 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(this.palette.workflow.commandStack.undostack[len - 1].figure.model);101 this.palette.workflow.commandStack.undo();102 //console.log(DCSSPACE.collection.toJSON());103 } else {104 this.palette.workflow.commandStack.undo();105 }106 }107}108draw2d.Toolundo.prototype.getImageUrl = function() {109 return this.url + ".jpeg";110};111draw2d.Toolredo = function(obj) {112 draw2d.Button.call(this, obj);113 this.setDimension(26, 25);114 this.setTooltip("redo");115};116draw2d.Toolredo.prototype = new draw2d.Button();117draw2d.Toolredo.prototype.type = "undo";118draw2d.Toolredo.prototype.url = "assert/images/redo";119draw2d.Toolredo.prototype.execute = function() {120 //this.palette.workflow.getCommandStack().redo();121 if(this.palette.workflow.getCommandStack().getRedoLabel() === "delete figure") {122 var len = this.palette.workflow.getCommandStack().redostack.length;123 if(this.palette.workflow.commandStack.redostack[len - 1].figure.type == "draw2d.Node") {124 this.palette.workflow.getCommandStack().redostack[len - 1].figure.model = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.getCommandStack().redostack[len - 1].figure.getId());125 DCSSPACE.view.blockView.prototype.ReduceSequenceNo(this.palette.workflow.commandStack.redostack[len - 1].figure.getSequenceNo() + 1)// Update Sequence Number of block126 // add model to current figure to retrive at undo operation127 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").remove(this.palette.workflow.getCommandStack().redostack[len - 1].figure.getId());128 // remove model from collection129 } else if(this.palette.workflow.commandStack.redostack[len - 1].figure.type == "draw2d.nodeConnetion") {130 var Sourcemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.getCommandStack().redostack[len - 1].figure.sourcePort.parentNode.getId());131 var connectionsrc = Sourcemodel.get("target");132 //connectionsrc.push(this.commandStack.redostack[len - 1].figure.getTarget().parentNode.getheader());133 var index = connectionsrc.indexOf(this.palette.workflow.commandStack.redostack[len - 1].figure.getTarget().parentNode.getLabel());134 // if element exist then remove135 if(index != -1) {136 connectionsrc.splice(index, 1);137 }138 Sourcemodel.set({139 "target" : connectionsrc140 })141 //get Targetmodel and set source attribute142 var Targetemodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.commandStack.redostack[len - 1].figure.targetPort.parentNode.getId());143 var connectiontarget = Targetemodel.get("source");144 var indx = connectiontarget.indexOf(this.palette.workflow.commandStack.redostack[len - 1].figure.getSource().parentNode.getLabel())145 // if element exist then remove146 if(indx != -1) {147 connectiontarget.splice(indx, 1);148 }149 Targetemodel.set({150 "source" : connectiontarget151 });152 var targetNode = this.palette.workflow.commandStack.redostack[len - 1].figure.targetPort.parentNode;153 if(targetNode.getnodeName() == "ADD" || targetNode.getnodeName() == "SUB" || targetNode.getnodeName() == "MUL" || targetNode.getnodeName() == "DIV" || targetNode.getnodeName() == "AND" || targetNode.getnodeName() == "OR") {154 this.palette.workflow.commandStack.redostack[len - 1].figure.removedInputPort = targetNode.removePortsatRuntime(targetNode, targetNode.getnodeName(), this.palette.workflow.commandStack.redostack[len - 1].figure.targetPort);155 }156 }157 this.palette.workflow.getCommandStack().redo();158 //console.log(DCSSPACE.collection.toJSON());159 } else if(this.palette.workflow.commandStack.getRedoLabel() === "create connection") {160 var len = this.palette.workflow.commandStack.redostack.length;161 var srcmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.commandStack.redostack[len - 1].source.parentNode.getId());162 //get source model163 var tarmodel = DCSSPACE.collection.get(tab_id).get("functionBlockCollection").get(this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getId());164 //get target model165 var srcarray = srcmodel.get("target");166 //get source model target attribute to remove target167 var tararray = tarmodel.get("source");168 // get target model ssource attribute to remove source169 if(this.palette.workflow.commandStack.redostack[len - 1].source.parentNode.getnodeName() == "CMP") {170 srcarray.push(this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.redostack[len - 1].source.name);171 tararray.push(this.palette.workflow.commandStack.redostack[len - 1].source.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.redostack[len - 1].source.name)172 } else if(this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getnodeName() == "CMP" || this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getnodeName() == "LIM") {173 srcarray.push(this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.redostack[len - 1].target.name);174 tararray.push(this.palette.workflow.commandStack.redostack[len - 1].source.parentNode.getLabel() + "-" + this.palette.workflow.commandStack.redostack[len - 1].target.name)175 } else {176 srcarray.push(this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getLabel());177 //Push target attrubute name in sourcearray178 tararray.push(this.palette.workflow.commandStack.redostack[len - 1].source.parentNode.getLabel());179 //Push source attrubute name in targetarray180 }181 //srcarray.push(this.palette.workflow.commandStack.redostack[len - 1].target.parentNode.getheader());182 //Push target attrubute name in sourcearray183 //tararray.push(this.palette.workflow.commandStack.redostack[len - 1].source.parentNode.getheader());184 //Push source attrubute name in targetarray185 srcmodel.set({186 "target" : srcarray187 });188 tarmodel.set({189 "source" : tararray190 });191 var targetNode = this.palette.workflow.commandStack.redostack[len - 1].target.parentNode;192 if(targetNode.getnodeName() == "ADD" || targetNode.getnodeName() == "SUB" || targetNode.getnodeName() == "MUL" || targetNode.getnodeName() == "DIV" || targetNode.getnodeName() == "AND" || targetNode.getnodeName() == "OR") {193 targetNode.addPort(this.palette.workflow.commandStack.redostack[len - 1].connection.removedInputPort, this.palette.workflow.commandStack.redostack[len - 1].connection.removedInputPort.originX, this.palette.workflow.commandStack.redostack[len - 1].connection.removedInputPort.originY);194 }195 this.palette.workflow.commandStack.redo();196 //console.log(DCSSPACE.collection.toJSON());197 } else if(this.palette.workflow.commandStack.getRedoLabel() === "add figure") {198 var len = this.palette.workflow.commandStack.redostack.length;199 DCSSPACE.collection.get(tab_id).get("functionBlockCollection").add(this.palette.workflow.commandStack.redostack[len - 1].figure.model);200 this.palette.workflow.commandStack.redo();201 //console.log(DCSSPACE.collection.toJSON());202 } else {203 this.palette.workflow.getCommandStack().redo();204 }205 //draw2d.ToolGeneric.prototype.execute.call(this);206}207draw2d.Toolredo.prototype.getImageUrl = function() {208 return this.url + ".jpeg";...
plain.js
Source:plain.js
...19 .filter((node) => node.type !== 'unchanged')20 .map((node) => {21 switch (node.type) {22 case 'removed':23 return `Property '${getNodeName(node, ancestor)}' was removed`;24 case 'changed':25 return `Property '${getNodeName(node, ancestor)}' was updated. From ${getValue(node.valueBefore)} to ${getValue(node.valueAfter)}`;26 case 'added':27 return `Property '${getNodeName(node, ancestor)}' was added with value: ${getValue(node.value)}`;28 case 'nested':29 return formatPlain(node.children, getNodeName(node, ancestor));30 default:31 return false;32 }33 });34 const innerValue = lines.join('\n');35 return innerValue;36};...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const element = await page.$('text=Get started');7 const elementName = await element._client.send('DOM.getNodeName', {8 });9 console.log(elementName.nodeName);10 await browser.close();11})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const element = await page.$('text=Get started');7 console.log(element._remoteObject.description);8 await browser.close();9})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const selector = 'text=Get started';7 const elementHandle = await page.$(selector);8 const nodeName = await elementHandle._remoteObject.description;9 console.log(nodeName);10 await browser.close();11})();12const puppeteer = require('puppeteer');13(async () => {14 const browser = await puppeteer.launch();15 const page = await browser.newPage();16 const selector = 'text=Get started';17 const elementHandle = await page.$(selector);18 const nodeName = await elementHandle._remoteObject.description;19 console.log(nodeName);20 await browser.close();21})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const element = await page.$('text=Get started');7 const name = await element._delegate.getNodeName();8 console.log(name);9 await browser.close();10})();
Using AI Code Generation
1const { chromium } = require("playwright");2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const handle = await page.$("text=Playwright");7 const name = await handle.evaluate((node) => node.nodeName);8 console.log(name);9 await browser.close();10})();11const { chromium } = require("playwright");12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 const handle = await page.$("text=Playwright");17 const innerHTML = await handle.evaluate((node) => node.innerHTML);18 console.log(innerHTML);19 await browser.close();20})();21const { chromium } = require("playwright");22(async () => {23 const browser = await chromium.launch();24 const context = await browser.newContext();25 const page = await context.newPage();26 const handle = await page.$("text=Playwright");27 const outerHTML = await handle.evaluate((node) => node.outerHTML);28 console.log(outerHTML);29 await browser.close();30})();31const { chromium } = require("playwright");32(async () => {33 const browser = await chromium.launch();34 const context = await browser.newContext();35 const page = await context.newPage();36 const handle = await page.$("text=Playwright");37 const innerText = await handle.evaluate((node) => node.innerText);38 console.log(innerText);39 await browser.close();40})();41const { chromium } = require("playwright");
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const element = await page.$('text=Get Started');7 const nodeName = await element._remoteObject().getNodeName();8 console.log(nodeName);9 await browser.close();10})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const element = await page.$('text=Docs');7 console.log(await element._page.getNodeName(element));8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 const element = await page.$('text=Docs');16 console.log(await element._page.getNodeName(element));17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 const element = await page.$('text=Docs');25 const tagName = await element._page.evaluate((element) => element.tagName, element);26 console.log(tagName);27 await browser.close();28})();
Using AI Code Generation
1const { getNodeName } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const element = await page.$('h1');7 console.log(getNodeName(element));8 await browser.close();9})();10const { getNodeName } = require('playwright/lib/server/dom.js');11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const page = await browser.newPage();15 const element = await page.$('h1');16 console.log(getNodeName(element));17 await browser.close();18})();19const { getNodeName } = require('playwright/lib/server/dom.js');20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const page = await browser.newPage();24 const element = await page.$('h1');25 console.log(getNodeName(element));26 await browser.close();27})();28const { getNodeName } = require('playwright/lib/server/dom.js');29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const page = await browser.newPage();33 const element = await page.$('h1');34 console.log(getNodeName(element));
Using AI Code Generation
1const { Playwright } = require('playwright');2const playwright = new Playwright();3const browser = await playwright.chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const element = await page.$('a');7const name = element._remoteObject.description;8console.log(name);9await browser.close();10const { Playwright } = require('playwright');11const playwright = new Playwright();12const browser = await playwright.chromium.launch();13const context = await browser.newContext();14const page = await context.newPage();15const element = await page.$('a');16const parent = await element._getParent();17console.log(parent);18await browser.close();19const { Playwright } = require('playwright');20const playwright = new Playwright();21const browser = await playwright.chromium.launch();22const context = await browser.newContext();23const page = await context.newPage();24const element = await page.$('a');25const child = await element._getChild();26console.log(child);27await browser.close();28const { Playwright } = require('playwright');29const playwright = new Playwright();30const browser = await playwright.chromium.launch();31const context = await browser.newContext();32const page = await context.newPage();33const element = await page.$('a');34const children = await element._getChildren();35console.log(children);36await browser.close();37const { Playwright } = require('play
Using AI Code Generation
1const { getNodeName } = require('@playwright/test');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const name = await getNodeName(await page.$('text=Docs'))7 console.log(name);8 await browser.close();9})();10const { getNodeName } = require('@playwright/test');11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const page = await browser.newPage();15 const name = await getNodeName(await page.$('text=Docs'))16 console.log(name);17 await browser.close();18})();19const { getNodeName } = require('@playwright/test');20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const page = await browser.newPage();24 const name = await getNodeName(await page.$('text=Docs'))25 console.log(name);26 await browser.close();27})();28const { getNodeName } = require('@playwright/test');29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const page = await browser.newPage();33 const name = await getNodeName(await page.$('text=Docs'))34 console.log(name);35 await browser.close();36})();37const { getNodeName
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!