测试站台关联关系

This commit is contained in:
joylink_zhaoerwei 2024-01-11 09:21:44 +08:00
parent fa5c16a337
commit 82ef30607f
7 changed files with 152 additions and 225 deletions

View File

@ -1,8 +1,5 @@
import { distance2, getRectangleCenter } from 'jl-graphic';
import { GPConsts } from './PlatformConfig.js'; import { GPConsts } from './PlatformConfig.js';
import { JlPlatform } from './JlPlatform.js'; import { JlPlatform } from './JlPlatform.js';
import { GPStation } from '../Station/GPStation.js';
import { JlSection } from '../Section/common/Section.js';
class GPPlatform extends JlPlatform { class GPPlatform extends JlPlatform {
constructor() { constructor() {
@ -16,54 +13,13 @@ class GPPlatform extends JlPlatform {
super.draw(); super.draw();
} }
buildRelation() { buildRelation() {
const stationas = this.queryStore.queryByType(GPStation.Type); super.buildCommonRelation();
for (let i = 0; i < stationas.length; i++) {
const sP = stationas[i].localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
this.relationManage.addRelation(this, stationas[i]);
break;
}
}
const sections = this.queryStore.queryByType(JlSection.Type);
const minDistanceRefSections = [];
sections.forEach((section) => {
const sP = section.localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
minDistanceRefSections.push(section);
}
});
if (minDistanceRefSections) {
const refSection = minDistanceRefSections.reduce((prev, cur) => {
return distance2(prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), this.position) >
distance2(cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), this.position)
? cur
: prev;
});
this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
this.relationManage.addRelation(this, refSection);
}
} }
saveRelations() { saveRelations() {
const refStation = this.relationManage super.saveCommonRelations();
.getRelationsOfGraphicAndOtherType(this, GPStation.Type)
.map((relation) => relation.getOtherGraphic(this).datas.id);
if (refStation.length) {
this.datas.refStation = refStation[0];
}
const refSection = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlSection.Type)
.map((relation) => relation.getOtherGraphic(this).datas.id);
if (refSection.length) {
this.datas.refSection = refSection[0];
}
} }
loadRelations() { loadRelations() {
if (this.datas.refStation) { super.loadCommonRelations();
this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refStation));
}
if (this.datas.refSection) {
this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refSection));
}
} }
} }

View File

@ -48,5 +48,8 @@ export declare abstract class JlPlatform extends JlGraphic {
get datas(): IPlatformData; get datas(): IPlatformData;
get code(): string; get code(): string;
draw(): void; draw(): void;
buildCommonRelation(): void;
saveCommonRelations(): void;
loadCommonRelations(): void;
} }
export {}; export {};

View File

@ -1,5 +1,7 @@
import { calculateMirrorPoint, JlGraphic, getRectangleCenter, VectorText } from 'jl-graphic'; import { calculateMirrorPoint, JlGraphic, distance2, getRectangleCenter, VectorText } from 'jl-graphic';
import { Container, Point, Graphics, Color, Rectangle } from 'pixi.js'; import { Container, Point, Graphics, Color, Rectangle } from 'pixi.js';
import { JlSection } from '../Section/common/Section.js';
import { JlStation } from '../Station/JlStation.js';
//子元素--矩形 //子元素--矩形
class RectGraphic extends Container { class RectGraphic extends Container {
@ -225,6 +227,56 @@ class JlPlatform extends JlGraphic {
draw() { draw() {
this.rectGraphic.draw(this.platformConsts); this.rectGraphic.draw(this.platformConsts);
} }
buildCommonRelation() {
const stationas = this.queryStore.queryByType(JlStation.Type);
for (let i = 0; i < stationas.length; i++) {
const sP = stationas[i].localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
this.relationManage.addRelation(this, stationas[i]);
break;
}
}
const sections = this.queryStore.queryByType(JlSection.Type);
const minDistanceRefSections = [];
sections.forEach((section) => {
const sP = section.localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
minDistanceRefSections.push(section);
}
});
if (minDistanceRefSections) {
const refSection = minDistanceRefSections.reduce((prev, cur) => {
return distance2(prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), this.position) >
distance2(cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), this.position)
? cur
: prev;
});
this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
this.relationManage.addRelation(this, refSection);
}
}
saveCommonRelations() {
const refStation = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlStation.Type)
.map((relation) => relation.getOtherGraphic(this).datas.id);
if (refStation.length) {
this.datas.refStation = refStation[0];
}
const refSection = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlSection.Type)
.map((relation) => relation.getOtherGraphic(this).datas.id);
if (refSection.length) {
this.datas.refSection = refSection[0];
}
}
loadCommonRelations() {
if (this.datas.refStation) {
this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refStation));
}
if (this.datas.refSection) {
this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refSection));
}
}
} }
export { DoorCodeLozenge, JlPlatform }; export { DoorCodeLozenge, JlPlatform };

View File

@ -1,7 +1,5 @@
import { distance2, getRectangleCenter } from 'jl-graphic';
import { THConsts } from './PlatformConfig.js'; import { THConsts } from './PlatformConfig.js';
import { JlPlatform, DoorCodeLozenge } from './JlPlatform.js'; import { JlPlatform, DoorCodeLozenge } from './JlPlatform.js';
import { JlSection } from '../Section/common/Section.js';
import { THStation } from '../Station/THStation.js'; import { THStation } from '../Station/THStation.js';
class THPlatform extends JlPlatform { class THPlatform extends JlPlatform {
@ -22,15 +20,15 @@ class THPlatform extends JlPlatform {
if (this.states.upSkipstop || this.states.downSkipstop) { if (this.states.upSkipstop || this.states.downSkipstop) {
this.rectGraphic.stateFillColor = THConsts.trainJump; this.rectGraphic.stateFillColor = THConsts.trainJump;
} }
/* const station = this.getGraphicApp().queryStore.queryByCodeAndType<Station>( const station = this.getGraphicApp().queryStore.queryByCodeAndType(this.states.rtuId > 9
this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, ? '' + this.states.rtuId
Station.Type : '0' + this.states.rtuId, THStation.Type);
); */
const doorGraphic = this.doorCodeLozenge.doorGraphic; const doorGraphic = this.doorCodeLozenge.doorGraphic;
doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen; doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen;
/* if (!!station?.states.ipRtuStusDown) { if (!!station?.states.ipRtuStusDown) {
doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue; doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue;
} */ if (this.states.psdCut) { }
else if (this.states.psdCut) {
doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed; doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed;
} }
super.draw(); super.draw();
@ -97,54 +95,13 @@ class THPlatform extends JlPlatform {
} }
} }
buildRelation() { buildRelation() {
const stationas = this.queryStore.queryByType(THStation.Type); super.buildCommonRelation();
for (let i = 0; i < stationas.length; i++) {
const sP = stationas[i].localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
this.relationManage.addRelation(this, stationas[i]);
break;
}
}
const sections = this.queryStore.queryByType(JlSection.Type);
const minDistanceRefSections = [];
sections.forEach((section) => {
const sP = section.localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
minDistanceRefSections.push(section);
}
});
if (minDistanceRefSections) {
const refSection = minDistanceRefSections.reduce((prev, cur) => {
return distance2(prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())), this.position) >
distance2(cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())), this.position)
? cur
: prev;
});
this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
this.relationManage.addRelation(this, refSection);
}
} }
saveRelations() { saveRelations() {
const refStation = this.relationManage super.saveCommonRelations();
.getRelationsOfGraphicAndOtherType(this, THStation.Type)
.map((relation) => relation.getOtherGraphic(this).datas.id);
if (refStation.length) {
this.datas.refStation = refStation[0];
}
const refSection = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlSection.Type)
.map((relation) => relation.getOtherGraphic(this).datas.id);
if (refSection.length) {
this.datas.refSection = refSection[0];
}
} }
loadRelations() { loadRelations() {
if (this.datas.refStation) { super.loadCommonRelations();
this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refStation));
}
if (this.datas.refSection) {
this.relationManage.addRelation(this, this.queryStore.queryById(this.datas.refSection));
}
} }
} }

View File

@ -20,68 +20,12 @@ export class GPPlatform extends JlPlatform {
super.draw(); super.draw();
} }
buildRelation() { buildRelation() {
const stationas = this.queryStore.queryByType<GPStation>(GPStation.Type); super.buildCommonRelation();
for (let i = 0; i < stationas.length; i++) {
const sP = stationas[i].localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
this.relationManage.addRelation(this, stationas[i]);
break;
}
}
const sections = this.queryStore.queryByType<JlSection>(JlSection.Type);
const minDistanceRefSections: JlSection[] = [];
sections.forEach((section) => {
const sP = section.localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
minDistanceRefSections.push(section);
}
});
if (minDistanceRefSections) {
const refSection = minDistanceRefSections.reduce((prev, cur) => {
return distance2(
prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())),
this.position,
) >
distance2(
cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())),
this.position,
)
? cur
: prev;
});
this.relationManage.deleteRelationOfGraphicAndOtherType(
this,
JlSection.Type,
);
this.relationManage.addRelation(this, refSection);
}
} }
saveRelations() { saveRelations() {
const refStation = this.relationManage super.saveCommonRelations();
.getRelationsOfGraphicAndOtherType(this, GPStation.Type)
.map((relation) => relation.getOtherGraphic<GPStation>(this).datas.id);
if (refStation.length) {
this.datas.refStation = refStation[0];
}
const refSection = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlSection.Type)
.map((relation) => relation.getOtherGraphic<JlSection>(this).datas.id);
if (refSection.length) {
this.datas.refSection = refSection[0];
}
} }
loadRelations() { loadRelations() {
if (this.datas.refStation) { super.loadCommonRelations();
this.relationManage.addRelation(
this,
this.queryStore.queryById<GPStation>(this.datas.refStation),
);
}
if (this.datas.refSection) {
this.relationManage.addRelation(
this,
this.queryStore.queryById<JlSection>(this.datas.refSection),
);
}
} }
} }

View File

@ -2,6 +2,7 @@ import {
JlGraphic, JlGraphic,
VectorText, VectorText,
calculateMirrorPoint, calculateMirrorPoint,
distance2,
getRectangleCenter, getRectangleCenter,
} from 'jl-graphic'; } from 'jl-graphic';
import { Container, Graphics, Rectangle, Color, Point } from 'pixi.js'; import { Container, Graphics, Rectangle, Color, Point } from 'pixi.js';
@ -12,6 +13,8 @@ import {
LozengeConstsConfig, LozengeConstsConfig,
PlatformConstsConfig, PlatformConstsConfig,
} from './PlatformConfig'; } from './PlatformConfig';
import { JlSection } from '../Section/common/Section';
import { JlStation } from '../Station/JlStation';
//子元素--矩形 //子元素--矩形
class RectGraphic extends Container { class RectGraphic extends Container {
@ -276,4 +279,69 @@ export abstract class JlPlatform extends JlGraphic {
draw(): void { draw(): void {
this.rectGraphic.draw(this.platformConsts); this.rectGraphic.draw(this.platformConsts);
} }
buildCommonRelation() {
const stationas = this.queryStore.queryByType<JlStation>(JlStation.Type);
for (let i = 0; i < stationas.length; i++) {
const sP = stationas[i].localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
this.relationManage.addRelation(this, stationas[i]);
break;
}
}
const sections = this.queryStore.queryByType<JlSection>(JlSection.Type);
const minDistanceRefSections: JlSection[] = [];
sections.forEach((section) => {
const sP = section.localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
minDistanceRefSections.push(section);
}
});
if (minDistanceRefSections) {
const refSection = minDistanceRefSections.reduce((prev, cur) => {
return distance2(
prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())),
this.position,
) >
distance2(
cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())),
this.position,
)
? cur
: prev;
});
this.relationManage.deleteRelationOfGraphicAndOtherType(
this,
JlSection.Type,
);
this.relationManage.addRelation(this, refSection);
}
}
saveCommonRelations() {
const refStation = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlStation.Type)
.map((relation) => relation.getOtherGraphic<JlStation>(this).datas.id);
if (refStation.length) {
this.datas.refStation = refStation[0];
}
const refSection = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlSection.Type)
.map((relation) => relation.getOtherGraphic<JlSection>(this).datas.id);
if (refSection.length) {
this.datas.refSection = refSection[0];
}
}
loadCommonRelations() {
if (this.datas.refStation) {
this.relationManage.addRelation(
this,
this.queryStore.queryById<JlStation>(this.datas.refStation),
);
}
if (this.datas.refSection) {
this.relationManage.addRelation(
this,
this.queryStore.queryById<JlSection>(this.datas.refSection),
);
}
}
} }

View File

@ -59,15 +59,18 @@ export class THPlatform extends JlPlatform {
if (this.states.upSkipstop || this.states.downSkipstop) { if (this.states.upSkipstop || this.states.downSkipstop) {
this.rectGraphic.stateFillColor = THConsts.trainJump; this.rectGraphic.stateFillColor = THConsts.trainJump;
} }
/* const station = this.getGraphicApp().queryStore.queryByCodeAndType<Station>( const station =
this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, this.getGraphicApp().queryStore.queryByCodeAndType<THStation>(
Station.Type this.states.rtuId > 9
); */ ? '' + this.states.rtuId
: '0' + this.states.rtuId,
THStation.Type,
);
const doorGraphic = this.doorCodeLozenge.doorGraphic; const doorGraphic = this.doorCodeLozenge.doorGraphic;
doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen; doorGraphic.stateFillColor = THConsts.doorGraphic.doorGreen;
/* if (!!station?.states.ipRtuStusDown) { if (!!station?.states.ipRtuStusDown) {
doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue; doorGraphic.stateFillColor = THConsts.doorGraphic.doorBlue;
} */ if (this.states.psdCut) { } else if (this.states.psdCut) {
doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed; doorGraphic.stateFillColor = THConsts.doorGraphic.doorRed;
} }
super.draw(); super.draw();
@ -137,68 +140,12 @@ export class THPlatform extends JlPlatform {
} }
} }
buildRelation() { buildRelation() {
const stationas = this.queryStore.queryByType<THStation>(THStation.Type); super.buildCommonRelation();
for (let i = 0; i < stationas.length; i++) {
const sP = stationas[i].localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
this.relationManage.addRelation(this, stationas[i]);
break;
}
}
const sections = this.queryStore.queryByType<JlSection>(JlSection.Type);
const minDistanceRefSections: JlSection[] = [];
sections.forEach((section) => {
const sP = section.localBoundsToCanvasPoints();
if (this.x > sP[0].x && this.x < sP[1].x) {
minDistanceRefSections.push(section);
}
});
if (minDistanceRefSections) {
const refSection = minDistanceRefSections.reduce((prev, cur) => {
return distance2(
prev.localToCanvasPoint(getRectangleCenter(prev.getLocalBounds())),
this.position,
) >
distance2(
cur.localToCanvasPoint(getRectangleCenter(cur.getLocalBounds())),
this.position,
)
? cur
: prev;
});
this.relationManage.deleteRelationOfGraphicAndOtherType(
this,
JlSection.Type,
);
this.relationManage.addRelation(this, refSection);
}
} }
saveRelations() { saveRelations() {
const refStation = this.relationManage super.saveCommonRelations();
.getRelationsOfGraphicAndOtherType(this, THStation.Type)
.map((relation) => relation.getOtherGraphic<THStation>(this).datas.id);
if (refStation.length) {
this.datas.refStation = refStation[0];
}
const refSection = this.relationManage
.getRelationsOfGraphicAndOtherType(this, JlSection.Type)
.map((relation) => relation.getOtherGraphic<JlSection>(this).datas.id);
if (refSection.length) {
this.datas.refSection = refSection[0];
}
} }
loadRelations() { loadRelations() {
if (this.datas.refStation) { super.loadCommonRelations();
this.relationManage.addRelation(
this,
this.queryStore.queryById<THStation>(this.datas.refStation),
);
}
if (this.datas.refSection) {
this.relationManage.addRelation(
this,
this.queryStore.queryById<JlSection>(this.datas.refSection),
);
}
} }
} }