!83 实现动态拽拖(Jig)

Merge pull request !83 from ChenX/jig
pull/83/MERGE
ChenX 6 years ago
commit 5c5d2a2518

@ -27,7 +27,7 @@ module.exports = {
},
resolve: {
},
devtool: "source-map",
// devtool: "source-map",
plugins: [
new webpack.DllPlugin({
path: 'manifest.json',

@ -1,66 +1,51 @@
import { app } from '../ApplicationServices/Application';
import { Entity } from '../DatabaseServices/Entity';
import { Command } from '../Editor/CommandMachine';
import { Jig } from '../Editor/Jig';
import { PromptStatus } from '../Editor/PromptResult';
import { SelectSet } from '../Editor/SelectSet';
import { CADFile } from '../DatabaseServices/CADFile';
import { Curve } from 'three';
import { MoveMatrix } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum';
export class Command_Copy implements Command
{
async exec(ss: SelectSet)
async exec()
{
if (ss.SelectEntityList.length === 0)
{
let ssRes = await app.m_Editor.GetSelection({ Msg: "请选择需要拷贝的实体:" });
if (ssRes.Status != PromptStatus.OK)
return;
ss = ssRes.SelectSet;
}
let ssRes = await app.m_Editor.GetSelection({ Msg: "请选择需要拷贝的实体:", UseSelect: true });
if (ssRes.Status != PromptStatus.OK)
return;
let ptRes = await app.m_Editor.GetPoint({ Msg: "请选择复制基点:" });
if (ptRes.Status != PromptStatus.OK) return;
if (ptRes.Status != PromptStatus.OK)
return;
let maps = new Map<CADFile, Entity>();
for (let en of ss.SelectEntityList)
{
let newE = en.Clone() as Entity;
app.m_Database.ModelSpace.Append(newE);
let f = new CADFile();
newE.WriteFile(f);
maps.set(f, newE);
}
let ptBase = ptRes.Value;
let ptLast = ptBase.clone();
const UpdateEntity = (p) =>
{
let m = MoveMatrix(p.clone().sub(ptRes.Value))
for (let [f, e] of maps)
{
f.Reset();
e.ReadFile(f);
e.ApplyMatrix(m);
}
app.m_Editor.UpdateScreen();
}
let orgEns = ssRes.SelectSet.SelectEntityList;
let jigEns = orgEns.map(e => Jig.Draw(e));
let ptRes2 = await app.m_Editor.GetPoint({
Msg: "请选择复制终点:",
Callback: UpdateEntity,
BasePoint: ptRes.Value,
AllowDrawRubberBand: true
});
if (ptRes2.Status != PromptStatus.OK)
while (true)
{
for (let [, e] of maps)
let ptRes2 = await app.m_Editor.GetPoint({
Msg: "请选择复制终点:",
Callback: (p) =>
{
let moveM = MoveMatrix(p.clone().sub(ptLast));
ptLast.copy(p);
jigEns.forEach(e => e.ApplyMatrix(moveM));
},
BasePoint: ptRes.Value,
AllowDrawRubberBand: true
});
if (ptRes2.Status === PromptStatus.OK)
{
e.Erase();
e.GoodBye();
let moveM = MoveMatrix(ptRes2.Value.sub(ptBase));
for (let e of orgEns)
app.m_Database.ModelSpace.Append(e.Clone().ApplyMatrix(moveM));
}
else
break;
}
else
UpdateEntity(ptRes2.Value);
Jig.End();
}
}

@ -1,6 +1,7 @@
import { app } from '../ApplicationServices/Application';
import { Arc } from '../DatabaseServices/Arc';
import { Command } from '../Editor/CommandMachine';
import { Jig } from '../Editor/Jig';
import { PromptStatus } from '../Editor/PromptResult';
import { equalv3 } from '../Geometry/GeUtils';
@ -20,13 +21,8 @@ export class DrawArc implements Command
let arc = new Arc();
arc.ApplyMatrix(app.m_Editor.UCSMatrix);
app.m_Editor.AddNoSnapEntity(arc);
const updateArc = (p) =>
{
if (!arc.Id)
app.m_Database.ModelSpace.Append(arc);
if (!equalv3(p, pt2) && !equalv3(p, pt2))
{
arc.FromThreePoint(pt1, pt2, p);
@ -34,14 +30,17 @@ export class DrawArc implements Command
}
}
Jig.Draw(arc);
let ptRes3 = await app.m_Editor.GetPoint({
Msg: "请输入第三个点:",
Callback: updateArc
});
if (ptRes3.Status != PromptStatus.OK)
arc.Erase();
else
if (ptRes3.Status === PromptStatus.OK)
{
updateArc(ptRes3.Value);
app.m_Database.ModelSpace.Append(arc);
}
Jig.End();
}
}

@ -7,6 +7,7 @@ import { Line } from '../DatabaseServices/Line';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { midPoint } from '../Geometry/GeUtils';
import { Jig } from '../Editor/Jig';
export class DrawLine implements Command
{
@ -180,32 +181,29 @@ export class DrawCircle implements Command
cir.ApplyMatrix(app.m_Editor.UCSMatrix);
cir.Center = val;
app.m_Database.ModelSpace.Append(cir);
app.m_Editor.AddNoSnapEntity(cir);
Jig.Draw(cir);
let disRes = await app.m_Editor.GetDistance({
Msg: "指定圆的半径:",
BasePoint: val,
Callback: (v) => cir.Radius = v,
});
if (disRes.Status === PromptStatus.OK)
{
cir.Radius = disRes.Value;
else
cir.Erase();
app.m_Database.ModelSpace.Append(cir);
}
Jig.Destroy();
}
async DrawCicleUseTwoPoint()
{
let ptRes1 = await app.m_Editor.GetPoint({
Msg: "指定圆直径的第一个端点:",
});
let ptRes1 = await app.m_Editor.GetPoint({ Msg: "指定圆直径的第一个端点:" });
if (ptRes1.Status != PromptStatus.OK)
return;
let cir = new Circle();
app.m_Database.ModelSpace.Append(cir);
app.m_Editor.AddNoSnapEntity(cir);
Jig.Draw(cir);
let ptRes2 = await app.m_Editor.GetPoint({
Msg: "指定圆直径的第二个端点:",
@ -221,23 +219,19 @@ export class DrawCircle implements Command
{
cir.Radius = ptRes2.Value.distanceTo(ptRes1.Value) / 2;
cir.Center = midPoint(ptRes2.Value, ptRes1.Value);
app.m_Database.ModelSpace.Append(cir);
}
else
cir.Erase();
Jig.Destroy();
}
async DrawCicleUseThreePoint()
{
let ptRes1 = await app.m_Editor.GetPoint({
Msg: "指定圆上第一个点:"
});
let ptRes1 = await app.m_Editor.GetPoint({ Msg: "指定圆上第一个点:" });
if (ptRes1.Status != PromptStatus.OK)
return;
let cir = new Circle();
let ar = new Arc();
app.m_Database.ModelSpace.Append(cir);
let ptRes2 = await app.m_Editor.GetPoint({
Msg: "指定圆上第二个点:",
BasePoint: ptRes1.Value,
@ -246,7 +240,8 @@ export class DrawCircle implements Command
if (ptRes2.Status != PromptStatus.OK)
return;
app.m_Editor.AddNoSnapEntity(cir);
Jig.Draw(cir);
let ptRes3 = await app.m_Editor.GetPoint({
Msg: "指定圆上第三个点:",
BasePoint: ptRes2.Value,
@ -263,9 +258,10 @@ export class DrawCircle implements Command
ar.FromThreePoint(ptRes1.Value, ptRes2.Value, ptRes3.Value);
cir.Radius = ar.Radius;
cir.Center = ar.Center;
app.m_Database.ModelSpace.Append(cir);
}
else
cir.Erase();
Jig.Destroy();
}
async DrawCicleUseCutoffPointAndRadious()
{
@ -280,9 +276,6 @@ export class DrawCircle implements Command
// let ptRes2 = await app.m_Editor.GetPoint({
// Msg: "指定对象与圆的第二个切点:",
// });
}
}

@ -1,11 +1,10 @@
import { Matrix4, Vector3, Vector2 } from 'three';
import { Vector2, Vector3 } from 'three';
import { app } from '../ApplicationServices/Application';
import { Vec2DTo3D, Vec3DTo2D, getCirAngleByChordAndTangent } from '../Common/CurveUtils';
import { Polyline, PolylineProps } from '../DatabaseServices/Polyline';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus, PromptSsgetResult } from '../Editor/PromptResult';
import { rotatePoint } from '../Geometry/GeUtils';
import { getCirAngleByChordAndTangent, Vec2DTo3D, Vec3DTo2D } from '../Common/CurveUtils';
import { GetPointPrompt } from '../Common/InputState';
import { Polyline } from '../DatabaseServices/Polyline';
import { PromptStatus } from '../Editor/PromptResult';
import { Jig } from '../Editor/Jig';
enum PolylineModel
{
@ -23,39 +22,45 @@ export class DrawPolyline
let pl = new Polyline();
pl.ApplyMatrix(app.m_Editor.UCSMatrix);
app.m_Database.ModelSpace.Append(pl);
app.m_Editor.AddNoSnapEntity(pl);
let plJig = Jig.Draw(pl);
let Callback = (p: Vector3) =>
this.UpdatePoint(pl, p);
this.UpdatePoint(plJig, p)
let firstOps: GetPointPrompt = { Msg: "请输入第一个点:", Callback };
let firstOps: GetPointPrompt = { Msg: "请输入第一个点:", Callback, AllowNone: true };
let keywords = [{ msg: "圆弧", key: "A" }, { msg: "直线", key: "L" }, { msg: "放弃", key: "U" }];
let keywords2 = keywords.concat([{ msg: "闭合", key: "C" }]);
let nextOps: GetPointPrompt = { Msg: "请点击下一个点或", Callback };
let nextOps: GetPointPrompt = { Msg: "请点击下一个点或", Callback, AllowNone: true };
while (true)
{
let ops: GetPointPrompt;
if (pl.NumberOfVertices === 0)
if (plJig.NumberOfVertices === 0)
ops = firstOps;
else
{
ops = nextOps;
ops.BasePoint = pl.EndPoint;
if (pl.NumberOfVertices >= 3 || (pl.NumberOfVertices === 2 && this.model === PolylineModel.Arc))
ops.BasePoint = plJig.EndPoint;
if (plJig.NumberOfVertices >= 3 || (plJig.NumberOfVertices === 2 && this.model === PolylineModel.Arc))
nextOps.KeyWordList = keywords2;
else
nextOps.KeyWordList = keywords;
}
pl.AddVertexAt(pl.NumberOfVertices, new Vector2());
plJig.AddVertexAt(plJig.NumberOfVertices, new Vector2());
let p = await app.m_Editor.GetPoint(ops);
if (p.Status === PromptStatus.OK)
{
this.UpdatePoint(plJig, p.Value);
pl.AddVertexAt(pl.NumberOfVertices, new Vector2());
this.UpdatePoint(pl, p.Value);
}
else if (p.Status === PromptStatus.Keyword)
{
this.RemoveLastVertex(pl);
this.RemoveLastVertex(plJig);
if (p.StringResult === "A")
{
this.model = PolylineModel.Arc;
@ -63,15 +68,16 @@ export class DrawPolyline
else if (p.StringResult === "L")
{
this.model = PolylineModel.Line;
if (pl.NumberOfVertices > 0)
pl.SetBulgeAt(pl.NumberOfVertices - 1, 0);
if (plJig.NumberOfVertices > 0)
plJig.SetBulgeAt(plJig.NumberOfVertices - 1, 0);
}
else if (p.StringResult === "U")
{
this.RemoveLastVertex(plJig);
this.RemoveLastVertex(pl);
if (pl.NumberOfVertices > 0)
if (plJig.NumberOfVertices > 0)
{
this.model = pl.GetBuilgeAt(pl.NumberOfVertices - 1) !== 0 ?
this.model = plJig.GetBuilgeAt(plJig.NumberOfVertices - 1) !== 0 ?
PolylineModel.Arc : PolylineModel.Line;
}
}
@ -88,13 +94,14 @@ export class DrawPolyline
}
}
else
{
this.RemoveLastVertex(pl);
break;
}
}
Jig.End();
if (pl.NumberOfVertices < 2)
pl.Erase();
{
app.m_Database.ModelSpace.Remove(pl);
return true;
}
}
UpdatePoint(pl: Polyline, pt: Vector3)

@ -5,6 +5,7 @@ import { Vec3DTo2D } from '../Common/CurveUtils';
import { Polyline } from '../DatabaseServices/Polyline';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { Jig } from '../Editor/Jig';
export class DrawRect implements Command
{
async exec()
@ -14,15 +15,13 @@ export class DrawRect implements Command
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);
Jig.Draw(rec);
let box = new Box3();
let updateRect = (p1, p2) =>
@ -45,9 +44,12 @@ export class DrawRect implements Command
Callback: (p) => updateRect(p, p1)
});
if (ptRes.Status == PromptStatus.OK)
if (ptRes.Status === PromptStatus.OK)
{
updateRect(ptRes.Value, p1);
else
rec.Erase();
app.m_Database.ModelSpace.Append(rec);
}
Jig.End();
}
}

@ -1,31 +0,0 @@
import { app } from '../ApplicationServices/Application';
import { Command } from "../Editor/CommandMachine";
import { PromptStatus } from "../Editor/PromptResult";
import { CADFile } from '../DatabaseServices/CADFile';
import { copyTextToClipboard } from '../Common/Utils';
/**
* ,.
*
* @export
* @class Command_GenerateCode
* @implements {Command}
*/
export class Command_GenerateCode implements Command
{
async exec()
{
let ssRes = await app.m_Editor.GetSelection({ UseSelect: true });
if (ssRes.Status != PromptStatus.OK) return;
let file = new CADFile();
for (let en of ssRes.SelectSet.SelectEntityList)
{
file.WriteObject(en);
}
copyTextToClipboard(JSON.stringify(file.Data));
app.m_Editor.m_CommandStore.Prompt("成功拷贝到剪切板.");
}
}

@ -3,6 +3,7 @@ import { app } from '../ApplicationServices/Application';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { MoveMatrix } from '../Geometry/GeUtils';
import { Jig } from '../Editor/Jig';
export class Command_Move implements Command
{
@ -13,47 +14,32 @@ export class Command_Move implements Command
let ptRes = await app.m_Editor.GetPoint({ Msg: "请点击移动基点:" });
if (ptRes.Status != PromptStatus.OK)
{ return; }
return;
let ens = ssRes.SelectSet.SelectEntityList;
let ptBase = ptRes.Value;
let ensClone = ens.map(e => Jig.Draw(e));
let pt1 = ptBase;
let ptBase = ptRes.Value;
let ptLast = ptBase.clone();
ptRes = await app.m_Editor.GetPoint(
{
Msg: "请点击移动终点:",
Callback: (p: THREE.Vector3) =>
{
let moveVec = p.clone().sub(pt1);
let moveMatrix = MoveMatrix(moveVec);
ens.forEach(e =>
{
e.ApplyMatrix(moveMatrix);
})
pt1 = p.clone();
let moveMatrix = MoveMatrix(p.clone().sub(ptLast));
ensClone.forEach(e => e.ApplyMatrix(moveMatrix));
ptLast.copy(p);
},
BasePoint: pt1,
BasePoint: ptBase,
AllowDrawRubberBand: true
});
//还原到原来的位置
let moveV = ptBase.clone().sub(pt1);
let moveM = MoveMatrix(moveV);
ens.forEach(e =>
{
e.ApplyMatrix(moveM);
})
Jig.End();
if (ptRes.Status === PromptStatus.OK)
{
moveV = ptRes.Value.clone().sub(ptBase);
moveM = MoveMatrix(moveV);
ens.forEach(e =>
{
e.ApplyMatrix(moveM);
})
let moveM = MoveMatrix(ptRes.Value.clone().sub(ptBase));
ens.forEach(e => e.ApplyMatrix(moveM));
}
}
}

@ -3,86 +3,69 @@ import { GetPointAtCurveDir } from '../Common/CurveUtils';
import { Curve } from '../DatabaseServices/Curve';
import { Command } from '../Editor/CommandMachine';
import { PromptStatus } from '../Editor/PromptResult';
import { Vector3 } from '../../node_modules/@types/three';
import { Jig } from '../Editor/Jig';
export class Command_Offset implements Command
{
offsetDis: number = 1;
async exec()
{
let dis = await app.m_Editor.GetDistance({
let disRes = await app.m_Editor.GetDistance({
Msg: "指定偏移距离:",
KeyWordList: [{ msg: "通过", key: "T" }],
Default: this.offsetDis
});
if (dis.Status != PromptStatus.OK) return;
this.offsetDis = dis.Value;
let dyn = false;
if (disRes.Status === PromptStatus.Keyword && disRes.StringResult === "T")
dyn = true;
else if (disRes.Status != PromptStatus.OK)
return;
else
this.offsetDis = disRes.Value;
while (true)
{
let enRes = await app.m_Editor.GetEntity({
Msg: "选择要偏移的对象:"
});
let enRes = await app.m_Editor.GetEntity({ Msg: "选择要偏移的对象:" });
if (enRes.Status === PromptStatus.Cancel)
break;
else if (enRes.Status !== PromptStatus.OK)
continue;
let pt = await app.m_Editor.GetPoint({
Msg: "指定要偏移的那一侧的点"
});
let cu = enRes.Entity;
let cu = enRes.Entity as Curve;
if (cu instanceof Curve)
{
let dir = GetPointAtCurveDir(cu, pt.Value) ? 1 : -1
let offCurs = cu.GetOffsetCurves(this.offsetDis * dir);
offCurs.forEach((offCur) =>
{
app.m_Database.ModelSpace.Append(offCur);
})
app.m_Viewer.m_bNeedUpdate = true;
}
}
}
}
export class Command_TestOffset implements Command
{
async exec()
{
//禁用捕捉服务
app.m_Editor.m_GetpointServices.snapServices.m_Disabled = true;
while (true)
{
let enRes = await app.m_Editor.GetEntity({
Msg: "选择要偏移的对象:"
});
if (enRes.Status != PromptStatus.OK)
{
//结束偏移后打开点捕捉
app.m_Editor.m_GetpointServices.snapServices.m_Disabled = false;
break;
}
let cu = enRes.Entity as Curve;
let lastpls: Curve[];
let ptRes = await app.m_Editor.GetPoint({
Msg: "指定要偏移的那一侧的点",
Callback: dyn ? (p: Vector3) =>
{
Jig.Destroy();
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1
cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir)
.forEach(c => Jig.Draw(c));
} : undefined
});
await app.m_Editor.GetPoint({
Msg: "指定要偏移的那一侧的点",
Callback: (p) =>
Jig.End();
if (ptRes.Status === PromptStatus.OK)
{
if (lastpls) lastpls.forEach(cu => cu.GoodBye());
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1
lastpls = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir);
lastpls.forEach((offCur) =>
let p = ptRes.Value;
let dir = GetPointAtCurveDir(cu, p) ? 1 : -1;
let offCus: Curve[];
if (dyn)
offCus = cu.GetOffsetCurves(p.distanceTo(cu.GetClosestPointTo(p, false)) * dir);
else
offCus = cu.GetOffsetCurves(this.offsetDis * dir);
offCus.forEach((offCur) =>
{
app.m_Database.ModelSpace.Append(offCur);
})
app.m_Viewer.m_bNeedUpdate = true;
}
});
else
return;
}
}
}
}

@ -1,8 +1,8 @@
import * as THREE from 'three';
import { app } from '../ApplicationServices/Application';
import { CADFile } from '../DatabaseServices/CADFile';
import { Entity } from '../DatabaseServices/Entity';
import { Command } from '../Editor/CommandMachine';
import { Jig } from '../Editor/Jig';
import { PromptStatus } from '../Editor/PromptResult';
import { SelectBox } from '../Editor/SelectBox';
import { SelectPick } from '../Editor/SelectPick';
@ -13,12 +13,11 @@ import { MoveMatrix } from '../Geometry/GeUtils';
interface StretchData
{
moveEntityList: Entity[];//被移动的图元(所有点都被选中)
stretchEntityMap: Map<Entity, Array<number>>; //被拉伸的图元,对照被拉伸的点索引.
stretchEntityMap: { Ent: Entity, Indexs: Array<number> }[]; //被拉伸的图元,对照被拉伸的点索引.
}
export class Stretch implements Command
{
m_CacheEntity: Map<Entity, CADFile> = new Map<Entity, CADFile>();
async exec()
{
let ssRes = await app.m_Editor.GetSelection({ UseSelect: true, Msg: "请选择拉伸对象:" });
@ -28,43 +27,52 @@ export class Stretch implements Command
let p1 = await app.m_Editor.GetPoint({ Msg: "指定基点:" });//, KeyWordList: [{ msg: "位移", key: "D" }]
if (p1.Status != PromptStatus.OK) return;
let data = this.parse(ss);
for (let [e] of data.stretchEntityMap)
app.m_Editor.AddNoSnapEntity(e);
let dataClone: StretchData =
{
moveEntityList: data.moveEntityList.map(e => Jig.Draw(e)),
stretchEntityMap: data.stretchEntityMap.map(v =>
{
return {
Ent: Jig.Draw(v.Ent),
Indexs: v.Indexs
}
})
}
let lastP = p1.Value.clone();
let curP = lastP.clone();
let p2 = await app.m_Editor.GetPoint(
{
BasePoint: p1.Value,
AllowDrawRubberBand: true,
Msg: "指定第二个点:",//或 <使用第一个点作为位移>
Callback: (p) =>
{
Jig.Restore();
let v = p.clone().sub(lastP);
this.s(data, v);
this.s(dataClone, v);
curP.copy(p);
}
});
if (p2.Status === PromptStatus.OK)
this.s(data, p2.Value.sub(lastP));
else
{
data.moveEntityList.forEach(e => this.RestoreEntity(e));
data.stretchEntityMap.forEach((v, k) => this.RestoreEntity(k));
}
app.m_Editor.ClearSnapEntity();
app.m_Editor.m_SelectCtrl.Cancel();
if (p1.Status != PromptStatus.OK) return;
this.m_CacheEntity.clear();
Jig.End();
}
/**
* ,,.
*
* @param {SelectSet} ss
* @returns {StretchData}
* @memberof Stretch
*/
parse(ss: SelectSet): StretchData
{
let data: StretchData =
{
stretchEntityMap: new Map<Entity, Array<number>>(),
stretchEntityMap: [],
moveEntityList: []
};
for (let set of ss.SelectSetList)
@ -89,8 +97,7 @@ export class Stretch implements Command
let en = obj.userData;
if (en && en instanceof Entity)
{
this.CacheEntity(en);
data.stretchEntityMap.set(en, indexArr);
data.stretchEntityMap.push({ Ent: en, Indexs: indexArr });
let pts = en.GetStretchPoints();
for (let i = pts.length; i--;)
{
@ -106,10 +113,6 @@ export class Stretch implements Command
}
}
}
for (let e of data.moveEntityList)
this.CacheEntity(e);
return data;
}
s(d: StretchData, vec: THREE.Vector3)
@ -117,26 +120,11 @@ export class Stretch implements Command
let moveMat = MoveMatrix(vec);
for (let e of d.moveEntityList)
{
this.RestoreEntity(e);
e.ApplyMatrix(moveMat);
}
for (let [e, arr] of d.stretchEntityMap)
for (let { Ent, Indexs } of d.stretchEntityMap)
{
this.RestoreEntity(e);
e.MoveStretchPoints(arr, vec);
Ent.MoveStretchPoints(Indexs, vec);
}
}
CacheEntity(e: Entity)
{
let f = new CADFile();
e.WriteFile(f);
this.m_CacheEntity.set(e, f);
}
RestoreEntity(e: Entity)
{
let f = this.m_CacheEntity.get(e);
f.Reset();
e.ReadFile(f);
}
}

@ -14,7 +14,7 @@ const ColorPalette = [
// [255, 0, 0, 255], //----- 8 - More red Red
// [255, 0, 0, 255], //----- 9 - More red Red
[255, 255, 255, 255],//----- 7 - White
[255, 255, 255, 255],//----- 8
[128, 128, 128, 255],//----- 8
[255, 255, 255, 255],//----- 9
[255, 0, 0, 255], //----- 10
[255, 127, 127, 255],//----- 11

@ -0,0 +1,11 @@
import { Object3D } from "three";
export function DisposeThreeObj(m: Object3D)
{
//@ts-ignores
if (m.geometry)
//@ts-ignore
m.geometry.dispose();
m.children.forEach(o => DisposeThreeObj(o));
}

@ -73,10 +73,11 @@ export abstract class CADObject
{
let ver = file.Read();
//write Id;
this.objectId = this.ReadObjectId(file);
if (this.objectId)
let id = this.ReadObjectId(file);
if (!this.objectId && id)//避免CopyFrom时错误的修改自身Id
{
this.objectId.Object = this;
this.objectId = id;
id.Object = this;
}
this._isErase = file.Read();
}
@ -121,14 +122,16 @@ export abstract class CADObject
newObject._db = undefined;
return newObject;
}
// //从一个实体拷贝数据,实体类型必须相同.
// CopyFrom(obj: CADObject)
// {
// this.WriteAllObjectRecord();
// let f = new CADFile();
// obj.WriteFile(f);
// this.ReadFile(f);
// }
//从一个实体拷贝数据,实体类型必须相同.
CopyFrom(obj: CADObject)
{
let id = this.objectId;
this.WriteAllObjectRecord();
let f = new CADFile();
obj.WriteFile(f);
this.ReadFile(f);
this.objectId = id;
}
//-------------------------File End-------------------------

@ -1,12 +1,12 @@
import { Line, Object3D, Shape, Vector3 } from 'three';
import { arrayRemoveDuplicateBySort, arraySortByNumber } from '../Common/ArrayExt';
import { ColorMaterial } from '../Common/ColorPalette';
import { equalv3, equaln } from '../Geometry/GeUtils';
import { Status } from '../Common/Status';
import { equaln, equalv3 } from '../Geometry/GeUtils';
import { RenderType } from '../GraphicsSystem/Enum';
import { IntersectOption } from '../GraphicsSystem/IntersectWith';
import { Factory } from './CADFactory';
import { Entity } from './Entity';
import { Status } from '../Common/Status';
export enum ExtendType
{
@ -161,4 +161,13 @@ export abstract class Curve extends Entity
let m = en as Line;
m.material = ColorMaterial.GetLineMaterial(this.m_Color);
}
UpdateJigMaterial()
{
for (let [type, en] of this.m_DrawEntity)
{
let l = en as Line;
l.material = ColorMaterial.GetLineMaterial(8);
}
}
}

@ -7,6 +7,7 @@ import { Factory } from './CADFactory';
import { CADFile } from './CADFile';
import { CADObject } from './CADObject';
import { ObjectId } from './ObjectId';
import { DisposeThreeObj } from '../Common/Dispose';
/**
* Entity ,.
@ -201,30 +202,33 @@ export class Entity extends CADObject
}
/**
* ,
*
* @memberof Entity
*/
UpdateJigMaterial()
{
}
RestoreJigMaterial()
{
for (let [type, en] of this.m_DrawEntity)
this.UpdateDrawObjectMaterial(type, en);
}
UpdateVisible()
{
for (let [, en] of this.m_DrawEntity)
{
en.visible = !this._isErase;
}
}
GoodBye()
{
for (let [, obj] of this.m_DrawEntity)
{
let geo = obj['Geometry']
if (geo && geo instanceof THREE.Geometry)
{
geo.dispose();
}
DisposeThreeObj(obj);
if (obj.parent)
{
obj.parent.remove(obj);
}
else
console.warn("重复加入数据库导致的错误!");
}
}
Erase(isErase: boolean = true)
@ -303,11 +307,11 @@ export class Entity extends CADObject
this.Update();
}
// CopyFrom(obj: CADObject)
// {
// super.CopyFrom(obj);
// this.Update();
// }
CopyFrom(obj: CADObject)
{
super.CopyFrom(obj);
this.Update();
}
//#endregion
}

@ -156,6 +156,7 @@ export class Polyline extends Curve
}
set StartPoint(v: Vector3)
{
this.WriteAllObjectRecord();
this.SetPointAt(0, Vec3DTo2D(v));
let bul = this.GetBuilgeAt(0)
if (bul !== 0)
@ -175,7 +176,11 @@ export class Polyline extends Curve
}
set EndPoint(v: Vector3)
{
this.WriteAllObjectRecord();
this.SetPointAt(this.EndParam, Vec3DTo2D(v));
if (this.EndParam === 0)
return;
let bul = this.GetBuilgeAt(this.EndParam - 1)
if (bul !== 0)
{
@ -894,11 +899,21 @@ export class Polyline extends Curve
}
UpdateDrawObject(type: RenderType, en: Object3D)
{
let plObj = en as THREE.Line;
let geo = new Geometry();
let shape = this.Shape;
geo.setFromPoints(shape.getPoints(50));
updateGeometry(plObj, geo);
let pts = shape.getPoints(30);
let plObj = en as THREE.Line;
let geo = plObj.geometry as Geometry;
if (pts.length === geo.vertices.length)
{
geo.setFromPoints(pts);
geo.verticesNeedUpdate = true;
}
else
{
geo = new Geometry();
geo.setFromPoints(shape.getPoints(50));
updateGeometry(plObj, geo);
}
}
GetSnapPoints(): Array<THREE.Vector3>

@ -1,7 +1,7 @@
import { app } from '../ApplicationServices/Application';
export interface Command
{
exec: Function;
exec: Function;//函数可以返回true,实现放弃命令的任何操作.
}
//命令状态机.
@ -26,20 +26,21 @@ export class CommandMachine
app.m_Database.hm.StartCmd(cmdName);
}
app.m_Editor.m_SelectCtrl.RestState();
let ss = app.m_Editor.m_SelectCtrl.SelectSet;
//命令执行...
this.m_CommandIng = true;
app.m_Editor.m_CommandStore.isCmdIng = true;
let abort: boolean = true;
try
{
await this.m_CommandList.get(cmdName).exec(ss);
abort = await this.m_CommandList.get(cmdName).exec();
}
catch (error)
{
app.m_Editor.m_CommandStore.Prompt("抱歉,命令造成了错误,请联系开发人员.");
console.error(error);
}
this.CommandEnd(cmdName);
this.CommandEnd(cmdName, abort);
}
else
{
@ -53,10 +54,12 @@ export class CommandMachine
this.m_CommandList.set(cmdName, cmd);
this.m_CommandNameList.add(cmdName);
}
CommandEnd(cmdName: string)
CommandEnd(cmdName: string, abort: boolean = false)
{
this.m_CommandIng = false;
app.m_Database.hm.EndCmd();
if (abort)
app.m_Database.hm.Undo();
app.m_Editor.m_CommandStore.isCmdIng = false;
app.m_Viewer.m_GripScene.UpdateAll();
app.m_Editor.ClearSnapEntity();

@ -1,12 +1,14 @@
import { DrawAxis } from '../Add-on/AddAxis';
import { Command_Array } from '../Add-on/Array';
import { IntersectionOperation, SubsractOperation, UnionOperation } from '../Add-on/BoolOperation';
import { Command_Break } from '../Add-on/Break';
import { Command_ClosePt } from '../Add-on/closetest';
import { Command_Copy } from '../Add-on/Copy';
import { CopyClip } from '../Add-on/CopyClip';
import { Command_CopyPoint } from '../Add-on/CopyPoint';
import { CustomUcs } from '../Add-on/CostumUCS';
import { Union } from '../Add-on/CSGUnion';
import { CMD_Divide } from '../Add-on/Divide';
import { DrawArc } from '../Add-on/DrawArc';
import { Command_DrawBoard } from '../Add-on/DrawBoard';
import { DrawAlignedDimension } from '../Add-on/DrawDim/DrawAlignedDimension';
@ -16,6 +18,7 @@ import { DrawEllipse } from '../Add-on/DrawEllipse';
import { DrawFloor } from '../Add-on/DrawFloor';
import { DrawGripStretch } from '../Add-on/DrawGripStretch';
import { DrawCircle, DrawLine, DrawSphere, DrawTest, ZoomE } from '../Add-on/DrawLine';
import { CMD_DrawPoint } from '../Add-on/DrawPoint';
import { DrawPolyline } from '../Add-on/DrawPolyline';
import { DrawRect } from '../Add-on/DrawRec';
import { DrawRegion } from '../Add-on/DrawRegion';
@ -29,14 +32,14 @@ import { Command_Erase } from '../Add-on/Erase';
import { Command_Explode } from '../Add-on/Explode';
import { Command_Extend } from '../Add-on/Extends';
import { CommandFillet } from '../Add-on/Fillet';
import { Command_GenerateCode } from '../Add-on/GenerateCode';
import { Command_INsTest } from '../Add-on/instest';
import { Command_Join } from '../Add-on/Join';
import { Command_Length } from '../Add-on/Length';
import { Command_Lisp } from '../Add-on/Lisp';
import { Fbx } from '../Add-on/loadfbx';
import { LoadImg } from '../Add-on/LoadImg';
import { Command_Move } from '../Add-on/Move';
import { Command_Offset, Command_TestOffset } from '../Add-on/Offset';
import { Command_Offset } from '../Add-on/Offset';
import { OffsetX } from '../Add-on/OffsetX';
import { Open } from '../Add-on/Open';
import { PasteClip } from '../Add-on/PasteClip';
@ -46,8 +49,10 @@ import { Command_PtInCu } from '../Add-on/ptincu';
import { Command_RevPl } from '../Add-on/RevPl';
import { Command_Rotate } from '../Add-on/Rotate';
import { Save } from '../Add-on/Save';
import { Command_Scale } from '../Add-on/Scale';
import { Command_Ssget } from '../Add-on/ssget';
import { Stretch } from '../Add-on/Stretch';
import { Sweep } from '../Add-on/Sweep';
import { Command_SwitchCamera } from '../Add-on/SwitchCamera';
import { Command_SwitchPass } from '../Add-on/SwitchPass';
// import { DrawFloor } from '../Add-on/DrawFloor';
@ -64,12 +69,6 @@ import { Redo, Undo } from '../Add-on/Undo';
import { ViewToFront, ViewToRight, ViewToTop } from '../Add-on/ViewChange';
import { Command_DimTest } from '../DatabaseServices/Dimension/dimTest';
import { commandMachine } from './CommandMachine';
import { Sweep } from '../Add-on/Sweep';
import { Command_Scale } from '../Add-on/Scale';
import { Command_Break } from '../Add-on/Break';
import { Command_Length } from '../Add-on/Length';
import { CMD_Divide } from '../Add-on/Divide';
import { CMD_DrawPoint } from '../Add-on/DrawPoint';
export function registerCommand()
{
@ -185,7 +184,6 @@ export function registerCommand()
commandMachine.RegisterCommand("close", new Command_ClosePt());
//用于测试包围盒
commandMachine.RegisterCommand("box", new Command_TestBox());
commandMachine.RegisterCommand("testoffset", new Command_TestOffset());
//测试标注
commandMachine.RegisterCommand("testdim", new Command_DimTest());
@ -194,7 +192,6 @@ export function registerCommand()
commandMachine.RegisterCommand("incu", new Command_PtInCu());
commandMachine.RegisterCommand("code", new Command_GenerateCode());
commandMachine.RegisterCommand("outcur", new TestTargeOnCurve());
commandMachine.RegisterCommand("join", new Command_Join());

@ -0,0 +1,102 @@
import { app } from "../ApplicationServices/Application";
import { Entity } from "../DatabaseServices/Entity";
import { RenderType } from "../GraphicsSystem/Enum";
import { CADFile } from "../DatabaseServices/CADFile";
/**
* ,.
*
* # Example:
* //1.开始拽拖:->
* //得到临时对象,如果en是已经存在的对象,那么将会被临时修改材质
* let jigEnt = Jig.Draw(en);
* //2.拽拖中:-> ....拽拖代码.更新jigEnt,你可以临时调用Jig.Destroy();
* //3.结束拽拖:
* Jig.End();
* @export
* @class Jig
*/
export class Jig
{
//临时图形,如果需要,将被销毁.
private static m_JigEnts: Entity[] = [];
//图纸数据缓存,用于还原
private static m_EntityCacheData: { Ent: Entity, File: CADFile }[] = [];
private static m_OrgEntitys: Entity[] = [];
static End()
{
this.Destroy();
this.RestoreOriginEntity();
}
/**
*
*
* @static
* @memberof Jig
*/
static RestoreOriginEntity()
{
this.m_OrgEntitys.forEach(e => e.RestoreJigMaterial());
this.m_EntityCacheData.length = 0;
}
/**
* .
* :,,,便.
* @static
* @param {Entity} enOrg
* @memberof Jig
*/
static Draw<T extends Entity>(enOrg: T): T
{
let enNew: T;
if (enOrg.Id)
{
enNew = enOrg.Clone();
this.m_OrgEntitys.push(enOrg);
enOrg.UpdateJigMaterial();
let f = new CADFile();
enNew.WriteFile(f);
this.m_EntityCacheData.push({ Ent: enNew, File: f });
}
else
enNew = enOrg;
this.m_JigEnts.push(enNew);
let obj = enNew.Draw(RenderType.Wireframe);
app.m_Viewer.Scene.add(obj);
return enNew;
}
/**
* .
* @static
* @memberof Jig
*/
static Restore()
{
this.m_EntityCacheData.forEach((v) =>
{
v.File.Reset();
v.Ent.ReadFile(v.File);
})
}
/**
* ,,.
* @static
* @memberof Jig
*/
static Destroy()
{
this.m_JigEnts.forEach(e =>
{
if (!e.Id)
e.GoodBye();
});
this.m_JigEnts.length = 0;
}
}

@ -3,12 +3,12 @@ import { Vector3 } from 'three';
import { end } from 'xaop';
import { app } from '../ApplicationServices/Application';
import { MouseKey } from '../Common/KeyEnum';
import { CADFile } from '../DatabaseServices/CADFile';
import { Entity } from '../DatabaseServices/Entity';
import { MoveMatrix } from '../Geometry/GeUtils';
import { InputState } from './../Common/InputState';
import { commandMachine } from './CommandMachine';
import { Editor, EditorService } from './Editor';
import { Jig } from './Jig';
import { MouseControls } from './MouseControls';
import { PromptStatus } from './PromptResult';
@ -69,38 +69,19 @@ export class SnapDragServices implements EditorService
app.m_Viewer.WorldToScreen(ptV);
if (ptV.distanceToSquared(this.mouseCtrl.m_CurMousePointVCS) < 100)
{
arr.push(i);
}
}
if (arr.length > 0)
{
snapIndexMap.push({ ent: en, indexArr: arr });
app.m_Editor.AddNoSnapEntity(en);
}
}
}
app.m_Viewer.m_GripScene.visible = false;
let restData = snapIndexMap.map(v =>
let snapIndexMapClone = snapIndexMap.map(v =>
{
let f = new CADFile();
v.ent.WriteFile(f);
return { Entity: v.ent, File: f };
})
const Reset = () =>
{
restData.forEach((v) =>
{
v.File.Reset();
v.Entity.ReadFile(v.File);
})
}
const DragTo = (p: Vector3) =>
return { ent: Jig.Draw(v.ent), indexArr: v.indexArr };
});
const DragTo = (p: Vector3, snapIndexMap = snapIndexMapClone) =>
{
Reset();
Jig.Restore();
for (let data of snapIndexMap)
{
let entDrawP = data.ent.GetSnapPoints()[data.indexArr[0]];
@ -117,19 +98,14 @@ export class SnapDragServices implements EditorService
});
if (ptRes.Status === PromptStatus.OK)
{
DragTo(ptRes.Value);
}
else
{
Reset();
}
DragTo(ptRes.Value, snapIndexMap);
Jig.End();
this.UpdateLastPoint();
this.UpdatePreLine();
commandMachine.CommandEnd("drag");
app.m_Viewer.m_GripScene.visible = true;
return true;
}

@ -153,6 +153,7 @@ export class SnapServices
{
if (this.notSnapEntity.has(obj.userData)) continue;
if (obj.userData.IsErase) continue;
if (!obj.userData.Id) continue;
for (let p of obj.userData.GetSnapPoints())
{
let pv = p.clone();

@ -97,11 +97,12 @@ export class Viewer
canvasContainer.appendChild(this.m_Render.domElement);
this.m_Render.autoClear = true;
this.m_Render.sortObjects = false;
//如果设置那么它希望所有的纹理和颜色都是预乘的伽玛。默认值为false。
this.m_Render.gammaInput = true;
this.m_Render.gammaOutput = true;
this.m_Render.shadowMap.enabled = true;
// this.m_Render.gammaInput = true;
// this.m_Render.gammaOutput = true;
// this.m_Render.shadowMap.enabled = true;
this.m_Render.setPixelRatio(window.devicePixelRatio);
//以下参数为三维渲染时需要开启的参数.

@ -135,7 +135,10 @@ const config: webpack.Configuration = {
typeOfAsset: "css",
includeSourcemap: false
},
{ filepath: "./dist/dll.js" },
{
filepath: "./dist/dll.js",
includeSourcemap: false
},
{ filepath: "./node_modules/three/build/three.min.js", includeSourcemap: false },
{
filepath: "./node_modules//three/examples/js/libs/inflate.min.js",

Loading…
Cancel
Save