Files
rk-backend/src/draw/draw.service.ts
T

320 lines
12 KiB
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { parseMotorRequest } from '../_dto/motor.dto';
import { parsePunktRequest } from '../_dto/punkt.dto';
import { DrawPunkt } from '../graphics/elements/drawPunkt';
import { DrawFahrwagenOben } from '../graphics/elements/drawFahrwagenOben';
import { parseFahrwagenObenRequest } from '../_dto/fahrwagen-oben.dto';
import { parseAnlageDurminRequest } from '../_dto/anlage-durmin.dto';
import { parsePfeilRequest } from '../_dto/pfeil.dto';
import { DrawWarnung, parseWarnungRequest } from '../graphics/elements/drawWarnung';
import { DrawShapeOptionenDto } from 'src/_dto/draw.dto';
import { DrawBand } from 'src/graphics/elements/drawBand';
import { DrawBehaelter } from 'src/graphics/elements/drawBehaelter';
import { DrawBrecher } from 'src/graphics/elements/drawBrecher';
import { DrawGurtfoerderer } from 'src/graphics/elements/drawGurtfoerderer';
import { DrawSetzmaschine } from 'src/graphics/elements/drawSetzmaschine';
import { Sieb } from 'src/graphics/elements/drawSieb';
import { createCsv } from './csv';
import { DrawSiebEntwaesserung } from 'src/graphics/elements/drawSiebEntwaesserung';
import { DrawWeiche } from 'src/graphics/elements/drawWeiche';
import { DrawZyklon } from 'src/graphics/elements/drawZyklon';
import { DrawTurbowascher } from 'src/graphics/elements/drawTurbowascher';
import { DrawHaspel } from 'src/graphics/elements/drawHaspel';
import { DrawSilo } from 'src/graphics/elements/drawSilo';
import { DrawFlex } from 'src/graphics/elements/drawFlex';
import { LineDto, VisuElementDto } from 'src/_dto/visuElement.dto';
import { DrawPfeil } from 'src/graphics/elements/drawPfeil';
import { DrawPumpe } from 'src/graphics/elements/drawPumpe';
import { DrawVentil } from 'src/graphics/elements/drawVentil';
import { DrawWasserZufuhr } from 'src/graphics/elements/drawWasserZufuhr';
import { DrawBehaelterMulti } from 'src/graphics/elements/drawBehaelterMulti';
import { DrawMotor } from 'src/graphics/elements/drawMotor';
import { DrawAnlageDurmin } from 'src/graphics/elements/drawAnlageDurmin2';
import { DrawBandOben } from '../graphics/elements/drawBandOben';
import { parseBandObenRequest } from '../_dto/band-oben.dto';
@Injectable()
export class DrawService {
constructor(
private readonly buildWarnung: DrawWarnung,
private readonly buildBandOben: DrawBandOben,
private readonly buildSieb: Sieb,
private readonly buildGurtfoerderer: DrawGurtfoerderer,
private readonly buildSetzmaschine: DrawSetzmaschine,
private readonly buildBand: DrawBand,
private readonly buildBrecher: DrawBrecher,
private readonly buildBehaelter: DrawBehaelter,
private readonly buildSiebentwaesseung: DrawSiebEntwaesserung,
private readonly buildWeiche: DrawWeiche,
private readonly buildZyklon: DrawZyklon,
private readonly buildTurbowascher: DrawTurbowascher,
private readonly buildHaspel: DrawHaspel,
private readonly buildSilo: DrawSilo,
private readonly buildFlex: DrawFlex,
private readonly buildPfeil: DrawPfeil,
private readonly buildPumpe: DrawPumpe,
private readonly buildVentil: DrawVentil,
private readonly buildWasserZufuhr: DrawWasserZufuhr,
private readonly buildBehaelterMulti: DrawBehaelterMulti,
private readonly buildMotor: DrawMotor,
private readonly buildAnlageDurmin: DrawAnlageDurmin,
private readonly buildFahrwagenOben: DrawFahrwagenOben,
private readonly buildPunkt: DrawPunkt,
) { }
getAnlageDurmin(){
return this.buildAnlageDurmin.getDrawObject({})
}
renderBandOben(input: unknown) {
const { config, options } = parseBandObenRequest(input);
return this.buildBandOben.getObject(config, options);
}
renderGraphic(type: string, input: unknown) {
switch (type) {
case 'punkt': {
const { config, options } = parsePunktRequest(input);
return this.buildPunkt.getObject(config, options);
}
case 'fahrbandOben': // Kompatibilität für bereits gespeicherte Generatoren.
case 'fahrwagenOben': {
const { config, options } = parseFahrwagenObenRequest(input);
return this.buildFahrwagenOben.getObject(config, options);
}
case 'anlageDurmin': {
const { config, options } = parseAnlageDurminRequest(input);
return this.buildAnlageDurmin.getObject(config, options);
}
case 'pfeil': {
const { config, options } = parsePfeilRequest(input);
return this.buildPfeil.getObject(config, options);
}
case 'warnung': {
const { config, options } = parseWarnungRequest(input);
return this.buildWarnung.getObject(config, options);
}
case 'bandOben': return this.renderBandOben(input);
case 'motor': {
const { config, options } = parseMotorRequest(input);
return this.buildMotor.getObject(config, options);
}
default: throw new NotFoundException('Unbekannter POST-Grafiktyp: ' + type);
}
}
sieb(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildSieb.getSvg(options);
return this.buildSieb.getDrawObject(options);
}
gurtfoerderer(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildGurtfoerderer.getSvg(options);
return this.buildGurtfoerderer.getDrawObject(options);
}
setzmaschine(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildSetzmaschine.getSvg(options);
return this.buildSetzmaschine.getDrawObject(options);
}
band(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildBand.getSvg(options);
return this.buildBand.getDrawObject(options);
}
brecher(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildBrecher.getSvg(options);
return this.buildBrecher.getDrawObject(options);
}
behaelter(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildBehaelter.getSvg(options);
return this.buildBehaelter.getDrawObject(options);
}
siebentwaesserung(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildSiebentwaesseung.getSvg(options);
return this.buildSiebentwaesseung.getDrawObject(options);
}
weiche(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildWeiche.getSvg(options);
return this.buildWeiche.getDrawObject(options);
}
zyklon(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildZyklon.getSvg(options);
return this.buildZyklon.getDrawObject(options);
}
turbowascher(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildTurbowascher.getSvg(options);
return this.buildTurbowascher.getDrawObject(options);
}
haspel(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildHaspel.getSvg(options);
return this.buildHaspel.getDrawObject(options);
}
silo(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildSilo.getSvg(options);
return this.buildSilo.getDrawObject(options);
}
pumpe(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildPumpe.getSvg(options);
return this.buildPumpe.getDrawObject(options);
}
ventil(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildVentil.getSvg(options);
return this.buildVentil.getDrawObject(options);
}
wasserZufuhr(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildWasserZufuhr.getSvg(options);
return this.buildWasserZufuhr.getDrawObject(options);
}
behaelterMulti(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildBehaelterMulti.getSvg(options);
return this.buildBehaelterMulti.getDrawObject(options);
}
punkt(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
return rawSvg ? this.buildPunkt.getSvg(options) : this.buildPunkt.getDrawObject(options);
}
motor(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildMotor.getSvg(options);
return this.buildMotor.getDrawObject(options);
}
flex(options?: DrawShapeOptionenDto, rawSvg?: boolean) {
if (rawSvg) return this.buildFlex.getSvg(options);
return this.buildFlex.getDrawObject(options);
}
drawElement(name: string, options: DrawShapeOptionenDto) {
switch (name) {
case "gurtfoerderer":
return this.buildGurtfoerderer.getDrawObject(options);
case "sieb":
return this.buildSieb.getDrawObject(options);
case "band":
return this.buildBand.getDrawObject(options);
case "setzmaschine":
return this.buildSetzmaschine.getDrawObject(options);
case "brecher":
return this.buildBrecher.getDrawObject(options);
case "behaelter":
return this.buildBehaelter.getDrawObject(options);
case "siebentwaesserung":
return this.buildSiebentwaesseung.getDrawObject(options);
case "weiche":
return this.buildWeiche.getDrawObject(options);
case "zyklon":
return this.buildZyklon.getDrawObject(options);
case "turbowascher":
return this.buildTurbowascher.getDrawObject(options);
case "haspel":
return this.buildHaspel.getDrawObject(options);
case "silo":
return this.buildSilo.getDrawObject(options);
case "pumpe":
return this.buildPumpe.getDrawObject(options);
case "ventil":
return this.buildVentil.getDrawObject(options);
case "wasserZufuhr":
return this.buildWasserZufuhr.getDrawObject(options);
case "behaelterMulti":
return this.buildBehaelterMulti.getDrawObject(options);
case "motor":
return this.buildMotor.getDrawObject(options);
}
}
drawLine(element: VisuElementDto, line: LineDto, state: "inactive" | "active" | "error", xaml?: boolean,color?:string) {
//if (!element || !line) return new BadRequestException('Element has no lines')
let options: DrawShapeOptionenDto ={}
if(color && state==='inactive') options['colorInactive']=color;
if(color && state==='active') options['colorActive']=color;
if(color && state==='error') options['colorError']=color;
options['state']=state;
console.log("getDrawObject-->");
let params = this.buildPfeil.getDrawObject(line,options);
console.log("getSvg-->");
if (xaml) params.svg = this.buildPfeil.getSvg(line, options, xaml);
return params;
}
drawShape(name: string, options: DrawShapeOptionenDto) {
switch (name) {
case "gurtfoerderer":
return this.buildGurtfoerderer.getSvg(options);
case "sieb":
return this.buildSieb.getSvg(options);
case "band":
return this.buildBand.getSvg(options);
case "setzmaschine":
return this.buildSetzmaschine.getSvg(options);
case "brecher":
return this.buildBrecher.getSvg(options);
case "behaelter":
return this.buildBehaelter.getSvg(options);
case "siebentwaesserung":
return this.buildSiebentwaesseung.getSvg(options);
case "weiche":
return this.buildWeiche.getSvg(options);
case "zyklon":
return this.buildZyklon.getSvg(options);
case "turbowascher":
return this.buildTurbowascher.getSvg(options);
case "haspel":
return this.buildHaspel.getSvg(options);
case "pumpe":
return this.buildPumpe.getSvg(options);
case "ventil":
return this.buildVentil.getSvg(options);
case "wasserZufuhr":
return this.buildWasserZufuhr.getSvg(options);
case "behaelterMulti":
return this.buildBehaelterMulti.getSvg(options);
case "motor":
return this.buildMotor.getSvg(options);
case "silo":
let silo = this.buildSilo.getSvg(options);
const base64 = Buffer.from(silo, "utf-8").toString("base64");
//console.log(base64);
return silo;
case "flex":
console.log('----flex----')
return this.buildFlex.getSvg(options);
}
}
csv(text: string) {
createCsv(text);
}
}