|
@@ -8,10 +8,9 @@ import { MathUtils } from "three";
|
|
import { DrawStore } from "@/core/store/index.ts";
|
|
import { DrawStore } from "@/core/store/index.ts";
|
|
import { getInitCtx, normalLineData } from "./use-draw.ts";
|
|
import { getInitCtx, normalLineData } from "./use-draw.ts";
|
|
|
|
|
|
-
|
|
|
|
export { default as Component } from "./line.vue";
|
|
export { default as Component } from "./line.vue";
|
|
export { default as TempComponent } from "./temp-line.vue";
|
|
export { default as TempComponent } from "./temp-line.vue";
|
|
-export { useDraw } from './use-draw.ts'
|
|
|
|
|
|
+export { useDraw } from "./use-draw.ts";
|
|
|
|
|
|
export const shapeName = "线段";
|
|
export const shapeName = "线段";
|
|
export const defaultStyle = {
|
|
export const defaultStyle = {
|
|
@@ -36,11 +35,11 @@ export const getMouseStyle = (data: LineData) => {
|
|
|
|
|
|
export const getSnapInfos = (data: LineData) => {
|
|
export const getSnapInfos = (data: LineData) => {
|
|
const vh = generateSnapInfos(getSnapPoints(data), true, false, true);
|
|
const vh = generateSnapInfos(getSnapPoints(data), true, false, true);
|
|
- data.lines.forEach(item => {
|
|
|
|
- const a = data.points.find(p => p.id === item.a)!
|
|
|
|
- const b = data.points.find(p => p.id === item.b)!
|
|
|
|
|
|
+ data.lines.forEach((item) => {
|
|
|
|
+ const a = data.points.find((p) => p.id === item.a)!;
|
|
|
|
+ const b = data.points.find((p) => p.id === item.b)!;
|
|
const prevVector = lineVector([a, b]);
|
|
const prevVector = lineVector([a, b]);
|
|
- const vLine = verticalVector(prevVector)
|
|
|
|
|
|
+ const vLine = verticalVector(prevVector);
|
|
|
|
|
|
vh.push({
|
|
vh.push({
|
|
point: a,
|
|
point: a,
|
|
@@ -48,9 +47,9 @@ export const getSnapInfos = (data: LineData) => {
|
|
linkDirections: [prevVector],
|
|
linkDirections: [prevVector],
|
|
linkAngle: [rangMod(MathUtils.radToDeg(vectorAngle(vLine)), 180)],
|
|
linkAngle: [rangMod(MathUtils.radToDeg(vectorAngle(vLine)), 180)],
|
|
});
|
|
});
|
|
- })
|
|
|
|
- return vh
|
|
|
|
-}
|
|
|
|
|
|
+ });
|
|
|
|
+ return vh;
|
|
|
|
+};
|
|
|
|
|
|
export const getSnapPoints = (data: LineData) => {
|
|
export const getSnapPoints = (data: LineData) => {
|
|
return data.points;
|
|
return data.points;
|
|
@@ -67,10 +66,10 @@ export type LineData = Partial<typeof defaultStyle> &
|
|
stroke: string;
|
|
stroke: string;
|
|
dash: number[];
|
|
dash: number[];
|
|
}[];
|
|
}[];
|
|
- polygon: { points: string[], id: string}[];
|
|
|
|
|
|
+ polygon: { points: string[]; id: string }[];
|
|
attitude: number[];
|
|
attitude: number[];
|
|
- updateTime?: number
|
|
|
|
- calcTime?: number
|
|
|
|
|
|
+ updateTime?: number;
|
|
|
|
+ calcTime?: number;
|
|
};
|
|
};
|
|
|
|
|
|
export const interactiveToData: InteractiveTo<"line"> = ({
|
|
export const interactiveToData: InteractiveTo<"line"> = ({
|
|
@@ -99,7 +98,7 @@ export const interactiveToData: InteractiveTo<"line"> = ({
|
|
export const interactiveFixData: InteractiveFix<"line"> = ({ data, info }) => {
|
|
export const interactiveFixData: InteractiveFix<"line"> = ({ data, info }) => {
|
|
const nv = [...info.consumed, info.cur!];
|
|
const nv = [...info.consumed, info.cur!];
|
|
|
|
|
|
- data.points.length = nv.length
|
|
|
|
|
|
+ data.points.length = nv.length;
|
|
for (let i = 0; i < nv.length; i++) {
|
|
for (let i = 0; i < nv.length; i++) {
|
|
if (inRevise(data.points[i], nv[i])) {
|
|
if (inRevise(data.points[i], nv[i])) {
|
|
if (!data.points[i]) {
|
|
if (!data.points[i]) {
|
|
@@ -115,7 +114,7 @@ export const interactiveFixData: InteractiveFix<"line"> = ({ data, info }) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- data.lines.length = nv.length - 1
|
|
|
|
|
|
+ data.lines.length = nv.length - 1;
|
|
for (let i = 0; i < nv.length - 1; i++) {
|
|
for (let i = 0; i < nv.length - 1; i++) {
|
|
if (!data.lines[i]) {
|
|
if (!data.lines[i]) {
|
|
data.lines[i] = {
|
|
data.lines[i] = {
|
|
@@ -156,15 +155,64 @@ export const getPredefine = (key: keyof LineData) => {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-
|
|
|
|
export const delItem = (store: DrawStore, data: LineData, childId: string) => {
|
|
export const delItem = (store: DrawStore, data: LineData, childId: string) => {
|
|
- const ndx = data.lines.findIndex(item => item.id === childId)
|
|
|
|
- if (!~ndx) return;
|
|
|
|
-
|
|
|
|
- const delLine = data.lines[ndx]
|
|
|
|
- const ctx = getInitCtx()
|
|
|
|
- ctx.del.lines[delLine.id] = delLine
|
|
|
|
- data.lines.splice(ndx, 1)
|
|
|
|
- normalLineData(data, ctx);
|
|
|
|
- store.setItem('line', {value: data, id: data.id})
|
|
|
|
-}
|
|
|
|
|
|
+ if (!childId) {
|
|
|
|
+ store.delItem("line", data.id);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let ndx;
|
|
|
|
+ if (~(ndx = data.lines.findIndex((item) => item.id === childId))) {
|
|
|
|
+ const delLine = data.lines[ndx];
|
|
|
|
+ const ctx = getInitCtx();
|
|
|
|
+ ctx.del.lines[delLine.id] = delLine;
|
|
|
|
+ data.lines.splice(ndx, 1);
|
|
|
|
+ normalLineData(data, ctx);
|
|
|
|
+ store.setItem("line", { value: data, id: data.id });
|
|
|
|
+ } else if (~(ndx = data.points.findIndex((item) => item.id === childId))) {
|
|
|
|
+ const { ctx } = delPoint(data, childId);
|
|
|
|
+ normalLineData(data, ctx);
|
|
|
|
+ store.setItem("line", { value: data, id: data.id });
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const delPoint = (data: LineData, id: string, ctx = getInitCtx()) => {
|
|
|
|
+ const p = data.points.find((item) => item.id === id);
|
|
|
|
+ if (!p) return { data, ctx };
|
|
|
|
+ const checkLines = data.lines.filter(
|
|
|
|
+ (item) => item.a === p.id || item.b === p.id
|
|
|
|
+ );
|
|
|
|
+ if (checkLines.length > 1) {
|
|
|
|
+ const joinPoints = new Set<string>();
|
|
|
|
+ checkLines.forEach((item) => {
|
|
|
|
+ joinPoints.add(item.a);
|
|
|
|
+ joinPoints.add(item.b);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (joinPoints.size === 3) {
|
|
|
|
+ const prev = checkLines.find((item) => item.b === p.id);
|
|
|
|
+ const next = checkLines.find((item) => item.a === p.id);
|
|
|
|
+ if (prev && next) {
|
|
|
|
+ const l = { ...prev, id: onlyId(), b: next.b };
|
|
|
|
+ ctx.add.lines[l.id] = l;
|
|
|
|
+ data.lines.push(l);
|
|
|
|
+ } else {
|
|
|
|
+ const l = prev || next || checkLines[0];
|
|
|
|
+ const ps = [...joinPoints].filter((item) => item !== p.id);
|
|
|
|
+ const nl = { ...l, id: onlyId(), a: ps[0], b: ps[1] };
|
|
|
|
+ ctx.add.lines[l.id] = nl;
|
|
|
|
+ data.lines.push(nl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ checkLines.forEach((l) => {
|
|
|
|
+ ctx.del.lines[l.id] = l;
|
|
|
|
+ const ndx = data.lines.findIndex((ln) => ln.id === l.id);
|
|
|
|
+ ~ndx && data.lines.splice(ndx, 1);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ ctx.del.points[p.id] = p;
|
|
|
|
+ const ndx = data.points.findIndex((pn) => pn.id === p.id);
|
|
|
|
+ ~ndx && data.points.splice(ndx, 1);
|
|
|
|
+ return { data, ctx };
|
|
|
|
+};
|