Opim isDelete() & show gen error
This commit is contained in:
parent
1b9c47f688
commit
63f13183d0
@ -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",
|
||||
|
@ -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": "对象不是一个群",
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ class Model extends Emitter<ModelEvent> {
|
||||
|
||||
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<ModelEvent> {
|
||||
* @param label 标签
|
||||
*/
|
||||
public getObjectByLabel(label: Label): CtrlObject[] {
|
||||
|
||||
if (label.isDeleted()) return [];
|
||||
|
||||
const res: CtrlObject[] = [];
|
||||
for (let i = 0; i < this.objectPool.length; i++) {
|
||||
|
||||
|
@ -130,7 +130,9 @@ class GroupDetails extends Component<IGroupDetailsProps & IMixinStatusProps> {
|
||||
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<IGroupDetailsProps & IMixinStatusProps> {
|
||||
}
|
||||
|
||||
private renderRangeGenOption(group: Group) {
|
||||
|
||||
let isRenderErrorInfo: boolean = false;
|
||||
if (group.genErrorMessageShowCount > 0) {
|
||||
group.genErrorMessageShowCount --;
|
||||
if (group.genErrorMessage) {
|
||||
isRenderErrorInfo = true;
|
||||
}
|
||||
} else {
|
||||
group.genErrorMessage = undefined;
|
||||
}
|
||||
|
||||
return <>
|
||||
<ObjectPicker
|
||||
keyI18n="Common.Attr.Key.Generation.Use.Range"
|
||||
type={"LR"}
|
||||
value={group.genRange}
|
||||
errorI18n={isRenderErrorInfo ? group.genErrorMessage as any : undefined}
|
||||
valueChange={(value) => {
|
||||
this.props.status?.changeGroupAttrib(group.id, "genRange", value);
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user