mirror of https://gitee.com/cf-fz/WebCAD.git
commit
5c5d2a2518
@ -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,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("成功拷贝到剪切板.");
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue