From cde4bc41deed164cbfa410c6069b7cc6face1bba Mon Sep 17 00:00:00 2001 From: lihanbo Date: Fri, 28 Mar 2025 16:49:31 +0800 Subject: [PATCH] =?UTF-8?q?105040=20Update=20=E5=A2=9E=E5=8A=A0=E6=B1=87?= =?UTF-8?q?=E5=B7=9D=E7=94=B5=E6=9C=BA=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=A4=9A=E5=93=81=E7=89=8C=E8=AF=86=E5=88=AB=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Datas/BrandData.cs | 39 +++++++++ Sinvo.EplanHpD.Plugin.WPFUI/Datas/Brands.cs | 58 +++++++++++++ .../Models/LectotypeLineModel.cs | 81 +------------------ .../View/LectotypeWindow.xaml | 2 +- .../View/LectotypeWindow.xaml.cs | 6 +- .../ViewModel/CableLectotypeViewModel.cs | 11 ++- .../ViewModel/LectotypeViewModel.cs | 73 ++++++++++++++--- 7 files changed, 170 insertions(+), 100 deletions(-) create mode 100644 Sinvo.EplanHpD.Plugin.WPFUI/Datas/BrandData.cs diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Datas/BrandData.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Datas/BrandData.cs new file mode 100644 index 0000000..e8dc3c8 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Datas/BrandData.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Datas +{ + public class BrandData + { + /// + /// 品牌名称 + /// + public string Name { get; set; } + /// + /// 是否使用复合线 + /// + public bool ComplexLine { get; set; } + /// + /// 使用的数据表 + /// + public string SheetName { get; set; } + + /// + /// 型号前缀 + /// + public string Prefix { get; set; } + /// + /// 电机型号前缀 + /// + public string MotorPrefix { get; set; } + + + /// + /// 型号后缀 + /// + public string Suffix { get; set; } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Datas/Brands.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Datas/Brands.cs index eb8100b..bf2cfb1 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Datas/Brands.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Datas/Brands.cs @@ -13,7 +13,65 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Datas { public const string UNKNOWN = "未知"; public const string ANCHUAN = "安川"; + public const string HUICHUAN = "汇川"; public const string SANLING = "三菱"; public const string SANLING_HK_KT = "HK-KT"; + + + public static BrandData GetBrandData(string brandName) + { + if(!BrandDataList.ContainsKey(brandName)) + { + return null; + } + return BrandDataList[brandName]; + } + /// + /// + /// + public static Dictionary BrandDataList = new Dictionary + { + /* + string ModelNo = "MR-"; + if (model.Motor.Brand == Brands.ANCHUAN) + { + ModelNo = "JZSP-"; + } + else if((model.Motor.Brand == Brands.HUICHUAN)) + { + ModelNo = "S6-L-"; + } + */ + {ANCHUAN, + new BrandData{ + Name = ANCHUAN, + ComplexLine = false, + SheetName = ANCHUAN, + Prefix = "JZSP-", + MotorPrefix = "SGMX", + Suffix = "-E" + } + }, + {HUICHUAN, + new BrandData{ + Name = HUICHUAN, + ComplexLine = false, + SheetName = HUICHUAN, + Prefix = "S6-L-", + MotorPrefix = "MS1H", + Suffix = "" + } + }, + {SANLING_HK_KT, + new BrandData{ + Name = SANLING_HK_KT, + ComplexLine = true, + SheetName = SANLING_HK_KT, + Prefix = "MR-", + MotorPrefix = "HK-KT", + Suffix = "" + } + }, + }; } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs index 49bf5d0..d0706fd 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs @@ -293,83 +293,8 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models { get { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - DrawingNo = ""; - if (Motor == null) - { - return ""; - } - string ModelNo = "MR-"; - if(Motor.Brand == Brands.ANCHUAN) - { - ModelNo = "JZSP-"; - } - var cableFlag = GetCableModelFlag(Motor?.MotorPower, CableType, CableConnectionClass, IsFlexibility); - if (string.IsNullOrWhiteSpace(cableFlag)) - { - - return ""; - } - else - { - ModelNo += cableFlag + "-"; - } - //编码器线+动力线 编码器线+动力刹车线 - if (CableType is "编码器线+动力线" or "编码器线+动力刹车线") // 组合线 - ModelNo += "A1-"; - - if (IsFlexibility) - { - ModelNo += "H-"; - } - else - { - ModelNo += "L-"; - - } - if (IsComplexLine) - { - ModelNo += $"{EncoderLineLength}-{PowerLineLength}"; - } - else if (IsEncoderLine) - { - ModelNo += $"{EncoderLineLength}"; - } - else if (IsPowerLine) - { - ModelNo += $"{PowerLineLength}"; - - } - else - { - ModelNo += $"{PowerLineLength}"; - - } - if (!string.IsNullOrEmpty(AxisNo)) - { - if(Motor.Brand == Brands.SANLING_HK_KT) - { - - ModelNo += "("; - } - if(Motor.Brand == Brands.ANCHUAN) - { - ModelNo += "-E("; - } - ModelNo += $"{AxisNo}"; - if (CableConnectionClass != "直通") - //if (!(CableType is "编码器线+动力线" or "编码器线+动力刹车线")) - ModelNo += $"-{CurrentLine}/{LineCount}"; - ModelNo += ")/定制"; - } - //if (isUpdateDrawNo) - { - DrawingNo = GetCableDrawNo(); - } - stopwatch.Stop(); - Debug.Print($"CableModelNo {ModelNo} : {stopwatch.ElapsedMilliseconds}ms"); - return ModelNo; + return this.GenCableModelNo(); + //return ModelNo; } set { @@ -401,7 +326,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models return ""; } } - private string GetCableModelFlag(string motorPower, string cableType, string cableConnectionType, bool isFlexibility) + public string GetCableModelFlag(string motorPower, string cableType, string cableConnectionType, bool isFlexibility) { var data = MotorExcelHelper.Instance.GetCableDatas(Motor.Brand); //var data = Core.CoreService.GetService().GetCableDatas(); diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml index 95f1e80..73884a3 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml @@ -238,7 +238,7 @@ - + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs index b594238..db25b18 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/LectotypeWindow.xaml.cs @@ -159,12 +159,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI FlexMessageBox.ShowText(FlexMessageBox.Type.INFO, "未获取到线材名称"); } else - { - + { ViewModel.ToSource(cableName); } - - //} + } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs index 8e2387c..9b75e05 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs @@ -98,8 +98,11 @@ public class CableLectotypeViewModel : INotifyPropertyChanged // WPFUISession.Instance.snackbarService.Show("相同轴号已经添加过数据,禁止重复添加!", "请检查是否添加错误", appearance: ControlAppearance.Danger, timeout: TimeSpan.FromSeconds(3)); // return; //} + + var brandData = Brands.GetBrandData(Motor.Brand); + // 安川第一条线不合并,所以需要再次添加另一个类型的线 - if (Motor.Brand == Brands.ANCHUAN) + if (!brandData.ComplexLine) { var motorPower = MotorExcelHelper.Instance.GetMotorPower(Motor.MotorModelStr); // 功率750W以下的电机,不需要前段线 @@ -160,7 +163,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged LectotypeList.Add(line); } - for (global::System.Int32 i = startIndex; i <= PowerLineParagraph; i++) + for (var i = startIndex; i <= PowerLineParagraph; i++) { //seqNo++; var cableConnectionType = "中段"; @@ -195,7 +198,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged powerLine.SubLines = GetSubLines(powerLine.DrawingNo); LectotypeList.Add(powerLine); } - for (global::System.Int32 i = startIndex; i <= EncoderLineParagraph; i++) + for (var i = startIndex; i <= EncoderLineParagraph; i++) { //seqNo++; var cableConnectionType = "中段"; @@ -408,7 +411,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged _cableConnectionType = value; OnPropertyChanged(nameof(CableConnectionType)); - IsEnableParagraph = !(_cableConnectionType == ConnectionType.Passthrough); + IsEnableParagraph = _cableConnectionType != ConnectionType.Passthrough; PowerLineParagraph = 0; EncoderLineParagraph = 0; if (!IsEnableParagraph) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs index 98aa20e..90c6c03 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs @@ -7,6 +7,7 @@ using EPLAN.Harness.ProjectCore.Occurrences; using EPLAN.Harness.ProjectCore.Occurrences.Designer; using HandyControl.Tools.Extension; using Sinvo.EplanHpD.Plugin.Service; +using Sinvo.EplanHpD.Plugin.Service.Model; using Sinvo.EplanHpD.Plugin.WPFUI.Datas; using Sinvo.EplanHpD.Plugin.WPFUI.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Models; @@ -209,6 +210,7 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged var isPowerLine = GetLineType(occCable.LibraryName,"动力线"); var isBrakePowerLine = GetLineType(occCable.LibraryName,"动力刹车线"); var isBrakeLine = GetLineType(occCable.LibraryName,"刹车线"); + //GetLineType(occCable,"刹车线"); var encoderLength = 0d; var powerLength = 0d; @@ -303,12 +305,12 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged if (axisNo != null && cabType != null) { //lineCount = cables.Count(cable => cable.AxisNo == axisNo && cable.CableType == cabType); - if(it.Motor != null) + if (it.Motor != null) { // 有电机信息时,取电机型号对应的线数 lineCount = service.GetLineCount(it.Motor.MotorUniqueFlag, cabType); } - if(lineCount == -1 || it.Motor == null) + if (lineCount == -1 || it.Motor == null) { // 无电机信息时,取轴号对应的线数 lineCount = cables.Count(cable => cable.AxisNo == axisNo && cable.CableType == cabType); @@ -324,6 +326,46 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged it.CableConnectionClass = "直通"; } } + //CableLectotype lecData = null; + try + { + if (it.Motor != null) + { + var lecData = service.GetCableLectotypeData(it.Motor.MotorUniqueFlag); + if (lecData != null) + { + var linesData = service.GetLectotypeLines(lecData?.CableLectotypeId); + if (linesData != null && linesData.Any()) + { + var line = linesData.FirstOrDefault(line => + line.MotorUniqueFlag == it.Motor.MotorUniqueFlag + && line.CableType == it.CableType + && line.CurrentLine == it.CurrentLine + ); + if (line != null) + { + it.CableConnectionClass = line.CableConnectionClass; + } + else + { + it.IsError = true; + it.IsChecked = true; + it.ErrorCount += 1; + it.CheckedMsg += "选型数据中不存在该线材类型!"; + } + } + } + + + } + } + catch (Exception) + { + it.CableConnectionClass = ""; + } + + + if (string.IsNullOrEmpty(it.CableConnectionClass)) { if (it.CurrentLine == 1 && it.CurrentLine != lineCount) @@ -371,7 +413,8 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged //2 合并同轴号的第一条数据 cables.Where(it => it.CurrentLine == 1).ForEach(it => { - if (it.Motor?.Brand != Brands.ANCHUAN) + var brandData = Brands.GetBrandData(it.Motor.Brand); + if (brandData.ComplexLine) { var existLine = datas.FirstOrDefault(data => data.AxisNo == it.AxisNo && data.CurrentLine == 1); @@ -599,6 +642,7 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged .Where(occ => (occ.Name?.StartsWith("HK-KT") ?? false) || (occ.Name?.StartsWith("SGMX") ?? false) + || (occ.Name?.StartsWith("MS1H") ?? false) ) .ToList(); var motorPowerDatas = MotorExcelHelper.Instance.GetMotorPowers(); @@ -635,7 +679,8 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged if (parent.Type == OCC_TYPE.wPART) { if ((parent.Name?.StartsWith("HK-KT") ?? false) - || (parent.Name?.StartsWith("SGMX") ?? false)) + || (parent.Name?.StartsWith("SGMX") ?? false) + || (parent.Name?.StartsWith("MS1H") ?? false)) { canAdd = false; } @@ -656,15 +701,17 @@ public class LectotypeViewModel(string docId) : INotifyPropertyChanged /// private string GetMotorBrand(string motorName) { - switch (motorName) - { - case string name when name.StartsWith("HK-KT"): - return Brands.SANLING_HK_KT; - case string name when name.StartsWith("SGMX"): - return Brands.ANCHUAN; - default: - return Brands.UNKNOWN; - } + //switch (motorName) + //{ + // case string name when name.StartsWith("HK-KT"): + // return Brands.SANLING_HK_KT; + // case string name when name.StartsWith("SGMX"): + // return Brands.ANCHUAN; + // default: + // return Brands.UNKNOWN; + //} + var brandData = Brands.BrandDataList.Where(it => motorName.StartsWith(it.Value.MotorPrefix)).FirstOrDefault(); + return brandData.Value.Name; } /// /// 去除电机型号中的多余信息