测试站台关联关系

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(); constructor();
get states(): IGPPlatformState; get states(): IGPPlatformState;
doRepaint(): void; 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 { 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() {
@ -12,6 +15,56 @@ class GPPlatform extends JlPlatform {
this.rectGraphic.stateFillColor = GPConsts.noTrainStop; this.rectGraphic.stateFillColor = GPConsts.noTrainStop;
super.draw(); 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 }; export { GPPlatform };

View File

@ -41,4 +41,7 @@ export declare class THPlatform extends JlPlatform {
constructor(); constructor();
get states(): ITHPlatformState; get states(): ITHPlatformState;
doRepaint(): void; 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 { 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';
class THPlatform extends JlPlatform { class THPlatform extends JlPlatform {
doorCodeLozenge; doorCodeLozenge;
@ -93,6 +96,56 @@ class THPlatform extends JlPlatform {
codeGraphic.stopTime.text = this.states.stopTime; 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 }; 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 { export declare class Section extends SectionBase {
constructor(); 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'; export { SectionTemplate } from '../common/Section.js';
const displayConfig = { const displayConfig = {
@ -6,7 +6,7 @@ const displayConfig = {
occupiedColor: '#f00', occupiedColor: '#f00',
lineWidth: 5, lineWidth: 5,
}; };
class Section extends Section$1 { class Section extends JlSection {
constructor() { constructor() {
super(); super();
this.setDisplayConfig(displayConfig); this.setDisplayConfig(displayConfig);

View File

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

View File

@ -18,13 +18,13 @@ const defaultDisplayConfig = {
occupiedColor: '#f00', occupiedColor: '#f00',
lineWidth: 5, lineWidth: 5,
}; };
let Section$1 = class Section extends JlGraphic { class JlSection extends JlGraphic {
static Type = 'Section'; static Type = 'Section';
lineGraphic; lineGraphic;
labelGraphic; labelGraphic;
displayConfig = defaultDisplayConfig; displayConfig = defaultDisplayConfig;
constructor() { constructor() {
super(Section.Type); super(JlSection.Type);
this.lineGraphic = new SectionGraphic(); this.lineGraphic = new SectionGraphic();
this.labelGraphic = new VectorText(''); this.labelGraphic = new VectorText('');
this.labelGraphic.setVectorFontSize(14); this.labelGraphic.setVectorFontSize(14);
@ -96,7 +96,7 @@ let Section$1 = class Section extends JlGraphic {
const relation = this.relationManage const relation = this.relationManage
.getRelationsOfGraphic(this) .getRelationsOfGraphic(this)
.find((relation) => relation.getRelationParam(this).getParam() === port && .find((relation) => relation.getRelationParam(this).getParam() === port &&
(relation.getOtherGraphic(this) instanceof Section || (relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout)); relation.getOtherGraphic(this) instanceof Turnout));
if (!relation) { if (!relation) {
return; return;
@ -146,9 +146,9 @@ let Section$1 = class Section extends JlGraphic {
* *
*/ */
buildRelation() { buildRelation() {
this.relationManage.deleteRelationOfGraphicAndOtherType(this, Section.Type); this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
if (this.datas.sectionType === SectionType.Physical) { 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) if (section.id === this.id)
return; return;
let param = []; let param = [];
@ -174,7 +174,7 @@ let Section$1 = class Section extends JlGraphic {
const paRelation = this.relationManage const paRelation = this.relationManage
.getRelationsOfGraphic(this) .getRelationsOfGraphic(this)
.find((relation) => relation.getRelationParam(this).param === DevicePort.A && .find((relation) => relation.getRelationParam(this).param === DevicePort.A &&
(relation.getOtherGraphic(this) instanceof Section || (relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout)); relation.getOtherGraphic(this) instanceof Turnout));
const paDevice = paRelation?.getOtherGraphic(this); const paDevice = paRelation?.getOtherGraphic(this);
if (paDevice) { if (paDevice) {
@ -186,7 +186,7 @@ let Section$1 = class Section extends JlGraphic {
const pbRelation = this.relationManage const pbRelation = this.relationManage
.getRelationsOfGraphic(this) .getRelationsOfGraphic(this)
.find((relation) => relation.getRelationParam(this).param === DevicePort.B && .find((relation) => relation.getRelationParam(this).param === DevicePort.B &&
(relation.getOtherGraphic(this) instanceof Section || (relation.getOtherGraphic(this) instanceof JlSection ||
relation.getOtherGraphic(this) instanceof Turnout)); relation.getOtherGraphic(this) instanceof Turnout));
const pbDevice = pbRelation?.getOtherGraphic(this); const pbDevice = pbRelation?.getOtherGraphic(this);
if (pbDevice) { if (pbDevice) {
@ -217,22 +217,22 @@ let Section$1 = class Section extends JlGraphic {
} }
} }
} }
}; }
class SectionTemplate extends JlGraphicTemplate { class SectionTemplate extends JlGraphicTemplate {
isCurve = false; isCurve = false;
segmentsCount = 10; segmentsCount = 10;
constructor(dataTemplate, stateTemplate) { constructor(dataTemplate, stateTemplate) {
super(Section$1.Type, { super(JlSection.Type, {
dataTemplate, dataTemplate,
stateTemplate, stateTemplate,
}); });
} }
new() { new() {
const section = new Section$1(); const section = new JlSection();
section.loadData(this.datas); section.loadData(this.datas);
section.loadState(this.states); section.loadState(this.states);
return section; 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 { GPConsts } from './PlatformConfig';
import { JlPlatform } from './JlPlatform'; import { JlPlatform } from './JlPlatform';
import { GPStation } from '../Station/GPStation';
import { JlSection } from '../Section/common/Section';
export interface IGPPlatformState extends GraphicState { export interface IGPPlatformState extends GraphicState {
id?: number; id?: number;
@ -17,4 +19,69 @@ export class GPPlatform extends JlPlatform {
this.rectGraphic.stateFillColor = GPConsts.noTrainStop; this.rectGraphic.stateFillColor = GPConsts.noTrainStop;
super.draw(); 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 { THConsts } from './PlatformConfig';
import { JlPlatform, DoorCodeLozenge } from './JlPlatform'; import { JlPlatform, DoorCodeLozenge } from './JlPlatform';
import { JlSection } from '../Section/common/Section';
import { THStation } from '../Station/THStation';
export interface ITHPlatformState extends GraphicState { export interface ITHPlatformState extends GraphicState {
get emergstop(): boolean; //紧急关闭 get emergstop(): boolean; //紧急关闭
@ -134,4 +136,69 @@ export class THPlatform extends JlPlatform {
codeGraphic.stopTime.text = this.states.stopTime; 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 { import {
Section as SectionBase, JlSection as SectionBase,
SectionDisplayConfig, SectionDisplayConfig,
} from '../common/Section'; } from '../common/Section';

View File

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