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.Common.Extensions;
using EPLAN.Harness.Core; using EPLAN.Harness.Core;
using EPLAN.Harness.Core.Controls; using EPLAN.Harness.Core.Controls;
@ -28,6 +30,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
private List<string> _motorIds; private List<string> _motorIds;
private MotorModel _motor; private MotorModel _motor;
private CableLectotypeViewModel cableLectotypeViewModel; private CableLectotypeViewModel cableLectotypeViewModel;
private HpdApi api;
public MotorModel Motor public MotorModel Motor
{ {
get => _motor; get => _motor;
@ -39,12 +42,16 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
public LayoutHelperViewModel() public LayoutHelperViewModel()
{ {
api = HpdApi.GetInstance();
api.Init();
} }
public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List<string> motorIds) public LayoutHelperViewModel(FlexDesigner currentFlexDesigner, List<string> motorIds)
{ {
_currentFlexDesigner = currentFlexDesigner; _currentFlexDesigner = currentFlexDesigner;
_motorIds = motorIds; _motorIds = motorIds;
api = HpdApi.GetInstance();
api.Init();
} }
public string SelectMotorModel public string SelectMotorModel
{ {
@ -61,17 +68,26 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
get get
{ {
try
{
if (_selectLineId == null) return ""; if (_selectLineId == null) return "";
var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId); var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId);
if (part != null) if (part != null)
{ {
return part.Parents?.First()?.LibraryName; return part.Parents?.FirstOrDefault()?.LibraryName;
} }
else else
{ {
return ""; return "";
} }
} }
catch (Exception)
{
return "";
}
}
set set
{ {
@ -209,7 +225,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
SelectedLine = SelectedLines[CurrentMotorSelectLineIndex]; SelectedLine = SelectedLines[CurrentMotorSelectLineIndex];
ReSetSubLines(); ReSetSubLines();
Motor = cableLectotypeViewModel.Motor; Motor = cableLectotypeViewModel.Motor;
return; return;
} }
} }
@ -238,7 +253,6 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
else else
{ {
CurrentMotorSelectLineIndex--; CurrentMotorSelectLineIndex--;
SelectedLine = SelectedLines[CurrentMotorSelectLineIndex]; SelectedLine = SelectedLines[CurrentMotorSelectLineIndex];
ReSetSubLines(); ReSetSubLines();
@ -250,7 +264,10 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
if (HasNext) if (HasNext)
{ {
if (CheckAndSetSelLine()) var canNext = CheckSelLine();
if (canNext)
{ {
if (CurrentMotorSelectLineIndex >= SelectedLines.Count - 1) if (CurrentMotorSelectLineIndex >= SelectedLines.Count - 1)
@ -268,22 +285,77 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
} }
} }
private bool CheckAndSetSelLine() private bool CheckSelLine()
{
try
{
var parts = _currentFlexDesigner.SelectSet;
foreach (var part in parts)
{ {
var part = _currentFlexDesigner.GetOccurrenceByID(_selectLineId);
if (part != null) if (part != null)
{ {
if (part.Properties.Any(it => it.ValueHolder.StrVal == "轴号")) return true; // 如果选中的是导线,则直接使用,如果选中的是绝缘层,则使用绝缘层,其他情况使用父级
var prop = new EPLAN.Harness.Core.Props.Property(new PropDef { Name = "轴号" }); var linePart = part is OccCableForked ?
prop.Set(SelectedLine.AxisNo); part as OccCableForked
part.Properties.Add(prop); : part is OccCablesInsulatorGraph ?
return true; 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 else
{ {
FlexMessageBox.Warning("当前选中的线不是推荐中的线"); imprint = (linePart as OccCablesInsulatorGraph).Imprint;//Properties.FirstOrDefault(it => it.PropertyName == "Imprint")?.ValueHolder.StrVal;
}
if (string.IsNullOrEmpty(imprint))
{
FlexMessageBox.Warning($"当前选中的线 {libName} 印记未填写");
return false; 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;
}
}
catch (Exception)
{
FlexMessageBox.Warning("抓取线信息异常");
return false;
}
FlexMessageBox.Warning("请选择正确的线");
return false;
} }
internal void ToPrevMotor() internal void ToPrevMotor()
@ -308,5 +380,34 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{ {
SubLines = SelectedLine.SubLines.Distinct(it => it.CableModel).ToList(); 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);
}
}
}