|
|
@@ -60,6 +60,12 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
if (SetProperty(ref _selectedPointInDataGrid, value))
|
|
|
{
|
|
|
SelectedPointInComboBox = value;
|
|
|
+ // update command availability
|
|
|
+ _MovePointUpCommand?.RaiseCanExecuteChanged();
|
|
|
+ _MovePointDownCommand?.RaiseCanExecuteChanged();
|
|
|
+ // 更新依赖可执行状态的命令
|
|
|
+ _TechPointCommand?.RaiseCanExecuteChanged();
|
|
|
+ _ExecuteMotion?.RaiseCanExecuteChanged();
|
|
|
}
|
|
|
// 可以同步到 SelectPoint 属性
|
|
|
SelectedPoint = value;
|
|
|
@@ -163,15 +169,15 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
|
|
|
private DelegateCommand<object> _ExecuteMotion;
|
|
|
public DelegateCommand<object> ExecuteMotion =>
|
|
|
- _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
|
|
|
+ _ExecuteMotion ?? (_ExecuteMotion = new DelegateCommand<object>(ExecuteExecuteMotion).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
|
|
|
|
|
|
private DelegateCommand<object> _JogCommand;
|
|
|
public DelegateCommand<object> JogCommand =>
|
|
|
- _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
|
|
|
+ _JogCommand ?? (_JogCommand = new DelegateCommand<object>(ExecuteJogCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
|
|
|
|
|
|
private DelegateCommand _TechPointCommand;
|
|
|
public DelegateCommand TechPointCommand =>
|
|
|
- _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
|
|
|
+ _TechPointCommand ?? (_TechPointCommand = new DelegateCommand(ExecuteTechPointCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute).ObservesProperty(() => SelectedPointInDataGrid));
|
|
|
|
|
|
private DelegateCommand<string> _MotorCommand;
|
|
|
public DelegateCommand<string> MotorCommand =>
|
|
|
@@ -202,7 +208,12 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
public DelegateCommand DeletePointCommand =>
|
|
|
_DeletePointCommand ?? (_DeletePointCommand = new DelegateCommand(ExecuteDeletePointCommand));
|
|
|
|
|
|
-
|
|
|
+ private DelegateCommand _MovePointUpCommand;
|
|
|
+ public DelegateCommand MovePointUpCommand => _MovePointUpCommand ?? (_MovePointUpCommand = new DelegateCommand(ExecuteMovePointUpCommand, CanMovePointUp));
|
|
|
+
|
|
|
+ private DelegateCommand _MovePointDownCommand;
|
|
|
+ public DelegateCommand MovePointDownCommand => _MovePointDownCommand ?? (_MovePointDownCommand = new DelegateCommand(ExecuteMovePointDownCommand, CanMovePointDown));
|
|
|
+
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
@@ -318,6 +329,10 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
/// <param name="obj"></param>
|
|
|
async void ExecuteExecuteMotion(object parameter)
|
|
|
{
|
|
|
+ if (parameter == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
var values = (object[])parameter;
|
|
|
var point = values[0] as RPoint;
|
|
|
MotionCommand motionCmd = (MotionCommand)values[1];
|
|
|
@@ -354,6 +369,8 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
async void ExecuteTechPointCommand()
|
|
|
{
|
|
|
if (Robot == null || !Robot.IsConnected) return;
|
|
|
+ if (SelectedPoint == null) return;
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
var curpos = await Robot.GetRobotPosAsync();
|
|
|
@@ -460,14 +477,12 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- if (Robot != null)
|
|
|
- {
|
|
|
- return Robot.CanExecute;
|
|
|
- }
|
|
|
- else
|
|
|
+ // 命令可执行仅当机器人可执行且已选择点位
|
|
|
+ if (Robot != null && Robot.CanExecute)
|
|
|
{
|
|
|
- return false;
|
|
|
+ return SelectedPointInDataGrid != null;
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -511,6 +526,9 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
{
|
|
|
Number = Points.Count + 1,
|
|
|
});
|
|
|
+ // update commands
|
|
|
+ _MovePointUpCommand?.RaiseCanExecuteChanged();
|
|
|
+ _MovePointDownCommand?.RaiseCanExecuteChanged();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -518,16 +536,89 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
/// </summary>
|
|
|
void ExecuteDeletePointCommand()
|
|
|
{
|
|
|
- if (SelectedPoint==null)
|
|
|
+ if (SelectedPoint == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
+ // 确认删除
|
|
|
+ if (MessageBox.Show("确认要删除选中的点位吗?", "删除点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int removedIndex = Points.IndexOf(SelectedPoint);
|
|
|
Points.Remove(SelectedPoint);
|
|
|
//重新编号
|
|
|
- for (int i = 1; i < Points.Count; i++)
|
|
|
+ for (int i = 0; i < Points.Count; i++)
|
|
|
{
|
|
|
Points[i].Number = i + 1;
|
|
|
}
|
|
|
+ // adjust selection
|
|
|
+ if (Points.Count > 0)
|
|
|
+ {
|
|
|
+ int newIndex = Math.Min(removedIndex, Points.Count - 1);
|
|
|
+ SelectedPointInDataGrid = Points[newIndex];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SelectedPointInDataGrid = null;
|
|
|
+ }
|
|
|
+ // update commands
|
|
|
+ _MovePointUpCommand?.RaiseCanExecuteChanged();
|
|
|
+ _MovePointDownCommand?.RaiseCanExecuteChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool CanMovePointUp()
|
|
|
+ {
|
|
|
+ return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool CanMovePointDown()
|
|
|
+ {
|
|
|
+ return SelectedPointInDataGrid != null && Points.IndexOf(SelectedPointInDataGrid) >= 0 && Points.IndexOf(SelectedPointInDataGrid) < Points.Count - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 向上移动点位
|
|
|
+ /// </summary>
|
|
|
+ void ExecuteMovePointUpCommand()
|
|
|
+ {
|
|
|
+ if (SelectedPointInDataGrid == null) return;
|
|
|
+ // 确认移动
|
|
|
+ if (MessageBox.Show("确认将选中点位上移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int idx = Points.IndexOf(SelectedPointInDataGrid);
|
|
|
+ if (idx <= 0) return;
|
|
|
+ var item = SelectedPointInDataGrid;
|
|
|
+ Points.Move(idx, idx - 1);
|
|
|
+ // renumber
|
|
|
+ for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
|
|
|
+ SelectedPointInDataGrid = item;
|
|
|
+ _MovePointUpCommand?.RaiseCanExecuteChanged();
|
|
|
+ _MovePointDownCommand?.RaiseCanExecuteChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 向下移动点位
|
|
|
+ /// </summary>
|
|
|
+ void ExecuteMovePointDownCommand()
|
|
|
+ {
|
|
|
+ if (SelectedPointInDataGrid == null) return;
|
|
|
+ // 确认移动
|
|
|
+ if (MessageBox.Show("确认将选中点位下移一位吗?", "移动点位", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int idx = Points.IndexOf(SelectedPointInDataGrid);
|
|
|
+ if (idx < 0 || idx >= Points.Count - 1) return;
|
|
|
+ var item = SelectedPointInDataGrid;
|
|
|
+ Points.Move(idx, idx + 1);
|
|
|
+ // renumber
|
|
|
+ for (int i = 0; i < Points.Count; i++) Points[i].Number = i + 1;
|
|
|
+ SelectedPointInDataGrid = item;
|
|
|
+ _MovePointUpCommand?.RaiseCanExecuteChanged();
|
|
|
+ _MovePointDownCommand?.RaiseCanExecuteChanged();
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -556,7 +647,7 @@ namespace TeamAAS_VP.ViewModels.Product
|
|
|
SelectedIndex = 0;
|
|
|
Points = SelectProduct.PickCameraPoints;
|
|
|
|
|
|
- if (Robot==null)
|
|
|
+ if (Robot == null)
|
|
|
{
|
|
|
Robot = _robotService.GetRobotByNumber(1);
|
|
|
}
|