diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs index c00ee4d..4cbadda 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/ScanCableModel.cs @@ -91,5 +91,46 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models OnPropertyChanged(nameof(E_Pin)); } } + private string _s_pinID; + public string S_pinID + { + get => _s_pinID; + set + { + _s_pinID = value; + OnPropertyChanged(nameof(S_pinID)); + } + } + private string _e_pinID; + public string E_pinID + { + get => _e_pinID; + set + { + _e_pinID = value; + OnPropertyChanged(nameof(E_pinID)); + } + } + + private string _s_part; + public string S_part + { + get => _s_part; + set + { + _s_part = value; + OnPropertyChanged(nameof(S_part)); + } + } + private string _e_part; + public string E_part + { + get => _e_part; + set + { + _e_part = value; + OnPropertyChanged(nameof(E_part)); + } + } } } diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml index 28c0302..6fcf789 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml @@ -6,58 +6,90 @@ xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel" - Title="ScannerInfo" - Width="1000" - Height="70" - MinHeight="85" - MaxHeight="85" + Title="布线常规属性" + Width="1100" + Height="120" + MinHeight="120" + MaxHeight="120" d:DataContext="{d:DesignInstance Type=viewmodel:ScannerViewModel}" - AllowsTransparency="True" + AllowsTransparency="False" Left="300" + ResizeMode="NoResize" Topmost="True" WindowStartupLocation="Manual" - WindowStyle="None" + WindowStyle="SingleBorderWindow" mc:Ignorable="d"> + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml.cs index 219f64b..666673e 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/View/ScannerInfo.xaml.cs @@ -44,26 +44,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View this.Topmost = true; } - private void DataGrid_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) - { - for (int i = 1; i < this.scannerinfo.Items.Count; i++) - { - DataGridRow row = (DataGridRow)scannerinfo.ItemContainerGenerator.ContainerFromIndex(i); - // 如果行还没有生成,则调用此方法以强制生成 - if (row == null) - { - scannerinfo.ScrollIntoView(scannerinfo.Items[i]); - scannerinfo.ScrollIntoView(scannerinfo.Items[i]); - row = (DataGridRow)scannerinfo.ItemContainerGenerator.ContainerFromIndex(i); - if (row != null) - { - row.Visibility = Visibility.Collapsed; - } - } - - - } - } + public void ScannerInfoClosed(object sender, EventArgs e) { this.Close(); // 或者你可以根据需要选择是否关闭当前窗口 diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/ScannerViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/ScannerViewModel.cs index d6bdc02..6ed0844 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/ScannerViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/ScannerViewModel.cs @@ -4,11 +4,15 @@ using EPLAN.Harness.AppCore.StudioCommon.TreeView; using EPLAN.Harness.Common; using EPLAN.Harness.Core.Controls; using EPLAN.Harness.Core.Extensions; +using EPLAN.Harness.Core.LibEntities; using EPLAN.Harness.Primitives.Treeviews; using EPLAN.Harness.ProjectCore; +using EPLAN.Harness.ProjectCore.Occurrences; using EPLAN.Harness.ProjectCore.Occurrences.Designer; +using HandyControl.Tools.Extension; using Sinvo.EplanHpD.Plugin.WPFUI.Common; using Sinvo.EplanHpD.Plugin.WPFUI.Models; +using Sinvo.EplanHpD.Plugin.WPFUI.Utils; using System; using System.Collections; using System.Collections.Generic; @@ -80,11 +84,109 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel if (ScanCableModels != value) { ScanCableModels = value; + OnPropertyChanged(nameof(_ScanCableModels)); } } } -private DispatcherTimer _debounceTimer; + + #region + private string _S_part; + public string S_part + { + get => _S_part; + set + { + _S_part = value; + + OnPropertyChanged(nameof(S_part)); + } + } + + private string _E_part; + public string E_part + { + get => _E_part; + set + { + _E_part = value; + + OnPropertyChanged(nameof(E_part)); + } + } + + private string _S_pin; + public string S_pin + { + get => _S_pin; + set + { + _S_pin = value; + + OnPropertyChanged(nameof(S_pin)); + } + } + + private string _E_pin; + public string E_pin + { + get => _E_pin; + set + { + _E_pin = value; + + OnPropertyChanged(nameof(E_pin)); + } + } + + private string _Name; + public string Name + { + get => _Name; + set + { + _Name = value; + + OnPropertyChanged(nameof(Name)); + } + } + private string _Code; + public string Code + { + get => _Code; + set + { + _Code = value; + + OnPropertyChanged(nameof(Code)); + } + } + + private string _Length; + public string Length + { + get => _Length; + set + { + _Length = value; + + OnPropertyChanged(nameof(Length)); + } + } + private string _Imprint; + public string Imprint + { + get => _Imprint; + set + { + _Imprint = value; + + OnPropertyChanged(nameof(Imprint)); + } + } + + #endregion + private DispatcherTimer _debounceTimer; public ScannerViewModel() { @@ -92,23 +194,39 @@ private DispatcherTimer _debounceTimer; } + public void GetAllCables() { ScanCableModels.Clear(); + string s_pinid = ""; + string e_pinid = ""; _currentFlexDesigner.GetOrganizerOccurrences().ToList().ForEach(occ => { if (occ is OccWire wire) { if (wire.Name.StartsWith("w_", StringComparison.OrdinalIgnoreCase)) { + + //获取线两端管脚id,id唯一 + var wire_pin = wire.DBG_GetPins.Split(';'); + if (wire_pin.Length != 0) + { + s_pinid = wire_pin[0].Substring(1, 32); + e_pinid = wire_pin[1].Trim().Substring(1, 32); + } + + + //保存线材基础属性 ScanCableModels.Add(new ScanCableModel() { Index = ScanCableModels.Count + 1, Id = wire.ID, - S_Pin= wire.ConnectedPinsUI.Substring(0,wire.ConnectedPinsUI.IndexOf("<>")), - E_Pin= wire.ConnectedPinsUI.Substring( wire.ConnectedPinsUI.IndexOf("<>")+3,wire.ConnectedPinsUI.Length- wire.ConnectedPinsUI.IndexOf("<>")-3), + S_Pin = wire.ConnectedPinsUI.Substring(0, wire.ConnectedPinsUI.IndexOf("<>")), + E_Pin = wire.ConnectedPinsUI.Substring(wire.ConnectedPinsUI.IndexOf("<>") + 3, wire.ConnectedPinsUI.Length - wire.ConnectedPinsUI.IndexOf("<>") - 3), + S_pinID = s_pinid, + E_pinID = e_pinid, Name = wire.LibraryName, - Length= Math.Ceiling(wire.Length_VH.GetValueInUnit(UNIT_CLASS.LENGTH)).ToString(), + Length = Math.Ceiling(wire.Length_VH.GetValueInUnit(UNIT_CLASS.LENGTH)).ToString(), Code = wire.Name, Imprint = wire.Imprint }); @@ -116,7 +234,55 @@ private DispatcherTimer _debounceTimer; } }); } + /// + /// scaninfo界面数据 和找到管脚上级部件 + /// + /// + public void ToMotorSource(ScanCableModel scanCableModel) + { + try + { + S_pin = scanCableModel.E_Pin; + E_pin = scanCableModel.E_Pin; + S_part = scanCableModel.S_part; + Length = scanCableModel.Length; + Name = scanCableModel.Name; + Code = scanCableModel.Code; + Imprint = scanCableModel.Imprint; + _currentFlexDesigner.GetOrganizerOccurrences().ToList().ForEach(occ => + { + //if (occ is OccConnector Assembly) + //{ + //var Assembly = occ; + //根据管脚id获取上级部件信息 + if (occ.ID.Equals(scanCableModel.S_pinID)) + { + var oriOcc = SelfControler.FindInstance(occ.ID); + var parent = oriOcc.Parents?.FirstOrDefault(); + var grandparent = parent.Parents?.FirstOrDefault(); + scanCableModel.S_part = grandparent.Name; + S_part = scanCableModel.S_part; + } + if (occ.ID.Equals(scanCableModel.E_pinID)) + { + var oriOcc = SelfControler.FindInstance(occ.ID); + var parent = oriOcc.Parents?.FirstOrDefault(); + var grandparent = parent.Parents?.FirstOrDefault(); + scanCableModel.E_part = grandparent.Name; + E_part = scanCableModel.E_part; + } + + //} + } + ); + + } + catch (Exception ex) + { + FlexMessageBox.Error(ex.Message); + } + } public void GetCurrentDoc() { try @@ -138,7 +304,7 @@ private DispatcherTimer _debounceTimer; FlexMessageBox.Error(ex.Message); } } - + private void DebounceTimer_Tick(object sender, EventArgs e) { @@ -152,6 +318,8 @@ private DispatcherTimer _debounceTimer; // 清除错误信息 ClearErrors(nameof(InputCode)); var cable = ScanCableModels.FirstOrDefault(c => c.Code.Equals(searchText, StringComparison.OrdinalIgnoreCase) || c.Imprint.StartsWith(searchText, StringComparison.OrdinalIgnoreCase)); + + if (cable != null) { @@ -167,12 +335,14 @@ private DispatcherTimer _debounceTimer; //cable.IsChecked = true; ScanCableModel scanCableModel = new ScanCableModel(); scanCableModel = cable; - scanCableModel.IsChecked = true; - ScanCableModels.Remove(cable); - ScanCableModels.Insert(0,scanCableModel); + + _ScanCableModels.Remove(cable); + _ScanCableModels.Insert(0, scanCableModel); + _ScanCableModels.FirstOrDefault().IsChecked = true; + ToMotorSource(scanCableModel); } - ScanedIndex = Math.Max(cable.Index - 1, 0); + ScanedIndex = 0;//Math.Max(cable.Index - 1, 0); ToSourceById(cable.Id); } @@ -222,7 +392,7 @@ private DispatcherTimer _debounceTimer; _currentFlexDesigner.FitToSelectSet(); _currentFlexDesigner.SelectSet.OnSelectionChanged(); - + //_currentFlexDesigner.Camera.GraphicControl._HighlightNode() /* List> nodeByEntity = this._occTreeView.GetNodeByEntity(baseOccurrence); @@ -240,7 +410,7 @@ private DispatcherTimer _debounceTimer; } } - + public void OthersOccShow(bool show = false) {