Sidebar-EngineComponent.js 2.92 KB

(function () {
	// Adds Atlassian shapes
	// engine 发动机
	Sidebar.prototype.addThingsKitEnginePalette = function () {

		const gn = 'mxgraph.engine';
		const dt = 'engine';
		const label = mxResources.get('engine')
		const width = 66;
		const height = 74;
		const prefix = `image;image=${window?.PROJECT_ENV.base}/webapp/images/thingskit/libs/`
		const defaultStyle = ';imageAspect=0;'
		this.setCurrentSearchEntryLibrary(dt);
		
		const { COMPONENT_KEY, CATEGORY } = window.CellAttributeKeyEnum

		function createUserObject(attribute) {
			attribute = Object.assign({ [COMPONENT_KEY]: '', [CATEGORY]: '' }, attribute || {})
			var xmlElement = mxUtils.createXmlDocument().createElement('UserObject');

			Object.keys(attribute).forEach(key => {
				xmlElement.setAttribute(key, attribute[key]);
			})
			return xmlElement
		}

		// 自定义属性
		const cellAttribute = {
			[COMPONENT_KEY]: 'Image',
			[CATEGORY]: 'DEFAULT'
		}

		const graphPathLib = [
			{ name: mxResources.get('3dEngine'), path: 'engine/3-D 发动机.svg' },
			{ name: mxResources.get('servoMotor'),   path: 'engine/伺服电机.svg' },
			{ name: mxResources.get('servoMotor')+'2',  path: 'engine/伺服电机2.svg' },
			{ name: mxResources.get('actuator'), path: 'engine/促动器.svg' },
			{ name: mxResources.get('reducer'), path: 'engine/减速器.svg' },
			{ name: mxResources.get('brakeMotor'), path: 'engine/制动马达.svg' },
			{ name: mxResources.get('engine')+'1', path: 'engine/发动机 1.svg' },
			{ name: mxResources.get('engine')+'2', path: 'engine/发动机 2.svg' },
			{ name: mxResources.get('engine')+'3', path: 'engine/发动机 3.svg' },
			{ name: mxResources.get('engine')+'4', path: 'engine/发动机 4.svg' },
			{ name: mxResources.get('industrialEngines'), path: 'engine/工业标准发动机.svg' },
			{ name: mxResources.get('brushlessMotor'), path: 'engine/无刷电机.svg' },
			{ name: mxResources.get('intelligentMotor'), path: 'engine/智能马达.svg' },
			{ name: mxResources.get('steppingMotor'), path: 'engine/步进电机驱动器.svg' },
			{ name: mxResources.get('airBrake'), path: 'engine/气压制动器.svg' },
			{ name: mxResources.get('simpleMotor'), path: 'engine/简单马达.svg' },
			{ name: mxResources.get('shaftEncoder'), path: 'engine/轴角编码器.svg' },
			{ name: mxResources.get('explosionMotor'), path: 'engine/防爆电动机.svg' },
		]

		const fns = graphPathLib.map(item => {
			return this.addEntry(this.getTagsForStencil(gn, item.name, dt).join(' '), mxUtils.bind(this, function () {
				const cell = new mxCell(createUserObject(cellAttribute), new mxGeometry(0, 0, width, height), `${prefix}${item.path}${defaultStyle}`);
				cell.setVertex(true)
				
				return this.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, item.name);
			}));
		})
		this.setGalleryLib(dt, label, graphPathLib)

		this.addPaletteFunctions(dt, label, false, fns);

		this.setCurrentSearchEntryLibrary();
	};
})();