123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- import { SGraphDeleteListCommand, SGraphEditScene, SGraphEdit } from "./../edit/"
- import { SMouseEvent } from "@persagy-web/base/lib";
- import { SArrowStyleType, SPoint, SRect } from '@persagy-web/draw';
- import { SItemStatus, SRectSelectItem } from '@persagy-web/big/lib';
- import { SGraphItem, SGraphSelectContainer, SOrderSetType } from "@persagy-web/graph/lib/";
- import { uuid } from "./until";
- import { SBaseArrow, SBaseEquipment, SBaseExpainEdit, SBasePipeUninTool, SBasePipe } from "./"
- import { PTopoParser } from "./../persagy-edit/"
- import { SBaseArrowPolyEdit } from './items/SBaseArrowPolyEdit';
- export class SBaseEditScene extends SGraphEditScene {
-
- Nodes: any = [];
-
- Markers: any = [];
-
- Relations: any = [];
-
- copyString: any[] = [];
-
- grabItem: null | SGraphEdit | SGraphItem = null;
-
- constructor() {
- super()
- }
-
- addExplainItem(event: SMouseEvent): void {
- const data = {
-
- name: '基础注释文本',
-
- type: "Text",
-
- pos: { x: event.x, y: event.y },
-
- properties: {
- type: "BaseExplain",
- },
- style: {
- default: {
- text: '请在右侧属性栏输入文字!',
- color: "#646c73",
- font: 14,
- backgroundcolor: "#f7f9facc",
- }
- }
- };
- const item = new SBaseExpainEdit(null, data);
- item.moveTo(event.x, event.y);
- item.selectable = true;
- item.moveable = true;
- this.addItem(item);
- this.grabItem = null;
- item.connect("onContextMenu", this, this.getItem);
- this.finishCreated(item);
- }
-
- addPolyLineArrow(event: SMouseEvent): void {
- const data = {
- name: '基础箭头',
- type: "Arrow",
- pos: { x: 0, y: 0 },
- properties: {
- type: "BaseArrow",
- },
- style: {
- outLine: [{ x: event.x, y: event.y }],
- begin: SArrowStyleType.None,
- end: SArrowStyleType.None,
- isMove: true,
- default: {}
- }
- };
- const item = new SBaseArrow(null, data);
- item.status = SItemStatus.Create;
- item.selectable = true;
- this.addItem(item);
- this.grabItem = item;
- item.connect("finishCreated", this, this.finishCreated);
- item.connect("onContextMenu", this, this.getItem);
- if (this.view) {
- this.view.update();
- }
- }
-
- addPolygonArrow(event: SMouseEvent): void {
- const data = {
-
- name: '多边形箭头',
-
- type: "ArrowPolygon",
-
- scale: { x: 1, y: 1, z: 1 },
-
- rolate: { x: 0, y: 0, z: 0 },
-
- pos: { x: 0, y: 0 },
-
- properties: {
- type: "BaseArrowPolygon"
- },
- style: {
- line: [{ x: event.x, y: event.y }],
- default: {
- }
- }
- };
- const item = new SBaseArrowPolyEdit(null, data);
- item.status = SItemStatus.Create;
- item.selectable = true;
- this.addItem(item);
- this.grabItem = item;
- item.connect("finishCreated", this, this.finishCreated);
- item.connect("onContextMenu", this, this.getItem);
- if (this.view) {
- this.view.update();
- }
- }
-
- addEuqipment(event: SMouseEvent, legendObj: any): void {
- const data = {
-
- name: '基础设备',
- num: 1,
- size: { width: 50, height: 50 },
-
- type: "Image",
-
- pos: { x: event.x, y: event.y },
-
- properties: {
- type: "BaseEquipment",
- },
- style: {
- default: {
- strokecolor: "#c0ccda",
- url: require('./../../../assets/images/equip/' + legendObj.url),
- }
- }
- }
- const item = new SBaseEquipment(null, data);
- item.status = SItemStatus.Create;
- this.addItem(item);
- item.selectable = true;
- item.moveable = true;
- this.grabItem = item;
- this.finishCreated(item)
- item.connect("onContextMenu", this, this.getItem);
- if (this.view) {
- this.view.update();
- }
- }
-
- addBasePipe(event: SMouseEvent) {
- const anc = this.clickIsAnchor(event);
- if (anc) {
- const p = anc.mapToScene(0, 0)
- anc.isConnected = true;
- event.x = p.x;
- event.y = p.y;;
- };
- const data = {
- name: '管道',
- lineType: '',
- pointList: [{ x: event.x, y: event.y }],
- properties: {
- type: "BasePipe",
- },
- style: {
- default: {
- }
- }
- };
- const item = new SBasePipe(null, data);
- item.status = SItemStatus.Create;
- item.selectable = true;
- this.addItem(item);
- this.grabItem = item;
-
- item.startAnchor = anc;
- if (anc) {
- anc.parent?.connect('changePos', item, item.changePos)
- item.anchor1ID = anc.id;
- item.node1Id = anc.parent.id;
- }
- item.connect("finishCreated", this, this.finishCreated);
- item.connect("onContextMenu", this, this.getItem);
- if (this.view) {
- this.view.update();
- }
- }
-
- addPipeUninTool(event: SMouseEvent, cmd: string): void {
- const cmdList = {
- 'wantou': 2,
- 'santong': 3,
- 'sitong': 4,
- }
- const data = {
-
- name: '基础管道接头',
-
- type: "Image",
-
- pos: { x: event.x, y: event.y },
-
- properties: {
- type: "BasePipeUninTool",
- },
- style: {
- uninToolType: cmdList[cmd] ? cmdList[cmd] : 2,
- default: {
- strokecolor: "#c0ccda",
- }
- }
- };
- const item = new SBasePipeUninTool(null, data);
- item.status = SItemStatus.Create;
- item.selectable = true;
- item.moveable = true;
- this.addItem(item);
- this.grabItem = item;
- this.finishCreated(item)
- item.connect("onContextMenu", this, this.getItem);
- if (this.view) {
- this.view.update();
- }
- }
-
- redo(): void {
- if (this.grabItem && this.grabItem instanceof SGraphEdit) {
- this.grabItem.redo()
- } else {
- this.undoStack.redo();
- }
- }
-
- undo(): void {
- if (this.grabItem && this.grabItem instanceof SGraphEdit) {
- this.grabItem.undo()
- } else {
- this.undoStack.undo();
- }
- }
-
- deleteItem(): any {
- if (this.selectContainer.count == 0) {
- return []
- }
- let itemList = this.selectContainer.itemList;
-
- this.undoStack.push(new SGraphDeleteListCommand(this, [...itemList]))
- itemList.forEach((element: any) => {
- this.removeItem(element)
- });
- if (this.view) {
- this.view.update()
- }
- return itemList
- }
-
- addRectSelect(event: SMouseEvent): void {
- let point = new SPoint(event.x, event.y);
- let rect = new SRectSelectItem(null, point);
- this.addItem(rect);
- this.grabItem = rect;
- }
-
- groupSelect(ctrl: boolean) {
-
-
-
- if (this.grabItem instanceof SRectSelectItem) {
- const rect = this.grabItem.boundingRect();
- this.arrToSelect(this.root.children, rect)
- }
- }
-
- private arrToSelect(arr: SGraphItem[], rect: SRect) {
- if (Array.isArray(arr) && arr.length) {
- arr.forEach(t => {
- if (!(t instanceof SGraphSelectContainer) && t.parent) {
- let temp = t.boundingRect();
- let lefttop = t.mapToScene(temp.left, temp.top)
- let rightbottom = t.mapToScene(temp.right, temp.bottom)
- let r = new SRect(lefttop, rightbottom)
- if (rect.isIn(r)) {
- this.selectContainer.toggleItem(t)
- }
- }
- })
- }
- }
-
-
-
- onMouseDown(event: SMouseEvent): any {
- if (!super.onMouseDown(event) && 1 == event.buttons) {
- this.addRectSelect(event);
- }
- }
-
- onMouseUp(event: SMouseEvent): boolean {
- console.log('-----baseEditScene');
- if (this.grabItem) {
-
- if (this.grabItem instanceof SRectSelectItem) {
- this.removeItem(this.grabItem);
- this.groupSelect(false);
- this.grabItem = null;
- if (this.view) {
- this.view.update()
- }
- console.log(1);
-
- return true;
- }
- console.log(2);
-
- return this.grabItem.onMouseUp(event);
- }
- console.log(3);
-
- return super.onMouseUp(event)
- }
-
- copy(): void {
- const itemList = this.save(false);
- if (itemList) {
-
-
- itemList.markers.map((item: any) => {
- delete item.id;
- delete item.graphId;
- delete item.markerId;
- return item
- });
- itemList.nodes.map((item: any) => {
- delete item.id;
- delete item.graphId;
- delete item.markerId;
- return item
- });
- itemList.relations.map((item: any) => {
- delete item.id;
- delete item.graphId;
- delete item.markerId;
- return item
- });
- this.copyString = itemList
-
- const input = document.createElement('input');
- input.setAttribute('id', 'COPYINPUT')
- input.value = JSON.stringify(this.copyString)
- sessionStorage.setItem("copyString", input.value);
- document.body.appendChild(input);
- input.select()
- document.execCommand('copy');
- input.style.display = 'none';
- console.log(input.value, Date.now());
- document.body.removeChild(input)
- }
- }
-
- paste(): void {
- const copyList = JSON.parse(JSON.stringify(this.copyString));
- console.log('copyList', copyList)
- const parserData = new PTopoParser();
- parserData.parseData(copyList);
- parserData.markers.forEach((item: SGraphEdit) => {
- item.selectable = true;
- item.moveable = true;
- if (this.view) {
- item.pos.x += 10 / this.view.scale
- item.pos.y += 10 / this.view.scale
- }
- this.addItem(item);
- });
- this.view ? this.view.update() : '';
- }
-
- setOrder(type: string) {
- this.selectContainer.setOrder(SOrderSetType.[type])
- }
-
- save(isAll: boolean = true): any {
- }
- }
|