From 3f62d18e4361cd1d7a49c126765d95b2ad9c8246 Mon Sep 17 00:00:00 2001 From: chr <chr@mailcom> Date: 星期二, 04 三月 2025 08:42:07 +0800 Subject: [PATCH] 优化插件; --- PdmSwPlugin.PropertySetting/CommonSettingControl.xaml.cs | 249 +++++++++++++++---------------------------------- 1 files changed, 75 insertions(+), 174 deletions(-) diff --git a/PdmSwPlugin.PropertySetting/CommonSettingControl.xaml.cs b/PdmSwPlugin.PropertySetting/CommonSettingControl.xaml.cs index 2ab4104..66a7d16 100644 --- a/PdmSwPlugin.PropertySetting/CommonSettingControl.xaml.cs +++ b/PdmSwPlugin.PropertySetting/CommonSettingControl.xaml.cs @@ -25,7 +25,7 @@ using System.IO; using System.Collections.ObjectModel; using System.Runtime.InteropServices; -using System.Diagnostics; +using PdmSwPlugin.PropertySetting.Util; namespace PdmSwPlugin.PropertySetting { @@ -67,12 +67,16 @@ Dictionary<string, string> datas = properties as Dictionary<string, string>; (container as UIElement).Dispatcher.Invoke(() => { - var props = container.GetType().GetProperties().Where(prop => System.Attribute.IsDefined(prop, typeof(PropertySettingAttr))) - .ToList(); + // PropHolder.SetPropToUI(container, datas); - foreach (var prop in props) + Dictionary<PropertyInfo, PropertySettingAttr> map = PropHolder.GetAttrMap(container.GetType()); + if (map == null) { - PropertySettingAttr attr = prop.GetCustomAttribute<PropertySettingAttr>(); + return; + } + foreach (var prop in map.Keys) + { + PropertySettingAttr attr = map[prop]; if (attr == null || !attr.NeedInit) { continue; @@ -89,8 +93,32 @@ // 鍏朵粬鍐欏叆initData if (initData != null) initData[name] = value; } - prop.SetValue(container, value); + PropHolder.SetPropToUI(container, prop, value); } + + // var props = container.GetType().GetProperties().Where(prop => System.Attribute.IsDefined(prop, typeof(PropertySettingAttr))) + //.ToList(); + // foreach (var prop in props) + // { + // PropertySettingAttr attr = prop.GetCustomAttribute<PropertySettingAttr>(); + // if (attr == null || !attr.NeedInit) + // { + // continue; + // } + // string name = attr.Name; + // string value = datas.Get(name, string.Empty); + // if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(attr.defaultValue)) + // { + // value = attr.defaultValue; + // // 榛樿鍊间笉鍐欏叆initData + // } + // else + // { + // // 鍏朵粬鍐欏叆initData + // if (initData != null) initData[name] = value; + // } + // prop.SetValue(container, value); + // } }); return true; } @@ -232,6 +260,18 @@ this.SwApp = SwApp; } + public Dictionary<string, string> GetPropsWithLog(ModelDoc2 currentModelDoc, + bool needResolve, + HashSet<string> skipName, + HashSet<string> skipResolveName) + { + if (currentModelDoc == null) return null; + var start = DateTime.Now; + var data = CustomPropertyUtil.GetCustomProperties2(currentModelDoc, needResolve, skipName, skipResolveName); + Logger.Debug($"Get Props {(DateTime.Now - start).TotalMilliseconds} ms."); + return data; + } + public void InitPropertyData() { try @@ -292,7 +332,7 @@ private void UpdateActiveDoc() { - long start = DateTime.Now.Millisecond; + var start = DateTime.Now; Logger.Debug("UpdateActiveDoc Start..."); if (activeDoc != null) { @@ -309,11 +349,8 @@ activeDoc.ClearSelection2(true); } } - Logger.Debug($"UpdateActiveDoc End {activeDoc?.GetPathName()} {DateTime.Now.Millisecond - start}ms."); - start = DateTime.Now.Millisecond; - Logger.Debug("UpdateUI Start..."); + Logger.Debug($"UpdateActiveDoc End {activeDoc?.GetPathName()} {(DateTime.Now - start).TotalMilliseconds}ms."); UpdateUI(activeDoc); - Logger.Debug($"UpdateUI End {activeDoc?.GetPathName()} {DateTime.Now.Millisecond - start}ms."); } /// <summary> @@ -390,15 +427,13 @@ public void UpdateUI(ModelDoc2 doc) { + var start = DateTime.Now; + Logger.Debug("UpdateUI Start..."); AlertSaveWindow(); LastReadDoc = ReadDoc; ReadDoc = doc; - Dispatcher.Invoke(() => - { - - // LoadDocProperties(); - }); SwitchVisiable(); + Logger.Debug($"UpdateUI End {activeDoc?.GetPathName()} {(DateTime.Now - start).TotalMilliseconds}ms."); } private int Ass_UserSelectionPostNotify() @@ -433,10 +468,15 @@ /// </summary> private void SwitchVisiable() { - var start = DateTime.Now.Millisecond; + var start = DateTime.Now; Logger.Debug("SwitchVisiable Start..."); - - HashSet<string> skipName = new HashSet<string> { + + HashSet<string> skipName = new HashSet<string> + { + NameConstant.weight + }; + + HashSet<string> skipResolveName = new HashSet<string> { NameConstant.materialCode }; @@ -457,7 +497,7 @@ else if (docType == (int)swDocumentTypes_e.swDocPART) { ReadDocPath = ReadDoc.GetPathName(); - properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, skipName); + properties = GetPropsWithLog(ReadDoc, true, skipName, skipResolveName); string fileType = properties.Get(NameConstant.docType); /*if (fileType == "鍔犲伐浠�" || fileType == "妯$粍") { @@ -495,7 +535,7 @@ else { // !Equals(LastReadDoc, ReadDoc) - properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, skipName); + properties = GetPropsWithLog(ReadDoc, true, skipName, skipResolveName); string fileType = properties.Get(NameConstant.docType); /*if (fileType == "鍔犲伐浠�" || fileType == "妯$粍") { @@ -547,162 +587,13 @@ contentPanel.Children.Add(control); }); - Logger.Debug($"SwitchVisiable End {activeDoc?.GetPathName()} {DateTime.Now.Millisecond - start}ms."); - } - - /// <summary> - /// 鏍规嵁婵�娲荤殑鏂囨。绫诲瀷锛屽彉鏇村睘鎬у彲瑙� - /// </summary> - private void SwitchVisiable2() - { - HashSet<string> skipName = new HashSet<string> { - NameConstant.materialCode - }; - - IPropertyOpt last = ActiveOpter as IPropertyOpt; - string contentKey = "default"; - int? docType = ReadDoc?.GetType(); - UserControl control; - IPropertyOpt newOne; - Dictionary<string, string> properties; - if (docType == (int)swDocumentTypes_e.swDocDRAWING) - { - ReadDocPath = ReadDoc.GetPathName(); - - control = new DefaultPanel(); - newOne = control as IPropertyOpt; - newOne.SetSettings(settings); - newOne.SetProperties(null, "褰撳墠涓嶆敮鎸佸伐绋嬪浘", true, out _); - } - else if (docType == (int)swDocumentTypes_e.swDocPART) - { - ReadDocPath = ReadDoc.GetPathName(); - properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, skipName); - string fileType = properties.Get(NameConstant.docType); - /*if (fileType == "鍔犲伐浠�" || fileType == "妯$粍") - { - contentKey = "jgjPart"; - }*/ - if (BomIniterHolder.Instance.IsJgj(ReadDoc)) - { - control = new JgjPartPanel(); - } - else - { - control = new StandardPartPanel(); - } - newOne = control as IPropertyOpt; - newOne.SetSettings(settings); - newOne.SetProperties(ReadDoc, properties, true, out _); - } - else if (docType == (int)swDocumentTypes_e.swDocASSEMBLY) - { - ReadDocPath = ReadDoc.GetPathName(); - // !Equals(LastReadDoc, ReadDoc) - properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, skipName); - string fileType = properties.Get(NameConstant.docType); - /*if (fileType == "鍔犲伐浠�" || fileType == "妯$粍") - { - contentKey = "jgjPart"; - }*/ - if (BomIniterHolder.Instance.IsJgj(ReadDoc)) - { - control = new JgjModulePanel(); - } - else - { - control = new StandardModulePanel(); - } - newOne = control as IPropertyOpt; - newOne.SetSettings(settings); - newOne.SetProperties(ReadDoc, properties, true, out _); - } - else - { - control = new DefaultPanel(); - newOne = control as IPropertyOpt; - - string PathName = ReadComponent?.GetPathName(); - if (PathName == null) - { - ReadDocPath = ""; - newOne.SetSettings(settings); - newOne.SetProperties(ReadDoc, "璇锋墦寮�涓�涓枃妗�", true, out _); - } - else - { - ReadDocPath = PathName; - string name = Path.GetFileNameWithoutExtension(PathName); - newOne.SetSettings(settings); - newOne.SetProperties(ReadDoc, $"銆恵name}銆戞湭鎵惧埌鏂囨。锛岃妫�鏌ユ槸鍚﹁鍘嬬缉鎴栬交閲忓寲", true, out _); - } - } - if (last != null) - { - last.UpdateProperty -= Jgj_SinglePropertyChanged; - last = null; - } - ActiveOpter = control; - contentPanel.Children.Clear(); - newOne.UpdateProperty += Jgj_SinglePropertyChanged; - contentPanel.Children.Add(control); - } - - /// <summary> - /// 浠庢縺娲荤殑鏂囨。涓鍙栧弬鏁� - /// </summary> - private void LoadDocProperties() - { - IPropertyOpt opt = ActiveOpter as IPropertyOpt; - string ErrMsg = null; - if (ReadDoc == null) - { - string PathName = ReadComponent?.GetPathName(); - if (PathName == null) - { - ReadDocPath = ""; - opt.SetProperties(ReadDoc, "璇锋墦寮�涓�涓枃妗�", true, out ErrMsg); - return; - } - ReadDocPath = PathName; - string name = Path.GetFileNameWithoutExtension(PathName); - opt.SetProperties(ReadDoc, $"銆恵name}銆戞湭鎵惧埌鏂囨。锛岃妫�鏌ユ槸鍚﹁鍘嬬缉鎴栬交閲忓寲", true, out ErrMsg); - return; - } - int docType = ReadDoc.GetType(); - ReadDocPath = ReadDoc.GetPathName(); - if (docType == (int)swDocumentTypes_e.swDocDRAWING) - { - opt.SetProperties(null, "褰撳墠涓嶆敮鎸佸伐绋嬪浘", true, out ErrMsg); - return; - } - HashSet<string> skipName = new HashSet<string> { - NameConstant.materialCode - }; - Dictionary<string, string> properties = CustomPropertyUtil.GetCustomProperties2(ReadDoc, true, skipName); - opt.SetProperties(ReadDoc, properties, !Equals(LastReadDoc, ReadDoc), out ErrMsg); - } - - private void ClearDocProperties() - { - IPropertyOpt opt = ActiveOpter as IPropertyOpt; - opt.ClearAllProperties(out string ErrMsg); - } - - /// <summary> - /// 灏嗗睘鎬ц缃繘鏂囨。锛屾敞鎰忥紝骞舵病鏈変繚瀛� - /// </summary> - /// <param name="doc">鏂囨。</param> - private void SetDocProperty(ModelDoc2 doc, Dictionary<string, string> props) - { - CustomPropertyUtil.SetCustomProperties(doc, props); + Logger.Debug($"SwitchVisiable End {activeDoc?.GetPathName()} {(DateTime.Now - start).TotalMilliseconds}ms."); } public void SetSwApp(SldWorks SwApp) { this.SwApp = SwApp; } - private void SaveDoc(bool qiaoqiaode) { @@ -735,6 +626,8 @@ public void RefreshData() { MaskAdorner.ShowMask(content, "灞炴�у姞杞戒腑锛岃绋嶅��..."); + var start = DateTime.Now; + Logger.Debug($"Refresh [{ReadDocPath}] Data start."); Task.Run(() => { try @@ -754,6 +647,7 @@ finally { MaskAdorner.HideMask(content); + Logger.Debug($"Refresh [{ReadDocPath}] Data end {(DateTime.Now - start).TotalMilliseconds}ms."); } }); } @@ -792,7 +686,6 @@ /// <param name="comp"></param> public void OnSwActiveDocChange(ModelDoc2 lastDoc, ModelDoc2 doc, Component2 comp) { - // CurrentChanged(); RefreshData(); } @@ -835,7 +728,7 @@ /// </summary> public void AlertSaveWindow() { - var start = DateTime.Now.Millisecond; + var start = DateTime.Now; Logger.Debug("AlertSaveWindow Start..."); IPropertyOpt opt = ActiveOpter as IPropertyOpt; if (opt != null && opt.GetDocChanged()) @@ -859,7 +752,7 @@ opt.ResetProperty(out string errMsg); } } - Logger.Debug($"AlertSaveWindow End {activeDoc?.GetPathName()} {DateTime.Now.Millisecond - start}ms."); + Logger.Debug($"AlertSaveWindow End {activeDoc?.GetPathName()} {(DateTime.Now - start).TotalMilliseconds}ms."); } public void OnTabControlSelectionChange(object sender, SelectionChangedEventArgs e) @@ -893,5 +786,13 @@ this.Error($"{ex.Message}"); } } + + public void DisabledHandler() + { + if (activeDoc != null) + { + DetachDocNotify(activeDoc); + } + } } } -- Gitblit v1.9.1