change input/output name works in js

1123
ZhangGe6 4 years ago
parent 4257934c11
commit dda773933b

2
.gitignore vendored

@ -1,4 +1,4 @@
__pycache__/ __pycache__/
gym/ gym/
*.onnx res_onnx/*.onnx

@ -530,6 +530,11 @@ onnx.Argument = class {
return this._name; return this._name;
} }
// https://bobbyhadz.com/blog/javascript-cannot-set-property-which-has-only-getter
set name(name) {
this._name = name;
}
get type() { get type() {
return this._type; return this._type;
} }

@ -240,10 +240,16 @@ sidebar.NodeSidebar = class {
origNameElement.innerHTML = argument.name + " => "; origNameElement.innerHTML = argument.name + " => ";
const newNameElement = this._host.document.createElement('input'); const newNameElement = this._host.document.createElement('input');
newNameElement.setAttribute('type', 'text'); newNameElement.setAttribute('type', 'text');
// reload the existed renamed value
if (this._host._view._graph._renameMap.get(this._modelNodeName) &&
this._host._view._graph._renameMap.get(this._modelNodeName).get(argument.name))
{
newNameElement.setAttribute('value', this._host._view._graph._renameMap.get(this._modelNodeName).get(argument.name));
}
newNameElement.addEventListener('input', (e) => { newNameElement.addEventListener('input', (e) => {
// console.log(e.target.value); // console.log(e.target.value);
this._host._view._graph.recordRenameInfo(this._modelNodeName, argument.name, e.target.value); this._host._view._graph.recordRenameInfo(this._modelNodeName, argument.name, e.target.value);
console.log(this._host._view._graph._renameMap); // console.log(this._host._view._graph._renameMap);
}); });
@ -259,8 +265,8 @@ sidebar.NodeSidebar = class {
} }
render() { render() {
console.log(this._elements) // console.log(this._elements)
console.log(this._renameAuxelements) // console.log(this._renameAuxelements)
// return this._elements; // return this._elements;
return this._elements.concat(this._renameAuxelements); return this._elements.concat(this._renameAuxelements);
} }
@ -577,7 +583,7 @@ sidebar.ValueTextView = class {
} }
render() { render() {
console.log(this._elements) // console.log(this._elements)
return this._elements; return this._elements;
} }

@ -589,6 +589,8 @@ view.View = class {
// console.log(this.lastViewGraph._modelNodeName2State) // console.log(this.lastViewGraph._modelNodeName2State)
// console.log('node state of lastViewGraph is loaded') // console.log('node state of lastViewGraph is loaded')
viewGraph._modelNodeName2State = this.lastViewGraph._modelNodeName2State; viewGraph._modelNodeName2State = this.lastViewGraph._modelNodeName2State;
viewGraph._renameMap = this.lastViewGraph._renameMap;
// console.log(viewGraph._renameMap);
} }
// console.log(viewGraph._modelNodeName2State) // console.log(viewGraph._modelNodeName2State)
viewGraph.add(graph); viewGraph.add(graph);
@ -953,6 +955,15 @@ view.Graph = class extends grapher.Graph {
for (const input of inputs) { for (const input of inputs) {
for (const argument of input.arguments) { for (const argument of input.arguments) {
if (argument.name != '' && !argument.initializer) { if (argument.name != '' && !argument.initializer) {
// if this argument has been renamed
if (
this._renameMap.get(viewNode.modelNodeName) &&
this._renameMap.get(viewNode.modelNodeName).get(argument.name)
)
{
argument.name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
}
this.createArgument(argument).to(viewNode); this.createArgument(argument).to(viewNode);
} }
} }
@ -970,6 +981,17 @@ view.Graph = class extends grapher.Graph {
throw new view.Error("Invalid null argument in '" + this.model.identifier + "'."); throw new view.Error("Invalid null argument in '" + this.model.identifier + "'.");
} }
if (argument.name != '') { if (argument.name != '') {
// if this argument has been renamed
if (
this._renameMap.get(viewNode.modelNodeName) &&
this._renameMap.get(viewNode.modelNodeName).get(argument.name)
)
{
console.log(argument.name)
console.log(this._renameMap.get(viewNode.modelNodeName).get(argument.name))
argument.name = this._renameMap.get(viewNode.modelNodeName).get(argument.name);
}
this.createArgument(argument).from(viewNode); this.createArgument(argument).from(viewNode);
} }
} }

Loading…
Cancel
Save