import { PathCommand } from "../lib/types/path.types"; import { DrawText } from '../lib/drawText' import { DrawGroup } from '../lib/drawGroup' import { DrawEllipse } from "../lib/drawEllipse"; import { cal_rotation_dim } from '../lib/drawFunktions' import { Injectable } from "@nestjs/common"; import { DrawDataDto, DrawDto, DrawShapeOptionenDto } from "src/_dto/draw.dto"; import type { GraphicGenerator } from './graphic-generator'; import type { MotorConfig, MotorOptions } from './types'; import { DrawHeader } from "../lib/drawHeader"; interface Para { scale?: number, } @Injectable() export class DrawMotor implements GraphicGenerator { scale = 0; winkel = 0; raster = 4; obj_height = 0; obj_width = 0; height = 0; width = 0; offset_x = 0; offset_y = 0; red = "#f00000"; normal = "#808080"; green = "#00f000"; constructor() { this.scale = 2.0; } create(optionen?: DrawShapeOptionenDto): DrawGroup { let color = optionen?.colorInactive ?? this.normal; if (optionen && optionen.state == 'active') color = optionen.colorActive ?? this.green; if (optionen && optionen.state == 'error') color = optionen.colorError ?? this.red; let raster = 4.0; if (optionen && optionen.raster) raster = optionen.raster; let scale = 2.0; if (optionen && optionen.scale) scale = optionen.scale; const x0 = 0; const x1 = 3 * raster * scale; // länge const x_m = (x0 + x1) / 2; // mitte kasten const y0 = 0; const y1 = 3 * raster * scale; // höhe Kasten const y_m = (y0 + y1) / 2; //mitte kasten const radius = x1 / 2; const obj_h = y0 + y1 + 0 * raster; const obj_w = x0 + x1 + 0 * raster; const height = obj_h / scale / raster; const width = obj_w / scale / raster; const groupInhalt = new DrawGroup({}); const z_kreis = new DrawEllipse({ cx: x_m, cy: y_m, rx: radius, ry: radius }); const z_text = new DrawText({ x: 0, y: 0, text: "M", centeredBox: { width: obj_w, height: obj_h, fontSize: obj_h * 0.6 }, }); z_kreis.setAtrr({ fill: color }) groupInhalt.add(z_text); groupInhalt.add(z_kreis); this.scale = scale; this.raster = raster; this.height = height; this.width = width; this.obj_height = obj_h; this.obj_width = obj_w; return groupInhalt; } getObject(config: MotorConfig, options?: Partial): DrawDataDto { const width = 3 * config.raster * config.scale; const states = ['inactive', 'active', 'error'] as const; const graphics = states.map(state => { const group = this.create({ ...config, ...options, state }); const header = new DrawHeader({ lenght: width, height: width }); header.add(group); return { state, svg: header.getChildString(false, 0), xaml: header.getChildString(true, 0) }; }); return { name: 'motor', width, height: width, varianten: graphics.map(item => ({ ...item, xamlBase64: Buffer.from(item.xaml, 'utf8').toString('base64') })), }; } getDrawObject(optionen?: DrawShapeOptionenDto): DrawDto { const groupSvg = this.create(optionen) const svg = groupSvg.getChildString(false, 0) return { name: "motor", height: this.height, length: this.width, px_height: this.obj_height, px_width: this.obj_width, raster: this.raster, scale: this.scale, offset_x: 0, offset_y: 0, svg } } getSvg(optionen?: DrawShapeOptionenDto): string { const groupSvg = this.create(optionen); const xaml = optionen && optionen.xaml ? true :false; const header = new DrawHeader({ lenght: this.obj_width, height: this.obj_height }); header.add(groupSvg); return header.getChildString(xaml, 0); } }