using CaeMesh; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace RBFMorphing { public class ViewBasePart { private readonly FeMesh _mesh; public ViewBasePart(FeMesh mesh) { _mesh = mesh; } [Category("零件")] [DisplayName("零件名")] [Description("指定零件名称")] [TypeConverter(typeof(NameListConverter))] public string Name { get; set; } [Browsable(false)] public List NameList { get { if (_mesh != null && _mesh.Parts.Count > 0) { return _mesh.Parts .Select(kvp => kvp.Value) .Where(p => !p.Internal && p.PartType == PartType.Solid) .Select(p => p.Name) .OrderBy(x => x) .ToList(); } return null; } } class NameListConverter : TypeConverter { public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { List list; // ReSharper disable once SuspiciousTypeConversion.Global if (context.Instance is ViewBasePart part) list = part.NameList; else list = null; return new StandardValuesCollection(list); } } } }