105040 Update 优化选中线检查逻辑

This commit is contained in:
lihanbo 2024-12-17 15:10:32 +08:00
parent e979379045
commit bd4063346c
1 changed files with 123 additions and 22 deletions

View File

@ -1,4 +1,6 @@
using EPLAN.Harness.API.Occurrences;
using EPLAN.Harness.API;
using EPLAN.Harness.API.ApiProperties;
using EPLAN.Harness.API.Occurrences;
using EPLAN.Harness.Common.Extensions;
using EPLAN.Harness.Core;
using EPLAN.Harness.Core.Controls;
@ -28,6 +30,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
private List<string> _motorIds;
private MotorModel _motor;
private CableLectotypeViewModel cableLectotypeViewModel;
private HpdApi api;
public MotorModel Motor
{
get => _motor;
@ -39,12 +42,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
public LayoutHelperViewModel()
{
api = HpdApi.GetInstance();
api.Init();
}
public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List<string> motorIds)
{
_currentFlexDesigner = currentFlexDesigner;
_motorIds = motorIds;
api = HpdApi.GetInstance();
api.Init();
}
public string SelectMotorModel
{
@ -61,13 +68,22 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
get
{
if (_selectLineId == null) return "";
var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId);
if (part != null)
try
{
return part.Parents?.First()?.LibraryName;
if (_selectLineId == null) return "";
var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId);
if (part != null)
{
return part.Parents?.FirstOrDefault()?.LibraryName;
}
else
{
return "";
}
}
else
catch (Exception)
{
return "";
}
@ -208,8 +224,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
SelectedLines = cableLectotypeViewModel.SelectedLines;
SelectedLine = SelectedLines[CurrentMotorSelectLineIndex];
ReSetSubLines();
Motor = cableLectotypeViewModel.Motor;
Motor = cableLectotypeViewModel.Motor;
return;
}
}
@ -238,7 +253,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
else
{
CurrentMotorSelectLineIndex--;
SelectedLine = SelectedLines[CurrentMotorSelectLineIndex];
ReSetSubLines();
@ -250,7 +264,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
if (HasNext)
{
if (CheckAndSetSelLine())
var canNext = CheckSelLine();
if (canNext)
{
if (CurrentMotorSelectLineIndex >= SelectedLines.Count - 1)
@ -268,22 +285,77 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
}
private bool CheckAndSetSelLine()
private bool CheckSelLine()
{
var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId);
if (part != null)
try
{
if (part.Properties.Any(it => it.ValueHolder.StrVal == "轴号")) return true;
var prop = new EPLAN.Harness.Core.Props.Property(new PropDef { Name = "轴号" });
prop.Set(SelectedLine.AxisNo);
part.Properties.Add(prop);
return true;
var parts = _currentFlexDesigner.SelectSet;
foreach (var part in parts)
{
if (part != null)
{
// 如果选中的是导线,则直接使用,如果选中的是绝缘层,则使用绝缘层,其他情况使用父级
var linePart = part is OccCableForked ?
part as OccCableForked
: part is OccCablesInsulatorGraph ?
part
: part.Parents?.FirstOrDefault() as OccCableForked;
if (linePart != null)
{
var libName = linePart?.LibraryName;
// 绝缘层选择上一层的导线来获取信息
if(part is OccCablesInsulatorGraph)
{
libName = (part.Parents?.First() as OccCableForked).LibraryName;
//partLineModel = (part.Parents?.First() as OccCableForked).LibraryName.Split('&')[1];
}
var partLineModel = (libName.Contains("&") ? libName.Split('&')[1] : libName).Trim(' ');
if (SubLines.Any(it => it.CableModel == partLineModel))
{
var subLine = SubLines.FirstOrDefault(it => it.CableModel == partLineModel);
var imprint = "";
// 导线需要取绝缘层的印记信息,导线本身没有印记
if(part is OccCableForked)
{
var insulatorGraph = part.Children.FirstOrDefault();
imprint = insulatorGraph.Properties.FirstOrDefault(it => it.PropertyName == "Imprint")?.ValueHolder.StrVal;
}
else
{
imprint = (linePart as OccCablesInsulatorGraph).Imprint;//Properties.FirstOrDefault(it => it.PropertyName == "Imprint")?.ValueHolder.StrVal;
}
if (string.IsNullOrEmpty(imprint))
{
FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写");
return false;
}
if ($"{SelectedLine.AxisNo}-{SelectedLine.CurrentLine}" == imprint)
{
subLine.IsChecked = true;
//cableLectotypeViewModel.SaveToDb();
SetSubLineAndSave(subLine.CableModel);
return SubLines.All(it => it.IsChecked);
}
else
{
FlexMessageBox.Warning($"当前选中的线 {libName} 印记与推荐中的线印记不一致");
return false;
}
}
}
}
FlexMessageBox.Warning($"当前选中的线不是推荐中的线型号");
return false;
}
}
else
catch (Exception)
{
FlexMessageBox.Warning("当前选中的线不是推荐中的线");
FlexMessageBox.Warning("抓取线信息异常");
return false;
}
FlexMessageBox.Warning("请选择正确的线");
return false;
}
internal void ToPrevMotor()
@ -305,8 +377,37 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
}
}
internal void ReSetSubLines()
{
{
SubLines = SelectedLine.SubLines.Distinct(it => it.CableModel).ToList();
}
internal void SetSubLineAndSave(string cableModel)
{
foreach (var it in cableLectotypeViewModel.SelectedLines)
{
if (it.AxisNo == SelectedLine.AxisNo && it.CurrentLine == SelectedLine.CurrentLine)
{
foreach (var line in it.SubLines)
{
if (cableModel == line.CableModel)
{
line.IsChecked = true;
line.OnPropertyChanged(nameof(line.IsChecked)); // Ensure property change is notified
}
}
}
}
SaveToDb(cableLectotypeViewModel);
}
public bool SaveToDb(CableLectotypeViewModel cableLectotypeViewModel)
{
var id = cableLectotypeViewModel.Motor.OccPartId;
var json = Newtonsoft.Json.JsonConvert.SerializeObject(cableLectotypeViewModel);
var service = new MotorLectotypeService();
return service.SaveMotorLectotypeData(id, json);
}
}
}