道岔测试

This commit is contained in:
joylink_zhaoerwei 2024-01-19 13:52:29 +08:00
parent bd7bbcc54c
commit f87f2178fb
5 changed files with 118 additions and 55 deletions

View File

@ -28,12 +28,14 @@ export interface ITHTurnoutState extends GraphicState {
export declare class THTurnout extends JlTurnout { export declare class THTurnout extends JlTurnout {
labelRect: Graphics; labelRect: Graphics;
speedLimit: Graphics; speedLimit: Graphics;
lostIndicationSquare: Graphics;
deltaTime: number; deltaTime: number;
constructor(); constructor();
get states(): ITHTurnoutState; get states(): ITHTurnoutState;
doRepaint(): void; doRepaint(): void;
setLineColor(color: string): void;
getSpeedLimitLinePoints(conf: 'normal' | 'reverse' | 'main'): IPointData[][]; getSpeedLimitLinePoints(conf: 'normal' | 'reverse' | 'main'): IPointData[][];
bindFlashAnimation(gList: Graphics[]): GraphicAnimation; bindFlashAnimation(gList: Graphics[], name: string): GraphicAnimation;
buildRelation(): void; buildRelation(): void;
saveRelations(): void; saveRelations(): void;
loadRelations(): void; loadRelations(): void;

View File

@ -11,16 +11,17 @@ const TurnoutLabelColor = {
RED: '#f00', RED: '#f00',
WHITE: '#fff', WHITE: '#fff',
}; };
//ForkGraphic单独处理
class THTurnout extends JlTurnout { class THTurnout extends JlTurnout {
labelRect; labelRect;
speedLimit; speedLimit;
lostIndicationSquare;
deltaTime; deltaTime;
constructor() { constructor() {
super(THConsts); super(THConsts);
this.name = 'turnout'; this.name = 'turnout';
this.labelRect = new Graphics(); this.labelRect = new Graphics();
this.speedLimit = new Graphics(); this.speedLimit = new Graphics();
this.lostIndicationSquare = new Graphics();
this.addChild(this.labelRect); this.addChild(this.labelRect);
this.addChild(this.speedLimit); this.addChild(this.speedLimit);
this.deltaTime = 0; this.deltaTime = 0;
@ -32,31 +33,58 @@ class THTurnout extends JlTurnout {
//线条颜色 //线条颜色
const station = this.queryStore.queryByCodeAndType(this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, THStation.Type); const station = this.queryStore.queryByCodeAndType(this.states.rtuId > 9 ? '' + this.states.rtuId : '0' + this.states.rtuId, THStation.Type);
if (station?.states.ipRtuStusDown) { if (station?.states.ipRtuStusDown) {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.blueShowColor)); this.setLineColor(THConsts.blueShowColor);
} }
else if (this.states.ipSingleSwitchStusCbtcOccupied) { else if (this.states.ipSingleSwitchStusCbtcOccupied) {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.cbtcOccupiedColor)); this.setLineColor(THConsts.cbtcOccupiedColor);
} }
else if (this.states.ipSingleSwitchStusCiOccupied) { else if (this.states.ipSingleSwitchStusCiOccupied) {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.ciOccupiedColor)); this.setLineColor(THConsts.ciOccupiedColor);
} }
else if (this.states.ipSingleSwitchStusLocked || else if (this.states.ipSingleSwitchStusLocked ||
this.states.ipSingleSwitchStusFailLocked) { this.states.ipSingleSwitchStusFailLocked) {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.lockedColor)); this.setLineColor(THConsts.lockedColor);
} }
else if (this.states.ipSingleSwitchStusAtcInvalid) { else if (this.states.ipSingleSwitchStusAtcInvalid) {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.atcInvalidColor)); this.setLineColor(THConsts.atcInvalidColor);
} }
else if (this.states.ipSingleSwitchStusOverlap) { else if (this.states.ipSingleSwitchStusOverlap) {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.overlapColor)); this.setLineColor(THConsts.overlapColor);
} }
else { else {
this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.idleColor)); this.setLineColor(THConsts.idleColor);
}
if (this.states.ipSingleSwitchStusJammed /* ||
this.turnout.states.ipSingleSwitchStusLostIndication */) {
let x, y;
const w = 24, h = 24;
if (this.datas.pointA[0].x > this.datas.pointB[0].x) {
x = -22;
}
else {
x = -2;
}
if (this.datas.pointC[0].y > 0) {
y = -2;
}
else {
y = -20;
}
this.lostIndicationSquare.lineStyle(2, '#f00').drawRect(x, y, w, h);
const flashAnimation = this.bindFlashAnimation([this.lostIndicationSquare], 'lostIndicationFlash');
flashAnimation.resume();
return;
}
const { pointB, pointC } = this.datas;
if (this.states.ipSingleSwitchStusNormal) {
this.graphics.fork.paint(pointB[0]);
this.removeAllAnimation();
}
else if (this.states.ipSingleSwitchStusReverse) {
this.graphics.fork.paint(pointC[0]);
this.removeAllAnimation();
} }
super.draw(); super.draw();
const { pointB, pointC } = this.datas;
this.graphics.fork.paint(pointB[0]);
this.graphics.fork.paint(pointC[0]);
this.graphics.label.text = this.datas.code; this.graphics.label.text = this.datas.code;
//文字颜色 //文字颜色
if (this.states.ipSingleSwitchStusBlocked1) { if (this.states.ipSingleSwitchStusBlocked1) {
@ -118,18 +146,21 @@ class THTurnout extends JlTurnout {
this.graphics.fork, this.graphics.fork,
this.graphics.sections[0], this.graphics.sections[0],
this.graphics.sections[1], this.graphics.sections[1],
]); ], 'flash');
} }
else if (this.states.ipSingleSwitchStusReverse) { else if (this.states.ipSingleSwitchStusReverse) {
this.bindFlashAnimation([ this.bindFlashAnimation([
this.graphics.fork, this.graphics.fork,
this.graphics.sections[0], this.graphics.sections[0],
this.graphics.sections[2], this.graphics.sections[2],
]); ], 'flash');
} }
this.animation('flash')?.resume(); this.animation('flash')?.resume();
} }
} }
setLineColor(color) {
this.graphics.sections.forEach((g) => (g.stateFillColor = color));
}
getSpeedLimitLinePoints(conf) { getSpeedLimitLinePoints(conf) {
const [pa, pb, pc] = [ const [pa, pb, pc] = [
this.datas.pointA[0], this.datas.pointA[0],
@ -185,9 +216,9 @@ class THTurnout extends JlTurnout {
]; ];
} }
} }
bindFlashAnimation(gList) { bindFlashAnimation(gList, name) {
const flashAnimation = GraphicAnimation.init({ const flashAnimation = GraphicAnimation.init({
name: 'flash', name,
run: (dt) => { run: (dt) => {
this.deltaTime += dt; this.deltaTime += dt;
if (this.deltaTime > 60) { if (this.deltaTime > 60) {

View File

@ -4,7 +4,7 @@ import { DevicePort } from 'common/common';
import { ITurnoutData, TurnoutConstsConfig } from './TurnoutConfig'; import { ITurnoutData, TurnoutConstsConfig } from './TurnoutConfig';
import { JlSection } from 'src/packages/Section/common/JlSection'; import { JlSection } from 'src/packages/Section/common/JlSection';
export declare function getForkPoint(r: number, p: IPointData): IPointData; export declare function getForkPoint(r: number, p: IPointData): IPointData;
declare class TurnoutSection extends Graphics { export declare class TurnoutSection extends Graphics {
turnoutConsts: TurnoutConstsConfig; turnoutConsts: TurnoutConstsConfig;
turnout: JlTurnout; turnout: JlTurnout;
port: DevicePort; port: DevicePort;
@ -16,6 +16,7 @@ declare class ForkGraphic extends Graphics {
turnoutConsts: TurnoutConstsConfig; turnoutConsts: TurnoutConstsConfig;
turnout: JlTurnout; turnout: JlTurnout;
stateFillColor?: string; stateFillColor?: string;
dt: number;
constructor(turnout: JlTurnout, turnoutConsts: TurnoutConstsConfig); constructor(turnout: JlTurnout, turnoutConsts: TurnoutConstsConfig);
paint(p: IPointData): void; paint(p: IPointData): void;
} }

View File

@ -51,6 +51,7 @@ class ForkGraphic extends Graphics {
turnoutConsts; turnoutConsts;
turnout; turnout;
stateFillColor; stateFillColor;
dt = 0;
constructor(turnout, turnoutConsts) { constructor(turnout, turnoutConsts) {
super(); super();
this.turnoutConsts = turnoutConsts; this.turnoutConsts = turnoutConsts;
@ -66,7 +67,7 @@ class ForkGraphic extends Graphics {
} }
} }
class JlTurnout extends JlGraphic { class JlTurnout extends JlGraphic {
static Type = 'JlTurnout'; static Type = 'Turnout';
graphics; graphics;
constructor(turnoutConsts) { constructor(turnoutConsts) {
super(JlTurnout.Type); super(JlTurnout.Type);
@ -231,4 +232,4 @@ class JlTurnout extends JlGraphic {
} }
} }
export { JlTurnout, getForkPoint }; export { JlTurnout, TurnoutSection, getForkPoint };

View File

@ -42,16 +42,17 @@ export interface ITHTurnoutState extends GraphicState {
rtuId: number; rtuId: number;
} }
//ForkGraphic单独处理
export class THTurnout extends JlTurnout { export class THTurnout extends JlTurnout {
labelRect: Graphics; labelRect: Graphics;
speedLimit: Graphics; speedLimit: Graphics;
lostIndicationSquare: Graphics;
deltaTime: number; deltaTime: number;
constructor() { constructor() {
super(THConsts); super(THConsts);
this.name = 'turnout'; this.name = 'turnout';
this.labelRect = new Graphics(); this.labelRect = new Graphics();
this.speedLimit = new Graphics(); this.speedLimit = new Graphics();
this.lostIndicationSquare = new Graphics();
this.addChild(this.labelRect); this.addChild(this.labelRect);
this.addChild(this.speedLimit); this.addChild(this.speedLimit);
this.deltaTime = 0; this.deltaTime = 0;
@ -66,42 +67,60 @@ export class THTurnout extends JlTurnout {
THStation.Type, THStation.Type,
); );
if (station?.states.ipRtuStusDown) { if (station?.states.ipRtuStusDown) {
this.graphics.sections.forEach( this.setLineColor(THConsts.blueShowColor);
(g) => (g.stateFillColor = THConsts.blueShowColor),
);
} else if (this.states.ipSingleSwitchStusCbtcOccupied) { } else if (this.states.ipSingleSwitchStusCbtcOccupied) {
this.graphics.sections.forEach( this.setLineColor(THConsts.cbtcOccupiedColor);
(g) => (g.stateFillColor = THConsts.cbtcOccupiedColor),
);
} else if (this.states.ipSingleSwitchStusCiOccupied) { } else if (this.states.ipSingleSwitchStusCiOccupied) {
this.graphics.sections.forEach( this.setLineColor(THConsts.ciOccupiedColor);
(g) => (g.stateFillColor = THConsts.ciOccupiedColor),
);
} else if ( } else if (
this.states.ipSingleSwitchStusLocked || this.states.ipSingleSwitchStusLocked ||
this.states.ipSingleSwitchStusFailLocked this.states.ipSingleSwitchStusFailLocked
) { ) {
this.graphics.sections.forEach( this.setLineColor(THConsts.lockedColor);
(g) => (g.stateFillColor = THConsts.lockedColor),
);
} else if (this.states.ipSingleSwitchStusAtcInvalid) { } else if (this.states.ipSingleSwitchStusAtcInvalid) {
this.graphics.sections.forEach( this.setLineColor(THConsts.atcInvalidColor);
(g) => (g.stateFillColor = THConsts.atcInvalidColor),
);
} else if (this.states.ipSingleSwitchStusOverlap) { } else if (this.states.ipSingleSwitchStusOverlap) {
this.graphics.sections.forEach( this.setLineColor(THConsts.overlapColor);
(g) => (g.stateFillColor = THConsts.overlapColor),
);
} else { } else {
this.graphics.sections.forEach( this.setLineColor(THConsts.idleColor);
(g) => (g.stateFillColor = THConsts.idleColor), }
if (
this.states.ipSingleSwitchStusJammed /* ||
this.turnout.states.ipSingleSwitchStusLostIndication */
) {
let x: number, y: number;
const w = 24,
h = 24;
if (this.datas.pointA[0].x > this.datas.pointB[0].x) {
x = -22;
} else {
x = -2;
}
if (this.datas.pointC[0].y > 0) {
y = -2;
} else {
y = -20;
}
this.lostIndicationSquare.lineStyle(2, '#f00').drawRect(x, y, w, h);
const flashAnimation = this.bindFlashAnimation(
[this.lostIndicationSquare],
'lostIndicationFlash',
); );
flashAnimation.resume();
return;
}
const { pointB, pointC } = this.datas;
if (this.states.ipSingleSwitchStusNormal) {
this.graphics.fork.paint(pointB[0]);
this.removeAllAnimation();
} else if (this.states.ipSingleSwitchStusReverse) {
this.graphics.fork.paint(pointC[0]);
this.removeAllAnimation();
} }
super.draw(); super.draw();
const { pointB, pointC } = this.datas;
this.graphics.fork.paint(pointB[0]);
this.graphics.fork.paint(pointC[0]);
this.graphics.label.text = this.datas.code; this.graphics.label.text = this.datas.code;
@ -170,21 +189,30 @@ export class THTurnout extends JlTurnout {
if (this.states.ipSingleSwitchStusCut) { if (this.states.ipSingleSwitchStusCut) {
if (this.states.ipSingleSwitchStusNormal) { if (this.states.ipSingleSwitchStusNormal) {
this.bindFlashAnimation([ this.bindFlashAnimation(
this.graphics.fork, [
this.graphics.sections[0], this.graphics.fork,
this.graphics.sections[1], this.graphics.sections[0],
]); this.graphics.sections[1],
],
'flash',
);
} else if (this.states.ipSingleSwitchStusReverse) { } else if (this.states.ipSingleSwitchStusReverse) {
this.bindFlashAnimation([ this.bindFlashAnimation(
this.graphics.fork, [
this.graphics.sections[0], this.graphics.fork,
this.graphics.sections[2], this.graphics.sections[0],
]); this.graphics.sections[2],
],
'flash',
);
} }
this.animation('flash')?.resume(); this.animation('flash')?.resume();
} }
} }
setLineColor(color: string) {
this.graphics.sections.forEach((g) => (g.stateFillColor = color));
}
getSpeedLimitLinePoints(conf: 'normal' | 'reverse' | 'main'): IPointData[][] { getSpeedLimitLinePoints(conf: 'normal' | 'reverse' | 'main'): IPointData[][] {
const [pa, pb, pc] = [ const [pa, pb, pc] = [
this.datas.pointA[0], this.datas.pointA[0],
@ -263,9 +291,9 @@ export class THTurnout extends JlTurnout {
]; ];
} }
} }
bindFlashAnimation(gList: Graphics[]) { bindFlashAnimation(gList: Graphics[], name: string) {
const flashAnimation = GraphicAnimation.init({ const flashAnimation = GraphicAnimation.init({
name: 'flash', name,
run: (dt: number) => { run: (dt: number) => {
this.deltaTime += dt; this.deltaTime += dt;
if (this.deltaTime > 60) { if (this.deltaTime > 60) {