1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Misc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
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.Imaging;
using System.Windows.Shapes;
namespace FLY.Thick.Base.UI
{
/// <summary>
/// Window_AHelper.xaml 的交互逻辑
/// </summary>
public partial class WdAbHelper2 : FLY.ControlLibrary.WindowBigClose
{
WdAbHelperVm viewModel;
public double A { get { return viewModel.A; } }
public double B { get { return viewModel.B; } }
//外部值
private double a;
private double b;
public WdAbHelper2()
{
InitializeComponent();
viewModel = new WdAbHelperVm();
this.DataContext = viewModel;
}
public void Init(double a,double b, ParamDictionary paramDictionary)
{
this.a = a;
this.b = b;
viewModel.A = a;
viewModel.B = b;
paramDictionary.SetBinding(viewModel, nameof(viewModel.IsJustB), "AbHelper.IsJustB", true);
}
private void button_cal_Click(object sender, RoutedEventArgs e)
{
if (viewModel.IsJustB)
{
//只是平移补偿
//只有X1,Y1
viewModel.A = a;
viewModel.B = viewModel.Y1 - viewModel.X1 + b;
}
else
{
if ((viewModel.X2 == viewModel.X1) && (viewModel.Y2 != viewModel.Y1))
{
string tit = (string)Application.Current.TryFindResource("str.WdAbHelper.ApplyFailed");
FLY.ControlLibrary.Window_WarningTip.Show(tit, "X2 == X1 but Y2 != Y1", TimeSpan.FromSeconds(2));
return;
}
if ((viewModel.X2 != viewModel.X1) && (viewModel.Y2 == viewModel.Y1))
{
string tit = (string)Application.Current.TryFindResource("str.WdAbHelper.ApplyFailed");
FLY.ControlLibrary.Window_WarningTip.Show(tit, "X2 != X1 but Y2 == Y1", TimeSpan.FromSeconds(2));
return;
}
else if (a == 0)
{
string tit = (string)Application.Current.TryFindResource("str.WdAbHelper.ApplyFailed");
FLY.ControlLibrary.Window_WarningTip.Show(tit, "A==0", TimeSpan.FromSeconds(2));
return;
}
if ((viewModel.X2 == viewModel.X1) && (viewModel.Y2 == viewModel.Y1))
{
viewModel.A = a;
viewModel.B = viewModel.Y2 - viewModel.X2 + b;
}
else
{
double x2 = (viewModel.X2 - b) / a;
double x1 = (viewModel.X1 - b) / a;
viewModel.A = (viewModel.Y2 - viewModel.Y1) / (x2 - x1);
viewModel.B = viewModel.Y2 - viewModel.A * x2;
}
}
{
string tit = (string)Application.Current.TryFindResource("str.WdAbHelper.ApplySuccessfully");
FLY.ControlLibrary.Window_Tip.Show(tit, null, TimeSpan.FromSeconds(2)) ;
}
}
private void button_apply_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
}
public class WdAbHelperVm : INotifyPropertyChanged
{
public double X1 { get; set; }
public double Y1 { get; set; }
public double X2 { get; set; }
public double Y2 { get; set; }
public double A { get; set; }
public double B { get; set; }
public bool IsJustB { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
}