diff --git a/Sinvo.EplanHpD.Plugin.Test/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin.Test/Properties/AssemblyInfo.cs index 493805c..7f214ee 100644 --- a/Sinvo.EplanHpD.Plugin.Test/Properties/AssemblyInfo.cs +++ b/Sinvo.EplanHpD.Plugin.Test/Properties/AssemblyInfo.cs @@ -16,5 +16,5 @@ using System.Runtime.InteropServices; [assembly: Guid("aec39474-528b-4da8-b650-99189acb7a2c")] // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.18")] -[assembly: AssemblyFileVersion("1.0.0.18")] +[assembly: AssemblyVersion("1.0.0.19")] +[assembly: AssemblyFileVersion("1.0.0.19")] diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Commands/UICommand.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Commands/UICommand.cs deleted file mode 100644 index 602ba99..0000000 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Commands/UICommand.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Windows.Input; - -namespace Sinvo.EplanHpD.Plugin.WPFUI.Commands -{ - public class UICommand : ICommand - { - private readonly Action _execute; - private readonly Func _canExecute; - public event EventHandler CanExecuteChanged; - - public bool CanExecute(object parameter) - { - return _canExecute != null || _canExecute(parameter); - } - - public void Execute(object parameter) - { - _execute.Invoke(parameter); - } - } -} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs index 2128120..d89d6e7 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LectotypeLineModel.cs @@ -26,8 +26,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models } } - - public int SeqNo; + private int _seqNo; + public int SeqNo + { + get => _seqNo; + set + { + _seqNo = value; + OnPropertyChanged(nameof(SeqNo)); + } + } public bool IsComplexLine; @@ -94,6 +102,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models { _drawingNo = value; OnPropertyChanged(nameof(DrawingNo)); + if (IsLectotype) + { + SubLines = GetSubLines(DrawingNo); + } } } @@ -159,6 +171,11 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models _isFlexibility = value; OnPropertyChanged(nameof(IsFlexibility)); OnPropertyChanged(nameof(CableModelNo)); + if (IsLectotype) + { + var drawNo = CableModelNo; + SubLines = GetSubLines(DrawingNo); + } } } @@ -342,7 +359,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models /// 获取线对应图纸编号 /// /// - private string GetCableDrawNo() + public string GetCableDrawNo() { var data = MotorExcelHelper.Instance.GetCableDatas(); //var data = Core.CoreService.GetService().GetCableDatas(); @@ -401,5 +418,40 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models OnPropertyChanged(nameof(SubLines)); } } + private string _cableModel; + public string CableModel + { + get => _cableModel; + set + { + _cableModel = value; + OnPropertyChanged(nameof(CableModel)); + } + } + public bool IsLectotype = false; + + private bool _isComplete; + public bool IsComplete + { + get => _isComplete; + set + { + _isComplete = value; + OnPropertyChanged(nameof(IsComplete)); + } + } + + private List GetSubLines(string drawingNo) + { + return MotorExcelHelper.Instance.GetBomList(drawingNo).Where(it => + { + return it.Name == "编码器线" || it.Name == "动力线"; + }).Select(it => new LectotypeLineModel + { + SeqNo = 0, + CableModel = it.Spec, + CableType = it.Name + }).ToList(); + } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs index 0829f69..eb1e300 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/MotorModel.cs @@ -53,7 +53,7 @@ } } /// - /// 电机系列 + /// 电机型号 /// private string _motorModel; /// diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs index ea8f16a..a6e5709 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Properties/AssemblyInfo.cs @@ -46,6 +46,6 @@ using System.Windows; // 生成号 // 修订号 // -[assembly: AssemblyVersion("1.0.0.18")] -[assembly: AssemblyFileVersion("1.0.0.18")] -[assembly: AssemblyInformationalVersion("1.0.0.18")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.0.19")] +[assembly: AssemblyFileVersion("1.0.0.19")] +[assembly: AssemblyInformationalVersion("1.0.0.19")] \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj index c5e6ac8..2103e6f 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {2DBCD22A-650D-4797-9908-9C4D5D6665FE} - Exe + Library Sinvo.EplanHpD.Plugin.WPFUI Sinvo.EplanHpD.Plugin.WPFUI v4.8.1 @@ -56,7 +56,8 @@ true - Sinvo.EplanHpD.Plugin.WPFUI.TestWindow + + true @@ -131,9 +132,9 @@ + - @@ -153,6 +154,8 @@ + + @@ -165,6 +168,7 @@ + @@ -247,6 +251,7 @@ + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs index 7e8c9a8..9f2f585 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/TestWindow.xaml.cs @@ -40,7 +40,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI [STAThread] public static void Main() { - var window = new CableLectotypeWindow(); + var window = new CableLectotypeWindow(new Models.MotorModel + { + AxisNo = "MRJ001", + MotorPower = "1000W(220V)", + MotorModelStr = "HK-KT103WJK", + MotorSerie = "HK-KT" + }); window.ShowDialog(); } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionType.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionType.cs new file mode 100644 index 0000000..8a03677 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +{ + public enum ConnectionType + { + [Description("直通")] + Passthrough, + [Description("全段")] + FullParagraph + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionTypeConverter.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionTypeConverter.cs new file mode 100644 index 0000000..340e613 --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/ConnectionTypeConverter.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils +{ + public class ConnectionTypeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var flag = (ConnectionType)value; + if (!Enum.IsDefined(typeof(ConnectionType), flag)) + { + return false; + } + return flag == (ConnectionType)parameter; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not bool isChecked) + { + throw new InvalidOperationException("The value must be a bool"); + } + + return isChecked ? (ConnectionType)parameter : Binding.DoNothing; + } + } +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs index a81c32b..f4418cc 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/Consts.cs @@ -22,5 +22,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils /// 变色套平方规格匹配 /// public static readonly Regex dRegex = new("V-[\\d]+\\.?[\\d]*", RegexOptions.Compiled); + + public static readonly Regex regexParenthesesContent = new(@"(?<=\()[^)]*(?=\))", RegexOptions.Compiled); } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs index 3d6474c..50431d0 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs @@ -12,7 +12,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public static MotorExcelHelper Instance = new(); private Stream dataFileStream; - public const string DATA_FILE_PATH = @"\\192.168.1.160\plm系统文档\线材选型";//@"\\192.168.1.160\plm系统文档\线材选型"; + public const string DATA_FILE_PATH = @"D:\旧电脑文件\Desktop\EPlan\线材选型";//@"\\192.168.1.160\plm系统文档\线材选型"; private const string DATA_FILE_NAME = "线材选型数据表.xlsx"; private const string DATA_FILE_NAME_BOM = "BOM表.xlsx"; private const string TEMPLATE_FILE_NAME = "下单定制线模板.xlsx"; @@ -28,7 +28,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils public List GetCableDatas() { if (dataFileStream == null) return null; - //var filePath = "D:\\Desktop\\Data\\三菱伺服HK-KT线材选型BOM表_按程序格式整理后.xlsx"; + //var filePath = "D:\\旧电脑文件\\Desktop\\Data\\三菱伺服HK-KT线材选型BOM表_按程序格式整理后.xlsx"; var data = MiniExcel.Query(dataFileStream, "HK-KT").ToList(); //MiniExcel.Query() return data; diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs new file mode 100644 index 0000000..d32fcab --- /dev/null +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/CableLectotypeViewModel.cs @@ -0,0 +1,322 @@ +using HandyControl.Controls; +using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Security.Cryptography.X509Certificates; +using System.Windows.Shapes; + +namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; + +public class CableLectotypeViewModel : INotifyPropertyChanged +{ + private const string MESSAGE_KEY = "CableLectotypeMessage"; + + /// + /// 生成线列表 + /// + public void Cablerator() + { + if (EncoderLineParagraph == 0 || PowerLineParagraph == 0) + { + ShowError("段数不能为零!"); + return; + } + + if (string.IsNullOrEmpty(AxisNo)) + { + ShowError("轴号不能为空!"); + return; + } + if (string.IsNullOrEmpty(CableType)) + { + ShowError("请选择线材类型!"); + return; + } + int seqNo = 1; + var LectotypeList = new List(); + var line = new LectotypeLineModel + { + SeqNo = seqNo, + //MechanicalNo = MechanicalNo, + //MechanicalName = MechanicalName, + AxisNo = AxisNo, + //MotorSerie = MotorSerie, + //MotorPower = Motor.MotorPower, + //DriverInterface = DriverInterface, + //DriverModel = DriverModel, + CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通", + CableType = CableType, + //IsFlexibility = IsFlexibility, + //PowerLineLength = PowerLineLength, + //EncoderLineLength = EncoderLineLength, + //PowerBrakeLineLength = PowerBrakeLineLength, + //DrawingNo = LineModelStr, + CableModelNo = CableModelStr, + //LineCount = Math.Max(PowerLineCount, EncoderLineCount), + //CurrentLineNumber = 1, + //BomList = GenBomListByCurrent(DrawingNo) + IsLectotype = true, + CurrentLine = 1, + Motor = Motor + }; + line.DrawingNo = line.GetCableDrawNo(); + line.SubLines = GetSubLines(line.DrawingNo); + + if (CableConnectionType == ConnectionType.FullParagraph) + { + LectotypeList.Clear(); + //if (SelectedLines.Any(it => it.AxisNo == AxisNo)) + //{ + // WPFUISession.Instance.snackbarService.Show("相同轴号已经添加过数据,禁止重复添加!", "请检查是否添加错误", appearance: ControlAppearance.Danger, timeout: TimeSpan.FromSeconds(3)); + // return; + //} + // 第一条线为所选线 + LectotypeList.Add(line); + for (global::System.Int32 i = 2; i <= PowerLineParagraph; i++) + { + seqNo++; + var cableConnectionType = "中段"; + if (i >= PowerLineParagraph) + { + cableConnectionType = "尾段"; + } + var powerLine = new LectotypeLineModel + { + SeqNo = seqNo, + //MechanicalNo = MechanicalNo, + //MechanicalName = MechanicalName, + AxisNo = AxisNo, + //MotorSerie = MotorSerie, + //MotorPower = MotorPower, + //DriverInterface = DriverInterface, + //DriverModel = DriverModel, + //PowerBrakeLineLength = PowerBrakeLineLength, + //DrawingNo = DrawingNo, + //CableModelNo = CableModelNo, + CableConnectionClass = cableConnectionType, + CableType = "动力线", + LineCount = PowerLineParagraph, + //PowerLineLength = PowerLineLength, + //CurrentLineNumber = i, + CurrentLine = i, + Motor = Motor, + IsLectotype = true + + //CableFlag = GetCableModelFlag(MotorPower, PowerLineName, cableConnectionType, false) + }; + powerLine.DrawingNo = powerLine.GetCableDrawNo(); + powerLine.SubLines = GetSubLines(powerLine.DrawingNo); + LectotypeList.Add(powerLine); + } + for (global::System.Int32 i = 2; i <= EncoderLineParagraph; i++) + { + seqNo++; + var cableConnectionType = "中段"; + if (i >= EncoderLineParagraph) + { + cableConnectionType = "尾段"; + } + var encoderLine = new LectotypeLineModel + { + SeqNo = seqNo, + //MechanicalNo = MechanicalNo, + //MechanicalName = MechanicalName, + AxisNo = AxisNo, + //MotorSerie = MotorSerie, + //MotorPower = MotorPower, + //DriverInterface = DriverInterface, + //DriverModel = DriverModel, + //PowerBrakeLineLength = PowerBrakeLineLength, + //DrawingNo = DrawingNo, + //CableModelNo = CableModelNo, + CableConnectionClass = cableConnectionType, + CableType = "编码器线", + LineCount = EncoderLineParagraph, + //PowerLineLength = PowerLineLength, + //CurrentLineNumber = i, + CurrentLine = i, + //CableFlag = GetCableModelFlag(MotorPower, PowerLineName, cableConnectionType, false) + Motor = Motor, + IsLectotype = true + }; + encoderLine.DrawingNo = encoderLine.GetCableDrawNo(); + encoderLine.SubLines = GetSubLines(encoderLine.DrawingNo); + LectotypeList.Add(encoderLine); + } + } + else + { + LectotypeList.Add(line); + } + SelectedLines = LectotypeList; + } + + private List GetSubLines(string drawingNo) + { + return MotorExcelHelper.Instance.GetBomList(drawingNo).Where(it => + { + return it.Name == "编码器线" || it.Name == "动力线"; + }).Select(it => new LectotypeLineModel + { + SeqNo = 0, + CableModel = it.Spec, + CableType = it.Name + }).ToList(); + } + private void ShowError(string msg) + { + Growl.Error(msg, MESSAGE_KEY); + } + #region Props + + public List CableTypes + { + get + { + return [ + new ConfigItemModel{ + ItemName = "编码器线+动力线", + ItemValue = "编码器线+动力线" + }, + new ConfigItemModel{ + ItemName = "编码器线+动力刹车线", + ItemValue = "编码器线+动力刹车线" + }, + ]; + } + set + { + OnPropertyChanged(nameof(CableTypes)); + } + } + + private List _selectedLines = []; + public List SelectedLines + { + get => _selectedLines; + set + { + _selectedLines = value; + OnPropertyChanged(nameof(SelectedLines)); + } + } + + public CableLectotypeViewModel(MotorModel motor) + { + Motor = motor; + if (motor != null && !string.IsNullOrEmpty(motor.AxisNo)) + { + AxisNo = motor.AxisNo; + } + } + private MotorModel _motor; + public MotorModel Motor + { + get { return _motor; } + set + { + _motor = value; + OnPropertyChanged(nameof(Motor)); + } + } + + private ConnectionType _cableConnectionType = ConnectionType.FullParagraph; + + public ConnectionType CableConnectionType + { + get { return _cableConnectionType; } + set + { + _cableConnectionType = value; + OnPropertyChanged(nameof(CableConnectionType)); + + if (_cableConnectionType == ConnectionType.Passthrough) + { + IsEnableParagraph = false; + PowerLineParagraph = 1; + EncoderLineParagraph = 1; + } + else + { + IsEnableParagraph = true; + PowerLineParagraph = 3; + EncoderLineParagraph = 3; + } + } + } + + private string _axison; + public string AxisNo + { + get { return _axison; } + set + { + _axison = value; + OnPropertyChanged(nameof(AxisNo)); + } + } + private string _cableType; + public string CableType + { + get { return _cableType; } + set + { + _cableType = value; + OnPropertyChanged(nameof(CableType)); + } + } + + private int _encoderLineParagraph; + public int EncoderLineParagraph + { + get { return _encoderLineParagraph; } + set + { + _encoderLineParagraph = value; + OnPropertyChanged(nameof(EncoderLineParagraph)); + } + } + + private int _powerLineParagraph; + public int PowerLineParagraph + { + get { return _powerLineParagraph; } + + set + { + _powerLineParagraph = value; + OnPropertyChanged(nameof(PowerLineParagraph)); + } + } + private string _cableModelStr; + public string CableModelStr + { + get { return _cableModelStr; } + set + { + _cableModelStr = value; + OnPropertyChanged(nameof(CableModelStr)); + } + } + private bool _isEnableParagraph = true; + public bool IsEnableParagraph + { + get => _isEnableParagraph; + set + { + _isEnableParagraph = value; + OnPropertyChanged(nameof(IsEnableParagraph)); + } + } + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + #endregion +} diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs index a23fc85..142d5d3 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs @@ -16,605 +16,604 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows.Controls; -namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel +namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel; + +public class LectotypeViewModel(string docId) : INotifyPropertyChanged { - public class LectotypeViewModel(string docId) : INotifyPropertyChanged + private List _wires; + public List Wires { - private List _wires; - public List Wires + get => _wires; + set { - get => _wires; - set - { - _wires = value; - OnPropertyChanged(); - } + _wires = value; + OnPropertyChanged(); } + } - private List _oriWires = []; - public List OriWires + private List _oriWires = []; + public List OriWires + { + get => _oriWires; + set { - get => _oriWires; - set - { - _oriWires = value; - OnPropertyChanged(); - } + _oriWires = value; + OnPropertyChanged(); } - private LectotypeLineModel _selectedItem; - public LectotypeLineModel SelectedItem + } + private LectotypeLineModel _selectedItem; + public LectotypeLineModel SelectedItem + { + get => _selectedItem; + set { - get => _selectedItem; - set - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - _selectedItem = value; - OnPropertyChanged(); - OnSelectedItemChange(); - stopwatch.Stop(); - Debug.Print($"OnSelectedItemChange :{stopwatch.ElapsedMilliseconds}ms"); - } + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + _selectedItem = value; + OnPropertyChanged(); + OnSelectedItemChange(); + stopwatch.Stop(); + Debug.Print($"OnSelectedItemChange :{stopwatch.ElapsedMilliseconds}ms"); } + } - private ObservableCollection _selectedSubItem = []; - public ObservableCollection SelectedSubItem + private ObservableCollection _selectedSubItem = []; + public ObservableCollection SelectedSubItem + { + get => _selectedSubItem; + set { - get => _selectedSubItem; - set - { - _selectedSubItem = value; - OnPropertyChanged(); - } + _selectedSubItem = value; + OnPropertyChanged(); } + } - private DataGridRowDetailsVisibilityMode _detailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; - public DataGridRowDetailsVisibilityMode DetailsShowMode + private DataGridRowDetailsVisibilityMode _detailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; + public DataGridRowDetailsVisibilityMode DetailsShowMode + { + get => _detailsShowMode; + set { - get => _detailsShowMode; - set - { - _detailsShowMode = value; - OnPropertyChanged(); - } + _detailsShowMode = value; + OnPropertyChanged(); } - private List _motors = []; - public List Motors + } + private List _motors = []; + public List Motors + { + get => _motors; + set { - get => _motors; - set - { - _motors = value; - OnPropertyChanged(); - } + _motors = value; + OnPropertyChanged(); } - private List _stuffedWires; - public List StuffedWires + } + private List _stuffedWires; + public List StuffedWires + { + get => _stuffedWires; + set { - get => _stuffedWires; - set - { - _stuffedWires = value; - OnPropertyChanged(); - } + _stuffedWires = value; + OnPropertyChanged(); } - private List _lineBoms; - public List LineBoms + } + private List _lineBoms; + public List LineBoms + { + get => _lineBoms; + set { - get => _lineBoms; - set - { - _lineBoms = value; - OnPropertyChanged(); - } + _lineBoms = value; + OnPropertyChanged(); } + } - /// - /// 机构号 - /// - private string _mechanismNo; - public string MechanismNo + /// + /// 机构号 + /// + private string _mechanismNo; + public string MechanismNo + { + get => _mechanismNo; + set { - get => _mechanismNo; - set - { - _mechanismNo = value; - OnPropertyChanged(); - } + _mechanismNo = value; + OnPropertyChanged(); } - /// - /// 机构名 - /// - private string _mechanismName; - public string MechanismName + } + /// + /// 机构名 + /// + private string _mechanismName; + public string MechanismName + { + get => _mechanismName; + set { - get => _mechanismName; - set - { - _mechanismName = value; - OnPropertyChanged(); - } + _mechanismName = value; + OnPropertyChanged(); } - public List Drivers { get; set; } = [ - "脉冲型驱动器", - "总线型驱动器(CCLINK IE TSN)", - "总线型驱动器(SSCNET III/H)", - "总线型驱动器(EtherCAT)" - ]; + } + public List Drivers { get; set; } = [ + "脉冲型驱动器", + "总线型驱动器(CCLINK IE TSN)", + "总线型驱动器(SSCNET III/H)", + "总线型驱动器(EtherCAT)" + ]; - public Task LoadData() + public Task LoadData() + { + if (string.IsNullOrEmpty(docId)) { - if (string.IsNullOrEmpty(docId)) - { - return Task.CompletedTask; - } - var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); - // 获取所有存在的 - var wires = designer.GetOrganizerOccurrences(designer.ID); - //OriWires = wires.ToList(); - // 所有的线材 - // OccCableForked 多芯线? 对应设计器中Cables(电缆)下的内容 - // OccWire 导线 对应设计器中Wires(导线)下的内容 - List cables = [.. wires - .Where(it => - it.GetType() == typeof(OccCableForked) - //|| it.GetType() == typeof(OccWire) - ) - //.Where(it => !string.IsNullOrEmpty(GetAxisNo((it.Children.First() as OccCablesInsulatorGraph).Imprint)) ) - //.Where(it =>it.PartStatus == EPLAN.Harness.Core.LibEntities.Enums.PartStatus.Released) - .Select(it => - { - var occCable = (it as OccCableForked); - var insulatorGraph = occCable.Children.First() as OccCablesInsulatorGraph; - - var isEncoderLine = GetLineType(insulatorGraph.Imprint,"L"); - var isPowerLine = GetLineType(insulatorGraph.Imprint,"N"); - var encoderLength = 0d; - var powerLength = 0d; - if(double.TryParse(insulatorGraph.CableLength_VH?.StrVal ?? "0",out double length)){ - length = Math.Round(length,0); - if(isEncoderLine){ - encoderLength = length; - }else{ - powerLength = length; - } - } - - return new LectotypeLineModel - { - Name= GetLectotypeName(occCable.LibraryName), - CableName = occCable.Name, - AxisNo = GetAxisNo(insulatorGraph.Imprint), - CurrentLine = GetCableLine(insulatorGraph.Imprint), - IsEncoderLine = isEncoderLine, - IsPowerLine = isPowerLine, - PowerLineLength = powerLength, - EncoderLineLength = encoderLength, - CableType = isEncoderLine ? "编码器线" : isPowerLine ? "动力线" : "未知类型", - }; - }) - .Where(it => it != null) - //.Where(it => !string.IsNullOrEmpty(it.AxisNo)) - .OrderBy(it => it?.CableName ?? "")]; - - Wires = StuffData(cables); - designer.SelectSet.NodeSelected += SelectSet_NodeSelected; return Task.CompletedTask; } - - private void SelectSet_NodeSelected(object sender, EPLAN.Harness.Common.Events.EventArgs e) - { - if (e != null) + var designer = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); + // 获取所有存在的 + var wires = designer.GetOrganizerOccurrences(designer.ID); + //OriWires = wires.ToList(); + // 所有的线材 + // OccCableForked 多芯线? 对应设计器中Cables(电缆)下的内容 + // OccWire 导线 对应设计器中Wires(导线)下的内容 + List cables = [.. wires + .Where(it => + it.GetType() == typeof(OccCableForked) + //|| it.GetType() == typeof(OccWire) + ) + //.Where(it => !string.IsNullOrEmpty(GetAxisNo((it.Children.First() as OccCablesInsulatorGraph).Imprint)) ) + //.Where(it =>it.PartStatus == EPLAN.Harness.Core.LibEntities.Enums.PartStatus.Released) + .Select(it => { + var occCable = (it as OccCableForked); + var insulatorGraph = occCable.Children.First() as OccCablesInsulatorGraph; + + var isEncoderLine = GetLineType(insulatorGraph.Imprint,"L"); + var isPowerLine = GetLineType(insulatorGraph.Imprint,"N"); + var encoderLength = 0d; + var powerLength = 0d; + if(double.TryParse(insulatorGraph.CableLength_VH?.StrVal ?? "0",out double length)){ + length = Math.Round(length,0); + if(isEncoderLine){ + encoderLength = length; + }else{ + powerLength = length; + } + } + + return new LectotypeLineModel + { + Name= GetLectotypeName(occCable.LibraryName), + CableName = occCable.Name, + AxisNo = GetAxisNo(insulatorGraph.Imprint), + CurrentLine = GetCableLine(insulatorGraph.Imprint), + IsEncoderLine = isEncoderLine, + IsPowerLine = isPowerLine, + PowerLineLength = powerLength, + EncoderLineLength = encoderLength, + CableType = isEncoderLine ? "编码器线" : isPowerLine ? "动力线" : "未知类型", + }; + }) + .Where(it => it != null) + //.Where(it => !string.IsNullOrEmpty(it.AxisNo)) + .OrderBy(it => it?.CableName ?? "")]; + + Wires = StuffData(cables); + designer.SelectSet.NodeSelected += SelectSet_NodeSelected; + return Task.CompletedTask; + } + + private void SelectSet_NodeSelected(object sender, EPLAN.Harness.Common.Events.EventArgs e) + { + if (e != null) + { - } } + } - public string GetLectotypeName(string libraryName) + public string GetLectotypeName(string libraryName) + { + if (libraryName.Contains("&")) { - if (libraryName.Contains("&")) - { - return libraryName.Split('&')[1]?.Trim() ?? libraryName; - } - else - { - return libraryName; - } + return libraryName.Split('&')[1]?.Trim() ?? libraryName; } - - public List StuffData(List cables) + else { - List datas = []; - OriWires.Clear(); - //1 整理数据 - cables.ForEach(it => + return libraryName; + } + } + + public List StuffData(List cables) + { + List datas = []; + OriWires.Clear(); + //1 整理数据 + cables.ForEach(it => + { + var lineCount = 0; + var axisNo = it.AxisNo; + var cabType = it.CableType; + if (axisNo != null && cabType != null) { - var lineCount = 0; - var axisNo = it.AxisNo; - var cabType = it.CableType; - if (axisNo != null && cabType != null) - { - lineCount = cables.Count(cable => cable.AxisNo == axisNo && cable.CableType == cabType); - } - it.LineCount = lineCount; - if (it.CurrentLine == 1) - { - - it.CableConnectionClass = "前段"; - } - else if (it.CurrentLine > 1 && it.CurrentLine < lineCount) - { - it.CableConnectionClass = "中段"; - - } - else if (it.CurrentLine == lineCount) - { - - it.CableConnectionClass = "尾段"; - } - if (string.IsNullOrEmpty(axisNo)) - { - it.IsError = true; - it.IsChecked = true; - it.ErrorCount += 1; - it.CheckedMsg += "轴号不能为空!\r\n"; - } - if (datas.Any(i => i.AxisNo == it.AxisNo && it.CableType == i.CableType && it.CurrentLine == i.CurrentLine)) - { - it.IsError = true; - it.CheckedMsg = "线段重复!"; - } - - if (Motors != null && Motors.Any()) - { - var motor = Motors.FirstOrDefault(motor => motor.AxisNo == it.AxisNo); - if (motor != null) - { - it.Motor = motor; - } - else - { - it.IsError = true; - it.ErrorCount = 1; - it.CheckedMsg = "未匹配到电机"; - } - } - if (it.Name.StartsWith("T")) - { - it.IsFlexibility = true; - } - - // 先把非第一行的数据添加到数据集合中 - if (it.CurrentLine != 1) - { - datas.Add(it); - } - OriWires.Add(it.MemoryClone()); - }); - //2 合并同轴号的第一条数据 - cables.Where(it => it.CurrentLine == 1).ForEach(it => + lineCount = cables.Count(cable => cable.AxisNo == axisNo && cable.CableType == cabType); + } + it.LineCount = lineCount; + if (it.CurrentLine == 1) { - var existLine = datas.FirstOrDefault(data => data.AxisNo == it.AxisNo && data.CurrentLine == 1); - if (existLine != null) + + it.CableConnectionClass = "前段"; + } + else if (it.CurrentLine > 1 && it.CurrentLine < lineCount) + { + it.CableConnectionClass = "中段"; + + } + else if (it.CurrentLine == lineCount) + { + + it.CableConnectionClass = "尾段"; + } + if (string.IsNullOrEmpty(axisNo)) + { + it.IsError = true; + it.IsChecked = true; + it.ErrorCount += 1; + it.CheckedMsg += "轴号不能为空!\r\n"; + } + if (datas.Any(i => i.AxisNo == it.AxisNo && it.CableType == i.CableType && it.CurrentLine == i.CurrentLine)) + { + it.IsError = true; + it.CheckedMsg = "线段重复!"; + } + + if (Motors != null && Motors.Any()) + { + var motor = Motors.FirstOrDefault(motor => motor.AxisNo == it.AxisNo); + if (motor != null) { - if (existLine.CableType == it.CableType) return; - else - { - if (existLine.IsPowerLine) - { - existLine.SeqNo = 3; - existLine.EncoderLineLength = it.EncoderLineLength; - - } - else if (existLine.IsEncoderLine) - { - existLine.SeqNo = 2; - - existLine.PowerLineLength = it.PowerLineLength; - } - } - existLine.IsComplexLine = true; - existLine.CableType = "编码器线+动力线"; - if (datas.Any(i => i.AxisNo == it.AxisNo && i.CurrentLine != 1)) - { - - existLine.CableConnectionClass = "前段"; - } - else - { - existLine.CableConnectionClass = "直通"; - } - // 多端线时,第一条线取最大段数 - var lineCount = datas.Where(data => data.AxisNo == existLine.AxisNo).Max(data => data.LineCount); - existLine.LineCount = lineCount; - - if (existLine.IsComplexLine) - { - existLine.SeqNo = 1; - existLine.Name = ""; - existLine.CableName = OriWires - .Where(data => data.AxisNo == existLine.AxisNo && data.CurrentLine == 1) - .Select(data => data.CableName) - .Aggregate("/"); - existLine.SubLines = OriWires.Where(i => i.AxisNo == existLine.AxisNo && i.CurrentLine == existLine.CurrentLine && i.CurrentLine == 1).ToList(); - } - - if ((it.IsFlexibility || existLine.IsFlexibility) && it.IsFlexibility != existLine.IsFlexibility) - { - existLine.SetError("请检查是否使用正确的高柔线"); - } - + it.Motor = motor; } else { - it.IsComplexLine = true; - datas.Add(it); + it.IsError = true; + it.ErrorCount = 1; + it.CheckedMsg = "未匹配到电机"; } - - }); - CheckLines(datas); - return [.. datas.OrderByDescending(it => it.SeqNo)]; - } - - private void CheckLines(List lines) - { - lines?.ForEach(line => + } + if (it.Name.StartsWith("T")) { - if (string.IsNullOrEmpty(line.CableModelNo)) + it.IsFlexibility = true; + } + + // 先把非第一行的数据添加到数据集合中 + if (it.CurrentLine != 1) + { + datas.Add(it); + } + OriWires.Add(it.MemoryClone()); + }); + //2 合并同轴号的第一条数据 + cables.Where(it => it.CurrentLine == 1).ForEach(it => + { + var existLine = datas.FirstOrDefault(data => data.AxisNo == it.AxisNo && data.CurrentLine == 1); + if (existLine != null) + { + if (existLine.CableType == it.CableType) return; + else { - line.SetError("未正确取得型号!请检查线材是否使用错误!"); + if (existLine.IsPowerLine) + { + existLine.SeqNo = 3; + existLine.EncoderLineLength = it.EncoderLineLength; + + } + else if (existLine.IsEncoderLine) + { + existLine.SeqNo = 2; + + existLine.PowerLineLength = it.PowerLineLength; + } } - if (line.CableType == "未知类型") + existLine.IsComplexLine = true; + existLine.CableType = "编码器线+动力线"; + if (datas.Any(i => i.AxisNo == it.AxisNo && i.CurrentLine != 1)) { - line.SetError("线材类型不正确,请检查印记内容!"); - } - }); - } - /// - /// L -> 动力线 N -> 编码器线 - /// - /// - /// - public bool GetLineType(string imprint, string lineFlag) - { - if (imprint != null && imprint.Contains("-")) - { - var vals = imprint.Split('-'); - var val = vals[1]; - Trace.WriteLine($"{vals[1]},{lineFlag},{val.ToUpper() == lineFlag.ToUpper()}"); - return val.ToUpper() == lineFlag.ToUpper(); - } - else - { - return false; - } - } - public string GetAxisNo(string imprint) - { - if (imprint != null && imprint.Contains("-")) - { - var vals = imprint.Split('-'); - return vals[0] ?? null; - } - else - { - return null; - } - } - public int GetCableLine(string imprint) - { - if (imprint != null && imprint.Contains("-")) - { - var vals = imprint.Split('-'); - if (int.TryParse(vals[2], out int line)) - { - return line; + existLine.CableConnectionClass = "前段"; } else { - return 0; + existLine.CableConnectionClass = "直通"; } + // 多端线时,第一条线取最大段数 + var lineCount = datas.Where(data => data.AxisNo == existLine.AxisNo).Max(data => data.LineCount); + existLine.LineCount = lineCount; + + if (existLine.IsComplexLine) + { + existLine.SeqNo = 1; + existLine.Name = ""; + existLine.CableName = OriWires + .Where(data => data.AxisNo == existLine.AxisNo && data.CurrentLine == 1) + .Select(data => data.CableName) + .Aggregate("/"); + existLine.SubLines = OriWires.Where(i => i.AxisNo == existLine.AxisNo && i.CurrentLine == existLine.CurrentLine && i.CurrentLine == 1).ToList(); + } + + if ((it.IsFlexibility || existLine.IsFlexibility) && it.IsFlexibility != existLine.IsFlexibility) + { + existLine.SetError("请检查是否使用正确的高柔线"); + } + + } + else + { + it.IsComplexLine = true; + datas.Add(it); + } + + }); + CheckLines(datas); + return [.. datas.OrderByDescending(it => it.SeqNo)]; + } + + private void CheckLines(List lines) + { + lines?.ForEach(line => + { + if (string.IsNullOrEmpty(line.CableModelNo)) + { + line.SetError("未正确取得型号!请检查线材是否使用错误!"); + } + if (line.CableType == "未知类型") + { + line.SetError("线材类型不正确,请检查印记内容!"); + + } + }); + } + /// + /// L -> 动力线 N -> 编码器线 + /// + /// + /// + public bool GetLineType(string imprint, string lineFlag) + { + if (imprint != null && imprint.Contains("-")) + { + var vals = imprint.Split('-'); + var val = vals[1]; + Trace.WriteLine($"{vals[1]},{lineFlag},{val.ToUpper() == lineFlag.ToUpper()}"); + return val.ToUpper() == lineFlag.ToUpper(); + } + else + { + return false; + } + } + public string GetAxisNo(string imprint) + { + if (imprint != null && imprint.Contains("-")) + { + var vals = imprint.Split('-'); + return vals[0] ?? null; + } + else + { + return null; + } + } + public int GetCableLine(string imprint) + { + if (imprint != null && imprint.Contains("-")) + { + var vals = imprint.Split('-'); + if (int.TryParse(vals[2], out int line)) + { + return line; } else { return 0; } } - //public string GetWireImprint(OccWire wire) - //{ - // return wire.Imprint; - //} - //public OccConnector GetOccEndPin(OccPin pin) - //{ - // if (pin == null || pin.Connector == null) - // { - // return null; - // } - // OccConnector connector = pin.Connector; - // if (connector != null) - // { - // return connector; - // } - // else - // { - // return null; - // } - //} - - public event PropertyChangedEventHandler PropertyChanged; - - private void OnPropertyChanged([CallerMemberName] string propertyName = null) + else { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - - public void ToSource(string cableName) - { - try - { - var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); - var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked)); - if (cable != null) - { - doc.SelectSet.Clear(); - var oriOcc = SelfControler.FindInstance(cable.ID); - oriOcc.SetVisibility(true, null); - doc.SelectSet.Add(oriOcc.Children.First()); - doc.FitToSelectSet(); - doc.SelectSet.OnSelectionChanged(); - } - } - catch (Exception ex) - { - FlexMessageBox.Error(ex.Message); - } - } - public void ToMotorSource(string motorId, string cableName) - { - try - { - var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); - var part = doc.GetOccurrenceByID(motorId); - var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked)); - if (part != null) - { - doc.SelectSet.Clear(); - var oriOcc = SelfControler.FindInstance(part.ID); - oriOcc.SetVisibility(true, null); - doc.SelectSet.Add(oriOcc.Children.First()); - if (!string.IsNullOrEmpty(cableName) && cable != null) - { - var cableOcc = SelfControler.FindInstance(cable.ID); - cableOcc.SetVisibility(true, null); - doc.SelectSet.Add(cableOcc.Children.First()); - } - doc.FitToSelectSet(); - doc.SelectSet.OnSelectionChanged(); - } - } - catch (Exception ex) - { - FlexMessageBox.Error(ex.Message); - } - } - - public Task GetMotors() - { - var motorsData = new List(); - var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); - var parts = doc.GetOrganizerOccurrences(docId) - .Where(occ => occ.Type == OCC_TYPE.wPART) - .Where(occ => occ.Name?.StartsWith("HK-KT") ?? false) - //.Where(occ => occ.Properties?.IsContarins("轴号") ?? false) - .ToList(); - var motorPowerDatas = MotorExcelHelper.Instance.GetMotorPowers(); - parts.ForEach(part => - { - var motorPowerData = motorPowerDatas.FirstOrDefault(it => it.ItemFlag == part.Name); - var axisNo = part.Properties.IsContarins("轴号") ? part.Properties.FirstOrDefault(it => it.PropertyName == "轴号").GetDisplayValue() : ""; - - var motor = new MotorModel - { - MotorModelStr = part.Name, - AxisNo = axisNo, - OccPartId = part.ID, - IsError = string.IsNullOrEmpty(axisNo) - }; - if (motorPowerData != null) - { - motor.MotorPower = motorPowerData.ItemValue; - } - else - { - motor.SetError("电机型号不存在于资料表中"); - } - if (string.IsNullOrEmpty(axisNo)) - { - motor.SetError("未填写轴号信息!"); - } - motorsData?.Add(motor); - }); - Motors = motorsData; - return Task.CompletedTask; - } - private void OnSelectedItemChange() - { - if (this.SelectedItem != null) - { - SelectedSubItem.Clear(); - DetailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; - - var subItems = OriWires.Where(it => it.AxisNo == SelectedItem.AxisNo && it.CurrentLine == SelectedItem.CurrentLine && it.CurrentLine == 1).ToList(); - if (subItems.Count > 1) - { - subItems.ForEach(SelectedSubItem.Add); - DetailsShowMode = DataGridRowDetailsVisibilityMode.VisibleWhenSelected; - } - else - { - SelectedSubItem.Clear(); - DetailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; - } - } - else - { - SelectedSubItem.Clear(); - DetailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; - } - } - - public bool GetBom(string cableModel) - { - var line = Wires.FirstOrDefault(it => it.CableModelNo == cableModel); - if (line != null) - { - var drawId = line.DrawingNo; - var bomList = MotorExcelHelper.Instance.GetBomList(drawId); - var genedBomList = new List(); - bomList.ForEach(it => - { - if (it.Name is "动力线" or "动力刹车线") - { - it.Qty = line.PowerLineLength; - } - if (it.Name == "编码器线") - { - it.Qty = line.EncoderLineLength; - } - var item = new LineBomItemModel - { - MechanicalNo = MechanismNo, - MechanicalName = MechanismName, - }; - item.Assign(it); - genedBomList.Add(item); - }); - LineBoms = genedBomList; - return true; - } - else - { - return false; - } - } - public void ExportBomList(string targetPath, string cableModel) - { - MotorExcelHelper.Instance.SaveBomListToExcel(targetPath, LineBoms, cableModel); - } - - public void ExportLines(string targetPath) - { - int seq = 1; - Wires.ForEach(it => - { - it.ItemSeqNo = seq++; - MechanismName ??= ""; - MechanismNo ??= ""; - }); - MotorExcelHelper.Instance.SaveLinesToExcel(targetPath, Wires); + return 0; } } + //public string GetWireImprint(OccWire wire) + //{ + // return wire.Imprint; + //} + //public OccConnector GetOccEndPin(OccPin pin) + //{ + // if (pin == null || pin.Connector == null) + // { + // return null; + // } + // OccConnector connector = pin.Connector; + // if (connector != null) + // { + // return connector; + // } + // else + // { + // return null; + // } + //} + + public event PropertyChangedEventHandler PropertyChanged; + + private void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public void ToSource(string cableName) + { + try + { + var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); + var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked)); + if (cable != null) + { + doc.SelectSet.Clear(); + var oriOcc = SelfControler.FindInstance(cable.ID); + oriOcc.SetVisibility(true, null); + doc.SelectSet.Add(oriOcc.Children.First()); + doc.FitToSelectSet(); + doc.SelectSet.OnSelectionChanged(); + } + } + catch (Exception ex) + { + FlexMessageBox.Error(ex.Message); + } + } + public void ToMotorSource(string motorId, string cableName) + { + try + { + var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); + var part = doc.GetOccurrenceByID(motorId); + var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked)); + if (part != null) + { + doc.SelectSet.Clear(); + var oriOcc = SelfControler.FindInstance(part.ID); + oriOcc.SetVisibility(true, null); + doc.SelectSet.Add(oriOcc.Children.First()); + if (!string.IsNullOrEmpty(cableName) && cable != null) + { + var cableOcc = SelfControler.FindInstance(cable.ID); + cableOcc.SetVisibility(true, null); + doc.SelectSet.Add(cableOcc.Children.First()); + } + doc.FitToSelectSet(); + doc.SelectSet.OnSelectionChanged(); + } + } + catch (Exception ex) + { + FlexMessageBox.Error(ex.Message); + } + } + + public Task GetMotors() + { + var motorsData = new List(); + var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId); + var parts = doc.GetOrganizerOccurrences(docId) + .Where(occ => occ.Type == OCC_TYPE.wPART) + .Where(occ => occ.Name?.StartsWith("HK-KT") ?? false) + //.Where(occ => occ.Properties?.IsContarins("轴号") ?? false) + .ToList(); + var motorPowerDatas = MotorExcelHelper.Instance.GetMotorPowers(); + parts.ForEach(part => + { + var motorPowerData = motorPowerDatas.FirstOrDefault(it => it.ItemFlag == part.Name); + var axisNo = part.Properties.IsContarins("轴号") ? part.Properties.FirstOrDefault(it => it.PropertyName == "轴号").GetDisplayValue() : ""; + + var motor = new MotorModel + { + MotorModelStr = part.Name, + AxisNo = axisNo, + OccPartId = part.ID, + IsError = string.IsNullOrEmpty(axisNo) + }; + if (motorPowerData != null) + { + motor.MotorPower = motorPowerData.ItemValue; + } + else + { + motor.SetError("电机型号不存在于资料表中"); + } + if (string.IsNullOrEmpty(axisNo)) + { + motor.SetError("未填写轴号信息!"); + } + motorsData?.Add(motor); + }); + Motors = motorsData; + return Task.CompletedTask; + } + private void OnSelectedItemChange() + { + if (this.SelectedItem != null) + { + SelectedSubItem.Clear(); + DetailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; + + var subItems = OriWires.Where(it => it.AxisNo == SelectedItem.AxisNo && it.CurrentLine == SelectedItem.CurrentLine && it.CurrentLine == 1).ToList(); + if (subItems.Count > 1) + { + subItems.ForEach(SelectedSubItem.Add); + DetailsShowMode = DataGridRowDetailsVisibilityMode.VisibleWhenSelected; + } + else + { + SelectedSubItem.Clear(); + DetailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; + } + } + else + { + SelectedSubItem.Clear(); + DetailsShowMode = DataGridRowDetailsVisibilityMode.Collapsed; + } + } + + public bool GetBom(string cableModel) + { + var line = Wires.FirstOrDefault(it => it.CableModelNo == cableModel); + if (line != null) + { + var drawId = line.DrawingNo; + var bomList = MotorExcelHelper.Instance.GetBomList(drawId); + var genedBomList = new List(); + bomList.ForEach(it => + { + if (it.Name is "动力线" or "动力刹车线") + { + it.Qty = line.PowerLineLength; + } + if (it.Name == "编码器线") + { + it.Qty = line.EncoderLineLength; + } + var item = new LineBomItemModel + { + MechanicalNo = MechanismNo, + MechanicalName = MechanismName, + }; + item.Assign(it); + genedBomList.Add(item); + }); + LineBoms = genedBomList; + return true; + } + else + { + return false; + } + } + public void ExportBomList(string targetPath, string cableModel) + { + MotorExcelHelper.Instance.SaveBomListToExcel(targetPath, LineBoms, cableModel); + } + + public void ExportLines(string targetPath) + { + int seq = 1; + Wires.ForEach(it => + { + it.ItemSeqNo = seq++; + MechanismName ??= ""; + MechanismNo ??= ""; + }); + MotorExcelHelper.Instance.SaveLinesToExcel(targetPath, Wires); + } } diff --git a/Sinvo.EplanHpD.Plugin/AppDomainDllLoader.cs b/Sinvo.EplanHpD.Plugin/AppDomainDllLoader.cs index 94fea4c..d17d513 100644 --- a/Sinvo.EplanHpD.Plugin/AppDomainDllLoader.cs +++ b/Sinvo.EplanHpD.Plugin/AppDomainDllLoader.cs @@ -42,7 +42,7 @@ namespace Sinvo.EplanHpD.Plugin .FirstOrDefault(a => a.FullName == assemblyName.FullName); if (loadedAssembly != null) { - Debug.WriteLine($"Dll is loaded -> {loadedAssembly.FullName}"); + Debug.WriteLine($"DLL is loaded -> {loadedAssembly.FullName}"); return loadedAssembly; } diff --git a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs index 57dc8b6..9f3228a 100644 --- a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs +++ b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs @@ -48,6 +48,8 @@ namespace Sinvo.EplanHpD.Plugin public HpDModule Module => HpDModule.WorkSpace; + public string ToolbarTooltip => "伺服电机线缆抓取"; + public void Execute(HpdApi api) { var doc = api.CurrentProject.GetActiveDocument(); @@ -63,7 +65,6 @@ namespace Sinvo.EplanHpD.Plugin { AppDomainDllLoader.SetLaoder(); ApplicationExt.InitApplication(); - } diff --git a/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs b/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs index 4945e51..1ef83af 100644 --- a/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs +++ b/Sinvo.EplanHpD.Plugin/Properties/AssemblyInfo.cs @@ -28,6 +28,6 @@ using System.Runtime.InteropServices; // 生成号 // 修订号 // -[assembly: AssemblyVersion("1.0.0.18")] -[assembly: AssemblyFileVersion("1.0.0.18")] -[assembly: AssemblyInformationalVersion("1.0.0.16")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.0.19")] +[assembly: AssemblyFileVersion("1.0.0.19")] +[assembly: AssemblyInformationalVersion("1.0.0.19")] \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj b/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj index 04a165f..acbda1b 100644 --- a/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj +++ b/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj @@ -81,7 +81,9 @@ False RefDLL\EPLAN.Harness.AppCore.dll - + + RefDLL\EPLAN.Harness.Common.dll + False RefDLL\EPLAN.Harness.Core.dll