diff --git a/src/plugins/GenerateArchitecture/GenerateArchitecture.js b/src/plugins/GenerateArchitecture/GenerateArchitecture.js index b472ab59d..8f01bd761 100644 --- a/src/plugins/GenerateArchitecture/GenerateArchitecture.js +++ b/src/plugins/GenerateArchitecture/GenerateArchitecture.js @@ -43,22 +43,39 @@ define([ GenerateArchitecture.prototype.constructor = GenerateArchitecture; GenerateArchitecture.prototype.main = function () { + this.addCustomLayersToMeta(); this.LayerDict = createLayerDict(this.core, this.META); this.uniqueId = 2; this._oldTemplateSettings = _.templateSettings; return PluginBase.prototype.main.apply(this, arguments); }; + GenerateArchitecture.prototype.addCustomLayersToMeta = function () { + var metaDict = this.core.getAllMetaNodes(this.rootNode); + + Object.keys(metaDict).map(id => metaDict[id]) + // Get all custom layers + .filter(node => this.core.isTypeOf(node, this.META.Layer)) + // Add them to the meta + .forEach(node => this.META[this.core.getAttribute(node, 'name')] = node); + }; + GenerateArchitecture.prototype.createOutputFiles = function (tree) { var layers = tree[Constants.CHILDREN], //initialLayers, result = {}, - code; + code = 'require \'nn\'\n\n'; //initialLayers = layers.filter(layer => layer[Constants.PREV].length === 0); // Add an index to each layer layers.forEach((l, index) => l[INDEX] = index); - code = this.genArchCode(layers); + + // Define custom layers + if (this.getCurrentConfig().standalone) { + code += this.genLayerDefinitions(layers); + } + + code += this.genArchCode(layers); result[tree.name + '.lua'] = code; _.templateSettings = this._oldTemplateSettings; // FIXME: Fix this in SimpleNodes @@ -66,10 +83,7 @@ define([ }; GenerateArchitecture.prototype.genArchCode = function (layers) { - // Create a 'null' start layer - return [ - 'require \'nn\'', this.createSequential(layers[0], 'net').code, '\nreturn net' ].join('\n'); @@ -174,5 +188,22 @@ define([ return !(value === undefined || value === null || value === ''); }; + GenerateArchitecture.prototype.genLayerDefinitions = function(layers) { + var code = '', + customLayerId = this.core.getPath(this.META.CustomLayer); + + code += '-------------- Custom Layer Definitions --------------\n\n'; + code += layers + .filter(layer => { // Get the custom layers + var node = this.META[layer.name]; + return this.core.getMixinPaths(node).indexOf(customLayerId) !== -1; + }) + .map(layer => layer.code) // add their 'code' attributes + .join('\n'); + + code += '\n\n-------------- Network --------------\n'; + + return code; + }; return GenerateArchitecture; }); diff --git a/src/plugins/GenerateArchitecture/metadata.json b/src/plugins/GenerateArchitecture/metadata.json index bc1403d3d..bd67e2389 100644 --- a/src/plugins/GenerateArchitecture/metadata.json +++ b/src/plugins/GenerateArchitecture/metadata.json @@ -9,5 +9,14 @@ }, "disableServerSideExecution": false, "disableBrowserSideExecution": false, - "configStructure": [] + "configStructure": [ + { + "name": "standalone", + "displayName": "Standalone", + "description": "Prepend custom layer definitions", + "value": false, + "valueType": "boolean", + "readOnly": false + } + ] } diff --git a/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js b/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js index e7fd669d1..9400c643e 100644 --- a/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js +++ b/src/visualizers/panels/ForgeActionButton/ForgeActionButton.js @@ -167,7 +167,6 @@ define([ // Set the color desc.color = '#9e9e9e'; - // TODO return desc; }; diff --git a/src/visualizers/panels/LayerEditor/LayerEditorPanel.js b/src/visualizers/panels/LayerEditor/LayerEditorPanel.js index bcfdbac5d..61811a212 100644 --- a/src/visualizers/panels/LayerEditor/LayerEditorPanel.js +++ b/src/visualizers/panels/LayerEditor/LayerEditorPanel.js @@ -1,20 +1,15 @@ /*globals define, _, WebGMEGlobal*/ /*jshint browser: true*/ -/** - * Generated by VisualizerGenerator 1.7.0 from webgme on Thu Jun 16 2016 08:47:07 GMT-0500 (CDT). - */ define([ 'js/PanelBase/PanelBaseWithHeader', 'js/PanelManager/IActivePanel', 'widgets/TextEditor/TextEditorWidget', - //'panels/TextEditor/TextEditorControl' './LayerEditorControl' ], function ( PanelBaseWithHeader, IActivePanel, - LayerEditorWidget, - //TextEditorControl + TextEditorWidget, LayerEditorControl ) { 'use strict'; @@ -49,7 +44,7 @@ define([ //set Widget title this.setTitle(''); - this.widget = new LayerEditorWidget(this.logger, this.$el); + this.widget = new TextEditorWidget(this.logger, this.$el); this.widget.setTitle = function (title) { self.setTitle(title); diff --git a/src/visualizers/widgets/LayerEditor/LayerEditorWidget.js b/src/visualizers/widgets/LayerEditor/LayerEditorWidget.js deleted file mode 100644 index 1ca2cb38e..000000000 --- a/src/visualizers/widgets/LayerEditor/LayerEditorWidget.js +++ /dev/null @@ -1,18 +0,0 @@ -/*globals define, WebGMEGlobal*/ -/*jshint browser: true*/ - -define([ - 'widgets/TextEditor/TextEditorWidget' -], function ( - TextEditorWidget -) { - 'use strict'; - - var LayerEditorWidget; - - LayerEditorWidget = function () { - TextEditorWidget.apply(this, arguments); - }; - - return LayerEditorWidget; -}); diff --git a/src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.css b/src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.css deleted file mode 100644 index 9a4502e23..000000000 --- a/src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.css +++ /dev/null @@ -1,10 +0,0 @@ -/** - * This file is for any css that you may want for this visualizer. - * - * Ideally, you would use the scss file also provided in this directory - * and then generate this file automatically from that. However, you can - * simply write css if you prefer - */ - -.layer-editor { - outline: none; } diff --git a/src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.scss b/src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.scss deleted file mode 100644 index 4b0e4f299..000000000 --- a/src/visualizers/widgets/LayerEditor/styles/LayerEditorWidget.scss +++ /dev/null @@ -1,7 +0,0 @@ -/** - * This file is for any scss that you may want for this visualizer. - */ - -.layer-editor { - outline: none; -}