diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml
index cebd946..31794cf 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml
@@ -6,6 +6,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:pdf="clr-namespace:PdfiumViewer;assembly=PdfiumViewer"
xmlns:util="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.Utils"
xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel"
Title="多芯线数据抓取"
@@ -105,173 +106,199 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ Orientation="Horizontal">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml.cs
index 9b2623a..3875811 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/LectotypeWindow.xaml.cs
@@ -1,8 +1,15 @@
using EPLAN.Harness.Core.Controls;
+using HandyControl.Controls;
+using Microsoft.Win32;
+using Microsoft.WindowsAPICodePack.Dialogs;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
+using System;
+using System.Diagnostics;
+using System.IO;
using System.Linq;
+using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -11,7 +18,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
///
/// LectotypeWindow.xaml 的交互逻辑
///
- public partial class LectotypeWindow : Window
+ public partial class LectotypeWindow : System.Windows.Window
{
private LectotypeViewModel ViewModel;
public LectotypeWindow(string docId)
@@ -25,12 +32,15 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
{
try
{
+ //DrawPDFHelper.CacheAllPdfToMemory();
MotorExcelHelper.Instance.ReadDataToStream();
LoadData();
}
catch (System.Exception ex)
{
FlexMessageBox.Error(ex.Message);
+ MotorExcelHelper.Instance.CloseStream();
+ //DrawPDFHelper.ClearCache();
}
}
@@ -99,15 +109,19 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
private void LettotypeListView_RowDetailsVisibilityChanged(object sender, System.Windows.Controls.DataGridRowDetailsEventArgs e)
{
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
var datagrid = sender as DataGrid;
if (datagrid != null)
{
- var DetailsDataGrid = e.DetailsElement as DataGrid;
+ var DetailsDataGrid = e.DetailsElement as ListView;
if (DetailsDataGrid != null)
{
DetailsDataGrid.ItemsSource = ViewModel.SelectedSubItem;
}
}
+ stopwatch.Stop();
+ Debug.Print($"LettotypeListView_RowDetailsVisibilityChanged :{stopwatch.ElapsedMilliseconds}ms");
}
private void SubToSourceMenuItem_Click(object sender, RoutedEventArgs e)
@@ -124,15 +138,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
private object SubDetailsDataGridSelectedItem;
private void SubDetailsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- DataGrid dataGrid = sender as DataGrid;
- if (dataGrid != null && dataGrid.SelectedItem != null)
+ var view = sender as ListView;
+ if (view != null && view.SelectedItem != null)
{
- SubDetailsDataGridSelectedItem = dataGrid.SelectedItem;
+ SubDetailsDataGridSelectedItem = view.SelectedItem;
}
}
private void Window_Closed(object sender, System.EventArgs e)
{
+ //DrawPDFHelper.ClearCache();
MotorExcelHelper.Instance.CloseStream();
}
@@ -149,5 +164,159 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
{
}
+
+ private void ViewDrawingButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button btn && btn.Tag != null)
+ {
+ try
+ {
+
+ //LoadingMask.Visibility = Visibility.Visible;
+ var drawId = btn.Tag.ToString();
+ if (string.IsNullOrEmpty(drawId))
+ {
+ DrawPDFDrawer.Tag = "";
+ FlexMessageBox.Error("没有图号!");
+ }
+ else
+ {
+
+ DrawPDFDrawer.Tag = drawId;
+ PdfCircleProgressBar.Visibility = Visibility.Visible;
+ DrawPDFDrawer.IsOpen = true;
+ }
+
+ }
+ catch (Exception ex)
+ {
+ LoadingMask.Visibility = Visibility.Collapsed;
+ FlexMessageBox.Warning(ex.Message);
+ }
+ }
+ }
+
+ private void DrawPDFDrawer_Opened(object sender, RoutedEventArgs e)
+ {
+ if (sender is Drawer drawer)
+ {
+ string drawId = drawer.Tag as string;
+ Task.Run(() =>
+ {
+ Task.Delay(10);
+ var padPath = @"\\192.168.1.160\plm系统文档\线材选型\图纸\";
+ // 在后台线程中获取PDF流
+ var pdfStream = new FileStream(Path.Combine(padPath, $"{drawId}.pdf"), FileMode.Open, FileAccess.Read);//DrawPDFHelper.GetPDFStream(drawId);
+
+ // 切换到主线程更新UI
+ Dispatcher.BeginInvoke(() =>
+ {
+ if (pdfStream != null)
+ {
+ PdfRenderer.OpenPdf(pdfStream);
+ PdfCircleProgressBar.Visibility = Visibility.Collapsed;
+
+ }
+ else
+ {
+ FlexMessageBox.Warning("图纸不存在!");
+ DrawPDFDrawer.IsOpen = false;
+ }
+ LoadingMask.Visibility = Visibility.Collapsed;
+ });
+ });
+ }
+ }
+
+ private void DrawPDFDrawer_Closed(object sender, RoutedEventArgs e)
+ {
+ this.Dispatcher.BeginInvoke(() =>
+ {
+ PdfRenderer.UnLoad();
+ });
+ }
+
+ private void ViewBOMButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button btn)
+ {
+ if (string.IsNullOrEmpty(ViewModel.MechanismNo) || string.IsNullOrEmpty(ViewModel.MechanismName))
+ {
+ FlexMessageBox.Warning("请完善机构信息!");
+ return;
+ }
+
+ var cableModel = btn.Tag as string;
+ if (string.IsNullOrEmpty(cableModel))
+ {
+ ExportBomBtn.Tag = "";
+ FlexMessageBox.Error("没有型号!");
+ }
+ else
+ {
+
+ if (ViewModel.GetBom(cableModel))
+ {
+ ExportBomBtn.Tag = cableModel;
+ CableModelLab.Text = cableModel;
+ BomDrawer.IsOpen = true;
+ }
+ }
+ }
+ }
+
+ private void ExportBomBtn_Click(object sender, RoutedEventArgs e)
+ {
+ if (sender is Button btn)
+ {
+ var cableModel = btn.Tag as string;
+ // 选择一个文件夹
+ var dialog = new SaveFileDialog
+ {
+ Filter = "Excel文件|*.xlsx",
+ FileName = $"线材BOM_{cableModel.Replace('\\', '_').Replace('/', '_')}_{DateTime.Now:yyyy_MM_dd}.xlsx"
+ };
+ if (dialog.ShowDialog() == true)
+ {
+ ViewModel.ExportBomList(dialog.FileName, cableModel);
+ }
+ FlexMessageBox.Info("导出完成");
+ }
+ }
+
+ private void ExportExcelBtn_Click(object sender, RoutedEventArgs e)
+ {
+ var exportedPath = new CommonOpenFileDialog
+ {
+ IsFolderPicker = true,
+ InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
+ };
+ if (exportedPath.ShowDialog() == CommonFileDialogResult.Ok)
+ {
+ ViewModel.ExportLines(exportedPath.FileName);
+ FlexMessageBox.Info("导出完成");
+ }
+ }
+
+ private void ToMotorSourceMenuItem_Click(object sender, RoutedEventArgs e)
+ {
+ var selectItem = LettotypeListView.SelectedItem;
+ if (selectItem is LectotypeLineModel model)
+ {
+ var motorModelStr = model.Motor?.MotorModelStr;
+
+ var cableName = model.IsComplexLine ? model.CableName.Split('/')[1] : model.CableName;
+ if (string.IsNullOrEmpty(motorModelStr))
+ {
+ FlexMessageBox.ShowText(FlexMessageBox.Type.INFO, "未获取到电机名称");
+ }
+ else
+ {
+
+ ViewModel.ToMotorSource(motorModelStr, cableName);
+ }
+ //}
+ }
+ }
}
}
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml
index 415c46e..b73fc05 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml
@@ -26,6 +26,7 @@
+
@@ -145,8 +146,7 @@
hc:InfoElement.Placeholder="W_00961"
hc:TitleElement.Title="线名称"
IsRealTime="True"
- SearchStarted="SearchBar_SearchStarted"
- ShowClearButton="True" />
+ SearchStarted="SearchBar_SearchStarted" />
+ public string MechanicalNo { get; set; }
+ ///
+ /// 机械机构名称
+ ///
+ public string MechanicalName { get; set; }
+
+ private int _itemSeqNo;
+ public int ItemSeqNo
+ {
+ get { return _itemSeqNo; }
+ set
+ {
+ _itemSeqNo = value;
+ OnPropertyChanged(nameof(ItemSeqNo));
+ }
+ }
+
public int SeqNo;
@@ -249,59 +269,67 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
{
get
{
- if (Motor == null) return "";
- string drawNo = "MR-";
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
+ if (Motor == null)
+ {
+ return "";
+ }
+ string ModelNo = "MR-";
var cableFlag = GetCableModelFlag(Motor?.MotorPower, CableType, CableConnectionClass, IsFlexibility);
if (string.IsNullOrWhiteSpace(cableFlag))
{
DrawingNo = "";
+
return "";
}
else
{
- drawNo += cableFlag + "-";
+ ModelNo += cableFlag + "-";
}
//编码器线+动力线 编码器线+动力刹车线
if (CableType is "编码器线+动力线" or "编码器线+动力刹车线") // 组合线
- drawNo += "A1-";
+ ModelNo += "A1-";
if (IsFlexibility)
{
- drawNo += "H-";
+ ModelNo += "H-";
}
else
{
- drawNo += "L-";
+ ModelNo += "L-";
}
if (IsComplexLine)
{
- drawNo += $"{EncoderLineLength}-{PowerLineLength}";
+ ModelNo += $"{EncoderLineLength}-{PowerLineLength}";
}
else if (IsEncoderLine)
{
- drawNo += $"{EncoderLineLength}";
+ ModelNo += $"{EncoderLineLength}";
}
else if (IsPowerLine)
{
- drawNo += $"{PowerLineLength}";
+ ModelNo += $"{PowerLineLength}";
}
if (!string.IsNullOrEmpty(AxisNo))
{
- drawNo += "(";
- drawNo += $"{AxisNo}";
+ ModelNo += "(";
+ ModelNo += $"{AxisNo}";
if (CableConnectionClass != "直通")
//if (!(CableType is "编码器线+动力线" or "编码器线+动力刹车线"))
- drawNo += $"-{CurrentLine} / {LineCount}";
- drawNo += ")";
+ ModelNo += $"-{CurrentLine} / {LineCount}";
+ ModelNo += ")";
}
//if (isUpdateDrawNo)
{
DrawingNo = GetCableDrawNo();
}
- return drawNo;
+ stopwatch.Stop();
+ Debug.Print($"CableModelNo : {stopwatch.ElapsedMilliseconds}ms");
+ return ModelNo;
}
set
{
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineBomItemModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineBomItemModel.cs
new file mode 100644
index 0000000..1a863d4
--- /dev/null
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineBomItemModel.cs
@@ -0,0 +1,36 @@
+using MiniExcelLibs.Attributes;
+
+namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
+{
+ public class LineBomItemModel : LineBomModel
+ {
+ ///
+ /// 机械机构号
+ ///
+ [ExcelColumnName("机构号")]
+ public string MechanicalNo { get; set; }
+ ///
+ /// 机械机构名称
+ ///
+ [ExcelColumnName("机构名称")]
+ public string MechanicalName { get; set; }
+
+
+ public void Assign(LineBomModel lineBomModel)
+ {
+ DrawingNo = lineBomModel.DrawingNo;
+ SeqNo = lineBomModel.SeqNo;
+ MaterialNo = lineBomModel.MaterialNo;
+ Type = lineBomModel.Type;
+ Name = lineBomModel.Name;
+ Spec = lineBomModel.Spec;
+ Qty = lineBomModel.Qty;
+ Unit = lineBomModel.Unit;
+ IsLength = lineBomModel.IsLength;
+ IsFlexibility = lineBomModel.IsFlexibility;
+
+ Remark = lineBomModel.Remark;
+
+ }
+ }
+}
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineBomModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineBomModel.cs
new file mode 100644
index 0000000..e285697
--- /dev/null
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineBomModel.cs
@@ -0,0 +1,233 @@
+using MiniExcelLibs.Attributes;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+
+namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
+{
+ ///
+ ///
+ ///
+ public class LineBomModel : INotifyPropertyChanged
+ {
+ /*
+ 线材图纸编号
+ 项次
+ 料号
+ 类型
+ 品名
+ 规格
+ 用量
+ 单位
+ 长度否(Y/N)
+ 高柔度(Y/N)
+ 备注
+ */
+ ///
+ /// 线材图纸编号
+ ///
+ private string _drawingNo;
+ ///
+ ///
+ ///
+ [ExcelColumnName("线材图纸编号")]
+ public string DrawingNo
+ {
+ get { return _drawingNo; }
+ set
+ {
+ _drawingNo = value;
+ OnPropertyChanged(nameof(DrawingNo));
+ }
+ }
+
+ ///
+ /// 项次
+ ///
+ private string _seqNo;
+ ///
+ ///
+ ///
+ [ExcelColumnName("项次")]
+ public string SeqNo
+ {
+ get { return _seqNo; }
+ set
+ {
+ _seqNo = value;
+ OnPropertyChanged(nameof(SeqNo));
+ }
+ }
+ ///
+ /// 料号
+ ///
+ private string _materialNo;
+ ///
+ ///
+ ///
+ [ExcelColumnName("料号")]
+ public string MaterialNo
+
+ {
+ get { return _materialNo; }
+ set
+ {
+ _materialNo = value;
+ OnPropertyChanged(nameof(MaterialNo));
+ }
+ }
+
+ ///
+ /// 类型
+ ///
+ private string _type;
+ ///
+ ///
+ ///
+ [ExcelColumnName("类型")]
+ public string Type
+ {
+ get { return _type; }
+ set
+ {
+ _type = value;
+ OnPropertyChanged(nameof(Type));
+ }
+ }
+ ///
+ /// 品名
+ ///
+ private string _name;
+ ///
+ ///
+ ///
+ [ExcelColumnName("品名")]
+ public string Name
+ {
+ get { return _name; }
+ set
+ {
+ _name = value;
+ OnPropertyChanged(nameof(Name));
+ }
+ }
+ ///
+ /// 规格
+ ///
+ private string _spec;
+ ///
+ ///
+ ///
+ [ExcelColumnName("规格")]
+ public string Spec
+ {
+ get { return _spec; }
+ set
+ {
+ _spec = value;
+ OnPropertyChanged(nameof(Spec));
+ }
+ }
+ ///
+ /// 用量
+ ///
+ private double _qty;
+ ///
+ ///
+ ///
+ [ExcelColumnName("用量")]
+ public double Qty
+ {
+ get { return _qty; }
+ set
+ {
+ _qty = value;
+ OnPropertyChanged(nameof(Qty));
+ }
+ }
+ ///
+ /// 单位
+ ///
+ private string _unit;
+ ///
+ ///
+ ///
+ [ExcelColumnName("单位")]
+ public string Unit
+ {
+ get { return _unit; }
+ set
+ {
+ _unit = value;
+ OnPropertyChanged(nameof(Unit));
+ }
+ }
+ ///
+ /// 长度否(Y/N)
+ ///
+ private string _isLength;
+ ///
+ ///
+ ///
+ [ExcelColumnName("长度否(Y/N)")]
+ public string IsLength
+ {
+ get { return _isLength; }
+ set
+ {
+ _isLength = value;
+ OnPropertyChanged(nameof(IsLength));
+ }
+ }
+ ///
+ /// 高柔度(Y/N)
+ ///
+ private string _isFlexibility;
+ ///
+ ///
+ ///
+ [ExcelColumnName("高柔度(Y/N)")]
+ public string IsFlexibility
+ {
+ get { return _isFlexibility; }
+ set
+ {
+ _isFlexibility = value;
+ OnPropertyChanged(nameof(IsFlexibility));
+ }
+ }
+ ///
+ /// 备注
+ ///
+ private string _remark;
+
+ ///
+ ///
+ ///
+ [ExcelColumnName("备注")]
+ public string Remark
+ {
+ get { return _remark; }
+ set
+ {
+ _remark = value;
+ OnPropertyChanged(nameof(Remark));
+ }
+ }
+
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
+ protected bool SetProperty(ref T field, T value, [CallerMemberName] string propertyName = null)
+ {
+ //if (Equals(field, value)) return false;
+ field = value;
+ OnPropertyChanged(propertyName);
+ return true;
+ }
+ }
+}
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineSegmentModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineSegmentModel.cs
deleted file mode 100644
index 2a473b9..0000000
--- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/LineSegmentModel.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
-{
- ///
- /// 线段信息
- ///
- public class LineSegmentModel
- {
- ///
- /// 轴号
- ///
- public string LineAxisNo { get; set; }
- ///
- /// 类型 -> [L -> 动力线] [N -> 编码器线]
- ///
- public string LineType { get; set; }
- ///
- /// 第几段
- ///
- public int LineParagraph { get; set; }
- }
-}
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj
index fc1d6f1..610a4a6 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/Sinvo.EplanHpD.Plugin.WPFUI.csproj
@@ -126,7 +126,8 @@
-
+
+
@@ -137,6 +138,7 @@
+
@@ -190,10 +192,15 @@
-
+
+
+ {60d3c75c-e71d-4116-bd7e-cac68c4dd96b}
+ PdfiumViewer
+
+
- 3.2.0
+ 3.5.1
1.34.2
@@ -203,6 +210,9 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
+
+ 8.0.6
+
\ No newline at end of file
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/DrawPDFHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/DrawPDFHelper.cs
new file mode 100644
index 0000000..0b00d9b
--- /dev/null
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/DrawPDFHelper.cs
@@ -0,0 +1,38 @@
+using System.Collections.Generic;
+using System.IO;
+
+namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
+{
+ public class DrawPDFHelper
+ {
+ private static string PDF_PATH = @"\\192.168.1.160\plm系统文档\线材选型\图纸\";
+ private static Dictionary _pdfDataDict = new Dictionary();
+
+ public static void CacheAllPdfToMemory()
+ {
+ var path = PDF_PATH;
+ var files = Directory.GetFiles(path, "*.pdf");
+ foreach (var file in files)
+ {
+ var drawId = Path.GetFileNameWithoutExtension(file);
+ var data = File.ReadAllBytes(file);
+ _pdfDataDict.Add(drawId, data);
+ }
+ }
+
+ public static MemoryStream GetPDFStream(string drawId)
+ {
+ if (_pdfDataDict.ContainsKey(drawId))
+ {
+ var data = _pdfDataDict[drawId];
+ return new MemoryStream(data);
+ }
+ return null;
+ }
+
+ public static void ClearCache()
+ {
+ _pdfDataDict.Clear();
+ }
+ }
+}
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs
index ab55eb6..d1ac996 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/Utils/MotorExcelHelper.cs
@@ -1,5 +1,6 @@
using MiniExcelLibs;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -77,6 +78,59 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
)).ToList();
}
+ public List GetBomList(string drawNo)
+ {
+ //var filePath = "D:\\Desktop\\Data\\BOM表.xlsx";
+ var filePath = Path.Combine(DATA_FILE_PATH, DATA_FILE_NAME_BOM);
+ var data = MiniExcel.Query(filePath).Where(it => it.DrawingNo == drawNo).ToList();
+ //MiniExcel.Query<>()
+ return data;
+ }
+ public void SaveBomListToExcel(string targetPath, List bomList, string cableModelNo)
+ {
+ MiniExcel.SaveAs(
+ targetPath,
+ bomList
+ );
+ }
+ public bool SaveLinesToExcel(string targetPath, List lines)
+ {
+ try
+ {
+ var templatePath = Path.Combine(DATA_FILE_PATH, TEMPLATE_FILE_NAME);
+ var data = lines.Select(line => new
+ {
+ line.ItemSeqNo,
+ line.SeqNo,
+ line.MechanicalNo,
+ line.MechanicalName,
+ line.CableModelNo,
+ line.CableType,
+ line.AxisNo,
+ line.DrawingNo,
+ EncoderLineLength = line.EncoderLineLength == 0 ? "" : line.EncoderLineLength.ToString(),
+ PowerLineLength = line.PowerLineLength == 0 ? "" : line.PowerLineLength.ToString(),
+
+ }).ToList();
+ MiniExcel.SaveAsByTemplate(
+ $"{targetPath}\\线材下单_{DateTime.Now:yyyy_MM_dd}.xlsx",
+ templatePath,
+ new
+ {
+ data
+ },
+ new MiniExcelLibs.OpenXml.OpenXmlConfiguration
+ {
+ FastMode = true
+ }
+ );
+ return true;
+ }
+ catch (System.Exception)
+ {
+ throw;
+ }
+ }
public void CloseStream()
{
diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs
index ebb7920..a8fbc69 100644
--- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs
+++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/LectotypeViewModel.cs
@@ -47,9 +47,13 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
get => _selectedItem;
set
{
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.Start();
_selectedItem = value;
OnPropertyChanged();
OnSelectedItemChange();
+ stopwatch.Stop();
+ Debug.Print($"OnSelectedItemChange :{stopwatch.ElapsedMilliseconds}ms");
}
}
@@ -96,7 +100,43 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
OnPropertyChanged();
}
}
+ private List _lineBoms;
+ public List LineBoms
+ {
+ get => _lineBoms;
+ set
+ {
+ _lineBoms = value;
+ OnPropertyChanged();
+ }
+ }
+ ///
+ /// 机构号
+ ///
+ private string _mechanismNo;
+ public string MechanismNo
+ {
+ get => _mechanismNo;
+ set
+ {
+ _mechanismNo = value;
+ OnPropertyChanged();
+ }
+ }
+ ///
+ /// 机构名
+ ///
+ private string _mechanismName;
+ public string MechanismName
+ {
+ get => _mechanismName;
+ set
+ {
+ _mechanismName = value;
+ OnPropertyChanged();
+ }
+ }
public List Drivers { get; set; } = [
"脉冲型驱动器",
"总线型驱动器(CCLINK IE TSN)",
@@ -122,7 +162,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
it.GetType() == typeof(OccCableForked)
//|| it.GetType() == typeof(OccWire)
)
- .Where(it => !string.IsNullOrEmpty(GetAxisNo((it.Children.First() as OccCablesInsulatorGraph).Imprint)) )
+ //.Where(it => !string.IsNullOrEmpty(GetAxisNo((it.Children.First() as OccCablesInsulatorGraph).Imprint)) )
//.Where(it =>it.PartStatus == EPLAN.Harness.Core.LibEntities.Enums.PartStatus.Released)
.Select(it =>
{
@@ -166,7 +206,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
if (libraryName.Contains("&"))
{
- return libraryName.Split('&')[1];
+ return libraryName.Split('&')[1]?.Trim() ?? libraryName;
}
else
{
@@ -294,16 +334,34 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
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 -> 编码器线
///
@@ -403,6 +461,35 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
FlexMessageBox.Error(ex.Message);
}
}
+ public void ToMotorSource(string motorName, string cableName)
+ {
+ try
+ {
+ var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == docId);
+ var part = doc.GetOccurrenceByName(motorName, typeof(OccSubPart));
+ 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 (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();
@@ -466,5 +553,56 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
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.sln b/Sinvo.EplanHpD.Plugin.sln
index 9834485..72f2250 100644
--- a/Sinvo.EplanHpD.Plugin.sln
+++ b/Sinvo.EplanHpD.Plugin.sln
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sinvo.EplanHpD.Plugin.WPFUI
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sinvo.EplanHpD.Plugin.Test", "Sinvo.EplanHpD.Plugin.Test\Sinvo.EplanHpD.Plugin.Test.csproj", "{AEC39474-528B-4DA8-B650-99189ACB7A2C}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfiumViewer", "..\PdfiumViewer\PdfiumViewer.csproj", "{60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -41,6 +43,14 @@ Global
{AEC39474-528B-4DA8-B650-99189ACB7A2C}.Release|Any CPU.Build.0 = Release|Any CPU
{AEC39474-528B-4DA8-B650-99189ACB7A2C}.Release|x64.ActiveCfg = Release|Any CPU
{AEC39474-528B-4DA8-B650-99189ACB7A2C}.Release|x64.Build.0 = Release|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Debug|x64.Build.0 = Debug|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|x64.ActiveCfg = Release|Any CPU
+ {60D3C75C-E71D-4116-BD7E-CAC68C4DD96B}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs
index e5b626d..740898f 100644
--- a/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs
+++ b/Sinvo.EplanHpD.Plugin/DesignPluginEntry.cs
@@ -5,6 +5,7 @@ using System;
using System.Drawing;
using System.IO;
using System.Reflection;
+using System.Windows.Forms.Integration;
namespace Sinvo.EplanHpD.Plugin
{
@@ -14,7 +15,7 @@ namespace Sinvo.EplanHpD.Plugin
public string Author => "Sinvo";
- public string Description => "兴禾EPLAN Harness proD 2.9 Studio插件,提供线材数据抓取功能";
+ public string Description => "兴禾EPLAN Harness proD 2.9 Studio插件,提供伺服电机线缆抓取功能";
///
/// 获取DLL版本
@@ -37,16 +38,18 @@ namespace Sinvo.EplanHpD.Plugin
}
}
- public string ToolbarText => "抓取线材数据";
+ public string ToolbarText => "伺服电机线缆抓取";
- public string ToolbarTooltip => "抓取线材数据";
+ public string ToolbarTooltip => "伺服电机线缆抓取";
public HpDModule Module => HpDModule.WorkSpace;
public void Execute(HpdApi api)
{
var doc = api.CurrentProject.GetActiveDocument();
- new LectotypeWindow(doc.ID).Show();
+ var window = new LectotypeWindow(doc.ID);
+ ElementHost.EnableModelessKeyboardInterop(window);
+ window.Show();
}
public void Initialize()
diff --git a/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj b/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj
index 9b228a3..841bcf3 100644
--- a/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj
+++ b/Sinvo.EplanHpD.Plugin/Sinvo.EplanHpD.Plugin.csproj
@@ -68,8 +68,8 @@
False
RefDLL\EPLAN.Harness.ProjectCore.dll
-
- ..\packages\HandyControl.3.2.0\lib\net48\HandyControl.dll
+
+ ..\packages\HandyControl.3.5.1\lib\net481\HandyControl.dll
diff --git a/Sinvo.EplanHpD.Plugin/packages.config b/Sinvo.EplanHpD.Plugin/packages.config
index 32729ae..d47dcff 100644
--- a/Sinvo.EplanHpD.Plugin/packages.config
+++ b/Sinvo.EplanHpD.Plugin/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file