Add parameter archive func & Add ctrl object archive function #42
@ -3,6 +3,16 @@ import { v4 as uuid } from "uuid";
|
|||||||
import type { IAnyObject, Model } from "@Model/Model";
|
import type { IAnyObject, Model } from "@Model/Model";
|
||||||
import type { ObjectID } from "@Model/Model";
|
import type { ObjectID } from "@Model/Model";
|
||||||
|
|
||||||
|
interface IArchiveCtrlObject {
|
||||||
|
displayName: CtrlObject["displayName"];
|
||||||
|
color: CtrlObject["color"];
|
||||||
|
display: CtrlObject["display"];
|
||||||
|
update: CtrlObject["update"];
|
||||||
|
id: string;
|
||||||
|
renderParameter: Record<string, string>;
|
||||||
|
deleteFlag: CtrlObject["deleteFlag"];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可控对象
|
* 可控对象
|
||||||
*/
|
*/
|
||||||
@ -97,7 +107,14 @@ class CtrlObject extends LabelObject {
|
|||||||
public isDeleted(): boolean {
|
public isDeleted(): boolean {
|
||||||
return this.deleteFlag;
|
return this.deleteFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toArchive(): IArchiveCtrlObject {
|
||||||
|
return {} as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
public fromArchive(archive: IArchiveCtrlObject): void {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CtrlObject;
|
export { CtrlObject, IArchiveCtrlObject };
|
||||||
export { CtrlObject };
|
|
@ -1,6 +1,12 @@
|
|||||||
import type { Group } from "@Model/Group";
|
import { Group } from "@Model/Group";
|
||||||
import type { Range } from "@Model/Range";
|
import { Range } from "@Model/Range";
|
||||||
import type { Label } from "@Model/Label";
|
import { Label } from "@Model/Label";
|
||||||
|
import { Behavior } from "@Model/Behavior";
|
||||||
|
|
||||||
|
type IObjectParamArchiveType = {
|
||||||
|
__LIVING_TOGETHER_OBJECT_ID: string;
|
||||||
|
__LIVING_TOGETHER_OBJECT_TYPE: string;
|
||||||
|
}
|
||||||
|
|
||||||
type IObjectParamCacheType<P, Q = P> = {
|
type IObjectParamCacheType<P, Q = P> = {
|
||||||
picker: P;
|
picker: P;
|
||||||
@ -26,6 +32,15 @@ type IMapObjectParamTypeKeyToType = {
|
|||||||
"CLG": IObjectParamCacheType<Label | Group | undefined, Group[]>;
|
"CLG": IObjectParamCacheType<Label | Group | undefined, Group[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IMapArchiveObjectParamTypeKeyToType = {
|
||||||
|
"R": IObjectParamCacheType<IObjectParamArchiveType | undefined>;
|
||||||
|
"G": IObjectParamCacheType<IObjectParamArchiveType | undefined>;
|
||||||
|
"LR": IObjectParamCacheType<IObjectParamArchiveType | undefined, IObjectParamArchiveType[]>;
|
||||||
|
"LG": IObjectParamCacheType<IObjectParamArchiveType | undefined, IObjectParamArchiveType[]>;
|
||||||
|
"CG": IObjectParamCacheType<IObjectParamArchiveType | undefined>;
|
||||||
|
"CLG": IObjectParamCacheType<IObjectParamArchiveType | undefined, IObjectParamArchiveType[]>;
|
||||||
|
}
|
||||||
|
|
||||||
type IMapVectorParamTypeKeyToType = {
|
type IMapVectorParamTypeKeyToType = {
|
||||||
"vec": number[];
|
"vec": number[];
|
||||||
"color": number[];
|
"color": number[];
|
||||||
@ -35,30 +50,42 @@ type IMapVectorParamTypeKeyToType = {
|
|||||||
* 参数类型映射
|
* 参数类型映射
|
||||||
*/
|
*/
|
||||||
type AllMapType = IMapBasicParamTypeKeyToType & IMapObjectParamTypeKeyToType & IMapVectorParamTypeKeyToType;
|
type AllMapType = IMapBasicParamTypeKeyToType & IMapObjectParamTypeKeyToType & IMapVectorParamTypeKeyToType;
|
||||||
|
type AllArchiveMapType = IMapBasicParamTypeKeyToType & IMapArchiveObjectParamTypeKeyToType & IMapVectorParamTypeKeyToType;
|
||||||
type IParamType = keyof AllMapType;
|
type IParamType = keyof AllMapType;
|
||||||
type IObjectType = keyof IMapObjectParamTypeKeyToType;
|
type IObjectType = keyof IMapObjectParamTypeKeyToType;
|
||||||
type IVectorType = keyof IMapVectorParamTypeKeyToType;
|
type IVectorType = keyof IMapVectorParamTypeKeyToType;
|
||||||
type IParamValue<K extends IParamType> = AllMapType[K];
|
type IParamValue<K extends IParamType> = AllMapType[K];
|
||||||
|
type IArchiveParamValue<K extends IParamType> = AllArchiveMapType[K];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 特殊对象类型判定
|
* 特殊对象类型判定
|
||||||
*/
|
*/
|
||||||
const objectTypeListEnumSet = new Set<string>(["R", "G", "LR", "LG", "CG", "CLG"]);
|
const objectTypeListEnumSet = new Set<string>(["R", "G", "LR", "LG", "CG", "CLG"]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对象断言表达式
|
* 对象断言表达式
|
||||||
*/
|
*/
|
||||||
function isObjectType(key: string): key is IVectorType {
|
function isObjectType(key: string): key is IVectorType {
|
||||||
return objectTypeListEnumSet.has(key);
|
return objectTypeListEnumSet.has(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向量断言表达式
|
* 向量断言表达式
|
||||||
*/
|
*/
|
||||||
function isVectorType(key: string): key is IObjectType {
|
function isVectorType(key: string): key is IObjectType {
|
||||||
return key === "vec";
|
return key === "vec";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 压缩对象断言表达式
|
||||||
|
*/
|
||||||
|
function isArchiveObjectType(key: Object): key is IObjectParamArchiveType {
|
||||||
|
return !!(
|
||||||
|
(key as IObjectParamArchiveType).__LIVING_TOGETHER_OBJECT_ID &&
|
||||||
|
(key as IObjectParamArchiveType).__LIVING_TOGETHER_OBJECT_TYPE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模型参数类型
|
* 模型参数类型
|
||||||
*/
|
*/
|
||||||
@ -144,6 +171,10 @@ type IParameterValue<P extends IParameter> = {
|
|||||||
[X in keyof P]: IParamValue<P[X]>
|
[X in keyof P]: IParamValue<P[X]>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IArchiveParameterValue<P extends IParameter> = {
|
||||||
|
[X in keyof P]: IArchiveParamValue<P[X]>
|
||||||
|
}
|
||||||
|
|
||||||
function getDefaultValue<P extends IParameter> (option: IParameterOption<P>): IParameterValue<P> {
|
function getDefaultValue<P extends IParameter> (option: IParameterOption<P>): IParameterValue<P> {
|
||||||
let defaultObj = {} as IParameterValue<P>;
|
let defaultObj = {} as IParameterValue<P>;
|
||||||
for (let key in option) {
|
for (let key in option) {
|
||||||
@ -193,7 +224,131 @@ function getDefaultValue<P extends IParameter> (option: IParameterOption<P>): IP
|
|||||||
return defaultObj;
|
return defaultObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IRealObjectType = Range | Group | Label | Behavior;
|
||||||
|
type IArchiveParseFn = (archive: IObjectParamArchiveType) => IRealObjectType | undefined;
|
||||||
|
|
||||||
|
function object2ArchiveObject(object: IRealObjectType | IRealObjectType[] | any, testArray: boolean = true):
|
||||||
|
IObjectParamArchiveType | IObjectParamArchiveType[] | undefined {
|
||||||
|
if (object instanceof Range) {
|
||||||
|
return {
|
||||||
|
__LIVING_TOGETHER_OBJECT_ID: "Range",
|
||||||
|
__LIVING_TOGETHER_OBJECT_TYPE: object.id
|
||||||
|
}
|
||||||
|
} else if (object instanceof Group) {
|
||||||
|
return {
|
||||||
|
__LIVING_TOGETHER_OBJECT_ID: "Group",
|
||||||
|
__LIVING_TOGETHER_OBJECT_TYPE: object.id
|
||||||
|
}
|
||||||
|
} else if (object instanceof Label) {
|
||||||
|
return {
|
||||||
|
__LIVING_TOGETHER_OBJECT_ID: "Label",
|
||||||
|
__LIVING_TOGETHER_OBJECT_TYPE: object.id
|
||||||
|
}
|
||||||
|
} else if (object instanceof Behavior) {
|
||||||
|
return {
|
||||||
|
__LIVING_TOGETHER_OBJECT_ID: "Behavior",
|
||||||
|
__LIVING_TOGETHER_OBJECT_TYPE: object.id
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(object) && testArray) {
|
||||||
|
const hasValue = (item: any): item is IObjectParamArchiveType => !!item;
|
||||||
|
return object.map(item => object2ArchiveObject(item, false)).filter(hasValue);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parameter2ArchiveObject<P extends IParameter>
|
||||||
|
(value: IParameterValue<P>, option?: IParameterOption<P>): IArchiveParameterValue<P> {
|
||||||
|
let archive = {} as IArchiveParameterValue<P>;
|
||||||
|
|
||||||
|
const handelColl = (key: string, cValue: IParamValue<IParamType>) => {
|
||||||
|
|
||||||
|
// 处理对象类型
|
||||||
|
if (cValue instanceof Object && !Array.isArray(cValue)) {
|
||||||
|
const picker = (cValue as IObjectParamCacheType<any>).picker;
|
||||||
|
const objects = (cValue as IObjectParamCacheType<any>).objects;
|
||||||
|
|
||||||
|
(archive[key] as any) = {
|
||||||
|
picker: object2ArchiveObject(picker),
|
||||||
|
objects: object2ArchiveObject(objects)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理数组类型
|
||||||
|
else if (Array.isArray(cValue)) {
|
||||||
|
(archive[key] as any) = cValue.concat([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理数值
|
||||||
|
else {
|
||||||
|
(archive[key] as any) = cValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在参考设置对象
|
||||||
|
if (option) {
|
||||||
|
for (const key in option) {
|
||||||
|
handelColl(key, value[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不存在设置对象
|
||||||
|
else {
|
||||||
|
for (const key in value) {
|
||||||
|
handelColl(key, value[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return archive;
|
||||||
|
}
|
||||||
|
|
||||||
|
function archiveObject2Parameter<P extends IParameter>
|
||||||
|
(value: IArchiveParameterValue<P>, parse: IArchiveParseFn, option?: IParameterOption<P>): IParameterValue<P> {
|
||||||
|
let parameter = {} as IParameterValue<P>;
|
||||||
|
|
||||||
|
const handelColl = (key: string, cValue: IArchiveParamValue<IParamType>) => {
|
||||||
|
|
||||||
|
// 处理对象类型
|
||||||
|
if (cValue instanceof Object && !Array.isArray(cValue)) {
|
||||||
|
const picker = (cValue as IObjectParamCacheType<IObjectParamArchiveType>).picker;
|
||||||
|
const objects = (cValue as IObjectParamCacheType<IObjectParamArchiveType>).objects;
|
||||||
|
|
||||||
|
(parameter[key] as any) = {
|
||||||
|
picker: picker ? parse(picker) : picker,
|
||||||
|
objects: objects ? parse(objects) : objects
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理数组类型
|
||||||
|
else if (Array.isArray(cValue)) {
|
||||||
|
(parameter[key] as any) = cValue.concat([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理数值
|
||||||
|
else {
|
||||||
|
(parameter[key] as any) = cValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 存在参考设置对象
|
||||||
|
if (option) {
|
||||||
|
for (const key in option) {
|
||||||
|
handelColl(key, value[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不存在设置对象
|
||||||
|
else {
|
||||||
|
for (const key in value) {
|
||||||
|
handelColl(key, value[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parameter;
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
IParamType, IParamValue, isObjectType, isVectorType, getDefaultValue,
|
IParamType, IParamValue, isObjectType, isVectorType, getDefaultValue,
|
||||||
IParameterOptionItem, IParameter, IParameterOption, IParameterValue
|
IParameterOptionItem, IParameter, IParameterOption, IParameterValue,
|
||||||
|
object2ArchiveObject, parameter2ArchiveObject
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user