|
|
|
@ -161,24 +161,32 @@ export class Database
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
let f = new WblockCloneFiler();
|
|
|
|
|
|
|
|
|
|
for (let obj of objects)
|
|
|
|
|
{
|
|
|
|
|
this.WblockCloneObject(obj, owner, idMap, drc, f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let oldDb = objects[0].Db;
|
|
|
|
|
/**
|
|
|
|
|
* 克隆引用对象 WriteHardObjectId
|
|
|
|
|
*/
|
|
|
|
|
private WblockCloneReferenceObject(object: CADObject, f: WblockCloneFiler, idMap: Map<ObjectId, ObjectId>, drc: DuplicateRecordCloning)
|
|
|
|
|
{
|
|
|
|
|
let oldData = f.Data;
|
|
|
|
|
f.Data = [];
|
|
|
|
|
|
|
|
|
|
for (let [n, id] of f.hardMaping)
|
|
|
|
|
let oldDb = object.Db;
|
|
|
|
|
let hardObjectIds = f.hardObjectIds;
|
|
|
|
|
f.hardObjectIds = new Set();
|
|
|
|
|
for (let idIndex of hardObjectIds)
|
|
|
|
|
{
|
|
|
|
|
let oldId = oldDb.GetObjectId(n);
|
|
|
|
|
let oldId = oldDb.GetObjectId(idIndex);
|
|
|
|
|
//使用旧的OwnerId得到新的OwnerId,假设所有者都是数据库默认存在的.
|
|
|
|
|
//TODO: 当OwnerId>100时,表示这个所有者不是数据库里面默认存在的,那么应该将Owner拷贝过来.
|
|
|
|
|
let newOwnerId = this.GetObjectId(oldId.Object.Owner.Index);//owner.Db === this
|
|
|
|
|
let newOwnerId = this.GetObjectId(oldId.Object.Owner.Index); //owner.Db === this
|
|
|
|
|
let newOwner = newOwnerId.Object as SymbolTable;
|
|
|
|
|
|
|
|
|
|
this.WblockCloneObject(oldId.Object, newOwner, idMap, drc, f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f.Data = oldData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private WblockCloneObject(
|
|
|
|
@ -189,7 +197,14 @@ export class Database
|
|
|
|
|
filer: WblockCloneFiler
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
//克隆的对象有可能被其他的对象依赖并且克隆完毕了.
|
|
|
|
|
let cloneId = filer.idMaping.get(object.Id.Index);
|
|
|
|
|
if (cloneId && cloneId.Object)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filer.Data.length = 0;
|
|
|
|
|
//表示该对象已经被拷贝了,至于成功与否,不重要(参考WblockClone.WriteHardObjectId)
|
|
|
|
|
filer.idMaping.set(object.Id.Index, undefined);
|
|
|
|
|
if (owner instanceof SymbolTable)
|
|
|
|
|
{
|
|
|
|
|
let record = object as SymbolTableRecord;
|
|
|
|
@ -211,6 +226,7 @@ export class Database
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filer.WriteObject(record);
|
|
|
|
|
this.WblockCloneReferenceObject(record, filer, idMap, drc);
|
|
|
|
|
filer.Reset();
|
|
|
|
|
let newRecord = filer.ReadObject() as SymbolTableRecord;
|
|
|
|
|
newRecord.Owner = undefined;
|
|
|
|
@ -227,6 +243,7 @@ export class Database
|
|
|
|
|
filer.idMaping.set(object.Id.Index, oldRecord.Id);
|
|
|
|
|
|
|
|
|
|
record.WriteFile(filer);
|
|
|
|
|
this.WblockCloneReferenceObject(record, filer, idMap, drc);
|
|
|
|
|
filer.Reset();
|
|
|
|
|
|
|
|
|
|
//此时重新读取的话,将会得到原先的id,实现id不变
|
|
|
|
@ -239,6 +256,7 @@ export class Database
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filer.WriteObject(object);
|
|
|
|
|
this.WblockCloneReferenceObject(object, filer, idMap, drc);
|
|
|
|
|
filer.Reset();
|
|
|
|
|
let newObject = filer.ReadObject() as SymbolTableRecord;
|
|
|
|
|
owner.Add(newObject, false);
|
|
|
|
|