From bd4063346c3e59bf9d0f6911ea6b049c4fbdc1ef Mon Sep 17 00:00:00 2001 From: lihanbo Date: Tue, 17 Dec 2024 15:10:32 +0800 Subject: [PATCH] =?UTF-8?q?105040=20Update=20=E4=BC=98=E5=8C=96=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E7=BA=BF=E6=A3=80=E6=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModel/LayoutHelperViewModel.cs | 145 +++++++++++++++--- 1 file changed, 123 insertions(+), 22 deletions(-) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs index 7b98b6e..51f99d0 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LayoutHelperViewModel.cs @@ -1,4 +1,6 @@ -using EPLAN.Harness.API.Occurrences; +using EPLAN.Harness.API; +using EPLAN.Harness.API.ApiProperties; +using EPLAN.Harness.API.Occurrences; using EPLAN.Harness.Common.Extensions; using EPLAN.Harness.Core; using EPLAN.Harness.Core.Controls; @@ -28,6 +30,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel private List _motorIds; private MotorModel _motor; private CableLectotypeViewModel cableLectotypeViewModel; + private HpdApi api; public MotorModel Motor { get => _motor; @@ -39,12 +42,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } public LayoutHelperViewModel() { - + api = HpdApi.GetInstance(); + api.Init(); } public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List motorIds) { _currentFlexDesigner = currentFlexDesigner; _motorIds = motorIds; + + api = HpdApi.GetInstance(); + api.Init(); } public string SelectMotorModel { @@ -61,13 +68,22 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { get { - if (_selectLineId == null) return ""; - var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId); - if (part != null) + try { - return part.Parents?.First()?.LibraryName; + + + if (_selectLineId == null) return ""; + var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId); + if (part != null) + { + return part.Parents?.FirstOrDefault()?.LibraryName; + } + else + { + return ""; + } } - else + catch (Exception) { return ""; } @@ -208,8 +224,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel SelectedLines = cableLectotypeViewModel.SelectedLines; SelectedLine = SelectedLines[CurrentMotorSelectLineIndex]; ReSetSubLines(); - Motor = cableLectotypeViewModel.Motor; - + Motor = cableLectotypeViewModel.Motor; return; } } @@ -238,7 +253,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } else { - CurrentMotorSelectLineIndex--; SelectedLine = SelectedLines[CurrentMotorSelectLineIndex]; ReSetSubLines(); @@ -250,7 +264,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel { if (HasNext) { - if (CheckAndSetSelLine()) + var canNext = CheckSelLine(); + + + if (canNext) { if (CurrentMotorSelectLineIndex >= SelectedLines.Count - 1) @@ -268,22 +285,77 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } } - private bool CheckAndSetSelLine() + private bool CheckSelLine() { - var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId); - if (part != null) + try { - if (part.Properties.Any(it => it.ValueHolder.StrVal == "轴号")) return true; - var prop = new EPLAN.Harness.Core.Props.Property(new PropDef { Name = "轴号" }); - prop.Set(SelectedLine.AxisNo); - part.Properties.Add(prop); - return true; + var parts = _currentFlexDesigner.SelectSet; + foreach (var part in parts) + { + if (part != null) + { + // 如果选中的是导线,则直接使用,如果选中的是绝缘层,则使用绝缘层,其他情况使用父级 + var linePart = part is OccCableForked ? + part as OccCableForked + : part is OccCablesInsulatorGraph ? + part + : part.Parents?.FirstOrDefault() as OccCableForked; + + if (linePart != null) + { + var libName = linePart?.LibraryName; + // 绝缘层选择上一层的导线来获取信息 + if(part is OccCablesInsulatorGraph) + { + libName = (part.Parents?.First() as OccCableForked).LibraryName; + //partLineModel = (part.Parents?.First() as OccCableForked).LibraryName.Split('&')[1]; + } + var partLineModel = (libName.Contains("&") ? libName.Split('&')[1] : libName).Trim(' '); + if (SubLines.Any(it => it.CableModel == partLineModel)) + { + var subLine = SubLines.FirstOrDefault(it => it.CableModel == partLineModel); + var imprint = ""; + // 导线需要取绝缘层的印记信息,导线本身没有印记 + if(part is OccCableForked) + { + var insulatorGraph = part.Children.FirstOrDefault(); + imprint = insulatorGraph.Properties.FirstOrDefault(it => it.PropertyName == "Imprint")?.ValueHolder.StrVal; + } + else + { + imprint = (linePart as OccCablesInsulatorGraph).Imprint;//Properties.FirstOrDefault(it => it.PropertyName == "Imprint")?.ValueHolder.StrVal; + } + if (string.IsNullOrEmpty(imprint)) + { + FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写"); + return false; + } + if ($"{SelectedLine.AxisNo}-{SelectedLine.CurrentLine}" == imprint) + { + subLine.IsChecked = true; + //cableLectotypeViewModel.SaveToDb(); + SetSubLineAndSave(subLine.CableModel); + return SubLines.All(it => it.IsChecked); + } + else + { + FlexMessageBox.Warning($"当前选中的线 {libName} 印记与推荐中的线印记不一致"); + return false; + } + } + } + } + FlexMessageBox.Warning($"当前选中的线不是推荐中的线型号"); + return false; + } } - else + catch (Exception) { - FlexMessageBox.Warning("当前选中的线不是推荐中的线"); + FlexMessageBox.Warning("抓取线信息异常"); return false; } + FlexMessageBox.Warning("请选择正确的线"); + return false; } internal void ToPrevMotor() @@ -305,8 +377,37 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel } } internal void ReSetSubLines() - { + { SubLines = SelectedLine.SubLines.Distinct(it => it.CableModel).ToList(); } + + internal void SetSubLineAndSave(string cableModel) + { + foreach (var it in cableLectotypeViewModel.SelectedLines) + { + if (it.AxisNo == SelectedLine.AxisNo && it.CurrentLine == SelectedLine.CurrentLine) + { + foreach (var line in it.SubLines) + { + if (cableModel == line.CableModel) + { + line.IsChecked = true; + line.OnPropertyChanged(nameof(line.IsChecked)); // Ensure property change is notified + } + } + } + } + SaveToDb(cableLectotypeViewModel); + } + + public bool SaveToDb(CableLectotypeViewModel cableLectotypeViewModel) + { + var id = cableLectotypeViewModel.Motor.OccPartId; + var json = Newtonsoft.Json.JsonConvert.SerializeObject(cableLectotypeViewModel); + var service = new MotorLectotypeService(); + return service.SaveMotorLectotypeData(id, json); + } } + + }