列车、分隔符、应答器调整

This commit is contained in:
dong 2023-12-29 17:40:17 +08:00
parent 66e28a8c68
commit 53f78e5952
6 changed files with 619 additions and 240 deletions

View File

@ -1,39 +1,36 @@
import { Color, Graphics } from 'pixi.js';
import { JlGraphic, JlGraphicTemplate } from 'jl-graphic';
import { ISeparatorData, SeparatorConstsMap, separatorTypeEnum } from './SeparatorConfig';
import { CategoryType } from '../CategoryType';
let SeparatorConsts = {
height: 12,
lineWidth: 2,
lineColor: '0xFFFFFF',
circleColor: '0xEF0200',
radius: 5,
}
import { JlGraphic } from 'jl-graphic';
import {
ISeparatorConsts,
ISeparatorData,
UpdateSeparatorConsts,
separatorTypeEnum,
getSeparatorConsts,
} from './SeparatorConfig';
/**
*
* @param {UpdateSeparatorConsts}
*
*/
export class Separator extends JlGraphic {
static Type = 'Separator';
rectGraphic: Graphics = new Graphics();
circleGraphic: Graphics = new Graphics();
private categoryType: CategoryType
constructor(categoryType: CategoryType) {
constDatas: ISeparatorConsts;
constructor(data?: UpdateSeparatorConsts) {
super(Separator.Type);
this.addChild(this.rectGraphic);
this.addChild(this.circleGraphic);
this.categoryType = categoryType
this.getConstDatas();
this.constDatas = getSeparatorConsts();
if (data) {
Object.assign(this.constDatas, data)
}
}
get datas(): ISeparatorData {
return this.getDatas<ISeparatorData>();
}
getConstDatas():void {
const constData = SeparatorConstsMap.get(this.categoryType)
if (constData) {
SeparatorConsts =constData
}
}
clear() {
this.rectGraphic.clear();
this.circleGraphic.clear();
@ -47,25 +44,25 @@ export class Separator extends JlGraphic {
const typeArr = ['section', 'turnout'];
if (typeArr.includes(this.datas.separatorType)) {
rectGraphic.lineStyle(
SeparatorConsts.lineWidth,
new Color(SeparatorConsts.lineColor)
this.constDatas.lineWidth,
new Color(this.constDatas.lineColor)
);
rectGraphic.moveTo(0, -SeparatorConsts.height / 2);
rectGraphic.lineTo(0, SeparatorConsts.height / 2);
rectGraphic.moveTo(0, -this.constDatas.height / 2);
rectGraphic.lineTo(0, this.constDatas.height / 2);
if (this.datas.separatorType == 'turnout') {
this.circleGraphic.lineStyle(1, SeparatorConsts.circleColor);
this.circleGraphic.drawCircle(0, 0, SeparatorConsts.radius);
this.circleGraphic.lineStyle(1, this.constDatas.circleColor);
this.circleGraphic.drawCircle(0, 0, this.constDatas.radius);
}
}
const endTypeArr = ['endA', 'endB'];
if (endTypeArr.includes(this.datas.separatorType)) {
let d = SeparatorConsts.radius;
let d = this.constDatas.radius;
if (this.datas.separatorType == 'endB') {
d = -d;
}
rectGraphic.lineStyle(
SeparatorConsts.lineWidth,
new Color(SeparatorConsts.lineColor)
this.constDatas.lineWidth,
new Color(this.constDatas.lineColor)
);
rectGraphic.moveTo(0, 0);
rectGraphic.lineTo(-d, 0);
@ -77,18 +74,3 @@ export class Separator extends JlGraphic {
}
}
}
export class SeparatorTemplate extends JlGraphicTemplate<Separator> {
categoryType:CategoryType;
constructor(dataTemplate: ISeparatorData,gategoryConsts: CategoryType) {
super(Separator.Type, {
dataTemplate,
});
this.categoryType = gategoryConsts;
}
new(): Separator {
const separator = new Separator(this.categoryType);
separator.loadData(this.datas);
return separator;
}
}

View File

@ -1,5 +1,4 @@
import { GraphicData } from "jl-graphic";
import { CategoryType } from "../CategoryType";
export enum separatorTypeEnum {
turnout = 'turnout', // 道岔分隔符
@ -8,30 +7,15 @@ export enum separatorTypeEnum {
section = 'section', // 区段分隔符
}
export interface SeparatorConstsConfig{
height: number,
lineWidth: number,
lineColor: string,
circleColor: string,
radius: number,
export interface ISeparatorConsts {
height: number;
lineWidth: number;
lineColor: string;
circleColor: string;
radius: number;
}
const THConsts = {
height: 12,
lineWidth: 2,
lineColor: '0xFFFFFF',
circleColor: '0xEF0200',
radius: 5,
};
const JKConsts = {
height: 12,
lineWidth: 2,
lineColor: '0x617799',
circleColor: '0xEF0200',
radius: 5,
};
export const SeparatorConstsMap = new Map<CategoryType, SeparatorConstsConfig>([[CategoryType.JK,JKConsts],[CategoryType.TH,THConsts]])
export type UpdateSeparatorConsts = Partial<ISeparatorConsts>;
export interface ISeparatorData extends GraphicData {
get code(): string; // 编号
@ -42,3 +26,14 @@ export interface ISeparatorData extends GraphicData {
copyFrom(data: ISeparatorData): void;
eq(other: ISeparatorData): boolean;
}
export function getSeparatorConsts(): ISeparatorConsts {
const separatorConsts = {
height: 12,
lineWidth: 2,
lineColor: '0x617799',
circleColor: '0xEF0200',
radius: 5,
};
return separatorConsts;
}

346
src/packages/Train/Train.ts Normal file
View File

@ -0,0 +1,346 @@
import { Color, Graphics, Container, Point } from 'pixi.js';
import { JlGraphic, VectorText, calculateMirrorPoint } from 'jl-graphic';
import {
ITrainConstsConfig,
EnumDiriveModel,
EnumStatusText,
UpdateTrainConsts,
getTrainConsts,
EnumTrainType,
ITrainData,
} from './TrainConfig';
interface bodyWH {
width: number; // 宽
height: number; // 高
}
class TrainHead extends Container {
arrow: Graphics; // 列车箭头
pause: Graphics; // 列车停止
train: Train;
isStop: boolean;
arrowColor: string;
pauseColor: string;
constructor(train: Train) {
super();
this.arrow = new Graphics();
this.pause = new Graphics();
this.addChild(this.arrow);
this.addChild(this.pause);
this.train = train;
this.isStop = true;
this.arrowColor = this.train.constDatas.arrowDefaultColor;
this.pauseColor = this.train.constDatas.pauseDefaultColor;
}
clear() {
this.arrow.clear();
this.pause.clear();
}
doRepaint() {
this.clear();
const trainConsts = this.train.constDatas;
const bodyWH = this.train.trainbody.getBodyWH();
const marginX = trainConsts.marginX;
const pauseW = trainConsts.pauseW;
const bodyWidth = bodyWH ? bodyWH.width : trainConsts.bodyWidth;
const bodyHeight = bodyWH ? bodyWH.height : trainConsts.bodyHeight;
let pauseTW = pauseW + marginX;
if (trainConsts.arrowPauseOnlyOne) {
pauseTW = 0;
}
let arrowPoint = [
-bodyHeight * 0.4 - marginX - pauseTW - bodyWidth / 2,
0,
-marginX - pauseTW - bodyWidth / 2,
bodyHeight / 2,
-marginX - pauseTW - bodyWidth / 2,
-bodyHeight / 2,
];
let pausePoint = [
-marginX - pauseW / 2 - bodyWidth / 2,
-bodyHeight / 2,
-marginX - pauseW / 2 - bodyWidth / 2,
bodyHeight / 2,
];
// 列车是向右或者向上
if (this.isRight()) {
const aP: Array<number> = [];
arrowPoint.forEach((item, index) => {
if (index % 2 == 1) {
const p = new Point(arrowPoint[index - 1], item);
const newP = calculateMirrorPoint(new Point(0, 0), p);
aP.push(newP.x, newP.y);
}
});
arrowPoint = aP;
const pP: Array<number> = [];
pausePoint.forEach((item, index) => {
if (index % 2 == 1) {
const p = new Point(pausePoint[index - 1], item);
const newP = calculateMirrorPoint(new Point(0, 0), p);
pP.push(newP.x, newP.y);
}
});
pausePoint = pP;
}
this.pause.lineStyle(pauseW, this.pauseColor, 1);
this.pause.moveTo(pausePoint[0], pausePoint[1]);
this.pause.lineTo(pausePoint[2], pausePoint[3]);
const arrow = this.arrow;
arrow.beginFill(this.arrowColor, 1);
arrow.drawPolygon(arrowPoint);
arrow.endFill();
}
isRight(): boolean {
let d = false;
if (this.train.isRightRoTop) {
d = true;
}
return d;
}
}
class TrainBody extends Container {
bodyRact: Graphics;
codeAGraph: VectorText = new VectorText(''); //识别号AA
codeBGraph: VectorText = new VectorText(''); //识别号BBB
train: Train;
codeAColor: string;
codeBColor: string;
codeAText: string;
codeBText: string;
constructor(train: Train) {
super();
this.bodyRact = new Graphics();
this.addChild(this.bodyRact);
this.addChild(this.codeAGraph);
this.addChild(this.codeBGraph);
this.train = train;
this.codeAGraph.setVectorFontSize(this.train.constDatas.codeFontSize);
this.codeBGraph.setVectorFontSize(this.train.constDatas.codeFontSize);
this.codeAColor = this.train.constDatas.codeColor;
this.codeBColor = this.train.constDatas.codeColor;
this.codeAText = '';
this.codeBText = '';
}
clear() {
this.bodyRact.clear();
}
getBodyWH(): bodyWH {
const bodyAWH = this.codeAGraph.getLocalBounds();
const bodyBWH = this.codeBGraph.getLocalBounds();
return {
width:
bodyAWH.width + bodyBWH.width + this.train.constDatas.bodyPadding * 2,
height: bodyAWH.height + this.train.constDatas.bodyPadding * 2,
};
}
doRepaint(): void {
this.clear();
const trainConsts = this.train.constDatas;
const codeAGraph = this.codeAGraph;
const codeBGraph = this.codeBGraph;
codeAGraph.text = this.codeAText;
codeBGraph.text = this.codeBText;
codeAGraph.anchor.set(0.5);
codeBGraph.anchor.set(0.5);
const styleA = {
fill: this.codeAColor,
fontSize: trainConsts.codeFontSize,
};
const styleB = {
fill: this.codeBColor,
fontSize: trainConsts.codeFontSize,
};
codeAGraph.style = styleA;
codeBGraph.style = styleB;
if (this.codeBText) {
const bodyAWH = codeAGraph.getLocalBounds();
const bodyBWH = codeBGraph.getLocalBounds();
codeAGraph.position.set(-bodyBWH.width / 2, 0);
codeBGraph.position.set(bodyAWH.width / 2, 0);
}
if (this.train.constDatas.hasBodyRact) {
const bodyRact = this.bodyRact;
const { width: bodyWidth, height: bodyHeight } = this.getBodyWH();
bodyRact.lineStyle(
trainConsts.borderWidth,
new Color(trainConsts.borderColor)
);
const bgColor = trainConsts.bodyBgColor;
bodyRact.beginFill(new Color(bgColor));
bodyRact.drawRect(-bodyWidth / 2, -bodyHeight / 2, bodyWidth, bodyHeight);
bodyRact.endFill();
}
}
}
class StatusText extends Container {
sText: VectorText = new VectorText('');
train: Train;
constructor(train: Train) {
super();
this.train = train;
this.addChild(this.sText);
}
doRepaint(text: EnumStatusText, bodyWH: bodyWH): void {
const trainConsts = this.train.constDatas;
let t = text as string;
if (trainConsts.statusTextTransform) {
t = trainConsts.statusTextTransform[text];
}
this.sText.text = t;
this.sText.anchor.set(0.5);
const c =
trainConsts.statusTextColor[text] || trainConsts.statusTextColor.D;
const style = {
fill: c,
fontSize: trainConsts.textFontSize,
};
this.sText.style = style;
const { width: bodyWidth, height: bodyHeight } = bodyWH;
const { width: textHWidth, height: textHeight } =
this.sText.getLocalBounds();
const num = trainConsts.statusTextList.length;
let index = trainConsts.statusTextList.findIndex((item) => {
return item == text;
});
if (index < 0) {
index = (num - 1) / 2; // 中间
}
const textMargin = (bodyWidth - textHWidth * num) / (num - 1);
this.sText.position.set(
-bodyWidth / 2 + (textHWidth * (index * 2 + 1)) / 2 + textMargin * index,
-bodyHeight / 2 - textHeight / 2 - trainConsts.textMarginY
);
}
clear(): void {
this.sText.text = '';
}
}
/**
*
*/
export class Train extends JlGraphic {
static Type = 'Train';
trainHead: TrainHead;
trainbody: TrainBody;
statusTextMap: Map<EnumStatusText, StatusText> = new Map();
isRightRoTop: boolean; // 方向是否向右或者向上
constDatas: ITrainConstsConfig;
constructor(data?: UpdateTrainConsts) {
super(Train.Type);
this.isRightRoTop = false;
this.constDatas = getTrainConsts();
if (data) {
Object.assign(this.constDatas, data);
}
this.trainbody = new TrainBody(this);
this.trainHead = new TrainHead(this);
this.addChild(this.trainHead);
this.addChild(this.trainbody);
}
get datas(): ITrainData {
return this.getDatas<ITrainData>();
}
doRepaint(): void {
this.trainbody.doRepaint();
this.trainHead.doRepaint();
}
// 设置列车是否显示停止
setIsStop(v: boolean) {
this.trainHead.isStop = v;
}
// 设置列车箭头是否显示
setArrowVisible(v: boolean) {
this.trainHead.arrow.visible = v;
}
// 设置列车暂停是否显示
setPauseVisible(v: boolean) {
this.trainHead.pause.visible = v;
}
run() {
this.trainHead.arrow.visible = true;
this.trainHead.pause.visible = !this.constDatas.arrowPauseOnlyOne;
}
stop() {
this.trainHead.arrow.visible = false;
this.trainHead.pause.visible = true;
}
setCodeAText(v: string) {
this.trainbody.codeAText = v;
}
setCodeBText(v: string) {
this.trainbody.codeBText = v;
}
// 设置驾驶模式对应颜色
setDiriveModelColor(s: EnumDiriveModel) {
const DiriveModelColorEnum = this.constDatas.DiriveModelColorEnum;
let aColor = DiriveModelColorEnum.AM;
let pColor = DiriveModelColorEnum.SM;
if (s == EnumDiriveModel.SM) {
aColor = DiriveModelColorEnum.SM;
pColor = DiriveModelColorEnum.SM;
} else if (s == EnumDiriveModel.RM) {
aColor = DiriveModelColorEnum.RM;
pColor = DiriveModelColorEnum.RM;
}
this.trainHead.arrowColor = aColor;
this.trainHead.pauseColor = pColor;
}
// 设置列车类型对应颜色
setTrainTypeColor(s: EnumTrainType) {
const typeColorEnum = this.constDatas.typeColorEnum;
const fillAColor = typeColorEnum.schedule;
let fillBColor = typeColorEnum.schedule;
if (s == EnumTrainType.late) {
fillBColor = typeColorEnum.late;
} else if (s == EnumTrainType.early) {
fillBColor = typeColorEnum.early;
} else if (s == EnumTrainType.head) {
fillBColor = typeColorEnum.head;
} else if (s == EnumTrainType.manual) {
fillBColor = typeColorEnum.manual;
}
this.trainbody.codeAColor = fillAColor;
this.trainbody.codeBColor = fillBColor;
}
// 显示列车状态文字
showStatus(s: EnumStatusText) {
if (this.statusTextMap.has(s)) {
return;
}
const bodyWH = this.trainbody.getBodyWH();
const textD = new StatusText(this);
textD.doRepaint(s, bodyWH);
this.addChild(textD);
this.statusTextMap.set(s, textD);
}
// 隐藏列车状态文字
hideStatus(s: EnumStatusText) {
if (!this.statusTextMap.has(s)) {
return;
}
const textD = this.statusTextMap.get(s);
if (textD) {
textD.clear();
this.statusTextMap.delete(s);
}
}
}

View File

@ -0,0 +1,116 @@
import { GraphicData } from "jl-graphic";
export interface ITrainConstsConfig{
bodyWidth: number; // body默认宽度
bodyHeight: number; // body默认高度
bodyPadding: number; // body默认内边距
borderWidth: number; // body边框线宽
codeFontSize: number; // code字体大小
textFontSize: number; // 状态字母大小
textMarginY: number; // 状态字母与列车距离
statusTextList: EnumStatusText[]; // 状态字母列表
marginX: number; // 图形箭头、停止、bodyx轴边距
pauseW: number; // 停止框宽度
bodyBgColor?: string; // body背景色
codeColor: string; // 车号颜色
borderColor: string; // 边框的颜色
arrowDefaultColor: string; // 箭头默认颜色
pauseDefaultColor: string; // 停止默认颜色
DiriveModelColorEnum: DiriveModelColor;
typeColorEnum: TypeColor;
statusTextColor: IStatusTextColor;
statusTextTransform?: IStatusTextColor; // 状态文字转换
arrowPauseOnlyOne: boolean; // 箭头和停止只能显示一个
hasBodyRact: boolean; // 有body矩形
}
export type UpdateTrainConsts = Partial<ITrainConstsConfig>
export enum EnumDiriveModel { // 驾驶模式
AM = 'AM', // ATO自动驾驶
SM = 'SM', // ATP 监控下的人工驾驶模式
RM = 'RM', // 限制人工驾驶模式
NRM = 'NRM', // 非限制人工驾驶模式
red = 'red', // 红色表示通信中断
}
export type DiriveModelColor = {
[key in EnumDiriveModel]: string;
}
export enum EnumTrainType { // 车类型
accuracy = 'accuracy', // 准点
early = 'early', // 早点
late = 'late', // 晚点
schedule = 'schedule', // 计划车
head = 'head', // 头码车
manual = 'manual', // 人工车
special = 'special', // 特殊车
}
export type TypeColor = {
[key in EnumTrainType]: string;
}
export enum EnumStatusText { // 车状态
H = 'H', // H扣车
S = 'S', // S跳停
D = 'D', // D开门
A = 'A', // A报警
// '>>' = '>>', // 列车重叠,点击可切换列车
}
export type IStatusTextColor = {
[key in EnumStatusText]: string;
}
export interface ITrainData extends GraphicData {
get code(): string; // 车号
set code(v: string);
clone(): ITrainData;
copyFrom(data: ITrainData): void;
eq(other: ITrainData): boolean;
}
export function getTrainConsts(): ITrainConstsConfig {
const trainConsts: ITrainConstsConfig = {
bodyWidth: 120,
bodyHeight: 40,
bodyPadding: 5,
borderWidth: 1,
codeFontSize: 22,
textFontSize: 16, // 状态字母大小
textMarginY: 10, // 状态字母与列车距离
statusTextList: [EnumStatusText.H, EnumStatusText.S, EnumStatusText.D, EnumStatusText.A],
marginX: 4, // 图形x轴边距
pauseW: 4, // 停止框宽度
codeColor: '0xffffff', // 车号颜色
borderColor: '0xA3E198', // 边框的颜色
bodyBgColor: '0x737373', // body背景色
arrowDefaultColor: '0x00FF00', // 箭头默认颜色
pauseDefaultColor: '0x00FF00', // 停止默认颜色
DiriveModelColorEnum: { // 驾驶模式对应颜色
AM: '0x00FF00', // ATO自动驾驶
SM: '0xFFFF00', // ATP 监控下的人工驾驶模式
RM: '0xFFC837', // 限制人工驾驶模式
NRM: '0xA0522D', // 非限制人工驾驶模式
red: '0xF80103', // 红色表示通信中断
},
typeColorEnum: { // 识别号颜色
accuracy: '0xffffff', // 准点
early: '0x00FF00', // 早点
late: '0xFFFF00', // 晚点
schedule: '0xffffff', // 计划车
head: '0xE9FC01', // 头码车
manual: '0xE9FC01', // 人工车
special: '0xE9FC01', // 特殊车
},
statusTextColor: {
H: '0xFFFF00', // H扣车
S: '0x6260F3', // S跳停
D: '0x00FF00', // D开门
A: '0xFF0000', // A报警
},
arrowPauseOnlyOne: false,
hasBodyRact: true, // 有body矩形
}
return trainConsts;
};

View File

@ -1,114 +1,13 @@
import { Container, Graphics } from 'pixi.js';
import { JlGraphic, VectorText } from 'jl-graphic';
import {
GraphicData,
JlGraphic,
JlGraphicTemplate,
VectorText,
} from 'jl-graphic';
import { CategoryType } from '../CategoryType';
import { TransponderConstsMap, TransponderTypeEnum } from './TransponderConfig';
export interface ITransponderData extends GraphicData {
get code(): string; // 编号
set code(v: string);
// get kilometerSystem(): KilometerSystem;
// set kilometerSystem(v: KilometerSystem);
// get TransponderRef(): IRelatedRefData;
// set TransponderRef(v: IRelatedRefData);
get centralizedStations(): number[];
set centralizedStations(v: number[]);
get fixedTelegram(): Uint8Array; // 无源应答器固定报文
set fixedTelegram(v: Uint8Array);
get type(): TransponderTypeEnum; // 应答器类型
set type(v: TransponderTypeEnum);
clone(): ITransponderData;
copyFrom(data: ITransponderData): void;
eq(other: ITransponderData): boolean;
}
let TransponderConsts = {
height: 12,
lineWidth: 2,
lineColor: '0xFFFFFF',
wblineColor: '0xFF0000',
textFontSize: 12,
textMarginY: 5, // 名称与应答器的距离
vblineColor: '0xFF00FF',
iblineColor: '0x0000FF',
};
export const transponderTypePoints = {
[TransponderTypeEnum[TransponderTypeEnum.FB]]: [
[-TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, TransponderConsts.height / 2],
[-TransponderConsts.height / 2, TransponderConsts.height / 2],
[
-TransponderConsts.height / 2,
-TransponderConsts.height / 2 - TransponderConsts.lineWidth / 2,
],
[-TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, TransponderConsts.height / 2],
[TransponderConsts.height / 2, -TransponderConsts.height / 2],
[-TransponderConsts.height / 2, TransponderConsts.height / 2],
],
[TransponderTypeEnum[TransponderTypeEnum.WB]]: [
[-TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, TransponderConsts.height / 2],
[-TransponderConsts.height / 2, TransponderConsts.height / 2],
[
-TransponderConsts.height / 2,
-TransponderConsts.height / 2 - TransponderConsts.lineWidth / 2,
],
[0, -TransponderConsts.height / 2],
[0, TransponderConsts.height / 2],
[TransponderConsts.height / 2, 0],
[-TransponderConsts.height / 2, 0],
],
[TransponderTypeEnum[TransponderTypeEnum.DB]]: [
[-TransponderConsts.height, -TransponderConsts.height / 2],
[TransponderConsts.height, -TransponderConsts.height / 2],
[TransponderConsts.height, TransponderConsts.height / 2],
[-TransponderConsts.height, TransponderConsts.height / 2],
[
-TransponderConsts.height,
-TransponderConsts.height / 2 - TransponderConsts.lineWidth / 2,
],
[-TransponderConsts.height, -TransponderConsts.height / 2],
[TransponderConsts.height, TransponderConsts.height / 2],
[TransponderConsts.height, -TransponderConsts.height / 2],
[-TransponderConsts.height, TransponderConsts.height / 2],
],
[TransponderTypeEnum[TransponderTypeEnum.VB]]: [
[-TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, TransponderConsts.height / 2],
[-TransponderConsts.height / 2, TransponderConsts.height / 2],
[
-TransponderConsts.height / 2,
-TransponderConsts.height / 2 - TransponderConsts.lineWidth / 2,
],
],
[TransponderTypeEnum[TransponderTypeEnum.IB]]: [
[-TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, -TransponderConsts.height / 2],
[TransponderConsts.height / 2, TransponderConsts.height / 2],
[-TransponderConsts.height / 2, TransponderConsts.height / 2],
[
-TransponderConsts.height / 2,
-TransponderConsts.height / 2 - TransponderConsts.lineWidth / 2,
],
[0, -TransponderConsts.height / 2],
[-TransponderConsts.height / 2, 0],
[-TransponderConsts.height / 2, TransponderConsts.height / 2],
[
TransponderConsts.height / 2,
-TransponderConsts.height / 2 + TransponderConsts.lineWidth / 2,
],
[TransponderConsts.height / 2, 0],
[0, TransponderConsts.height / 2],
],
};
ITransponderData,
ITransponderConsts,
TransponderTypeEnum,
UpdateTransponderConsts,
getTransponderConsts,
getTypePoints,
} from './TransponderConfig';
export class TransponderCode extends Container {
codeText: VectorText = new VectorText('');
@ -130,19 +29,14 @@ export class Transponder extends JlGraphic {
static Type = 'Transponder';
polygonGraphic: Graphics = new Graphics();
labelGraphic: TransponderCode = new TransponderCode();
private categoryType: CategoryType
constructor(categoryType: CategoryType) {
constDatas: ITransponderConsts;
constructor(data?: UpdateTransponderConsts) {
super(Transponder.Type);
this.addChild(this.polygonGraphic);
this.addChild(this.labelGraphic);
this.categoryType = categoryType
this.getConstDatas();
}
getConstDatas():void {
const constData = TransponderConstsMap.get(this.categoryType)
if (constData) {
TransponderConsts =constData
this.constDatas = getTransponderConsts();
if (data) {
Object.assign(this.constDatas, data)
}
}
@ -156,18 +50,17 @@ export class Transponder extends JlGraphic {
doRepaint(): void {
this.clear();
const polygonGraphic = this.polygonGraphic;
const type = TransponderTypeEnum[this.datas.type];
const ps = transponderTypePoints[type];
let lineColor = TransponderConsts.lineColor;
if (type == 'WB') {
lineColor = TransponderConsts.wblineColor;
} else if (type == 'VB') {
lineColor = TransponderConsts.vblineColor;
} else if (type == 'IB') {
lineColor = TransponderConsts.iblineColor;
const ps = getTypePoints(this.datas.type, this.constDatas);
let lineColor = this.constDatas.lineColor;
if (this.datas.type == TransponderTypeEnum.WB) {
lineColor = this.constDatas.wblineColor;
} else if (this.datas.type == TransponderTypeEnum.VB) {
lineColor = this.constDatas.vblineColor;
} else if (this.datas.type == TransponderTypeEnum.IB) {
lineColor = this.constDatas.iblineColor;
}
polygonGraphic.lineStyle(TransponderConsts.lineWidth, lineColor);
polygonGraphic.beginFill(TransponderConsts.lineColor, 0.00001); // 填充透明色(用于碰撞检测)
polygonGraphic.lineStyle(this.constDatas.lineWidth, lineColor);
polygonGraphic.beginFill(this.constDatas.lineColor, 0.00001); // 填充透明色(用于碰撞检测)
const indexArr = [0, 5, 7];
ps.forEach((item, index) => {
if (indexArr.includes(index)) {
@ -180,7 +73,7 @@ export class Transponder extends JlGraphic {
this.labelGraphic.paint(this.datas);
const style = {
fill: lineColor,
fontSize: TransponderConsts.textFontSize,
fontSize: this.constDatas.textFontSize,
};
this.labelGraphic.codeText.style = style;
const codeTransform = this.datas?.childTransforms?.find(
@ -196,23 +89,8 @@ export class Transponder extends JlGraphic {
const { height: textHeight } = this.labelGraphic.getLocalBounds();
this.labelGraphic.position.set(
0,
polygonHeight / 2 + textHeight / 2 + TransponderConsts.textMarginY
polygonHeight / 2 + textHeight / 2 + this.constDatas.textMarginY
);
}
}
}
export class TransponderTemplate extends JlGraphicTemplate<Transponder> {
categoryType:CategoryType;
constructor(dataTemplate: ITransponderData, gategoryConsts: CategoryType) {
super(Transponder.Type, {
dataTemplate,
});
this.categoryType = gategoryConsts;
}
new(): Transponder {
const transponder = new Transponder(this.categoryType);
transponder.loadData(this.datas);
return transponder;
}
}

View File

@ -1,7 +1,4 @@
import {
GraphicData,
} from 'jl-graphic';
import { CategoryType } from '../CategoryType';
import { GraphicData } from 'jl-graphic';
export interface ITransponderData extends GraphicData {
get code(): string; // 编号
@ -29,26 +26,91 @@ export enum TransponderTypeEnum {
IB, // 预告应答器
}
export interface TransponderConstsConfig{
height: number,
lineWidth: number,
lineColor: string,
wblineColor: string,
textFontSize: number,
textMarginY: number, // 名称与应答器的距离
vblineColor: string,
iblineColor: string,
export interface ITransponderConsts {
height: number;
lineWidth: number;
lineColor: string;
wblineColor: string;
textFontSize: number;
textMarginY: number; // 名称与应答器的距离
vblineColor: string;
iblineColor: string;
}
const THConsts = {
height: 12,
lineWidth: 2,
lineColor: '0xFFFFFF',
wblineColor: '0xFF0000',
textFontSize: 12,
textMarginY: 5, // 名称与应答器的距离
vblineColor: '0xFF00FF',
iblineColor: '0x0000FF',
};
export function getTypePoints(
type: TransponderTypeEnum,
TrConsts: ITransponderConsts
) {
const transponderTypePoints = {
[TransponderTypeEnum.FB]: [
[-TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, -TrConsts.height / 2 - TrConsts.lineWidth / 2],
[-TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, TrConsts.height / 2],
[TrConsts.height / 2, -TrConsts.height / 2],
[-TrConsts.height / 2, TrConsts.height / 2],
],
[TransponderTypeEnum.WB]: [
[-TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, -TrConsts.height / 2 - TrConsts.lineWidth / 2],
[0, -TrConsts.height / 2],
[0, TrConsts.height / 2],
[TrConsts.height / 2, 0],
[-TrConsts.height / 2, 0],
],
[TransponderTypeEnum.DB]: [
[-TrConsts.height, -TrConsts.height / 2],
[TrConsts.height, -TrConsts.height / 2],
[TrConsts.height, TrConsts.height / 2],
[-TrConsts.height, TrConsts.height / 2],
[-TrConsts.height, -TrConsts.height / 2 - TrConsts.lineWidth / 2],
[-TrConsts.height, -TrConsts.height / 2],
[TrConsts.height, TrConsts.height / 2],
[TrConsts.height, -TrConsts.height / 2],
[-TrConsts.height, TrConsts.height / 2],
],
[TransponderTypeEnum.VB]: [
[-TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, -TrConsts.height / 2 - TrConsts.lineWidth / 2],
],
[TransponderTypeEnum.IB]: [
[-TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, -TrConsts.height / 2],
[TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, TrConsts.height / 2],
[-TrConsts.height / 2, -TrConsts.height / 2 - TrConsts.lineWidth / 2],
[0, -TrConsts.height / 2],
[-TrConsts.height / 2, 0],
[-TrConsts.height / 2, TrConsts.height / 2],
[TrConsts.height / 2, -TrConsts.height / 2 + TrConsts.lineWidth / 2],
[TrConsts.height / 2, 0],
[0, TrConsts.height / 2],
],
};
return transponderTypePoints[type];
}
export const TransponderConstsMap = new Map<CategoryType, TransponderConstsConfig>([[CategoryType.JK,THConsts],[CategoryType.TH,THConsts]])
export type UpdateTransponderConsts = Partial<ITransponderConsts>;
export function getTransponderConsts() {
const transponderConsts = {
height: 12,
lineWidth: 2,
lineColor: '0xFFFFFF',
wblineColor: '0xFF0000',
textFontSize: 12,
textMarginY: 5, // 名称与应答器的距离
vblineColor: '0xFF00FF',
iblineColor: '0x0000FF',
};
return transponderConsts;
}