清理className 的代码. 现在统一使用js机制获得

pull/7/head
ChenX 7 years ago
parent 9c3396307f
commit dec015d9a6

@ -127,15 +127,6 @@ test('xxx', () =>
}); });
CADFactory.RegisterObject(Line);
CADFactory.RegisterObject(BlockTableRecord);
CADFactory.RegisterObject(CommandHistoryRecord);
CADFactory.RegisterObject(HistorycRecord);
CADFactory.RegisterObject(ObjectAllDataHistoryRecord);
CADFactory.RegisterObject(AllObjectData);
CADFactory.RegisterObject(RemoveObjectData);
CADFactory.RegisterObject(CreateObjectData);
let l = CADFactory.CreateObject("Line"); let l = CADFactory.CreateObject("Line");

@ -120,19 +120,16 @@ id只有在一个情况下才会更新.跨文档复制时.
export class CADFactory export class CADFactory
{ {
private constructor() { } private constructor() { }
private objectNameMap = new Map<string, () => CADObject>(); private objectNameMap = new Map<string, any>();
private static factory = new CADFactory(); private static factory = new CADFactory();
static RegisterObject(C) static RegisterObject(C)
{ {
let obj = new C() as CADObject; this.factory.objectNameMap.set(C.name, C);
this.factory.objectNameMap.set(obj.ClassName.toUpperCase(), () => new C());
} }
static CreateObject(name: string): CADObject static CreateObject(name: string): CADObject
{ {
let createF = this.factory.objectNameMap.get(name.toUpperCase()); let C = this.factory.objectNameMap.get(name);
if (createF) if (C) return new C();
return createF();
} }
} }
@ -201,10 +198,9 @@ export class CADObject
//#region -------------------------File------------------------- //#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string get ClassName(): string
{ {
return "CADObject"; return this.constructor.name;
} }
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
@ -428,11 +424,6 @@ export class CreateObjectData extends CADObject
//#region -----------------------------File----------------------------- //#region -----------------------------File-----------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "CreateObjectData";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -466,11 +457,7 @@ export class RemoveObjectData extends CADObject
//#region -----------------------------File----------------------------- //#region -----------------------------File-----------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "RemoveData";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -503,12 +490,6 @@ export class AllObjectData extends CADObject
//#region -------------------------File------------------------- //#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "AllObjectData";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -579,11 +560,7 @@ export class ObjectCollection<T> extends CADObject
//#region -----------------------------File----------------------------- //#region -----------------------------File-----------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "ObjectCollection";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -625,7 +602,7 @@ export class ObjectCollection<T> extends CADObject
//命令历史记录集合 //命令历史记录集合
export class CommandHistoryRecord extends CADObject export class CommandHistoryRecord extends CADObject
{ {
constructor(cmdName: string) constructor(cmdName?: string)
{ {
super(); super();
this.commandName = cmdName; this.commandName = cmdName;
@ -690,11 +667,6 @@ export class CommandHistoryRecord extends CADObject
//#region -------------------------File------------------------- //#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "CommandHistoryRecord";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
@ -755,12 +727,6 @@ export class HistorycRecord extends CADObject
//#region -------------------------File------------------------- //#region -------------------------File-------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "HistorycRecord";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -1003,11 +969,6 @@ export class BlockTableRecord extends ObjectCollection<Entity>
//#region -----------------------------File----------------------------- //#region -----------------------------File-----------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "BlockTableRecord";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -1045,12 +1006,6 @@ export class Line extends Entity
//-----------------------------File----------------------------- //-----------------------------File-----------------------------
//对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化 //对象应该实现dataIn和DataOut的方法,为了对象的序列化和反序列化
//类名,保证序列化时得到正确的new
get ClassName(): string
{
return "Line";
}
//对象从文件中读取数据,初始化自身 //对象从文件中读取数据,初始化自身
ReadFile(file: CADFile) ReadFile(file: CADFile)
{ {
@ -1097,3 +1052,11 @@ export class Line extends Entity
} }
CADFactory.RegisterObject(Line); CADFactory.RegisterObject(Line);
CADFactory.RegisterObject(BlockTableRecord);
CADFactory.RegisterObject(CommandHistoryRecord);
CADFactory.RegisterObject(HistorycRecord);
CADFactory.RegisterObject(ObjectAllDataHistoryRecord);
CADFactory.RegisterObject(AllObjectData);
CADFactory.RegisterObject(RemoveObjectData);
CADFactory.RegisterObject(CreateObjectData);

Loading…
Cancel
Save