157 lines
6.0 KiB
C#
157 lines
6.0 KiB
C#
using JiangsuEarthquake.Common;
|
|
using JiangsuEarthquake.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.Tracing;
|
|
using System.Linq;
|
|
using System.Numerics;
|
|
using System.Security.Cryptography.Xml;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Media.Media3D;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using static System.Math;
|
|
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
|
using Point = System.Windows.Point;
|
|
using Quaternion = System.Windows.Media.Media3D.Quaternion;
|
|
using UserControl = System.Windows.Controls.UserControl;
|
|
|
|
namespace JiangsuEarthquake.Views.UserControls
|
|
{
|
|
/// <summary>
|
|
/// BaseStationModel.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class BaseStationModel : UserControl
|
|
{
|
|
public BaseStationModel()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
//包装器
|
|
public float Rotate_X
|
|
{
|
|
get { return (float)this.GetValue(Rotate_XProperty); }
|
|
set { this.SetValue(Rotate_XProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty Rotate_XProperty = DependencyProperty.Register("Rotate_X", typeof(float), typeof(BaseStationModel), new PropertyMetadata(default(float), new PropertyChangedCallback(OnPropertyChanged)));
|
|
|
|
public float Rotate_Y
|
|
{
|
|
get { return (float)this.GetValue(Rotate_YProperty); }
|
|
set { this.SetValue(Rotate_YProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty Rotate_YProperty = DependencyProperty.Register("Rotate_Y", typeof(float), typeof(BaseStationModel), new PropertyMetadata(default(float), new PropertyChangedCallback(OnPropertyChanged)));
|
|
|
|
public float Rotate_Z
|
|
{
|
|
get { return (float)this.GetValue(Rotate_ZProperty); }
|
|
set { this.SetValue(Rotate_ZProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty Rotate_ZProperty = DependencyProperty.Register("Rotate_Z", typeof(float), typeof(BaseStationModel), new PropertyMetadata(default(float), new PropertyChangedCallback(OnPropertyChanged)));
|
|
|
|
/// <summary>
|
|
/// 是否可以使用鼠标跟随
|
|
/// </summary>
|
|
public bool TBDEnable
|
|
{
|
|
get { return (bool)this.GetValue(TBDEnableProperty); }
|
|
set { this.SetValue(TBDEnableProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty TBDEnableProperty = DependencyProperty.Register("TBDEnable", typeof(bool), typeof(BaseStationModel), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnPropertyChanged)));
|
|
|
|
|
|
/// <summary>
|
|
/// 是否启用线性动画
|
|
/// </summary>
|
|
public bool AnimationEnable
|
|
{
|
|
get { return (bool)this.GetValue(AnimationEnableProperty); }
|
|
set { this.SetValue(AnimationEnableProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty AnimationEnableProperty = DependencyProperty.Register("AnimationEnable", typeof(bool), typeof(BaseStationModel), new PropertyMetadata(default(bool), new PropertyChangedCallback(OnPropertyChanged)));
|
|
|
|
public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
(d as BaseStationModel).Refresh();
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (AnimationEnable)
|
|
{
|
|
if (this.rotateX.Angle != Rotate_X)
|
|
{
|
|
DoubleAnimation rotationAnimation = new DoubleAnimation(this.rotateX.Angle, Rotate_X - 90, TimeSpan.FromSeconds(2));
|
|
rotateX.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation);
|
|
}
|
|
if (this.rotateY.Angle != Rotate_Y)
|
|
{
|
|
DoubleAnimation rotationAnimation = new DoubleAnimation(this.rotateY.Angle, Rotate_Y - 95, TimeSpan.FromSeconds(2));
|
|
rotateY.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation);
|
|
}
|
|
if (this.rotateZ.Angle != Rotate_Z)
|
|
{
|
|
DoubleAnimation rotationAnimation = new DoubleAnimation(this.rotateZ.Angle, Rotate_Z, TimeSpan.FromSeconds(2));
|
|
rotateZ.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.rotateX.Angle = Rotate_X - 90;
|
|
this.rotateY.Angle = Rotate_Y - 95;
|
|
this.rotateZ.Angle = Rotate_Z;
|
|
}
|
|
|
|
this.angleX.Content = Rotate_X;
|
|
this.angleY.Content = Rotate_Y;
|
|
this.angleZ.Content = Rotate_Z;
|
|
|
|
this.TBD.IsEnabled = TBDEnable;
|
|
}
|
|
|
|
private Point pointBefore;
|
|
|
|
|
|
private void TBD_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
Point currentPosition = e.GetPosition(this);
|
|
|
|
// avoid any zero axis conditions//没有移动
|
|
if (currentPosition == pointBefore) return;
|
|
|
|
// Prefer tracking to zooming if both buttons are pressed.如果按下两个按钮,最好跟踪缩放
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
|
{
|
|
Point pointAfter = e.GetPosition(this);
|
|
|
|
var moveX = pointAfter.X - pointBefore.X;
|
|
var moveY = pointAfter.Y - pointBefore.Y;
|
|
this.angleX.Content = moveY.ToString("0.00");
|
|
this.angleY.Content = moveX.ToString("0.00");
|
|
this.angleZ.Content = Sqrt(moveX * moveX + moveY * moveY).ToString("0.00");
|
|
}
|
|
}
|
|
|
|
|
|
private void TBD_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
pointBefore = e.GetPosition(this);
|
|
}
|
|
}
|
|
}
|