!2581 优化:ROTATE旋转功能,使用“C”关键字时COPY实体

pull/2571/MERGE
林三 6 months ago committed by ChenX
parent 1663b4a5b9
commit 96856c75e0

@ -1,4 +1,5 @@
import { Intent } from '@blueprintjs/core';
import { Matrix4 } from 'three';
import { app } from '../ApplicationServices/Application';
import { Log, LogType } from '../Common/Log';
import { DuplicateRecordCloning } from '../Common/Status';
@ -73,25 +74,57 @@ export class Command_Copy implements Command
let ptBase = ptRes.Point;
let ptLast = ptBase.clone();
let oens = ssRes.SelectSet.SelectEntityList;
oens = RemoveRoomAutoGenEntity(oens);
let olds = new Set(oens);
let jens = oens.map(e => JigUtils.Draw(e));
for (let e of oens) e.DrawObject.visible = true;
const { copyEnts, dbEnts, idMapRev, idMap, oldEntsSet } = GetCopyEntsParam(ssRes.SelectSet.SelectEntityList);
while (true)
{
app.Database.hm.StartMark();
let ptRes2 = await app.Editor.GetPoint({
AllowNone: true,
Msg: "请选择复制终点:",
NotSnapZ: true,
Callback: (p) =>
{
let moveM = MoveMatrix(p.clone().sub(ptLast));
ptLast.copy(p);
for (let e of copyEnts)
e.ApplyMatrix(moveM);
},
BasePoint: ptRes.Point,
AllowDrawRubberBand: true
});
if (ptRes2.Status === PromptStatus.OK)
{
let moveM = MoveMatrix(ptRes2.Point.sub(ptBase));
HardCloneObject(dbEnts, moveM, idMapRev, idMap, oldEntsSet);
}
else
break;
}
}
}
export function GetCopyEntsParam(originalEnts: Entity[]): { copyEnts: Entity[]; dbEnts: Entity[]; idMapRev: IdMaping; idMap: IdMaping; oldEntsSet: Set<Entity>; }
{
originalEnts = RemoveRoomAutoGenEntity(originalEnts);
let oldEntsSet = new Set(originalEnts);
let copyEnts = originalEnts.map(e => JigUtils.Draw(e));
for (let e of originalEnts) e.DrawObject.visible = true;
//#region 拷贝实体
let tempDb = new Database(false, false, true);
let filer = new WblockCloneFiler2();
let idMap: IdMaping = new Map();
let nens = tempDb.WblockCloneObejcts(oens, app.Viewer.isLayout ? tempDb.LayoutSpace : tempDb.ModelSpace, idMap, DuplicateRecordCloning.Ignore, filer) as Entity[];
let news = new Set(nens);
let newEnts = tempDb.WblockCloneObejcts(originalEnts, app.Viewer.isLayout ? tempDb.LayoutSpace : tempDb.ModelSpace, idMap, DuplicateRecordCloning.Ignore, filer) as Entity[];
let newEntsSet = new Set(newEnts);
let idMapRev: IdMaping = new Map();
for (let [k, v] of idMap) idMapRev.set(v, k);
for (let e of tempDb.ModelSpace.Entitys)
{
if (news.has(e)) continue;
if (newEntsSet.has(e)) continue;
//板件删除时会清除关联的排钻 我们不想清除
if (e instanceof Board)
{
@ -106,41 +139,22 @@ export class Command_Copy implements Command
Purge(tempDb);
PurgeTemplateTreeRoot(tempDb);
//#endregion
let dbEnts = app.Viewer.isLayout ? tempDb.LayoutSpace.Entitys : tempDb.ModelSpace.Entitys.concat(tempDb.Lights.Entitys);
return { copyEnts, dbEnts, idMapRev, idMap, oldEntsSet };
}
let dbens = app.Viewer.isLayout ? tempDb.LayoutSpace.Entitys : tempDb.ModelSpace.Entitys.concat(tempDb.Lights.Entitys);
while (true)
{
app.Database.hm.StartMark();
let ptRes2 = await app.Editor.GetPoint({
AllowNone: true,
Msg: "请选择复制终点:",
NotSnapZ: true,
Callback: (p) =>
{
let moveM = MoveMatrix(p.clone().sub(ptLast));
ptLast.copy(p);
for (let e of jens)
e.ApplyMatrix(moveM);
},
BasePoint: ptRes.Point,
AllowDrawRubberBand: true
});
if (ptRes2.Status === PromptStatus.OK)
export function HardCloneObject(dbAllEnts: Entity[], mtx: Matrix4, idMapRev: IdMaping, idMap: IdMaping, oldEntsSet: Set<Entity>)
{
let moveM = MoveMatrix(ptRes2.Point.sub(ptBase));
let filer2 = new WblockCloneFiler2();
let idMap2: IdMaping = new Map();
let blkRec = app.Viewer.isLayout ? app.Database.LayoutSpace : app.Database.ModelSpace;
let newEns = app.Database.WblockCloneObejcts(dbens, blkRec, idMap2, DuplicateRecordCloning.Ignore, filer2) as Entity[];
let newEns = app.Database.WblockCloneObejcts(dbAllEnts, blkRec, idMap2, DuplicateRecordCloning.Ignore, filer2) as Entity[];
let idMap2Rev: IdMaping = new Map();
for (let [k, v] of idMap2) idMap2Rev.set(v, k);
for (let e of newEns) e.ApplyMatrix(moveM);
for (let e of newEns) e.ApplyMatrix(mtx);
//新id倒推旧id
function GetOldObjectId(newObjectId: ObjectId)
@ -172,7 +186,7 @@ export class Command_Copy implements Command
if (!id || id.IsErase) continue;
let br = id.Object as Board; //关联刀默认为板
if (olds.has(br)) continue;//已经拷贝
if (oldEntsSet.has(br)) continue; //已经拷贝
if (temp.Subtract([br], [], true))
e.RelevanceSubtract(br, true); //关联切割重新绑定
@ -183,7 +197,7 @@ export class Command_Copy implements Command
if (!id || id.IsErase) continue;
let br = id.Object as Board; //关联刀默认为板
if (olds.has(br)) continue;//已经拷贝
if (oldEntsSet.has(br)) continue; //已经拷贝
if (br.Clone().Subtract([e], [], true))
br.RelevanceSubtract(e, true); //关联切割重新绑定
@ -223,11 +237,12 @@ export class Command_Copy implements Command
//处理通孔(如果通孔没拷贝,那么移除通孔属性)(这里没有考虑到图纸中的对象可能会组成新的通孔)
if (oldE.OtherHalfTongKong)
{
if (!olds.has(oldE.OtherHalfTongKong.Object as Entity))
if (!oldEntsSet.has(oldE.OtherHalfTongKong.Object as Entity))
{
e.OtherHalfTongKong = null;
if (e instanceof CylinderHole)
e.Type = GangDrillType.Ymj;
else
(e as ExtrudeHole).isThrough = false;
}
@ -264,7 +279,7 @@ export class Command_Copy implements Command
if (oldHole.FId && !oldHole.FId.IsErase)
{
if (!olds.has(oldHole.FId.Object as Board))//父亲没拷贝
if (!oldEntsSet.has(oldHole.FId.Object as Board)) //父亲没拷贝
{
e.FId = fbr.Id;
fbr.AppendDrillList(mbr.Id, [groupHoles.map(e => e.Id)]);
@ -282,7 +297,7 @@ export class Command_Copy implements Command
if (oldHole.MId && !oldHole.MId.IsErase)
{
if (!olds.has(oldHole.MId.Object as Board))//母亲没拷贝
if (!oldEntsSet.has(oldHole.MId.Object as Board)) //母亲没拷贝
{
e.MId = mbr.Id;
mbr.AppendDrillList(fbr.Id, [groupHoles.map(e => e.Id)]);
@ -309,7 +324,7 @@ export class Command_Copy implements Command
let ent = id.Object;
if (ent instanceof Board) //只复制了五金 却没复制板
{
if (!olds.has(ent))
if (!oldEntsSet.has(ent))
{
e.RelevanceBoards.push(ent.Id);
ent.RelativeHardware.push(e.Id);
@ -317,7 +332,7 @@ export class Command_Copy implements Command
}
else if (ent instanceof HardwareCompositeEntity) //复合板
{
if (!olds.has(ent))
if (!oldEntsSet.has(ent))
{
e.RelevanceBoards.push(ent.Id);
ent.RelevanceHardware.push(e.Id);
@ -346,16 +361,11 @@ export class Command_Copy implements Command
let fullCopy = e.RelevancyWalls.length === (e.Points.length - 1) && e.RelevancyWalls.every(id =>
{
let oldId = GetOldObjectId(id);
return olds.has(oldId.Object as Entity);
return oldEntsSet.has(oldId.Object as Entity);
});
if (!fullCopy)
e.Erase();//我们现在直接删除它,我们其实应该重新放置它,但是我们没做!
}
}
}
else
break;
e.Erase();
}
}
}

@ -5,6 +5,7 @@ import { Command } from '../Editor/CommandMachine';
import { JigUtils } from '../Editor/JigUtils';
import { PromptStatus } from '../Editor/PromptResult';
import { ZAxis, angle } from '../Geometry/GeUtils';
import { GetCopyEntsParam, HardCloneObject } from './Copy';
import { UpdateEntityDrawTask } from './UpdateEntityDrawTask';
export class Command_Rotate implements Command
@ -51,7 +52,7 @@ export class Command_Rotate implements Command
if (isCopy)
{
JigUtils.Restore();
this.Update(pt1, anRes.Distance - refAng, cloneEns, isCopy, true);
this.Update(pt1, anRes.Distance - refAng, ens, isCopy, true);
}
else
this.Update(pt1, anRes.Distance - refAng, ens, isCopy, true);
@ -91,13 +92,20 @@ export class Command_Rotate implements Command
let moveMatInv = new Matrix4().getInverse(moveMat);
let roMat = new Matrix4().makeRotationAxis(ZAxis.clone().applyMatrix4(app.Editor.UCSMatrix.clone().setPosition(0, 0, 0)), MathUtils.degToRad(an));
let mtx = moveMat.multiply(roMat).multiply(moveMatInv);
for (let en of ens)
{
en.ApplyMatrix(mtx);
if (isCopy)
app.Database.ModelSpace.Append(en);
{
let { dbEnts, idMapRev, idMap, oldEntsSet } = GetCopyEntsParam(ens);
HardCloneObject(dbEnts, mtx, idMapRev, idMap, oldEntsSet);
ens = dbEnts;
}
for (let en of ens)
{
if (!isCopy)
en.ApplyMatrix(mtx);
if (resetUpdate)
en.AutoUpdate = true;
}

Loading…
Cancel
Save