mirror of https://gitee.com/cf-fz/WebCAD.git
!82 实现点实体和div功能
parent
e4b7ce6acd
commit
bd4f42af39
@ -0,0 +1,98 @@
|
||||
import { app } from '../ApplicationServices/Application';
|
||||
import { Curve } from '../DatabaseServices/Curve';
|
||||
import { Point } from '../DatabaseServices/Point';
|
||||
import { Command } from '../Editor/CommandMachine';
|
||||
import { PromptStatus, PromptEntityResult } from '../Editor/PromptResult';
|
||||
|
||||
export class CMD_Divide implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let enRes = await app.m_Editor.GetEntity(
|
||||
{
|
||||
Msg: "请选择定数等分的对象",
|
||||
KeyWordList: [{ key: "D", msg: "定数等分" }, { key: "S", msg: "定距等分" }]
|
||||
});
|
||||
switch (enRes.Status)
|
||||
{
|
||||
case PromptStatus.Cancel:
|
||||
{
|
||||
return;
|
||||
}
|
||||
case PromptStatus.Keyword:
|
||||
{
|
||||
if (enRes.StringResult == "D")//定数等分
|
||||
{
|
||||
await this.Divided(enRes);
|
||||
}
|
||||
else if (enRes.StringResult == "S")//定距等分
|
||||
{
|
||||
await this.Measured();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PromptStatus.OK:
|
||||
{
|
||||
await this.Divided(enRes);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
async Divided(enRes: PromptEntityResult)//定数等分
|
||||
{
|
||||
|
||||
let numRes = await app.m_Editor.GetDistance({ Msg: "请输入段数" });
|
||||
if (numRes.Status != PromptStatus.OK)
|
||||
return;
|
||||
|
||||
let divCount = numRes.Value;
|
||||
if (divCount === 0)
|
||||
{
|
||||
app.m_Editor.m_CommandStore.Prompt("您不能等分0");
|
||||
return;
|
||||
}
|
||||
if (enRes.Entity instanceof Curve)
|
||||
{
|
||||
let cu = enRes.Entity;
|
||||
let len = cu.Length;
|
||||
let divLen = len / numRes.Value;
|
||||
for (let i = 0; i < divCount - 1; i++)
|
||||
{
|
||||
let pt = cu.GetPointAtDistance(divLen * (i + 1));
|
||||
let ptEnt = new Point(pt);
|
||||
app.m_Database.ModelSpace.Append(ptEnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async Measured()//定距等分
|
||||
{
|
||||
let enRes = await app.m_Editor.GetEntity({ Msg: "请选择定距等分的对象" });
|
||||
let numRes = await app.m_Editor.GetDistance({ Msg: "请指定分段的长度" });
|
||||
let divLen = numRes.Value;
|
||||
if (divLen === 0)
|
||||
{
|
||||
app.m_Editor.m_CommandStore.Prompt("分段长度不能为0");
|
||||
return;
|
||||
}
|
||||
if (enRes.Entity instanceof Curve)
|
||||
{
|
||||
let cu = enRes.Entity;
|
||||
let len = cu.Length;
|
||||
if (divLen > len)
|
||||
{
|
||||
app.m_Editor.m_CommandStore.Prompt("分段长度不能超过对象长度");
|
||||
return;
|
||||
}
|
||||
let divCount = len / divLen;
|
||||
for (let i = 0; i < divCount - 1; i++)
|
||||
{
|
||||
let pt = cu.GetPointAtDistance(divLen * (i + 1));
|
||||
let ptEnt = new Point(pt);
|
||||
app.m_Database.ModelSpace.Append(ptEnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import { app } from '../ApplicationServices/Application';
|
||||
import { Point } from '../DatabaseServices/Point';
|
||||
import { Command } from '../Editor/CommandMachine';
|
||||
import { PromptStatus, PromptEntityResult } from '../Editor/PromptResult';
|
||||
|
||||
|
||||
export class CMD_DrawPoint implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ptRes = await app.m_Editor.GetPoint({ Msg: "请输入或点取点的位置" });
|
||||
if (ptRes.Status != PromptStatus.OK)
|
||||
return;
|
||||
let ptEnt = new Point(ptRes.Value);
|
||||
app.m_Database.ModelSpace.Append(ptEnt);
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
import { AdditiveBlending, BufferGeometry, Float32BufferAttribute, Geometry, Object3D, Points, PointsMaterial, TextureLoader, Vector3 } from "three";
|
||||
import { MoveMatrix } from "../Geometry/GeUtils";
|
||||
import { RenderType } from "../GraphicsSystem/Enum";
|
||||
import { Factory } from "./CADFactory";
|
||||
import { CADFile } from "./CADFile";
|
||||
import { Entity } from "./Entity";
|
||||
|
||||
let pointMaterial: PointsMaterial;
|
||||
function LoadPointMaterial()
|
||||
{
|
||||
if (!pointMaterial)
|
||||
{
|
||||
let textureLoader = new TextureLoader();
|
||||
pointMaterial = new PointsMaterial({
|
||||
size: window.screen.height * 0.025,
|
||||
map: textureLoader.load(require("../textures/ddptype/target.png")),
|
||||
blending: AdditiveBlending,
|
||||
depthTest: false,
|
||||
transparent: true,
|
||||
sizeAttenuation: false
|
||||
});
|
||||
}
|
||||
return pointMaterial;
|
||||
}
|
||||
|
||||
LoadPointMaterial();
|
||||
|
||||
@Factory
|
||||
export class Point extends Entity
|
||||
{
|
||||
private m_Position: Vector3;
|
||||
constructor(position: Vector3 = new Vector3())
|
||||
{
|
||||
super();
|
||||
this.m_Position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化绘制的threejs实体,子类型重载该函数初始化绘制实体.
|
||||
*
|
||||
* @param {RenderType} [renderType=RenderType.Wireframe] 渲染类型
|
||||
* @returns {Object3D} 返回的threejs实体.
|
||||
* @memberof Entity
|
||||
*/
|
||||
|
||||
protected InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
|
||||
{
|
||||
let geometry = new BufferGeometry();
|
||||
geometry.addAttribute("position", new Float32BufferAttribute(this.m_Position.toArray(), 3));
|
||||
return new Points(geometry, LoadPointMaterial());
|
||||
}
|
||||
|
||||
private UpdateGeometry(geometry: Geometry)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 当实体需要更新时,需要重载该方法,实现实体更新
|
||||
*
|
||||
* @param {RenderType} type
|
||||
* @param {Object3D} en
|
||||
* @memberof Entity
|
||||
*/
|
||||
UpdateDrawObject(type: RenderType, en: Object3D)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
GetSnapPoints(): Array<Vector3>
|
||||
{
|
||||
return [this.m_Position.clone().applyMatrix4(this.OCS)];
|
||||
}
|
||||
|
||||
MoveSnapPoints(indexList: number[], vec: Vector3)
|
||||
{
|
||||
if (indexList.length === 1)
|
||||
{
|
||||
this.WriteAllObjectRecord();
|
||||
this.ApplyMatrix(MoveMatrix(vec));
|
||||
}
|
||||
}
|
||||
|
||||
GetStretchPoints(): Array<Vector3>
|
||||
{
|
||||
return this.GetSnapPoints();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉伸夹点,用于Stretch命令
|
||||
*
|
||||
* @param {Array<number>} indexList 拉伸点索引列表.
|
||||
* @param {Vector3} vec 移动向量
|
||||
* @memberof Entity
|
||||
*/
|
||||
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
|
||||
{
|
||||
this.MoveSnapPoints(indexList, vec);
|
||||
}
|
||||
|
||||
//#region -------------------------File-------------------------
|
||||
|
||||
//对象从文件中读取数据,初始化自身
|
||||
ReadFile(file: CADFile)
|
||||
{
|
||||
let ver = file.Read();
|
||||
super.ReadFile(file);
|
||||
this.m_Position.fromArray(file.Read());
|
||||
}
|
||||
//对象将自身数据写入到文件.
|
||||
WriteFile(file: CADFile)
|
||||
{
|
||||
file.Write(1);
|
||||
super.WriteFile(file);
|
||||
file.Write(this.m_Position.toArray());
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 459 B |
Loading…
Reference in new issue