diff --git a/public/drawIcon.svg b/public/drawIcon.svg index 65cadd3..15c7d92 100644 --- a/public/drawIcon.svg +++ b/public/drawIcon.svg @@ -127,4 +127,11 @@ + + + + + + + diff --git a/src/drawApp/graphics/FAS/AcsInteraction.ts b/src/drawApp/graphics/FAS/AcsInteraction.ts new file mode 100644 index 0000000..2faeca8 --- /dev/null +++ b/src/drawApp/graphics/FAS/AcsInteraction.ts @@ -0,0 +1,38 @@ +import * as pb_1 from 'google-protobuf'; +import { GraphicDataBase } from '../GraphicDataBase'; +import { Acs, IAcsData } from 'src/graphics/FAS/acs/Acs'; +import { iscsGraphicData } from 'src/protos/iscs_graphic_data'; + +export class AcsData extends GraphicDataBase implements IAcsData { + constructor(data?: iscsGraphicData.Acs) { + let acs; + if (data) { + acs = data; + } else { + acs = new iscsGraphicData.Acs({ + common: GraphicDataBase.defaultCommonInfo(Acs.Type), + }); + } + super(acs); + } + + public get data(): iscsGraphicData.Acs { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + clone(): AcsData { + return new AcsData(this.data.cloneMessage()); + } + copyFrom(data: AcsData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: AcsData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/graphics/FAS/SprayPumpInteraction.ts b/src/drawApp/graphics/FAS/SprayPumpInteraction.ts new file mode 100644 index 0000000..1790522 --- /dev/null +++ b/src/drawApp/graphics/FAS/SprayPumpInteraction.ts @@ -0,0 +1,41 @@ +import * as pb_1 from 'google-protobuf'; +import { GraphicDataBase } from '../GraphicDataBase'; +import { + SprayPump, + ISprayPumpData, +} from 'src/graphics/FAS/sprayPump/SprayPump'; +import { iscsGraphicData } from 'src/protos/iscs_graphic_data'; + +export class SprayPumpData extends GraphicDataBase implements ISprayPumpData { + constructor(data?: iscsGraphicData.SprayPump) { + let sprayPump; + if (data) { + sprayPump = data; + } else { + sprayPump = new iscsGraphicData.SprayPump({ + common: GraphicDataBase.defaultCommonInfo(SprayPump.Type), + }); + } + super(sprayPump); + } + + public get data(): iscsGraphicData.SprayPump { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + clone(): SprayPumpData { + return new SprayPumpData(this.data.cloneMessage()); + } + copyFrom(data: SprayPumpData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: SprayPumpData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/graphics/FAS/StabilizedPressurePumpInteraction.ts b/src/drawApp/graphics/FAS/StabilizedPressurePumpInteraction.ts new file mode 100644 index 0000000..1b3ee53 --- /dev/null +++ b/src/drawApp/graphics/FAS/StabilizedPressurePumpInteraction.ts @@ -0,0 +1,44 @@ +import * as pb_1 from 'google-protobuf'; +import { GraphicDataBase } from '../GraphicDataBase'; +import { iscsGraphicData } from 'src/protos/iscs_graphic_data'; +import { + StabilizedPressurePump, + IStabilizedPressurePumpData, +} from 'src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump'; + +export class StabilizedPressurePumpData + extends GraphicDataBase + implements IStabilizedPressurePumpData +{ + constructor(data?: iscsGraphicData.StabilizedPressurePump) { + let stabilizedPressurePump; + if (data) { + stabilizedPressurePump = data; + } else { + stabilizedPressurePump = new iscsGraphicData.StabilizedPressurePump({ + common: GraphicDataBase.defaultCommonInfo(StabilizedPressurePump.Type), + }); + } + super(stabilizedPressurePump); + } + + public get data(): iscsGraphicData.StabilizedPressurePump { + return this.getData(); + } + + get code(): string { + return this.data.code; + } + set code(v: string) { + this.data.code = v; + } + clone(): StabilizedPressurePumpData { + return new StabilizedPressurePumpData(this.data.cloneMessage()); + } + copyFrom(data: StabilizedPressurePumpData): void { + pb_1.Message.copyInto(data.data, this.data); + } + eq(other: StabilizedPressurePumpData): boolean { + return pb_1.Message.equals(this.data, other.data); + } +} diff --git a/src/drawApp/iscsApp.ts b/src/drawApp/iscsApp.ts index c7738cc..457e5a5 100644 --- a/src/drawApp/iscsApp.ts +++ b/src/drawApp/iscsApp.ts @@ -68,6 +68,21 @@ import { EscalatorData } from './graphics/BAS/EscalatorInteraction'; import { FirePump, FirePumpTemplate } from 'src/graphics/FAS/firePump/FirePump'; import { FirePumpDraw } from 'src/graphics/FAS/firePump/FirePumpAssistant'; import { FirePumpData } from './graphics/FAS/FirePumpInteraction'; +import { SprayPumpDraw } from 'src/graphics/FAS/sprayPump/SprayPumpAssistant'; +import { + SprayPump, + SprayPumpTemplate, +} from 'src/graphics/FAS/sprayPump/SprayPump'; +import { SprayPumpData } from './graphics/FAS/SprayPumpInteraction'; +import { StabilizedPressurePumpData } from './graphics/FAS/StabilizedPressurePumpInteraction'; +import { StabilizedPressurePumpDraw } from 'src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePumpAssistant'; +import { + StabilizedPressurePump, + StabilizedPressurePumpTemplate, +} from 'src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump'; +import { AcsDraw } from 'src/graphics/FAS/acs/AcsAssistant'; +import { Acs, AcsTemplate } from 'src/graphics/FAS/acs/Acs'; +import { AcsData } from './graphics/FAS/AcsInteraction'; // import { getOnlyToken } from 'src/configs/TokenManage'; let drawApp: IDrawApp | null = null; @@ -122,6 +137,12 @@ export function initIscsDrawApp(): IDrawApp { ); new FireShutterDraw(app, new FireShutterTemplate(new FireShutterData())); new FirePumpDraw(app, new FirePumpTemplate(new FirePumpData())); + new SprayPumpDraw(app, new SprayPumpTemplate(new SprayPumpData())); + new StabilizedPressurePumpDraw( + app, + new StabilizedPressurePumpTemplate(new StabilizedPressurePumpData()) + ); + new AcsDraw(app, new AcsTemplate(new AcsData())); app.addKeyboardListener( new KeyListener({ @@ -310,6 +331,19 @@ export async function loadDrawDatas(): Promise { fasOfPlatformAlarm.firePumps.forEach((firePump) => { datas.push(new FirePumpData(firePump)); }); + fasOfPlatformAlarm.sprayPumps.forEach((sprayPump) => { + datas.push(new SprayPumpData(sprayPump)); + }); + fasOfPlatformAlarm.stabilizedPressurePumps.forEach( + (stabilizedPressurePump) => { + datas.push( + new StabilizedPressurePumpData(stabilizedPressurePump) + ); + } + ); + fasOfPlatformAlarm.acs.forEach((acs) => { + datas.push(new AcsData(acs)); + }); break; } } @@ -452,6 +486,17 @@ export function saveDrawDatas(app: IDrawApp) { } else if (g instanceof FirePump) { const firePumpData = g.saveData(); fasStorage.firePumps.push((firePumpData as FirePumpData).data); + } else if (g instanceof SprayPump) { + const sprayPumpData = g.saveData(); + fasStorage.sprayPumps.push((sprayPumpData as SprayPumpData).data); + } else if (g instanceof StabilizedPressurePump) { + const stabilizedPressurePumpData = g.saveData(); + fasStorage.stabilizedPressurePumps.push( + (stabilizedPressurePumpData as StabilizedPressurePumpData).data + ); + } else if (g instanceof Acs) { + const acsData = g.saveData(); + fasStorage.acs.push((acsData as AcsData).data); } }); storage.fasOfPlatformAlarmStorages[i] = fasStorage; diff --git a/src/graphics/FAS/acs/Acs.ts b/src/graphics/FAS/acs/Acs.ts new file mode 100644 index 0000000..025f053 --- /dev/null +++ b/src/graphics/FAS/acs/Acs.ts @@ -0,0 +1,70 @@ +import { Graphics } from 'pixi.js'; +import { + GraphicData, + JlGraphic, + JlGraphicTemplate, + VectorText, +} from 'jl-graphic'; + +export interface IAcsData extends GraphicData { + get code(): string; // 编号 + set code(v: string); + clone(): IAcsData; + copyFrom(data: IAcsData): void; + eq(other: IAcsData): boolean; +} + +const acsConsts = { + rectWidth: 64, + rectHeight: 24, + rectBackground: '0x99ccff', + textColor: '0x33cc00', + text: 'ACS联动', + fontSize: 12, +}; + +export class Acs extends JlGraphic { + static Type = 'Acs'; + rectGraphic: Graphics = new Graphics(); + textGraphic: VectorText = new VectorText(); + constructor() { + console.log('22222222'); + super(Acs.Type); + this.addChild(this.rectGraphic); + this.addChild(this.textGraphic); + } + + get datas(): IAcsData { + return this.getDatas(); + } + doRepaint(): void { + console.log('111111111'); + const rectGraphic = this.rectGraphic; + rectGraphic.clear(); + rectGraphic.beginFill(acsConsts.rectBackground); + rectGraphic.drawRect(0, 0, acsConsts.rectWidth, acsConsts.rectHeight); + rectGraphic.endFill(); + + this.textGraphic.text = acsConsts.text; + this.textGraphic.setVectorFontSize(acsConsts.fontSize); + this.textGraphic.anchor.set(0.5); + this.textGraphic.style.fill = acsConsts.textColor; + this.textGraphic.position.set( + acsConsts.rectWidth / 2, + acsConsts.rectHeight / 2 + ); + } +} + +export class AcsTemplate extends JlGraphicTemplate { + constructor(dataTemplate: IAcsData) { + super(Acs.Type, { + dataTemplate, + }); + } + new(): Acs { + const acs = new Acs(); + acs.loadData(this.datas); + return acs; + } +} diff --git a/src/graphics/FAS/acs/AcsAssistant.ts b/src/graphics/FAS/acs/AcsAssistant.ts new file mode 100644 index 0000000..e42164b --- /dev/null +++ b/src/graphics/FAS/acs/AcsAssistant.ts @@ -0,0 +1,112 @@ +import { DisplayObject, FederatedMouseEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + GraphicTransformEvent, + IDrawApp, + JlGraphic, +} from 'jl-graphic'; +import { IAcsData, Acs, AcsTemplate } from './Acs'; + +export class AcsDraw extends GraphicDrawAssistant { + _acs: Acs | null = null; + constructor(app: IDrawApp, template: AcsTemplate) { + super(app, template, 'svguse:../drawIcon.svg#icon-fas-alarm', 'ACS'); + AcsInteraction.init(app); + } + + bind(): void { + super.bind(); + if (!this._acs) { + this._acs = this.graphicTemplate.new(); + this.container.addChild(this._acs); + this._acs.doRepaint(); + } + } + + public get acs(): Acs { + if (!this._acs) { + this._acs = this.graphicTemplate.new(); + this.container.addChild(this._acs); + } + return this._acs; + } + + redraw(cp: Point): void { + console.log(this.acs, '==='); + this.acs.position.copyFrom(cp); + } + onLeftUp(e: FederatedMouseEvent): void { + this.acs.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + prepareData(data: IAcsData): boolean { + data.transform = this.acs.saveTransform(); + return true; + } + onEsc(): void { + this.finish(); + } +} + +/** + * 构建吸附线 + * @param fasAlarm + */ +function buildAbsorbablePositions(acs: Acs): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const acses = acs.queryStore.queryByType(Acs.Type); + const canvas = acs.getCanvas(); + acses.forEach((item) => { + if (item.id === acs.id) { + return; + } + const ala = new AbsorbableLine( + new Point(item.x, 0), + new Point(item.x, canvas.height) + ); + const alb = new AbsorbableLine( + new Point(0, item.y), + new Point(canvas.width, item.y) + ); + aps.push(ala); + aps.push(alb); + }); + + return aps; +} + +export class AcsInteraction extends GraphicInteractionPlugin { + static Name = 'acs_transform'; + constructor(app: IDrawApp) { + super(AcsInteraction.Name, app); + } + static init(app: IDrawApp) { + return new AcsInteraction(app); + } + filter(...grahpics: JlGraphic[]): Acs[] | undefined { + return grahpics.filter((g) => g.type === Acs.Type).map((g) => g as Acs); + } + bind(g: Acs): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.scalable = true; + g.rotatable = true; + g.on('transformstart', this.transformstart, this); + } + unbind(g: Acs): void { + g.eventMode = 'none'; + g.scalable = false; + g.rotatable = false; + g.off('transformstart', this.transformstart, this); + } + transformstart(e: GraphicTransformEvent) { + const target = e.target as DisplayObject; + const acs = target.getGraphic() as Acs; + acs.getGraphicApp().setOptions({ + absorbablePositions: buildAbsorbablePositions(acs), + }); + } +} diff --git a/src/graphics/FAS/sprayPump/SprayPump.json b/src/graphics/FAS/sprayPump/SprayPump.json new file mode 100644 index 0000000..9ce17f2 --- /dev/null +++ b/src/graphics/FAS/sprayPump/SprayPump.json @@ -0,0 +1,21 @@ +{ + "frames": { + "normal.png": { + "frame": { "x": 0, "y": 0, "w": 22, "h": 46 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 22, "h": 46 }, + "sourceSize": { "w": 22, "h": 46 }, + "anchor": { "x": 0.5, "y": 0.5 } + } + }, + "meta": { + "app": "https://www.codeandweb.com/texturepacker", + "version": "1.1", + "image": "SprayPump.png", + "format": "RGBA8888", + "size": { "w": 27, "h": 26 }, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:e7620bd2d73cc0b3e2deea9704e7eefc:f129a1d9e4b9ba57720b3861c22b155b:eb2d421f7759984b7713aa4aa5354134$" + } +} diff --git a/src/graphics/FAS/sprayPump/SprayPump.png b/src/graphics/FAS/sprayPump/SprayPump.png new file mode 100644 index 0000000..01acaf8 Binary files /dev/null and b/src/graphics/FAS/sprayPump/SprayPump.png differ diff --git a/src/graphics/FAS/sprayPump/SprayPump.ts b/src/graphics/FAS/sprayPump/SprayPump.ts new file mode 100644 index 0000000..5d95efc --- /dev/null +++ b/src/graphics/FAS/sprayPump/SprayPump.ts @@ -0,0 +1,63 @@ +import { GraphicData, JlGraphic, JlGraphicTemplate } from 'jl-graphic'; +import { Assets, Sprite, Spritesheet, Texture } from 'pixi.js'; +// import { iscsGraphicData } from 'src/protos/iscs_graphic_data'; +import SprayPumpJson from './SprayPump.json'; +import SparyPumpAssets from './SprayPump.png'; + +export interface ISprayPumpData extends GraphicData { + get code(): string; + set code(v: string); +} + +interface SprayPumpTextures { + normal: Texture; +} + +export class SprayPump extends JlGraphic { + static Type = 'SprayPump'; + _sprayPump: Sprite; + sprayPumpTextures: SprayPumpTextures; + __state = 0; + + constructor(sprayPumpTextures: SprayPumpTextures) { + super(SprayPump.Type); + this._sprayPump = new Sprite(); + this.sprayPumpTextures = sprayPumpTextures; + this._sprayPump.anchor.set(0.5); + this.addChild(this._sprayPump); + this._sprayPump.texture = this.sprayPumpTextures.normal; + } + get code(): string { + return this.datas.code; + } + get datas(): ISprayPumpData { + return this.getDatas(); + } + + doRepaint(): void {} +} + +export class SprayPumpTemplate extends JlGraphicTemplate { + sprayPumpTextures?: SprayPumpTextures; + constructor(dataTemplate: ISprayPumpData) { + super(SprayPump.Type, { dataTemplate }); + this.loadAssets(); + } + new(): SprayPump { + if (this.sprayPumpTextures) { + const g = new SprayPump(this.sprayPumpTextures); + g.loadData(this.datas); + return g; + } + throw new Error('资源未加载/加载失败'); + } + async loadAssets(): Promise { + const texture = await Assets.load(SparyPumpAssets); + const sprayPumpSheet = new Spritesheet(texture, SprayPumpJson); + const result = await sprayPumpSheet.parse(); + this.sprayPumpTextures = { + normal: result['normal.png'], + }; + return this.sprayPumpTextures as SprayPumpTextures; + } +} diff --git a/src/graphics/FAS/sprayPump/SprayPumpAssistant.ts b/src/graphics/FAS/sprayPump/SprayPumpAssistant.ts new file mode 100644 index 0000000..a58adf4 --- /dev/null +++ b/src/graphics/FAS/sprayPump/SprayPumpAssistant.ts @@ -0,0 +1,117 @@ +import { DisplayObject, FederatedMouseEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + GraphicTransformEvent, + IDrawApp, + JlGraphic, +} from 'jl-graphic'; +import { ISprayPumpData, SprayPump, SprayPumpTemplate } from './SprayPump'; + +export class SprayPumpDraw extends GraphicDrawAssistant< + SprayPumpTemplate, + ISprayPumpData +> { + _sprayPump: SprayPump | null = null; + constructor(app: IDrawApp, template: SprayPumpTemplate) { + super(app, template, 'svguse:../drawIcon.svg#icon-spray-pump', '喷淋泵'); + SprayPumpInteraction.init(app); + } + + bind(): void { + super.bind(); + if (!this._sprayPump) { + this._sprayPump = this.graphicTemplate.new(); + this.container.addChild(this._sprayPump); + } + } + + public get sprayPump(): SprayPump { + if (!this._sprayPump) { + this._sprayPump = this.graphicTemplate.new(); + this.container.addChild(this._sprayPump); + } + return this._sprayPump; + } + + redraw(cp: Point): void { + this.sprayPump.position.copyFrom(cp); + } + onLeftUp(e: FederatedMouseEvent): void { + this.sprayPump.position.copyFrom(this.toCanvasCoordinates(e.global)); + this.createAndStore(true); + } + prepareData(data: ISprayPumpData): boolean { + data.transform = this.sprayPump.saveTransform(); + return true; + } + onEsc(): void { + this.finish(); + } +} + +/** + * 构建吸附线 + * @param sprayPump + */ +function buildAbsorbablePositions(sprayPump: SprayPump): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const sprayPumps = sprayPump.queryStore.queryByType( + SprayPump.Type + ); + const canvas = sprayPump.getCanvas(); + sprayPumps.forEach((item) => { + if (item.id === sprayPump.id) { + return; + } + const ala = new AbsorbableLine( + new Point(item.x, 0), + new Point(item.x, canvas.height) + ); + const alb = new AbsorbableLine( + new Point(0, item.y), + new Point(canvas.width, item.y) + ); + aps.push(ala); + aps.push(alb); + }); + + return aps; +} + +export class SprayPumpInteraction extends GraphicInteractionPlugin { + static Name = 'spary_pump_transform'; + constructor(app: IDrawApp) { + super(SprayPumpInteraction.Name, app); + } + static init(app: IDrawApp) { + return new SprayPumpInteraction(app); + } + filter(...grahpics: JlGraphic[]): SprayPump[] | undefined { + return grahpics + .filter((g) => g.type === SprayPump.Type) + .map((g) => g as SprayPump); + } + bind(g: SprayPump): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.scalable = true; + g.rotatable = true; + g.on('transformstart', this.transformstart, this); + } + unbind(g: SprayPump): void { + g.eventMode = 'none'; + g.scalable = false; + g.rotatable = false; + g.off('transformstart', this.transformstart, this); + } + transformstart(e: GraphicTransformEvent) { + const target = e.target as DisplayObject; + const sprayPump = target.getGraphic() as SprayPump; + sprayPump.getGraphicApp().setOptions({ + absorbablePositions: buildAbsorbablePositions(sprayPump), + }); + } +} diff --git a/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.json b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.json new file mode 100644 index 0000000..b05230f --- /dev/null +++ b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.json @@ -0,0 +1,21 @@ +{ + "frames": { + "normal.png": { + "frame": { "x": 0, "y": 0, "w": 36, "h": 25 }, + "rotated": false, + "trimmed": false, + "spriteSourceSize": { "x": 0, "y": 0, "w": 36, "h": 25 }, + "sourceSize": { "w": 27, "h": 26 }, + "anchor": { "x": 0.5, "y": 0.5 } + } + }, + "meta": { + "app": "https://www.codeandweb.com/texturepacker", + "version": "1.1", + "image": "StabilizedPressurePump.png", + "format": "RGBA8888", + "size": { "w": 36, "h": 25 }, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:e7620bd2d73cc0b3e2deea9704e7eefc:f129a1d9e4b9ba57720b3861c22b155b:eb2d421f7759984b7713aa4aa5354134$" + } +} diff --git a/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.png b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.png new file mode 100644 index 0000000..b36ecb0 Binary files /dev/null and b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.png differ diff --git a/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.ts b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.ts new file mode 100644 index 0000000..7211862 --- /dev/null +++ b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump.ts @@ -0,0 +1,68 @@ +import { GraphicData, JlGraphic, JlGraphicTemplate } from 'jl-graphic'; +import { Assets, Sprite, Spritesheet, Texture } from 'pixi.js'; +// import { iscsGraphicData } from 'src/protos/iscs_graphic_data'; +import StabilizedPressurePumpJson from './StabilizedPressurePump.json'; +import StabilizedPressurePumpAssets from './StabilizedPressurePump.png'; + +export interface IStabilizedPressurePumpData extends GraphicData { + get code(): string; + set code(v: string); +} + +interface StabilizedPressurePumpTextures { + normal: Texture; +} + +export class StabilizedPressurePump extends JlGraphic { + static Type = 'StabilizedPressurePump'; + _stabilizedPressurePump: Sprite; + stabilizedPressurePumpTextures: StabilizedPressurePumpTextures; + __state = 0; + + constructor(stabilizedPressurePumpTextures: StabilizedPressurePumpTextures) { + super(StabilizedPressurePump.Type); + this._stabilizedPressurePump = new Sprite(); + this.stabilizedPressurePumpTextures = stabilizedPressurePumpTextures; + this._stabilizedPressurePump.anchor.set(0.5); + this.addChild(this._stabilizedPressurePump); + this._stabilizedPressurePump.texture = + this.stabilizedPressurePumpTextures.normal; + } + get code(): string { + return this.datas.code; + } + get datas(): IStabilizedPressurePumpData { + return this.getDatas(); + } + + doRepaint(): void {} +} + +export class StabilizedPressurePumpTemplate extends JlGraphicTemplate { + stabilizedPressurePumpTextures?: StabilizedPressurePumpTextures; + constructor(dataTemplate: IStabilizedPressurePumpData) { + super(StabilizedPressurePump.Type, { dataTemplate }); + this.loadAssets(); + } + new(): StabilizedPressurePump { + if (this.stabilizedPressurePumpTextures) { + const g = new StabilizedPressurePump(this.stabilizedPressurePumpTextures); + g.loadData(this.datas); + return g; + } + throw new Error('资源未加载/加载失败'); + } + async loadAssets(): Promise { + const texture = await Assets.load(StabilizedPressurePumpAssets); + const stabilizedPressurePumpSheet = new Spritesheet( + texture, + StabilizedPressurePumpJson + ); + const result = await stabilizedPressurePumpSheet.parse(); + this.stabilizedPressurePumpTextures = { + normal: result['normal.png'], + }; + return this + .stabilizedPressurePumpTextures as StabilizedPressurePumpTextures; + } +} diff --git a/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePumpAssistant.ts b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePumpAssistant.ts new file mode 100644 index 0000000..20fc1a7 --- /dev/null +++ b/src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePumpAssistant.ts @@ -0,0 +1,132 @@ +import { DisplayObject, FederatedMouseEvent, Point } from 'pixi.js'; +import { + AbsorbableLine, + AbsorbablePosition, + GraphicDrawAssistant, + GraphicInteractionPlugin, + GraphicTransformEvent, + IDrawApp, + JlGraphic, +} from 'jl-graphic'; +import { + StabilizedPressurePump, + IStabilizedPressurePumpData, + StabilizedPressurePumpTemplate, +} from './StabilizedPressurePump'; + +export class StabilizedPressurePumpDraw extends GraphicDrawAssistant< + StabilizedPressurePumpTemplate, + IStabilizedPressurePumpData +> { + _stabilizedPressurePump: StabilizedPressurePump | null = null; + constructor(app: IDrawApp, template: StabilizedPressurePumpTemplate) { + super( + app, + template, + 'svguse:../drawIcon.svg#icon-stabilized-pressure-pump', + '稳压泵' + ); + StabilizedPressurePumpInteraction.init(app); + } + + bind(): void { + super.bind(); + if (!this._stabilizedPressurePump) { + this._stabilizedPressurePump = this.graphicTemplate.new(); + this.container.addChild(this._stabilizedPressurePump); + } + } + + public get stabilizedPressurePump(): StabilizedPressurePump { + if (!this._stabilizedPressurePump) { + this._stabilizedPressurePump = this.graphicTemplate.new(); + this.container.addChild(this._stabilizedPressurePump); + } + return this._stabilizedPressurePump; + } + + redraw(cp: Point): void { + this.stabilizedPressurePump.position.copyFrom(cp); + } + onLeftUp(e: FederatedMouseEvent): void { + this.stabilizedPressurePump.position.copyFrom( + this.toCanvasCoordinates(e.global) + ); + this.createAndStore(true); + } + prepareData(data: IStabilizedPressurePumpData): boolean { + data.transform = this.stabilizedPressurePump.saveTransform(); + return true; + } + onEsc(): void { + this.finish(); + } +} + +/** + * 构建吸附线 + * @param stabilizedPressurePump + */ +function buildAbsorbablePositions( + stabilizedPressurePump: StabilizedPressurePump +): AbsorbablePosition[] { + const aps: AbsorbablePosition[] = []; + const stabilizedPressurePumps = + stabilizedPressurePump.queryStore.queryByType( + StabilizedPressurePump.Type + ); + const canvas = stabilizedPressurePump.getCanvas(); + stabilizedPressurePumps.forEach((item) => { + if (item.id === stabilizedPressurePump.id) { + return; + } + const ala = new AbsorbableLine( + new Point(item.x, 0), + new Point(item.x, canvas.height) + ); + const alb = new AbsorbableLine( + new Point(0, item.y), + new Point(canvas.width, item.y) + ); + aps.push(ala); + aps.push(alb); + }); + + return aps; +} + +export class StabilizedPressurePumpInteraction extends GraphicInteractionPlugin { + static Name = 'stabilized_pressure_pump_transform'; + constructor(app: IDrawApp) { + super(StabilizedPressurePumpInteraction.Name, app); + } + static init(app: IDrawApp) { + return new StabilizedPressurePumpInteraction(app); + } + filter(...grahpics: JlGraphic[]): StabilizedPressurePump[] | undefined { + return grahpics + .filter((g) => g.type === StabilizedPressurePump.Type) + .map((g) => g as StabilizedPressurePump); + } + bind(g: StabilizedPressurePump): void { + g.eventMode = 'static'; + g.cursor = 'pointer'; + g.scalable = true; + g.rotatable = true; + g.on('transformstart', this.transformstart, this); + } + unbind(g: StabilizedPressurePump): void { + g.eventMode = 'none'; + g.scalable = false; + g.rotatable = false; + g.off('transformstart', this.transformstart, this); + } + transformstart(e: GraphicTransformEvent) { + const target = e.target as DisplayObject; + const stabilizedPressurePump = + target.getGraphic() as StabilizedPressurePump; + stabilizedPressurePump.getGraphicApp().setOptions({ + absorbablePositions: buildAbsorbablePositions(stabilizedPressurePump), + }); + } +} diff --git a/src/layouts/IscsDrawLayout.vue b/src/layouts/IscsDrawLayout.vue index 26a5637..91ca8a9 100644 --- a/src/layouts/IscsDrawLayout.vue +++ b/src/layouts/IscsDrawLayout.vue @@ -314,6 +314,9 @@ import { Escalator } from 'src/graphics/BAS/escalator/Escalator'; import { TemperatureDetector } from 'src/graphics/FAS/temperatureDetector/TemperatureDetector'; import { FireShutter } from 'src/graphics/FAS/fireShutter/FireShutter'; import { FirePump } from 'src/graphics/FAS/firePump/FirePump'; +import { SprayPump } from 'src/graphics/FAS/sprayPump/SprayPump'; +import { StabilizedPressurePump } from 'src/graphics/FAS/stabilizedPressurePump/StabilizedPressurePump'; +import { Acs } from 'src/graphics/FAS/acs/Acs'; const $q = useQuasar(); const route = useRoute(); @@ -405,6 +408,9 @@ function handleUtilsOption() { drawAssistantsTypes.push(TemperatureDetector.Type); drawAssistantsTypes.push(FireShutter.Type); drawAssistantsTypes.push(FirePump.Type); + drawAssistantsTypes.push(SprayPump.Type); + drawAssistantsTypes.push(StabilizedPressurePump.Type); + drawAssistantsTypes.push(Acs.Type); break; } drawAssistantsTypes.forEach((type) => {