123 lines
3.6 KiB
TypeScript
123 lines
3.6 KiB
TypeScript
|
import { Graphics, IPointData } from 'pixi.js';
|
||
|
import {
|
||
|
GraphicData,
|
||
|
GraphicRelationParam,
|
||
|
JlGraphic,
|
||
|
JlGraphicTemplate,
|
||
|
VectorText,
|
||
|
} from 'src/jl-graphic';
|
||
|
import { IRelatedRefData, protoPort2Data } from '../CommonGraphics';
|
||
|
import { SectionPort } from '../section/Section';
|
||
|
|
||
|
export interface IAxleCountingSectionData extends GraphicData {
|
||
|
get code(): string; // 编号
|
||
|
set code(v: string);
|
||
|
get points(): IPointData[]; // 线坐标点
|
||
|
set points(points: IPointData[]);
|
||
|
get paRef(): IRelatedRefData | undefined;
|
||
|
set paRef(ref: IRelatedRefData | undefined);
|
||
|
get pbRef(): IRelatedRefData | undefined;
|
||
|
set pbRef(ref: IRelatedRefData | undefined);
|
||
|
clone(): IAxleCountingSectionData;
|
||
|
copyFrom(data: IAxleCountingSectionData): void;
|
||
|
eq(other: IAxleCountingSectionData): boolean;
|
||
|
}
|
||
|
|
||
|
export const AxleCountingSectionConsts = {
|
||
|
lineColor: '0xff0000',
|
||
|
lineWidth: 2,
|
||
|
};
|
||
|
|
||
|
export class AxleCountingSection extends JlGraphic {
|
||
|
static Type = 'AxleCountingSection';
|
||
|
lineGraphic: Graphics;
|
||
|
labelGraphic: VectorText;
|
||
|
constructor() {
|
||
|
super(AxleCountingSection.Type);
|
||
|
this.lineGraphic = new Graphics();
|
||
|
this.labelGraphic = new VectorText();
|
||
|
this.labelGraphic.setVectorFontSize(14);
|
||
|
this.labelGraphic.anchor.set(0.5);
|
||
|
this.labelGraphic.style.fill = '#0f0';
|
||
|
this.labelGraphic.transformSave = true;
|
||
|
this.labelGraphic.name = 'label';
|
||
|
this.transformSave = true;
|
||
|
this.addChild(this.lineGraphic);
|
||
|
this.addChild(this.labelGraphic);
|
||
|
}
|
||
|
|
||
|
get datas(): IAxleCountingSectionData {
|
||
|
return this.getDatas<IAxleCountingSectionData>();
|
||
|
}
|
||
|
doRepaint(): void {
|
||
|
if (this.datas.points.length < 2) {
|
||
|
throw new Error('AxleCountingSection坐标数据异常');
|
||
|
}
|
||
|
this.lineGraphic.clear();
|
||
|
this.lineGraphic.lineStyle(
|
||
|
AxleCountingSectionConsts.lineWidth,
|
||
|
AxleCountingSectionConsts.lineColor
|
||
|
);
|
||
|
this.datas.points.forEach((p, i) => {
|
||
|
if (i !== 0) {
|
||
|
this.lineGraphic.lineTo(p.x, p.y);
|
||
|
} else {
|
||
|
this.lineGraphic.moveTo(p.x, p.y);
|
||
|
}
|
||
|
});
|
||
|
this.labelGraphic.text = this.datas.code;
|
||
|
const labelPosition = this.datas.childTransforms?.find(
|
||
|
(t) => t.name === this.labelGraphic.name
|
||
|
)?.transform.position;
|
||
|
if (labelPosition) {
|
||
|
this.labelGraphic.position.set(labelPosition.x, labelPosition.y);
|
||
|
} else {
|
||
|
this.labelGraphic.position.set(
|
||
|
this.datas.points[0].x,
|
||
|
this.datas.points[0].y + 20
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
get linePoints(): IPointData[] {
|
||
|
return this.datas.points;
|
||
|
}
|
||
|
set linePoints(points: IPointData[]) {
|
||
|
const old = this.datas.clone();
|
||
|
old.points = points;
|
||
|
this.updateData(old);
|
||
|
}
|
||
|
loadRelations() {
|
||
|
if (this.datas?.paRef?.id) {
|
||
|
this.relationManage.addRelation(
|
||
|
new GraphicRelationParam(this, SectionPort.A),
|
||
|
new GraphicRelationParam(
|
||
|
this.queryStore.queryById(this.datas.paRef.id),
|
||
|
protoPort2Data(this.datas.paRef.devicePort)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
if (this.datas?.pbRef?.id) {
|
||
|
this.relationManage.addRelation(
|
||
|
new GraphicRelationParam(this, SectionPort.B),
|
||
|
new GraphicRelationParam(
|
||
|
this.queryStore.queryById(this.datas.pbRef.id),
|
||
|
protoPort2Data(this.datas.pbRef.devicePort)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class AxleCountingSectionTemplate extends JlGraphicTemplate<AxleCountingSection> {
|
||
|
constructor(dataTemplate: IAxleCountingSectionData) {
|
||
|
super(AxleCountingSection.Type, {
|
||
|
dataTemplate,
|
||
|
});
|
||
|
}
|
||
|
new(): AxleCountingSection {
|
||
|
const axleCountingSection = new AxleCountingSection();
|
||
|
axleCountingSection.loadData(this.datas);
|
||
|
return axleCountingSection;
|
||
|
}
|
||
|
}
|