mirror of https://gitee.com/cf-fz/WebCAD.git
parent
6cbe7a5d39
commit
50aaabeed9
@ -1,55 +1,44 @@
|
||||
import * as THREE from 'three';
|
||||
import { Vector3, Vector2 } from 'three';
|
||||
|
||||
import { app } from '../ApplicationServices/Application';
|
||||
import { Arc } from '../DatabaseServices/Arc';
|
||||
import { Command } from '../Editor/CommandMachine';
|
||||
import { PromptStatus } from '../Editor/PromptResult';
|
||||
import { RenderType } from '../GraphicsSystem/Enum';
|
||||
import { Arc } from '../DatabaseServices/Arc';
|
||||
|
||||
export class DrawArc implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let pt1 = app.m_Editor.m_MouseCtrl.m_CurMousePointWCS.clone();
|
||||
let pt2 = pt1;
|
||||
let pt3 = pt2;
|
||||
|
||||
app.m_Editor.UpdateScreen();
|
||||
let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入第一个点:" });
|
||||
if (ptRes.Status != PromptStatus.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pt1 = ptRes.Value;
|
||||
let pt1 = ptRes.Value;
|
||||
let ptRes2 = await app.m_Editor.GetPoint({ Msg: "请输入第二个点:", BasePoint: pt1, AllowDrawRubberBand: true });
|
||||
if (ptRes2.Status != PromptStatus.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pt2 = ptRes2.Value;
|
||||
let pt2 = ptRes2.Value;
|
||||
|
||||
let arc = new Arc();
|
||||
arc.ApplyMatrix(app.m_Editor.UCSMatrix);
|
||||
|
||||
app.m_Database.ModelSpace.Append(arc);
|
||||
app.m_Editor.AddNoSnapEntity(arc);
|
||||
|
||||
let ptRes3 = await app.m_Editor.GetPoint({
|
||||
Msg: "请输入第三个点:", Callback: (p) =>
|
||||
const updateArc = (p) =>
|
||||
{
|
||||
if (!p.equals(pt2) && !p.equals(pt1))
|
||||
{
|
||||
arc.FromThreePoint(pt1, pt2, p);
|
||||
arc.Update();
|
||||
if (!arc.Id)
|
||||
{
|
||||
app.m_Database.ModelSpace.Append(arc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let ptRes3 = await app.m_Editor.GetPoint({
|
||||
Msg: "请输入第三个点:",
|
||||
Callback: updateArc
|
||||
});
|
||||
if (ptRes.Status != PromptStatus.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
app.m_Database.hm.EndCmd();
|
||||
|
||||
if (ptRes3.Status != PromptStatus.OK)
|
||||
arc.Erase();
|
||||
else
|
||||
updateArc(ptRes3.Value);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
import * as THREE from 'three';
|
||||
import { Box3, Vector3 } from 'three';
|
||||
import { app } from '../ApplicationServices/Application';
|
||||
import { Vec3DTo2D } from '../Common/CurveUtils';
|
||||
import { Polyline } from '../DatabaseServices/Polyline';
|
||||
import { Command } from '../Editor/CommandMachine';
|
||||
import { PromptStatus } from '../Editor/PromptResult';
|
||||
export class DrawRect implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ptRes = await app.m_Editor.GetPoint();
|
||||
if (ptRes.Status != PromptStatus.OK)
|
||||
return;
|
||||
|
||||
let p1: THREE.Vector3;
|
||||
let p2: THREE.Vector3;
|
||||
p1 = ptRes.Value;
|
||||
|
||||
let rec = new Polyline();
|
||||
rec.CloseMark = true;
|
||||
rec.ApplyMatrix(app.m_Editor.UCSMatrix);
|
||||
|
||||
app.m_Database.ModelSpace.Append(rec);
|
||||
app.m_Editor.AddNoSnapEntity(rec);
|
||||
|
||||
let box = new Box3();
|
||||
let updateRect = (p1, p2) =>
|
||||
{
|
||||
box.setFromPoints([p2, p1].map((p: Vector3) => p.clone().applyMatrix4(rec.OCSInv)));
|
||||
|
||||
let px1 = Vec3DTo2D(box.min);
|
||||
let px3 = Vec3DTo2D(box.max);
|
||||
let px2 = new THREE.Vector2(px3.x, px1.y);
|
||||
let px4 = new THREE.Vector2(px1.x, px3.y);
|
||||
|
||||
rec.LineData = [
|
||||
{ pt: px1, bul: 0 },
|
||||
{ pt: px2, bul: 0 },
|
||||
{ pt: px3, bul: 0 },
|
||||
{ pt: px4, bul: 0 }];
|
||||
}
|
||||
|
||||
ptRes = await app.m_Editor.GetPoint({
|
||||
Callback: (p) => updateRect(p, p1)
|
||||
});
|
||||
|
||||
if (ptRes.Status == PromptStatus.OK)
|
||||
updateRect(ptRes.Value, p1);
|
||||
else
|
||||
rec.Erase();
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { Circle } from "../../DatabaseServices/Circle";
|
||||
import { Curve } from "../../DatabaseServices/Curve";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { IntersectLAndLFor3D, IntersectOption, IntersectCircleAndCircle } from "../../GraphicsSystem/IntersectWith";
|
||||
import { Line } from "three";
|
||||
import { Arc } from "../../DatabaseServices/Arc";
|
||||
|
||||
export class TestIntersect implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
// this.testLineAndLine();
|
||||
// this.testLineAndCirOrArc();
|
||||
this.testCirAndCir()
|
||||
app.m_Editor.UpdateScreen();
|
||||
}
|
||||
async testLineAndLine()
|
||||
{
|
||||
let exRefSsRes = await app.m_Editor.GetSelection({ Msg: "请选择对象<全部选择>:", UseSelect: true });
|
||||
if (exRefSsRes.Status !== PromptStatus.OK) return;
|
||||
let cus = exRefSsRes.SelectSet.SelectEntityList as Curve[];
|
||||
let pt = IntersectLAndLFor3D(cus[0].StartPoint, cus[0].EndPoint, cus[1].StartPoint, cus[1].EndPoint);
|
||||
console.log('pt: ', pt);
|
||||
if (pt)
|
||||
{
|
||||
cus[0].ColorIndex = 7;
|
||||
cus[1].ColorIndex = 7;
|
||||
let cir = new Circle(pt, 0.1);
|
||||
cir.ColorIndex = 2;
|
||||
app.m_Database.ModelSpace.Append(cir);
|
||||
} else
|
||||
{
|
||||
cus[0].ColorIndex = 1;
|
||||
cus[1].ColorIndex = 1;
|
||||
}
|
||||
}
|
||||
async testLineAndCirOrArc()
|
||||
{
|
||||
let exRefSsRes = await app.m_Editor.GetSelection({ Msg: "请选择对象<全部选择>:", UseSelect: true });
|
||||
if (exRefSsRes.Status !== PromptStatus.OK) return;
|
||||
let cus = exRefSsRes.SelectSet.SelectEntityList as Curve[];
|
||||
if (cus.length > 1)
|
||||
{
|
||||
let [cu1, cu2] = cus[0] instanceof Line ? cus : cus.reverse();
|
||||
let pts = cu1.IntersectWith(cu2, IntersectOption.ExtendBoth);
|
||||
if (pts.length)
|
||||
{
|
||||
pts.forEach(p =>
|
||||
{
|
||||
let cir = new Circle(p, 0.2);
|
||||
cir.ColorIndex = 2;
|
||||
app.m_Database.ModelSpace.Append(cir);
|
||||
})
|
||||
} else
|
||||
{
|
||||
cu1.ColorIndex = 1;
|
||||
cu2.ColorIndex = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
async testCirAndCir()
|
||||
{
|
||||
let exRefSsRes = await app.m_Editor.GetSelection({ Msg: "请选择对象<全部选择>:", UseSelect: true });
|
||||
if (exRefSsRes.Status !== PromptStatus.OK) return;
|
||||
let cus = exRefSsRes.SelectSet.SelectEntityList as Array<Circle | Arc>;
|
||||
if (cus.length > 1)
|
||||
{
|
||||
let pt = IntersectCircleAndCircle(cus[0], cus[1]);
|
||||
console.log('pt: ', pt);
|
||||
if (pt.length)
|
||||
{
|
||||
cus[0].ColorIndex = 7;
|
||||
cus[1].ColorIndex = 7;
|
||||
pt.forEach(p =>
|
||||
{
|
||||
let cir = new Circle(p, 0.1);
|
||||
cir.ColorIndex = 2;
|
||||
app.m_Database.ModelSpace.Append(cir);
|
||||
})
|
||||
} else
|
||||
{
|
||||
cus[0].ColorIndex = 1;
|
||||
cus[1].ColorIndex = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue