测试站台关联关系

This commit is contained in:
joylink_zhaoerwei 2024-01-10 17:25:39 +08:00
parent a08ef74550
commit fa5c16a337
12 changed files with 282 additions and 36 deletions

View File

@ -7,4 +7,7 @@ export declare class GPPlatform extends JlPlatform {
constructor();
get states(): IGPPlatformState;
doRepaint(): void;
buildRelation(): void;
saveRelations(): void;
loadRelations(): void;
}

View File

@ -1,5 +1,8 @@
import { distance2, getRectangleCenter } from 'jl-graphic';
import { GPConsts } from './PlatformConfig.js';
import { JlPlatform } from './JlPlatform.js';
import { GPStation } from '../Station/GPStation.js';
import { JlSection } from '../Section/common/Section.js';
class GPPlatform extends JlPlatform {
constructor() {
@ -12,6 +15,56 @@ class GPPlatform extends JlPlatform {
this.rectGraphic.stateFillColor = GPConsts.noTrainStop;
super.draw();
}
buildRelation() {
const stationas = this.queryStore.queryByType(GPStation.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);
}
}
saveRelations() {
const refStation = this.relationManage
.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() {
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 { GPPlatform };

View File

@ -41,4 +41,7 @@ export declare class THPlatform extends JlPlatform {
constructor();
get states(): ITHPlatformState;
doRepaint(): void;
buildRelation(): void;
saveRelations(): void;
loadRelations(): void;
}

View File

@ -1,5 +1,8 @@
import { distance2, getRectangleCenter } from 'jl-graphic';
import { THConsts } from './PlatformConfig.js';
import { JlPlatform, DoorCodeLozenge } from './JlPlatform.js';
import { JlSection } from '../Section/common/Section.js';
import { THStation } from '../Station/THStation.js';
class THPlatform extends JlPlatform {
doorCodeLozenge;
@ -93,6 +96,56 @@ class THPlatform extends JlPlatform {
codeGraphic.stopTime.text = this.states.stopTime;
}
}
buildRelation() {
const stationas = this.queryStore.queryByType(THStation.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);
}
}
saveRelations() {
const refStation = this.relationManage
.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() {
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 { THPlatform };

View File

@ -1,4 +1,4 @@
import { Section as SectionBase } from '../common/Section';
import { JlSection as SectionBase } from '../common/Section';
export declare class Section extends SectionBase {
constructor();
}

View File

@ -1,4 +1,4 @@
import { Section as Section$1 } from '../common/Section.js';
import { JlSection } from '../common/Section.js';
export { SectionTemplate } from '../common/Section.js';
const displayConfig = {
@ -6,7 +6,7 @@ const displayConfig = {
occupiedColor: '#f00',
lineWidth: 5,
};
class Section extends Section$1 {
class Section extends JlSection {
constructor() {
super();
this.setDisplayConfig(displayConfig);

View File

@ -35,7 +35,7 @@ export interface SectionDisplayConfig {
lineWidth: number;
}
export declare const defaultDisplayConfig: SectionDisplayConfig;
export declare class Section extends JlGraphic {
export declare class JlSection extends JlGraphic {
static Type: string;
lineGraphic: SectionGraphic;
labelGraphic: VectorText;
@ -51,7 +51,7 @@ export declare class Section extends JlGraphic {
get linePoints(): IPointData[];
set linePoints(points: IPointData[]);
getConnectElement(port: DevicePort): {
g: Turnout | Section;
g: Turnout | JlSection;
port: DevicePort;
} | undefined;
/** 获取拆分逻辑区段数据 */
@ -65,9 +65,9 @@ export declare class Section extends JlGraphic {
saveRelations(): void;
loadRelations(): void;
}
export declare class SectionTemplate extends JlGraphicTemplate<Section> {
export declare class SectionTemplate extends JlGraphicTemplate<JlSection> {
isCurve: boolean;
segmentsCount: number;
constructor(dataTemplate: ISectionData, stateTemplate?: ISectionState);
new(): Section;
new(): JlSection;
}

View File

@ -18,13 +18,13 @@ const defaultDisplayConfig = {
occupiedColor: '#f00',
lineWidth: 5,
};
let Section$1 = class Section extends JlGraphic {
class JlSection extends JlGraphic {
static Type = 'Section';
lineGraphic;
labelGraphic;
displayConfig = defaultDisplayConfig;
constructor() {
super(Section.Type);
super(JlSection.Type);
this.lineGraphic = new SectionGraphic();
this.labelGraphic = new VectorText('');
this.labelGraphic.setVectorFontSize(14);
@ -96,7 +96,7 @@ let Section$1 = class Section extends JlGraphic {
const relation = this.relationManage
.getRelationsOfGraphic(this)
.find((relation) => relation.getRelationParam(this).getParam() === port &&
(relation.getOtherGraphic(this) instanceof Section ||
(relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout));
if (!relation) {
return;
@ -146,9 +146,9 @@ let Section$1 = class Section extends JlGraphic {
*
*/
buildRelation() {
this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type);
this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
if (this.datas.sectionType === SectionType.Physical) {
this.queryStore.queryByType(Section.Type).forEach((section) => {
this.queryStore.queryByType(JlSection.Type).forEach((section) => {
if (section.id === this.id)
return;
let param = [];
@ -174,7 +174,7 @@ let Section$1 = class Section extends JlGraphic {
const paRelation = this.relationManage
.getRelationsOfGraphic(this)
.find((relation) => relation.getRelationParam(this).param === DevicePort.A &&
(relation.getOtherGraphic(this) instanceof Section ||
(relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout));
const paDevice = paRelation?.getOtherGraphic(this);
if (paDevice) {
@ -186,7 +186,7 @@ let Section$1 = class Section extends JlGraphic {
const pbRelation = this.relationManage
.getRelationsOfGraphic(this)
.find((relation) => relation.getRelationParam(this).param === DevicePort.B &&
(relation.getOtherGraphic(this) instanceof Section ||
(relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout));
const pbDevice = pbRelation?.getOtherGraphic(this);
if (pbDevice) {
@ -217,22 +217,22 @@ let Section$1 = class Section extends JlGraphic {
}
}
}
};
}
class SectionTemplate extends JlGraphicTemplate {
isCurve = false;
segmentsCount = 10;
constructor(dataTemplate, stateTemplate) {
super(Section$1.Type, {
super(JlSection.Type, {
dataTemplate,
stateTemplate,
});
}
new() {
const section = new Section$1();
const section = new JlSection();
section.loadData(this.datas);
section.loadState(this.states);
return section;
}
}
export { Section$1 as Section, SectionTemplate, SectionType, defaultDisplayConfig };
export { JlSection, SectionTemplate, SectionType, defaultDisplayConfig };

View File

@ -1,6 +1,8 @@
import { GraphicState } from 'jl-graphic';
import { GraphicState, distance2, getRectangleCenter } from 'jl-graphic';
import { GPConsts } from './PlatformConfig';
import { JlPlatform } from './JlPlatform';
import { GPStation } from '../Station/GPStation';
import { JlSection } from '../Section/common/Section';
export interface IGPPlatformState extends GraphicState {
id?: number;
@ -17,4 +19,69 @@ export class GPPlatform extends JlPlatform {
this.rectGraphic.stateFillColor = GPConsts.noTrainStop;
super.draw();
}
buildRelation() {
const stationas = this.queryStore.queryByType<GPStation>(GPStation.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);
}
}
saveRelations() {
const refStation = this.relationManage
.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() {
if (this.datas.refStation) {
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

@ -1,6 +1,8 @@
import { GraphicState } from 'jl-graphic';
import { GraphicState, distance2, getRectangleCenter } from 'jl-graphic';
import { THConsts } from './PlatformConfig';
import { JlPlatform, DoorCodeLozenge } from './JlPlatform';
import { JlSection } from '../Section/common/Section';
import { THStation } from '../Station/THStation';
export interface ITHPlatformState extends GraphicState {
get emergstop(): boolean; //紧急关闭
@ -134,4 +136,69 @@ export class THPlatform extends JlPlatform {
codeGraphic.stopTime.text = this.states.stopTime;
}
}
buildRelation() {
const stationas = this.queryStore.queryByType<THStation>(THStation.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);
}
}
saveRelations() {
const refStation = this.relationManage
.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() {
if (this.datas.refStation) {
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),
);
}
}
}

View File

@ -1,5 +1,5 @@
import {
Section as SectionBase,
JlSection as SectionBase,
SectionDisplayConfig,
} from '../common/Section';

View File

@ -59,14 +59,14 @@ export const defaultDisplayConfig: SectionDisplayConfig = {
lineWidth: 5,
};
export class Section extends JlGraphic {
export class JlSection extends JlGraphic {
static Type = 'Section';
lineGraphic: SectionGraphic;
labelGraphic: VectorText;
displayConfig = defaultDisplayConfig;
constructor() {
super(Section.Type);
super(JlSection.Type);
this.lineGraphic = new SectionGraphic();
this.labelGraphic = new VectorText('');
this.labelGraphic.setVectorFontSize(14);
@ -150,14 +150,14 @@ export class Section extends JlGraphic {
.find(
(relation) =>
relation.getRelationParam(this).getParam<DevicePort>() === port &&
(relation.getOtherGraphic(this) instanceof Section ||
(relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout),
);
if (!relation) {
return;
}
return {
g: relation?.getOtherGraphic(this) as Section | Turnout,
g: relation?.getOtherGraphic(this) as JlSection | Turnout,
port: relation?.getOtherRelationParam(this).getParam<DevicePort>(),
};
}
@ -217,10 +217,10 @@ export class Section extends JlGraphic {
*/
buildRelation() {
this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type);
this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
if (this.datas.sectionType === SectionType.Physical) {
this.queryStore.queryByType<Section>(Section.Type).forEach((section) => {
this.queryStore.queryByType<JlSection>(JlSection.Type).forEach((section) => {
if (section.id === this.id) return;
let param: DevicePort[] = [];
@ -272,10 +272,10 @@ export class Section extends JlGraphic {
.find(
(relation) =>
relation.getRelationParam(this).param === DevicePort.A &&
(relation.getOtherGraphic(this) instanceof Section ||
(relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout),
);
const paDevice = paRelation?.getOtherGraphic<Section | Turnout>(this);
const paDevice = paRelation?.getOtherGraphic<JlSection | Turnout>(this);
if (paDevice) {
this.datas.paRef = IRelatedRef.create(
paDevice.type,
@ -290,10 +290,10 @@ export class Section extends JlGraphic {
.find(
(relation) =>
relation.getRelationParam(this).param === DevicePort.B &&
(relation.getOtherGraphic(this) instanceof Section ||
(relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout),
);
const pbDevice = pbRelation?.getOtherGraphic<Section | Turnout>(this);
const pbDevice = pbRelation?.getOtherGraphic<JlSection | Turnout>(this);
if (pbDevice) {
this.datas.pbRef = IRelatedRef.create(
pbDevice.type,
@ -330,7 +330,7 @@ export class Section extends JlGraphic {
if (this.datas.trackSectionId) {
this.relationManage.addRelation(
this,
this.queryStore.queryById<Section>(this.datas.trackSectionId),
this.queryStore.queryById<JlSection>(this.datas.trackSectionId),
);
}
if (this.datas.sectionType === SectionType.TurnoutPhysical) {
@ -346,17 +346,17 @@ export class Section extends JlGraphic {
}
}
export class SectionTemplate extends JlGraphicTemplate<Section> {
export class SectionTemplate extends JlGraphicTemplate<JlSection> {
isCurve = false;
segmentsCount = 10;
constructor(dataTemplate: ISectionData, stateTemplate?: ISectionState) {
super(Section.Type, {
super(JlSection.Type, {
dataTemplate,
stateTemplate,
});
}
new(): Section {
const section = new Section();
new(): JlSection {
const section = new JlSection();
section.loadData(this.datas);
section.loadState(this.states);
return section;