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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Net.Http;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using log4net;
using Microsoft.Win32;
using PdmSwPlugin.Commmon.Util.UI;
using PdmSwPlugin.Common;
using PdmSwPlugin.Common.Constants;
using PdmSwPlugin.Common.Entity;
using PdmSwPlugin.Common.Interface;
using PdmSwPlugin.Common.Setting;
using PdmSwPlugin.Common.Util;
using PdmSwPlugin.Common.Util.Http;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
 
namespace PdmSwPlugin.PropertySetting
{
    /// <summary>
    /// UserControl1.xaml 的交互逻辑
    /// </summary>
    [PdmSwPlugin(Title = "属性设置")]
    public partial class PropertySettingControl : UserControl, ISwAppSetter, INotifyPropertyChanged, IActiveDocChangeHandler
    {
        private static ILog Logger = LogManager.GetLogger("PropertySetting");
        #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);
            }
        }
        #endregion
 
        #region 属性
        public SldWorks SwApp { get; private set; }
        public ModelDoc2 LastModelDoc { set; get; }
        public ModelDoc2 ActiveDoc { set; get; }
        public Component2 Component { set; get; }
 
        public CustomPropertyManager swCuspro1;
        private HttpClient Client { get; set; }
        #endregion
 
        #region UI绑定
        private string _activeDocPath;
        public string ActiveDocPath
        {
            get => _activeDocPath;
            set => RaiseAndSetIfChanged(ref _activeDocPath, value);
        }
 
        private int _activeDocType;
        public int ActiveDocType
        {
            get => _activeDocType;
            set
            {
                RaiseAndSetIfChanged(ref _activeDocType, value);
            }
        }
 
        private string _materialType;
        public string MaterialType
        {
            get => _materialType;
            set
            {
                RaiseAndSetIfChanged(ref _materialType, value);
                GetStuffItemSource();
            }
        }
 
        private string _stuffType;
        public string StuffType
        {
            get => _stuffType;
            set
            {
                RaiseAndSetIfChanged(ref _stuffType, value);
                GetSurfaceItemSource();
                GetHeatItemSource();
            }
        }
 
        private string _surfaceType;
        public string SurfaceType
        {
            get => _surfaceType;
            set => RaiseAndSetIfChanged(ref _surfaceType, value);
        }
 
        private string _heatType;
        public string HeatType
        {
            get => _heatType;
            set => RaiseAndSetIfChanged(ref _heatType, value);
        }
 
        private ObservableCollection<string> _materialTypeItemSource;
        public ObservableCollection<string> MaterialTypeItemSource
        {
            get => _materialTypeItemSource;
            set => RaiseAndSetIfChanged(ref _materialTypeItemSource, value);
        }
 
        private ObservableCollection<string> _stuffItemSource;
        public ObservableCollection<string> StuffItemSource
        {
            get => _stuffItemSource;
            set => RaiseAndSetIfChanged(ref _stuffItemSource, value);
        }
 
        private ObservableCollection<string> _surfaceItemSource;
        public ObservableCollection<string> SurfaceItemSource
        {
            get => _surfaceItemSource;
            set => RaiseAndSetIfChanged(ref _surfaceItemSource, value);
        }
 
        private ObservableCollection<string> _heatItemSource;
        public ObservableCollection<string> HeatItemSource
        {
            get => _heatItemSource;
            set => RaiseAndSetIfChanged(ref _heatItemSource, value);
        }
 
        private ObservableCollection<PropertyInfo_2D> _propertyDataSource_2D;
        public ObservableCollection<PropertyInfo_2D> PropertyDataSource_2D
        {
            get => _propertyDataSource_2D;
            set => RaiseAndSetIfChanged(ref _propertyDataSource_2D, value);
        }
        #endregion
        private HttpClientCreator clientCreator { get; set; }
 
        public PropertySettingControl()
        {
            clientCreator = new HttpClientCreator(new HttpConfig(PluginSetting.Instance.BaseAddress));
            InitializeComponent();
            self.DataContext = this;
        }
 
        public PropertySettingControl(SldWorks SwApp) : this()
        {
            this.SwApp = SwApp;
        }
 
        private void InitPropertyData()
        {
            if (Client == null)
            {
                Client = clientCreator.GetClient();
            }
            LoadComboxItemSource();
        }
 
        /// <summary>
        /// 从服务器加载各种选项
        /// </summary>
        private void LoadComboxItemSource()
        {
            GetMaterialTypeItemSource();
            GetStuffItemSource();
            GetSurfaceItemSource();
            GetHeatItemSource();
        }
 
        /// <summary>
        /// 查询加工件类型
        /// </summary>
        private async void GetMaterialTypeItemSource()
        {
            try
            {
                Result<ObservableCollection<string>> httpResult =
                  await Client.GetAsyncAction<ObservableCollection<string>>("openApi/wpf/materialType/select");
                var temp = httpResult.HandleResult();
                temp = temp ?? new ObservableCollection<string>();
                temp.Insert(0, "无");
                MaterialTypeItemSource = temp;
            }
            catch (Exception e)
            {
                Logger.Error("获取加工件类型数据异常!", e);
                var temp = new ObservableCollection<string>();
                temp.Insert(0, "无");
                MaterialTypeItemSource = temp;
                MessageBox.Show("获取加工件类型数据异常!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 
        /// <summary>
        /// 查询材料类型
        /// </summary>
        private async void GetStuffItemSource()
        {
            if (string.IsNullOrEmpty(MaterialType))
            {
                StuffItemSource = new ObservableCollection<string> {
                   "无"
                };
                return;
            }
            try
            {
                Result<ObservableCollection<string>> httpResult =
                  await Client.GetAsyncAction<ObservableCollection<string>>("openApi/wpf/stuff/select",
                  new Dictionary<string, string>
                  {
                      ["materialType"] = MaterialType
                  }
                  );
                var temp = httpResult.HandleResult();
                temp = temp ?? new ObservableCollection<string>();
                temp.Insert(0, "无");
                StuffItemSource = temp;
            }
            catch (Exception e)
            {
                Logger.Error("获取材料数据异常!", e);
                var temp = new ObservableCollection<string>();
                temp.Insert(0, "无");
                StuffItemSource = temp;
                MessageBox.Show("获取材料数据异常!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 
        /// <summary>
        /// 查询表处理类型
        /// </summary>
        private async void GetSurfaceItemSource()
        {
            try
            {
                Result<ObservableCollection<string>> httpResult =
                  await Client.GetAsyncAction<ObservableCollection<string>>("openApi/wpf/surface/select",
                   new Dictionary<string, string>
                   {
                       ["materialType"] = MaterialType,
                       ["stuffType"] = StuffType
                   });
                var temp = httpResult.HandleResult();
                temp = temp ?? new ObservableCollection<string>();
                temp.Insert(0, "无");
                SurfaceItemSource = temp;
            }
            catch (Exception e)
            {
                var temp = new ObservableCollection<string>();
                temp.Insert(0, "无");
                SurfaceItemSource = temp;
                MessageBox.Show("获取表面处理数据异常!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 
        /// <summary>
        /// 查询热处理类型
        /// </summary>
        private async void GetHeatItemSource()
        {
            try
            {
                Result<ObservableCollection<string>> httpResult =
                  await Client.GetAsyncAction<ObservableCollection<string>>("openApi/wpf/heat/select",
                   new Dictionary<string, string>
                   {
                       ["materialType"] = MaterialType,
                       ["stuffType"] = StuffType
                   });
                var temp = httpResult.HandleResult();
                temp = temp ?? new ObservableCollection<string>();
                temp.Insert(0, "无");
                HeatItemSource = temp;
            }
            catch (Exception e)
            {
                var temp = new ObservableCollection<string>();
                temp.Insert(0, "无");
                HeatItemSource = temp;
                MessageBox.Show("获取热处理数据异常!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 
        /// <summary>
        /// 根据激活的文档类型,变更属性可视
        /// </summary>
        private void SwitchVisiable()
        {
            // 2D图纸
            if (ActiveDocType == (int)swDocumentTypes_e.swDocDRAWING)
            {
                mainPanel.Visibility = Visibility.Collapsed;
                dataGridPanel.Visibility = Visibility.Visible;
            }
            else
            {
                mainPanel.Visibility = Visibility.Visible;
                dataGridPanel.Visibility = Visibility.Collapsed;
            }
 
            // 零件
            if (ActiveDocType == (int)swDocumentTypes_e.swDocPART)
            {
                materialTypePanel.Visibility = Visibility.Visible;
                stuffPanel.Visibility = Visibility.Visible;
                surfacePanel.Visibility = Visibility.Visible;
                heatPanel.Visibility = Visibility.Visible;
                pricePanel.Visibility = Visibility.Visible;
            }
            // 装配体
            else if (ActiveDocType == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                materialTypePanel.Visibility = Visibility.Collapsed;
                stuffPanel.Visibility = Visibility.Collapsed;
                surfacePanel.Visibility = Visibility.Collapsed;
                heatPanel.Visibility = Visibility.Collapsed;
                pricePanel.Visibility = Visibility.Collapsed;
            }
        }
 
        /// <summary>
        /// 从激活的文档中读取参数
        /// </summary>
        private async void LoadDocProperties()
        {
            string tempStr;
            HashSet<string> skipValue = new HashSet<string> { "$PRP:\"SW-File Name\"" };
            Dictionary<string, string> properties;
            if (ActiveDocType == (int)swDocumentTypes_e.swDocPART)
            {
                properties = CustomPropertyUtil.GetCustomProperties(ActiveDoc, true, skipValue);
 
                // 零件
                version.Text = "A";
                materialCode.Text = properties.GetCustomValue(PropertyName.PART_NO);
                materialModel.Text = properties.GetCustomValue(PropertyName.PART_MODEL);
                materialName.Text = properties.GetCustomValue(PropertyName.PART_NAME);
                tempStr = properties.GetCustomValue("Rev");
                // 版本 Rev
                if (string.IsNullOrEmpty(tempStr) == false)
                {
                    version.Text = tempStr;
                }
 
                tempStr = properties.GetCustomValue(PropertyName.JGJ_TYPE);
                // 加工件类型 jgjlx
                if (string.IsNullOrEmpty(tempStr) == false)
                {
                    MaterialType = tempStr;
                }
                else
                {
                    materialType.SelectedIndex = 0;
                }
 
                tempStr = properties.GetCustomValue(PropertyName.STUFF_TYPE);
                // 材料名称 MATERIAL
                if (string.IsNullOrEmpty(tempStr) == false)
                {
                    StuffType = tempStr;
                }
                else
                {
                    stuff.SelectedIndex = 0;
                }
                // 表面处理 Finished
                tempStr = properties.GetCustomValue(PropertyName.SURFACE_TYPE);
                if (string.IsNullOrEmpty(tempStr) == false)
                {
                    SurfaceType = tempStr;
                }
                else
                {
                    surface.SelectedIndex = 0;
                }
 
                // 热处理 HEAT TREATMENT
                tempStr = properties.GetCustomValue(PropertyName.HEAT_TYPE);
                if (string.IsNullOrEmpty(tempStr) == false)
                {
                    HeatType = tempStr;
                }
                else
                {
                    heat.SelectedIndex = 0;
                }
 
                // 价格 jgjPrice
                tempStr = properties.GetCustomValue("jgjPrice");
                if (string.IsNullOrEmpty(tempStr) == false)
                {
                    price.Text = tempStr;
                }
                else
                {
                    price.Text = "0.00";
                }
                return;
            }
            else if (ActiveDocType == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                properties = CustomPropertyUtil.GetCustomProperties(ActiveDoc, true, skipValue);
                // 装配体
                version.Text = "装配体";
                materialCode.Text = properties.GetCustomValue(PropertyName.PART_NO);
                materialModel.Text = properties.GetCustomValue(PropertyName.PART_MODEL);
                materialName.Text = properties.GetCustomValue(PropertyName.PART_NAME);
            }
            else if (ActiveDocType == (int)swDocumentTypes_e.swDocDRAWING)
            {
                // 2D图纸
                PropertyDataSource_2D = PropertyDataSource_2D ?? new ObservableCollection<PropertyInfo_2D>();
                PropertyDataSource_2D.Clear();
                if (!EngineeringDrawingPropertiesClass.SetDesigner(ActiveDoc, System.Environment.UserName))
                {
                    // GlobalFileLogger.Log("往工程图{0}里写入设计者{1}属性时失败", activeDoc.GetPathName(), System.Environment.UserName);
                }
                NameValueCollection allProperties = EngineeringDrawingPropertiesClass
                    .ReadViaNotesAtFirstView(ActiveDoc, EngineeringDrawingPropertiesClass.PredefinedProperties);
                if (allProperties != null)
                {
                    foreach (var v in allProperties.AllKeys)
                    {
                        PropertyDataSource_2D.Add(new PropertyInfo_2D(v, allProperties[v]));
                    }
                }
 
            }
 
        }
 
        private void ClearDocProperties()
        {
            version.Text = "";
            materialCode.Text = "";
            materialModel.Text = "";
            materialName.Text = "";
            version.Text = "";
            MaterialType = "";
            StuffType = "";
            SurfaceType = "";
            HeatType = "";
            price.Text = "0.00";
        }
 
        private void SetDocProperties(Dictionary<string, string> datas, bool forceUpdate)
        {
        }
 
        /// <summary>
        /// 获取当前页面的属性信息,防止变更文件后属性也变了
        /// </summary>
        /// <returns>属性集合</returns>
        private Dictionary<string, string> GetCurrentProperties()
        {
            Dictionary<string, string> props = new Dictionary<string, string>();
            // 零件
            if (ActiveDocType == (int)swDocumentTypes_e.swDocPART)
            {
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[0]] = materialCode.Text;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[1]] = materialModel.Text;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[2]] = materialName.Text;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[3]] = MaterialType;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[4]] = StuffType;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[5]] = SurfaceType;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[6]] = HeatType;
                props["Rev"] = version.Text;
                if (!price.IsReadOnly)
                {
                    if (decimal.TryParse(price.Text, out decimal priceValue) && priceValue > 0)
                    {
                        props["jgjPrice"] = price.Text;
                    }
                }
                // CustomerPropertiesWrapper.SetSingle(doc, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[6], HeatType);
            }
            else if (ActiveDocType == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[0]] = materialCode.Text;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[1]] = materialModel.Text;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[2]] = materialName.Text;
                props[GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[3]] = MaterialType;
            }
            return props;
        }
 
        /// <summary>
        /// 将属性设置进文档,注意,并没有保存
        /// </summary>
        /// <param name="doc">文档</param>
        private void SetDocProperty(ModelDoc2 doc, Dictionary<string, string> props)
        {
            props = props ?? GetCurrentProperties();
            foreach (string name in doc.GetConfigurationNames())
            { // 遍历所有的配置
                Configuration config = doc.GetConfigurationByName(name) as Configuration;
                if (config.CustomPropertyManager != null)
                { // 只要该配置的自定义属性管理器不为空
                    foreach (KeyValuePair<string, string> keyValuePair in props)
                    {
                        if (config.CustomPropertyManager.Add3(keyValuePair.Key, (int)swCustomInfoType_e.swCustomInfoText, keyValuePair.Value, 1)
                            == (int)swCustomInfoAddResult_e.swCustomInfoAddResult_AddedOrChanged)
                        { // 增加或改变成功
 
                        }
                    }
                    if (!props.ContainsKey("jgjPrice"))
                    { // 如果没有加工件价格,就删除它
                        config.CustomPropertyManager.Delete2("jgjPrice");
                    }
                }
            }
        }
 
        public void SetSwApp(SldWorks SwApp)
        {
            this.SwApp = SwApp;
        }
 
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (ActiveDoc == null)
            {
                return;
            }
            if (Component != null)
            {
                ModelDoc2 doc = SwApp.IActiveDoc2;
                if (!DocUtil.IsSameDoc(ActiveDoc, doc))
                {
                    this.Warning("当前属性与Solidworks打开的文档不同,请先刷新!");
                    return;
                }
 
                // 不知道在干啥
                swComponentSuppressionState_e CompState = (swComponentSuppressionState_e)Component.GetSuppression();
                if (CompState == swComponentSuppressionState_e.swComponentLightweight)
                {
                    swSuppressionError_e result = (swSuppressionError_e)Component.SetSuppression2((int)swComponentSuppressionState_e.swComponentResolved);
                    if (result != swSuppressionError_e.swSuppressionChangeOk)
                    {
                        return;
                    }
                }
 
                SetDocProperty(ActiveDoc, null);
                // swComponentLightweight
                int value = Component.SetSuppression2((int)swComponentSuppressionState_e.swComponentLightweight);
                Component.Select2(false, -1);
                ActiveDoc.Save();
                this.Info("保存成功");
            }
            else
            {
                SetDocProperty(ActiveDoc, null);
                int errors = 0, warnings = 0;
                ActiveDoc.Save3((int)swSaveAsOptions_e.swSaveAsOptions_AvoidRebuildOnSave, ref errors, ref warnings);
                this.Info("保存成功");
            }
        }
 
        private void SaveAsButton_Click(object sender, RoutedEventArgs e)
        {
            if (ActiveDoc == null)
            {
                return;
            }
            ModelDoc2 doc = SwApp.IActiveDoc2;
            if (!DocUtil.IsSameDoc(ActiveDoc, doc))
            {
                this.Warning("当前属性与Solidworks打开的文档不同,请先刷新!");
                return;
            }
 
            string originDocPath = ActiveDoc.GetPathName();
            string ext = Path.GetExtension(originDocPath);
 
            SaveFileDialog dlg = new SaveFileDialog
            {
                Title = "另存为",
                FileName = Path.GetFileNameWithoutExtension(originDocPath),
                DefaultExt = ext,
                Filter = $"(*{ext})|*{ext}",
                InitialDirectory = Path.GetDirectoryName(originDocPath),
            };
 
            if (dlg.ShowDialog() == true)
            {
                // 把属性写入原文件,不保存,直接另存
                SetDocProperty(ActiveDoc, null);
                ActiveDoc.SaveAs3(dlg.FileName, 0, 2);
                // 打开新文件,关闭旧文件
                ModelDoc2 docTemp = SwApp.OpenDoc(dlg.FileName, (int)swDocumentTypes_e.swDocPART) as ModelDoc2;
                docTemp.Save();
                SwApp.CloseDoc(originDocPath);
            }
        }
 
        private void DoReLoad()
        {
            try
            {
                ModelDoc2 doc = SwApp.IActiveDoc2;
                Component2 comp = null;
                if (doc != null)
                {
                    Configuration activeConfiguration = doc.GetActiveConfiguration() as Configuration;
                    if (activeConfiguration == null)
                    {
                        return;
                    }
                    comp = activeConfiguration.GetRootComponent3(false);
                }
                Dispatcher.Invoke(
                        delegate
                        {
                            ActiveDoc = doc;
                            if (doc == null)
                            {
                                ActiveDocPath = "";
                                Component = null;
                                ClearDocProperties();
                                return;
                            }
 
                            ActiveDocPath = doc.GetPathName();
                            Component = comp;
                            if (doc == LastModelDoc)
                            {
                                return;
                            }
 
                            LastModelDoc = doc;
                            ActiveDocType = doc.GetType();
                            // 这里委托
                            SwitchVisiable();
                            // 读取文件,设置参数
                            LoadDocProperties();
                        });
            }
            catch (Exception ex)
            {
                Logger.Error($"读取参数异常,文件:[{ActiveDocPath}]!", ex);
                this.Error($"读取参数异常:{ex.Message}");
            }
        }
 
        private async void Refresh_Click(object sender, RoutedEventArgs e)
        {
            MaskAdorner.ShowMask(mainPanel);
            try
            {
                await Task.Run(() =>
                {
                    DoReLoad();
                });
            }
            finally
            {
                MaskAdorner.HideMask(mainPanel);
            }
        }
 
        private void LoadComboBox_Click(object sender, RoutedEventArgs e)
        {
            LoadComboxItemSource();
        }
 
        private void PropertySettingControl_Initialized(object sender, EventArgs e)
        {
            InitPropertyData();
        }
 
        /// <summary>
        /// 激活的文档变更触发
        /// </summary>
        /// <param name="lastDoc"></param>
        /// <param name="doc"></param>
        /// <param name="comp"></param>
        public void OnSwActiveDocChange(ModelDoc2 lastDoc, ModelDoc2 doc, Component2 comp)
        {
            // 因为里面有更新UI的操作,所以委托主线程去做下面的任务
            // WPF真难用
            // 2023-09-04 把自动更新注释了
            //Dispatcher.Invoke(
            //        delegate
            //        {
            //            try
            //            {
            //                ActiveDoc = doc;
            //                ActiveDocPath = doc.GetPathName();
            //                Component = comp;
 
            //                if (doc == null)
            //                {
            //                    ClearDocProperties();
            //                    return;
            //                }
 
            //                if (doc == LastModelDoc)
            //                {
            //                    return;
            //                }
 
            //                LastModelDoc = doc;
            //                ActiveDocType = doc.GetType();
            //                // 这里委托
            //                SwitchVisiable();
            //                // 读取文件,设置参数
            //                LoadDocProperties();
 
            //                // CustomerPropertiesWrapper.GetSingle(doc, GetDocumentPropertiesViaDM.PropertyNamesOftenUsed[0], false);
            //            }
            //            catch (Exception ex)
            //            {
            //                throw new PdmException("init初始化时发生异常", ex);
            //            }
            //        });
        }
 
        public void OnSwActiveDocSaved(ModelDoc2 doc, Component2 comp)
        {
            // 读取文件,设置参数
            // LoadDocProperties();
        }
 
        public void OnCustomPropertyChange(string propName, string Configuration, string oldValue, string NewValue, int valueType)
        {
 
        }
 
        public void OnDocDestroy(ModelDoc2 doc)
        {
 
        }
 
        public void AfterDocDestroy()
        {
 
        }
 
        public void DisabledHandler()
        {
 
        }
    }
}