From 63f13183d069af9a4351995ebacdf4b939cae4b7 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Thu, 17 Mar 2022 17:39:43 +0800 Subject: [PATCH] Opim isDelete() & show gen error --- source/Localization/EN-US.ts | 4 ++ source/Localization/ZH-CN.ts | 4 ++ source/Model/Group.ts | 49 ++++++++++++++++++---- source/Model/Label.ts | 19 ++++++--- source/Model/Model.ts | 4 ++ source/Panel/GroupDetails/GroupDetails.tsx | 16 ++++++- 6 files changed, 82 insertions(+), 14 deletions(-) diff --git a/source/Localization/EN-US.ts b/source/Localization/EN-US.ts index 0a03879..b18fb44 100644 --- a/source/Localization/EN-US.ts +++ b/source/Localization/EN-US.ts @@ -75,6 +75,10 @@ const EN_US = { "Common.Attr.Key.Generation.Point.X": "Generation Point X", "Common.Attr.Key.Generation.Point.Y": "Generation Point Y", "Common.Attr.Key.Generation.Point.Z": "Generation Point Z", + "Common.Attr.Key.Generation.Error.Empty.Object": "Please select a range object or label to add to the object", + "Common.Attr.Key.Generation.Error.Empty.Range.List": "The specified label does not contain any scope objects", + "Common.Attr.Key.Generation.Error.Invalid.Range": "The specified scope object is invalid", + "Common.Attr.Key.Generation.Error.Invalid.Label": "The specified label has expired", "Panel.Info.Range.Details.Attr.Error.Not.Range": "Object is not a Range", "Panel.Info.Range.Details.Attr.Error.Unspecified": "Unspecified range object", "Panel.Info.Group.Details.Attr.Error.Not.Group": "Object is not a Group", diff --git a/source/Localization/ZH-CN.ts b/source/Localization/ZH-CN.ts index d5d3bf0..e880dd5 100644 --- a/source/Localization/ZH-CN.ts +++ b/source/Localization/ZH-CN.ts @@ -75,6 +75,10 @@ const ZH_CN = { "Common.Attr.Key.Generation.Point.X": "生成位置 X 坐标", "Common.Attr.Key.Generation.Point.Y": "生成位置 Y 坐标", "Common.Attr.Key.Generation.Point.Z": "生成位置 Z 坐标", + "Common.Attr.Key.Generation.Error.Empty.Object": "请选择一个范围对象或添加至对象的标签", + "Common.Attr.Key.Generation.Error.Empty.Range.List": "指定的标签中没有包含任何范围对象", + "Common.Attr.Key.Generation.Error.Invalid.Range": "指定的范围对象已失效", + "Common.Attr.Key.Generation.Error.Invalid.Label": "指定的标签已失效", "Panel.Info.Range.Details.Attr.Error.Not.Range": "对象不是一个范围", "Panel.Info.Range.Details.Attr.Error.Unspecified": "未指定范围对象", "Panel.Info.Group.Details.Attr.Error.Not.Group": "对象不是一个群", diff --git a/source/Model/Group.ts b/source/Model/Group.ts index 1ab400b..831083f 100644 --- a/source/Model/Group.ts +++ b/source/Model/Group.ts @@ -47,9 +47,9 @@ class Group extends CtrlObject { /** * 生成错误信息 */ - public genErrorMessageShowCount?: string; + public genErrorMessageShowCount: number = 0; - private genInSingelRange(count: number, range: Range) { + private genInSingleRange(count: number, range: Range) { for (let i = 0; i < count; i++) { let individual = new Individual(this); individual.position[0] = range.position[0] + (Math.random() - .5) * 2 * range.radius[0]; @@ -75,18 +75,44 @@ class Group extends CtrlObject { // 单一范围对象 if (this.genRange instanceof Range) { - rangeList = [this.genRange]; + + // 无效的对象 + if (this.genRange.isDeleted()) { + this.genErrorMessage = "Common.Attr.Key.Generation.Error.Invalid.Range"; + return false; + } + + else { + rangeList = [this.genRange]; + } } // 多重范围对象 - if (this.genRange instanceof Label) { - let objList: CtrlObject[] = this.model.getObjectByLabel(this.genRange); - rangeList = objList.filter((obj) => obj instanceof Range) as Range[] + else if (this.genRange instanceof Label) { + + // 无效的标签 + if (this.genRange.isDeleted()) { + this.genErrorMessage = "Common.Attr.Key.Generation.Error.Invalid.Label"; + return false; + } + + else { + let objList: CtrlObject[] = this.model.getObjectByLabel(this.genRange); + rangeList = objList.filter((obj) => { + return obj instanceof Range + }) as Range[]; + } + } + + // 空对象 + else { + this.genErrorMessage = "Common.Attr.Key.Generation.Error.Empty.Object"; + return false; } // 单一范围生成 if (rangeList.length === 1) { - this.genInSingelRange(this.genCount, rangeList[0]); + this.genInSingleRange(this.genCount, rangeList[0]); return true; } @@ -127,12 +153,19 @@ class Group extends CtrlObject { // 数据生成 for (let i = 0; i < rangeList.length; i++) { - this.genInSingelRange(genData[i], rangeList[i]); + this.genInSingleRange(genData[i], rangeList[i]); } return true; } + // 空数据 + else { + this.genErrorMessage = "Common.Attr.Key.Generation.Error.Empty.Range.List"; + return false; + } + + this.genErrorMessage = "Common.No.Unknown.Error"; return false; } diff --git a/source/Model/Label.ts b/source/Model/Label.ts index 032873b..81c1d2b 100644 --- a/source/Model/Label.ts +++ b/source/Model/Label.ts @@ -46,6 +46,7 @@ class Label { * 判断是否为相同标签 */ public equal(label: Label): boolean { + if (this.isDeleted() || label.isDeleted()) return false; return this === label || this.id === label.id; } @@ -55,11 +56,9 @@ class Label { private deleteFlag: boolean = false; /** - * 是否被删除 + * 测试是否被删除 */ - public isDeleted(): boolean { - if (this.deleteFlag) return true; - if (this.isBuildIn) return false; + public testDelete() { for (let i = 0; i < this.model.labelPool.length; i++) { if (this.model.labelPool[i].equal(this)) return false; } @@ -67,6 +66,15 @@ class Label { return true; } + /** + * 是否被删除 + */ + public isDeleted(): boolean { + if (this.isBuildIn) return false; + if (this.deleteFlag) return true; + return false; + } + /** * 设置为内置标签 */ @@ -115,9 +123,10 @@ class LabelObject { * 是否存在标签 */ public hasLabel(label: Label): boolean { + if (label.isDeleted()) return false; let has = false; this.labels.forEach((localLabel) => { - if (localLabel.equal(label)) has = true; + if (!localLabel.isDeleted() && localLabel.equal(label)) has = true; }); return has; } diff --git a/source/Model/Model.ts b/source/Model/Model.ts index cafec89..9e537db 100644 --- a/source/Model/Model.ts +++ b/source/Model/Model.ts @@ -95,6 +95,7 @@ class Model extends Emitter { if (deletedLabel) { this.labelPool.splice(index, 1); + deletedLabel.testDelete(); console.log(`Model: Delete label ${deletedLabel.name ?? deletedLabel.id}`); this.emit("labelDelete", deletedLabel); this.emit("labelChange", this.labelPool); @@ -106,6 +107,9 @@ class Model extends Emitter { * @param label 标签 */ public getObjectByLabel(label: Label): CtrlObject[] { + + if (label.isDeleted()) return []; + const res: CtrlObject[] = []; for (let i = 0; i < this.objectPool.length; i++) { diff --git a/source/Panel/GroupDetails/GroupDetails.tsx b/source/Panel/GroupDetails/GroupDetails.tsx index 8844fdf..f38596e 100644 --- a/source/Panel/GroupDetails/GroupDetails.tsx +++ b/source/Panel/GroupDetails/GroupDetails.tsx @@ -130,7 +130,9 @@ class GroupDetails extends Component { keyI18n="Common.Attr.Key.Generation" onIconName="BuildDefinition" offIconName="BuildDefinition" valueChange={() => { - group.genIndividuals(); + if(!group.genIndividuals()) { + this.props.status?.changeGroupAttrib(group.id, "genErrorMessageShowCount", 1); + } }} /> @@ -169,11 +171,23 @@ class GroupDetails extends Component { } private renderRangeGenOption(group: Group) { + + let isRenderErrorInfo: boolean = false; + if (group.genErrorMessageShowCount > 0) { + group.genErrorMessageShowCount --; + if (group.genErrorMessage) { + isRenderErrorInfo = true; + } + } else { + group.genErrorMessage = undefined; + } + return <> { this.props.status?.changeGroupAttrib(group.id, "genRange", value); }}