2023-07-07 17:15:53 +08:00
|
|
|
|
import { Graphics, IPointData } from 'pixi.js';
|
|
|
|
|
import {
|
|
|
|
|
GraphicData,
|
|
|
|
|
GraphicRelationParam,
|
|
|
|
|
JlGraphic,
|
|
|
|
|
JlGraphicTemplate,
|
|
|
|
|
VectorText,
|
2023-07-12 15:51:33 +08:00
|
|
|
|
calculateLineMidpoint,
|
2023-07-07 17:15:53 +08:00
|
|
|
|
} from 'src/jl-graphic';
|
|
|
|
|
import { IRelatedRefData, protoPort2Data } from '../CommonGraphics';
|
|
|
|
|
import { SectionPort } from '../section/Section';
|
|
|
|
|
|
2023-07-11 15:35:35 +08:00
|
|
|
|
export interface ITurnoutPosRefData {
|
|
|
|
|
get id(): string; //道岔的ID
|
|
|
|
|
set id(v: string);
|
|
|
|
|
get position(): number; //道岔的正反为,0是正位,1是反位
|
|
|
|
|
set position(v: number);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 17:15:53 +08:00
|
|
|
|
export interface IAxleCountingSectionData extends GraphicData {
|
|
|
|
|
get code(): string; // 编号
|
|
|
|
|
set code(v: string);
|
|
|
|
|
get points(): IPointData[]; // 线坐标点
|
|
|
|
|
set points(points: IPointData[]);
|
2023-07-11 15:35:35 +08:00
|
|
|
|
get paRef(): IRelatedRefData | undefined; //区段A端关联的设备
|
2023-07-07 17:15:53 +08:00
|
|
|
|
set paRef(ref: IRelatedRefData | undefined);
|
2023-07-11 15:35:35 +08:00
|
|
|
|
get pbRef(): IRelatedRefData | undefined; //区段B端关联的设备
|
2023-07-07 17:15:53 +08:00
|
|
|
|
set pbRef(ref: IRelatedRefData | undefined);
|
2023-07-12 10:12:15 +08:00
|
|
|
|
get turnoutPosRef(): ITurnoutPosRefData[]; //关联道岔的定反位--0是定位,1是反位
|
2023-07-11 15:35:35 +08:00
|
|
|
|
set turnoutPosRef(ref: ITurnoutPosRefData[]);
|
2023-07-11 16:18:02 +08:00
|
|
|
|
get indexNumber(): number; // 索引编号
|
|
|
|
|
set indexNumber(v: number);
|
2023-07-07 17:15:53 +08:00
|
|
|
|
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);
|
2023-07-12 15:51:33 +08:00
|
|
|
|
this.labelGraphic.style.fill = '0xff0000';
|
2023-07-07 17:15:53 +08:00
|
|
|
|
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 {
|
2023-07-12 15:51:33 +08:00
|
|
|
|
const centerPos = calculateLineMidpoint(
|
|
|
|
|
this.datas.points[0],
|
|
|
|
|
this.datas.points[this.datas.points.length - 1]
|
2023-07-07 17:15:53 +08:00
|
|
|
|
);
|
2023-07-12 15:57:08 +08:00
|
|
|
|
this.labelGraphic.position.set(centerPos.x, centerPos.y + 40);
|
2023-07-07 17:15:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-07-12 10:41:28 +08:00
|
|
|
|
if (this.datas?.turnoutPosRef.length) {
|
|
|
|
|
this.datas.turnoutPosRef.forEach((ref) => {
|
|
|
|
|
this.relationManage.addRelation(
|
|
|
|
|
this,
|
|
|
|
|
new GraphicRelationParam(
|
|
|
|
|
this.queryStore.queryById(ref.id),
|
|
|
|
|
ref.position
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-07 17:15:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|