From f87f2178fbe12129266054afcc6cffcb4bff1caa Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Fri, 19 Jan 2024 13:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=93=E5=B2=94=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/packages/Turnout/THTurnout.d.ts | 4 +- components/packages/Turnout/THTurnout.js | 61 ++++++++--- .../packages/Turnout/common/JlTurnout.d.ts | 3 +- .../packages/Turnout/common/JlTurnout.js | 5 +- src/packages/Turnout/THTurnout.ts | 100 +++++++++++------- 5 files changed, 118 insertions(+), 55 deletions(-) diff --git a/components/packages/Turnout/THTurnout.d.ts b/components/packages/Turnout/THTurnout.d.ts index 6414cf4..0c25b1a 100644 --- a/components/packages/Turnout/THTurnout.d.ts +++ b/components/packages/Turnout/THTurnout.d.ts @@ -28,12 +28,14 @@ export interface ITHTurnoutState extends GraphicState { export declare class THTurnout extends JlTurnout { labelRect: Graphics; speedLimit: Graphics; + lostIndicationSquare: Graphics; deltaTime: number; constructor(); get states(): ITHTurnoutState; doRepaint(): void; + setLineColor(color: string): void; getSpeedLimitLinePoints(conf: 'normal' | 'reverse' | 'main'): IPointData[][]; - bindFlashAnimation(gList: Graphics[]): GraphicAnimation; + bindFlashAnimation(gList: Graphics[], name: string): GraphicAnimation; buildRelation(): void; saveRelations(): void; loadRelations(): void; diff --git a/components/packages/Turnout/THTurnout.js b/components/packages/Turnout/THTurnout.js index bc6697e..c777ac8 100644 --- a/components/packages/Turnout/THTurnout.js +++ b/components/packages/Turnout/THTurnout.js @@ -11,16 +11,17 @@ const TurnoutLabelColor = { RED: '#f00', WHITE: '#fff', }; -//ForkGraphic单独处理 class THTurnout extends JlTurnout { labelRect; speedLimit; + lostIndicationSquare; deltaTime; constructor() { super(THConsts); this.name = 'turnout'; this.labelRect = new Graphics(); this.speedLimit = new Graphics(); + this.lostIndicationSquare = new Graphics(); this.addChild(this.labelRect); this.addChild(this.speedLimit); 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); if (station?.states.ipRtuStusDown) { - this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.blueShowColor)); + this.setLineColor(THConsts.blueShowColor); } else if (this.states.ipSingleSwitchStusCbtcOccupied) { - this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.cbtcOccupiedColor)); + this.setLineColor(THConsts.cbtcOccupiedColor); } else if (this.states.ipSingleSwitchStusCiOccupied) { - this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.ciOccupiedColor)); + this.setLineColor(THConsts.ciOccupiedColor); } else if (this.states.ipSingleSwitchStusLocked || this.states.ipSingleSwitchStusFailLocked) { - this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.lockedColor)); + this.setLineColor(THConsts.lockedColor); } else if (this.states.ipSingleSwitchStusAtcInvalid) { - this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.atcInvalidColor)); + this.setLineColor(THConsts.atcInvalidColor); } else if (this.states.ipSingleSwitchStusOverlap) { - this.graphics.sections.forEach((g) => (g.stateFillColor = THConsts.overlapColor)); + this.setLineColor(THConsts.overlapColor); } 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(); - const { pointB, pointC } = this.datas; - this.graphics.fork.paint(pointB[0]); - this.graphics.fork.paint(pointC[0]); this.graphics.label.text = this.datas.code; //文字颜色 if (this.states.ipSingleSwitchStusBlocked1) { @@ -118,18 +146,21 @@ class THTurnout extends JlTurnout { this.graphics.fork, this.graphics.sections[0], this.graphics.sections[1], - ]); + ], 'flash'); } else if (this.states.ipSingleSwitchStusReverse) { this.bindFlashAnimation([ this.graphics.fork, this.graphics.sections[0], this.graphics.sections[2], - ]); + ], 'flash'); } this.animation('flash')?.resume(); } } + setLineColor(color) { + this.graphics.sections.forEach((g) => (g.stateFillColor = color)); + } getSpeedLimitLinePoints(conf) { const [pa, pb, pc] = [ this.datas.pointA[0], @@ -185,9 +216,9 @@ class THTurnout extends JlTurnout { ]; } } - bindFlashAnimation(gList) { + bindFlashAnimation(gList, name) { const flashAnimation = GraphicAnimation.init({ - name: 'flash', + name, run: (dt) => { this.deltaTime += dt; if (this.deltaTime > 60) { diff --git a/components/packages/Turnout/common/JlTurnout.d.ts b/components/packages/Turnout/common/JlTurnout.d.ts index 1244644..0ad6dbe 100644 --- a/components/packages/Turnout/common/JlTurnout.d.ts +++ b/components/packages/Turnout/common/JlTurnout.d.ts @@ -4,7 +4,7 @@ import { DevicePort } from 'common/common'; import { ITurnoutData, TurnoutConstsConfig } from './TurnoutConfig'; import { JlSection } from 'src/packages/Section/common/JlSection'; export declare function getForkPoint(r: number, p: IPointData): IPointData; -declare class TurnoutSection extends Graphics { +export declare class TurnoutSection extends Graphics { turnoutConsts: TurnoutConstsConfig; turnout: JlTurnout; port: DevicePort; @@ -16,6 +16,7 @@ declare class ForkGraphic extends Graphics { turnoutConsts: TurnoutConstsConfig; turnout: JlTurnout; stateFillColor?: string; + dt: number; constructor(turnout: JlTurnout, turnoutConsts: TurnoutConstsConfig); paint(p: IPointData): void; } diff --git a/components/packages/Turnout/common/JlTurnout.js b/components/packages/Turnout/common/JlTurnout.js index 2e3fc67..d74c924 100644 --- a/components/packages/Turnout/common/JlTurnout.js +++ b/components/packages/Turnout/common/JlTurnout.js @@ -51,6 +51,7 @@ class ForkGraphic extends Graphics { turnoutConsts; turnout; stateFillColor; + dt = 0; constructor(turnout, turnoutConsts) { super(); this.turnoutConsts = turnoutConsts; @@ -66,7 +67,7 @@ class ForkGraphic extends Graphics { } } class JlTurnout extends JlGraphic { - static Type = 'JlTurnout'; + static Type = 'Turnout'; graphics; constructor(turnoutConsts) { super(JlTurnout.Type); @@ -231,4 +232,4 @@ class JlTurnout extends JlGraphic { } } -export { JlTurnout, getForkPoint }; +export { JlTurnout, TurnoutSection, getForkPoint }; diff --git a/src/packages/Turnout/THTurnout.ts b/src/packages/Turnout/THTurnout.ts index f7ed871..deb414b 100644 --- a/src/packages/Turnout/THTurnout.ts +++ b/src/packages/Turnout/THTurnout.ts @@ -42,16 +42,17 @@ export interface ITHTurnoutState extends GraphicState { rtuId: number; } -//ForkGraphic单独处理 export class THTurnout extends JlTurnout { labelRect: Graphics; speedLimit: Graphics; + lostIndicationSquare: Graphics; deltaTime: number; constructor() { super(THConsts); this.name = 'turnout'; this.labelRect = new Graphics(); this.speedLimit = new Graphics(); + this.lostIndicationSquare = new Graphics(); this.addChild(this.labelRect); this.addChild(this.speedLimit); this.deltaTime = 0; @@ -66,42 +67,60 @@ export class THTurnout extends JlTurnout { THStation.Type, ); if (station?.states.ipRtuStusDown) { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.blueShowColor), - ); + this.setLineColor(THConsts.blueShowColor); } else if (this.states.ipSingleSwitchStusCbtcOccupied) { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.cbtcOccupiedColor), - ); + this.setLineColor(THConsts.cbtcOccupiedColor); } else if (this.states.ipSingleSwitchStusCiOccupied) { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.ciOccupiedColor), - ); + this.setLineColor(THConsts.ciOccupiedColor); } else if ( this.states.ipSingleSwitchStusLocked || this.states.ipSingleSwitchStusFailLocked ) { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.lockedColor), - ); + this.setLineColor(THConsts.lockedColor); } else if (this.states.ipSingleSwitchStusAtcInvalid) { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.atcInvalidColor), - ); + this.setLineColor(THConsts.atcInvalidColor); } else if (this.states.ipSingleSwitchStusOverlap) { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.overlapColor), - ); + this.setLineColor(THConsts.overlapColor); } else { - this.graphics.sections.forEach( - (g) => (g.stateFillColor = THConsts.idleColor), + this.setLineColor(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(); - const { pointB, pointC } = this.datas; - this.graphics.fork.paint(pointB[0]); - this.graphics.fork.paint(pointC[0]); this.graphics.label.text = this.datas.code; @@ -170,21 +189,30 @@ export class THTurnout extends JlTurnout { if (this.states.ipSingleSwitchStusCut) { if (this.states.ipSingleSwitchStusNormal) { - this.bindFlashAnimation([ - this.graphics.fork, - this.graphics.sections[0], - this.graphics.sections[1], - ]); + this.bindFlashAnimation( + [ + this.graphics.fork, + this.graphics.sections[0], + this.graphics.sections[1], + ], + 'flash', + ); } else if (this.states.ipSingleSwitchStusReverse) { - this.bindFlashAnimation([ - this.graphics.fork, - this.graphics.sections[0], - this.graphics.sections[2], - ]); + this.bindFlashAnimation( + [ + this.graphics.fork, + this.graphics.sections[0], + this.graphics.sections[2], + ], + 'flash', + ); } this.animation('flash')?.resume(); } } + setLineColor(color: string) { + this.graphics.sections.forEach((g) => (g.stateFillColor = color)); + } getSpeedLimitLinePoints(conf: 'normal' | 'reverse' | 'main'): IPointData[][] { const [pa, pb, pc] = [ 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({ - name: 'flash', + name, run: (dt: number) => { this.deltaTime += dt; if (this.deltaTime > 60) {