diff --git a/__test__/EntityData.quo.ts b/__test__/EntityData.quo.ts index b16ed251e..0df47d094 100644 --- a/__test__/EntityData.quo.ts +++ b/__test__/EntityData.quo.ts @@ -1,4 +1,3 @@ -import * as console from 'console'; import { autorun } from 'mobx'; import * as mst from 'mobx-state-tree'; diff --git a/__test__/FileSystem/FileSystem.test.ts b/__test__/FileSystem/FileSystem.test.ts index 9d43c4672..653ce9ac2 100644 --- a/__test__/FileSystem/FileSystem.test.ts +++ b/__test__/FileSystem/FileSystem.test.ts @@ -1,6 +1,5 @@ -import * as THREE from 'three'; - +import { ArrayRemove } from '../../src/Common/Utils'; /* 关于webCAD 文件系统的原型. 包括了对象的保存,撤销,还原. @@ -156,6 +155,10 @@ class CADObject { return this.isErase; } + Erase(isErase: boolean = true) + { + this.isErase = isErase; + } //#endregion //#region -------------------------id------------------------- @@ -212,6 +215,108 @@ class CADFile { } + +class AppendData extends CADObject +{ + objData: CADFile; + //#region -----------------------------File----------------------------- + //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 + //类名,保证序列化时得到正确的new + get ClassName(): string + { + return "CADObject"; + } + //对象从文件中读取数据,初始化自身 + FileIn(file: CADFile) + { } + //对象将自身数据写入到文件. + FileOut(file: CADFile) + { } + //局部撤销 + ApplyPartialUndo(file: CADFile) + { } + //#endregion -----------------------------File End----------------------------- +} +class RemoveData extends CADObject +{ + index: number; + + //#region -----------------------------File----------------------------- + //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 + //类名,保证序列化时得到正确的new + get ClassName(): string + { + return "CADObject"; + } + //对象从文件中读取数据,初始化自身 + FileIn(file: CADFile) + { } + //对象将自身数据写入到文件. + FileOut(file: CADFile) + { } + //局部撤销 + ApplyPartialUndo(file: CADFile) + { } + //#endregion -----------------------------File End----------------------------- +} + +//对象集合. +class ObjectCollection extends CADObject +{ + private objectCol: CADObject[] = []; + Append(obj: CADObject) + { + this.objectCol.push(obj); + + let hisRec = new HistoricRecord(); + let redo = new AppendData(); + redo.objData = new CADFile(); + obj.FileOut(redo.objData); + hisRec.redoData = redo; + + let undo = new RemoveData(); + undo.index = this.objectCol.length - 1; + hisRec.undoData = undo; + + this.db.hm.UndoData.WriteObjectHistoryPath(this, hisRec); + } + Remove(obj: CADObject) + { + ArrayRemove(this.objectCol, obj); + + this.db.hm.UndoData.WriteObjectHistoryPath(this, undefined); + } + + //#region -----------------------------File----------------------------- + //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 + //类名,保证序列化时得到正确的new + get ClassName(): string + { + return "ObjectCollection"; + } + //对象从文件中读取数据,初始化自身 + FileIn(file: CADFile) + { } + //对象将自身数据写入到文件. + FileOut(file: CADFile) + { } + //局部撤销 + ApplyPartialUndo(file: CADObject) + { + if (file instanceof AppendData) + { + file.objData//cad file. + //create object + //append object + } + else if (file instanceof RemoveData) + { + //remove object + } + } + //#endregion -----------------------------File End----------------------------- +} + //命令历史记录集合 class CommandHistoryRecord extends CADObject { @@ -253,12 +358,11 @@ class HistoricRecord extends CADObject userData: CADObject; } - //历史记录管理 class HistoricManage extends CADObject { private curIndex: number = -1; //当前执行位置 - private historyRecord: CommandHistoryRecord[] = []; //历史记录 + private historyRecord: CommandHistoryRecord[] = []; //历史记录 constructor(db: Database) { @@ -507,4 +611,4 @@ console.log(id); db.hm.Undo();/*?*/ -db.hm.Redo();/*?*/ \ No newline at end of file +db.hm.Redo();/*?*/ diff --git a/src/Common/Utils.ts b/src/Common/Utils.ts index b6d6a2b46..ed56a7c56 100644 --- a/src/Common/Utils.ts +++ b/src/Common/Utils.ts @@ -1,7 +1,6 @@ -import { app } from '../ApplicationServices/Application'; - -export function log(msg) +export async function log(msg) { + let app = (await import("../ApplicationServices/Application")).app; app.m_Editor.m_CommandStore.Prompt(msg); }