|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import { Factory } from './CADFactory';
|
|
|
|
|
import { CADFiler } from './CADFiler';
|
|
|
|
|
import { CADObject } from './CADObject';
|
|
|
|
|
import { CreateObjectData } from './CreateObjectData';
|
|
|
|
|
import { EraseEntityData } from "./EraseEntityData";
|
|
|
|
|
import { HistorycRecord } from './HistorycRecord';
|
|
|
|
|
import { ObjectAllDataHistoryRecord } from './ObjectAllDataHistoryRecord';
|
|
|
|
@ -12,71 +13,71 @@ import { ObjectId } from './ObjectId';
|
|
|
|
|
@Factory
|
|
|
|
|
export class CommandHistoryRecord extends CADObject
|
|
|
|
|
{
|
|
|
|
|
constructor(cmdName?: string)
|
|
|
|
|
constructor(public CommandName = "")
|
|
|
|
|
{
|
|
|
|
|
super();
|
|
|
|
|
this.commandName = cmdName;
|
|
|
|
|
}
|
|
|
|
|
//命令名称
|
|
|
|
|
private commandName: string;
|
|
|
|
|
get CommandName()
|
|
|
|
|
{
|
|
|
|
|
return this.commandName;
|
|
|
|
|
}
|
|
|
|
|
//历史记录表
|
|
|
|
|
private historyCol = new Map<ObjectId, HistorycRecord[]>();
|
|
|
|
|
private _HistoryList = new Map<ObjectId, HistorycRecord[]>();
|
|
|
|
|
private _CreateObjects = new Map<CADObject, HistorycRecord>();
|
|
|
|
|
|
|
|
|
|
get HistoryList(): Map<ObjectId, HistorycRecord[]>
|
|
|
|
|
{
|
|
|
|
|
return this.historyCol;
|
|
|
|
|
return this._HistoryList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private GetObjectHistoryList(id: ObjectId)
|
|
|
|
|
{
|
|
|
|
|
if (!this.historyCol.has(id))
|
|
|
|
|
{
|
|
|
|
|
this.historyCol.set(id, []);
|
|
|
|
|
}
|
|
|
|
|
return this.historyCol.get(id);
|
|
|
|
|
if (!this._HistoryList.has(id))
|
|
|
|
|
this._HistoryList.set(id, []);
|
|
|
|
|
return this._HistoryList.get(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EndCommand()
|
|
|
|
|
{
|
|
|
|
|
for (let [id, recs] of this.historyCol)
|
|
|
|
|
for (let [id, hrs] of this._HistoryList)
|
|
|
|
|
{
|
|
|
|
|
let rec = this.GetObjectAllDataRecord(recs);
|
|
|
|
|
if (rec)
|
|
|
|
|
{
|
|
|
|
|
rec.WriteRedo();
|
|
|
|
|
}
|
|
|
|
|
let hr = this.GetObjectAllDataRecord(hrs);
|
|
|
|
|
if (hr)
|
|
|
|
|
hr.WriteRedo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let [, hr] of this._CreateObjects)
|
|
|
|
|
{
|
|
|
|
|
let h = hr.redoData as CreateObjectData;
|
|
|
|
|
h.Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//获得对象的记录
|
|
|
|
|
GetObjectAllDataRecord(historyList: HistorycRecord[]): ObjectAllDataHistoryRecord
|
|
|
|
|
|
|
|
|
|
//获取对象快照记录(如果有的话)
|
|
|
|
|
GetObjectAllDataRecord(historyList: HistorycRecord[]): ObjectAllDataHistoryRecord | undefined
|
|
|
|
|
{
|
|
|
|
|
if (historyList.length > 0)
|
|
|
|
|
{
|
|
|
|
|
let rec = historyList[historyList.length - 1];
|
|
|
|
|
if (rec instanceof ObjectAllDataHistoryRecord)
|
|
|
|
|
{
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
let hr = historyList[historyList.length - 1];
|
|
|
|
|
if (hr instanceof ObjectAllDataHistoryRecord)
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//对象写入数据
|
|
|
|
|
|
|
|
|
|
//对象写入历史记录
|
|
|
|
|
WriteObjectHistoryPath(obj: CADObject, history: HistorycRecord)
|
|
|
|
|
{
|
|
|
|
|
let his = this.GetObjectHistoryList(obj.Id);
|
|
|
|
|
if (this.GetObjectAllDataRecord(his))
|
|
|
|
|
{
|
|
|
|
|
//console.log("优化掉重复的全部数据");
|
|
|
|
|
if (this._CreateObjects.has(obj))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let hrs = this.GetObjectHistoryList(obj.Id);
|
|
|
|
|
if (this.GetObjectAllDataRecord(hrs))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (history instanceof ObjectAllDataHistoryRecord && history.undoData === undefined)
|
|
|
|
|
{
|
|
|
|
|
history.WriteUndo();
|
|
|
|
|
}
|
|
|
|
|
his.push(history);
|
|
|
|
|
else if (history.redoData instanceof CreateObjectData)
|
|
|
|
|
this._CreateObjects.set(history.redoData.Object, history);
|
|
|
|
|
|
|
|
|
|
hrs.push(history);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreateObjectHistory(obj: CADObject): ObjectAllDataHistoryRecord
|
|
|
|
|
{
|
|
|
|
|
if (!obj.Id)
|
|
|
|
@ -84,10 +85,11 @@ export class CommandHistoryRecord extends CADObject
|
|
|
|
|
console.warn("错误!CreateObjectHistory");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let rec = new ObjectAllDataHistoryRecord(obj.Id);
|
|
|
|
|
this.WriteObjectHistoryPath(obj, rec);
|
|
|
|
|
return rec;
|
|
|
|
|
let hr = new ObjectAllDataHistoryRecord(obj.Id);
|
|
|
|
|
this.WriteObjectHistoryPath(obj, hr);
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreateEraseHistory(obj: CADObject, isErase: boolean)
|
|
|
|
|
{
|
|
|
|
|
let hr = new HistorycRecord();
|
|
|
|
@ -104,20 +106,20 @@ export class CommandHistoryRecord extends CADObject
|
|
|
|
|
ReadFile(file: CADFiler)
|
|
|
|
|
{
|
|
|
|
|
let ver = file.Read();
|
|
|
|
|
this.commandName = file.Read();
|
|
|
|
|
this.CommandName = file.Read();
|
|
|
|
|
let cout = file.Read();
|
|
|
|
|
|
|
|
|
|
this.historyCol.clear();
|
|
|
|
|
this._HistoryList.clear();
|
|
|
|
|
for (let i = 0; i < cout; i++)
|
|
|
|
|
{
|
|
|
|
|
let id = file.ReadObjectId();
|
|
|
|
|
let length = file.Read();
|
|
|
|
|
let recs = [];
|
|
|
|
|
this.historyCol.set(id, recs);
|
|
|
|
|
let hrs: HistorycRecord[] = [];
|
|
|
|
|
this._HistoryList.set(id, hrs);
|
|
|
|
|
for (let j = 0; j < length; j++)
|
|
|
|
|
{
|
|
|
|
|
let rec = file.ReadObject();
|
|
|
|
|
recs.push(rec);
|
|
|
|
|
let hr = file.ReadObject() as HistorycRecord;
|
|
|
|
|
hrs.push(hr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -125,15 +127,15 @@ export class CommandHistoryRecord extends CADObject
|
|
|
|
|
WriteFile(file: CADFiler)
|
|
|
|
|
{
|
|
|
|
|
file.Write(1);
|
|
|
|
|
file.Write(this.commandName);
|
|
|
|
|
file.Write(this.historyCol.size);
|
|
|
|
|
for (let [id, recs] of this.historyCol)
|
|
|
|
|
file.Write(this.CommandName);
|
|
|
|
|
file.Write(this._HistoryList.size);
|
|
|
|
|
for (let [id, hrs] of this._HistoryList)
|
|
|
|
|
{
|
|
|
|
|
file.WriteObjectId(id);
|
|
|
|
|
file.Write(recs.length);
|
|
|
|
|
for (let rec of recs)
|
|
|
|
|
file.Write(hrs.length);
|
|
|
|
|
for (let hr of hrs)
|
|
|
|
|
{
|
|
|
|
|
file.WriteObject(rec);
|
|
|
|
|
file.WriteObject(hr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|