设置倒角半径和shift切换到角点

pull/24/head
wangsan 7 years ago
parent 9a78764b7c
commit 8db8adfb60

@ -8,12 +8,17 @@ import { Command } from '../Editor/CommandMachine';
import { PromptEntityResult, PromptStatus } from '../Editor/PromptResult';
import { angle, midPoint } from '../Geometry/GeUtils';
import { Intersect } from '../GraphicsSystem/IntersectWith';
import { KeyBoard } from '../Common/KeyEnum';
enum FilletState { Invalid = -1, Normal, Parallel, RadiousInvalid }
export class CommandFillet implements Command
{
static m_radiousRecord: number = 0;//记录设置的半径值
private m_radious: number = 0;
async exec()
{
this.m_radious = CommandFillet.m_radiousRecord;
//拾取曲线1.
let enRes = await this.SelectCurve([
{ msg: "放弃", key: "U" },
@ -38,41 +43,49 @@ export class CommandFillet implements Command
let new_cu1 = this.SplitCurve(cu1, in_pts, enRes.Point);
let new_cu2 = this.SplitCurve(cu2, in_pts, enRes2.Point);
//偏移
let off_cu1 = this.OffsetCurve(new_cu1, new_cu2, 3);
let off_cu2 = this.OffsetCurve(new_cu2, new_cu1, 3);
//圆心
let center = off_cu1.IntersectWith(off_cu2, Intersect.ExtendBoth)[0];
//圆弧点1
let arcP1 = new_cu1.GetClosestPointTo(center, true);
if (!new_cu1.PtOnCurve(arcP1))
//按下shift键时半径归0
if (app.m_Editor.m_KeyCtrl.KeyIsDown(KeyBoard.Shift))
{
app.m_Editor.m_CommandStore.Prompt("半径过大");
return;
this.m_radious = 0;
}
//圆弧点2
let arcP2 = new_cu2.GetClosestPointTo(center, true);
if (!new_cu2.PtOnCurve(arcP2))
if (this.m_radious > 0)
{
app.m_Editor.m_CommandStore.Prompt("半径过大");
return;
}
//偏移
let off_cu1 = this.OffsetCurve(new_cu1, new_cu2, this.m_radious);
let off_cu2 = this.OffsetCurve(new_cu2, new_cu1, this.m_radious);
//圆心
let center = off_cu1.IntersectWith(off_cu2, Intersect.ExtendBoth)[0];
//圆弧点1
let arcP1 = new_cu1.GetClosestPointTo(center, true);
if (!new_cu1.PtOnCurve(arcP1))
{
app.m_Editor.m_CommandStore.Prompt("半径过大");
return;
}
//圆弧点2
let arcP2 = new_cu2.GetClosestPointTo(center, true);
if (!new_cu2.PtOnCurve(arcP2))
{
app.m_Editor.m_CommandStore.Prompt("半径过大");
return;
}
//时针校验
let v1 = arcP1.clone().sub(center);
let v2 = arcP2.clone().sub(center);
let [startAngle, endAngle] = [angle(v1), angle(v2)];
if (v1.cross(v2).z > 0)
[startAngle, endAngle] = [endAngle, startAngle];
//时针校验
let v1 = arcP1.clone().sub(center);
let v2 = arcP2.clone().sub(center);
let [startAngle, endAngle] = [angle(v1), angle(v2)];
if (v1.cross(v2).z > 0)
[startAngle, endAngle] = [endAngle, startAngle];
//绘制圆弧
let arc = new Arc(center, 3, startAngle, endAngle);
app.m_Database.ModelSpace.Append(arc);
//绘制圆弧
let arc = new Arc(center, this.m_radious, startAngle, endAngle);
app.m_Database.ModelSpace.Append(arc);
//延伸或者裁剪到圆弧点
this.ExtendPt(new_cu1 as Line, in_pts[0], arcP1);
this.ExtendPt(new_cu2 as Line, in_pts[0], arcP2);
//延伸或者裁剪到圆弧点
this.ExtendPt(new_cu1 as Line, in_pts[0], arcP1);
this.ExtendPt(new_cu2 as Line, in_pts[0], arcP2);
}
cu1.CopyFrom(new_cu1);
cu2.CopyFrom(new_cu2);
@ -169,7 +182,7 @@ export class CommandFillet implements Command
while (true)
{
let enRes = await app.m_Editor.GetEntity({
Msg: oldCurve ? "选择第二个对象:" : "选择第一个对象:",
Msg: oldCurve ? "选择第二个对象,或按住shift键选择对象以应用角点或" : "选择第一个对象:",
KeyWordList: keyword,
});
switch (enRes.Status)
@ -186,7 +199,22 @@ export class CommandFillet implements Command
break;
case PromptStatus.Cancel:
return undefined;
case PromptStatus.Keyword:
{
if (enRes.StringResult == "R")
{
let ret = await app.m_Editor.GetDistance({ Msg: "指定圆角半径:" });
if (ret.Status == PromptStatus.OK)
{
this.m_radious = ret.Value;
CommandFillet.m_radiousRecord = ret.Value;
}
}
}
break;
default:
break;
}
}

Loading…
Cancel
Save