webgme-dss
Version:
Design Studio for Dynamic Systems with Modelica as backend
114 lines (102 loc) • 5.29 kB
JavaScript
/*globals define*/
/*eslint-env node, browser*/
/**
* Generated by PluginGenerator 2.20.5 from webgme on Thu Nov 08 2018 12:27:13 GMT-0600 (Central Standard Time).
* A plugin that inherits from the PluginBase. To see source code documentation about available
* properties and methods visit %host%/docs/source/PluginBase.html.
*/
define([
'plugin/PluginConfig',
'text!./metadata.json',
'plugin/PluginBase',
'text!./../../../../../../svgcache.json',
], function (
PluginConfig,
pluginMetadata,
PluginBase,
SVGCACHE) {
'use strict';
pluginMetadata = JSON.parse(pluginMetadata);
SVGCACHE = JSON.parse(SVGCACHE);
/**
* Initializes a new instance of MoveSVGToRegistryUtil.
* @class
* @augments {PluginBase}
* @classdesc This class represents the plugin MoveSVGToRegistryUtil.
* @constructor
*/
function MoveSVGToRegistryUtil() {
// Call base class' constructor.
PluginBase.call(this);
this.pluginMetadata = pluginMetadata;
}
/**
* Metadata associated with the plugin. Contains id, name, version, description, icon, configStructure etc.
* This is also available at the instance at this.pluginMetadata.
* @type {object}
*/
MoveSVGToRegistryUtil.metadata = pluginMetadata;
// Prototypical inheritance from PluginBase.
MoveSVGToRegistryUtil.prototype = Object.create(PluginBase.prototype);
MoveSVGToRegistryUtil.prototype.constructor = MoveSVGToRegistryUtil;
/**
* Main function for the plugin to execute. This will perform the execution.
* Notes:
* - Always log with the provided logger.[error,warning,info,debug].
* - Do NOT put any user interaction logic UI, etc. inside this method.
* - callback always has to be called even if error happened.
*
* @param {function(Error|null, plugin.PluginResult)} callback - the result callback
*/
MoveSVGToRegistryUtil.prototype.main = function (callback) {
// Use this to access core, project, result, logger etc from PluginBase.
const self = this;
const metaNodes = this.core.getAllMetaNodes(this.activeNode);
const core = this.core;
const defaultSvg = {
base: '<svg baseProfile="full" height="210.0" version="1.1" viewBox="0 0 210.0 210.0" ' +
'width="210.0" xmlns="http://www.w3.org/2000/svg" ' +
'xmlns:ev="http://www.w3.org/2001/xml-events" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink">\n <defs/>\n <defs>\n ' +
'<linearGradient id="926845b4-f7c1-4e3c-a437-8265e5af9bdb" x1="0%" x2="0%" y1="0%" y2="100%">' +
'\n <stop offset="0" stop-color="rgb(200, 200, 200)" stop-opacity="1"/>\n ' +
'<stop offset="0.3" stop-color="rgb(248, 248, 248)" stop-opacity="1"/>\n ' +
'<stop offset="0.7" stop-color="rgb(248, 248, 248)" stop-opacity="1"/>\n ' +
'<stop offset="1" stop-color="rgb(200, 200, 200)" stop-opacity="1"/>\n ' +
'</linearGradient>\n </defs>\n <defs/>\n <defs/>\n <defs/>\n <defs/>\n <defs/>\n ' +
'<desc>Modelica.Fluid.Icons.VariantLibrary</desc>\n ' +
'<rect fill="url(#926845b4-f7c1-4e3c-a437-8265e5af9bdb)" height="200.0" rx="25.0" ry="25.0" ' +
'stroke="rgb(200,200,200)" stroke-width="0.25mm" width="200.0" x="5.0" y="5.0"/>\n ' +
'<rect fill="none" fill-opacity="0" height="200.0" rx="25.0" ry="25.0" ' +
'stroke="rgb(128,128,128)" stroke-width="0.25mm" width="200.0" x="5.0" y="5.0"/>\n ' +
'<ellipse cx="65.0" cy="145.0" fill="rgb(76,76,76)" rx="30.0" ry="30.0"/>\n ' +
'<ellipse cx="145.0" cy="145.0" fill="rgb(0,0,0)" rx="30.0" ry="30.0"/>\n ' +
'<ellipse cx="145.0" cy="65.0" fill="rgb(128,128,128)" rx="30.0" ry="30.0"/>\n ' +
'<ellipse cx="65.0" cy="65.0" fill="rgb(255,255,255)" rx="30.0" ry="30.0" ' +
'stroke="rgb(128,128,128)" stroke-width="0.25mm"/>\n</svg>',
ports: {
x: 0, y: 0, height: 100, width: 100,
},
bbox: {},
attributes: {},
};
for (let metaPath in metaNodes) {
const metaNode = metaNodes[metaPath];
const svg = SVGCACHE[core.getAttribute(metaNode, 'name')] || {};
core.setRegistry(metaNode, 'SVGIcon', svg.base || defaultSvg.base);
core.setRegistry(metaNode, 'SVGBbox', svg.bbox || defaultSvg.bbox);
core.setRegistry(metaNode, 'SVGPorts', svg.ports || defaultSvg.ports);
core.setRegistry(metaNode, 'SVGAttributes', svg.attributes || defaultSvg.attributes);
}
this.save('Fill up SVG related registry entries')
.then(() => {
this.result.setSuccess(true);
callback(null, self.result);
})
.catch((err) => {
this.logger.error(err.stack);
callback(err, self.result);
});
};
return MoveSVGToRegistryUtil;
});