|
@@ -1,32 +1,122 @@
|
|
import { SGraphScene } from '@saga-web/graph/lib';
|
|
import { SGraphScene } from '@saga-web/graph/lib';
|
|
import { SMouseEvent } from '@saga-web/base/lib';
|
|
import { SMouseEvent } from '@saga-web/base/lib';
|
|
-import { SPoint } from '@saga-web/draw/lib';
|
|
|
|
-import { SFloorParser, SImageItem,STextItem,SLineItem,SPolylineItem } from "@saga-web/big";
|
|
|
|
|
|
+import { SPoint, SPainter, SRect, SColor } from '@saga-web/draw/lib';
|
|
|
|
+import { SFloorParser, SImageItem, STextItem, SLineItem, SPolylineItem, SAnchorItem, SItemStatus } from "@saga-web/big";
|
|
|
|
+import { SMathUtil } from '@saga-web/big/lib/utils/SMathUtil';
|
|
|
|
+import { SImgTextItem } from './SImgTextItem';
|
|
|
|
+import { TipelineItem } from './TipelineItem';
|
|
|
|
|
|
export class FloorScene extends SGraphScene {
|
|
export class FloorScene extends SGraphScene {
|
|
- isLining: boolean = false;
|
|
|
|
|
|
|
|
- constructor(){
|
|
|
|
|
|
+ CMD: number = 0;
|
|
|
|
+
|
|
|
|
+ // 图标itemlist
|
|
|
|
+ imgtextList: SImgTextItem[] = [];
|
|
|
|
+
|
|
|
|
+ // 构造函数
|
|
|
|
+ constructor() {
|
|
super();
|
|
super();
|
|
|
|
+<<<<<<< HEAD
|
|
this.selectContainer.connect('listChange',this,this.listChange)
|
|
this.selectContainer.connect('listChange',this,this.listChange)
|
|
|
|
+=======
|
|
|
|
+ this.selectContainer.connect('listChange', this, this.listChange)
|
|
|
|
+>>>>>>> master
|
|
}
|
|
}
|
|
|
|
|
|
- listChange(){
|
|
|
|
|
|
+ //
|
|
|
|
+ listChange() {
|
|
console.log(arguments)
|
|
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 {
|
|
onMouseDown(event: SMouseEvent): boolean {
|
|
- if (this.isLining) {
|
|
|
|
- if (this.grabItem instanceof SPolylineItem) {
|
|
|
|
|
|
+ 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);
|
|
return super.onMouseDown(event);
|
|
- } else {
|
|
|
|
- const item = new SPolylineItem(null, new SPoint(event.x, event.y));
|
|
|
|
- this.addItem(item);
|
|
|
|
- this.grabItem = item;
|
|
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- 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);
|
|
}
|
|
}
|
|
}
|
|
}
|