|
@@ -4,16 +4,19 @@ import {
|
|
|
getWholeLineLinesRaw,
|
|
|
getWholeLinePoints,
|
|
|
} from "./whole-line-base";
|
|
|
-import { ref } from "vue";
|
|
|
+import { computed, ref, watchEffect } from "vue";
|
|
|
+import { WLP, WholeLineAttrib, WholeLinePointAttrib } from "../view";
|
|
|
+import { Attrib } from "../../../type";
|
|
|
import {
|
|
|
- WholeLineAttrib,
|
|
|
- WholeLineLine,
|
|
|
- WholeLinePoint,
|
|
|
- WholeLinePointAttrib,
|
|
|
-} from "../view";
|
|
|
-import { Attrib, ShapeType } from "../../../type";
|
|
|
-import { penWholeLinePoygonsEdit } from "./whole-line-edit";
|
|
|
-import { Container } from "../../container";
|
|
|
+ PenWholeLinePoygonsEditProps,
|
|
|
+ penWholeLinePoygonsEdit,
|
|
|
+} from "./whole-line-edit";
|
|
|
+import addMouseIco from "../../../shared/cursor/pic_pen_a.ico";
|
|
|
+import delMouseIco from "../../../shared/cursor/pic_pen_r.ico";
|
|
|
+import { getRealAbsoluteSize } from "../../../shared";
|
|
|
+import { lineShapeFactory, pointShapeFactory } from "../style";
|
|
|
+import { Layer } from "konva/lib/Layer";
|
|
|
+import { Group } from "konva/lib/Group";
|
|
|
|
|
|
export type WholeLineHelperInfo = {
|
|
|
change: WholeLineChange;
|
|
@@ -30,24 +33,13 @@ export type WholeLineHelperInfoAL = ReturnType<
|
|
|
*/
|
|
|
export const penWholeLinePoygonsEditWithHelperMouse = <
|
|
|
P extends Omit<WholeLinePointAttrib, "id">
|
|
|
->(props: {
|
|
|
- tree: Container;
|
|
|
- config: WholeLineAttrib<P & Attrib>;
|
|
|
- polygonId?: string;
|
|
|
- pointAttribFactory?: (pos: number[]) => Omit<P, "id">;
|
|
|
- quotePoint?: boolean;
|
|
|
- canOper?: (
|
|
|
- tree: WholeLineLine | WholeLinePoint,
|
|
|
- operShape: ShapeType
|
|
|
- ) => boolean;
|
|
|
- canDelPoint?: (point: P, evt: KonvaEventObject<any>) => boolean;
|
|
|
- changePolygon?: (polygonId: string) => void;
|
|
|
- quitHandler?: () => void;
|
|
|
-}) => {
|
|
|
+>(
|
|
|
+ props: PenWholeLinePoygonsEditProps<P> & { quitHandler?: () => void }
|
|
|
+) => {
|
|
|
const copyAttrib = () =>
|
|
|
JSON.parse(JSON.stringify(props.config)) as WholeLineAttrib<P & Attrib>;
|
|
|
|
|
|
- const edit = penWholeLinePoygonsEdit({ ...props, dev: true });
|
|
|
+ const edit = penWholeLinePoygonsEdit({ ...props });
|
|
|
const helper = penWholeLinePoygonsEdit({
|
|
|
...props,
|
|
|
changePolygon: undefined,
|
|
@@ -73,7 +65,7 @@ export const penWholeLinePoygonsEditWithHelperMouse = <
|
|
|
const moveHandler = (evt: KonvaEventObject<any>) => {
|
|
|
if (downing) return;
|
|
|
syncHelper();
|
|
|
- const change = helper.continuous(evt);
|
|
|
+ const { change } = helper.continuous(evt);
|
|
|
const { config } = helper.getStatus();
|
|
|
helperInfo.value = {
|
|
|
change,
|
|
@@ -84,21 +76,26 @@ export const penWholeLinePoygonsEditWithHelperMouse = <
|
|
|
downing = false;
|
|
|
moveHandler(evt);
|
|
|
};
|
|
|
- let prevTime = 0;
|
|
|
const clickHandler = (evt: KonvaEventObject<any>) => {
|
|
|
- if (Date.now() - prevTime < 200) {
|
|
|
+ const { isClose } = edit.continuous(evt);
|
|
|
+ syncHelper();
|
|
|
+ if (isClose) {
|
|
|
+ leaveEditMode();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const quitHandler = (ev: KeyboardEvent) => {
|
|
|
+ if (ev.key === "Escape") {
|
|
|
leaveEditMode();
|
|
|
- } else {
|
|
|
- prevTime = Date.now();
|
|
|
- edit.continuous(evt);
|
|
|
- syncHelper();
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
let leaveEditMode = () => {
|
|
|
- stage.off("mousedown.editPolygonsMode", clickHandler);
|
|
|
+ stage.off("click.editPolygonsMode", clickHandler);
|
|
|
stage.off("mousedown.editPolygonsMode", downHandler);
|
|
|
stage.off("mousemove.editPolygonsMode", moveHandler);
|
|
|
stage.off("mouseup.editPolygonsMode", upHandler);
|
|
|
+ document.removeEventListener("keydown", quitHandler);
|
|
|
|
|
|
helperInfo.value = undefined;
|
|
|
edit.end();
|
|
@@ -110,6 +107,7 @@ export const penWholeLinePoygonsEditWithHelperMouse = <
|
|
|
stage.on("mousemove.editPolygonsMode", moveHandler);
|
|
|
stage.on("mouseup.editPolygonsMode", upHandler);
|
|
|
stage.on("mousedown.editPolygonsMode", clickHandler);
|
|
|
+ document.addEventListener("keydown", quitHandler);
|
|
|
|
|
|
return {
|
|
|
helperInfo,
|
|
@@ -218,3 +216,71 @@ export const wholeLineAnalysisHelperInfo = (
|
|
|
cloneLines,
|
|
|
};
|
|
|
};
|
|
|
+
|
|
|
+export const penWholeLinePoygonsEditWithHelperShapesMouse = <
|
|
|
+ W extends WholeLineAttrib
|
|
|
+>(
|
|
|
+ props: PenWholeLinePoygonsEditProps<WLP<W>> & { quitHandler?: () => void },
|
|
|
+ tel: Group | Layer
|
|
|
+) => {
|
|
|
+ const { helperInfo: helperInfoRaw, destory: mouseDestory } =
|
|
|
+ penWholeLinePoygonsEditWithHelperMouse({
|
|
|
+ ...props,
|
|
|
+ quitHandler: () => {
|
|
|
+ stopWatchHelper();
|
|
|
+ props.quitHandler && props.quitHandler();
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const helperInfo = computed(
|
|
|
+ () =>
|
|
|
+ helperInfoRaw.value &&
|
|
|
+ wholeLineAnalysisHelperInfo(helperInfoRaw.value, props.autoClose)
|
|
|
+ );
|
|
|
+
|
|
|
+ const tempPoint = pointShapeFactory();
|
|
|
+ tempPoint.shape.listening(false);
|
|
|
+
|
|
|
+ const tempLine = lineShapeFactory();
|
|
|
+ tempLine.active();
|
|
|
+ tempLine.shape.dash([5, 5]);
|
|
|
+ tempLine.shape.listening(false);
|
|
|
+
|
|
|
+ const stopWatchHelper = watchEffect((onCleanup) => {
|
|
|
+ if (!helperInfo.value) return;
|
|
|
+
|
|
|
+ const { addLines, cloneLines, addPoints } = helperInfo.value;
|
|
|
+
|
|
|
+ const lineShapes = [...addLines, ...Object.values(cloneLines)].map(
|
|
|
+ (line) => {
|
|
|
+ tempLine.setData(line);
|
|
|
+ return tempLine.shape.clone() as Group;
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ const [scale] = getRealAbsoluteSize(tel as any, [1, 1]);
|
|
|
+ const pointShapes = addPoints.map((point) => {
|
|
|
+ tempPoint.setData(point);
|
|
|
+ tempPoint.shape.scale({ x: scale, y: scale });
|
|
|
+ return tempPoint.shape.clone() as Group;
|
|
|
+ });
|
|
|
+
|
|
|
+ tel.add(...lineShapes, ...pointShapes);
|
|
|
+
|
|
|
+ let clearCursor;
|
|
|
+ if (helperInfo.value.delPoints.length) {
|
|
|
+ clearCursor = props.tree.setCursor(delMouseIco);
|
|
|
+ } else if (addPoints.length) {
|
|
|
+ clearCursor = props.tree.setCursor(addMouseIco);
|
|
|
+ }
|
|
|
+
|
|
|
+ onCleanup(() => {
|
|
|
+ [...lineShapes, ...pointShapes].forEach((shape) => {
|
|
|
+ shape.remove();
|
|
|
+ });
|
|
|
+ clearCursor && clearCursor();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return mouseDestory;
|
|
|
+};
|