diff --git a/src/Common/CurveUtils.ts b/src/Common/CurveUtils.ts index bcffd2fdb..bc47eb585 100644 --- a/src/Common/CurveUtils.ts +++ b/src/Common/CurveUtils.ts @@ -582,3 +582,22 @@ export function IsRect(cu: Curve): { isRect: boolean, size?: Vector3, box?: Box3 } return { isRect: false }; } + +/**用4个矩形点构造矩形 */ +export function getRectFrom4Pts(pts: Vector3[]) +{ + if (pts.length !== 4) return; + let p = pts.shift(); + pts.sort((p1, p2) => p.distanceTo(p1) - p.distanceTo(p2)); + pts.splice(1, 0, p); + let lineData = pts.map(p => + { + return { + pt: new Vector2(p.x, p.y), + bul: 0 + } + }); + let l = new Polyline(lineData); + l.CloseMark = true; + return l; +} diff --git a/src/Editor/UserConfig.ts b/src/Editor/UserConfig.ts index 73fc07f1f..7cf2da60c 100644 --- a/src/Editor/UserConfig.ts +++ b/src/Editor/UserConfig.ts @@ -28,8 +28,6 @@ export class UserConfig let type = sessionStorage.getItem(StoreageKeys.RenderType); if (type) this._renderType = parseFloat(type); - - this.openExactDrill = localStorage.getItem(StoreageKeys.ExactDrill) === "true"; } set RenderType(t: RenderType) { diff --git a/src/Geometry/SpaceParse/SurroundOutlineParse.ts b/src/Geometry/SpaceParse/SurroundOutlineParse.ts index 09811baf6..d25c56563 100644 --- a/src/Geometry/SpaceParse/SurroundOutlineParse.ts +++ b/src/Geometry/SpaceParse/SurroundOutlineParse.ts @@ -7,6 +7,8 @@ import { BoolOpeartionType } from "../../GraphicsSystem/BoolOperateUtils"; import { equaln, isParallelTo, isPerpendicularityTo } from "../GeUtils"; import { ISpaceParse } from "./ISpaceParse"; import { Board } from "../../DatabaseServices/Entity/Board"; +import { getRectFrom4Pts } from "../../Common/CurveUtils"; +import { arrayLast } from "../../Common/ArrayExt"; /** * 板件周围轮廓分析 @@ -27,13 +29,20 @@ export class SurroundOutlineParse extends ISpaceParse for (let br of brs) { let brNormal = br.Normal; - let box = br.BoundingBoxInOCS; - + let min = box.min; + let max = box.max; + //盒子8个点,避免盒子旋转后被破坏 + let pts = [ + min, new Vector3(max.x, min.y, min.z), + new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), + new Vector3(min.x, max.y, min.z), new Vector3(max.x, max.y, min.z), + new Vector3(min.x, max.y, max.z), max + ]; //br->ucs let mtx = new Matrix4().multiplyMatrices(ucsInv, br.OCS); - box.applyMatrix4(mtx); - + pts.forEach(p => p.applyMatrix4(mtx)); + pts.sort((p1, p2) => p1.z - p2.z); if (isParallelTo(brNormal, ucsNormal)) { let cu = br.ContourCurve; @@ -45,11 +54,11 @@ export class SurroundOutlineParse extends ISpaceParse } } else if (isPerpendicularityTo(brNormal, ucsNormal)) - pls.push(new Polyline().Create2Pt(box.min, box.max)); + pls.push(getRectFrom4Pts(pts.slice(0, 4))); else continue; - maxZ = Math.max(maxZ, box.max.z); + maxZ = Math.max(maxZ, arrayLast(pts).z); } let retCus = this.GetOutline(pls); @@ -93,44 +102,32 @@ export class SurroundOutlineParse extends ISpaceParse boxes.push(box); boxMap.set(box, br); } - - boxes.sort((b1, b2) => - { - let min1 = b1.min; - let min2 = b2.min; - if (!equaln(min1.x, min2.x)) - return min1.x - min2.x; - else if (equaln(min1.y, min2.y)) - return min1.y - min2.y; - else - return min1.z - min2.z; - }); - - let originBox: Box3; let boardList: Board[][] = []; - let usedBox = new WeakSet(); while (boxes.length > 0) { - originBox = boxes.shift(); - let brs = []; - if (!usedBox.has(originBox)) + let originBox = boxes.shift(); + let brs = [boxMap.get(originBox)]; + while (true) { - usedBox.add(originBox); - brs.push(boxMap.get(originBox)); - } - else continue; + let remBoxes = boxes.filter(b => + { + if (originBox.intersectsBox(b)) + { + originBox.union(b); + brs.push(boxMap.get(b)); + return false; + } + return true; + }) - for (let b of boxes) - { - if (usedBox.has(b)) continue; - if (originBox.intersectsBox(b)) + if (remBoxes.length === boxes.length) { - originBox.union(b); - brs.push(boxMap.get(b)); - usedBox.add(b); + boardList.push(brs); + break; } + else + boxes = remBoxes; } - boardList.push(brs); } return boardList; } diff --git a/src/UI/Components/Modal/OptionModal/DrawConfigPanel.tsx b/src/UI/Components/Modal/OptionModal/DrawConfigPanel.tsx index b5c7f36dd..1298ae511 100644 --- a/src/UI/Components/Modal/OptionModal/DrawConfigPanel.tsx +++ b/src/UI/Components/Modal/OptionModal/DrawConfigPanel.tsx @@ -3,7 +3,6 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import { app } from '../../../../ApplicationServices/Application'; import { UserConfig } from '../../../../Editor/UserConfig'; -import { StoreageKeys } from '../../../../Common/KeyEnum'; interface IConfigProps { @@ -36,15 +35,6 @@ export class DrawConfigPanel extends React.Component { checked={userConfig.openDrillingReactor} onChange={this.toggleDrillingReactor} /> - - { - userConfig.openExactDrill = !userConfig.openExactDrill; - localStorage.setItem(StoreageKeys.ExactDrill, String(userConfig.openExactDrill)) - }} - />
板件绘图配置