194 lines
4.1 KiB
TypeScript
194 lines
4.1 KiB
TypeScript
import { PathCommand } from "../lib/types/path.types";
|
|
import { DrawLine } from '../lib/drawLine'
|
|
import { DrawPath } from '../lib/drawPath'
|
|
import { DrawGroup } from '../lib/drawGroup'
|
|
import { DrawEllipse } from "../lib/drawEllipse";
|
|
|
|
import { cal_rotation_dim } from '../lib/drawFunktions'
|
|
import { Injectable } from "@nestjs/common";
|
|
import { DrawDto, DrawShapeOptionenDto } from "src/_dto/draw.dto";
|
|
import { DrawHeader } from "../lib/drawHeader";
|
|
|
|
interface Para {
|
|
scale?: number,
|
|
}
|
|
|
|
|
|
@Injectable()
|
|
export class DrawTurbowascher {
|
|
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;
|
|
}
|
|
|
|
anker(x: number, y: number, direction: boolean, faktor: number) {
|
|
const a_h = 2.5 * faktor;
|
|
const a_l = 0.3 * faktor;
|
|
const a_d = 0.2 * faktor;
|
|
|
|
let di = 1;
|
|
if (direction) di = -1;
|
|
|
|
let path: PathCommand[] = [
|
|
{ type: 'M', x: x, y: y },
|
|
{ type: 'V', y: y + a_h * di },
|
|
{ type: 'H', x: x + a_l },
|
|
{ type: 'V', y: y + ((a_h - a_d) * di) },
|
|
{ type: 'H', x: x + a_d },
|
|
{ type: 'V', y: y },
|
|
{ type: 'Z' },
|
|
|
|
]
|
|
return path;
|
|
}
|
|
|
|
|
|
|
|
create(optionen?: DrawShapeOptionenDto): DrawGroup {
|
|
let color = this.normal;
|
|
if (optionen && optionen.state == 'active') color = this.green;
|
|
if (optionen && optionen.state == 'error') color = 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 faktor = raster * scale;
|
|
|
|
const x0 = 0 * faktor;
|
|
const y0 = 0 * faktor;
|
|
const l1 = 14 * faktor;
|
|
const l2 = 12 * faktor;
|
|
const h = 6 * faktor;
|
|
const d = 0.4 * faktor;
|
|
|
|
const d_between = 2.5;
|
|
|
|
let obj_h = (x0 + h);
|
|
let obj_w = (y0 + l1 + 1 * raster);
|
|
let laenge = obj_w / raster / scale;
|
|
let hoehe = obj_h / raster / scale;
|
|
|
|
|
|
const groupAnker = new DrawGroup({});
|
|
let anker_pos_x = 1 * faktor;
|
|
let step = 1.5 * faktor;
|
|
let anz = 9;
|
|
let di = false;
|
|
|
|
for (let i = 0; i < anz; i++) {
|
|
const path = this.anker(anker_pos_x, h / 2, di, faktor);
|
|
const z_anker = new DrawPath(path); // Kasten
|
|
groupAnker.add(z_anker);
|
|
di = !di;
|
|
anker_pos_x += step;
|
|
}
|
|
|
|
|
|
|
|
//Kasten
|
|
const g1_path: PathCommand[] = [
|
|
{ type: 'M', x: x0, y: y0 },
|
|
{ type: 'H', x: l1 },
|
|
{ type: 'V', y: h },
|
|
{ type: 'H', x: x0 },
|
|
{ type: 'Z' }
|
|
];
|
|
|
|
// Kasten Hinten
|
|
const g2_path: PathCommand[] = [
|
|
{ type: 'M', x: x0 + l1, y: y0 },
|
|
{ type: 'H', x: x0 + l1 + 1 * raster },
|
|
{ type: 'V', y: h },
|
|
{ type: 'H', x: x0 + l1 },
|
|
{ type: 'Z' }
|
|
];
|
|
|
|
const g3_path: PathCommand[] = [
|
|
{ type: 'M', x: x0, y: h / 2 - d / 2 },
|
|
{ type: 'H', x: l1 + raster },
|
|
{ type: 'V', y: h / 2 + d / 2 },
|
|
{ type: 'H', x: x0 },
|
|
{ type: 'Z' }
|
|
];
|
|
|
|
|
|
|
|
|
|
const groupInhalt = new DrawGroup({});
|
|
|
|
const z_g1 = new DrawPath(g1_path); // Kasten
|
|
z_g1.setAtrr({ fill: color })
|
|
|
|
const z_g2 = new DrawPath(g2_path); // Kasten
|
|
z_g2.setAtrr({ fill: '#808080' })
|
|
|
|
const z_g3 = new DrawPath(g3_path); // Kasten
|
|
z_g3.setAtrr({ fill: '#808080' })
|
|
|
|
groupInhalt.add(z_g2);
|
|
groupInhalt.add(z_g3);
|
|
groupInhalt.add(groupAnker);
|
|
groupInhalt.add(z_g1);
|
|
|
|
|
|
|
|
this.obj_height = obj_h;
|
|
this.obj_width = obj_w;
|
|
this.scale = scale;
|
|
this.raster = raster;
|
|
this.height = hoehe;
|
|
this.width = laenge;
|
|
|
|
return groupInhalt;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
getDrawObject(optionen?: DrawShapeOptionenDto): DrawDto {
|
|
const groupSvg = this.create(optionen)
|
|
const svg = groupSvg.getChildString(false, 0)
|
|
return {
|
|
name: "turbowasher",
|
|
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);
|
|
|
|
}
|
|
}
|
|
|