|
@@ -18,7 +18,6 @@ import {
|
|
|
penWholeLinePoygonsEditWithHelperShapesMouse,
|
|
|
repeatMoveWholeLineLine,
|
|
|
spliceWholeLineLineByPoint,
|
|
|
- updateConstant,
|
|
|
wholeLineDelPolygon,
|
|
|
} from "../service";
|
|
|
import {
|
|
@@ -29,7 +28,8 @@ import {
|
|
|
} from "../../../shared/shape-mose";
|
|
|
import { ShapeType } from "../../../type";
|
|
|
import { getAdsorbPosition } from "../../../shared/adsorb";
|
|
|
-import { getRealAbsoluteSize } from "../../../shared";
|
|
|
+import { currentConstant } from "../../view-constant";
|
|
|
+import mitt from "mitt";
|
|
|
|
|
|
export class EditWholeLine<
|
|
|
W extends WholeLineAttrib = WholeLineAttrib,
|
|
@@ -85,41 +85,52 @@ export class EditWholeLine<
|
|
|
private endCreatePolygon: () => void;
|
|
|
createPolygon() {
|
|
|
disableMouse();
|
|
|
+ this.container.constant.use();
|
|
|
const prePolygonIds: Set<string> = new Set();
|
|
|
let interrupt = false;
|
|
|
|
|
|
this.endCreatePolygon && this.endCreatePolygon();
|
|
|
this.container.bus.emit("dataChangeBefore");
|
|
|
|
|
|
+ const bus = mitt<{ penStart: void }>();
|
|
|
+ let emited = false;
|
|
|
+
|
|
|
const promise = new Promise<string>((resolve) => {
|
|
|
this.endCreatePolygon = penWholeLinePoygonsEditWithHelperShapesMouse(
|
|
|
{
|
|
|
quotePoint: true,
|
|
|
autoClose: false,
|
|
|
tree: this.container,
|
|
|
- adsorbRadius: getRealAbsoluteSize(this.shape, [5, 5], true)[0],
|
|
|
+ adsorbRadius: currentConstant.WHOLE_LINE_POINT_MERGE_DIST,
|
|
|
config: this.attrib,
|
|
|
changePolygon: (pid) => {
|
|
|
+ console.log("changePolygon", pid);
|
|
|
if (pid) {
|
|
|
prePolygonIds.add(pid);
|
|
|
}
|
|
|
},
|
|
|
+ onChange(change) {
|
|
|
+ if (!emited && change.pointChange.add.length) {
|
|
|
+ bus.emit("penStart");
|
|
|
+ emited = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
quitHandler: () => {
|
|
|
this.container.bus.emit("dataChangeAfter");
|
|
|
this.endCreatePolygon = null;
|
|
|
for (const pid of prePolygonIds) {
|
|
|
const polygonAttrib = getWholeLinePolygonRaw(this.attrib, pid);
|
|
|
- if (!polygonAttrib) return;
|
|
|
+ if (!polygonAttrib) continue;
|
|
|
|
|
|
if (!interrupt) {
|
|
|
this.polygonAfterHandler(polygonAttrib);
|
|
|
} else {
|
|
|
wholeLineDelPolygon(this.attrib, pid);
|
|
|
}
|
|
|
-
|
|
|
- resolve(interrupt ? "cancel" : "submit");
|
|
|
}
|
|
|
+ resolve(interrupt ? "cancel" : "submit");
|
|
|
enableMouse();
|
|
|
+ this.container.constant.unuse();
|
|
|
},
|
|
|
},
|
|
|
this.shape
|
|
@@ -127,6 +138,7 @@ export class EditWholeLine<
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
+ bus,
|
|
|
submit: this.endCreatePolygon.bind(this),
|
|
|
cancel: () => {
|
|
|
interrupt = true;
|
|
@@ -137,25 +149,27 @@ export class EditWholeLine<
|
|
|
}
|
|
|
|
|
|
pointAfterHandler(pointAttrib: WholeLinePointAttrib) {
|
|
|
- updateConstant(getRealAbsoluteSize(this.container.stage, [1, 1], true)[0]);
|
|
|
+ this.container.constant.use();
|
|
|
const merge = mergeWholeLinePointsByPoint(this.attrib, pointAttrib.id);
|
|
|
spliceWholeLineLineByPoint(
|
|
|
this.attrib,
|
|
|
merge?.info.main.id || pointAttrib.id
|
|
|
);
|
|
|
fixWholeLineConfig(this.attrib);
|
|
|
+ this.container.constant.unuse();
|
|
|
}
|
|
|
|
|
|
lineAfterHandler(lineAttrib: WholeLineLineAttrib) {
|
|
|
- updateConstant(getRealAbsoluteSize(this.container.stage, [1, 1], true)[0]);
|
|
|
+ this.container.constant.use();
|
|
|
for (let i = 0; i < lineAttrib.pointIds.length; i++) {
|
|
|
spliceWholeLineLineByPoint(this.attrib, lineAttrib.pointIds[i]);
|
|
|
}
|
|
|
fixWholeLineConfig(this.attrib);
|
|
|
+ this.container.constant.unuse();
|
|
|
}
|
|
|
|
|
|
polygonAfterHandler(polygonAttrib: WholeLinePolygonAttrib) {
|
|
|
- updateConstant(getRealAbsoluteSize(this.container.stage, [1, 1], true)[0]);
|
|
|
+ this.container.constant.use();
|
|
|
getWholeLinePolygonPoints(this.attrib, polygonAttrib.id).forEach(
|
|
|
(attrib) => {
|
|
|
if (this.attrib.points.includes(attrib)) {
|
|
@@ -164,6 +178,7 @@ export class EditWholeLine<
|
|
|
}
|
|
|
);
|
|
|
fixWholeLineConfig(this.attrib);
|
|
|
+ this.container.constant.unuse();
|
|
|
}
|
|
|
|
|
|
init() {
|
|
@@ -189,6 +204,7 @@ export class EditWholeLine<
|
|
|
|
|
|
this.pointDragHandler = {
|
|
|
readyHandler: (attrib) => {
|
|
|
+ this.container.constant.use();
|
|
|
this.container.bus.emit("dataChangeBefore");
|
|
|
const polygons = getWholeLinePolygonLinesByPoint(
|
|
|
this.attrib,
|
|
@@ -198,7 +214,7 @@ export class EditWholeLine<
|
|
|
let points = getWholeLinePolygonPoints(this.attrib, polygonId);
|
|
|
const startNdx = points.indexOf(attrib);
|
|
|
points = [
|
|
|
- ...points.slice(startNdx, points.length - 1),
|
|
|
+ ...points.slice(startNdx + 1, points.length - 1),
|
|
|
...points.slice(0, startNdx),
|
|
|
];
|
|
|
return points.map((point) => [point.x, point.y]);
|
|
@@ -212,22 +228,11 @@ export class EditWholeLine<
|
|
|
).map((line) => WholeLineLine.namespace + line.id);
|
|
|
exclusionIds.push(WholeLinePoint.namespace + pointAttrib.id);
|
|
|
|
|
|
- const [radius] = getRealAbsoluteSize(
|
|
|
- this.container.stage,
|
|
|
- [10, 10],
|
|
|
- true
|
|
|
- );
|
|
|
- const [radiusInner] = getRealAbsoluteSize(
|
|
|
- this.container.stage,
|
|
|
- [500, 500],
|
|
|
- true
|
|
|
- );
|
|
|
-
|
|
|
const position = getAdsorbPosition({
|
|
|
tree: this.container,
|
|
|
position: move,
|
|
|
- radius,
|
|
|
- radiusInner,
|
|
|
+ radius: currentConstant.WHOLE_LINE_POINT_MERGE_DIST,
|
|
|
+ radiusInner: currentConstant.WHOLE_LINE_POINT_CHECK_DIST,
|
|
|
pointsArray,
|
|
|
exclusionIds: exclusionIds,
|
|
|
});
|
|
@@ -235,6 +240,7 @@ export class EditWholeLine<
|
|
|
pointAttrib.y = position[1];
|
|
|
},
|
|
|
endHandler: (attrib) => {
|
|
|
+ this.container.constant.unuse();
|
|
|
this.pointAfterHandler(attrib);
|
|
|
this.container.bus.emit("dataChangeAfter");
|
|
|
},
|