道岔代码备用
This commit is contained in:
parent
a616f4a5da
commit
69cd136393
|
@ -16,7 +16,7 @@
|
||||||
"test": "node ./test.cjs"
|
"test": "node ./test.cjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"jl-graphic": "git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#v0.1.3"
|
"jl-graphic": "git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#v0.1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-alias": "^5.1.0",
|
"@rollup/plugin-alias": "^5.1.0",
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {
|
||||||
import { IPointData } from 'pixi.js';
|
import { IPointData } from 'pixi.js';
|
||||||
import { SectionGraphic } from './SectionGraphic';
|
import { SectionGraphic } from './SectionGraphic';
|
||||||
import { DevicePort, DeviceType, IRelatedRef } from 'common/common';
|
import { DevicePort, DeviceType, IRelatedRef } from 'common/common';
|
||||||
import { Turnout } from 'src/packages/Turnout/Turnout';
|
import { JlTurnout } from 'src/packages/Turnout/common/JlTurnout';
|
||||||
import { AxleCounting } from 'src/packages/AxleCounting/AxleCounting';
|
import { AxleCounting } from 'src/packages/AxleCounting/AxleCounting';
|
||||||
|
|
||||||
const tolerance = 0.01;
|
const tolerance = 0.01;
|
||||||
|
@ -151,13 +151,13 @@ export class JlSection extends JlGraphic {
|
||||||
(relation) =>
|
(relation) =>
|
||||||
relation.getRelationParam(this).getParam<DevicePort>() === port &&
|
relation.getRelationParam(this).getParam<DevicePort>() === port &&
|
||||||
(relation.getOtherGraphic(this) instanceof JlSection ||
|
(relation.getOtherGraphic(this) instanceof JlSection ||
|
||||||
relation.getOtherGraphic(this) instanceof Turnout),
|
relation.getOtherGraphic(this) instanceof JlTurnout),
|
||||||
);
|
);
|
||||||
if (!relation) {
|
if (!relation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
g: relation?.getOtherGraphic(this) as JlSection | Turnout,
|
g: relation?.getOtherGraphic(this) as JlSection | JlTurnout,
|
||||||
port: relation?.getOtherRelationParam(this).getParam<DevicePort>(),
|
port: relation?.getOtherRelationParam(this).getParam<DevicePort>(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -217,52 +217,57 @@ export class JlSection extends JlGraphic {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buildRelation() {
|
buildRelation() {
|
||||||
this.relationManage.deleteRelationOfGraphicAndOtherType(this, JlSection.Type);
|
this.relationManage.deleteRelationOfGraphicAndOtherType(
|
||||||
|
this,
|
||||||
|
JlSection.Type,
|
||||||
|
);
|
||||||
|
|
||||||
if (this.datas.sectionType === SectionType.Physical) {
|
if (this.datas.sectionType === SectionType.Physical) {
|
||||||
this.queryStore.queryByType<JlSection>(JlSection.Type).forEach((section) => {
|
this.queryStore
|
||||||
if (section.id === this.id) return;
|
.queryByType<JlSection>(JlSection.Type)
|
||||||
|
.forEach((section) => {
|
||||||
|
if (section.id === this.id) return;
|
||||||
|
|
||||||
let param: DevicePort[] = [];
|
let param: DevicePort[] = [];
|
||||||
if (
|
if (
|
||||||
distance2(
|
distance2(
|
||||||
this.localToCanvasPoint(this.getStartPoint()),
|
this.localToCanvasPoint(this.getStartPoint()),
|
||||||
section.localToCanvasPoint(section.getStartPoint()),
|
section.localToCanvasPoint(section.getStartPoint()),
|
||||||
) <= tolerance
|
) <= tolerance
|
||||||
) {
|
) {
|
||||||
param = [DevicePort.A, DevicePort.A];
|
param = [DevicePort.A, DevicePort.A];
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
distance2(
|
distance2(
|
||||||
this.localToCanvasPoint(this.getEndPoint()),
|
this.localToCanvasPoint(this.getEndPoint()),
|
||||||
section.localToCanvasPoint(section.getStartPoint()),
|
section.localToCanvasPoint(section.getStartPoint()),
|
||||||
) <= tolerance
|
) <= tolerance
|
||||||
) {
|
) {
|
||||||
param = [DevicePort.B, DevicePort.A];
|
param = [DevicePort.B, DevicePort.A];
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
distance2(
|
distance2(
|
||||||
this.localToCanvasPoint(this.getStartPoint()),
|
this.localToCanvasPoint(this.getStartPoint()),
|
||||||
section.localToCanvasPoint(section.getEndPoint()),
|
section.localToCanvasPoint(section.getEndPoint()),
|
||||||
) <= tolerance
|
) <= tolerance
|
||||||
) {
|
) {
|
||||||
param = [DevicePort.A, DevicePort.B];
|
param = [DevicePort.A, DevicePort.B];
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
distance2(
|
distance2(
|
||||||
this.localToCanvasPoint(this.getEndPoint()),
|
this.localToCanvasPoint(this.getEndPoint()),
|
||||||
section.localToCanvasPoint(section.getEndPoint()),
|
section.localToCanvasPoint(section.getEndPoint()),
|
||||||
) <= tolerance
|
) <= tolerance
|
||||||
) {
|
) {
|
||||||
param = [DevicePort.B, DevicePort.B];
|
param = [DevicePort.B, DevicePort.B];
|
||||||
}
|
}
|
||||||
if (param.length) {
|
if (param.length) {
|
||||||
this.relationManage.addRelation(
|
this.relationManage.addRelation(
|
||||||
new GraphicRelationParam(this, param[0]),
|
new GraphicRelationParam(this, param[0]),
|
||||||
new GraphicRelationParam(section, param[1]),
|
new GraphicRelationParam(section, param[1]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +278,9 @@ export class JlSection extends JlGraphic {
|
||||||
(relation) =>
|
(relation) =>
|
||||||
relation.getRelationParam(this).param === DevicePort.A &&
|
relation.getRelationParam(this).param === DevicePort.A &&
|
||||||
(relation.getOtherGraphic(this) instanceof JlSection ||
|
(relation.getOtherGraphic(this) instanceof JlSection ||
|
||||||
relation.getOtherGraphic(this) instanceof Turnout),
|
relation.getOtherGraphic(this) instanceof JlTurnout),
|
||||||
);
|
);
|
||||||
const paDevice = paRelation?.getOtherGraphic<JlSection | Turnout>(this);
|
const paDevice = paRelation?.getOtherGraphic<JlSection | JlTurnout>(this);
|
||||||
if (paDevice) {
|
if (paDevice) {
|
||||||
this.datas.paRef = IRelatedRef.create(
|
this.datas.paRef = IRelatedRef.create(
|
||||||
paDevice.type,
|
paDevice.type,
|
||||||
|
@ -291,9 +296,9 @@ export class JlSection extends JlGraphic {
|
||||||
(relation) =>
|
(relation) =>
|
||||||
relation.getRelationParam(this).param === DevicePort.B &&
|
relation.getRelationParam(this).param === DevicePort.B &&
|
||||||
(relation.getOtherGraphic(this) instanceof JlSection ||
|
(relation.getOtherGraphic(this) instanceof JlSection ||
|
||||||
relation.getOtherGraphic(this) instanceof Turnout),
|
relation.getOtherGraphic(this) instanceof JlTurnout),
|
||||||
);
|
);
|
||||||
const pbDevice = pbRelation?.getOtherGraphic<JlSection | Turnout>(this);
|
const pbDevice = pbRelation?.getOtherGraphic<JlSection | JlTurnout>(this);
|
||||||
if (pbDevice) {
|
if (pbDevice) {
|
||||||
this.datas.pbRef = IRelatedRef.create(
|
this.datas.pbRef = IRelatedRef.create(
|
||||||
pbDevice.type,
|
pbDevice.type,
|
||||||
|
|
|
@ -43,7 +43,7 @@ import {
|
||||||
type IPointData,
|
type IPointData,
|
||||||
type DisplayObject,
|
type DisplayObject,
|
||||||
} from 'pixi.js';
|
} from 'pixi.js';
|
||||||
import { Turnout } from 'src/packages/Turnout/Turnout';
|
import { JlTurnout } from 'src/packages/Turnout/common/JlTurnout';
|
||||||
import { AxleCounting } from 'src/packages/AxleCounting/AxleCounting';
|
import { AxleCounting } from 'src/packages/AxleCounting/AxleCounting';
|
||||||
import { DevicePort } from 'common/common';
|
import { DevicePort } from 'common/common';
|
||||||
import { Section } from '../GPSection';
|
import { Section } from '../GPSection';
|
||||||
|
@ -348,7 +348,7 @@ function buildAbsorbablePositions(section: Section): AbsorbablePosition[] {
|
||||||
aps.push(xs, ys, xe, ye);
|
aps.push(xs, ys, xe, ye);
|
||||||
});
|
});
|
||||||
|
|
||||||
const turnouts = section.queryStore.queryByType<Turnout>(Turnout.Type);
|
const turnouts = section.queryStore.queryByType<JlTurnout>(JlTurnout.Type);
|
||||||
turnouts.forEach((turnout) => {
|
turnouts.forEach((turnout) => {
|
||||||
turnout.getPortPoints().forEach((points) => {
|
turnout.getPortPoints().forEach((points) => {
|
||||||
turnout.localToCanvasPoints(...points).forEach((p) => {
|
turnout.localToCanvasPoints(...points).forEach((p) => {
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { JlTurnout } from './common/JlTurnout';
|
||||||
|
|
||||||
|
export class Turnout extends JlTurnout {
|
||||||
|
static Type = 'Turnout';
|
||||||
|
doRepaint(): void {
|
||||||
|
super.draw();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
import { DevicePort, IRelatedRef, KilometerSystem } from 'common/common';
|
|
||||||
import { GraphicData, JlGraphic } from 'jl-graphic';
|
|
||||||
import { IPointData } from 'pixi.js';
|
|
||||||
|
|
||||||
export enum SwitchMachineType {
|
|
||||||
Unknown = 0,
|
|
||||||
ZDJ9_Single = 1,
|
|
||||||
ZDJ9_Double = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ITurnoutData extends GraphicData {
|
|
||||||
code: string;
|
|
||||||
pointA: IPointData[];
|
|
||||||
pointB: IPointData[];
|
|
||||||
pointC: IPointData[];
|
|
||||||
paRef?: IRelatedRef;
|
|
||||||
pbRef?: IRelatedRef;
|
|
||||||
pcRef?: IRelatedRef;
|
|
||||||
kilometerSystem: KilometerSystem;
|
|
||||||
paTrackSectionId?: number;
|
|
||||||
pbTrackSectionId?: number;
|
|
||||||
pcTrackSectionId?: number;
|
|
||||||
switchMachineType?: SwitchMachineType;
|
|
||||||
centralizedStations?: number[];
|
|
||||||
clone(): ITurnoutData;
|
|
||||||
copyFrom(data: ITurnoutData): void;
|
|
||||||
eq(other: ITurnoutData): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Turnout extends JlGraphic {
|
|
||||||
static Type = 'Turnout';
|
|
||||||
doRepaint(): void {
|
|
||||||
console.log(111);
|
|
||||||
}
|
|
||||||
get datas(): ITurnoutData {
|
|
||||||
return this.getDatas<ITurnoutData>();
|
|
||||||
}
|
|
||||||
|
|
||||||
getGraphicOfPort(port: DevicePort) {
|
|
||||||
return this.relationManage
|
|
||||||
.getRelationsOfGraphic(this)
|
|
||||||
.filter(
|
|
||||||
(relation) =>
|
|
||||||
relation.getRelationParam(this).getParam<DevicePort>() === port,
|
|
||||||
)
|
|
||||||
.map((relation) => {
|
|
||||||
return relation.getOtherGraphic(this);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getPortPoints() {
|
|
||||||
return [this.datas.pointA, this.datas.pointB, this.datas.pointC];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,130 @@
|
||||||
|
import { JlGraphic, VectorText } from 'jl-graphic';
|
||||||
|
import { IPointData, Graphics } from 'pixi.js';
|
||||||
|
import { DevicePort } from 'common/common';
|
||||||
|
import { ITurnoutData, TurnoutConstsConfig } from './TurnoutConfig';
|
||||||
|
|
||||||
|
export function getForkPoint(r: number, p: IPointData): IPointData {
|
||||||
|
if (r === 0) return { x: 0, y: 0 };
|
||||||
|
const len = Math.sqrt((-p.x) ** 2 + (-p.y) ** 2);
|
||||||
|
const scale = r / len;
|
||||||
|
return { x: scale * p.x, y: scale * p.y };
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TurnoutSection extends Graphics {
|
||||||
|
turnoutConsts: TurnoutConstsConfig;
|
||||||
|
turnout: JlTurnout;
|
||||||
|
port: DevicePort;
|
||||||
|
stateFillColor?: string;
|
||||||
|
constructor(
|
||||||
|
turnout: JlTurnout,
|
||||||
|
port: DevicePort,
|
||||||
|
turnoutConsts: TurnoutConstsConfig,
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this.turnoutConsts = turnoutConsts;
|
||||||
|
this.turnout = turnout;
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint() {
|
||||||
|
let pList: IPointData[] = [];
|
||||||
|
switch (this.port) {
|
||||||
|
case DevicePort.A:
|
||||||
|
pList = this.turnout.datas.pointA;
|
||||||
|
break;
|
||||||
|
case DevicePort.B:
|
||||||
|
pList = this.turnout.datas.pointB;
|
||||||
|
break;
|
||||||
|
case DevicePort.C:
|
||||||
|
pList = this.turnout.datas.pointC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const gap = this.port === DevicePort.A ? 0 : this.turnoutConsts.forkLenth;
|
||||||
|
const fillColor = this.stateFillColor || this.turnoutConsts.lineColor;
|
||||||
|
const start = getForkPoint(gap, pList[0]);
|
||||||
|
this.clear()
|
||||||
|
.lineStyle(this.turnoutConsts.lineWidth, fillColor)
|
||||||
|
.moveTo(start.x, start.y);
|
||||||
|
pList.forEach((p) => {
|
||||||
|
const { x, y } = p;
|
||||||
|
this.lineTo(x, y);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ForkGraphic extends Graphics {
|
||||||
|
turnoutConsts: TurnoutConstsConfig;
|
||||||
|
turnout: JlTurnout;
|
||||||
|
stateFillColor?: string;
|
||||||
|
constructor(turnout: JlTurnout, turnoutConsts: TurnoutConstsConfig) {
|
||||||
|
super();
|
||||||
|
this.turnoutConsts = turnoutConsts;
|
||||||
|
this.turnout = turnout;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint(p: IPointData) {
|
||||||
|
const fillColor = this.stateFillColor || this.turnoutConsts.lineColor;
|
||||||
|
const target = getForkPoint(this.turnoutConsts.forkLenth, p);
|
||||||
|
this.clear()
|
||||||
|
.lineStyle(this.turnoutConsts.lineWidth, fillColor)
|
||||||
|
.moveTo(0, 0)
|
||||||
|
.lineTo(target.x, target.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class JlTurnout extends JlGraphic {
|
||||||
|
static Type = 'Turnout';
|
||||||
|
graphics: {
|
||||||
|
fork: ForkGraphic;
|
||||||
|
sections: [TurnoutSection, TurnoutSection, TurnoutSection];
|
||||||
|
label: VectorText;
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(turnoutConsts: TurnoutConstsConfig) {
|
||||||
|
super(JlTurnout.Type);
|
||||||
|
this.name = 'turnout';
|
||||||
|
this.graphics = {
|
||||||
|
fork: new ForkGraphic(this, turnoutConsts),
|
||||||
|
sections: [
|
||||||
|
new TurnoutSection(this, DevicePort.A, turnoutConsts),
|
||||||
|
new TurnoutSection(this, DevicePort.B, turnoutConsts),
|
||||||
|
new TurnoutSection(this, DevicePort.C, turnoutConsts),
|
||||||
|
],
|
||||||
|
label: new VectorText(),
|
||||||
|
};
|
||||||
|
this.addChild(this.graphics.fork);
|
||||||
|
this.addChild(this.graphics.sections[0]);
|
||||||
|
this.addChild(this.graphics.sections[1]);
|
||||||
|
this.addChild(this.graphics.sections[2]);
|
||||||
|
this.graphics.label.anchor.set(0.5);
|
||||||
|
this.graphics.label.style.fill = '#0f0';
|
||||||
|
this.graphics.label.setVectorFontSize(turnoutConsts.labelFontSize);
|
||||||
|
this.graphics.label.position.set(20, 20);
|
||||||
|
this.graphics.label.transformSave = true;
|
||||||
|
this.graphics.label.name = 'label';
|
||||||
|
this.addChild(this.graphics.label);
|
||||||
|
}
|
||||||
|
draw(): void {
|
||||||
|
this.graphics.label.text = this.datas.code;
|
||||||
|
this.graphics.sections.forEach((sectionGraphic) => sectionGraphic.paint());
|
||||||
|
}
|
||||||
|
get datas(): ITurnoutData {
|
||||||
|
return this.getDatas<ITurnoutData>();
|
||||||
|
}
|
||||||
|
|
||||||
|
getPortPoints() {
|
||||||
|
return [this.datas.pointA, this.datas.pointB, this.datas.pointC];
|
||||||
|
}
|
||||||
|
|
||||||
|
getGraphicOfPort(port: DevicePort) {
|
||||||
|
return this.relationManage
|
||||||
|
.getRelationsOfGraphic(this)
|
||||||
|
.filter(
|
||||||
|
(relation) =>
|
||||||
|
relation.getRelationParam(this).getParam<DevicePort>() === port,
|
||||||
|
)
|
||||||
|
.map((relation) => {
|
||||||
|
return relation.getOtherGraphic(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
import { IRelatedRef, KilometerSystem } from 'common/common';
|
||||||
|
import { GraphicData } from 'jl-graphic';
|
||||||
|
import { IPointData } from 'pixi.js';
|
||||||
|
|
||||||
|
export interface TurnoutConstsConfig {
|
||||||
|
lineColor: string;
|
||||||
|
occupiedColor: string;
|
||||||
|
lineWidth: number;
|
||||||
|
forkLenth: number;
|
||||||
|
labelFontSize: number;
|
||||||
|
normalLabelColor: string;
|
||||||
|
reverseLabelColor: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GPConsts = {
|
||||||
|
lineColor: '#5578b6',
|
||||||
|
occupiedColor: '#f00',
|
||||||
|
lineWidth: 5,
|
||||||
|
forkLenth: 20,
|
||||||
|
labelFontSize: 12,
|
||||||
|
normalLabelColor: '#0f0',
|
||||||
|
reverseLabelColor: '#ff0',
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum SwitchMachineType {
|
||||||
|
Unknown = 0,
|
||||||
|
ZDJ9_Single = 1,
|
||||||
|
ZDJ9_Double = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ITurnoutData extends GraphicData {
|
||||||
|
code: string;
|
||||||
|
pointA: IPointData[]; //A端点列表(从岔心向外)
|
||||||
|
pointB: IPointData[];
|
||||||
|
pointC: IPointData[];
|
||||||
|
paRef?: IRelatedRef; // 道岔A端关联的设备
|
||||||
|
pbRef?: IRelatedRef;
|
||||||
|
pcRef?: IRelatedRef;
|
||||||
|
kilometerSystem: KilometerSystem; // 道岔公里标
|
||||||
|
paTrackSectionId?: number; // A端轨道区段id
|
||||||
|
pbTrackSectionId?: number;
|
||||||
|
pcTrackSectionId?: number;
|
||||||
|
switchMachineType?: SwitchMachineType; // 转辙机类型
|
||||||
|
centralizedStations?: number[]; // 集中站Id列表--北京
|
||||||
|
clone(): ITurnoutData;
|
||||||
|
copyFrom(data: ITurnoutData): void;
|
||||||
|
eq(other: ITurnoutData): boolean;
|
||||||
|
}
|
|
@ -1182,9 +1182,9 @@ ismobilejs@^1.1.0:
|
||||||
resolved "https://registry.npmmirror.com/ismobilejs/-/ismobilejs-1.1.1.tgz#c56ca0ae8e52b24ca0f22ba5ef3215a2ddbbaa0e"
|
resolved "https://registry.npmmirror.com/ismobilejs/-/ismobilejs-1.1.1.tgz#c56ca0ae8e52b24ca0f22ba5ef3215a2ddbbaa0e"
|
||||||
integrity sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw==
|
integrity sha512-VaFW53yt8QO61k2WJui0dHf4SlL8lxBofUuUmwBo0ljPk0Drz2TiuDW4jo3wDcv41qy/SxrJ+VAzJ/qYqsmzRw==
|
||||||
|
|
||||||
"jl-graphic@git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#v0.1.3":
|
"jl-graphic@git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#v0.1.7":
|
||||||
version "0.1.3"
|
version "0.1.6"
|
||||||
resolved "git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#100ddafc75ffa2fc646ad26359682e0f083511e3"
|
resolved "git+https://git.code.tencent.com/jl-framework/graphic-pixi.git#9a4a307efa10f55708f5f1d518f815882df567a3"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@pixi/graphics-extras" "^7.3.2"
|
"@pixi/graphics-extras" "^7.3.2"
|
||||||
"@pixi/utils" "^7.3.2"
|
"@pixi/utils" "^7.3.2"
|
||||||
|
|
Loading…
Reference in New Issue