diff --git a/kadmos/vistoms/templates/VISTOMS.html b/kadmos/vistoms/templates/VISTOMS.html index 8e849c8017747fe7583bf1befdae7ce9eb09656e..de188bd14e618e9d37b240bd75388616dc65fbbb 100644 --- a/kadmos/vistoms/templates/VISTOMS.html +++ b/kadmos/vistoms/templates/VISTOMS.html @@ -18741,7 +18741,620 @@ //aigner: Here, the data is read and the XDSM is created //#####################################################################// function startXDSM(data, graphID) - { + { + + //Highlight function, that shows usage of a node in the XDSM + function highlight(data,aText) + { + aText = "/"+data.data.name+aText; + if (data.parent){highlight(data.parent,aText)} + else + { + scenarioKeys.forEach(function(k) + { + var xdsm_tmp; + xdsm_tmp = xdsms[k]; + if (xdsm_tmp) + { + xdsm_tmp.svg.selectAll(".edge").each(function(p) + { + var firstElement_tmp = p.name.split("/")[1] + var text_fromFirst = "/"+firstElement_tmp+aText.split(firstElement_tmp)[1] + if (include(p.name,text_fromFirst)) + { + var highlightEdge = d3.select(this).select("polygon"); + highlightEdge + .style("stroke-width",5.) + .style("stroke","#CC0000") + d3.selectAll(".treeFrame") + .attr("fill-opacity", 0.5) + .attr("stroke-opacity", 0.5); + d3.selectAll(".nodeText").style("fill-opacity",0.5); + } + }) + } + }) + } + } + + //Unhighlight function again + function unhighlight(data,aText) + { + aText = "/"+data.data.name+aText; + if (data.parent){unhighlight(data.parent,aText)} + else + { + scenarioKeys.forEach(function(k) + { + var xdsm_tmp; + xdsm_tmp = xdsms[k]; + if (xdsm_tmp) + { + xdsm_tmp.svg.selectAll(".edge").each(function(p) + { + var firstElement_tmp = p.name.split("/")[1] + var text_fromFirst = "/"+firstElement_tmp+aText.split(firstElement_tmp)[1] + if (include(p.name,text_fromFirst)) + { + var highlightEdge = d3.select(this).select("polygon"); + highlightEdge + .style("stroke-width",1.) + .style("stroke","black"); + d3.selectAll(".treeFrame") + .attr("fill-opacity", 0.8) + .attr("stroke-opacity", 0.8); + d3.selectAll(".nodeText").style("fill-opacity",1); + } + }) + } + }) + } + } + + + function showVariableTable(aVariable) + { + var headLine = "Node Information (" + aVariable.data.name + ")"; + var data = []; + // render the table(s) + data.push({ "name" : "Name", "value" : "\""+aVariable.data.name+"\"" }) + data.push({ "name" : "xPath", "value" : aVariable.data.xPath }) + if (aVariable.data.type){data.push({ "name" : "Type", "value" : aVariable.data.type })} + if (aVariable.data.level){data.push({ "name" : "Level", "value" : aVariable.data.level })} + if (aVariable.data.children){data.push({ "name" : "Number of children", "value" : aVariable.data.children.length })} + if (aVariable.data.dimension){data.push({ "name" : "Dimension", "value" : aVariable.data.dimension })} + else if(aVariable.data.dimension===null){data.push({ "name" : "Dimension", "value" : "undefined" })} + if (aVariable.data.value){data.push({ "name" : "Value(s)", "value" : aVariable.data.value })} + + var d3_body = d3.select("body"); + + var panel_div = d3_body.append("div").attr("class", "myPanel panel-default") + panel_div.append("div").attr("class","panel-heading") + .append("div").attr("class","panel_title").append("h4").text(headLine) + var listGroup = panel_div.append("div").attr("class","panel-body") + .append("table").attr("id","myTable") + .append("tbody") + + data.forEach(function(listElement) + { + var row = listGroup.append("tr") + row.append("td").text(listElement.name) + row.append("td").text(listElement.value) + + }) + $('.myPanel').lobiPanel({ + reload: false, + editTitle: false, + expand: false, + unpin: false, + resize: "none", + minWidth: 200, + minHeight: 200, + maxWidth: 1100, + maxHeight: 1200, + }); + $('.myPanel').lobiPanel('unpin'); + } + + + function markVariable(aNode,variableData) + { + + function getFullXPath(data,aText) + { + aText = "/"+data.data.name+aText; + if (data.parent){return getFullXPath(data.parent,aText)} + else{return aText} + } + var path=""; + var xPath = getFullXPath(aNode, path); + d3.select('.d3-context-menu').style('display', 'none'); + + var bootboxContent = {title: 'Marking variable as ' + variableData.variableType, message: '<p>Please be patient...</p>'}; + var xhr = $.ajax({ + type: 'POST', + url: '/kadmosMarkVariable', + data: { + 'graphID':graphID, + 'xPath':xPath, + 'variableType':variableData.variableType, + 'upperBound':variableData.upperBound, + 'lowerBound':variableData.lowerBound, + 'nominalValue':variableData.nominalValue, + 'operator':variableData.operator, + 'currentOrder':nodeOrder + }, + success: function(result) + { + if (result.includes("ERROR:")) + { + bootboxContent.message = result + kadmosErrorMessage(bootboxContent); + } + else + { + var updatedData = {}; + updatedData = data; + var graphData = JSON.parse(result); + for (var i = 0; i < updatedData.graphs.length; i++) + { + if (graphID == updatedData.graphs[i].id) + { + updatedData.graphs[i] = graphData.graphs[0]; + } + } + + clearView(); + makeKadmosMenu(updatedData); + xdsm_script(updatedData,graphID); + + bootboxContent.message = "Success!" + kadmosSuccessMessage(bootboxContent) + } + }, + error: function(result) + { + bootboxContent.message = result + kadmosErrorMessage(bootboxContent); + } + }); + kadmosHavePatience(xhr, bootboxContent) + } + + function unmarkVariable(aNode) + { + var firstFromSchema = currentGraph.variableSchemes["schema"].name + function getFullXPath(data,aText) + { + aText = "/"+data.data.name+aText; + if (data.parent){return getFullXPath(data.parent,aText)} + else{return aText} + } + var path=""; + var xPath = getFullXPath(aNode, path); + var xPath_split = xPath.split(firstFromSchema)[1] + xPath = "/"+firstFromSchema+xPath_split; + + d3.select('.d3-context-menu').style('display', 'none'); + + var bootboxContent = {title: 'Unmarking variable<p>Please be patient...</p>'}; + var xhr = $.ajax({ + type: 'POST', + url: '/kadmosUnmarkVariable', + data: { + 'graphID':graphID, + 'xPath':xPath, + 'currentOrder':nodeOrder + }, + success: function(result) + { + if (result.includes("ERROR:")) + { + bootboxContent.message = result + kadmosErrorMessage(bootboxContent); + } + else + { + var updatedData = {}; + updatedData = data; + var graphData = JSON.parse(result); + for (var i = 0; i < updatedData.graphs.length; i++) + { + if (graphID == updatedData.graphs[i].id) + { + updatedData.graphs[i] = graphData.graphs[0]; + } + } + + clearView(); + makeKadmosMenu(updatedData); + xdsm_script(updatedData,graphID); + + bootboxContent.message = "Success!" + kadmosSuccessMessage(bootboxContent) + } + }, + error: function(result) + { + bootboxContent.message = result + kadmosErrorMessage(bootboxContent); + } + }); + kadmosHavePatience(xhr, bootboxContent) + } + + //aigner: Marking variables as ... in KADMOS + var markingOptions = [ + { + title: 'design variable', + onMouseClick: function(elm, d, i) { + var theVariableData = {}; + theVariableData.variableType = "designVariable"; + theVariableData.operator = ""; + theVariableData.upperBound = 0.; + theVariableData.lowerBound = 0.; + theVariableData.nominalValue = 0.; + + bootbox.hideAll(); + bootbox.confirm({ + title: 'Marking variable as ' + theVariableData.variableType, + message:"<form id='infos' action=''>" + +"\Nominal Value: <input type='text' id='nominalValue' name='nominalValue' /><br/>" + +"\Upper Bound: <input type='text' id='upperBound' name='upperBound' /><br/>" + +"\Lower Bound: <input type='text' id='lowerBound' name='lowerBound' />\</form>", + callback: function(result){ + if(result){ + theVariableData.nominalValue = $('#nominalValue').submit()[0].value; + theVariableData.upperBound = $('#upperBound').submit()[0].value; + theVariableData.lowerBound = $('#lowerBound').submit()[0].value; + markVariable(elm.__data__, theVariableData); + } + } + }); + }, + onMouseOver: function(elm,d,i){} + }, + { + title: 'objective', + onMouseClick: function(elm, d, i) { + var theVariableData = {}; + theVariableData.variableType = "objective"; + theVariableData.operator = ""; + theVariableData.upperBound = 0.; + theVariableData.lowerBound = 0.; + theVariableData.nominalValue = 0.; + markVariable(elm.__data__, theVariableData); + }, + onMouseOver: function(elm,d,i){} + }, + { + title: 'constraint', + onMouseClick: function(elm, d, i) { + var theVariableData = {}; + theVariableData.variableType = "constraint"; + theVariableData.operator = ""; + theVariableData.upperBound = 0.; + theVariableData.lowerBound = 0.; + theVariableData.nominalValue = 0.; + + bootbox.hideAll(); + bootbox.confirm({ + title: 'Marking variable as ' + theVariableData.variableType, + message:"<form id='infos' action=''>" + +"\Nominal Value: <input type='text' id='nominalValue' name='nominalValue' /><br/>" + +"\Mathematical operator (<, <=, = ,>=, >): <input type='text' id='operator' name='operator' />\</form>", + callback: function(result){ + if(result){ + theVariableData.nominalValue = $('#nominalValue').submit()[0].value; + theVariableData.operator = $('#operator').submit()[0].value; + markVariable(elm.__data__, theVariableData); + } + } + }); + }, + onMouseOver: function(elm,d,i){} + }, + { + title: 'quantity of interest', + onMouseClick: function(elm, d, i) { + var theVariableData = {}; + theVariableData.variableType = "quantityOfInterest"; + theVariableData.operator = ""; + theVariableData.upperBound = 0.; + theVariableData.lowerBound = 0.; + theVariableData.nominalValue = 0.; + markVariable(elm.__data__, theVariableData); + }, + onMouseOver: function(elm,d,i){} + }, + ]; + + + //menu --> functions for right click options + var nodeMenu = [ + { + title: 'Show node information', + onMouseDown: function(elm, d, i) { + console.log(elm) + console.log(d) + showVariableTable(d); + }, + onMouseUp: function(elm, d, i) {}, + onMouseOver: function(elm, d, i) {}, + childrenItems: [] + }, + { + title: 'Show usage of node in XDSM', + onMouseDown: function(elm, d, i) { + var theText=""; + highlight(d,theText); + }, + onMouseUp: function(elm, d, i) { + var theText=""; + unhighlight(d,theText); + }, + onMouseOver: function(elm, d, i) { + }, + childrenItems: [] + }, + { + title: 'Copy x-path to clipboard', + onMouseDown: function(elm, d, i) { + function copyToClipboard(text) + { + window.prompt("Copy to clipboard: Ctrl+C, Enter", text); + } + function copyXPathToClipboard(data,aText) + { + aText = "/"+data.data.name+aText; + if (data.parent){copyXPathToClipboard(data.parent,aText)} + else{copyToClipboard(aText);} + } + var copyText=""; + copyXPathToClipboard(d,copyText); + d3.select('.d3-context-menu').style('display', 'none'); + }, + onMouseUp: function(elm, d, i) { + }, + onMouseOver: function(elm, d, i) { + }, + childrenItems: [] + }, + { + title: 'Download full tree as XML-file', + onMouseDown: function(elm, d, i) { + //Begin xml structure with the first element + var xmlString = "<"+nodes[0].data.name+">"+"</"+nodes[0].data.name+">"; + //Create a new xml document + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" + //Get initial xPath of the tree and pass it to the function "writeTreeToXML" + var initialXPath = "/"+nodes[0].data.name; + writeTreeToXML(nodes[0],xmlDocument,initialXPath); + //remove all attributes dummyID + removeAttributeInAllElements(xmlDocument,'dummyID'); + //Make the xml document a string + var serializer = new XMLSerializer(); + var xmlString = serializer.serializeToString(xmlDocument); + xmlString = vkbeautify.xml(xmlString); + //Download a document with the xml-schema + download(aName+'_full.xml',xmlString); + }, + onMouseUp: function(elm, d, i) { + }, + onMouseOver: function(elm, d, i) { + }, + childrenItems: [] + }, + { + title: 'Download tree as XML-file from current node', + onMouseDown: function(elm, d, i) { + var xmlString = putAncestorsInXMLString({ val : '' }, d).val; + var initialXPath = putAncestorsInXPath({ val : '' }, d).val; + //Create a new xml document + var parser = new DOMParser(); + var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" + //Get initial xPath of the tree and pass it to the function "writeCurrentTreeToXML" + writeTreeToXML(d,xmlDocument,initialXPath); + //remove all attributes dummyID + removeAttributeInAllElements(xmlDocument,'dummyID'); + //Make the xml document a string + var serializer = new XMLSerializer(); + xmlString = serializer.serializeToString(xmlDocument); + xmlString = vkbeautify.xml(xmlString); + //Download a document with the xml-schema + download(aName+"_"+d.data.name+'.xml',xmlString); + }, + onMouseUp: function(elm, d, i) { + }, + onMouseOver: function(elm, d, i) { + }, + childrenItems: [] + }, + { + title: 'Mark variable', + onMouseDown: function(elm, d, i) {}, + onMouseUp: function(elm, d, i) {}, + onMouseOver: function(elm, d, i) {}, + childrenItems: markingOptions + }, + { + title: 'Unmark variable', + onMouseDown: function(elm, d, i) { + bootbox.hideAll(); + bootbox.confirm("Are you sure you want to do this?", function(sure) + { + if (sure) + {unmarkVariable(elm.__data__)} + }) + }, + onMouseUp: function(elm, d, i) {}, + onMouseOver: function(elm, d, i) {}, + childrenItems: [] + } + ] + + + + + //Function writeTreeToXML goes through tree nodes and puts the into an xml document + function writeTreeToXML(aNode,anXMLDoc,anXPath) + { + //Variable "children" + //--> One children variable, no matter whether a node has "_children" (collapsed) or "children" (expanded) + var children; + if (aNode._children){children = aNode._children;} + else if (aNode.children){children = aNode.children;} + + //Get current xml element with its xPath + var element = anXMLDoc.evaluate(anXPath,anXMLDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; + if (element != null) {element.value = '...';} + + //If a node has children (collapsed or expanded), loop through them + if (children) + { + for (var i=0; i < children.length;i++) + { + //Name of the new XML element --> childName + var child = children[i]; + var childName = child.data.name.split(/[\[\]]+/);//Split childName at "[]" which is the uID + var cleanChildName = childName[0].split(/[\+\*\^\-\ \#]+/);//Split childName all special characters + var newNode = anXMLDoc.createElement(String(cleanChildName[0])); + + //The children are appended to the xPath --> newXPath + var newXPath = anXPath+"/"+cleanChildName[0]; + + //If childName contains a uID, make the uID an attribute + if (childName[1]) + { + if (parseInt(childName[1])) + { + var dummyID = childName[1]; + newNode.setAttribute("dummyID", dummyID) + newXPath = newXPath+"[@dummyID='"+dummyID+"']"; + } + else + { + var uID = childName[1]; + newNode.setAttribute("uID", uID) + newXPath = newXPath+"[@uID='"+uID+"']"; + } + } + if (cleanChildName.length>1) {newNode.setAttribute("elementName", childName[0])}; + + //Append the newNode to the xml structure + element.appendChild(newNode); + + + + ////aigner: Sorting of XML elements according to "uID" + // var items = element.children; + // var itemsArr = []; + // for (var j in items) { + // if (items[j].nodeType == 1) { // get rid of the whitespace text nodes + // itemsArr.push(items[j]); + // } + // } + // itemsArr.sort(function(a,b){ + // if (a.getAttribute("uID") < b.getAttribute("uID")) + // return -1; + // if (a.getAttribute("uID") > b.getAttribute("uID")) + // return 1; + // return 0; + // }); + + // for (j = 0; j < itemsArr.length; ++j) { + // element.appendChild(itemsArr[j]); + // } + + //call function writeTreeToXML recursively for all children + writeTreeToXML(child,anXMLDoc,newXPath) + } + } + else + { + if (aNode.data.value){element.innerHTML = String(aNode.data.value);} + else{element.innerHTML = " ";} + } + //return the xml document + return anXMLDoc; + } + + function removeAttributeInAllElements(aDocument,attribute) + { + var matchingElements = []; + var allElements = aDocument.getElementsByTagName('*'); + for (var i = 0, n = allElements.length; i < n; i++) + { + if (allElements[i].getAttribute(attribute) !== null) + { + allElements[i].removeAttribute(attribute); + } + } + return matchingElements; + } + + function putAncestorsInXMLString(strWrapper, aNode) + { + //Name of the new XML element + var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID + var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters + //If nodeName contains a uID, make the uID an attribute + if (nodeName[1]) + { + var uID = nodeName[1]; + strWrapper.val = "<"+cleanNodeName[0]+" uID='"+ uID +"'>"+strWrapper.val+"</"+cleanNodeName[0]+">";; + } + else + { + strWrapper.val = "<"+cleanNodeName[0]+">"+strWrapper.val+"</"+cleanNodeName[0]+">";; + } + var aParent = aNode.parent; + if (aParent) + { + return putAncestorsInXMLString(strWrapper, aParent); + } + else + { + return strWrapper; + } + } + + function putAncestorsInXPath(strWrapper, aNode) + { + //Name of the new XML element + var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID + var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters + //If nodeName contains a uID, make the uID an attribute + if (nodeName[1]) + { + var uID = nodeName[1]; + strWrapper.val = "/"+cleanNodeName[0]+"[@uID='"+uID+"']"+strWrapper.val; + } + else + { + strWrapper.val = "/"+cleanNodeName[0]+strWrapper.val; + } + var aParent = aNode.parent; + if (aParent) + { + return putAncestorsInXPath(strWrapper, aParent); + } + else + { + return strWrapper; + } + } + + + + + + + + + + var graphs, currentGraph, varCategories, entireData; entireData = data; @@ -19472,9 +20085,6 @@ { var list = [] list = functions.concat(variables); - console.log(functions) - console.log(variables) - console.log(list) show_bootBox_listMessage(list); } } @@ -19513,24 +20123,24 @@ .append("table").attr("id","myTable") .append("tbody") - aList.forEach(function(listElement) - { - var td = listGroup.append("tr").append("td") - .text(listElement.name) - .on("mouseover",function(){ - d3.select(this).style("cursor", "pointer") - }) - if (listElement.type=="variable") - { - td.on("mousedown",function(){ - console.log(listElement) - }) - } - else if (listElement.type=="function") - { - td.on("mousedown",function(){bootbox.alert("I'm a function!")}) - } - }) + var tr = listGroup + .selectAll('tr') + .data(aList).enter() + .append('tr') + var td = tr.append("td").html(function(d) { return d.name; }) + tr.on('contextmenu', d3.contextMenu(nodeMenu)); + <!-- aList.forEach(function(listElement) --> + <!-- { --> + <!-- var td = tr.append("td").text(listElement.name) --> + <!-- if (listElement.type=="variable") --> + <!-- { --> + <!-- tr.on('contextmenu', d3.contextMenu(nodeMenu)); --> + <!-- } --> + <!-- else if (listElement.type=="function") --> + <!-- { --> + <!-- tr.on("mousedown",function(){bootbox.alert("I'm a function!")}) --> + <!-- } --> + <!-- }) --> $('.myPanel').lobiPanel({ reload: false, editTitle: false, @@ -21764,606 +22374,7 @@ //.text(function(d) { return d.data.text; }); - //Highlight function, that shows usage of a node in the XDSM - function highlight(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){highlight(data.parent,aText)} - else - { - scenarioKeys.forEach(function(k) - { - var xdsm_tmp; - xdsm_tmp = xdsms[k]; - if (xdsm_tmp) - { - xdsm_tmp.svg.selectAll(".edge").each(function(p) - { - var firstElement_tmp = p.name.split("/")[1] - var text_fromFirst = "/"+firstElement_tmp+aText.split(firstElement_tmp)[1] - if (include(p.name,text_fromFirst)) - { - var highlightEdge = d3.select(this).select("polygon"); - highlightEdge - .style("stroke-width",5.) - .style("stroke","#CC0000") - d3.selectAll(".treeFrame") - .attr("fill-opacity", 0.5) - .attr("stroke-opacity", 0.5); - d3.selectAll(".nodeText").style("fill-opacity",0.5); - } - }) - } - }) - } - } - - //Unhighlight function again - function unhighlight(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){unhighlight(data.parent,aText)} - else - { - scenarioKeys.forEach(function(k) - { - var xdsm_tmp; - xdsm_tmp = xdsms[k]; - if (xdsm_tmp) - { - xdsm_tmp.svg.selectAll(".edge").each(function(p) - { - var firstElement_tmp = p.name.split("/")[1] - var text_fromFirst = "/"+firstElement_tmp+aText.split(firstElement_tmp)[1] - if (include(p.name,text_fromFirst)) - { - var highlightEdge = d3.select(this).select("polygon"); - highlightEdge - .style("stroke-width",1.) - .style("stroke","black"); - d3.selectAll(".treeFrame") - .attr("fill-opacity", 0.8) - .attr("stroke-opacity", 0.8); - d3.selectAll(".nodeText").style("fill-opacity",1); - } - }) - } - }) - } - } - - - function showVariableTable(aVariable) - { - var headLine = "Node Information (" + aVariable.data.name + ")"; - var data = []; - // render the table(s) - data.push({ "name" : "Name", "value" : "\""+aVariable.data.name+"\"" }) - data.push({ "name" : "xPath", "value" : aVariable.data.xPath }) - if (aVariable.data.type){data.push({ "name" : "Type", "value" : aVariable.data.type })} - if (aVariable.data.level){data.push({ "name" : "Level", "value" : aVariable.data.level })} - if (aVariable.data.children){data.push({ "name" : "Number of children", "value" : aVariable.data.children.length })} - if (aVariable.data.dimension){data.push({ "name" : "Dimension", "value" : aVariable.data.dimension })} - else if(aVariable.data.dimension===null){data.push({ "name" : "Dimension", "value" : "undefined" })} - if (aVariable.data.value){data.push({ "name" : "Value(s)", "value" : aVariable.data.value })} - - var d3_body = d3.select("body"); - - var panel_div = d3_body.append("div").attr("class", "myPanel panel-default") - panel_div.append("div").attr("class","panel-heading") - .append("div").attr("class","panel_title").append("h4").text(headLine) - var listGroup = panel_div.append("div").attr("class","panel-body") - .append("table").attr("id","myTable") - .append("tbody") - - data.forEach(function(listElement) - { - var row = listGroup.append("tr") - row.append("td").text(listElement.name) - row.append("td").text(listElement.value) - - }) - $('.myPanel').lobiPanel({ - reload: false, - editTitle: false, - expand: false, - unpin: false, - resize: "none", - minWidth: 200, - minHeight: 200, - maxWidth: 1100, - maxHeight: 1200, - }); - $('.myPanel').lobiPanel('unpin'); - } - - - function markVariable(aNode,variableData) - { - - function getFullXPath(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){return getFullXPath(data.parent,aText)} - else{return aText} - } - var path=""; - var xPath = getFullXPath(aNode, path); - d3.select('.d3-context-menu').style('display', 'none'); - - var bootboxContent = {title: 'Marking variable as ' + variableData.variableType, message: '<p>Please be patient...</p>'}; - var xhr = $.ajax({ - type: 'POST', - url: '/kadmosMarkVariable', - data: { - 'graphID':graphID, - 'xPath':xPath, - 'variableType':variableData.variableType, - 'upperBound':variableData.upperBound, - 'lowerBound':variableData.lowerBound, - 'nominalValue':variableData.nominalValue, - 'operator':variableData.operator, - 'currentOrder':nodeOrder - }, - success: function(result) - { - if (result.includes("ERROR:")) - { - bootboxContent.message = result - kadmosErrorMessage(bootboxContent); - } - else - { - var updatedData = {}; - updatedData = data; - var graphData = JSON.parse(result); - for (var i = 0; i < updatedData.graphs.length; i++) - { - if (graphID == updatedData.graphs[i].id) - { - updatedData.graphs[i] = graphData.graphs[0]; - } - } - - clearView(); - makeKadmosMenu(updatedData); - xdsm_script(updatedData,graphID); - - bootboxContent.message = "Success!" - kadmosSuccessMessage(bootboxContent) - } - }, - error: function(result) - { - bootboxContent.message = result - kadmosErrorMessage(bootboxContent); - } - }); - kadmosHavePatience(xhr, bootboxContent) - } - - function unmarkVariable(aNode) - { - var firstFromSchema = currentGraph.variableSchemes["schema"].name - function getFullXPath(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){return getFullXPath(data.parent,aText)} - else{return aText} - } - var path=""; - var xPath = getFullXPath(aNode, path); - var xPath_split = xPath.split(firstFromSchema)[1] - xPath = "/"+firstFromSchema+xPath_split; - - d3.select('.d3-context-menu').style('display', 'none'); - - var bootboxContent = {title: 'Unmarking variable<p>Please be patient...</p>'}; - var xhr = $.ajax({ - type: 'POST', - url: '/kadmosUnmarkVariable', - data: { - 'graphID':graphID, - 'xPath':xPath, - 'currentOrder':nodeOrder - }, - success: function(result) - { - if (result.includes("ERROR:")) - { - bootboxContent.message = result - kadmosErrorMessage(bootboxContent); - } - else - { - var updatedData = {}; - updatedData = data; - var graphData = JSON.parse(result); - for (var i = 0; i < updatedData.graphs.length; i++) - { - if (graphID == updatedData.graphs[i].id) - { - updatedData.graphs[i] = graphData.graphs[0]; - } - } - - clearView(); - makeKadmosMenu(updatedData); - xdsm_script(updatedData,graphID); - - bootboxContent.message = "Success!" - kadmosSuccessMessage(bootboxContent) - } - }, - error: function(result) - { - bootboxContent.message = result - kadmosErrorMessage(bootboxContent); - } - }); - kadmosHavePatience(xhr, bootboxContent) - } - - //aigner: Marking variables as ... in KADMOS - var markingOptions = [ - { - title: 'design variable', - onMouseClick: function(elm, d, i) { - var theVariableData = {}; - theVariableData.variableType = "designVariable"; - theVariableData.operator = ""; - theVariableData.upperBound = 0.; - theVariableData.lowerBound = 0.; - theVariableData.nominalValue = 0.; - - bootbox.hideAll(); - bootbox.confirm({ - title: 'Marking variable as ' + theVariableData.variableType, - message:"<form id='infos' action=''>" - +"\Nominal Value: <input type='text' id='nominalValue' name='nominalValue' /><br/>" - +"\Upper Bound: <input type='text' id='upperBound' name='upperBound' /><br/>" - +"\Lower Bound: <input type='text' id='lowerBound' name='lowerBound' />\</form>", - callback: function(result){ - if(result){ - theVariableData.nominalValue = $('#nominalValue').submit()[0].value; - theVariableData.upperBound = $('#upperBound').submit()[0].value; - theVariableData.lowerBound = $('#lowerBound').submit()[0].value; - markVariable(elm.__data__, theVariableData); - } - } - }); - }, - onMouseOver: function(elm,d,i){} - }, - { - title: 'objective', - onMouseClick: function(elm, d, i) { - var theVariableData = {}; - theVariableData.variableType = "objective"; - theVariableData.operator = ""; - theVariableData.upperBound = 0.; - theVariableData.lowerBound = 0.; - theVariableData.nominalValue = 0.; - markVariable(elm.__data__, theVariableData); - }, - onMouseOver: function(elm,d,i){} - }, - { - title: 'constraint', - onMouseClick: function(elm, d, i) { - var theVariableData = {}; - theVariableData.variableType = "constraint"; - theVariableData.operator = ""; - theVariableData.upperBound = 0.; - theVariableData.lowerBound = 0.; - theVariableData.nominalValue = 0.; - - bootbox.hideAll(); - bootbox.confirm({ - title: 'Marking variable as ' + theVariableData.variableType, - message:"<form id='infos' action=''>" - +"\Nominal Value: <input type='text' id='nominalValue' name='nominalValue' /><br/>" - +"\Mathematical operator (<, <=, = ,>=, >): <input type='text' id='operator' name='operator' />\</form>", - callback: function(result){ - if(result){ - theVariableData.nominalValue = $('#nominalValue').submit()[0].value; - theVariableData.operator = $('#operator').submit()[0].value; - markVariable(elm.__data__, theVariableData); - } - } - }); - }, - onMouseOver: function(elm,d,i){} - }, - { - title: 'quantity of interest', - onMouseClick: function(elm, d, i) { - var theVariableData = {}; - theVariableData.variableType = "quantityOfInterest"; - theVariableData.operator = ""; - theVariableData.upperBound = 0.; - theVariableData.lowerBound = 0.; - theVariableData.nominalValue = 0.; - markVariable(elm.__data__, theVariableData); - }, - onMouseOver: function(elm,d,i){} - }, - ]; - - - //menu --> functions for right click options - var nodeMenu = [ - { - title: 'Show node information', - onMouseDown: function(elm, d, i) { - showVariableTable(d); - }, - onMouseUp: function(elm, d, i) {}, - onMouseOver: function(elm, d, i) {}, - childrenItems: [] - }, - { - title: 'Show usage of node in XDSM', - onMouseDown: function(elm, d, i) { - var theText=""; - highlight(d,theText); - }, - onMouseUp: function(elm, d, i) { - var theText=""; - unhighlight(d,theText); - }, - onMouseOver: function(elm, d, i) { - }, - childrenItems: [] - }, - { - title: 'Copy x-path to clipboard', - onMouseDown: function(elm, d, i) { - function copyToClipboard(text) - { - window.prompt("Copy to clipboard: Ctrl+C, Enter", text); - } - function copyXPathToClipboard(data,aText) - { - aText = "/"+data.data.name+aText; - if (data.parent){copyXPathToClipboard(data.parent,aText)} - else{copyToClipboard(aText);} - } - var copyText=""; - copyXPathToClipboard(d,copyText); - d3.select('.d3-context-menu').style('display', 'none'); - }, - onMouseUp: function(elm, d, i) { - }, - onMouseOver: function(elm, d, i) { - }, - childrenItems: [] - }, - { - title: 'Download full tree as XML-file', - onMouseDown: function(elm, d, i) { - //Begin xml structure with the first element - var xmlString = "<"+nodes[0].data.name+">"+"</"+nodes[0].data.name+">"; - //Create a new xml document - var parser = new DOMParser(); - var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" - //Get initial xPath of the tree and pass it to the function "writeTreeToXML" - var initialXPath = "/"+nodes[0].data.name; - writeTreeToXML(nodes[0],xmlDocument,initialXPath); - //remove all attributes dummyID - removeAttributeInAllElements(xmlDocument,'dummyID'); - //Make the xml document a string - var serializer = new XMLSerializer(); - var xmlString = serializer.serializeToString(xmlDocument); - xmlString = vkbeautify.xml(xmlString); - //Download a document with the xml-schema - download(aName+'_full.xml',xmlString); - }, - onMouseUp: function(elm, d, i) { - }, - onMouseOver: function(elm, d, i) { - }, - childrenItems: [] - }, - { - title: 'Download tree as XML-file from current node', - onMouseDown: function(elm, d, i) { - var xmlString = putAncestorsInXMLString({ val : '' }, d).val; - var initialXPath = putAncestorsInXPath({ val : '' }, d).val; - //Create a new xml document - var parser = new DOMParser(); - var xmlDocument = parser.parseFromString(xmlString, "text/xml"); //important to use "text/xml" - //Get initial xPath of the tree and pass it to the function "writeCurrentTreeToXML" - writeTreeToXML(d,xmlDocument,initialXPath); - //remove all attributes dummyID - removeAttributeInAllElements(xmlDocument,'dummyID'); - //Make the xml document a string - var serializer = new XMLSerializer(); - xmlString = serializer.serializeToString(xmlDocument); - xmlString = vkbeautify.xml(xmlString); - //Download a document with the xml-schema - download(aName+"_"+d.data.name+'.xml',xmlString); - }, - onMouseUp: function(elm, d, i) { - }, - onMouseOver: function(elm, d, i) { - }, - childrenItems: [] - }, - { - title: 'Mark variable', - onMouseDown: function(elm, d, i) {}, - onMouseUp: function(elm, d, i) {}, - onMouseOver: function(elm, d, i) {}, - childrenItems: markingOptions - }, - { - title: 'Unmark variable', - onMouseDown: function(elm, d, i) { - bootbox.hideAll(); - bootbox.confirm("Are you sure you want to do this?", function(sure) - { - if (sure) - {unmarkVariable(elm.__data__)} - }) - }, - onMouseUp: function(elm, d, i) {}, - onMouseOver: function(elm, d, i) {}, - childrenItems: [] - } - ] - - - - //Function writeTreeToXML goes through tree nodes and puts the into an xml document - function writeTreeToXML(aNode,anXMLDoc,anXPath) - { - //Variable "children" - //--> One children variable, no matter whether a node has "_children" (collapsed) or "children" (expanded) - var children; - if (aNode._children){children = aNode._children;} - else if (aNode.children){children = aNode.children;} - - //Get current xml element with its xPath - var element = anXMLDoc.evaluate(anXPath,anXMLDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue; - if (element != null) {element.value = '...';} - - //If a node has children (collapsed or expanded), loop through them - if (children) - { - for (var i=0; i < children.length;i++) - { - //Name of the new XML element --> childName - var child = children[i]; - var childName = child.data.name.split(/[\[\]]+/);//Split childName at "[]" which is the uID - var cleanChildName = childName[0].split(/[\+\*\^\-\ \#]+/);//Split childName all special characters - var newNode = anXMLDoc.createElement(String(cleanChildName[0])); - - //The children are appended to the xPath --> newXPath - var newXPath = anXPath+"/"+cleanChildName[0]; - - //If childName contains a uID, make the uID an attribute - if (childName[1]) - { - if (parseInt(childName[1])) - { - var dummyID = childName[1]; - newNode.setAttribute("dummyID", dummyID) - newXPath = newXPath+"[@dummyID='"+dummyID+"']"; - } - else - { - var uID = childName[1]; - newNode.setAttribute("uID", uID) - newXPath = newXPath+"[@uID='"+uID+"']"; - } - } - if (cleanChildName.length>1) {newNode.setAttribute("elementName", childName[0])}; - - //Append the newNode to the xml structure - element.appendChild(newNode); - - - - ////aigner: Sorting of XML elements according to "uID" - // var items = element.children; - // var itemsArr = []; - // for (var j in items) { - // if (items[j].nodeType == 1) { // get rid of the whitespace text nodes - // itemsArr.push(items[j]); - // } - // } - // itemsArr.sort(function(a,b){ - // if (a.getAttribute("uID") < b.getAttribute("uID")) - // return -1; - // if (a.getAttribute("uID") > b.getAttribute("uID")) - // return 1; - // return 0; - // }); - - // for (j = 0; j < itemsArr.length; ++j) { - // element.appendChild(itemsArr[j]); - // } - - //call function writeTreeToXML recursively for all children - writeTreeToXML(child,anXMLDoc,newXPath) - } - } - else - { - if (aNode.data.value){element.innerHTML = String(aNode.data.value);} - else{element.innerHTML = " ";} - } - //return the xml document - return anXMLDoc; - } - - function removeAttributeInAllElements(aDocument,attribute) - { - var matchingElements = []; - var allElements = aDocument.getElementsByTagName('*'); - for (var i = 0, n = allElements.length; i < n; i++) - { - if (allElements[i].getAttribute(attribute) !== null) - { - allElements[i].removeAttribute(attribute); - } - } - return matchingElements; - } - - function putAncestorsInXMLString(strWrapper, aNode) - { - //Name of the new XML element - var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID - var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters - //If nodeName contains a uID, make the uID an attribute - if (nodeName[1]) - { - var uID = nodeName[1]; - strWrapper.val = "<"+cleanNodeName[0]+" uID='"+ uID +"'>"+strWrapper.val+"</"+cleanNodeName[0]+">";; - } - else - { - strWrapper.val = "<"+cleanNodeName[0]+">"+strWrapper.val+"</"+cleanNodeName[0]+">";; - } - var aParent = aNode.parent; - if (aParent) - { - return putAncestorsInXMLString(strWrapper, aParent); - } - else - { - return strWrapper; - } - } - - function putAncestorsInXPath(strWrapper, aNode) - { - //Name of the new XML element - var nodeName = aNode.data.name.split(/[\[\]]+/);//Split name at "[]" which is the uID - var cleanNodeName = nodeName[0].split(/[\+\*\^\-\ \#]+/);//Split nodeName all special characters - //If nodeName contains a uID, make the uID an attribute - if (nodeName[1]) - { - var uID = nodeName[1]; - strWrapper.val = "/"+cleanNodeName[0]+"[@uID='"+uID+"']"+strWrapper.val; - } - else - { - strWrapper.val = "/"+cleanNodeName[0]+strWrapper.val; - } - var aParent = aNode.parent; - if (aParent) - { - return putAncestorsInXPath(strWrapper, aParent); - } - else - { - return strWrapper; - } - } nodeEnter = nodeEnter .on('contextmenu', d3.contextMenu(nodeMenu));