From 25dc549a2079e5a1e3feb794b2565a36f8827ce7 Mon Sep 17 00:00:00 2001 From: baigner <benedikt.aigner@rwth-aachen.de> Date: Wed, 23 May 2018 17:31:15 +0200 Subject: [PATCH] VISTOMS update: Changed marking of variables. Now one can preselect all variables that are of special interest. Then by clicking the "Assign Parameter Roles" button in the "FPG Manipulations" menu, kadmos marks all special variables all at once. This is a lot faster! Former-commit-id: 35b07769d283274d2fc03a0fbce22fda76702239 --- kadmos/vistoms/templates/VISTOMS.html | 88 ++++++++++++++++++--------- kadmos/vistoms/vistoms.py | 34 +++++------ 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/kadmos/vistoms/templates/VISTOMS.html b/kadmos/vistoms/templates/VISTOMS.html index 01e2f81ac..a4713a8f3 100644 --- a/kadmos/vistoms/templates/VISTOMS.html +++ b/kadmos/vistoms/templates/VISTOMS.html @@ -264,7 +264,15 @@ if(visPackDiv){visPackDiv.remove()}; var navigationBarDiv = d3.select(".navigationBarDiv"); if(navigationBarDiv){navigationBarDiv.remove()}; - + var lobiPanels = d3.selectAll(".lobipanel"); + if (lobiPanels) + { + lobiPanels.each(function() + { + this.remove(); + }) + } + var imageWidth = 200; var imageHeight = 150; var padding = 10; @@ -18858,26 +18866,26 @@ $('.myPanel').lobiPanel('unpin'); } + var markedVariables = []; + function preMarkVariable(variableData) + { + markedVariables.push(variableData) + } - function markVariable(aNode,variableData) + function markVariable(variableData_arr) { - var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] - var xPath = "/"+firstFromSchema+aNode.data.xPath.split(firstFromSchema)[1]; - d3.select('.d3-context-menu').style('display', 'none'); + + //Stringify variable data before sending it to kadmos + var variableData_str = JSON.stringify(variableData_arr) - var bootboxContent = {title: 'Marking variable as ' + variableData.variableType, message: '<p>Please be patient...</p>'}; + var bootboxContent = {title: 'Assign parameter roles', 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, + 'variableData_str':variableData_str, 'currentOrder':nodeOrder }, success: function(result) @@ -18917,11 +18925,8 @@ kadmosHavePatience(xhr, bootboxContent) } - function unmarkVariable(aNode) + function unmarkVariable(xPath) { - var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] - var xPath = "/"+firstFromSchema+aNode.data.xPath.split(firstFromSchema)[1]; - d3.select('.d3-context-menu').style('display', 'none'); var bootboxContent = {title: 'Unmarking variable<p>Please be patient...</p>'}; @@ -18994,7 +18999,11 @@ theVariableData.nominalValue = $('#nominalValue').submit()[0].value; theVariableData.upperBound = $('#upperBound').submit()[0].value; theVariableData.lowerBound = $('#lowerBound').submit()[0].value; - markVariable(elm.__data__, theVariableData); + + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+elm.__data__.data.xPath.split(firstFromSchema)[1]; + theVariableData.xPath = xPath; + preMarkVariable(theVariableData); } } }); @@ -19010,7 +19019,10 @@ theVariableData.upperBound = 0.; theVariableData.lowerBound = 0.; theVariableData.nominalValue = 0.; - markVariable(elm.__data__, theVariableData); + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+elm.__data__.data.xPath.split(firstFromSchema)[1]; + theVariableData.xPath = xPath; + preMarkVariable(theVariableData); }, onMouseOver: function(elm,d,i){} }, @@ -19034,7 +19046,10 @@ if(result){ theVariableData.nominalValue = $('#nominalValue').submit()[0].value; theVariableData.operator = $('#operator').submit()[0].value; - markVariable(elm.__data__, theVariableData); + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+elm.__data__.data.xPath.split(firstFromSchema)[1]; + theVariableData.xPath = xPath; + preMarkVariable(theVariableData); } } }); @@ -19050,7 +19065,10 @@ theVariableData.upperBound = 0.; theVariableData.lowerBound = 0.; theVariableData.nominalValue = 0.; - markVariable(elm.__data__, theVariableData); + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+elm.__data__.data.xPath.split(firstFromSchema)[1]; + theVariableData.xPath = xPath; + preMarkVariable(theVariableData); }, onMouseOver: function(elm,d,i){} }, @@ -19106,7 +19124,11 @@ bootbox.confirm("Are you sure you want to do this?", function(sure) { if (sure) - {unmarkVariable(elm.__data__)} + { + var firstFromSchema = currentGraph.variableSchemes["schema"][0].xPath.split("/")[1] + var xPath = "/"+firstFromSchema+elm.__data__.data.xPath.split(firstFromSchema)[1]; + unmarkVariable(xPath) + } }) }, onMouseUp: function(elm, d, i) {}, @@ -19461,7 +19483,6 @@ varCategory: varCategories[j].name, description: varCategories[j].description, onMouseClick: function(elm, data, i) { - console.log(elm) showIOTree(data.varCategory,data.description,elm.__data__,"out")}, onMouseOver: function(elm,data,i){}}); } @@ -20218,7 +20239,7 @@ //push back functions in list functions_all.forEach(function(aFunction){ - if (graphElements.includes(aFunction.name)){functions.push(aFunction);} + if (graphElements.includes(aFunction.uID)){functions.push(aFunction);} }) //push back variables in list @@ -20292,7 +20313,7 @@ { //push back functions in list functions_all.forEach(function(aFunction){ - if (graphElements.includes(aFunction.name)){functions.push(aFunction);} + if (graphElements.includes(aFunction.uID)){functions.push(aFunction);} }) } showList(title,functions,toolMenu); @@ -21011,16 +21032,25 @@ .on("mouseover", function(){d3.select(this).style("cursor", "pointer")}) .on("mousedown", function() { - bootbox.hideAll(); + if (markedVariables.length<1) + { + bootbox.hideAll(); bootbox.alert({ title: "Assign parameter roles", - message: "<p>Please mark all variables, which are of special interest. The options are:</p>" + message: "<p>Please mark all parameters, which are of special interest. The options are:</p>" +"<ul><li><b>Design Variable</b></li>" - +"<li><b>Objective Variable</b></li>" - +"<li><b>Constraint Variable</b></li>" + +"<li><b>Objective</b></li>" + +"<li><b>Constraint</b></li>" +"<li><b>State Variable</b> (also \"quantity of interest\")</li></ul><br/>" - +"<p>To mark special variables open the <b>Data Model/schema</b> and select the variables via right-mouse click.</p>" + +"<p>To \"pre-mark\" special parameters open the <b>Data Model Tree</b> or <b>Data Model List</b>, select the parameters via right-mouse click and use one if the \"Mark Variable\" options.</p>" + +"<p><b>IMPORTANT: After all parameters are \"pre-marked\", klick this button again to assign the parameter roles!</b></p>" }) + } + else + { + markVariable(markedVariables) + } + }) fpgManipulations.append("li").append("a") diff --git a/kadmos/vistoms/vistoms.py b/kadmos/vistoms/vistoms.py index e23622cce..d7c2e52d3 100644 --- a/kadmos/vistoms/vistoms.py +++ b/kadmos/vistoms/vistoms.py @@ -1277,12 +1277,9 @@ def kadmosMarkVariable(): # get request form graphID = request.form['graphID'] function_order = request.form['currentOrder'].split(',') - variableType = request.form['variableType'] - xPath = request.form['xPath'] - operator = request.form['operator'] - upperBound = float(request.form['upperBound']) - lowerBound = float(request.form['lowerBound']) - nominalValue = float(request.form['nominalValue']) + variableData_str = request.form['variableData_str'] + # read json data + variableData_py = json.loads(variableData_str) # Save previous graph as backup before making the changes savePreviousGraph(graphID) @@ -1300,19 +1297,18 @@ def kadmosMarkVariable(): fpg = graph else: fpg = FundamentalProblemGraph(graph) - - - - if (variableType=='designVariable'): - fpg.mark_as_design_variable(xPath, nominal_value=nominalValue, upper_bound=upperBound, lower_bound=lowerBound) - elif (variableType=='objective'): - fpg.mark_as_objective(xPath) - elif (variableType=='constraint'): - fpg.mark_as_constraint(xPath,reference_value=nominalValue,operator=operator) - elif (variableType=='quantityOfInterest'): - fpg.mark_as_qois([xPath]) - else: - return ("ERROR: Something went wrong in KADMOS!") + for data in variableData_py: + if data['variableType'] == 'designVariable': + fpg.mark_as_design_variable(data['xPath'], nominal_value=float(data['nominalValue']), + upper_bound=float(data['upperBound']), lower_bound=float(data['lowerBound'])) + elif data['variableType'] == 'objective': + fpg.mark_as_objective(data['xPath']) + elif data['variableType'] == 'constraint': + fpg.mark_as_constraint(data['xPath'], reference_value=float(data['nominalValue']), operator=data['operator']) + elif data['variableType'] == 'quantityOfInterest': + fpg.mark_as_qois([data['xPath']]) + else: + return ("ERROR: Something went wrong in KADMOS!") # Add the graph with the updated function order to VISTOMS newVistomsData = fpg.vistoms_add_json(function_order=function_order, graph_id=graphID, mpg=mpg) -- GitLab