From 06cc98dcdd47f5c4f71ffe45f922cd4216c20c32 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Thu, 7 Jul 2016 10:20:54 -0500 Subject: [PATCH] Added import torch action to arch editor. Fixes #447 --- src/plugins/ImportTorch/ImportTorch.js | 19 ++++++++++++------- .../panels/ForgeActionButton/Actions.js | 7 +++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/plugins/ImportTorch/ImportTorch.js b/src/plugins/ImportTorch/ImportTorch.js index 62507efcf..ffd1f9885 100644 --- a/src/plugins/ImportTorch/ImportTorch.js +++ b/src/plugins/ImportTorch/ImportTorch.js @@ -57,12 +57,17 @@ define([ this.blobClient.getMetadata(srcHash) .then(mdata => { // Create the new model - var name = mdata.name.replace('.lua', ''); - this.tgtNode = this.core.createNode({ - base: this.META.Architecture, - parent: this.activeNode - }); - this.core.setAttribute(this.tgtNode, 'name', name); + // If the current node is an architecture, assume we are just extending it + this.importedName = mdata.name.replace('.lua', ''); + if (this.isMetaTypeOf(this.activeNode, this.META.Architecture)) { + this.tgtNode = this.activeNode; + } else { // Create a new architecture + this.tgtNode = this.core.createNode({ + base: this.META.Architecture, + parent: this.activeNode + }); + this.core.setAttribute(this.tgtNode, 'name', this.importedName); + } return this.blobClient.getObjectAsString(srcHash); }) .then(src => { // Retrieved the source code @@ -81,7 +86,7 @@ define([ return this.save('ImportTorch updated model.'); }) .then(() => { // changes saved successfully - var name = this.core.getAttribute(this.tgtNode, 'name'); + var name = this.importedName; this.result.setSuccess(true); this.createMessage(this.tgtNode, `Successfully imported ${name} architecture`); diff --git a/src/visualizers/panels/ForgeActionButton/Actions.js b/src/visualizers/panels/ForgeActionButton/Actions.js index 02eaa4e9d..a8639f0c3 100644 --- a/src/visualizers/panels/ForgeActionButton/Actions.js +++ b/src/visualizers/panels/ForgeActionButton/Actions.js @@ -208,6 +208,13 @@ define([ this.addOperation(); } } + ], + Architecture: [ + { + name: 'Import Torch Architecture', + icon: 'swap_vert', + action: importTorch + } ] }; });