!1014 优化:保存时清理历史记录

pull/1014/MERGE
ZoeLeeFZ 4 years ago committed by ChenX
parent 6be61f7768
commit b17d91d6ca

@ -10,25 +10,68 @@ import { SaveAsModal } from "../UI/Components/Modal/SavaAsModal";
import { ModalPosition, ModalState } from "../UI/Components/Modal/ModalInterface";
import { AppToaster } from "../UI/Components/Toaster";
import { IndexedDbStore, StoreName } from "../IndexedDb/IndexedDbStore";
import { Intent } from "@blueprintjs/core";
import { Database } from "../DatabaseServices/Database";
import { arrayRemoveIf } from "../Common/ArrayExt";
import { CADFiler } from "../DatabaseServices/CADFiler";
//清理历史记录
const MAX_HS_COUNT = 20;
export class Save implements Command
{
NoHistory = true;
async exec()
{
if (app.Saved)
const hm = app.Database.hm;
let curIndex = hm.curIndex;
let curCount = hm.historyRecord.length;
if (app.Saved && curCount < MAX_HS_COUNT)
{
app.Editor.Prompt("文件已保存!");
return;
}
let fileServer = FileServer.GetInstance() as FileServer;
let fileData = app.FileOut().Data;
let DB = app.Database;
let f = DB.FileWrite();
let vf = new CADFiler();
app.Viewer.CameraCtrl.WriteFile(vf);
if (curCount - curIndex <= MAX_HS_COUNT && curCount > MAX_HS_COUNT)
{
DB = new Database().FileRead(f);
const changeObjects = DB.hm.GetRangeChangeObject(curCount - MAX_HS_COUNT, curCount);
let deleteCount = DB.hm.historyRecord.splice(0, curCount - MAX_HS_COUNT).length;
DB.hm.curIndex -= deleteCount;
arrayRemoveIf(DB.ModelSpace.Entitys, e => e.IsErase && !changeObjects.has(e));
arrayRemoveIf(DB.TemplateTable.Objects, e => e.IsErase && !changeObjects.has(e));
arrayRemoveIf(DB.GroupTable.Objects, g =>
{
return !changeObjects.has(g) && (g.Entitys.length === 0 || g.Entitys.every(e => !e || (e.IsErase && !changeObjects.has(e.Object))));
});
f = DB.FileWrite();
AppToaster.show({
message: `清理了${deleteCount}条历史记录,剩余${DB.hm.historyRecord.length}条记录,可用PU命令清理全部历史记录!`,
timeout: 5000,
intent: Intent.SUCCESS,
});
}
f.Write(vf.Data);
let fileData = f.Data;
let file = JSON.stringify(fileData);
file = deflate(file);
let logo = await uploadLogo(GetCurrentViewPreViewImage());
if (!logo) return;
let fileServer = FileServer.GetInstance() as FileServer;
if (fileServer.m_CurFileId)
{
await fileServer.UpdateFile({ file_id: fileServer.m_CurFileId, file, logo });

@ -152,6 +152,14 @@ export class HistoricManage extends CADObject
}
return objects;
}
GetRangeChangeObject(startIndex: number, endIndex: number): Set<CADObject>
{
let objects = new Set<CADObject>();
for (let i = startIndex; i < endIndex; i++)
for (let [id] of this.historyRecord[i].HistoryList)
objects.add(id.Object);
return objects;
}
/**
* ,,,,.

Loading…
Cancel
Save