105040 Update 调整选择线段类型逻辑

This commit is contained in:
lihanbo 2025-01-13 11:22:45 +08:00
parent 5d8eb5d05a
commit e825595117
9 changed files with 178 additions and 86 deletions

View File

@ -24,7 +24,10 @@ namespace Sinvo.EplanHpD.Plugin.Service.Model
public string AxisNo { get; set; }
[SugarColumn(IsNullable = true)]
public string CableType { get; set; }
public string CableTypePrimary { get; set; }
[SugarColumn(IsNullable = true)]
public string CableTypeSecond { get; set; }
[SugarColumn(IsNullable = true)]
public int EncoderLineParagraph { get; set; }

View File

@ -82,7 +82,8 @@ namespace Sinvo.EplanHpD.Plugin.Service
},
CableConnectionType = (ConnectionType)Enum.Parse(typeof(ConnectionType), cableLectotype.CableConnectionType.ToString()),
AxisNo = cableLectotype.AxisNo,
CableType = cableLectotype.CableType,
CableTypePrimary = cableLectotype.CableTypePrimary,
CableTypeSecond = cableLectotype.CableTypeSecond,
EncoderLineParagraph = cableLectotype.EncoderLineParagraph,
PowerLineParagraph = cableLectotype.PowerLineParagraph,
CableModelStr = cableLectotype.CableModelStr,
@ -127,6 +128,14 @@ namespace Sinvo.EplanHpD.Plugin.Service
}).ToList();
}
public bool ClearSubLines(string motorOccId)
{
var changeCount = DBHelper.DB.Deleteable<LectotypeLine>()
.Where(sl => sl.MotorId == motorOccId)
.ExecuteCommand();
return changeCount > 0;
}
public bool SaveMotorLectotypeData(string motorOccId, CableLectotypeViewModel data)
{
var db = DBHelper.DB;
@ -163,8 +172,10 @@ namespace Sinvo.EplanHpD.Plugin.Service
CableLectotypeId = Guid.NewGuid().ToString(),
MotorId = motor.OccPartId,
CableConnectionType = (int)data.CableConnectionType,
AxisNo = data.AxisNo,
CableType = data.CableType,
CableTypePrimary = data.CableTypePrimary,
CableTypeSecond = data.CableTypeSecond,
EncoderLineParagraph = data.EncoderLineParagraph,
PowerLineParagraph = data.PowerLineParagraph,
CableModelStr = data.CableModelStr,

View File

@ -14,7 +14,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Utils
{
public static class LectotypeManager
{
public static string CURRENT_DOC_ID = "";
public class LectotypeViewModelFactory
{

View File

@ -120,7 +120,7 @@
Text="{Binding AxisNo, Mode=TwoWay}" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel Margin="0,10,0,0" Orientation="Horizontal">
<!--<hc:SimpleStackPanel Margin="0,10,0,0" Orientation="Horizontal">
<TextBlock
Width="100"
VerticalAlignment="Center"
@ -132,7 +132,7 @@
SelectedIndex="0"
SelectedValue="{Binding CableType}"
SelectedValuePath="ItemValue" />
</hc:SimpleStackPanel>
</hc:SimpleStackPanel>-->
<!--<hc:SimpleStackPanel Margin="0,10,0,0" Orientation="Vertical">
<hc:SimpleStackPanel Orientation="Horizontal">
<TextBlock Width="100" Text="编码器线长度:" VerticalAlignment="Center"/>
@ -148,25 +148,44 @@
</hc:SimpleStackPanel>
</hc:SimpleStackPanel>-->
<hc:SimpleStackPanel Margin="0,10" Orientation="Vertical">
<hc:SimpleStackPanel Orientation="Horizontal">
<TextBlock
Width="100"
<hc:SimpleStackPanel VerticalAlignment="Stretch" Orientation="Horizontal">
<hc:SimpleStackPanel
Width="200"
VerticalAlignment="Center"
Text="编码器线段数:" />
Orientation="Horizontal">
<hc:ComboBox
Width="153"
DisplayMemberPath="ItemName"
ItemsSource="{Binding CableTypes}"
SelectedIndex="0"
SelectedValue="{Binding CableTypePrimary}"
SelectedValuePath="ItemValue" />
<TextBlock VerticalAlignment="Center" Text="段数:" />
</hc:SimpleStackPanel>
<hc:TextBox
Width="263"
Width="163"
Height="30"
IsEnabled="{Binding IsEnableParagraph}"
IsReadOnly="False"
Text="{Binding EncoderLineParagraph, Mode=TwoWay}" />
</hc:SimpleStackPanel>
<hc:SimpleStackPanel Orientation="Horizontal">
<TextBlock
Width="100"
<hc:SimpleStackPanel
Width="200"
VerticalAlignment="Center"
Text="动力线段数:" />
Orientation="Horizontal">
<hc:ComboBox
Width="153"
DisplayMemberPath="ItemName"
IsEnabled="{Binding IsEnableParagraph}"
ItemsSource="{Binding CableTypes}"
SelectedIndex="0"
SelectedValue="{Binding CableTypeSecond}"
SelectedValuePath="ItemValue" />
<TextBlock VerticalAlignment="Center" Text="段数:" />
</hc:SimpleStackPanel>
<hc:TextBox
Width="263"
Width="163"
Height="30"
IsEnabled="{Binding IsEnableParagraph}"
IsReadOnly="False"
@ -287,7 +306,7 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="是否布线完成">
<!--<DataGridTemplateColumn Header="是否布线完成">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox
@ -297,7 +316,7 @@
IsEnabled="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGridTemplateColumn>-->
<DataGridTextColumn
Binding="{Binding CableModelNo}"
Header="型号"

View File

@ -1,6 +1,9 @@
using CommunityToolkit.Mvvm.Messaging;
using EPLAN.Harness.Core.Controls;
using EPLAN.Harness.Core.Tasks;
using EPLAN.Harness.Graphics;
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using EPLAN.Harness.ProjectCore;
using HandyControl.Controls;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Common;
@ -15,6 +18,8 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using static Sinvo.EplanHpD.Plugin.WPFUI.Utils.LectotypeManager;
using System.Linq;
using EPLAN.Harness.ProjectCore.Occurrences;
namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{
@ -142,5 +147,29 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.View
}
}
public void ToMotorSource(string motorId)
{
try
{
if (string.IsNullOrEmpty(LectotypeManager.CURRENT_DOC_ID)) return;
var doc = FlexProject.CurrentProject.GetDesigners().FirstOrDefault(designer => designer.ID == LectotypeManager.CURRENT_DOC_ID);
var part = doc.GetOccurrenceByID(motorId);
//var cable = doc.GetOccurrenceByName(cableName, typeof(OccCableForked));
if (part != null)
{
doc.SelectSet.Clear();
var oriOcc = SelfControler<BaseOccurrence>.FindInstance(part.ID);
oriOcc.SetVisibility(true, null);
doc.SelectSet.Add(oriOcc);
doc.FitToSelectSet();
doc.SelectSet.OnSelectionChanged();
}
}
catch (Exception ex)
{
FlexMessageBox.Error(ex.Message);
}
}
}
}

View File

@ -48,32 +48,47 @@
VerticalAlignment="Top"
Panel.ZIndex="99" />
</ScrollViewer>
<hc:SimpleStackPanel Grid.Row="0" Orientation="Horizontal">
<!--<TextBlock FontSize="14" TextWrapping="Wrap">
<Run Text="选中的电机:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectMotorModel}" />
</TextBlock>-->
<TextBlock
Margin="0,0,0,0"
FontSize="14"
TextWrapping="Wrap">
<Run Text="当前布线的电机:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding Motor.MotorModelStr}" />
<Run Text=" " />
<Run Text="轴号:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectedLine.AxisNo}" />
</TextBlock>
</hc:SimpleStackPanel>
<StackPanel Grid.Row="1" VerticalAlignment="Center">
<TextBlock VerticalAlignment="Center" FontSize="14">
<Run Text="当前线段:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectedLine.CableConnectionClass}" />
<Run Text=" " />
<Run Text="当前线类型:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectedLine.CableType}" />
</TextBlock>
</StackPanel>
<Grid Grid.Row="0" Grid.RowSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<hc:SimpleStackPanel Grid.Row="0" Orientation="Horizontal">
<!--<TextBlock FontSize="14" TextWrapping="Wrap">
<Run Text="选中的电机:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectMotorModel}" />
</TextBlock>-->
<TextBlock
Margin="0,0,0,0"
FontSize="14"
TextWrapping="Wrap">
<Run Text="当前布线的电机:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding Motor.MotorModelStr}" />
<Run Text=" " />
<Run Text="轴号:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectedLine.AxisNo}" />
</TextBlock>
</hc:SimpleStackPanel>
<StackPanel Grid.Row="1" VerticalAlignment="Center">
<TextBlock VerticalAlignment="Center" FontSize="14">
<Run Text="当前线段:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectedLine.CableConnectionClass}" />
<Run Text=" " />
<Run Text="当前线类型:" />
<Run Foreground="{StaticResource DangerBrush}" Text="{Binding SelectedLine.CableType}" />
</TextBlock>
</StackPanel>
<Button
Grid.Row="0"
Grid.RowSpan="2"
Grid.Column="1"
Content="转到电机"
Style="{StaticResource ButtonPrimary}" />
</Grid>
<ListView
Grid.Row="2"
hc:GridViewAttach.ColumnHeaderHeight="10"
@ -106,7 +121,7 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="230" Header="操作">
<!--<GridViewColumn Width="230" Header="操作">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button
@ -116,7 +131,7 @@
Tag="{Binding CableModel}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridViewColumn>-->
</GridView>
</ListView.View>
</ListView>

View File

@ -312,7 +312,7 @@
</TabItem>
<TabItem Header="整理后的数据">
<TabItem Header="多芯线数据">
<!--
RowDetailsVisibilityChanged="LettotypeListView_RowDetailsVisibilityChanged"
RowDetailsVisibilityMode="{Binding DetailsShowMode}"

View File

@ -39,6 +39,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI
{
InitializeComponent();
//_docId = docId;
LectotypeManager.CURRENT_DOC_ID = docId;
this.DataContext = ViewModel = new LectotypeViewModel(docId);
Application.Current.SetMainWindow(this);

View File

@ -21,6 +21,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
{
private const string MESSAGE_KEY = "CableLectotypeMessage";
private readonly MotorExcelHelper motorExcelHelper = MotorExcelHelper.Instance;
private MotorLectotypeService motorService = new MotorLectotypeService();
private Dictionary<string,Dictionary<int,int>> CableTypeIndexs = new Dictionary<string, Dictionary<int, int>>
{
@ -33,27 +34,35 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
/// </summary>
public void Cablerator()
{
SelectedLines?.Clear();
if (string.IsNullOrEmpty(Motor.MotorPower))
{
ShowWarning("电机功率不能为空!");
return;
}
if (EncoderLineParagraph == 0 || PowerLineParagraph == 0)
{
ShowWarning("段数不能为零!");
return;
}
if(IsEnableParagraph)
if (EncoderLineParagraph == 0 || PowerLineParagraph == 0)
{
ShowWarning("段数不能为零!");
return;
}
if (string.IsNullOrEmpty(AxisNo))
{
ShowWarning("轴号不能为空!");
return;
}
if (string.IsNullOrEmpty(CableType))
if (string.IsNullOrEmpty(CableTypePrimary))
{
ShowWarning("请选择线材类型!");
return;
}
if (CableTypePrimary.Equals(CableTypeSecond))
{
ShowWarning("不能选择同样的线段类型!");
return;
}
int seqNo = 1;
var LectotypeList = new List<LectotypeLineModel>();
var line = new LectotypeLineModel
@ -67,7 +76,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
//DriverInterface = DriverInterface,
//DriverModel = DriverModel,
CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通",
CableType = CableType,
CableType = Motor.Brand == Brands.ANCHUAN ? CableTypePrimary : $"{CableTypePrimary}+{CableTypeSecond}",
//IsFlexibility = IsFlexibility,
//PowerLineLength = PowerLineLength,
//EncoderLineLength = EncoderLineLength,
@ -98,16 +107,16 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
// 安川第一条线不合并,所以需要再次添加另一个类型的线
if (Motor.Brand == Brands.ANCHUAN)
{
var index = CableTypeIndexs[CableType];
var secLineCableType = "";
var flag = index.Keys.First() + index.Values.First();
if (CableType.Contains("刹车") && flag != 1)
{
// 动力线 or 动力刹车线
flag = 0;
}
//else
secLineCableType = CableTypeIndexs.Keys.ToList()[flag];
//var index = CableTypeIndexs[CableTypePrimary];
//var secLineCableType = "";
//var flag = index.Keys.First() + index.Values.First();
//if (CableTypePrimary.Contains("刹车") && flag != 1)
//{
// // 动力线 or 动力刹车线
// flag = 0;
//}
////else
//secLineCableType = CableTypeIndexs.Keys.ToList()[flag];
var secLine = new LectotypeLineModel
{
@ -120,7 +129,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
//DriverInterface = DriverInterface,
//DriverModel = DriverModel,
CableConnectionClass = CableConnectionType == ConnectionType.FullParagraph ? "前段" : "直通",
CableType = secLineCableType,
CableType = CableTypeSecond,
//IsFlexibility = IsFlexibility,
//PowerLineLength = PowerLineLength,
//EncoderLineLength = EncoderLineLength,
@ -162,7 +171,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
//DrawingNo = DrawingNo,
//CableModelNo = CableModelNo,
CableConnectionClass = cableConnectionType,
CableType = CableType.Contains("刹车") ? "动力刹车线" : "动力线",
CableType = CableTypeSecond,
LineCount = PowerLineParagraph,
//PowerLineLength = PowerLineLength,
//CurrentLineNumber = i,
@ -198,7 +207,7 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
//DrawingNo = DrawingNo,
//CableModelNo = CableModelNo,
CableConnectionClass = cableConnectionType,
CableType = "编码器线",
CableType = CableTypePrimary,
LineCount = EncoderLineParagraph,
//PowerLineLength = PowerLineLength,
//CurrentLineNumber = i,
@ -314,18 +323,13 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
_cableConnectionType = value;
OnPropertyChanged(nameof(CableConnectionType));
if (_cableConnectionType == ConnectionType.Passthrough)
IsEnableParagraph = !(_cableConnectionType == ConnectionType.Passthrough);
PowerLineParagraph = 0;
EncoderLineParagraph = 0;
if (!IsEnableParagraph)
{
IsEnableParagraph = false;
PowerLineParagraph = 1;
EncoderLineParagraph = 1;
}
else
{
IsEnableParagraph = true;
PowerLineParagraph = 3;
EncoderLineParagraph = 3;
}
}
}
@ -339,17 +343,26 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
OnPropertyChanged(nameof(AxisNo));
}
}
private string _cableType;
public string CableType
private string _cableTypePrimary;
public string CableTypePrimary
{
get { return _cableType; }
get { return _cableTypePrimary; }
set
{
_cableType = value;
OnPropertyChanged(nameof(CableType));
_cableTypePrimary = value;
OnPropertyChanged(nameof(CableTypePrimary));
}
}
private string _cableTypeSecond;
public string CableTypeSecond
{
get { return _cableTypeSecond; }
set
{
_cableTypeSecond = value;
OnPropertyChanged(nameof(CableTypeSecond));
}
}
private int _encoderLineParagraph;
public int EncoderLineParagraph
{
@ -396,9 +409,9 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
public bool SaveToDb()
{
var service = new MotorLectotypeService();
//var service = new MotorLectotypeService();
// 查找或添加 Motor
return service.SaveMotorLectotypeData(Motor.OccPartId, this);
return motorService.SaveMotorLectotypeData(Motor.OccPartId, this);
}
public event PropertyChangedEventHandler PropertyChanged;
@ -417,7 +430,8 @@ public class CableLectotypeViewModel : INotifyPropertyChanged
Motor = viewModel.Motor;
CableConnectionType = viewModel.CableConnectionType;
AxisNo = viewModel.AxisNo;
CableType = viewModel.CableType;
CableTypePrimary = viewModel.CableTypePrimary;
CableTypeSecond = viewModel.CableTypeSecond;
EncoderLineParagraph = viewModel.EncoderLineParagraph;
PowerLineParagraph = viewModel.PowerLineParagraph;
CableModelStr = viewModel.CableModelStr;