123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- import { SMouseEvent, SUndoStack } from "@saga-web/base";
- import { SGraphScene, SGraphLayoutType } from '@saga-web/graph/lib';
- import { SFloorParser, SLineItem, SPolylineItem, SItemStatus, ItemOrder } from "@saga-web/big";
- import { SGraphItem, SImageItem, STextItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate, SGraphAddCommand } from "@saga-web/graph/lib";
- import { SZoneLegendItem } from "@/lib/items/SZoneLegendItem";
- import { TipelineItem } from "@/lib/items/TipelineItem";
- import { SImgTextItem } from "@/lib/items/SImgTextItem"
- import { SPoint, SFont } from '@saga-web/draw/lib';
- export class EditScence extends SGraphScene {
- undoStack = new SUndoStack();
-
- private cmd = 'choice';
-
- get getCmd(): string {
- return this.cmd;
- }
-
- set setCmd(cmd: string) {
- if (cmd == 'choice') {
- this.grabItem = null;
- }
- this.cmd = cmd;
- if (this.focusItem) {
-
- this.focusItem.cancelOperate();
- this.focusItem = null;
-
- }
- if (this.view) {
- this.view.update();
- }
- };
-
- focusItem: SGraphItem | null = null;
-
- Nodes: any = [];
-
- Markers: any = [];
-
- Relations: any = [];
- constructor() {
- super();
-
- this.selectContainer.connect("listChange", this, this.listChange);
- }
-
- listChange(obj: any) {
- let itemType: string = 'equipment'
- if (obj.itemList[0] instanceof STextItem) {
- itemType = 'text'
- } else if (obj.itemList[0] instanceof SImageItem) {
- itemType = 'images'
- } else if (obj.itemList[0] instanceof SLineItem) {
- itemType = 'line'
- } else if (obj.itemList[0] instanceof SPolylineItem) {
- itemType = 'pipeline'
- } else if (obj.itemList[0] instanceof SZoneLegendItem) {
- itemType = 'position'
- } else if (obj.itemList[0] instanceof SImgTextItem) {
- itemType = 'equipment'
- } else {
- itemType = ''
- };
- if (obj.itemList.length == 1) {
-
- this.focusItem = obj.itemList[0]
- }
- let msg = {
- itemList: obj.itemList,
- itemType,
- }
- this.emitChange(msg)
- }
- emitChange(msg: any) {
- }
-
- addLine(event: SMouseEvent): boolean {
- const item = new SLineItem(null, new SPoint(event.x, event.y));
- item.status = SItemStatus.Create;
- item.zOrder = ItemOrder.lineOrder;
- item.selectable = true;
- this.addItem(item);
- item.connect("finishCreated", this, this.finishCreated);
- this.grabItem = item;
- this.undoStack.push(new SGraphAddCommand(this, item));
-
- return true
- }
-
- addPolylineItem(event: SMouseEvent): boolean {
- const point = new SPoint(event.x, event.y)
- const item = new TipelineItem(null, [point]);
-
- item.selectable = true;
- item.status = SItemStatus.Create;
- item.zOrder = ItemOrder.polylineOrder
- this.addItem(item);
- item.connect("finishCreated", this, this.finishCreated);
-
- this.grabItem = item;
- this.focusItem = item;
- return true
- }
-
- addPolygonItem(event: SMouseEvent): void {
-
- const Legend = {
- ID: 123,
- Name: "哈哈",
- GraphElementType: 'Zone',
- GraphElementId: '123',
- Pos: { x: 0, y: 0 },
- OutLine: [[new SPoint(event.x, event.y)]],
- Properties: {
- strokeColor: '#3d73c0',
- fillColor: '#eda986'
- },
- Num: 123
- }
- const Polylines = new SZoneLegendItem(null, Legend);
- Polylines.selectable = true;
-
- Polylines.setStatus = SItemStatus.Create;
- const point = new SPoint(event.x, event.y);
- Polylines.zOrder = ItemOrder.polygonOrder;
- Polylines.setPointList = [point];
- Polylines.moveable = true;
- this.addItem(Polylines);
- Polylines.connect("finishCreated", this, this.finishCreated);
- this.grabItem = Polylines;
- this.focusItem = Polylines;
- this.Nodes.push(Polylines)
- }
-
- addImgItem(event: SMouseEvent) {
- const url = require('./../../assets/logo.png')
- const item = new SImageItem(null);
- item.url = url;
- item.zOrder = ItemOrder.imageOrder;
- item.selectable = true;
- item.moveable = true;
- item.moveTo(event.x, event.y);
- this.addItem(item);
- this.grabItem == null;
- this.focusItem = item;
- this.cmd = 'choice';
- }
-
- addTextItem(event: SMouseEvent): void {
- const item = new STextItem(null, '请在右侧属性栏输入文字!');
- item.moveTo(event.x, event.y);
- item.selectable = true;
- item.moveable = true;
- item.zOrder = ItemOrder.textOrder;
- this.addItem(item);
- this.grabItem == null
- this.cmd = 'choice';
- }
-
- addIconItem(): void {
- }
-
- editItemStatus(): void {
- }
-
- updatedText(str: string): void {
- if (this.focusItem) {
- const old = this.focusItem.text;
- this.focusItem.text = str;
-
- }
- }
-
- updatedFontSize(size: number): void {
- if (this.focusItem) {
- let old = new SFont(this.focusItem.font);
- let font = new SFont(this.focusItem.font);
- font.size = size;
- this.focusItem.font = font;
-
- }
- }
-
- updatedLineWidth(lineWidth: number): void {
- if (this.focusItem) {
-
-
-
- this.focusItem.lineWidth = lineWidth;
-
- }
- }
-
- updatedFontColor(color: string): void {
- if (this.focusItem) {
- let old = this.focusItem.color;
- this.focusItem.color = color;
-
- }
- }
-
- updatedBorderColor(color: string): void {
- if (this.focusItem) {
- let old = this.focusItem.strokeColor;
- this.focusItem.strokeColor = color;
-
- }
- }
-
- updatedWidth(width: number): void {
- if (this.focusItem) {
-
- this.focusItem.width = width;
-
- }
- }
-
- updatedHeight(height: number): void {
- if (this.focusItem) {
-
- this.focusItem.height = height;
-
- }
- }
-
- updatedPosition(x: number, y: number): void {
- if (this.focusItem) {
- let p = this.focusItem.mapFromScene(x, y)
-
-
- this.focusItem.x = p.x - this.focusItem.boundingRect().left + this.focusItem.x;
- this.focusItem.y = p.y - this.focusItem.boundingRect().top + this.focusItem.y;
- }
- }
-
- updatedbackColor(color: string): void {
- if (this.focusItem) {
- this.focusItem.backgroundColor = color;
- }
- }
-
- deleiteItem(): void {
- if (this.focusItem) {
- this.removeItem(this.focusItem);
- this.focusItem = null;
- }
- if (this.view) {
- this.view.update();
- }
- }
-
- changeAlignItem(v: any): void {
- console.log(v);
- this.selectContainer.layout(v);
- }
-
- extractItem(): void {
- console.log(this)
- }
-
- saveMsgItem(): any {
- const Nodes: any = []
- this.Nodes.forEach(e => {
- Nodes.push(e.toData())
- });
- let element = {
- Nodes
- }
- return element
- }
-
- lockItem(): void {
- }
-
- redo(): void {
- this.undoStack.undo();
- }
-
- undo(): void {
- this.undoStack.redo();
- }
-
- finishCreated(item: any) {
- this.setCmd = 'choice';
- this.focusItem = item;
- this.selectContainer.toggleItem(item)
- }
-
-
- onMouseDown(event: SMouseEvent): any {
- if (this.grabItem) {
- return this.grabItem.onMouseDown(event);
- }
- switch (this.cmd) {
- case 'baseLine':
- this.addLine(event);
- break;
- case 'baseText':
- this.addTextItem(event);
- break;
- case 'baseImage':
- this.addImgItem(event)
- break;
- case 'Zone':
- this.addPolygonItem(event);
- break;
-
-
-
- case 'Line':
- this.addPolylineItem(event);
- break;
- default:
- return super.onMouseDown(event);
- }
- }
-
- onKeyDown(event: KeyboardEvent): any {
- if (this.grabItem) {
- this.grabItem.onKeyDown(event);
- }
-
-
-
- return false
- }
- }
|