上海预案管理平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1248 lines
41 KiB

import { Component, OnInit, ElementRef, ViewChild, AfterViewInit, Input } from '@angular/core';
import * as PIXI from 'pixi.js';
import { EventEmitter } from 'events';
import { EventManager } from '@angular/platform-browser';
import { OutlineFilter, OldFilmFilter } from 'pixi-filters';
import { CanvasShareDataService } from '../canvas-share-data.service';
import * as ObjectID from 'bson-objectid';
import { Charm } from './charm';
import { SinglePointIcon } from './model/singlePointIcon';
import { GameMode } from './model/gameMode';
import { MultipointIcon } from './model/multipointIcon';
import { PolygonIcon } from './model/polygonIcon';
import { PutCarArea } from './model/putCarArea';
import { Arrows } from './model/arrows';
import { Pipeline } from './model/pipeline';
import { PaintMode } from './model/paintModel';
@Component({
selector: 'app-working-area',
templateUrl: './working-area.component.html',
styleUrls: ['./working-area.component.scss']
})
/**
*
*/
export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterViewInit {
constructor(private eventManager: EventManager, public canvasData: CanvasShareDataService) {
super();
}
@ViewChild('content')
content: ElementRef;
/**
*
*/
@Input() init: any;
/**
* pixijs
*/
public app: PIXI.Application;
/**
*
*/
public loader = PIXI.Loader.shared;
/**
*
*/
public backgroundImage: PIXI.Sprite;
/**
*
*/
public previewSinglePointIcon = new PIXI.Sprite();
/**
* 线
*/
public previewLineSegment = new PIXI.Graphics();
/**
*
*/
public circleShadow = new PIXI.Graphics();
/**
*
*/
public mousePosition: PIXI.Point = new PIXI.Point(0, 0);
/**
*
*/
private paintMode: PaintMode;
/**
*
*/
public selection: Selection = new Selection(this);
/**
*
*/
public currentClickPoint: PIXI.Graphics = new PIXI.Graphics();
/**
*
*/
public paintPoints: PIXI.Point[] = [];
/**
* 线
*/
public paintingPipeline: Pipeline = null;
/**
*
*/
public paintingArrows: Arrows = null;
/**
*
*/
public paintingIcon: MultipointIcon;
/**
* 线
*/
public paintingLine: PIXI.Graphics = new PIXI.Graphics();
/**
* 绿
*/
public outlineFilterGreen = new OutlineFilter(2, 0x00ff00);
/**
*
*/
public copyData: any[] = [];
/**
*
*/
private enterPaintEndButton = PIXI.Sprite.from('assets/images/enterPaintButton.png');
/**
*
*/
private rectToolGraphics = new PIXI.Graphics();
/**
*
*/
private initialScreenMousePos: PIXI.Point = new PIXI.Point();
/**
*
*/
private finalScreenMousePos: PIXI.Point = new PIXI.Point();
/**
*
*/
public allowEdit = true;
/**
*
*/
public animator;
public animation;
public animationIcon;
public animationTime;
// 车辆作业面
public carAreas: PolygonIcon[];
// 车辆数据
public carData: Map<string, any> = new Map<string, any>();
// 当前选择的车辆id
public selectCar: any = null;
/**
*
*/
ngOnInit(): void {
this.eventManager.addGlobalEventListener('window', 'keydown', (event: any) => {
if (event.keyCode === 17) {
this.selection.isMultiselection = true;
}
});
this.eventManager.addGlobalEventListener('window', 'keyup', (event: any) => {
if (event.keyCode === 17) {
this.selection.isMultiselection = false;
this.rectToolGraphics.visible = false;
this.rectToolGraphics.clear();
}
if (event.keyCode === 46) {
this.selection.objects.forEach(item => {
// 删除 选中的数据
if (item.assetData?.IsFromBuilding) {
delete this.canvasData.originalcompanyBuildingData?.data[item.assetData.Id];
} else {
delete this.canvasData.originaleveryStoreyData?.data[item.assetData.Id];
}
// 删除选中的图标
this.backgroundImage.removeChild(this.backgroundImage.getChildByName(item.assetData.Id));
// 标记
this.canvasData.isChange = true;
});
this.emit('deleteIcon');
}
});
}
/**
*
*/
ngAfterViewInit(): void {
this.createCanvas();
window.onresize = () => {
this.resizeCanvas();
};
}
/**
*
* @param event
*/
public mouseWheelHandel(event) {
const delX = this.mousePosition.x - this.backgroundImage.position.x;
const delY = this.mousePosition.y - this.backgroundImage.position.y;
const pivot = this.backgroundImage.toLocal(this.mousePosition);
const delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
if (delta > 0) {
if (this.backgroundImage.scale.x >= 32) {
this.backgroundImage.scale.x = 32;
this.backgroundImage.scale.y = 32;
this.emit('backgroundScale', this.backgroundImage.scale.x);
return;
}
this.backgroundImage.pivot.set(pivot.x, pivot.y);
this.backgroundImage.scale.x += this.backgroundImage.scale.x * 0.1;
this.backgroundImage.scale.y += this.backgroundImage.scale.y * 0.1;
this.backgroundImage.position.x += delX;
this.backgroundImage.position.y += delY;
} else if (delta < 0) {
if (this.backgroundImage.scale.x <= 0.1) {
this.backgroundImage.scale.x = 0.1;
this.backgroundImage.scale.y = 0.1;
this.emit('backgroundScale', this.backgroundImage.scale.x);
return;
}
this.backgroundImage.pivot.set(pivot.x, pivot.y);
this.backgroundImage.scale.x -= this.backgroundImage.scale.x * 0.1;
this.backgroundImage.scale.y -= this.backgroundImage.scale.y * 0.1;
this.backgroundImage.position.x += delX;
this.backgroundImage.position.y += delY;
}
this.emit('backgroundScale', this.backgroundImage.scale.x);
}
/**
*
* @param icon
*/
public moveIconToScreenCenter(icon) {
if (icon.parent === this.backgroundImage && (
icon.assetData.Type === 1 ||
icon.assetData.Type === 2 ||
icon.assetData.Type === 3 ||
icon.assetData.Type === 4
)) {
console.log(this.backgroundImage.position);
this.backgroundImage.pivot.set(icon.x, icon.y);
this.backgroundImage.position.set(771, 404);
clearTimeout(this.animationTime);
this.animation?.pause();
this.animationIcon?.scale.set(1);
this.animation = this.animator.breathe(icon, 10, 10, 30, true, 0);
this.animationIcon = icon;
this.animationTime = setTimeout(() => {
this.animation?.pause();
this.animationIcon?.scale.set(1);
}, 5000);
}
}
/**
*
*/
private createCanvas(): void {
this.app = new PIXI.Application({
width: this.content.nativeElement.clientWidth,
height: this.content.nativeElement.clientHeight,
antialias: true,
transparent: false,
resolution: 1,
backgroundColor: 0xE9FAFF
});
this.content.nativeElement.appendChild(this.app.view);
this.animator = new Charm(PIXI);
this.app.ticker.add((delta) => {
this.animator.update();
this.mousePosition = this.app.renderer.plugins.interaction.mouse.global;
if (this.backgroundImage !== undefined) {
this.previewSinglePointIcon.position = this.backgroundImage.toLocal(this.mousePosition);
this.circleShadow.position = this.backgroundImage.toLocal(this.mousePosition);
this.refreshPreviewLineSegment(this.currentClickPoint.position, this.circleShadow.position);
}
if (this.rectToolGraphics.visible === true) {
const init = this.initialScreenMousePos;
const final = this.finalScreenMousePos;
this.rectToolGraphics.clear();
this.rectToolGraphics.lineStyle(2, 0x00ff00, 1);
this.rectToolGraphics.beginFill(0xccccf2, 0.25);
this.rectToolGraphics.drawRect(init.x, init.y, final.x - init.x, final.y - init.y);
this.rectToolGraphics.endFill();
this.rectToolGraphics.closePath();
}
if (this.paintingArrows !== null) {
this.paintingArrows.assetData.pointB = new PIXI.Point(this.circleShadow.position.x, this.circleShadow.position.y);
this.paintingArrows.refresh();
}
});
this.on('select', obj => {
this.moveIconToScreenCenter(obj);
if (this.allowEdit) {
if (obj instanceof MultipointIcon) {
obj.setPointVisiable(true);
} else if (obj instanceof PolygonIcon) {
obj.setPointVisiable(true);
} else {
obj.filters = [this.outlineFilterGreen];
}
} else {
obj.filters = [this.outlineFilterGreen];
}
});
this.on('deselect', obj => {
if (this.allowEdit) {
if (obj instanceof MultipointIcon) {
obj.setPointVisiable(false);
} else if (obj instanceof PolygonIcon) {
obj.setPointVisiable(false);
} else {
obj.filters = [];
}
} else {
obj.filters = [];
}
});
this.on('backgroundScale', scale => {
this.previewSinglePointIcon.scale.set(1 / this.backgroundImage.scale.x);
this.backgroundImage.children.forEach(item => {
if (item instanceof SinglePointIcon) {
if (item.assetData.FixedSize) {
const data = 1 / scale;
item.scale.set(data);
} else {
const data = 1 / scale;
item.text.scale.set(data);
}
} else if (item instanceof MultipointIcon) {
const data = 1 / scale;
item.text.scale.set(data);
} else if (item instanceof PolygonIcon) {
const data = 1 / scale;
item.text.scale.set(data);
}
});
});
this.on('createIcon', obj => {
if (obj.assetData.GameMode === GameMode.BasicInformation) {
if (obj.assetData.IsFromBuilding) {
this.canvasData.originalcompanyBuildingData.data[obj.assetData.Id] = obj.assetData;
} else {
this.canvasData.originaleveryStoreyData.data[obj.assetData.Id] = obj.assetData;
}
} else {
this.canvasData.selectPanelPoint.Data.Stock[obj.assetData.Id] = obj.assetData;
}
this.canvasData.isChange = true;
});
}
/**
*
*/
public resizeCanvas() {
this.app.renderer.resize(this.content.nativeElement.clientWidth, this.content.nativeElement.clientHeight);
}
/**
*
* @param value true false
* @param mode BasicInformation = 0 Assignment想定作业 = 1
*/
public setNameVisible(value: boolean, mode: GameMode): void {
this.backgroundImage?.children.forEach(item => {
if (item instanceof SinglePointIcon) {
item.setNameVisible(value, mode);
} else if (item instanceof MultipointIcon) {
item.setNameVisible(value, mode);
} else if (item instanceof PolygonIcon) {
item.setNameVisible(value, mode);
}
});
}
/**
* id刷新图标
* @param id id
*/
public refreshIcon(id: string): void {
const icon = this.backgroundImage.children.find(item => item.name === id);
if (icon instanceof SinglePointIcon) {
icon.refresh();
} else if (icon instanceof MultipointIcon) {
icon.refresh();
} else if (icon instanceof PolygonIcon) {
icon.refresh();
}
}
/**
*
* @param value
*/
public setIconScale(value: number): void {
this.backgroundImage.children.forEach(item => {
if (item instanceof SinglePointIcon) {
item.scale.set(value);
} else if (item instanceof MultipointIcon) {
} else if (item instanceof PolygonIcon) {
}
});
}
/**
*
*/
public setHighlight(ids: string[]): void {
this.selection.deselectAll();
ids.forEach(item => {
let obj = this.backgroundImage.getChildByName(item);
if (obj === null) {
obj = this.app.stage.getChildByName(item);
}
this.selection.select(obj);
});
}
/**
*
*/
public async refresh() {
this.resizeCanvas();
this.destroyBackgroundImage();
await this.createBackgroundImage(this.canvasData.selectStorey.imageUrl);
// this.refreshBackgroundImage();
this.versionChecking();
const floorData = this.canvasData.originaleveryStoreyData.data;
const buildingData = this.canvasData.originalcompanyBuildingData.data;
const floor = this.canvasData.selectStorey;
// // key=>属性名 data[key]=>属性值
Object.keys(floorData).forEach((key) => {
switch (floorData[key].InteractiveMode) {
case 0:
const singleIcon = new SinglePointIcon(floorData[key], this);
break;
case 1:
const icon = new MultipointIcon(floorData[key], this);
break;
case 2:
const polygonIcon = new PolygonIcon(floorData[key], this);
break;
}
});
Object.keys(buildingData).forEach((key) => {
if (buildingData[key].FloorId === floor.id) {
switch (buildingData[key].InteractiveMode) {
case 0:
const singleIcon = new SinglePointIcon(buildingData[key], this);
break;
case 1:
const icon = new MultipointIcon(buildingData[key], this);
break;
case 2:
const polygonIcon = new PolygonIcon(buildingData[key], this);
break;
}
}
});
const nodeData = this.canvasData.selectPanelPoint.Data;
if (nodeData !== undefined) {
Object.keys(nodeData).forEach((key) => {
Object.keys(nodeData[key]).forEach((tempKey) => {
switch (nodeData[key][tempKey].InteractiveMode) {
case 0:
const singleIcon = new SinglePointIcon(nodeData[key][tempKey], this);
break;
case 1:
const icon = new MultipointIcon(nodeData[key][tempKey], this);
break;
case 2:
const polygonIcon = new PolygonIcon(nodeData[key][tempKey], this);
break;
}
});
});
}
this.emit('backgroundScale', this.backgroundImage.scale.x);
}
/**
*
* @param id ID
* @param b /
*/
public setIconVisible(ids: string[], b: boolean) {
ids.forEach(item => {
this.backgroundImage.getChildByName(item).visible = b;
});
}
/**
*
*/
public versionChecking(): void {
const floorData = this.canvasData.originaleveryStoreyData;
const buildingData = this.canvasData.originalcompanyBuildingData;
const nodeData = this.canvasData.selectPanelPoint;
if (floorData.version && floorData.version === '1.0') {
floorData.version = '2.0';
Object.keys(floorData.data).forEach(item => {
floorData.data[item].Point.y *= -1;
floorData.data[item].MultiPoint?.forEach(element => {
element.y *= -1;
});
});
}
if (buildingData.version && buildingData.version === '1.0') {
buildingData.version = '2.0';
Object.keys(buildingData.data).forEach(item => {
buildingData.data[item].Point.y *= -1;
buildingData.data[item].MultiPoint?.forEach(element => {
element.y *= -1;
});
});
}
if (nodeData.Version && nodeData.Version === '1.0') {
nodeData.Version = '2.0';
Object.keys(nodeData.Data).forEach((key) => {
Object.keys(nodeData.Data[key]).forEach((tempKey) => {
nodeData.Data[key][tempKey].Point.y *= -1;
nodeData.Data[key][tempKey].MultiPoint?.forEach(element => {
element.y *= -1;
});
});
});
}
}
/**
*
*/
private createEnterPaintEndButton() {
this.enterPaintEndButton.width = 60;
this.enterPaintEndButton.height = 60;
this.enterPaintEndButton.anchor.set(0.5);
this.enterPaintEndButton.position = new PIXI.Point(0, 0);
this.enterPaintEndButton.interactive = true;
this.enterPaintEndButton.buttonMode = true;
this.enterPaintEndButton
.on('mousedown', event => {
event.stopPropagation();
this.enterPaint();
});
this.backgroundImage.addChild(this.enterPaintEndButton);
this.enterPaintEndButton.zIndex = this.backgroundImage.children.length;
this.enterPaintEndButton.visible = false;
}
/**
*
*/
private async createBackgroundImage(imageUrl: string): Promise<void> {
const image = await PIXI.Texture.fromURL(imageUrl);
this.backgroundImage = new PIXI.Sprite(image);
this.backgroundImage.anchor.set(0.5);
this.backgroundImage.x = this.app.view.width / 2;
this.backgroundImage.y = this.app.view.height / 2;
this.backgroundImage.interactive = true;
this.backgroundImage.name = 'background';
// const left = this.init.element.nativeElement.querySelector('.functionalDomainLeft').clientWidth;
// const right = this.init.element.nativeElement.querySelector('.functionalDomainRight').clientWidth;
const imageWidth = this.backgroundImage.texture.width;
const imageHeight = this.backgroundImage.texture.height;
const appWidth = this.app.view.width - 470;
const appHeight = this.app.view.height;
const wScale = appWidth / imageWidth;
const hScale = appHeight / imageHeight;
const scale = wScale < hScale
? wScale
: hScale;
this.backgroundImage.scale.set(scale);
this.backgroundImage.sortableChildren = true;
this.backgroundImage
.on('mousedown', event => {
if (!event.currentTarget.dragging && this.selection.isMultiselection === false) {
event.currentTarget.data = event.data;
event.currentTarget.dragging = true;
event.currentTarget.dragPoint = event.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.dragPoint.x -= event.currentTarget.x;
event.currentTarget.dragPoint.y -= event.currentTarget.y;
switch (this.paintMode) {
case PaintMode.endPaint:
console.log(this.backgroundImage.toLocal(this.mousePosition));
break;
case PaintMode.singlePointIcon:
const json = JSON.parse(JSON.stringify(this.canvasData.selectTemplateData.propertyInfos));
const list = [];
json.forEach(element => {
const property = new PropertyInfo(element);
list.push(property);
});
const assetData = {
TemplateId: this.canvasData.selectTemplateData.id,
FloorId: this.canvasData.selectStorey.id,
Angle: this.canvasData.selectTemplateData.angle,
Color: this.canvasData.selectTemplateData.color,
Enabled: this.canvasData.selectTemplateData.enabled,
FillMode: this.canvasData.selectTemplateData.fillMode,
FireElementId: this.canvasData.selectTemplateData.fireElementId,
FixedSize: this.canvasData.selectTemplateData.fixedSize,
Height : 32,
Width : 32,
Id: ObjectID.default.generate(),
ImageUrl: this.canvasData.selectTemplateData.imageUrl,
InteractiveMode: this.canvasData.selectTemplateData.interactiveMode,
MultiPoint : null,
Point: new PIXI.Point(this.previewSinglePointIcon.x, this.previewSinglePointIcon.y),
Name : this.canvasData.selectTemplateData.name,
PropertyInfos: list,
Border : this.canvasData.selectTemplateData.border,
DrawMode : this.canvasData.selectTemplateData.drawMode,
Thickness : this.canvasData.selectTemplateData.thickness,
IsFromBuilding : this.canvasData.selectTemplateData.isFromBuilding,
GameMode : this.canvasData.gameMode
};
const singleIcon = new SinglePointIcon(assetData, this);
this.emit('createIcon', singleIcon);
this.emit('backgroundScale', this.backgroundImage.scale.x);
break;
case PaintMode.lineIcon:
this.previewLineSegment.visible = true;
this.currentClickPoint.position = new PIXI.Point(this.circleShadow.x, this.circleShadow.y);
this.paintPoints.push(new PIXI.Point(this.circleShadow.x, this.circleShadow.y));
if (this.paintPoints.length >= 2) {
this.enterPaintEndButton.position = this.circleShadow.position;
this.enterPaintEndButton.visible = true;
}
if (this.paintingIcon !== null) {
this.backgroundImage.removeChild(this.paintingIcon);
}
const jsonObject = JSON.parse(JSON.stringify(this.canvasData.selectTemplateData.propertyInfos));
const propertyList = [];
jsonObject.forEach(element => {
const property = new PropertyInfo(element);
propertyList.push(property);
});
const assetData1 = {
TemplateId: this.canvasData.selectTemplateData.id,
FloorId: this.canvasData.selectStorey.id,
Angle: this.canvasData.selectTemplateData.angle,
Color: this.canvasData.selectTemplateData.color,
Enabled: this.canvasData.selectTemplateData.enabled,
FillMode: this.canvasData.selectTemplateData.fillMode,
FireElementId: this.canvasData.selectTemplateData.fireElementId,
FixedSize: this.canvasData.selectTemplateData.fixedSize,
Height: 32,
Width: 32,
Id: ObjectID.default.generate(),
ImageUrl: this.canvasData.selectTemplateData.imageUrl,
InteractiveMode: this.canvasData.selectTemplateData.interactiveMode,
MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)),
Point: new PIXI.Point(0, 0),
Name: this.canvasData.selectTemplateData.name,
PropertyInfos: propertyList,
Border: this.canvasData.selectTemplateData.border,
DrawMode: this.canvasData.selectTemplateData.drawMode,
Thickness: this.canvasData.selectTemplateData.thickness,
IsFromBuilding: this.canvasData.selectTemplateData.isFromBuilding,
GameMode: this.canvasData.gameMode
};
// const assetData1 = {
// ImageUrl: this.canvasData.selectTemplateData.imageUrl,
// Point: new PIXI.Point(0, 0),
// Width: 32,
// Height: 32,
// MultiPoint: this.paintPoints,
// Name: this.canvasData.selectTemplateData.name
// };
this.paintingIcon = new MultipointIcon(assetData1, this);
// this.paintingIcon = new MultipointIcon(this.previewSinglePointIcon.texture, new PIXI.Point(0, 0), this.paintPoints, this,
// this.canvasData.selectTemplateData.name);
this.emit('backgroundScale', this.backgroundImage.scale.x);
break;
case PaintMode.polygonIcon:
this.previewLineSegment.visible = true;
this.currentClickPoint.position = new PIXI.Point(this.circleShadow.x, this.circleShadow.y);
this.paintPoints.push(new PIXI.Point(this.circleShadow.x, this.circleShadow.y));
if (this.paintPoints.length === 1) {
this.enterPaintEndButton.position = this.circleShadow.position;
} else if (this.paintPoints.length >= 3) {
this.enterPaintEndButton.visible = true;
}
this.paintPoints.forEach((value, index, array) => {
if (index === 0) {
this.paintingLine.clear();
this.paintingLine.lineStyle(1, 0xffd900, 1);
this.paintingLine.moveTo(value.x, value.y);
} else {
this.paintingLine.lineTo(value.x, value.y);
}
});
// if (this.paintingIcon !== null) {
// this.backgroundImage.removeChild(this.paintingIcon);
// }
// this.paintingIcon = new PolygonIcon(this.paintPoints, this);
break;
case PaintMode.Pipeline:
if (this.paintingPipeline !== null) {
this.currentClickPoint.position = new PIXI.Point(this.circleShadow.x, this.circleShadow.y);
this.paintPoints.push(new PIXI.Point(this.circleShadow.x, this.circleShadow.y));
this.paintingPipeline.assetData.MultiPoint = JSON.parse(JSON.stringify(this.paintPoints));
this.paintingPipeline.refresh();
}
// this.emit('backgroundScale', this.backgroundImage.scale.x);
break;
case PaintMode.Arrows:
if (this.paintingArrows === null) {
const data = {
Id: ObjectID.default.generate(),
name: 'string',
point: new PIXI.Point(this.circleShadow.x, this.circleShadow.y),
pointA: new PIXI.Point(this.circleShadow.x, this.circleShadow.y),
pointB: new PIXI.Point(this.circleShadow.x, this.circleShadow.y),
source: 'assets/images/进攻方向.png',
};
this.paintingArrows = new Arrows(data, this);
} else {
this.paintingArrows.ready = true;
this.paintingArrows = null;
this.paintMode = PaintMode.endPaint;
}
break;
case PaintMode.Car:
// console.log('创建车辆');
break;
}
} else if (!event.currentTarget.dragging && this.selection.isMultiselection === true) {
this.rectToolGraphics.visible = true;
event.currentTarget.dragging = true;
this.initialScreenMousePos = this.backgroundImage.toLocal(this.mousePosition);
this.finalScreenMousePos = this.backgroundImage.toLocal(this.mousePosition);
}
})
.on('mouseup', event => {
if (event.currentTarget.dragging) {
event.currentTarget.dragging = false;
event.currentTarget.data = null;
}
if (this.rectToolGraphics.visible === true) {
this.backgroundImage.children.forEach(item => {
if (item instanceof SinglePointIcon
|| item instanceof MultipointIcon
|| item instanceof PolygonIcon) {
if (this.rectToolGraphics.getLocalBounds().contains(item.x, item.y)) {
this.selection.select(item);
}
}
});
this.rectToolGraphics.clear();
this.rectToolGraphics.visible = false;
}
})
.on('mouseupoutside', event => {
if (event.currentTarget.dragging) {
event.currentTarget.dragging = false;
event.currentTarget.data = null;
}
})
.on('mousemove', event => {
if (event.currentTarget.dragging && this.selection.isMultiselection === false) {
const newPosition = event.currentTarget.data.getLocalPosition(event.currentTarget.parent);
event.currentTarget.x = newPosition.x - event.currentTarget.dragPoint.x;
event.currentTarget.y = newPosition.y - event.currentTarget.dragPoint.y;
} else if (event.currentTarget.dragging && this.selection.isMultiselection === true) {
if (this.rectToolGraphics.visible === true) {
this.finalScreenMousePos = this.backgroundImage.toLocal(this.mousePosition);
}
}
}).on('rightclick', event => {
event.stopPropagation();
this.cancelPaint();
this.selection.deselectAll();
})
.on('pointerover', (event) => {
this.previewSinglePointIcon.filters = [new OldFilmFilter()];
})
.on('pointerout', (event) => {
this.previewSinglePointIcon.filters = null;
});
this.app.stage.addChild(this.backgroundImage);
this.createPreviewSinglePointIcon();
this.createPreviewLineSegment();
this.createCircleShadow();
this.createEnterPaintEndButton();
this.backgroundImage.addChild(this.paintingLine);
}
/**
*
*/
public refreshBackgroundImage(): void {
if (!this.canvasData.selectStorey.imageUrl) {
this.backgroundImage.visible = false;
} else {
this.backgroundImage.texture = PIXI.Texture.from(this.canvasData.selectStorey.imageUrl);
this.backgroundImage.angle = this.canvasData.selectStorey.imageAngle;
this.backgroundImage.visible = true;
}
}
/**
*
*/
public destroyBackgroundImage(): void {
this.app.stage.removeChild(this.backgroundImage);
// this.removeAllListeners('backgroundScale');
}
/**
*
* @param scale
*/
public setBackgroundScale(scale: number): void {
this.backgroundImage.scale.set(scale);
this.emit('backgroundScale', this.backgroundImage.scale.x);
}
/**
*
* @param imageAngle
*/
public setBackgroundAngle(imageAngle: number) {
this.backgroundImage.angle = imageAngle;
}
/**
*
*/
private createPreviewSinglePointIcon(): void {
this.previewSinglePointIcon = PIXI.Sprite.from('assets/images/noImg.png');
this.previewSinglePointIcon.width = 32;
this.previewSinglePointIcon.height = 32;
this.previewSinglePointIcon.alpha = 1;
this.previewSinglePointIcon.anchor.set(0.5);
this.previewSinglePointIcon.visible = false;
this.backgroundImage.addChild(this.previewSinglePointIcon);
}
/**
*
* @param uri
*/
private changePreviewSinglePointIcon(uri: string): void {
this.previewSinglePointIcon.texture = PIXI.Texture.from(uri);
this.previewSinglePointIcon.visible = true;
}
/**
* 线
*/
private createPreviewLineSegment() {
this.previewLineSegment.visible = false;
this.backgroundImage.addChild(this.currentClickPoint);
this.backgroundImage.addChild(this.previewLineSegment);
this.backgroundImage.addChild(this.rectToolGraphics);
this.rectToolGraphics.visible = false;
}
/**
* 线
* @param pointA A
* @param pointB B
*/
private refreshPreviewLineSegment(pointA: PIXI.Point, pointB: PIXI.Point) {
this.previewLineSegment.clear();
this.previewLineSegment.lineStyle(1, 0xffd900, 1);
this.previewLineSegment.moveTo(pointA.x, pointA.y);
this.previewLineSegment.lineTo(pointB.x, pointB.y );
}
/**
*
* @param x
*/
private createCircleShadow(): void {
this.circleShadow.beginFill(0xFFCC5A);
this.circleShadow.drawCircle(0, 0, 10);
this.circleShadow.endFill();
this.circleShadow.visible = false;
this.backgroundImage.addChild(this.circleShadow);
}
/**
*
*/
public beginPaint() {
switch (this.canvasData.selectTemplateData.interactiveMode) {
case 0:
this.beginPaintSinglePointIcon();
break;
case 1:
this.beginPaintLineIcon();
break;
case 2:
this.beginPaintPolygonIcon();
break;
}
}
/**
*
*/
private beginPaintSinglePointIcon(): void {
this.cancelPaint();
this.paintMode = PaintMode.singlePointIcon;
this.changePreviewSinglePointIcon(this.canvasData.selectTemplateData.imageUrl);
}
/**
*
*/
private beginPaintPolygonIcon(): void {
this.cancelPaint();
this.paintMode = PaintMode.polygonIcon;
this.circleShadow.visible = true;
}
/**
*
*/
private beginPaintLineIcon(): void {
this.cancelPaint();
this.paintMode = PaintMode.lineIcon;
this.previewSinglePointIcon.texture = PIXI.Texture.from(this.canvasData.selectTemplateData.imageUrl);
this.circleShadow.visible = true;
}
/**
* 线
*/
public beginPaintPipeline(): void {
this.paintMode = PaintMode.Pipeline;
}
public paintingPipelineFinish(): void {
if (this.paintMode === PaintMode.Pipeline) {
this.paintMode = PaintMode.endPaint;
this.paintPoints.splice(0, this.paintPoints.length);
this.paintingPipeline = null;
}
}
public beginPaintingArrows(): void {
this.paintMode = PaintMode.Arrows;
}
/**
*
*/
public cancelPaint(): void {
switch (this.paintMode) {
case PaintMode.singlePointIcon:
this.previewSinglePointIcon.visible = false;
this.paintMode = PaintMode.endPaint;
break;
case PaintMode.lineIcon:
this.circleShadow.visible = false;
this.previewLineSegment.visible = false;
this.paintPoints.splice(0, this.paintPoints.length);
if (this.paintingIcon !== null) {
this.backgroundImage.removeChild(this.paintingIcon);
}
this.paintMode = PaintMode.endPaint;
break;
case PaintMode.polygonIcon:
this.circleShadow.visible = false;
this.previewLineSegment.visible = false;
this.paintingIcon = null;
this.paintPoints.splice(0, this.paintPoints.length);
this.paintingLine.clear();
this.paintMode = PaintMode.endPaint;
break;
}
}
/**
*
* @param mode
*/
public setPaintMode(mode: PaintMode) {
this.reset();
this.paintMode = mode;
switch (mode) {
case PaintMode.endPaint:
this.selectCar = null;
this.backgroundImage.children.forEach(item => {
if (item instanceof PutCarArea) {
if (item.assetData.Type.indexOf(this.selectCar?.Type) !== -1) {
item.visible = true;
} else {
item.visible = false;
}
}
});
break;
}
}
/**
*
*/
public getPaintMode(): PaintMode {
return this.paintMode;
}
/**
*
*/
public reset() {
this.previewSinglePointIcon.filters = null;
this.previewSinglePointIcon.visible = false;
this.previewSinglePointIcon.angle = 0;
}
/**
*
*/
private enterPaint(): void {
this.previewLineSegment.visible = false;
this.enterPaintEndButton.visible = false;
switch (this.paintMode) {
case PaintMode.lineIcon:
if (this.paintPoints.length >= 2) {
this.emit('createIcon', this.paintingIcon);
this.paintingIcon = null;
}
break;
case PaintMode.polygonIcon:
this.paintingLine.clear();
if (this.paintPoints.length >= 3) {
const jsonList = JSON.parse(JSON.stringify(this.canvasData.selectTemplateData.propertyInfos));
const propertyList = [];
jsonList.forEach(element => {
const property = new PropertyInfo(element);
propertyList.push(property);
});
const assetData = {
TemplateId: this.canvasData.selectTemplateData.id,
FloorId: this.canvasData.selectStorey.id,
Angle: this.canvasData.selectTemplateData.angle,
Color: this.canvasData.selectTemplateData.color,
Enabled: this.canvasData.selectTemplateData.enabled,
FillMode: this.canvasData.selectTemplateData.fillMode,
FireElementId: this.canvasData.selectTemplateData.fireElementId,
FixedSize: this.canvasData.selectTemplateData.fixedSize,
Height: 32,
Width: 32,
Id: ObjectID.default.generate(),
ImageUrl: this.canvasData.selectTemplateData.imageUrl,
InteractiveMode: this.canvasData.selectTemplateData.interactiveMode,
MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)),
Point: new PIXI.Point(0, 0),
Name: this.canvasData.selectTemplateData.name,
PropertyInfos: propertyList,
Border: this.canvasData.selectTemplateData.border,
DrawMode: this.canvasData.selectTemplateData.drawMode,
Thickness: this.canvasData.selectTemplateData.thickness,
IsFromBuilding: this.canvasData.selectTemplateData.isFromBuilding,
GameMode: this.canvasData.gameMode
};
const polygonIcon = new PolygonIcon(assetData, this);
this.emit('createIcon', polygonIcon);
}
break;
}
this.paintPoints.splice(0, this.paintPoints.length);
this.emit('backgroundScale', this.backgroundImage.scale.x);
}
/**
*
*/
public copy(): void {
this.copyData = [];
this.selection.objects.forEach(item => {
const newData = JSON.parse(JSON.stringify(item.assetData));
this.copyData.push(newData);
});
}
/**
*
*/
public paste(companyId: string, buildingId: string, floorId: string): void {
this.copyData.forEach(item => {
item.Point = new PIXI.Point(item.Point.x + 5, item.Point.y + 5);
const newData = JSON.parse(JSON.stringify(item));
newData.Id = ObjectID.default.generate(),
newData.CompanyId = companyId;
newData.BuildingId = buildingId;
newData.FloorId = floorId;
newData.Point = new PIXI.Point(item.Point.x + 5, item.Point.y + 5);
if (newData.IsFromBuilding) {
this.canvasData.originalcompanyBuildingData.data[newData.Id] = newData;
} else {
this.canvasData.originaleveryStoreyData.data[newData.Id] = newData;
}
switch (item.InteractiveMode) {
case PaintMode.singlePointIcon:
const singleIcon = new SinglePointIcon(newData, this);
break;
case PaintMode.lineIcon:
const lineIcon = new MultipointIcon(newData, this);
break;
case PaintMode.polygonIcon:
const polygonIcon = new PolygonIcon(newData, this);
break;
}
this.selection.select(this.backgroundImage.getChildByName(newData.Id));
});
}
}
/**
*
*/
export class Selection {
constructor(private workingArea: WorkingAreaComponent) {}
public objects: any[] = [];
public isMultiselection = false;
/**
*
* @param obj
*/
public contains(obj: any): boolean {
return this.objects.includes(obj);
}
/**
*
* @param obj
*/
public select(obj: any) {
if (!this.contains(obj)) {
this.workingArea.emit('select', obj);
this.objects.push(obj);
}
}
/**
*
* @param obj
*/
public deselect(obj: any) {
if (this.contains(obj)) {
this.workingArea.emit('deselect', obj);
const idx = this.objects.findIndex(x => x === obj);
this.objects.splice(idx, 1);
}
}
/**
*
* @param obj
*/
public selectOrDeselect(obj: any) {
if (this.contains(obj)) {
this.deselect(obj);
} else {
this.select(obj);
}
}
/**
*
*/
public deselectAll() {
this.objects.forEach(item => {
this.workingArea.emit('deselect', item);
});
this.objects.splice(0, this.objects.length);
}
/**
*
* @param obj
*/
public selectOne(obj: any) {
if (this.isMultiselection) {
this.selectOrDeselect(obj);
} else {
this.deselectAll();
this.select(obj);
}
}
/**
*
* @param objects
*/
public selectAll(objects: any[]) {
this.objects.forEach(item => {
this.select(item);
});
}
}
/**
*
*/
export class PropertyInfo {
constructor(instanceData: any) {
this.Tag = instanceData.tag;
this.Order = instanceData.order;
this.Enabled = instanceData.enabled;
this.Visible = instanceData.visible;
this.Required = instanceData.required;
this.RuleName = instanceData.ruleName;
this.RuleValue = instanceData.ruleValue;
this.PhysicalUnit = instanceData.physicalUnit;
this.PropertyName = instanceData.propertyName;
this.PropertyType = instanceData.propertyType;
this.PropertyValue = instanceData.propertyValue;
}
/**
* ,
*/
public Tag: string;
/**
*
*/
public Order: number;
/**
*
*/
public Enabled: boolean;
/**
*
*/
public Visible: boolean;
/**
*
*/
public Required: boolean;
/**
*
*/
public RuleName: string;
/**
*
*/
public RuleValue: string;
/**
*
*/
public PhysicalUnit: string;
/**
*
*/
public PropertyName: string;
/**
*
*/
public PropertyType: number;
/**
*
*/
public PropertyValue: string;
}
/**
*
*/
export enum Type {
= 0,
= 1,
= 2,
= 3,
= 4
}