using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows; namespace XP.ImageProcessing.RoiControl.Models { /// /// ROI形状类型 /// public enum ROIType { Polygon } /// /// ROI基类 /// public abstract class ROIShape : INotifyPropertyChanged { private bool _isSelected; private string _id = Guid.NewGuid().ToString(); private string _color = "Red"; public string Id { get => _id; set { _id = value; OnPropertyChanged(); } } public bool IsSelected { get => _isSelected; set { _isSelected = value; OnPropertyChanged(); } } public string Color { get => _color; set { _color = value; OnPropertyChanged(); } } public abstract ROIType ROIType { get; } public event PropertyChangedEventHandler? PropertyChanged; public void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } /// /// 多边形ROI /// public class PolygonROI : ROIShape { private ObservableCollection _points = new ObservableCollection(); public override ROIType ROIType => ROIType.Polygon; public ObservableCollection Points { get => _points; set { _points = value; OnPropertyChanged(); } } /// /// 用于JSON序列化的Points列表(不参与UI绑定) /// [System.Text.Json.Serialization.JsonPropertyName("PointsList")] public List PointsList { get => new List(_points); set { _points = new ObservableCollection(value ?? new List()); OnPropertyChanged(nameof(Points)); } } } }