diff --git a/XP.Common/Controls/VirtualJoystick.cs b/XP.Common/Controls/VirtualJoystick.cs
index 14fc43b..3066547 100644
--- a/XP.Common/Controls/VirtualJoystick.cs
+++ b/XP.Common/Controls/VirtualJoystick.cs
@@ -136,6 +136,27 @@ namespace XP.Common.Controls
#endregion
+ #region SwapMouseButtons 依赖属性 | SwapMouseButtons Dependency Property
+
+ public static readonly DependencyProperty SwapMouseButtonsProperty =
+ DependencyProperty.Register(nameof(SwapMouseButtons), typeof(bool), typeof(VirtualJoystick),
+ new PropertyMetadata(false, OnSwapMouseButtonsChanged));
+
+ /// 是否交换左右键功能 | Whether to swap left and right button functions
+ public bool SwapMouseButtons
+ {
+ get => (bool)GetValue(SwapMouseButtonsProperty);
+ set => SetValue(SwapMouseButtonsProperty, value);
+ }
+
+ private static void OnSwapMouseButtonsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is VirtualJoystick joystick)
+ joystick.UpdateIconVisibility();
+ }
+
+ #endregion
+
#region 四向图标依赖属性 | Directional Icon Dependency Properties
// 左键图标 | Left button icons
@@ -185,7 +206,9 @@ namespace XP.Common.Controls
{
base.OnMouseLeftButtonDown(e);
if (_isDragging || !IsEnabled) return;
- StartDrag(MouseButtonType.Left);
+ // 如果启用了左右键交换,则左键触发右键逻辑,反之亦然
+ var buttonType = SwapMouseButtons ? MouseButtonType.Right : MouseButtonType.Left;
+ StartDrag(buttonType);
e.Handled = true;
}
@@ -193,7 +216,9 @@ namespace XP.Common.Controls
{
base.OnMouseRightButtonDown(e);
if (_isDragging || !IsEnabled) return;
- StartDrag(MouseButtonType.Right);
+ // 如果启用了左右键交换,则右键触发左键逻辑,反之亦然
+ var buttonType = SwapMouseButtons ? MouseButtonType.Left : MouseButtonType.Right;
+ StartDrag(buttonType);
e.Handled = true;
}
@@ -233,7 +258,10 @@ namespace XP.Common.Controls
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
- if (!_isDragging || ActiveMouseButton != MouseButtonType.Left) return;
+ if (!_isDragging) return;
+ // 结束拖拽时,根据当前实际按下的按钮类型判断
+ var expectedType = SwapMouseButtons ? MouseButtonType.Right : MouseButtonType.Left;
+ if (ActiveMouseButton != expectedType) return;
EndDrag();
e.Handled = true;
}
@@ -241,7 +269,10 @@ namespace XP.Common.Controls
protected override void OnMouseRightButtonUp(MouseButtonEventArgs e)
{
base.OnMouseRightButtonUp(e);
- if (!_isDragging || ActiveMouseButton != MouseButtonType.Right) return;
+ if (!_isDragging) return;
+ // 结束拖拽时,根据当前实际按下的按钮类型判断
+ var expectedType = SwapMouseButtons ? MouseButtonType.Left : MouseButtonType.Right;
+ if (ActiveMouseButton != expectedType) return;
EndDrag();
e.Handled = true;
}
@@ -326,16 +357,21 @@ namespace XP.Common.Controls
SetVisibility(Visibility.Visible, defaultTop, defaultBottom, defaultLeft, defaultRight);
// 根据 ActiveMouseButton 切换 | Switch based on ActiveMouseButton
+ // 如果启用了左右键交换,则显示相反的图标组
switch (ActiveMouseButton)
{
case MouseButtonType.Left:
SetVisibility(Visibility.Collapsed, defaultTop, defaultBottom, defaultLeft, defaultRight);
- SetVisibility(Visibility.Visible, leftTop, leftBottom, leftLeft, leftRight);
+ // 如果交换了左右键,这里显示的是右键图标组
+ var leftIcons = SwapMouseButtons ? new[] { rightTop, rightBottom, rightLeft, rightRight } : new[] { leftTop, leftBottom, leftLeft, leftRight };
+ SetVisibility(Visibility.Visible, leftIcons);
if (_thumbElement != null) _thumbElement.Fill = new SolidColorBrush(Color.FromRgb(0x3A, 0x7B, 0xC8));
break;
case MouseButtonType.Right:
SetVisibility(Visibility.Collapsed, defaultTop, defaultBottom, defaultLeft, defaultRight);
- SetVisibility(Visibility.Visible, rightTop, rightBottom, rightLeft, rightRight);
+ // 如果交换了左右键,这里显示的是左键图标组
+ var rightIcons = SwapMouseButtons ? new[] { leftTop, leftBottom, leftLeft, leftRight } : new[] { rightTop, rightBottom, rightLeft, rightRight };
+ SetVisibility(Visibility.Visible, rightIcons);
if (_thumbElement != null) _thumbElement.Fill = new SolidColorBrush(Color.FromRgb(0x5B, 0xA8, 0x5B));
break;
default:
diff --git a/XP.Hardware.MotionControl/Resources/BackPointDisable.png b/XP.Hardware.MotionControl/Resources/BackPointDisable.png
new file mode 100644
index 0000000..88b197f
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/BackPointDisable.png differ
diff --git a/XP.Hardware.MotionControl/Resources/BackPointEnable.png b/XP.Hardware.MotionControl/Resources/BackPointEnable.png
new file mode 100644
index 0000000..0893dd1
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/BackPointEnable.png differ
diff --git a/XP.Hardware.MotionControl/Resources/SavePoint.png b/XP.Hardware.MotionControl/Resources/SavePoint.png
new file mode 100644
index 0000000..a8a9798
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/SavePoint.png differ
diff --git a/XP.Hardware.MotionControl/Resources/SwingDisable.png b/XP.Hardware.MotionControl/Resources/SwingDisable.png
new file mode 100644
index 0000000..89a2cda
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/SwingDisable.png differ
diff --git a/XP.Hardware.MotionControl/Resources/SwingEnable.png b/XP.Hardware.MotionControl/Resources/SwingEnable.png
new file mode 100644
index 0000000..9d6f810
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/SwingEnable.png differ
diff --git a/XP.Hardware.MotionControl/Resources/ToggleDisable.png b/XP.Hardware.MotionControl/Resources/ToggleDisable.png
new file mode 100644
index 0000000..5b6712c
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/ToggleDisable.png differ
diff --git a/XP.Hardware.MotionControl/Resources/ToggleEnable.png b/XP.Hardware.MotionControl/Resources/ToggleEnable.png
new file mode 100644
index 0000000..bd97663
Binary files /dev/null and b/XP.Hardware.MotionControl/Resources/ToggleEnable.png differ
diff --git a/XP.Hardware.MotionControl/ViewModels/AxisControlViewModel.cs b/XP.Hardware.MotionControl/ViewModels/AxisControlViewModel.cs
index 94ebafd..4c7ce5e 100644
--- a/XP.Hardware.MotionControl/ViewModels/AxisControlViewModel.cs
+++ b/XP.Hardware.MotionControl/ViewModels/AxisControlViewModel.cs
@@ -82,6 +82,7 @@ namespace XP.Hardware.MotionControl.ViewModels
// 初始化命令 | Initialize commands
ToggleEnableCommand = new DelegateCommand(ExecuteToggleEnable, () => IsPlcConnected);
+ ToggleSwapMouseButtonsCommand = new DelegateCommand(ExecuteToggleSwapMouseButtons);
SavePositionsCommand = new DelegateCommand(ExecuteSavePositions);
RestorePositionsCommand = new DelegateCommand(ExecuteRestorePositions, () => _savedPositions != null && IsPlcConnected);
@@ -254,6 +255,10 @@ namespace XP.Hardware.MotionControl.ViewModels
/// 摇杆使能状态 | Joystick enable state
public bool IsJoystickEnabled { get => _isJoystickEnabled; set => SetProperty(ref _isJoystickEnabled, value); }
+ private bool _swapMouseButtons;
+ /// 是否交换摇杆左右键功能 | Whether to swap left and right joystick button functions
+ public bool SwapMouseButtons { get => _swapMouseButtons; set => SetProperty(ref _swapMouseButtons, value); }
+
private bool _isPlcConnected;
/// PLC 连接状态 | PLC connection status
public bool IsPlcConnected { get => _isPlcConnected; set => SetProperty(ref _isPlcConnected, value); }
@@ -264,11 +269,21 @@ namespace XP.Hardware.MotionControl.ViewModels
#endregion
+ #region 保存位置状态 | Saved Positions State
+
+ /// 是否有保存的位置数据 | Whether saved position data exists
+ public bool HasSavedPositions => _savedPositions != null;
+
+ #endregion
+
#region 命令 | Commands
/// 切换使能开关命令 | Toggle enable switch command
public DelegateCommand ToggleEnableCommand { get; }
+ /// 切换摇杆左右键功能命令 | Toggle joystick button swap command
+ public DelegateCommand ToggleSwapMouseButtonsCommand { get; }
+
/// 保存当前轴位置命令 | Save current axis positions command
public DelegateCommand SavePositionsCommand { get; }
@@ -375,6 +390,7 @@ namespace XP.Hardware.MotionControl.ViewModels
private void RaiseCommandCanExecuteChanged()
{
ToggleEnableCommand.RaiseCanExecuteChanged();
+ ToggleSwapMouseButtonsCommand.RaiseCanExecuteChanged();
SavePositionsCommand.RaiseCanExecuteChanged();
RestorePositionsCommand.RaiseCanExecuteChanged();
}
@@ -440,6 +456,15 @@ namespace XP.Hardware.MotionControl.ViewModels
// TODO: 发送使能状态到 PLC(根据实际 PLC 信号定义)| Send enable state to PLC (based on actual PLC signal definition)
}
+ ///
+ /// 切换左右键交换状态 | Toggle swap mouse buttons state
+ ///
+ private void ExecuteToggleSwapMouseButtons()
+ {
+ SwapMouseButtons = !SwapMouseButtons;
+ _logger.Info("摇杆左右键功能交换:{Enabled} | Joystick button swap toggled: {Enabled}", SwapMouseButtons);
+ }
+
///
/// 保存当前 6 个轴位置到内部变量 | Save current 6 axis positions to internal variable
///
@@ -456,6 +481,7 @@ namespace XP.Hardware.MotionControl.ViewModels
FixtureRotation = FixtureRotationAngle
};
RestorePositionsCommand.RaiseCanExecuteChanged();
+ RaisePropertyChanged(nameof(HasSavedPositions));
_logger.Info("轴位置已保存 | Axis positions saved");
}
diff --git a/XP.Hardware.MotionControl/Views/AxisControlView.xaml b/XP.Hardware.MotionControl/Views/AxisControlView.xaml
index 4b9acd2..325e094 100644
--- a/XP.Hardware.MotionControl/Views/AxisControlView.xaml
+++ b/XP.Hardware.MotionControl/Views/AxisControlView.xaml
@@ -61,25 +61,25 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -90,6 +90,7 @@
JoystickMode="SingleAxisY"
Width="41" Height="150"
IsEnabled="{Binding IsJoystickEnabled}"
+ SwapMouseButtons="{Binding SwapMouseButtons}"
DefaultTopIcon="↑" DefaultBottomIcon="↓"
LeftButtonTopIcon="SZ↑" LeftButtonBottomIcon="SZ↓"
RightButtonTopIcon="DZ↑" RightButtonBottomIcon="DZ↓"
@@ -100,6 +101,7 @@
JoystickMode="DualAxis"
Width="150" Height="150"
IsEnabled="{Binding IsJoystickEnabled}"
+ SwapMouseButtons="{Binding SwapMouseButtons}"
DefaultTopIcon="↑" DefaultBottomIcon="↓" DefaultLeftIcon="←" DefaultRightIcon="→"
LeftButtonTopIcon="Y+" LeftButtonBottomIcon="Y-" LeftButtonLeftIcon="X-" LeftButtonRightIcon="X+"
RightButtonTopIcon="R+" RightButtonBottomIcon="R-" RightButtonLeftIcon="DT-" RightButtonRightIcon="DT+"
@@ -107,64 +109,110 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
+
+ ToolTip="{loc:Localization AC_Enable}"
+ telerik:StyleManager.Theme="Crystal">
+
+
+
+
+
+
+
+
+
+
+
-
+ ToolTip="{loc:Localization AC_Save}"
+ telerik:StyleManager.Theme="Crystal">
+
+
+
+
-
+ ToolTip="{loc:Localization AC_Restore}"
+ IsEnabled="{Binding HasSavedPositions}"
+ telerik:StyleManager.Theme="Crystal">
+
+
+
+
diff --git a/XP.Hardware.MotionControl/XP.Hardware.MotionControl.csproj b/XP.Hardware.MotionControl/XP.Hardware.MotionControl.csproj
index 1519476..740fc18 100644
--- a/XP.Hardware.MotionControl/XP.Hardware.MotionControl.csproj
+++ b/XP.Hardware.MotionControl/XP.Hardware.MotionControl.csproj
@@ -13,16 +13,29 @@
-
- ResXFileCodeGenerator
- Resources.Designer.cs
-
+
-
- True
- True
- Resources.resx
-
+
+ Never
+
+
+ Never
+
+
+ Never
+
+
+ Never
+
+
+ Never
+
+
+ Never
+
+
+ Never
+
diff --git a/XplorePlane/App.config b/XplorePlane/App.config
index 7465d52..fcf4686 100644
--- a/XplorePlane/App.config
+++ b/XplorePlane/App.config
@@ -148,7 +148,7 @@
-
+
diff --git a/XplorePlane/Views/Main/MainWindow.xaml b/XplorePlane/Views/Main/MainWindow.xaml
index a1995f5..3bec450 100644
--- a/XplorePlane/Views/Main/MainWindow.xaml
+++ b/XplorePlane/Views/Main/MainWindow.xaml
@@ -514,7 +514,7 @@
-
+
-
+
-
-
-
+
+
+
diff --git a/XplorePlane/XplorePlane.csproj b/XplorePlane/XplorePlane.csproj
index df3b7ca..77b0a66 100644
--- a/XplorePlane/XplorePlane.csproj
+++ b/XplorePlane/XplorePlane.csproj
@@ -52,6 +52,7 @@
..\ExternalLibraries\Telerik
..\bin\
+ x64