吸附点逻辑修改,集中区分隔线也加上这个吸附逻辑,相邻点的x/y
This commit is contained in:
parent
178c5758f2
commit
4794c99fbf
@ -9,7 +9,7 @@ import {
|
||||
addWayPoint,
|
||||
clearWayPoint,
|
||||
MenuItemOptions,
|
||||
ContextMenu
|
||||
ContextMenu,
|
||||
} from 'jl-graphic';
|
||||
import {
|
||||
IConcentrationDividingLineData,
|
||||
@ -25,6 +25,7 @@ import {
|
||||
Point,
|
||||
} from 'pixi.js';
|
||||
import { getWayLineIndex } from '../polygon/PolygonUtils';
|
||||
import { onEditPointCreate } from '../section/SectionDrawAssistant';
|
||||
|
||||
export class ConcentrationDividingLineDraw extends GraphicDrawAssistant<
|
||||
ConcentrationDividingLineTemplate,
|
||||
@ -194,7 +195,9 @@ export class ConcentrationDividingLinePointEditPlugin extends GraphicInteraction
|
||||
PolylineEditPlugin.Name
|
||||
);
|
||||
if (!lep) {
|
||||
lep = new PolylineEditPlugin(concentrationDividingLine);
|
||||
lep = new PolylineEditPlugin(concentrationDividingLine, {
|
||||
onEditPointCreate,
|
||||
});
|
||||
concentrationDividingLine.addAssistantAppend(lep);
|
||||
}
|
||||
lep.showAll();
|
||||
|
@ -54,6 +54,7 @@ import {
|
||||
SectionTemplate,
|
||||
SectionType,
|
||||
} from './Section';
|
||||
import { ConcentrationDividingLine } from '../concentrationDividingLine/ConcentrationDividingLine';
|
||||
|
||||
export class SectionDraw extends GraphicDrawAssistant<
|
||||
SectionTemplate,
|
||||
@ -337,18 +338,38 @@ export class SectionGraphicHitArea implements IHitArea {
|
||||
}
|
||||
}
|
||||
|
||||
function buildAbsorbablePositions(section: Section): AbsorbablePosition[] {
|
||||
function buildAbsorbablePositions(
|
||||
section: Section | ConcentrationDividingLine,
|
||||
dp: DraggablePoint
|
||||
): AbsorbablePosition[] {
|
||||
const aps: AbsorbablePosition[] = [];
|
||||
const [ps, pe] = [
|
||||
section.localToCanvasPoint(section.getStartPoint()),
|
||||
section.localToCanvasPoint(section.getEndPoint()),
|
||||
];
|
||||
const { width, height } = section.getGraphicApp().canvas;
|
||||
const xs = new AbsorbableLine({ x: 0, y: ps.y }, { x: width, y: ps.y });
|
||||
const ys = new AbsorbableLine({ x: ps.x, y: 0 }, { x: ps.x, y: height });
|
||||
const xe = new AbsorbableLine({ x: 0, y: pe.y }, { x: width, y: pe.y });
|
||||
const ye = new AbsorbableLine({ x: pe.x, y: 0 }, { x: pe.x, y: height });
|
||||
aps.push(xs, ys, xe, ye);
|
||||
const changePoints = section.localToCanvasPoints(...section.datas.points);
|
||||
for (let i = 0; i < changePoints.length; i++) {
|
||||
if (changePoints[i].equals(dp)) {
|
||||
const { width, height } = section.getGraphicApp().canvas;
|
||||
if (i == 0 || i == changePoints.length - 1) {
|
||||
const ps =
|
||||
i == 0 ? changePoints[1] : changePoints[changePoints.length - 2];
|
||||
const x = new AbsorbableLine({ x: 0, y: ps.y }, { x: width, y: ps.y });
|
||||
const y = new AbsorbableLine({ x: ps.x, y: 0 }, { x: ps.x, y: height });
|
||||
aps.push(x, y);
|
||||
} else {
|
||||
const generateAxisPoint = [changePoints[i - 1], changePoints[i + 1]];
|
||||
generateAxisPoint.forEach((point) => {
|
||||
const x = new AbsorbableLine(
|
||||
{ x: 0, y: point.y },
|
||||
{ x: width, y: point.y }
|
||||
);
|
||||
const y = new AbsorbableLine(
|
||||
{ x: point.x, y: 0 },
|
||||
{ x: point.x, y: height }
|
||||
);
|
||||
aps.push(x, y);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
const sections = section.queryStore
|
||||
.queryByType<Section>(Section.Type)
|
||||
.filter((g) => g.datas.sectionType == SectionType.Physical);
|
||||
@ -371,12 +392,12 @@ function buildAbsorbablePositions(section: Section): AbsorbablePosition[] {
|
||||
return aps;
|
||||
}
|
||||
|
||||
function onEditPointCreate(g: ILineGraphic, dp: DraggablePoint): void {
|
||||
const section = g as Section;
|
||||
export function onEditPointCreate(g: ILineGraphic, dp: DraggablePoint): void {
|
||||
const section = g as Section | ConcentrationDividingLine;
|
||||
dp.on('transformstart', (e: GraphicTransformEvent) => {
|
||||
if (e.isShift()) {
|
||||
section.getGraphicApp().setOptions({
|
||||
absorbablePositions: buildAbsorbablePositions(section),
|
||||
absorbablePositions: buildAbsorbablePositions(section, dp),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user