2023-07-13 17:57:13 +08:00
|
|
|
import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js';
|
2023-07-07 17:15:53 +08:00
|
|
|
import {
|
|
|
|
GraphicDrawAssistant,
|
|
|
|
GraphicIdGenerator,
|
|
|
|
GraphicInteractionPlugin,
|
|
|
|
JlDrawApp,
|
|
|
|
JlGraphic,
|
|
|
|
linePoint,
|
|
|
|
} from 'src/jl-graphic';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IAxleCountingSectionData,
|
|
|
|
AxleCountingSection,
|
|
|
|
AxleCountingSectionTemplate,
|
|
|
|
AxleCountingSectionConsts,
|
2023-07-11 15:35:35 +08:00
|
|
|
ITurnoutPosRefData,
|
2023-07-07 17:15:53 +08:00
|
|
|
} from './AxleCountingSection';
|
|
|
|
import { AxleCounting } from '../axleCounting/AxleCounting';
|
2023-07-13 17:57:13 +08:00
|
|
|
import { Section } from '../section/Section';
|
|
|
|
import { Turnout } from '../turnout/Turnout';
|
2023-07-07 17:15:53 +08:00
|
|
|
import { createRelatedRefProto } from '../CommonGraphics';
|
|
|
|
|
2023-07-13 17:57:13 +08:00
|
|
|
function removePortBC<T>(a: T, b: T): boolean {
|
|
|
|
if ((a == 'B' && b == 'C') || (a == 'C' && b == 'B')) {
|
|
|
|
return false;
|
2023-07-07 17:15:53 +08:00
|
|
|
}
|
2023-07-13 17:57:13 +08:00
|
|
|
return true;
|
2023-07-07 17:15:53 +08:00
|
|
|
}
|
|
|
|
export interface IAxleCountingSectionDrawOptions {
|
|
|
|
newData: () => IAxleCountingSectionData;
|
|
|
|
}
|
|
|
|
export class AxleCountingSectionDraw extends GraphicDrawAssistant<
|
|
|
|
AxleCountingSectionTemplate,
|
|
|
|
IAxleCountingSectionData
|
|
|
|
> {
|
|
|
|
codeGraph: AxleCountingSection;
|
|
|
|
constructor(app: JlDrawApp, template: AxleCountingSectionTemplate) {
|
|
|
|
super(app, template, 'sym_o_circle', '不展示');
|
|
|
|
this.codeGraph = this.graphicTemplate.new();
|
|
|
|
this.container.addChild(this.codeGraph);
|
2023-07-12 17:16:12 +08:00
|
|
|
AxleCountingSectionInteraction.init(app);
|
2023-07-07 17:15:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bind(): void {
|
|
|
|
super.bind();
|
|
|
|
this.codeGraph.loadData(this.graphicTemplate.datas);
|
|
|
|
this.codeGraph.doRepaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
clearCache(): void {
|
|
|
|
//this.codeGraph.destroy();
|
|
|
|
}
|
|
|
|
onLeftDown(e: FederatedPointerEvent): void {
|
|
|
|
this.container.position.copyFrom(this.toCanvasCoordinates(e.global));
|
|
|
|
this.createAndStore(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
redraw(p: Point): void {
|
|
|
|
this.container.position.copyFrom(p);
|
|
|
|
}
|
|
|
|
prepareData(data: IAxleCountingSectionData): boolean {
|
|
|
|
data.transform = this.container.saveTransform();
|
|
|
|
return true;
|
|
|
|
}
|
2023-07-11 15:35:35 +08:00
|
|
|
draw(
|
|
|
|
graphics: AxleCounting[],
|
|
|
|
commonElement: JlGraphic[],
|
2023-07-11 17:42:04 +08:00
|
|
|
map: Map<string, number>,
|
2023-07-13 17:57:13 +08:00
|
|
|
turoutPos?: number[]
|
2023-07-11 15:35:35 +08:00
|
|
|
) {
|
2023-07-11 17:42:04 +08:00
|
|
|
if (
|
|
|
|
map.has(`${graphics[0].id}+${graphics[1].id}`) ||
|
|
|
|
map.has(`${graphics[1].id}+${graphics[0].id}`)
|
|
|
|
)
|
|
|
|
return;
|
2023-07-13 17:57:13 +08:00
|
|
|
map.set(`${graphics[0].id}+${graphics[1].id}`, 1);
|
2023-07-07 17:15:53 +08:00
|
|
|
const axleCountingSection = new AxleCountingSection();
|
|
|
|
axleCountingSection.loadData(this.graphicTemplate.datas);
|
|
|
|
axleCountingSection.datas.points = [
|
|
|
|
graphics[0].position,
|
|
|
|
graphics[1].position,
|
|
|
|
];
|
|
|
|
axleCountingSection.id = GraphicIdGenerator.next();
|
|
|
|
const paRef = createRelatedRefProto(graphics[0].type, graphics[0].id);
|
|
|
|
const pbRef = createRelatedRefProto(graphics[1].type, graphics[1].id);
|
2023-07-11 15:35:35 +08:00
|
|
|
const turnoutPosData: ITurnoutPosRefData[] = [];
|
|
|
|
if (commonElement[0].type == 'Turnout') {
|
2023-07-12 18:42:52 +08:00
|
|
|
commonElement.forEach((Turnout, i) => {
|
2023-07-13 17:57:13 +08:00
|
|
|
turnoutPosData.push({
|
|
|
|
id: Turnout.id,
|
|
|
|
position: (turoutPos as number[])[i],
|
|
|
|
});
|
2023-07-11 15:35:35 +08:00
|
|
|
});
|
|
|
|
}
|
2023-07-07 17:15:53 +08:00
|
|
|
axleCountingSection.datas.paRef = paRef;
|
|
|
|
axleCountingSection.datas.pbRef = pbRef;
|
2023-07-11 15:35:35 +08:00
|
|
|
axleCountingSection.datas.turnoutPosRef = turnoutPosData;
|
2023-07-07 17:15:53 +08:00
|
|
|
this.storeGraphic(axleCountingSection);
|
|
|
|
axleCountingSection.loadRelations();
|
|
|
|
}
|
|
|
|
oneGenerates() {
|
2023-07-11 17:42:04 +08:00
|
|
|
const map = new Map();
|
2023-07-10 15:03:47 +08:00
|
|
|
const axleCountingSections =
|
2023-07-07 17:25:51 +08:00
|
|
|
this.app.queryStore.queryByType<AxleCountingSection>(
|
|
|
|
AxleCountingSection.Type
|
|
|
|
);
|
2023-07-11 17:42:04 +08:00
|
|
|
axleCountingSections.forEach((axleCountingSection) => {
|
|
|
|
map.set(
|
|
|
|
`${axleCountingSection.datas.paRef?.id}+${axleCountingSection.datas.pbRef?.id}`,
|
|
|
|
1
|
|
|
|
);
|
|
|
|
});
|
2023-07-07 17:15:53 +08:00
|
|
|
const axleCountings = this.app.queryStore.queryByType<AxleCounting>(
|
|
|
|
AxleCounting.Type
|
|
|
|
);
|
|
|
|
axleCountings.forEach((axleCounting) => {
|
2023-07-13 17:57:13 +08:00
|
|
|
//计轴关联的区段
|
|
|
|
const axleCountingRefSection =
|
|
|
|
axleCounting.relationManage.getRelationsOfGraphicAndOtherType(
|
|
|
|
axleCounting,
|
|
|
|
Section.Type
|
2023-07-07 17:15:53 +08:00
|
|
|
);
|
2023-07-13 17:57:13 +08:00
|
|
|
axleCountingRefSection.forEach((ref) => {
|
|
|
|
const refDevice = ref.getOtherGraphic<Section>(axleCounting);
|
|
|
|
const refDevicePort = ref.getOtherRelationParam(axleCounting).param;
|
|
|
|
const refDeviceOtherPort = refDevicePort == 'A' ? 'B' : 'A';
|
|
|
|
const otherPortRefAxle = refDevice.relationManage
|
|
|
|
.getRelationsOfGraphicAndOtherType(refDevice, AxleCounting.Type)
|
|
|
|
.find(
|
|
|
|
(relation) =>
|
|
|
|
relation.getRelationParam(refDevice).param == refDeviceOtherPort
|
|
|
|
)
|
|
|
|
?.getOtherGraphic(refDevice);
|
|
|
|
if (otherPortRefAxle !== undefined) {
|
2023-07-11 15:35:35 +08:00
|
|
|
this.draw(
|
2023-07-13 17:57:13 +08:00
|
|
|
[axleCounting, otherPortRefAxle as AxleCounting],
|
|
|
|
[refDevice],
|
2023-07-11 17:42:04 +08:00
|
|
|
map
|
2023-07-11 15:35:35 +08:00
|
|
|
);
|
2023-07-10 10:04:53 +08:00
|
|
|
}
|
2023-07-13 17:57:13 +08:00
|
|
|
});
|
|
|
|
//计轴关联的道岔
|
|
|
|
const axleCountingRefTurnout =
|
2023-07-12 18:42:52 +08:00
|
|
|
axleCounting.relationManage.getRelationsOfGraphicAndOtherType(
|
|
|
|
axleCounting,
|
2023-07-13 17:57:13 +08:00
|
|
|
Turnout.Type
|
2023-07-12 18:42:52 +08:00
|
|
|
);
|
2023-07-13 17:57:13 +08:00
|
|
|
axleCountingRefTurnout.forEach((ref) => {
|
|
|
|
const refDevice = ref.getOtherGraphic<Turnout>(axleCounting);
|
|
|
|
const refDevicePort = ref.getOtherRelationParam(axleCounting).param;
|
|
|
|
let refDeviceOtherPort: string[] = [];
|
|
|
|
switch (refDevicePort) {
|
|
|
|
case 'A':
|
|
|
|
refDeviceOtherPort = ['B', 'C'];
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
refDeviceOtherPort = ['A', 'C'];
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
refDeviceOtherPort = ['A', 'B'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//关联道岔的其它端点--需要找路径
|
|
|
|
refDeviceOtherPort.forEach((port) => {
|
|
|
|
const otherPortRefAxle = refDevice.relationManage
|
|
|
|
.getRelationsOfGraphicAndOtherType(refDevice, AxleCounting.Type)
|
|
|
|
.find(
|
|
|
|
(relation) => relation.getRelationParam(refDevice).param == port
|
|
|
|
)
|
|
|
|
?.getOtherGraphic(refDevice);
|
|
|
|
if (
|
|
|
|
otherPortRefAxle !== undefined &&
|
|
|
|
removePortBC(refDevicePort, port)
|
|
|
|
) {
|
|
|
|
let turoutPos = 0;
|
|
|
|
if (refDevicePort == 'C' || port == 'C') {
|
|
|
|
turoutPos = 1;
|
|
|
|
}
|
|
|
|
this.draw(
|
|
|
|
[axleCounting, otherPortRefAxle as AxleCounting],
|
|
|
|
[refDevice],
|
|
|
|
map,
|
|
|
|
[turoutPos]
|
|
|
|
);
|
|
|
|
} else if (otherPortRefAxle == undefined) {
|
|
|
|
const refDeviceRefTurnoutRelation = refDevice.relationManage
|
|
|
|
.getRelationsOfGraphicAndOtherType(refDevice, Turnout.Type)
|
|
|
|
.find(
|
|
|
|
(relation) => relation.getRelationParam(refDevice).param == port
|
|
|
|
);
|
|
|
|
const refDeviceRefTurnout =
|
|
|
|
refDeviceRefTurnoutRelation?.getOtherGraphic(refDevice);
|
|
|
|
const refDeviceRefTurnoutPort =
|
|
|
|
refDeviceRefTurnoutRelation?.getRelationParam(
|
|
|
|
refDeviceRefTurnout as JlGraphic
|
|
|
|
).param;
|
|
|
|
const otherPortRefAxleInfo: {
|
|
|
|
axle: AxleCounting;
|
|
|
|
turoutPort: string;
|
|
|
|
}[] = [];
|
2023-07-14 08:48:21 +08:00
|
|
|
refDeviceRefTurnout?.relationManage
|
2023-07-13 17:57:13 +08:00
|
|
|
.getRelationsOfGraphicAndOtherType(
|
|
|
|
refDeviceRefTurnout,
|
|
|
|
AxleCounting.Type
|
|
|
|
)
|
|
|
|
.filter((relation) => {
|
|
|
|
return (
|
|
|
|
relation.getRelationParam(refDeviceRefTurnout).param !==
|
|
|
|
refDeviceRefTurnoutPort
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.forEach((ref) => {
|
|
|
|
otherPortRefAxleInfo.push({
|
|
|
|
axle: ref.getOtherGraphic(refDeviceRefTurnout),
|
|
|
|
turoutPort: ref.getRelationParam(refDeviceRefTurnout).param,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const bbConnect =
|
|
|
|
port == 'B' && refDeviceRefTurnoutPort == 'B' ? true : false;
|
|
|
|
otherPortRefAxleInfo?.forEach((info) => {
|
|
|
|
if (
|
|
|
|
(refDevicePort !== 'C' && info.turoutPort !== 'C') ||
|
|
|
|
(refDevicePort == 'A' && info.turoutPort == 'C' && !bbConnect)
|
|
|
|
) {
|
|
|
|
let turoutPos: number[] = [];
|
|
|
|
if (
|
|
|
|
refDevicePort == 'A' &&
|
|
|
|
info.turoutPort == 'C' &&
|
|
|
|
!bbConnect
|
|
|
|
) {
|
|
|
|
turoutPos = [0, 1];
|
|
|
|
} else {
|
|
|
|
turoutPos = [0, 0];
|
|
|
|
}
|
|
|
|
this.draw(
|
|
|
|
[axleCounting, info.axle as AxleCounting],
|
|
|
|
[refDevice, refDeviceRefTurnout as JlGraphic],
|
|
|
|
map,
|
|
|
|
turoutPos
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2023-07-12 18:42:52 +08:00
|
|
|
}
|
|
|
|
});
|
2023-07-13 17:57:13 +08:00
|
|
|
});
|
2023-07-12 18:42:52 +08:00
|
|
|
});
|
2023-07-07 17:15:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class AxleCountingSectionGraphicHitArea implements IHitArea {
|
|
|
|
axleCountingSection: AxleCountingSection;
|
|
|
|
constructor(axleCountingSection: AxleCountingSection) {
|
|
|
|
this.axleCountingSection = axleCountingSection;
|
|
|
|
}
|
|
|
|
contains(x: number, y: number): boolean {
|
|
|
|
for (let i = 1; i < this.axleCountingSection.datas.points.length; i++) {
|
|
|
|
const p1 = this.axleCountingSection.datas.points[i - 1];
|
|
|
|
const p2 = this.axleCountingSection.datas.points[i];
|
|
|
|
if (linePoint(p1, p2, { x, y }, AxleCountingSectionConsts.lineWidth)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class AxleCountingSectionInteraction extends GraphicInteractionPlugin<AxleCountingSection> {
|
|
|
|
static Name = 'AxleCountingSection_transform';
|
2023-07-12 17:16:12 +08:00
|
|
|
constructor(app: JlDrawApp) {
|
2023-07-07 17:15:53 +08:00
|
|
|
super(AxleCountingSectionInteraction.Name, app);
|
|
|
|
}
|
2023-07-12 17:16:12 +08:00
|
|
|
static init(app: JlDrawApp) {
|
|
|
|
return new AxleCountingSectionInteraction(app);
|
2023-07-07 17:15:53 +08:00
|
|
|
}
|
|
|
|
filter(...grahpics: JlGraphic[]): AxleCountingSection[] | undefined {
|
|
|
|
return grahpics
|
|
|
|
.filter((g) => g.type === AxleCountingSection.Type)
|
|
|
|
.map((g) => g as AxleCountingSection);
|
|
|
|
}
|
|
|
|
bind(g: AxleCountingSection): void {
|
|
|
|
g.eventMode = 'static';
|
|
|
|
g.cursor = 'pointer';
|
|
|
|
g.scalable = true;
|
|
|
|
g.transformSave = true;
|
|
|
|
g.lineGraphic.eventMode = 'static';
|
|
|
|
g.lineGraphic.cursor = 'pointer';
|
|
|
|
g.lineGraphic.hitArea = new AxleCountingSectionGraphicHitArea(g);
|
|
|
|
g.labelGraphic.eventMode = 'static';
|
|
|
|
g.labelGraphic.cursor = 'pointer';
|
|
|
|
g.labelGraphic.selectable = true;
|
|
|
|
g.labelGraphic.draggable = true;
|
|
|
|
}
|
|
|
|
unbind(g: AxleCountingSection): void {
|
|
|
|
g.eventMode = 'none';
|
|
|
|
g.scalable = false;
|
|
|
|
g.rotatable = false;
|
|
|
|
g.lineGraphic.eventMode = 'none';
|
|
|
|
g.lineGraphic.draggable = false;
|
|
|
|
g.lineGraphic.selectable = false;
|
|
|
|
g.lineGraphic.transformSave = false;
|
|
|
|
g.labelGraphic.eventMode = 'none';
|
|
|
|
g.labelGraphic.draggable = false;
|
|
|
|
g.labelGraphic.selectable = false;
|
|
|
|
g.labelGraphic.transformSave = false;
|
|
|
|
}
|
|
|
|
}
|