添加项目文件。
This commit is contained in:
60
QuickModeling/Models/ComponentConfig.cs
Normal file
60
QuickModeling/Models/ComponentConfig.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuickModeling.Models
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public partial class ComponentConfig : ObservableValidator, ICloneable
|
||||
{
|
||||
private ComponentType componentType;
|
||||
|
||||
private string description;
|
||||
|
||||
private bool isEnabled = true;
|
||||
|
||||
private string name;
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var copy = (ComponentConfig)MemberwiseClone();
|
||||
copy.Guid = Guid.NewGuid();
|
||||
copy.Parameters = new ObservableCollection<Parameter>(Parameters.Select(p => p.Clone() as Parameter));
|
||||
return copy;
|
||||
}
|
||||
[JsonProperty]
|
||||
public Guid Guid { get; set; }
|
||||
/// <summary>
|
||||
/// 配置名称
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "配置名称不能为空")]
|
||||
[MinLength(1, ErrorMessage = "配置名称不能为空")]
|
||||
[JsonProperty]
|
||||
public string Name { get => name; set => SetProperty(ref name, value, true); }
|
||||
|
||||
[JsonProperty]
|
||||
public ComponentType ComponentType { get => componentType; set => SetProperty(ref componentType, value); }
|
||||
/// <summary>
|
||||
/// 配置描述
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public string Description { get => description; set => SetProperty(ref description, value); }
|
||||
|
||||
[JsonProperty]
|
||||
public bool IsEnabled { get => isEnabled; set => SetProperty(ref isEnabled, value); }
|
||||
|
||||
/// <summary>
|
||||
/// 参数
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public ObservableCollection<Parameter> Parameters { get; set; } = new ObservableCollection<Parameter>();
|
||||
}
|
||||
}
|
||||
43
QuickModeling/Models/ComponentType.cs
Normal file
43
QuickModeling/Models/ComponentType.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QuickModeling.Models
|
||||
{
|
||||
public enum ComponentType
|
||||
{
|
||||
/// <summary>
|
||||
/// 管环
|
||||
/// </summary>
|
||||
[Description("管环")]
|
||||
SegmentRing,
|
||||
/// <summary>
|
||||
/// 仰拱填充
|
||||
/// </summary>
|
||||
[Description("仰拱填充")]
|
||||
VaultFill,
|
||||
/// <summary>
|
||||
/// 盖板
|
||||
/// </summary>
|
||||
[Description("盖板")]
|
||||
Cover,
|
||||
/// <summary>
|
||||
/// 侧沟槽身
|
||||
/// </summary>
|
||||
[Description("侧沟槽身")]
|
||||
SideGroovedBody,
|
||||
/// <summary>
|
||||
/// 导台
|
||||
/// </summary>
|
||||
[Description("导台")]
|
||||
Guides,
|
||||
/// <summary>
|
||||
/// 踏步板
|
||||
/// </summary>
|
||||
[Description("踏步板")]
|
||||
TreadBoard
|
||||
}
|
||||
}
|
||||
127
QuickModeling/Models/Parameter.cs
Normal file
127
QuickModeling/Models/Parameter.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
using Bentley.DgnPlatformNET;
|
||||
using Bentley.GeometryNET;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace QuickModeling.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 项参数
|
||||
/// </summary>
|
||||
public partial class Parameter : ObservableValidator, ICloneable
|
||||
{
|
||||
/// <summary>
|
||||
/// 对应CustomProperty的数据类型
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private TypeKind dataType;
|
||||
/// <summary>
|
||||
/// 对应ItemType
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(FullName))]
|
||||
private string group;
|
||||
/// <summary>
|
||||
/// 对应CustomProperty的名称
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[Required(ErrorMessage = "属性名称必填")]
|
||||
[MinLength(1, ErrorMessage = "参数名称不能为空")]
|
||||
[MaxLength(20, ErrorMessage = "参数名称不能超过20个字符")]
|
||||
[NotifyDataErrorInfo]
|
||||
[NotifyPropertyChangedFor(nameof(FullName))]
|
||||
private string name;
|
||||
/// <summary>
|
||||
/// 对应CustomProperty的值
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
[NotifyDataErrorInfo]
|
||||
[CustomValidation(typeof(Parameter), nameof(ValidateValue))]
|
||||
private object value;
|
||||
|
||||
///// <summary>
|
||||
///// 工作单位
|
||||
///// </summary>
|
||||
//[ObservableProperty]
|
||||
//private WorkingUnit unit = WorkingUnit.Unspecified;
|
||||
/// <summary>
|
||||
/// 对应CustomProperty的单位
|
||||
/// </summary>
|
||||
//[ObservableProperty]
|
||||
//private DgnECUnit dgnUnit;
|
||||
partial void OnDataTypeChanged(TypeKind kind)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Value?.ToString()))
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case TypeKind.Boolean:
|
||||
Value = false;
|
||||
break;
|
||||
case TypeKind.Double:
|
||||
Value = 0.0;
|
||||
break;
|
||||
case TypeKind.Integer:
|
||||
Value = 0;
|
||||
break;
|
||||
case TypeKind.String:
|
||||
Value = string.Empty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var copy = (Parameter)MemberwiseClone();
|
||||
//copy.DgnUnit = new DgnECUnit(Unit);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateValue(string value, ValidationContext context)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return new ValidationResult("参数值为空");
|
||||
}
|
||||
Parameter instance = (Parameter)context.ObjectInstance;
|
||||
switch (instance.DataType)
|
||||
{
|
||||
case TypeKind.Boolean:
|
||||
if (bool.TryParse(value, out _))
|
||||
{
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
break;
|
||||
case TypeKind.Double:
|
||||
if (double.TryParse(value, out _))
|
||||
{
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
break;
|
||||
case TypeKind.Integer:
|
||||
if (int.TryParse(value, out _))
|
||||
{
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
break;
|
||||
case TypeKind.String:
|
||||
// 字符串类型不需要额外验证
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
return new("参数值与值类型不匹配");
|
||||
}
|
||||
|
||||
//public string Name { get => name; set => SetProperty(ref name, value, true); }
|
||||
public string FullName => $"{Group}-{Name}";
|
||||
}
|
||||
}
|
||||
33
QuickModeling/Models/TypeKind.cs
Normal file
33
QuickModeling/Models/TypeKind.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace QuickModeling.Models
|
||||
{
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum TypeKind
|
||||
{
|
||||
[Description("布尔值")]
|
||||
Boolean = 0,
|
||||
//[Description("日期")]
|
||||
//DateTime = 1,
|
||||
/// <summary>
|
||||
/// Number,数字,支持WorkUnit
|
||||
/// </summary>
|
||||
[Description("数字")]
|
||||
Double = 2,
|
||||
[Description("整数")]
|
||||
Integer = 3,
|
||||
/// <summary>
|
||||
/// 点坐标,支持WorkUnit
|
||||
/// </summary>
|
||||
//[Description("坐标点")]
|
||||
//Point = 4,
|
||||
[Description("字符串")]
|
||||
String = 5,
|
||||
//[Description("自定义")]
|
||||
//Custom
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user