From cb8d017390eb17adeaafd2bc98a27e2869be5742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=AF=97=E6=B4=A5?= <2723065175@qq.com> Date: Tue, 9 Apr 2024 03:08:14 +0000 Subject: [PATCH] =?UTF-8?q?!2666=20=E4=BC=98=E5=8C=96:=E5=9C=86=E5=BC=A7?= =?UTF-8?q?=E6=9D=BF=E6=8F=90=E5=8F=96=E5=BA=94=E7=94=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/TemplateRecord/ArcBoard.test.ts | 18 + src/Add-on/ArcBoard/DrawArcBoard.ts | 375 ++++++++++--------- src/UI/Components/Board/BoardConfigModal.tsx | 131 ++++++- 3 files changed, 328 insertions(+), 196 deletions(-) create mode 100644 __test__/TemplateRecord/ArcBoard.test.ts diff --git a/__test__/TemplateRecord/ArcBoard.test.ts b/__test__/TemplateRecord/ArcBoard.test.ts new file mode 100644 index 000000000..afa6557ec --- /dev/null +++ b/__test__/TemplateRecord/ArcBoard.test.ts @@ -0,0 +1,18 @@ +import { Factory } from "../../src/DatabaseServices/CADFactory"; +import { CADFiler } from "../../src/DatabaseServices/CADFiler"; +import { Database } from "../../src/DatabaseServices/Database"; +import { TemplateRecord } from "../../src/DatabaseServices/Template/TemplateRecord"; + +test('圆弧板模板倒角半径为0', () => +{ + let json = `[11,102,1,2,1,0,0,1,"",2,2,0,0,1,"Board",10,2,100,0,1,2,0,[0,1,0,0,-1,0,0,0,0,0,1,0,800,0,0,1],101,0,1,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],0,0,1,3,800,449.2333530337135,18,true,"Polyline",10,2,0,0,0,7,0,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],0,0,1,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],0,0,1,2,4,[0,0],0,[449.2333530337135,0],0,[449.2333530337135,800],0,[0,800],0,true,0,3,0,0,0,0,0,19,0,"层板","","","","","",0,0,"三合一",2,0,"0","0","0","0","","","",4,"三合一","三合一","三合一","三合一",true,true,1,"1","1",0,0,0,0,0,0,0,true,0,0,null,0,0,"","","","",0,false,0,"Polyline",10,2,0,0,0,2,0,[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],0,0,1,[1,0,0,0,0,1,0,0,0,0,1,0,-2914.643523520821,-28.28220860874053,0,1],0,0,1,2,4,[0,0],0,[183.64996103329167,0],0.41421356237309503,[260.03150412339346,76.3815430901018],0,[260.03150412339346,221.9850877696656],0,false,0,1,true,2,-1,0,6,6,2,0,0,0,3,0,1,119.97985,6,6,2,0,0,0,3,0,2,4,0,0,5,0,2,3,0,0,5,0,0,0,0,0,1,-1,0,2,5,0,0,1,"TemplateRecord",3,2,101,0,5,1,"圆弧板",0,0,0,11,"TemplateParam",2,"L","",800,null,"宽",1,null,null,null,0,false,"TemplateParam",2,"W","",260.031494140625,null,"深",1,null,null,null,0,false,"TemplateParam",2,"H","",221.985107421875,null,"高",1,null,null,null,0,false,"TemplateParam",2,"PX","",0,null,null,1,null,null,null,0,false,"TemplateParam",2,"PY","",0,null,null,1,null,null,null,0,false,"TemplateParam",2,"PZ","",0,null,null,1,null,null,null,0,false,"TemplateParam",2,"RX","",0,null,null,1,null,null,null,0,false,"TemplateParam",2,"RY","",0,null,null,1,null,null,null,0,false,"TemplateParam",2,"RZ","",0,null,null,1,null,null,null,0,false,"TemplateParam",2,"BH","",18,null,"板厚",1,null,null,null,0,false,"TemplateParam",2,"R","",0,null,"圆弧",1,null,null,null,1,"TemplateFilletAction",5,3,"动作1","R",null,1,100,0,0,0,1,-1.5,false,1,100,"",-1,1,2,6,0,0,0,1,2,7,0,0,1,"",2,8,0,0,0,2,9,0,0,0,1,2,10,0,0,1,"",2,11,0,0,0,0,1,2,12,0,0,5,0,0,null]`; + + Factory(TemplateRecord); + + let file = JSON.parse(json); + let f = new CADFiler(file); + let db = new Database().FileRead(f); + let template = db.TemplateTable.Objects[0].Root; + + template.UpdateTemplateTree(); +}); diff --git a/src/Add-on/ArcBoard/DrawArcBoard.ts b/src/Add-on/ArcBoard/DrawArcBoard.ts index 863ec6b1a..fa52e417b 100644 --- a/src/Add-on/ArcBoard/DrawArcBoard.ts +++ b/src/Add-on/ArcBoard/DrawArcBoard.ts @@ -29,221 +29,236 @@ export class Command_DrawArcBoard implements Command if (pathRes.Status !== PromptStatus.OK) return; let path1 = pathRes.Entity as Polyline; - UCSUtils.UCSMtx = path1.OCS; - - path1 = ArcBoardBuild.OffsetPolyline(path1, 18); - path1 = ArcBoardBuild.OffsetPolyline(path1, -18); - - // 2.指定要偏移的方向 - let offsetDis = 18; - let oldDir = 0; - let isClose = path1.IsClose; - const ptRes = await app.Editor.GetPoint({ - DisabledSnap: true, - Msg: "指定要偏移的方向", - Callback: (p: Vector3) => + await DrawArcBoard(path1); + } +} + +export async function GetArcBoardParams(path1: Polyline) +{ + UCSUtils.UCSMtx = path1.OCS; + + path1 = ArcBoardBuild.OffsetPolyline(path1, 18); + path1 = ArcBoardBuild.OffsetPolyline(path1, -18); + + // 2.指定要偏移的方向 + let offsetDis = 18; + let oldDir = 0; + let isClose = path1.IsClose; + const ptRes = await app.Editor.GetPoint({ + DisabledSnap: true, + Msg: "指定要偏移的方向", + Callback: (p: Vector3) => + { + let dir = GetPointAtCurveDir(path1, p); + if (dir !== oldDir) { - let dir = GetPointAtCurveDir(path1, p); - if (dir !== oldDir) + JigUtils.Destroy(); + let offCus = path1.GetOffsetCurves(offsetDis * dir); + offCus.forEach(c => { - JigUtils.Destroy(); - let offCus = path1.GetOffsetCurves(offsetDis * dir); - offCus.forEach(c => + c.ColorIndex = 8; + JigUtils.Draw(c); + // 首尾不相连,才需求补线 + if (!isClose) { - c.ColorIndex = 8; - JigUtils.Draw(c); - // 首尾不相连,才需求补线 - if (!isClose) - { - let line1 = new Line(c.StartPoint, path1.StartPoint); - let line2 = new Line(c.EndPoint, path1.EndPoint); - line1.ColorIndex = 8; - line2.ColorIndex = 8; - - JigUtils.Draw(line1); - JigUtils.Draw(line2); - } - }); - oldDir = dir; - } + let line1 = new Line(c.StartPoint, path1.StartPoint); + let line2 = new Line(c.EndPoint, path1.EndPoint); + line1.ColorIndex = 8; + line2.ColorIndex = 8; + + JigUtils.Draw(line1); + JigUtils.Draw(line2); + } + }); + oldDir = dir; } - }); - if (ptRes.Status !== PromptStatus.OK) return; - - let odir = GetPointAtCurveDir(path1, ptRes.Point); - let path2 = path1.GetOffsetCurves(offsetDis * odir)[0]; - path1 = path1.Clone(); - JigUtils.Draw(path1); - JigUtils.Draw(path2); - - // 3.选择见光面 - const faceRes = await app.Editor.GetPoint({ - DisabledSnap: true, - Msg: "选择见光面", - Callback: (p: Vector3) => + } + }); + if (ptRes.Status !== PromptStatus.OK) return; + + let odir = GetPointAtCurveDir(path1, ptRes.Point); + let path2 = path1.GetOffsetCurves(offsetDis * odir)[0]; + path1 = path1.Clone(); + JigUtils.Draw(path1); + JigUtils.Draw(path2); + + // 3.选择见光面 + const faceRes = await app.Editor.GetPoint({ + DisabledSnap: true, + Msg: "选择见光面", + Callback: (p: Vector3) => + { + let tdir = GetPointAtCurveDir(path1, p); + path1.ColorIndex = odir === tdir ? 8 : 2; + path2.ColorIndex = odir === tdir ? 2 : 8; + } + }); + if (faceRes.Status !== PromptStatus.OK) return; + + const params = { odir, faceRes, path2 }; + return params; +} + +export async function DrawArcBoard(path1: Polyline) +{ + const params = await GetArcBoardParams(path1); + if (!params) return; + const { odir, faceRes, path2 } = params; + + //4.选择要弯曲的板 或者创建个板 + const brRes = await app.Editor.GetSelection({ + Msg: "选择要弯曲的板:", + Filter: { + filterTypes: [Board], + }, + KeyWordList: [ { - let tdir = GetPointAtCurveDir(path1, p); - path1.ColorIndex = odir === tdir ? 8 : 2; - path2.ColorIndex = odir === tdir ? 2 : 8; + key: "C", + msg: "创建板" } - }); - if (faceRes.Status !== PromptStatus.OK) return; - - //4.选择要弯曲的板 或者创建个板 - const brRes = await app.Editor.GetSelection({ - Msg: "选择要弯曲的板:", - Filter: { - filterTypes: [Board], - }, - KeyWordList: [ - { - key: "C", - msg: "创建板" - } - ] - }); + ] + }); - if (!(brRes.Status === PromptStatus.OK || brRes.Status === PromptStatus.Keyword)) return; + if (!(brRes.Status === PromptStatus.OK || brRes.Status === PromptStatus.Keyword)) return; - //见光面方向 - let fdir = GetPointAtCurveDir(path1, faceRes.Point); - let backPath: Polyline; - let brWidth: number; + //见光面方向 + let fdir = GetPointAtCurveDir(path1, faceRes.Point); + let backPath: Polyline; + let brWidth: number; - //如果见光面方向等于偏移方向 则使用path1 作为背面路径 - if (fdir === odir) - { - backPath = path1; - if (odir < 0) - backPath.Reverse(); + //如果见光面方向等于偏移方向 则使用path1 作为背面路径 + if (fdir === odir) + { + backPath = path1; + if (odir < 0) + backPath.Reverse(); - brWidth = Number.parseFloat(FixedNotZero(path2.Length, 5)); - } - else//反之 + brWidth = Number.parseFloat(FixedNotZero(path2.Length, 5)); + } + else//反之 + { + backPath = path2; + if (odir > 0) + backPath.Reverse(); + + brWidth = Number.parseFloat(FixedNotZero(path1.Length, 5)); + } + + if (brRes.Status === PromptStatus.Keyword) + { + const store = arcBoardStore; + store.m_Option.width = brWidth; + store.UpdateUIOption(); + app.Editor.ModalManage.RenderModal(BoardModal, { store, type: BoardModalType.ArcBr }); + const res = await app.Editor.ModalManage.Wait(); + if (res.Status === ModalState.Cancel) return; + + const { name, type, height, width, thickness } = store.m_Option; + //针对此path构件一个板 + let br = new Board().InitBoard(height, width, thickness, type); + br.Name = name; + br.BoardProcessOption = store.BoardProcessOption; + + if (brWidth != store.m_Option.width) { - backPath = path2; - if (odir > 0) - backPath.Reverse(); + br.FixArcSweepPathLength(); + } + + let x = backPath.EndPoint.sub(backPath.StartPoint).normalize(); + if (equalv3(x, ZeroVec)) + x = new Vector3(1, 0, 0); + let y = backPath.Normal; + let z = new Vector3().crossVectors(x, y); + + br.ApplyMatrix(new Matrix4().makeBasis(x, y, z).setPosition(backPath.StartPoint)); + br.SweepVisibleFace = FaceDirection.Front; - brWidth = Number.parseFloat(FixedNotZero(path1.Length, 5)); + let path = backPath.Clone(); + let [angle, isRev] = Path2BoardPath(br, path); + if (isRev) + { + console.error("未预料到的错误 我们已经根据起点和终点构建了 没想到还是出错了!!!!"); } + br.SetSweepPath(path, angle); + Draw(br); + } + else + { + const brs = brRes.SelectSet.SelectEntityList as Board[]; - if (brRes.Status === PromptStatus.Keyword) + enum Keep { - const store = arcBoardStore; - store.m_Option.width = brWidth; - store.UpdateUIOption(); - app.Editor.ModalManage.RenderModal(BoardModal, { store, type: BoardModalType.ArcBr }); - const res = await app.Editor.ModalManage.Wait(); - if (res.Status === ModalState.Cancel) return; - - const { name, type, height, width, thickness } = store.m_Option; - //针对此path构件一个板 - let br = new Board().InitBoard(height, width, thickness, type); - br.Name = name; - br.BoardProcessOption = store.BoardProcessOption; - - if (brWidth != store.m_Option.width) - { - br.FixArcSweepPathLength(); - } + none = 0, + br = 1, + path = 2, + } + let kp = Keep.none; - let x = backPath.EndPoint.sub(backPath.StartPoint).normalize(); - if (equalv3(x, ZeroVec)) - x = new Vector3(1, 0, 0); - let y = backPath.Normal; - let z = new Vector3().crossVectors(x, y); + let keyRes = await app.Editor.GetKeyWords({ + Msg: "请选择需要应用的尺寸", + KeyWordList: [ + { + key: "1", + msg: "路径" + }, + { + key: "2", + msg: "板" + } + ] + }); + if (keyRes.Status !== PromptStatus.Keyword) return; - br.ApplyMatrix(new Matrix4().makeBasis(x, y, z).setPosition(backPath.StartPoint)); - br.SweepVisibleFace = FaceDirection.Front; + kp = (keyRes.StringResult === "1") ? Keep.path : Keep.br; + for (let br of brs) + { let path = backPath.Clone(); let [angle, isRev] = Path2BoardPath(br, path); if (isRev) { - console.error("未预料到的错误 我们已经根据起点和终点构建了 没想到还是出错了!!!!"); - } - br.SetSweepPath(path, angle); - Draw(br); - } - else - { - const brs = brRes.SelectSet.SelectEntityList as Board[]; + let dir = FaceDirection.Front; + if (backPath === path1) + { + path = path2.Clone(); - enum Keep - { - none = 0, - br = 1, - path = 2, - } - let kp = Keep.none; + dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front; + } + else + { + path = path1.Clone(); - let keyRes = await app.Editor.GetKeyWords({ - Msg: "请选择需要应用的尺寸", - KeyWordList: [ - { - key: "1", - msg: "路径" - }, - { - key: "2", - msg: "板" - } - ] - }); - if (keyRes.Status !== PromptStatus.Keyword) return; + dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back; + } - kp = (keyRes.StringResult === "1") ? Keep.path : Keep.br; + br.SweepVisibleFace = dir; + //TODO:正确的计算见光面 - for (let br of brs) + [angle, isRev] = Path2BoardPath(br, path); + } + else { - let path = backPath.Clone(); - let [angle, isRev] = Path2BoardPath(br, path); - if (isRev) + let dir: FaceDirection; + if (backPath === path1) { - let dir = FaceDirection.Front; - if (backPath === path1) - { - path = path2.Clone(); - - dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front; - } - else - { - path = path1.Clone(); - - dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back; - } - - br.SweepVisibleFace = dir; - //TODO:正确的计算见光面 - - [angle, isRev] = Path2BoardPath(br, path); + dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back; } else { - let dir: FaceDirection; - if (backPath === path1) - { - dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back; - } - else - { - dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front; - } - br.SweepVisibleFace = dir; + dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front; } + br.SweepVisibleFace = dir; + } - br.SetSweepPath(path, angle); + br.SetSweepPath(path, angle); - let length = br.ArcBuild.SweepLength; - let brLength = br.ParseBoardLengthInArcSweep(); + let length = br.ArcBuild.SweepLength; + let brLength = br.ParseBoardLengthInArcSweep(); - if (kp === Keep.path || (length < brLength && path.IsClose)) - br.FixContourByArcSweepPath(); - else - br.FixArcSweepPathLength(); - } + if (kp === Keep.path || (length < brLength && path.IsClose)) + br.FixContourByArcSweepPath(); + else + br.FixArcSweepPathLength(); } } } diff --git a/src/UI/Components/Board/BoardConfigModal.tsx b/src/UI/Components/Board/BoardConfigModal.tsx index c7cc0a0a0..d23ef35df 100644 --- a/src/UI/Components/Board/BoardConfigModal.tsx +++ b/src/UI/Components/Board/BoardConfigModal.tsx @@ -5,13 +5,13 @@ import * as React from 'react'; import { MathUtils, Matrix4, Scene, Vector3 } from "three"; import { ArcBoardBuild } from "../../../Add-on/ArcBoard/ArcBoardBuild"; import { ArcBoardOptions } from "../../../Add-on/ArcBoard/ArcBoardFeeding"; -import { Path2BoardPath } from "../../../Add-on/ArcBoard/DrawArcBoard"; +import { GetArcBoardParams, Path2BoardPath } from "../../../Add-on/ArcBoard/DrawArcBoard"; import { ExtrudeApplyContour, SelectExtrudeContour, selectOutlinePosition } from "../../../Add-on/DrawBoard/DrawSpecialShapeBoardTool"; import { FaceDirection } from "../../../Add-on/DrawDrilling/DrillType"; import { app } from "../../../ApplicationServices/Application"; import { CheckObjectType } from "../../../Common/CheckoutVaildValue"; import { BigFaceSelectOption } from "../../../Common/CommonSelectOption"; -import { ConverCircleToPolyline, curveLinkGroup } from "../../../Common/CurveUtils"; +import { ConverCircleToPolyline, GetPointAtCurveDir, curveLinkGroup } from "../../../Common/CurveUtils"; import { DisposeThreeObj } from "../../../Common/Dispose"; import { ToplineUrls } from "../../../Common/HostUrl"; import { Log, LogType } from "../../../Common/Log"; @@ -33,7 +33,7 @@ import { Polyline } from "../../../DatabaseServices/Entity/Polyline"; import { Region } from "../../../DatabaseServices/Entity/Region"; import { CommandWrap } from "../../../Editor/CommandMachine"; import { JigUtils } from "../../../Editor/JigUtils"; -import { PromptStatus } from "../../../Editor/PromptResult"; +import { PromptPointResult, PromptStatus } from "../../../Editor/PromptResult"; import { SelectBox, SelectType } from "../../../Editor/SelectBox"; import { CreateContours } from "../../../Geometry/CreateContour2"; import { ContourTreeNode } from "../../../Geometry/ExtrudeMeshGeomBuilder/ExtrudeEdgeGeometry2"; @@ -72,7 +72,8 @@ const EDITOR_2D_PATH = "editor2dpath"; const EDITOR_3D_PATH = "editor3dpath"; @observer -export class BoardConfigModal extends React.Component{ +export class BoardConfigModal extends React.Component +{ private pars = [["height", "显示高"], ["width", "显示宽"], ["thickness", "显示厚"], ]; private groovePars = [ @@ -794,7 +795,7 @@ export class BoardConfigModal extends React.Component{ build.ParseSweepCurves(); let pls = build.SweepCurves1.map(c => c.Clone()); let pl = Polyline.Combine(pls); - pl.Position = br.Position; + pl.ApplyMatrix(new Matrix4().makeRotationX(Math.PI / 2)).ApplyMatrix(br.OCS).ApplyMatrix(build.Rotate2OCSMtx); let cu = JigUtils.Draw(pl); await selectOutlinePosition(cu); @@ -807,9 +808,107 @@ export class BoardConfigModal extends React.Component{ ChangeCurveBoard = async () => { + const DrawBoardByParams = async (br: Board, path1: Polyline, path2: Polyline, odir: number, faceRes: PromptPointResult) => + { + //见光面方向 + let fdir = GetPointAtCurveDir(path1, faceRes.Point); + let backPath: Polyline; + let brWidth: number; + + //如果见光面方向等于偏移方向 则使用path1 作为背面路径 + if (fdir === odir) + { + backPath = path1; + if (odir < 0) + backPath.Reverse(); + + brWidth = Number.parseFloat(FixedNotZero(path2.Length, 5)); + } + else//反之 + { + backPath = path2; + if (odir > 0) + backPath.Reverse(); + + brWidth = Number.parseFloat(FixedNotZero(path1.Length, 5)); + } + + enum Keep + { + none = 0, + br = 1, + path = 2, + } + let kp = Keep.none; + + let keyRes = await app.Editor.GetKeyWords({ + Msg: "请选择需要应用的尺寸", + KeyWordList: [ + { + key: "1", + msg: "路径" + }, + { + key: "2", + msg: "板" + } + ] + }); + if (keyRes.Status !== PromptStatus.Keyword) return; + + kp = (keyRes.StringResult === "1") ? Keep.path : Keep.br; + + let path = backPath.Clone(); + let [angle, isRev] = Path2BoardPath(br, path); + if (isRev) + { + let dir = FaceDirection.Front; + if (backPath === path1) + { + path = path2.Clone(); + + dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front; + } + else + { + path = path1.Clone(); + + dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back; + } + + br.SweepVisibleFace = dir; + //TODO:正确的计算见光面 + + [angle, isRev] = Path2BoardPath(br, path); + } + else + { + let dir: FaceDirection; + if (backPath === path1) + { + dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back; + } + else + { + dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front; + } + br.SweepVisibleFace = dir; + } + + br.SetSweepPath(path, angle); + + let length = br.ArcBuild.SweepLength; + let brLength = br.ParseBoardLengthInArcSweep(); + + if (kp === Keep.path || (length < brLength && path.IsClose)) + br.FixContourByArcSweepPath(); + else + br.FixArcSweepPathLength(); + }; + await CommandWrap(async () => { - let br = this.props.br; + const br = this.props.br; app.Editor.ModalManage.Destory(); let brsRes = await app.Editor.GetSelection({ @@ -855,22 +954,22 @@ export class BoardConfigModal extends React.Component{ let paths = cuRes.SelectSet.SelectEntityList as Curve[]; let pl = curveLinkGroup(paths)[0]; //应用第一个曲线 - let curves = Polyline.Combine(pl); + const path1 = Polyline.Combine(pl); - Path2BoardPath(br, curves); - curves.Move(curves.StartPoint.negate()); - br.SetSweepPath(curves, br.SweepAngle); - br.FixArcSweepPathLength(); + const params = await GetArcBoardParams(path1); + if (!params) return; + const { odir, faceRes, path2 } = params; + await DrawBoardByParams(br, path1, path2, odir, faceRes); } else { let pl = curveLinkGroup(cus)[0]; - let curves = Polyline.Combine(pl).Clone(); + const path1 = Polyline.Combine(pl).Clone(); - Path2BoardPath(br, curves); - curves.Move(curves.StartPoint.negate()); - br.SetSweepPath(curves, br.SweepAngle); - br.FixArcSweepPathLength(); + const params = await GetArcBoardParams(path1); + if (!params) return; + const { odir, faceRes, path2 } = params; + await DrawBoardByParams(br, path1, path2, odir, faceRes); } }, "圆弧应用"); };