123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import { SGraphScene, SAnchorItem } from '@saga-web/graph/lib';
- import { SMouseEvent } from '@saga-web/base/lib';
- import { SPoint, SPainter, SRect, SColor } from '@saga-web/draw';
- import { SFloorParser, SLineItem, SPolylineItem, SItemStatus } from "@saga-web/big";
- import { SMathUtil } from '@saga-web/big/lib/utils/SMathUtil';
- import { SImgTextItem } from './items/SImgTextItem';
- import { TipelineItem } from './items/TipelineItem';
- export class FloorScene extends SGraphScene {
- CMD: number = 0;
- // 图标itemlist
- imgtextList: SImgTextItem[] = [];
- // 构造函数
- constructor() {
- super();
- this.selectContainer.connect('listChange', this, this.listChange)
- }
- //
- listChange() {
- console.log(arguments)
- }
- // 创建图标item
- createSImgText(event: SMouseEvent): SImgTextItem {
- const item = new SImgTextItem(null);
- item.moveTo(event.x, event.y);
- this.addItem(item);
- this.imgtextList.push(item);
- this.CMD = 0;
- // this.grabItem = item;
- return item;
- }
- // 创建图标item
- createSPolyline(event: SMouseEvent, anchor: SAnchorItem | null = null): TipelineItem {
- const item = new TipelineItem(null, [new SPoint(event.x, event.y)]);
- this.addItem(item);
- item.startAnchor = anchor;
- if (anchor) {
- anchor.parent?.connect('changePos', item, item.changePos)
- }
- this.grabItem = item;
- return item;
- }
- onMouseDown(event: SMouseEvent): boolean {
- if (this.CMD == 1) {
- this.createSImgText(event);
- return true;
- } else if (this.CMD == 2) {
- const anc = this.clickIsAnchor(event);
- if (anc) {
- const p = anc.mapToScene(0, 0)
- anc.isConnected = true;
- event.x = p.x;
- event.y = p.y;
- }
- if (this.grabItem instanceof TipelineItem) {
- // 是否点击锚点
- if (anc){
- if (this.grabItem.pointList.length) {
- this.grabItem.endAnchor = anc;
- anc.parent?.connect('changePos', this.grabItem, this.grabItem.changePos)
- }
- this.grabItem.onMouseDown(event);
- this.grabItem.status = SItemStatus.Edit;
- this.CMD = 0;
- return true
- }
- return super.onMouseDown(event);
- }
- this.createSPolyline(event, anc);
- return true;
- }
- this.CMD = 0
- return super.onMouseDown(event);
- }
- /**
- * 划线时点击位置是否是锚点
- *
- * @param event 事件
- * @param len 限制距离
- * @return 点击的锚点
- * */
- clickIsAnchor(event: SMouseEvent): SAnchorItem | null {
- let minAnchor = null;
- let len: number = -1;
- this.imgtextList.forEach(imgtext => {
- console.log(imgtext.anchorList)
- imgtext.anchorList.forEach(anchor => {
- let anchorPoint = anchor.mapToScene(0, 0);
- let dis = SMathUtil.pointDistance(
- event.x,
- event.y,
- anchorPoint.x,
- anchorPoint.y
- );
- if (len < 0) {
- len = anchor.sceneDis;
- }
- if (dis < len) {
- minAnchor = anchor;
- len = dis;
- }
- })
- })
- return minAnchor;
- } // Function clickIsAnchor()
- drawScene(painter: SPainter, rect: SRect) {
- super.drawScene(painter, rect);
- }
- }
|