Sidebar-ConduitComponent.js 2.88 KB

(function () {
	// Adds Atlassian shapes
	// conduit 管道
	Sidebar.prototype.addThingsKitConduitPalette = function () {

		const gn = 'mxgraph.conduit';
		const dt = 'conduit';
		const label = mxResources.get('piping')
		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('yShaped'), path: 'conduit/Y形接头.svg' },
			{ name: mxResources.get('tee'), path: 'conduit/三通.svg' },
			{ name: mxResources.get('fourWayConnector'), path: 'conduit/四通.svg' },
			{ name: mxResources.get('diagonalUp'), path: 'conduit/斜三通 上.svg' },
			{ name: mxResources.get('diagonalLower'), path: 'conduit/斜三通 下.svg' },
			{ name: mxResources.get('obliqueCross'), path: 'conduit/斜四通.svg' },
			{ name: mxResources.get('obliqueBend') +'1', path: 'conduit/斜面弯管 1.svg' },
			{ name: mxResources.get('obliqueBend')+ '1', path: 'conduit/斜面弯管 2.svg' },
			{ name: mxResources.get('obliqueBend')+ '3', path: 'conduit/斜面弯管 3.svg' },
			{ name: mxResources.get('obliqueBend')+ '4', path: 'conduit/斜面弯管 4.svg' },
			{ name: mxResources.get('straightTube') + '2', path: 'conduit/直管 2.svg' },
			{ name: mxResources.get('straightTube'), path: 'conduit/直管.svg' },
			{ name: mxResources.get('conversionJoint')+'2', path: 'conduit/转换接头 2.svg' },
			{ name: mxResources.get('conversionJoint')+'3', path: 'conduit/转换接头 3.svg' },
			{ name: mxResources.get('conversionJoint')+'4', path: 'conduit/转换接头 4.svg' },
			{ name: mxResources.get('conversionJoint')+'5', path: 'conduit/转换接头 5.svg' },
			{ name: mxResources.get('conversionJoint'), path: 'conduit/转换接头.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();
	};
})();