From 9118eae00f6760ead481bde717675d679d6ed13a Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 29 Aug 2023 14:50:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E9=94=AE=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=BB=A7=E7=94=B5=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../properties/RelayCabinetProperty.vue | 108 +++++++++++++++--- src/graphics/relayCabinet/RelayCabinet.ts | 2 - .../relayCabinet/RelayCabinetDrawAssistant.ts | 30 ++++- 3 files changed, 124 insertions(+), 16 deletions(-) diff --git a/src/components/draw-app/properties/RelayCabinetProperty.vue b/src/components/draw-app/properties/RelayCabinetProperty.vue index c57facd..2024fe7 100644 --- a/src/components/draw-app/properties/RelayCabinetProperty.vue +++ b/src/components/draw-app/properties/RelayCabinetProperty.vue @@ -8,10 +8,18 @@ label="继电器柜" lazy-rules /> + + diff --git a/src/graphics/relayCabinet/RelayCabinet.ts b/src/graphics/relayCabinet/RelayCabinet.ts index 67a02db..2c8fb0e 100644 --- a/src/graphics/relayCabinet/RelayCabinet.ts +++ b/src/graphics/relayCabinet/RelayCabinet.ts @@ -53,14 +53,12 @@ export class RelayCabinet extends JlGraphic { relayCabinetConsts.lineWidth, new Color(relayCabinetConsts.lineColor) ); - relayCabinetGraphic.beginFill(relayCabinetConsts.lineColor, 0.00001); relayCabinetGraphic.drawRect( 0, 0, relayCabinetConsts.width, relayCabinetConsts.height ); - relayCabinetGraphic.endFill; const rectP = new Rectangle( 0, 0, diff --git a/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts b/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts index ec337d8..8464230 100644 --- a/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts +++ b/src/graphics/relayCabinet/RelayCabinetDrawAssistant.ts @@ -1,4 +1,4 @@ -import { FederatedPointerEvent, Point } from 'pixi.js'; +import { FederatedPointerEvent, IHitArea, Point } from 'pixi.js'; import { AbsorbableLine, AbsorbablePosition, @@ -6,12 +6,14 @@ import { GraphicInteractionPlugin, JlDrawApp, JlGraphic, + linePoint, } from 'src/jl-graphic'; import { IRelayCabinetData, RelayCabinet, RelayCabinetTemplate, + relayCabinetConsts, } from './RelayCabinet'; export interface IRelayCabinetDrawOptions { @@ -78,6 +80,31 @@ function buildAbsorbablePositions( return aps; } +//碰撞检测 +export class RectGraphicHitArea implements IHitArea { + rect: RelayCabinet; + constructor(rect: RelayCabinet) { + this.rect = rect; + } + contains(x: number, y: number): boolean { + let contains = false; + const tolerance = relayCabinetConsts.lineWidth; + const p1 = new Point(0, 0); + const p2 = new Point(p1.x + relayCabinetConsts.width, p1.y); + const p3 = new Point( + p1.x + relayCabinetConsts.width, + p1.y + relayCabinetConsts.height + ); + const p4 = new Point(p1.x, p1.y + relayCabinetConsts.height); + const p = new Point(x, y); + contains = contains || linePoint(p1, p2, p, tolerance); + contains = contains || linePoint(p2, p3, p, tolerance); + contains = contains || linePoint(p3, p4, p, tolerance); + contains = contains || linePoint(p4, p1, p, tolerance); + return contains; + } +} + export class relayCabinetInteraction extends GraphicInteractionPlugin { static Name = 'relayCabinet_transform'; constructor(app: JlDrawApp) { @@ -97,6 +124,7 @@ export class relayCabinetInteraction extends GraphicInteractionPlugin