181 lines
3.6 KiB
TypeScript
181 lines
3.6 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,
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
p2
|
|
| \
|
|
/
|
|
p1 p3
|
|
|
|
l1 l2
|
|
|
|
p5- p4
|
|
|
|
p2.1 p2.3
|
|
|
|
p2.2
|
|
|
|
|
|
*/
|
|
@Injectable()
|
|
export class DrawSetzmaschine {
|
|
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 = 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 = 1.0;
|
|
if (optionen && optionen.scale) scale = optionen.scale;
|
|
|
|
const x0 = 0;
|
|
const y0 = 0;
|
|
|
|
|
|
const l1 = 1.5 * raster * scale
|
|
const l2 = 11.5 * raster * scale
|
|
const h1 = 5 * raster * scale
|
|
const h2 = h1 + 1 * raster * scale
|
|
|
|
|
|
const r_x0 = l1 + 1 * raster;
|
|
const r_x1 = l2;
|
|
const r_y0 = 0;
|
|
const r_y1 = h1 - 1 * raster;
|
|
|
|
|
|
|
|
const l_x0 = r_x0;
|
|
const l_y0 = r_y1 / 2;
|
|
|
|
const l_x1 = r_x1;
|
|
const l_y1 = l_y0 + 1 * raster * scale;
|
|
|
|
const obj_h = h1 + h2 - 4;
|
|
const obj_w = l2;
|
|
|
|
const height = obj_h / raster / scale;
|
|
const width = obj_w / raster / scale;
|
|
|
|
//const { height, width, offsetX, offsetY } = cal_rotation_dim(0, obj_w, obj_h);
|
|
|
|
|
|
|
|
|
|
|
|
const deck: PathCommand[] = [
|
|
{ type: "M", x: x0, y: y0 },
|
|
{ type: "H", x: l1 },
|
|
{ type: "V", y: h1 },
|
|
{ type: "H", x: l2 },
|
|
{ type: "V", y: h2 },
|
|
{ type: "A", rx: (l2) / 2, ry: (l2 - 20) / 2, xAxisRotation: 0, largeArcFlag: 0, sweepFlag: 1, x: 0, y: h2 }, // u
|
|
{ type: "Z" }
|
|
];
|
|
|
|
const rechteck: PathCommand[] = [
|
|
{ type: "M", x: r_x0, y: r_y0 },
|
|
{ type: "H", x: r_x1 },
|
|
{ type: "V", y: r_y1 },
|
|
{ type: "H", x: r_x0 },
|
|
{ type: "Z" }
|
|
];
|
|
|
|
|
|
|
|
const groupInhalt = new DrawGroup({});
|
|
|
|
|
|
const z_deck = new DrawPath(deck);
|
|
z_deck.setAtrr({ fill: '#808080' })
|
|
|
|
const z_rechteck = new DrawPath(rechteck);
|
|
z_rechteck.setAtrr({ fill: color })
|
|
|
|
const z_line = new DrawLine({ x1: l_x0, y1: l_y0, x2: l_x1, y2: l_y1 });
|
|
z_line.setAtrr({ "dasharray": "5,5" });
|
|
|
|
|
|
const header = new DrawHeader({ lenght: obj_w, height: obj_h });
|
|
groupInhalt.add(z_line);
|
|
groupInhalt.add(z_rechteck);
|
|
groupInhalt.add(z_deck);
|
|
|
|
this.scale = scale;
|
|
this.height = height;
|
|
this.width = width;
|
|
this.obj_height = obj_h;
|
|
this.obj_width = obj_w;
|
|
|
|
return groupInhalt;
|
|
|
|
|
|
}
|
|
|
|
getDrawObject(optionen?: DrawShapeOptionenDto): DrawDto {
|
|
const groupSvg = this.create(optionen)
|
|
const svg = groupSvg.getChildString(false, 0)
|
|
return {
|
|
name: "setzmaschine",
|
|
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);
|
|
|
|
}
|
|
}
|
|
|