!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)
{
@ -100,47 +133,28 @@ export class Command_Copy implements Command
}
e.GoodBye();
tempDb.DeleteId(e.Id.Index);//否则查到引用仍然拷贝
tempDb.DeleteId(e.Id.Index); //否则查到引用仍然拷贝
}
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)
{
let moveM = MoveMatrix(ptRes2.Point.sub(ptBase));
export function HardCloneObject(dbAllEnts: Entity[], mtx: Matrix4, idMapRev: IdMaping, idMap: IdMaping, oldEntsSet: Set<Entity>)
{
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)
@ -171,27 +185,27 @@ export class Command_Copy implements Command
{
if (!id || id.IsErase) continue;
let br = id.Object as Board;//关联刀默认为板
if (olds.has(br)) continue;//已经拷贝
let br = id.Object as Board; //关联刀默认为板
if (oldEntsSet.has(br)) continue; //已经拷贝
if (temp.Subtract([br], [], true))
e.RelevanceSubtract(br, true);//关联切割重新绑定
e.RelevanceSubtract(br, true); //关联切割重新绑定
}
for (let id of oldBr.RelevanceMeats)
{
if (!id || id.IsErase) continue;
let br = id.Object as Board;//关联刀默认为板
if (olds.has(br)) continue;//已经拷贝
let br = id.Object as Board; //关联刀默认为板
if (oldEntsSet.has(br)) continue; //已经拷贝
if (br.Clone().Subtract([e], [], true))
br.RelevanceSubtract(e, true);//关联切割重新绑定
br.RelevanceSubtract(e, true); //关联切割重新绑定
}
e.CopyInRenderTpye = userConfig.RenderType;
// oldBr.RelativeHardware; //关联的五金肯定没办法重新关联
}
else if (e instanceof CylinderHole && e.Type === GangDrillType.Nail)//层板钉
else if (e instanceof CylinderHole && e.Type === GangDrillType.Nail) //层板钉
{
let oldId = GetOldObjectId(e.Id);
let oldE = oldId.Object as CylinderHole;
@ -208,7 +222,7 @@ export class Command_Copy implements Command
}
}
if (!e.MId || e.MId.IsErase)//层板没拷贝
if (!e.MId || e.MId.IsErase) //层板没拷贝
{
if (oldE.MId && !oldE.MId.IsErase)
{
@ -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;
}
@ -235,20 +250,20 @@ export class Command_Copy implements Command
}
else if (e instanceof Hole)
{
if (repHoled.has(e)) continue;//因为我们以编组为单位,所以我们不会选到非编组外的排钻,所以这样是正确的
if (repHoled.has(e)) continue; //因为我们以编组为单位,所以我们不会选到非编组外的排钻,所以这样是正确的
let groupHoles: Hole[] = [];
if (e.GroupId?.Object)
{
let g = e.GroupId.Object as GroupRecord;
if (g.Name)//如果没有名称,那么可能是用户自己编组的
if (g.Name) //如果没有名称,那么可能是用户自己编组的
{
for (let id of g.Entitys)
{
if (id.Object instanceof Hole)
{
groupHoles.push(id.Object);
repHoled.add(id.Object);//因为实体在编组里,所以我们肯定它已经被选中拷贝!
repHoled.add(id.Object); //因为实体在编组里,所以我们肯定它已经被选中拷贝!
}
}
}
@ -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)]);
@ -298,7 +313,7 @@ export class Command_Copy implements Command
}
}
}
else if (e instanceof HardwareCompositeEntity)//五金
else if (e instanceof HardwareCompositeEntity) //五金
{
let oldId = GetOldObjectId(e.Id);
let oldE = oldId.Object as HardwareCompositeEntity;
@ -307,9 +322,9 @@ export class Command_Copy implements Command
{
if (!id || id.IsErase) continue;
let ent = id.Object;
if (ent instanceof Board)//只复制了五金 却没复制板
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);
@ -325,7 +340,7 @@ export class Command_Copy implements Command
}
}
}
else if (e instanceof HardwareTopline)//顶线不需要
else if (e instanceof HardwareTopline) //顶线不需要
{
}
else if (e instanceof ViewportEntity)
@ -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