chr
2025-03-04 3f62d18e4361cd1d7a49c126765d95b2ad9c8246
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using PdmSwPlugin.Common.CustomHandler;
using PdmSwPlugin.PropertySetting.Interface;
using PdmSwPlugin.PropertySetting.Panel.Attr;
using SolidWorks.Interop.sldworks;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Controls;
 
namespace PdmSwPlugin.PropertySetting.Panel
{
    /// <summary>
    /// DrwPanel.xaml 的交互逻辑
    /// </summary>
    public partial class DefaultPanel : UserControl, IPropertyOpt, INotifyPropertyChanged
    {
        #region 不能公用的东西,真有你的啊C#
        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
 
        public void RaiseAndSetIfChanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
        {
            old = @new;
            if (propertyName != null)
            {
                RaisePropertyChanged(propertyName);
                var attr = this.GetType().GetProperty(propertyName)?.GetCustomAttribute<PropertySettingAttr>();
                if (attr == null)
                {
                    return;
                }
                if (attr.NeedSave)
                {
                    UpdateProperty?.Invoke(this, attr.Name, @new);
                }
            }
        }
        #endregion
 
        private string _message;
 
        public string message
        {
            get => _message;
            set => RaiseAndSetIfChanged(ref _message, value);
        }
 
        public DefaultPanel()
        {
            DataContext = this;
            InitializeComponent();
        }
 
        private ModelDoc2 doc;
 
        public event PanelPropertyChanged UpdateProperty;
 
        public bool ClearAllProperties(out string ErrMsg)
        {
            ErrMsg = null;
            return true;
        }
 
        public Dictionary<string, string> GetAllProperties()
        {
            return null;
        }
 
        public object GetPropertyValue(string propertyName)
        {
            return null;
        }
 
        public bool SetProperties(ModelDoc2 doc, object properties, bool docChange, out string errMsg)
        {
            errMsg = null;
            message = properties.ToString();
            return true;
        }
 
        public bool SaveDoc(ref int err, ref int warn){
            return true;
        }
 
        public bool SetSettings(object settings)
        {
            return true;
        }
 
        public bool UpdateSingleProperty(string name, string value)
        {
            return true;
        }
 
        public bool GetDocChanged()
        {
            return false;
        }
 
        public bool ResetProperty(out string errMsg)
        {
            return SetProperties(doc, message, false, out errMsg);
        }
    }
}