首次上传

This commit is contained in:
hanqiangqiang
2026-03-24 15:04:02 +08:00
commit 2e080a8764
1392 changed files with 406579 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace SicUI.Controls.Common
{
public class AnimationHelper
{
public static void TranslateX(TranslateTransform translation, int targetX, int ms, Action actionComplete = null)
{
var time = TimeSpan.FromMilliseconds(ms);
var oldValue = translation.X;
var animation = new DoubleAnimation(oldValue, targetX, time);
animation.Completed += (s, e) =>
{
actionComplete?.Invoke();
};
translation.BeginAnimation(TranslateTransform.XProperty, animation);
}
public static void TranslateX(UIElement uIElement, int startX, int targetX, int ms, Action actionComplete = null)
{
var transform = new TranslateTransform();
uIElement.RenderTransform = transform;
var time = TimeSpan.FromMilliseconds(ms);
var animation = new DoubleAnimation(startX, targetX, time);
animation.AutoReverse = false;
animation.Completed += (s, e) =>
{
actionComplete?.Invoke();
};
transform.BeginAnimation(TranslateTransform.XProperty, animation);
}
public static void TranslateY(TranslateTransform translation, int targetY, int ms, Action actionComplete = null)
{
var time = TimeSpan.FromMilliseconds(ms);
var animation = new DoubleAnimation(targetY, time);
animation.Completed += (s, e) =>
{
actionComplete?.Invoke();
};
translation.BeginAnimation(TranslateTransform.YProperty, animation);
}
public static void TranslateYRelative(TranslateTransform translation, int y, int ms, Action actionComplete = null)
{
var currentY = translation.Y;
var time = TimeSpan.FromMilliseconds(ms);
var animation = new DoubleAnimation(currentY + y, time);
animation.Completed += (s, e) =>
{
actionComplete?.Invoke();
};
translation.BeginAnimation(TranslateTransform.YProperty, animation);
}
}
}
+103
View File
@@ -0,0 +1,103 @@
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace SicUI.Controls.Common
{
public class AnimationQueue
{
private ConcurrentQueue<AnimationParameter> queue;
private AutoResetEvent eventHandler;
public event EventHandler<StatusUpdateArgs> StatusUpdated;
private bool idle;
private ReaderWriterLockSlim idleLocker;
private readonly string name;
public AnimationQueue(string name)
{
idleLocker = new ReaderWriterLockSlim();
eventHandler = new AutoResetEvent(false);
queue = new ConcurrentQueue<AnimationParameter>();
idle = true;
this.name = name;
Task.Run(() => Consume());
}
public void EnqueueStatus(AnimationParameter parameter)
{
queue.Enqueue(parameter);
try
{
idleLocker.EnterReadLock();
if (idle)
{
eventHandler.Set();
idle = false;
}
}
finally
{
idleLocker.ExitReadLock();
}
}
public AnimationParameter LastStatus
{
get;
private set;
}
private void Consume()
{
Thread.CurrentThread.Name = name;
while (true)
{
eventHandler.WaitOne();
AnimationParameter parameter = null;
if (queue.TryDequeue(out parameter))
{
LastStatus = parameter;
if (StatusUpdated != null)
{
try
{
idleLocker.EnterWriteLock();
idle = false;
}
finally
{
idleLocker.ExitWriteLock();
}
StatusUpdated(this, new StatusUpdateArgs() { Event = eventHandler, Parameter = parameter });
}
}
else
{
try
{
idleLocker.EnterWriteLock();
idle = true;
}
finally
{
idleLocker.ExitWriteLock();
}
}
}
}
}
public class StatusUpdateArgs : EventArgs
{
public AutoResetEvent Event { get; set; }
public AnimationParameter Parameter { get; set; }
}
public class AnimationParameter
{
public string Target { get; set; }
public string ArmA { get; set; }
public string ArmB { get; set; }
}
}
+128
View File
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SicUI.Controls.Common
{
public class AxisBorder:Border
{
private Storyboard currentStoryboard;
public void Stop()
{
if (currentStoryboard != null)
{
currentStoryboard.Stop(this);
currentStoryboard = null;
}
}
public void MoveToUp(bool isUp, double times, Action onComplete = null)
{
Storyboard storyboard = new Storyboard(); //创建Storyboard对象
int desYPoint = 0;
int orgYPoint = 0;
if (isUp)
{
orgYPoint = 0;
desYPoint = -10;
}
else
{
orgYPoint = -10;
desYPoint = 0;
}
DoubleAnimation doubleAnimation = new DoubleAnimation(orgYPoint, desYPoint, new Duration(TimeSpan.FromMilliseconds(times)));
Storyboard.SetTarget(doubleAnimation, this);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(doubleAnimation);
storyboard.Completed += (s, e) =>
{
InvalidateVisual();
currentStoryboard = null;
onComplete?.Invoke();
};
currentStoryboard = storyboard;
storyboard.Begin();
}
public void MoveToEnd(bool frontToEnd, int times, Action onComplete = null)
{
Path path1 = new Path();
if (frontToEnd)
{
path1.Data = Geometry.Parse("M 0,0 A 300,160 0 0 0 -250,13");
}
else
{
path1.Data = Geometry.Parse("M -250,13 A 300,160 0 0 1 0,0");
}
TranslateTransform translate = new TranslateTransform();
this.RenderTransform = translate;
NameScope.SetNameScope(this, new NameScope());
this.RegisterName("translate", translate);
DoubleAnimationUsingPath animationX = new DoubleAnimationUsingPath();
animationX.PathGeometry = path1.Data.GetFlattenedPathGeometry();
animationX.Source = PathAnimationSource.X;
animationX.Duration = new Duration(TimeSpan.FromMilliseconds(times));
animationX.FillBehavior = FillBehavior.HoldEnd;
DoubleAnimationUsingPath animationY = new DoubleAnimationUsingPath();
animationY.PathGeometry = path1.Data.GetFlattenedPathGeometry();
animationY.Source = PathAnimationSource.Y;
animationY.Duration = animationX.Duration;
animationY.FillBehavior = FillBehavior.HoldEnd;
Storyboard storyboard = new Storyboard();
storyboard.AutoReverse = false;
storyboard.Children.Add(animationX);
storyboard.Children.Add(animationY);
Storyboard.SetTargetName(animationX, "translate");
Storyboard.SetTargetName(animationY, "translate");
Storyboard.SetTargetProperty(animationX, new PropertyPath(TranslateTransform.XProperty));
Storyboard.SetTargetProperty(animationY, new PropertyPath(TranslateTransform.YProperty));
storyboard.Completed += (s, e) =>
{
InvalidateVisual();
currentStoryboard = null;
onComplete?.Invoke();
};
currentStoryboard = storyboard;
storyboard.Begin(this);
}
public void MoveToUpDown(bool toUp,int orgYPoint, int desYPoint, double times, Action onComplete = null)
{
Storyboard storyboard = new Storyboard(); //创建Storyboard对象
DoubleAnimation doubleAnimation = new DoubleAnimation(orgYPoint, desYPoint, new Duration(TimeSpan.FromMilliseconds(times)));
Storyboard.SetTarget(doubleAnimation, this);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(doubleAnimation);
storyboard.Completed += (s, e) =>
{
InvalidateVisual();
currentStoryboard = null;
onComplete?.Invoke();
};
currentStoryboard = storyboard;
storyboard.Begin();
}
}
}
+163
View File
@@ -0,0 +1,163 @@
using System;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace SicUI.Controls.Common
{
public class AxisCanvas : Canvas
{
private Storyboard currentStoryboard;
public bool ShowAxisPoint
{
get { return (bool)GetValue(ShowAxisPointProperty); }
set { SetValue(ShowAxisPointProperty, value); }
}
// Using a DependencyProperty as the backing store for ShowAxisPoint. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ShowAxisPointProperty =
DependencyProperty.Register("ShowAxisPoint", typeof(bool), typeof(AxisCanvas), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty AxisLeftProperty;
static AxisCanvas()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(AxisCanvas), new FrameworkPropertyMetadata(typeof(AxisCanvas)));
AxisLeftProperty = DependencyProperty.Register("AxisLeft", typeof(int), typeof(AxisCanvas), new UIPropertyMetadata(8));
}
public int AxisLeft
{
get
{
return (int)GetValue(AxisLeftProperty);
}
set
{
SetValue(AxisLeftProperty, value);
}
}
protected override void OnRender(DrawingContext dc)
{
base.OnRender(dc);
if (ShowAxisPoint)
{
dc.DrawEllipse(Brushes.Black, new Pen(Brushes.White, 2), new Point(AxisLeft, Height / 2), 5, 5);
}
// var text = new FormattedText(
//CurrentAngle.ToString(),
//CultureInfo.GetCultureInfo("en-us"),
//FlowDirection.LeftToRight,
//new Typeface("Verdana"),
//14,
//Brushes.Black);
// dc.DrawText(text, new Point(AxisLeft, 60));
}
public double CurrentAngle
{
get
{
if (RenderTransform is RotateTransform)
{
return (RenderTransform as RotateTransform).Angle;
}
return 0;
}
}
public void Rotate(int angle, bool absolute = true, int ms = 0, double accelerationRatio = 0, double decelerationRatio = 0, Action onComplete = null)
{
var storyboard = new Storyboard();
storyboard.Completed += (s, e) => onComplete?.Invoke();
if (Rotate(storyboard, angle, absolute, ms, accelerationRatio, decelerationRatio, onComplete))
{
storyboard.Begin();
}
else
{
onComplete?.Invoke();
}
}
public bool Rotate(Storyboard storyboard, int angle, bool absolute = true, int ms = 0, double accelerationRatio = 0, double decelerationRatio = 0, Action onComplete = null)
{
var oldAngle = 0d;
if (RenderTransform is RotateTransform)
{
oldAngle = (RenderTransform as RotateTransform).Angle;
}
var newAngle = absolute ? angle : oldAngle + angle;
if (newAngle == oldAngle)
{
return false;
}
var top = Height / 2;
var leftPoint = new Point(AxisLeft, top);
if (ms <= 0)
{
RenderTransform = new RotateTransform(newAngle, leftPoint.X, leftPoint.Y);
return false;
//InvalidateVisual();
}
else
{
var rotateTransform = new RotateTransform();
rotateTransform.CenterX = leftPoint.X;
rotateTransform.CenterY = leftPoint.Y;
RenderTransform = rotateTransform;
var animation = new DoubleAnimation(oldAngle, newAngle, TimeSpan.FromMilliseconds(ms));
animation.AccelerationRatio = accelerationRatio;
animation.DecelerationRatio = decelerationRatio;
storyboard.Children.Add(animation);
Storyboard.SetTarget(animation, this);
Storyboard.SetTargetProperty(animation, new PropertyPath("RenderTransform.Angle"));
return true;
}
}
public void MoveToUpDown(int orgYPoint, int desYPoint, double times, Action onComplete = null)
{
Storyboard storyboard = new Storyboard(); //创建Storyboard对象
DoubleAnimation doubleAnimation = new DoubleAnimation(orgYPoint, desYPoint, new Duration(TimeSpan.FromMilliseconds(times)));
Storyboard.SetTarget(doubleAnimation, this);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Top)"));
storyboard.Children.Add(doubleAnimation);
storyboard.Completed += (s, e) =>
{
InvalidateVisual();
currentStoryboard = null;
onComplete?.Invoke();
};
currentStoryboard = storyboard;
storyboard.Begin();
}
public void Stop()
{
if (currentStoryboard != null)
{
currentStoryboard.Stop(this);
currentStoryboard = null;
}
}
}
}
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SicUI.Controls.Common
{
public class BodyMovePoint
{
public int LidX;
public int LidY;
}
public class BodyMovePosition
{
public BodyMovePoint StartPosition;
public BodyMovePoint EndPosition;
}
public enum ChamberBodyInfo
{
Head,
TopHead,
MiddleTopHead,
}
}
+49
View File
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace SicUI.Controls.Common
{
public class RelayCommand : ICommand
{
private readonly Func<Object, Boolean> canExecute;
private readonly Action<Object> execute;
public RelayCommand(Action<Object> execute) : this(execute, null)
{
}
public RelayCommand(Action<Object> execute, Func<Object, Boolean> canExecute)
{
this.execute = execute ?? throw new ArgumentNullException("execute");
this.canExecute = canExecute;
}
public event EventHandler CanExecuteChanged
{
add
{
if (canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
public Boolean CanExecute(Object parameter)
{
return canExecute == null ? true : canExecute(parameter);
}
public void Execute(Object parameter)
{
execute(parameter);
}
}
}
+15
View File
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SicUI.Controls.Common
{
public class RobotConstant
{
public const string RobotRetract = "0";
public const string RobotExtend = "1";
public const string UnknownTarget = "Unknown";
}
}
+10
View File
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SicUI.Controls.Common
{
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SicUI.Controls.Common
{
public class RobotPosition
{
public int X;
public int Z;
public int Root;
public int Arm;
public int Hand;
}
public class StationPosition
{
public RobotPosition StartPosition;
public RobotPosition EndPosition;
}
}
+43
View File
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using Aitex.Core.UI.MVVM;
using Aitex.Core.Util;
using Aitex.Core.Utilities;
namespace SicUI.Controls.Common
{
public class ViewModelControl : UserControl, INotifyPropertyChanged, IViewModelControl
{
public event PropertyChangedEventHandler PropertyChanged;
public void SubscribeKeys(SubscriptionViewModelBase baseModel)
{
baseModel.SubscribeKeys(this);
}
public void InvokePropertyChanged()
{
if (PropertyChanged != null)
{
var ps = this.GetType().GetProperties();
foreach (var p in ps)
{
if (!p.GetCustomAttributes(false).Any(attribute => attribute is IgnorePropertyChangeAttribute))
PropertyChanged(this, new PropertyChangedEventArgs(p.Name));
if (p.PropertyType == typeof(ICommand))
{
if (p.GetValue(this, null) is IDelegateCommand cmd)
cmd.RaiseCanExecuteChanged();
}
}
}
}
}
}