!2666 优化:圆弧板提取应用功能

pull/2667/MERGE
黄诗津 6 months ago committed by ChenX
parent 27131b5221
commit cb8d017390

@ -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();
});

@ -29,221 +29,236 @@ export class Command_DrawArcBoard implements Command
if (pathRes.Status !== PromptStatus.OK) return; if (pathRes.Status !== PromptStatus.OK) return;
let path1 = pathRes.Entity as Polyline; let path1 = pathRes.Entity as Polyline;
UCSUtils.UCSMtx = path1.OCS; await DrawArcBoard(path1);
}
path1 = ArcBoardBuild.OffsetPolyline(path1, 18); }
path1 = ArcBoardBuild.OffsetPolyline(path1, -18);
export async function GetArcBoardParams(path1: Polyline)
// 2.指定要偏移的方向 {
let offsetDis = 18; UCSUtils.UCSMtx = path1.OCS;
let oldDir = 0;
let isClose = path1.IsClose; path1 = ArcBoardBuild.OffsetPolyline(path1, 18);
const ptRes = await app.Editor.GetPoint({ path1 = ArcBoardBuild.OffsetPolyline(path1, -18);
DisabledSnap: true,
Msg: "指定要偏移的方向", // 2.指定要偏移的方向
Callback: (p: Vector3) => 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); JigUtils.Destroy();
if (dir !== oldDir) let offCus = path1.GetOffsetCurves(offsetDis * dir);
offCus.forEach(c =>
{ {
JigUtils.Destroy(); c.ColorIndex = 8;
let offCus = path1.GetOffsetCurves(offsetDis * dir); JigUtils.Draw(c);
offCus.forEach(c => // 首尾不相连,才需求补线
if (!isClose)
{ {
c.ColorIndex = 8; let line1 = new Line(c.StartPoint, path1.StartPoint);
JigUtils.Draw(c); let line2 = new Line(c.EndPoint, path1.EndPoint);
// 首尾不相连,才需求补线 line1.ColorIndex = 8;
if (!isClose) line2.ColorIndex = 8;
{
let line1 = new Line(c.StartPoint, path1.StartPoint); JigUtils.Draw(line1);
let line2 = new Line(c.EndPoint, path1.EndPoint); JigUtils.Draw(line2);
line1.ColorIndex = 8; }
line2.ColorIndex = 8; });
oldDir = dir;
JigUtils.Draw(line1);
JigUtils.Draw(line2);
}
});
oldDir = dir;
}
} }
}); }
if (ptRes.Status !== PromptStatus.OK) return; });
if (ptRes.Status !== PromptStatus.OK) return;
let odir = GetPointAtCurveDir(path1, ptRes.Point);
let path2 = path1.GetOffsetCurves(offsetDis * odir)[0]; let odir = GetPointAtCurveDir(path1, ptRes.Point);
path1 = path1.Clone(); let path2 = path1.GetOffsetCurves(offsetDis * odir)[0];
JigUtils.Draw(path1); path1 = path1.Clone();
JigUtils.Draw(path2); JigUtils.Draw(path1);
JigUtils.Draw(path2);
// 3.选择见光面
const faceRes = await app.Editor.GetPoint({ // 3.选择见光面
DisabledSnap: true, const faceRes = await app.Editor.GetPoint({
Msg: "选择见光面", DisabledSnap: true,
Callback: (p: Vector3) => 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); key: "C",
path1.ColorIndex = odir === tdir ? 8 : 2; msg: "创建板"
path2.ColorIndex = odir === tdir ? 2 : 8;
} }
}); ]
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 fdir = GetPointAtCurveDir(path1, faceRes.Point);
let backPath: Polyline; let backPath: Polyline;
let brWidth: number; let brWidth: number;
//如果见光面方向等于偏移方向 则使用path1 作为背面路径 //如果见光面方向等于偏移方向 则使用path1 作为背面路径
if (fdir === odir) if (fdir === odir)
{ {
backPath = path1; backPath = path1;
if (odir < 0) if (odir < 0)
backPath.Reverse(); backPath.Reverse();
brWidth = Number.parseFloat(FixedNotZero(path2.Length, 5)); brWidth = Number.parseFloat(FixedNotZero(path2.Length, 5));
} }
else//反之 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; br.FixArcSweepPathLength();
if (odir > 0) }
backPath.Reverse();
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; none = 0,
store.m_Option.width = brWidth; br = 1,
store.UpdateUIOption(); path = 2,
app.Editor.ModalManage.RenderModal(BoardModal, { store, type: BoardModalType.ArcBr }); }
const res = await app.Editor.ModalManage.Wait(); let kp = Keep.none;
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();
}
let x = backPath.EndPoint.sub(backPath.StartPoint).normalize(); let keyRes = await app.Editor.GetKeyWords({
if (equalv3(x, ZeroVec)) Msg: "请选择需要应用的尺寸",
x = new Vector3(1, 0, 0); KeyWordList: [
let y = backPath.Normal; {
let z = new Vector3().crossVectors(x, y); key: "1",
msg: "路径"
},
{
key: "2",
msg: "板"
}
]
});
if (keyRes.Status !== PromptStatus.Keyword) return;
br.ApplyMatrix(new Matrix4().makeBasis(x, y, z).setPosition(backPath.StartPoint)); kp = (keyRes.StringResult === "1") ? Keep.path : Keep.br;
br.SweepVisibleFace = FaceDirection.Front;
for (let br of brs)
{
let path = backPath.Clone(); let path = backPath.Clone();
let [angle, isRev] = Path2BoardPath(br, path); let [angle, isRev] = Path2BoardPath(br, path);
if (isRev) if (isRev)
{ {
console.error("未预料到的错误 我们已经根据起点和终点构建了 没想到还是出错了!!!!"); let dir = FaceDirection.Front;
} if (backPath === path1)
br.SetSweepPath(path, angle); {
Draw(br); path = path2.Clone();
}
else
{
const brs = brRes.SelectSet.SelectEntityList as Board[];
enum Keep dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front;
{ }
none = 0, else
br = 1, {
path = 2, path = path1.Clone();
}
let kp = Keep.none;
let keyRes = await app.Editor.GetKeyWords({ dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back;
Msg: "请选择需要应用的尺寸", }
KeyWordList: [
{
key: "1",
msg: "路径"
},
{
key: "2",
msg: "板"
}
]
});
if (keyRes.Status !== PromptStatus.Keyword) return;
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 dir: FaceDirection;
let [angle, isRev] = Path2BoardPath(br, path); if (backPath === path1)
if (isRev)
{ {
let dir = FaceDirection.Front; dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back;
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 else
{ {
let dir: FaceDirection; dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front;
if (backPath === path1)
{
dir = (fdir === odir) ? FaceDirection.Front : FaceDirection.Back;
}
else
{
dir = (fdir === odir) ? FaceDirection.Back : FaceDirection.Front;
}
br.SweepVisibleFace = dir;
} }
br.SweepVisibleFace = dir;
}
br.SetSweepPath(path, angle); br.SetSweepPath(path, angle);
let length = br.ArcBuild.SweepLength; let length = br.ArcBuild.SweepLength;
let brLength = br.ParseBoardLengthInArcSweep(); let brLength = br.ParseBoardLengthInArcSweep();
if (kp === Keep.path || (length < brLength && path.IsClose)) if (kp === Keep.path || (length < brLength && path.IsClose))
br.FixContourByArcSweepPath(); br.FixContourByArcSweepPath();
else else
br.FixArcSweepPathLength(); br.FixArcSweepPathLength();
}
} }
} }
} }

@ -5,13 +5,13 @@ import * as React from 'react';
import { MathUtils, Matrix4, Scene, Vector3 } from "three"; import { MathUtils, Matrix4, Scene, Vector3 } from "three";
import { ArcBoardBuild } from "../../../Add-on/ArcBoard/ArcBoardBuild"; import { ArcBoardBuild } from "../../../Add-on/ArcBoard/ArcBoardBuild";
import { ArcBoardOptions } from "../../../Add-on/ArcBoard/ArcBoardFeeding"; 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 { ExtrudeApplyContour, SelectExtrudeContour, selectOutlinePosition } from "../../../Add-on/DrawBoard/DrawSpecialShapeBoardTool";
import { FaceDirection } from "../../../Add-on/DrawDrilling/DrillType"; import { FaceDirection } from "../../../Add-on/DrawDrilling/DrillType";
import { app } from "../../../ApplicationServices/Application"; import { app } from "../../../ApplicationServices/Application";
import { CheckObjectType } from "../../../Common/CheckoutVaildValue"; import { CheckObjectType } from "../../../Common/CheckoutVaildValue";
import { BigFaceSelectOption } from "../../../Common/CommonSelectOption"; import { BigFaceSelectOption } from "../../../Common/CommonSelectOption";
import { ConverCircleToPolyline, curveLinkGroup } from "../../../Common/CurveUtils"; import { ConverCircleToPolyline, GetPointAtCurveDir, curveLinkGroup } from "../../../Common/CurveUtils";
import { DisposeThreeObj } from "../../../Common/Dispose"; import { DisposeThreeObj } from "../../../Common/Dispose";
import { ToplineUrls } from "../../../Common/HostUrl"; import { ToplineUrls } from "../../../Common/HostUrl";
import { Log, LogType } from "../../../Common/Log"; import { Log, LogType } from "../../../Common/Log";
@ -33,7 +33,7 @@ import { Polyline } from "../../../DatabaseServices/Entity/Polyline";
import { Region } from "../../../DatabaseServices/Entity/Region"; import { Region } from "../../../DatabaseServices/Entity/Region";
import { CommandWrap } from "../../../Editor/CommandMachine"; import { CommandWrap } from "../../../Editor/CommandMachine";
import { JigUtils } from "../../../Editor/JigUtils"; import { JigUtils } from "../../../Editor/JigUtils";
import { PromptStatus } from "../../../Editor/PromptResult"; import { PromptPointResult, PromptStatus } from "../../../Editor/PromptResult";
import { SelectBox, SelectType } from "../../../Editor/SelectBox"; import { SelectBox, SelectType } from "../../../Editor/SelectBox";
import { CreateContours } from "../../../Geometry/CreateContour2"; import { CreateContours } from "../../../Geometry/CreateContour2";
import { ContourTreeNode } from "../../../Geometry/ExtrudeMeshGeomBuilder/ExtrudeEdgeGeometry2"; import { ContourTreeNode } from "../../../Geometry/ExtrudeMeshGeomBuilder/ExtrudeEdgeGeometry2";
@ -72,7 +72,8 @@ const EDITOR_2D_PATH = "editor2dpath";
const EDITOR_3D_PATH = "editor3dpath"; const EDITOR_3D_PATH = "editor3dpath";
@observer @observer
export class BoardConfigModal extends React.Component<BoardConfigProps, {}>{ export class BoardConfigModal extends React.Component<BoardConfigProps, {}>
{
private pars = [["height", "显示高"], ["width", "显示宽"], ["thickness", "显示厚"], private pars = [["height", "显示高"], ["width", "显示宽"], ["thickness", "显示厚"],
]; ];
private groovePars = [ private groovePars = [
@ -794,7 +795,7 @@ export class BoardConfigModal extends React.Component<BoardConfigProps, {}>{
build.ParseSweepCurves(); build.ParseSweepCurves();
let pls = build.SweepCurves1.map(c => c.Clone()); let pls = build.SweepCurves1.map(c => c.Clone());
let pl = Polyline.Combine(pls); 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); let cu = JigUtils.Draw(pl);
await selectOutlinePosition(cu); await selectOutlinePosition(cu);
@ -807,9 +808,107 @@ export class BoardConfigModal extends React.Component<BoardConfigProps, {}>{
ChangeCurveBoard = async () => 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 () => await CommandWrap(async () =>
{ {
let br = this.props.br; const br = this.props.br;
app.Editor.ModalManage.Destory(); app.Editor.ModalManage.Destory();
let brsRes = await app.Editor.GetSelection({ let brsRes = await app.Editor.GetSelection({
@ -855,22 +954,22 @@ export class BoardConfigModal extends React.Component<BoardConfigProps, {}>{
let paths = cuRes.SelectSet.SelectEntityList as Curve[]; let paths = cuRes.SelectSet.SelectEntityList as Curve[];
let pl = curveLinkGroup(paths)[0]; //应用第一个曲线 let pl = curveLinkGroup(paths)[0]; //应用第一个曲线
let curves = Polyline.Combine(pl); const path1 = Polyline.Combine(pl);
Path2BoardPath(br, curves); const params = await GetArcBoardParams(path1);
curves.Move(curves.StartPoint.negate()); if (!params) return;
br.SetSweepPath(curves, br.SweepAngle); const { odir, faceRes, path2 } = params;
br.FixArcSweepPathLength(); await DrawBoardByParams(br, path1, path2, odir, faceRes);
} }
else else
{ {
let pl = curveLinkGroup(cus)[0]; let pl = curveLinkGroup(cus)[0];
let curves = Polyline.Combine(pl).Clone(); const path1 = Polyline.Combine(pl).Clone();
Path2BoardPath(br, curves); const params = await GetArcBoardParams(path1);
curves.Move(curves.StartPoint.negate()); if (!params) return;
br.SetSweepPath(curves, br.SweepAngle); const { odir, faceRes, path2 } = params;
br.FixArcSweepPathLength(); await DrawBoardByParams(br, path1, path2, odir, faceRes);
} }
}, "圆弧应用"); }, "圆弧应用");
}; };

Loading…
Cancel
Save