简易的文件系统原型

pull/7/head
ChenX 7 years ago
parent eddeac7c1a
commit 2438a0dd92

@ -0,0 +1,300 @@
/*
webCAD .
,,.
.
ID
.
*/
class CADObject
{
ApplyUndoData(data: any)
{
}
}
/**
*
*
* @class Database
*/
class Database extends CADObject
{
private curUndoIndex = -1;
//命令撤销数据列表
commandUndoData: { cmdName: string, undoData: Map<CADObject, UndoFile> }[] = [];
get UndoData(): Map<CADObject, UndoFile>
{
if (this.commandUndoData.length == 0)
{
this.startCmd("");
}
return this.commandUndoData[this.commandUndoData.length - 1].undoData;
}
startCmd(cmdName: string)
{
if (this.commandUndoData.length > 0 && this.curUndoIndex != this.commandUndoData.length - 1)
{
this.commandUndoData.splice(this.curUndoIndex, this.commandUndoData.length - this.curUndoIndex);
}
this.commandUndoData.push({ cmdName: "", undoData: new Map<CADObject, UndoFile>() });
this.curUndoIndex = this.commandUndoData.length - 1;
}
Undo(cout: number)
{
if (this.curUndoIndex == -1)
{
return;
}
for (let [obj, data] of this.commandUndoData[this.curUndoIndex].undoData)
{
for (let i = data.m_UndoDataList.length; i--;)
{
let d = data.m_UndoDataList[i];
obj.ApplyUndoData(d);
}
}
this.curUndoIndex--;
}
Redo(cout: number)
{
for (let i = this.curUndoIndex + 1; i < this.commandUndoData.length; i++)
{
for (let [obj, data] of this.commandUndoData[i].undoData)
{
for (let d of data.m_UndoDataList)
{
obj.ApplyUndoData(d);
}
}
}
}
}
let arr = [0, 1, 2, 3, 4, 5, 6];
arr.splice(3, arr.length - 3);
arr
/**
*
*
* @class UndoFile
*/
class UndoFile
{
m_UndoDataList = [];
}
enum EntityUndoType
{
}
//
interface EntityData
{
id: number;
isErase: boolean;
}
/**
*
*
*
* @class Entity
*/
class Entity extends CADObject
{
protected m_Data: EntityData;
m_Db: Database;
constructor()
{
super();
this.m_Data = {
id: -1,
isErase: false
}
}
get UndoFile(): UndoFile
{
if (this.m_Db)
{
let undoData = this.m_Db.UndoData;
if (!undoData.has(this))
{
undoData.set(this, new UndoFile());
}
return undoData.get(this);
}
}
WriteUndoData(data: any)
{
let undoFile = this.UndoFile;
if (undoFile)
{
undoFile.m_UndoDataList.push(data);
}
}
}
/**
* 线
*
* @enum {number}
*/
enum LineUndoType
{
Full = 0,
StartPoint = 1,
EndPoint = 2,
}
//
interface LineData extends EntityData
{
startPoint: number[],
endPoint: number[]
}
/**
* 线
*
* @class Line
*/
class Line extends Entity
{
protected m_Data: LineData;
constructor()
{
super();
this.m_Data.startPoint = [0, 0, 0];
this.m_Data.endPoint = [0, 0, 0];
}
get StartPoint(): number[]
{
return this.m_Data.startPoint;
}
set StartPoint(value: number[])
{
this.WriteUndoData({ type: LineUndoType.StartPoint, data: { startPoint: this.m_Data.startPoint } });
this.m_Data.startPoint = value;
}
ApplyUndoData(data: any)
{
switch (data.type)
{
case LineUndoType.Full:
break;
case LineUndoType.StartPoint:
this.m_Data.startPoint = data.data.startPoint;
break;
default:
break;
}
}
}
/**
* ,使.
*
* @class EentiyDrawAdapter
*/
class EentiyDrawAdapter
{
Draw(): THREE.Object3D
{
return undefined;
}
}
/**
* 线
*
* @class LineAdapter
* @extends {EentiyDrawAdapter}
*/
class LineAdapter extends EentiyDrawAdapter
{
Draw(): THREE.Object3D
{
return undefined;
}
Update(type: number)
{
switch (type)
{
case LineUndoType.Full:
break;
case LineUndoType.StartPoint:
break;
case LineUndoType.EndPoint:
break;
default:
break;
}
}
}
let line = new Line();
console.log(line);
line.StartPoint = [1, 2, 3];
console.log(line);
let db = new Database();
line.m_Db = db;
line.StartPoint = [3, 3, 3];
console.log(line);
line.StartPoint = [3, 3, 5];
line.StartPoint = [12, 3, 5];
console.log(line);
console.log(db.commandUndoData);
db.Undo(1);
console.log(line);
db.Redo(1);
console.log(line.StartPoint);

@ -9,3 +9,11 @@ Vector3 {
`;
exports[`相交测试 2`] = `undefined`;
exports[`相交测试 3`] = `
Vector3 {
"x": 0.5,
"y": 5,
"z": 0,
}
`;

Loading…
Cancel
Save