UserControlOne.xaml.cs
54.4 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using OS.Spin.ViewModle.Models;
using OS.Spin.View.Utils;
using OS.Spin.ViewModle.Flaw;
using OS.Spin.Common;
using OS.Spin.View.Windows;
using OS.Spin.Modle.BusinessLayer;
using System.Windows.Input;
namespace OS.Spin.View.MainWindowControls
{
/// <summary>
/// UserControlOne.xaml 的交互逻辑
/// </summary>
public partial class UserControlOne : UserControl
{
public UserControlOne()
{
InitializeComponent();
}
/// <summary>
/// 添加瑕疵点数据
/// </summary>
/// <param name="image"></param>
public void addDefectMap(ImageData image)
{
if (image != null)
{
label.addImageData(image);
}
}
/// <summary>
/// 控制瑕疵点选择态和非选择态之间的转换
/// </summary>
/// <param name="image"></param>
public void changeDefectMap(ImageData image)
{
try
{
//1、获取图片数据集合
List<ImageData> data = label.GetImageDatas();
//2、该点在图片数据集合中是否存在(若存在则转换,不存在则返回)
int a = 0;
for (int i = 0; i < data.Count; i++) //操纵图片数据list集合
{
if (a == 1) //找到就直接退出
{
continue;
}
ImageData imageData = data[i];
if (imageData.StartX == image.StartX && imageData.StartY == image.StartY) //此图标在集合中存在
{
a = 1;
//如果这个点存在则改变它的状态
if (imageData.Choice == 0)
{
imageData.Type = 2;
imageData.Choice = 1;
}
else if (imageData.Choice == 1)
{
imageData.Type = 1;
imageData.Choice = 0;
}
}
}
//3、重新加载最新的数据
addLable(label.getListObject().Count);
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("changeDefectMap:{0}", ex.Message));
}
}
/// <summary>
/// 默认初始化瑕疵点是选择态还是非选择态
/// </summary>
/// <param name="choice"></param>
public void showDefectMap(int choice)
{
try
{
//获取图标数据集合
List<ImageData> imageDatas = label.GetImageDatas();
if (imageDatas.Count == 0 || imageDatas == null)
{
return;
}
//获取控件的实际高度和宽度
int width = (int)addLabel.ActualWidth; //该Canvas控件的实际宽度
int height = (int)addLabel.ActualHeight; //该Canvas控件的实际高度
LabelData labelData = label.getLabelData(); //存放标签刻度的JavaBean
int start = labelData.Start; //刻度起始值
int end = labelData.End; //刻度终止值
int number = label.getListObject().Count;
int addNumber = (end - start) / (number - 1); //标签的间隔数值
//double space = (double)height / number; //每一间隔所对应的纵坐标值
//新添加的逻辑
double reallyInterval = (double)(998 - 69) / (number - 1); //实际标签之间的间隔百分比
double reallyLeftInterval = (double)18 / 469; //标签左边实际间隔百分比
double userControlX = (double)reallyLeftInterval * width; //实际起始横坐标
double userControlY = (double)69 / 1066 * height; //实际起始纵坐标
//标签实际间隔
double space = (double)(reallyInterval / 1066) * height;
//1、将前面的选择态置为非选择,或是将非选择置为选择
if (choice == 0) //将状态置为选择1
{
for (int i = 0; i < imageDatas.Count; i++)
{
imageDatas[i].Type = 1;
imageDatas[i].Choice = 0;
//如果是1直接显示圆(表示选择态)
double pWidth = imageDatas[i].StartX;
double pHeight = imageDatas[i].StartY;
if (pWidth > 2.2 || pHeight > end || pHeight < start)
{
continue;
}
//根据该瑕疵点的长度和宽度计算点的位置
//double x = pWidth * width / 2.2 ; //横坐标
//double y = (pHeight - start) / addNumber * space ; //纵坐标
UserControlReal userControlReal = new UserControlReal();
FlawsView.Children.Add(userControlReal);
//Canvas.SetLeft(userControlReal, x); //这里可能还要做数据的转换
//Canvas.SetTop(userControlReal, y); //比如米数和坐标系对应距离的转换
Canvas.SetLeft(userControlReal, GetReallyX(pWidth, true));
Canvas.SetTop(userControlReal, GetReallyY(pHeight, true));
}
}
else if (choice == 1) //将状态置为选择2
{
for (int i = 0; i < imageDatas.Count; i++)
{
imageDatas[i].Type = 2;
imageDatas[i].Choice = 1;
double pWidth = imageDatas[i].StartX;
double pHeight = imageDatas[i].StartY;
if (pWidth > 2.2 || pHeight > end || pHeight < start)
{
continue;
}
//根据该瑕疵点的长度和宽度计算点的位置
//double x = pWidth * width / 2.2 -5; //横坐标
//double y = (pHeight - start) / addNumber * space ; //纵坐标
UserControlEmpty userControlEmpty = new UserControlEmpty();
FlawsView.Children.Add(userControlEmpty);
//Canvas.SetLeft(userControlEmpty, x);
//Canvas.SetTop(userControlEmpty, y);
Canvas.SetLeft(userControlEmpty, GetReallyX(pWidth));
Canvas.SetTop(userControlEmpty, GetReallyY(pHeight));
}
//如果是2直接显示(表示非选择态)
}
else
{
return;
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("showDefectMap:{0}", ex.Message));
}
}
/// <summary>
/// 获取非选择态瑕疵点集合
/// </summary>
/// <returns></returns>
public List<ImageData> getNonChoiceImageData()
{
try
{
List<ImageData> images = label.GetImageDatas();
List<ImageData> nonChoice = new List<ImageData>();
for (int i = 0; i < images.Count; i++)
{
if (images[i].Choice == 0)
{
nonChoice.Add(images[i]);
}
}
if (nonChoice != null && nonChoice.Count > 0)
{
return nonChoice;
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("getNonChoiceImageData:{0}", ex.Message));
}
return null;
}
/// <summary>
/// 获取选择态瑕疵点集合
/// </summary>
/// <returns></returns>
public List<ImageData> getChoiceImageData()
{
try
{
List<ImageData> imageDatas = label.GetImageDatas();
List<ImageData> nonChioce = getNonChoiceImageData();
if (nonChioce != null && nonChioce.Count > 0)
{
for (int i = 0; i < nonChioce.Count; i++)
{
imageDatas.Remove(nonChioce[i]);
}
}
return imageDatas;
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("getChoiceImageData:{0}", ex.Message));
return null;
}
}
/// <summary>
/// 删除所有瑕疵点数据
/// </summary>
public void clearImage()
{
try
{
int width = (int)this.Width; //窗体的宽度(用户计算点的坐标)
int height = (int)this.Height; //窗体的高度(用于计算子控件的坐标和间距)
int userControlX = 0; //子控件的横坐标
int userControlY = 0; //子控件的纵坐标
//你这里内存确实清空了,但是界面并没有清空
label.clearImageData(); //清空图片数据
//清空界面
addLabel.Children.Clear();
FlawsView.Children.Clear();
//重新加载Label和刻度值
LabelData data = label.getLabelData(); //获取起始值和终值
int start = data.Start;
int end = data.End;
//获取标签集
List<UserControl1> list = label.getListObject();
//添加标签
int space = height / list.Count; //设置均值和标签高度
int num = (end - start) / list.Count;
for (var i = 0; i < list.Count; i++)
{
start += num;
//UserControl1 userControl = new UserControl1();
list[i].Height = space;
list[i].Width = width;
addLabel.Children.Add(list[i]);
//label.addLabels(userControl); //这里看一下是否还需要重新添加到内存中
list[i].LableText.runtimes = start;
//设置用户控件在Canvas中的位置
Canvas.SetLeft(list[i], userControlX);
Canvas.SetTop(list[i], userControlY);
userControlY += space;
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("clearImage:{0}", ex.Message));
}
}
/// <summary>
/// 设置显示瑕疵点的位置,主要由以下三种:
/// 1、只设置起点 2、只设置终点 3、既设置起点也设置终点
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
public void setUpDisPlay(double a, double b) //比如(30,60)就只显示此区域之间的点坐标
{
try
{
//List<ImageData> images = label.GetImageDatas(); //获取图标直角坐标系中的坐标
//List<ImageData> effect = new List<ImageData>(); //存放有效数据
//LabelData labelData = label.getLabelData(); //获取默认设置的初始值和终止值
////保存本次设置数据
//SetData setData = label.getSetData();
//setData.Start = a;
//setData.End = b;
//int start = labelData.Start; //最新设置的起始值
//int end = labelData.End; //最新设置的终止值
//int number = label.getListObject().Count; //标签个数
//int addNumber = (end - start) / number; //标签间隔数值
//int width = (int)this.ActualWidth;
//int height = (int)this.ActualHeight;
//double userControlX = 0; //子控件的横坐标
//double userControlY = 0; //子控件的纵坐标
// //int number = LabelUtils.getNumbers(); //获取内存中标签的个数
//double space = height / number; //获取等分距离
// //输入数据合法性校验
//if (b < start || a > end || a < start || b > end)
//{
// return;
//}
////1、默认情况加载当前区域的有效图片
//if (a == 0 && b == 0) //默认情况下就是现实当前区域的有效图片数据
//{
// // LabelData labelData = label.getLabelData(); //获取最新输入的起始值和终点值
// //只要加载当前默认起点和终点位之间的值即可
// for (int i = 0; i < images.Count; i++)
// {
// ImageData data = images[i];
// if (data.StartY >= start && data.StartY <= end)
// {
// if (!effect.Contains(data))
// {
// effect.Add(data);
// }
// }
// }
//}
////2、只设置起点值
//if (a != 0 && b == 0)
//{
// //这里可以假想每一匹布的总长度是固定
// //我这里只是控制图标在布匹上的不同范围内的显示而已
// //设置筛选条件
// for (int i = 0; i < images.Count; i++)
// {
// ImageData data = images[i];
// if (data.StartY >= a) //大于起点值的图像才显示
// {
// if (!effect.Contains(data))
// { //如果没有该图标且满足条件就添加
// effect.Add(data);
// }
// }
// }
//}
////3、只设置终点值
//if (a == 0 && b != 0)
//{
// for (int i = 0; i < images.Count; i++)
// {
// ImageData data = images[i];
// if (data.StartY < b)
// {
// if (!effect.Contains(data))
// {
// effect.Add(data);
// }
// }
// }
//}
////4、设置起点值和终点值
//if (a != 0 && b != 0)
//{
// for (int i = 0; i < images.Count; i++)
// {
// ImageData data = images[i];
// if (data.StartY >= a && data.StartY <= b)
// {
// if (!effect.Contains(data))
// {
// effect.Add(data);
// }
// }
// }
//}
////5、将有效数据展示出来
////(1)刚开始时默认加载的是设置初始值和终点值之间的图像全部显示出来
////所以第一步先要清理界面的数据(只清除界面上的数据而不清楚内存中的数据)
////显示符合条件的数据集合
//if (effect.Count > 0) //该区域存在图标
//{
// addLabel.Children.Clear(); //清空所有的子控件
// FlawsView.Children.Clear();
// List<UserControl1> list = label.getListObject();
// //添加标签
// //double space = height / list.Count; //标签间隔对应的纵坐标值
// //int num = (end - start) / list.Count;
// for (var i = 0; i < list.Count; i++)
// {
// start += addNumber;
// //UserControl1 userControl = new UserControl1();
// list[i].Height = space;
// list[i].Width = width;
// addLabel.Children.Add(list[i]);
// //label.addLabels(userControl); //这里看一下是否还需要重新添加到内存中
// list[i].LableText.runtimes = start;
// //设置用户控件在Canvas中的位置
// Canvas.SetLeft(list[i], userControlX);
// Canvas.SetTop(list[i], userControlY);
// userControlY += space;
// }
// //显示符合条件的该区域的图标
// for (var j = 0; j < effect.Count; j++)
// {
// ImageData image = effect[j];
// int bgin = labelData.Start;
// double x = image.StartX * width / 2.2;
// double y = (image.StartY - bgin) / addNumber * space;
// //double x = image.StartX * width / 2.2; //布匹的实际宽度
// //double y = image.StartY * height / end;
// if (image.Choice == 0) //选择
// {
// UserControlReal userControlReal = new UserControlReal();
// FlawsView.Children.Add(userControlReal);
// //Canvas.SetLeft(userControlReal, x); //这里可能还要做数据的转换
// //Canvas.SetTop(userControlReal, y ); //比如米数和坐标系对应距离的转换
// Canvas.SetLeft(userControlReal, GetReallyX(image.StartX, true));
// Canvas.SetTop(userControlReal, GetReallyY(image.StartY, true));
// }
// else if (image.Choice == 1)
// {
// UserControlEmpty userControlEmpty = new UserControlEmpty();
// FlawsView.Children.Add(userControlEmpty);
// //Canvas.SetLeft(userControlEmpty, x-5);
// //Canvas.SetTop(userControlEmpty, y);
// Canvas.SetLeft(userControlEmpty, GetReallyX(image.StartX));
// Canvas.SetTop(userControlEmpty, GetReallyY(image.StartY));
// }
// else
// {
// return; //数据类型存入错误
// }
// }
//}
//else
//{
// return; //该区域不存在直接返回
//}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("setUpDisPlay:{0}", ex.Message));
}
}
//获取单例实例
LabelUtils label = LabelUtils.getInstance();
/// <summary>
/// 默认创建标签个数
/// 1、如果存在初始值和终止值则默认赋值
/// 2、如果存在瑕疵点,则默认加载瑕疵点
/// </summary>
/// <param name="number"></param>
public void addLable(int number)
{
try
{
if (number == 0) //非空校验
{
return;
}
//新添加的逻辑
double reallyInterval = (double)(998 - 69) / (number - 1); //实际标签之间的间隔百分比
double reallyLeftInterval = (double)18 / 469; //标签左边实际间隔百分比
double width = (double)addLabel.ActualWidth;
double height = (double)addLabel.ActualHeight;
//标签实际起始横纵坐标
double userControlX = (double)reallyLeftInterval * width;
double userControlY = (double)69 / 1066 * height;
//标签实际间隔
double space = (double)(reallyInterval / 1066) * height;
label.deleteLabels(); //清空前面的List
addLabel.Children.Clear(); //添加之前先清除界面上所有的UserControl,所以这里并不需要对UserControl1对象保存
FlawsView.Children.Clear();
//循环开始前应该先加载cm标签
//该标签的纵坐标
double startSpace = (double)49 / 1066 * height;
double bY = (double)20 / 1066 * height;
label.getUserControl3().Height = startSpace; //加载刻度值标签(cm或m)
label.getUserControl3().Width = width;
addLabel.Children.Add(label.getUserControl3());
Canvas.SetLeft(label.getUserControl3(), userControlX);
Canvas.SetTop(label.getUserControl3(), bY);
for (var i = 1; i <= number; i++)
{
UserControl1 userControl = new UserControl1();
userControl.Height = space; //子标签的高度等于等间距的高度
userControl.Width = width; //子标签的宽度等于控件窗体的宽度
addLabel.Children.Add(userControl); //动态的添加用户控件
label.addLabels(userControl); //将新创建的标签集合添加到内存标签集合中
//设置用户控件在Canvas中的位置
Canvas.SetLeft(userControl, userControlX);
Canvas.SetTop(userControl, userControlY);
//添加完了所有的label之后再动态的添加最后一个全局缩放按钮
//if (i == number) //循环结束时(这里需要详细的计算其位置)
//{
// double bx = (double)127 / 431 * width;
// double by = (double)730 / 809 * height;
// addLabel.Children.Add(label.getUserControl2());
// //Canvas.SetLeft(label.getUserControl2(), bx);
// //Canvas.SetTop(label.getUserControl2(), userControlY);
// Canvas.SetLeft(label.getUserControl2(), bx);
// Canvas.SetTop(label.getUserControl2(), by);
//}
userControlY += space;
}
LabelData labelD = label.getLabelData();
int start = labelD.Start;
int end = labelD.End;
List<UserControl1> list = label.getListObject();
int addNumber = (end - start) / (list.Count);
if (label.isNull()) //不为空,则重新加载显示数据
{
showBingData(start, end);
}
//动态加载图标数据
if (label.isNullImageData())
{
//获取内存中的数据集合
List<ImageData> images = label.GetImageDatas();
int begin = labelD.Start;
//遍历赋值
for (var j = 0; j < images.Count; j++)
{
ImageData data = images[j];
double x = data.StartX * width / 2.2;
double y = (data.StartY - begin) / (addNumber - 1) * space;
y = (data.StartY - begin) * (addNumber - 1) * space / (end - start) + 10;
//判断它是加载的哪种类型的图片
if (data.Choice == 0)
{
UserControlReal userControlReal = new UserControlReal();
FlawsView.Children.Add(userControlReal);
//Canvas.SetLeft(userControlReal, x); //这里可能还要做数据的转换
//Canvas.SetTop(userControlReal, y); //比如米数和坐标系对应距离的转换
Canvas.SetLeft(userControlReal, GetReallyX(data.StartX, true));
Canvas.SetTop(userControlReal, GetReallyY(data.StartY, true));
}
else if (data.Choice == 1)
{
UserControlEmpty userControlEmpty = new UserControlEmpty();
FlawsView.Children.Add(userControlEmpty);
//Canvas.SetLeft(userControlEmpty, x-5);
//Canvas.SetTop(userControlEmpty, y);
Canvas.SetLeft(userControlEmpty, GetReallyX(data.StartX));
Canvas.SetTop(userControlEmpty, GetReallyY(data.StartY));
}
}
}
//加载上次的设值显示
if (label.isNullSetData())
{
double a = label.getSetData().Start;
double b = label.getSetData().End;
setUpDisPlay(a, b);
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("addLable:{0}", ex.Message));
}
}
private double _minY = 0;
private double _maxY = 50;
private double _minX = 0;
private double _maxX = 2.2;
public void AddFlaw(MFlawInfo flaw)
{
try
{
//var flawInfo = Selected(flaw.Id);
if (FlawsView.Children.Count == 15)
{
FlawsView.Children.RemoveRange(0, 3);
//FlawsView
}
for (int i = 0; i < 3; i++)
{
Image img = new Image();
img.Width = 320;
img.Height = 160;
img.Tag = "Camera_" + (i + 1);
img.MouseLeftButtonDown += Img_MouseLeftButtonDown;
img.Margin = new Thickness(0, 10, 0, 0);
img.Source = OS.Spin.Common.UserConvert.Mat2BitmapSource(flaw.Mats[i]);
FlawsView.Children.Add(img);
scroll.ScrollToEnd();
}
//scroll.ScrollToBottom();
//if (flaw.CenterY > _maxY - 5)
//{
// MakeChangeY(_maxY + 50);
//}
//var fv = new UCFlawArm(flaw)
//{
// Width = 25,
// Height = 25
//};
//this.FlawsView.Children.Add(fv);
//SetReallyLocation(fv);
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("AddFlaw:{0}", ex.Message));
}
}
private void Img_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//MFlawSnapView flaw = (MFlawSnapView)(sender as Image).Tag;
if (e.ClickCount == 2)
{
var fv = FlawView.GetInstance((sender as Image).Source, (sender as Image).Tag.ToString());
fv.WindowState = WindowState.Maximized;
fv.Topmost = true;
fv.Focus();
fv.Show();
}
}
private const int LableCount = 23;
private void MakeChangeY(double y)
{
try
{
_maxY = y;
var space = (_maxY - _minY) / (LableCount);
var cText = space;
foreach (var c in addLabel.Children)
{
var text = c as UserControl1;
if (null == text)
{
continue;
}
text.textData.Text = cText.ToString("f1");
cText += space;
}
foreach (var f in FlawsView.Children)
{
var flaw = f as UCFlawArm;
if (null == flaw)
{
continue;
}
SetReallyLocation(flaw);
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("MakeChangeY:{0}", ex.Message));
}
}
private UCFlawArm _selected = null;
public void Zero()
{
FlawsView.Children.Clear();
//MakeChangeY(50);
_selected = null;
}
public MFlawSnapView Selected(string id)
{
try
{
if (null != _selected)
{
_selected.IsSelected = false;
}
UCFlawArm flaw = null;
foreach (var f in FlawsView.Children)
{
flaw = f as UCFlawArm;
if (null == flaw)
{
continue;
}
if (id.Equals(flaw.FlawInfo.Id))
{
break;
}
}
_selected = flaw;
if (null != _selected)
{
_selected.IsSelected = true;
return flaw.FlawInfo;
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("Selected:{0}", ex.Message));
}
return null;
}
private void SetReallyLocation(UCFlawArm flaw)
{
var left = GetReallyX(flaw.FlawInfo.CenterX) - flaw.Width / 2;
var top = GetReallyY(flaw.FlawInfo.CenterY) - flaw.Height / 2;
Canvas.SetTop(flaw, top);
Canvas.SetLeft(flaw, left);
}
private double GetReallyX(double x)
{
return this.FlawsView.ActualWidth / (_maxX - _minX) * (x - _minX);
}
private double GetReallyY(double y)
{
return this.FlawsView.ActualHeight / (_maxY - _minY) * (y - _minY);
}
private double _endData = -1;
/// <summary>
/// 给标签动态绑定设值
/// </summary>
/// <param name="startData"></param>
/// <param name="endData"></param>
public void showBingData(int startData, int endData)
{
try
{
if (_endData.Equals(endData))
{
return;
}
_endData = endData;
//并且这里没调用一次就需要更新这个startData,endData
//最好的方法是封装成一个类
//直接覆盖更新,保证是最新数据
LabelData labelData = label.getLabelData();
labelData.Start = startData; //保存起始值
labelData.End = endData; //保存终点值
////检测一下赋值过程是否成功
////MessageBox.Show(labelData.ToString());
List<UserControl1> list = label.getListObject();
int addNumber = (endData - startData) / (list.Count - 1);
for (var i = 0; i < list.Count; i++)
{
list[i].LableText.runtimes = startData;
//list[i].LableText.runtimes = endData;
//list[i].DataContext = startData;
startData += addNumber;
//endData -= addNumber;
if (startData > endData)
{
return;
}
}
setUpDisPlay(labelData.Start, labelData.End);
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("showBingData:{0}", ex.Message));
}
}
/// <summary>
/// 鼠标拖动位置改变图标和标签的位置
/// 1、changX代表鼠标改变的水平位置
/// 2、changY代表鼠标改变的水平位置(因为这里暂时只做数据的上下改变所以只需要纵向坐标即可)
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public void changeWithMouse(double changX, double changY)
{
try
{
//重新规划数据,哪些需要重新设计和布局的
//1、清空画布上的所有显示元素包括(标签、图标)
//addLabel.Children.Clear();
FlawsView.Children.Clear();
#region 注释
////2、重新计算当前标签的位置
//double width = (double)addLabel.ActualWidth;
//double height = (double)addLabel.ActualHeight - changY;
//int number = label.getListObject().Count;
//int userControlX = 0; //子控件的横坐标
//double userControlY = 0; //子控件的纵坐标
//double space = (double)height / number;
//label.deleteLabels(); //清空前面的List
//for (var i = 1; i <= number; i++)
//{
// UserControl1 userControl = new UserControl1();
// userControl.Height = space; //子标签的高度等于等间距的高度
// userControl.Width = width; //子标签的宽度等于控件窗体的宽度
// addLabel.Children.Add(userControl); //动态的添加用户控件
// label.addLabels(userControl);
// //设置用户控件在Canvas中的位置
// Canvas.SetLeft(userControl, userControlX);
// Canvas.SetTop(userControl, userControlY);
// userControlY += space;
//}
#endregion
LabelData labelD = label.getLabelData();
#region 注释
//int start = labelD.Start;
//int end = labelD.End;
//List<UserControl1> list = label.getListObject();
//int addNumber = (end - start) / (list.Count);
////动态加载标签刻度
//if (label.isNull())
//{
// for (var i = 0; i < list.Count; i++)
// {
// start += addNumber;
// list[i].LableText.runtimes = start;
// if (start > end)
// {
// return;
// }
// }
//}
#endregion
if (label.isNullImageData())
{
//获取内存中的数据集合
List<ImageData> images = label.GetImageDatas();
int begin = labelD.Start;
//遍历赋值
for (var j = 0; j < images.Count; j++)
{
ImageData data = images[j];
//double x = data.StartX * width / 2.2;
//double y = (data.StartY - begin) / addNumber * space;
//判断它是加载的哪种类型的图片
if (data.Choice == 0)
{
UserControlReal userControlReal = new UserControlReal();
FlawsView.Children.Add(userControlReal);
//Canvas.SetLeft(userControlReal, x ); //这里可能还要做数据的转换
//Canvas.SetTop(userControlReal, y); //比如米数和坐标系对应距离的转换
Canvas.SetLeft(userControlReal, GetReallyX(data.StartX, true));
Canvas.SetTop(userControlReal, GetReallyY(data.StartY, true));
}
else if (data.Choice == 1)
{
UserControlEmpty userControlEmpty = new UserControlEmpty();
FlawsView.Children.Add(userControlEmpty);
//Canvas.SetLeft(userControlEmpty, x -5);
//Canvas.SetTop(userControlEmpty, y);
Canvas.SetLeft(userControlEmpty, GetReallyX(data.StartX));
Canvas.SetTop(userControlEmpty, GetReallyY(data.StartY));
}
}
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("changeWithMouse:{0}", ex.Message));
}
}
/// <summary>
/// 随窗体自适应改变重新加载赋值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AddLabel_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (null == sender || label.getListObject().Count == 0)
{
return;
}
//1、自适应重新加载Label
//2、自适应重新加载标签刻度
//重新加载图片的坐标(只要坐标一改变就重新加载)
//3、自适应重新加载图标
//addLable(label.getListObject().Count);
}
SquareBoxUtils squareBoxUtils = SquareBoxUtils.getInstance();
/// <summary>
/// 点击瑕疵图片重新加载显示瑕疵点的状态(一次加载cm标签、瑕疵点、全局放大按钮)
/// </summary>
/// <param name="defectShowDatas"></param>
public void reloadDefectShowData(List<DefectShowData> defectShowDatas)
{
try
{
DefectShowData defectShowData = null;
List<OS.Spin.View.Utils.ControlUserOne> controlUserOnes = squareBoxUtils.getUserControlFathers();
//这一步我只要找到是哪个瑕疵点照片被点击了
for (var i = 0; i < controlUserOnes.Count; i++)
{
int ground = controlUserOnes[i].ground;
int j = 0;
if (j == 1) //已经找到了就直接退出
{
continue;
}
if (ground == 1)
{
j++;
OS.Spin.View.SquareBox.UserControOne userControOne = controlUserOnes[i].userControOne;
StackPanel stackPanel = userControOne.StackPanel;
//找到下面显示数据的用户控件
OS.Spin.View.SquareBox.UserControl1 userControl1 = (OS.Spin.View.SquareBox.UserControl1)stackPanel.Children[2];
//UserControl1的父StackPanel
StackPanel stackFather = userControl1.StackPanel;
StackPanel stackOne = (StackPanel)stackFather.Children[0]; //破洞
TextBlock textOne = (TextBlock)stackOne.Children[1];
String hole = textOne.Text; // 取role值
StackPanel stackTwo = (StackPanel)stackFather.Children[1]; //尺寸
TextBlock textTwo = (TextBlock)stackTwo.Children[1];
String size = textTwo.Text; //取size值
StackPanel stackThree = (StackPanel)stackFather.Children[2]; //属性
TextBlock textThree = (TextBlock)stackThree.Children[1];
String attribute = textThree.Text;
//能够比较的前提是瑕疵点照片没有重复的两张照片
defectShowData = new DefectShowData(hole, size, attribute);
}
}
//直接清空该画布
//addLabel.Children.Clear();
FlawsView.Children.Clear();
//获取控件的实际高度和宽度
int width = (int)addLabel.ActualWidth; //该Canvas控件的实际宽度
int height = (int)addLabel.ActualHeight; //该Canvas控件的实际高度
LabelData labelData = label.getLabelData(); //存放标签刻度的JavaBean
int start = labelData.Start; //刻度起始值
int end = labelData.End; //刻度终止值
int number = label.getListObject().Count;
//addLable(number);
//int addNumber = (end - start) / (number - 1); //标签的间隔数值
// //double space = (double)height / number; //每一间隔所对应的纵坐标值
// //新添加的逻辑
//double reallyInterval = (double)(998 - 69) / (number - 1); //实际标签之间的间隔百分比
//double reallyLeftInterval = (double)18 / 469; //标签左边实际间隔百分比
//double userControlX = (double)reallyLeftInterval * width; //实际起始横坐标
//double userControlY = (double)69 / 1066 * height; //实际起始纵坐标
// //标签实际间隔
//double space = (double)(reallyInterval / 1066) * height;
double pWidth = 0;
double pHeight = 0;
//double x = 0;
//double y = 0;
////循环开始前应该先加载cm标签
////该标签的纵坐标
//double startSpace = (double)49 / 1066 * height;
//double bY = (double)20 / 1066 * height;
//label.getUserControl3().Height = startSpace; //加载刻度值标签(cm或m)
//label.getUserControl3().Width = width;
//addLabel.Children.Add(label.getUserControl3());
//Canvas.SetLeft(label.getUserControl3(), userControlX);
//Canvas.SetTop(label.getUserControl3(), bY);
//if (label.isNull()) //不为空,则重新加载显示数据
//{
// showBingData(start, end);
//}
for (var j = 0; j < defectShowDatas.Count; j++)
{
//对比首先不为空,如果存在就改变,如果不存在则不改变(只有破洞,尺寸,属性都对上才证明是这个瑕疵点)
if (null != defectShowData && defectShowData.hole.Equals(defectShowDatas[j].hole) &&
defectShowData.size.Equals(defectShowDatas[j].size) &&
defectShowData.attribute.Equals(defectShowDatas[j].attribute))
{
pWidth = defectShowDatas[j].defectWidth;
pHeight = defectShowDatas[j].defectHeight;
if (pWidth > 2.2 || pHeight > end || pHeight < start)
{
continue;
}
//根据该瑕疵点的长度和宽度计算点的位置
//x = pWidth * width / 2.2 - 5; //横坐标
//y = (pHeight - start) / addNumber * space ; //纵坐标
UserControlEmpty userControlReal = new UserControlEmpty();
FlawsView.Children.Add(userControlReal);
//Canvas.SetLeft(userControlReal, x); //这里可能还要做数据的转换
//Canvas.SetTop(userControlReal, y); //比如米数和坐标系对应距离的转换
Canvas.SetLeft(userControlReal, GetReallyX(pWidth));
Canvas.SetTop(userControlReal, GetReallyY(pHeight));
}
else
{
//如果是1直接显示圆(表示选择态)
pWidth = defectShowDatas[j].defectWidth;
pHeight = defectShowDatas[j].defectHeight;
if (pWidth > 2.2 || pHeight > end || pHeight < start)
{
continue;
}
//根据该瑕疵点的长度和宽度计算点的位置
//x = pWidth * width / 2.2 ; //横坐标
//y = (pHeight - start) / addNumber * space ; //纵坐标
UserControlReal userControlReal = new UserControlReal();
FlawsView.Children.Add(userControlReal);
//Canvas.SetLeft(userControlReal, x ); //这里可能还要做数据的转换
//Canvas.SetTop(userControlReal, y); //比如米数和坐标系对应距离的转换
Canvas.SetLeft(userControlReal, GetReallyX(pWidth, true));
Canvas.SetTop(userControlReal, GetReallyY(pHeight, true));
}
//if (j == defectShowDatas.Count) //循环结束时(这里需要详细的计算其位置)
//{
// double bx = (double)127 / 431 * width;
// double by = (double)730 / 809 * height;
// addLabel.Children.Add(label.getUserControl2());
// //Canvas.SetLeft(label.getUserControl2(), bx);
// //Canvas.SetTop(label.getUserControl2(), userControlY);
// Canvas.SetLeft(label.getUserControl2(), bx);
// Canvas.SetTop(label.getUserControl2(), by);
//}
}
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("reloadDefectShowData:{0}", ex.Message));
}
}
/// <summary>
/// 初始化根据瑕疵图片来加载瑕疵点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
//List<DefectShowData> defectShowDatas = squareBoxUtils.getDefectShowDatas(); //获取瑕疵点数据
////注册瑕疵图片状态改变函数(注册委托)
//DefectShowDelegateUtil defectShowDelegateUtil = squareBoxUtils.getDefectShowDelegateUtil();
//defectShowDelegateUtil.defectShowDelegate += reloadDefectShowData;
//if (defectShowDatas.Count == 0 || defectShowDatas == null) //假如从内存中没有取到数据(说明还没有瑕疵点数据传过来)
//{
// return;
//}
////获取控件的实际高度和宽度
//int width = (int)addLabel.ActualWidth; //该Canvas控件的实际宽度
//int height = (int)addLabel.ActualHeight; //该Canvas控件的实际高度
//LabelData labelData = label.getLabelData(); //存放标签刻度的JavaBean
//int start = labelData.Start; //刻度起始值
//int end = labelData.End; //刻度终止值
//int number = label.getListObject().Count; //获取标签个数
////计算瑕疵点的实际坐标
//double reallyInterval = (double)(998 - 69) / (number - 1); //实际标签之间的间隔百分比
//double reallyLeftInterval = (double)18 / 469; //标签左边实际间隔百分比
//double userControlX = (double)reallyLeftInterval * width; //实际起始横坐标
//double userControlY = (double)69 / 1066 * height; //实际起始纵坐标
////标签实际间隔
//double space = (double)(reallyInterval / 1066) * height;
//for (int i = 0; i < defectShowDatas.Count; i++)
//{
// ////如果是1直接显示圆(表示选择态)
// double pWidth = defectShowDatas[i].defectWidth;
// double pHeight = defectShowDatas[i].defectHeight;
// if (pWidth > 2.2 || pHeight > end || pHeight < start)
// {
// continue;
// }
// //默认是未选中状态,即开始是小圆圈
// //double x = pWidth * width / 2.2; //横坐标
// //double y = (pHeight - start) / addNumber * space; //纵坐标
// UserControlReal userControlReal = new UserControlReal();
// FlawsView.Children.Add(userControlReal);
// //Canvas.SetLeft(userControlReal, x); //这里可能还要做数据的转换
// //Canvas.SetTop(userControlReal, y); //比如米数和坐标系对应距离的转换
// Canvas.SetLeft(userControlReal, GetReallyX(pWidth, true));
// Canvas.SetTop(userControlReal, GetReallyY(pHeight, true));
//}
try
{
////新添加的逻辑
//double reallyInterval = (double)(998 - 69) / (LableCount - 1); //实际标签之间的间隔百分比
//double reallyLeftInterval = (double)18 / 469; //标签左边实际间隔百分比
//double width = (double)addLabel.ActualWidth;
//double height = (double)addLabel.ActualHeight;
////标签实际起始横纵坐标
//double userControlX = (double)reallyLeftInterval * width;
//double userControlY = (double)69 / 1066 * height;
////标签实际间隔
//double space = (double)(reallyInterval / 1066) * height;
////循环开始前应该先加载cm标签
////该标签的纵坐标
//double startSpace = (double)49 / 1066 * height;
//double bY = (double)20 / 1066 * height;
//var lableCm = new UserControl3();
//lableCm.Height = startSpace; //加载刻度值标签(cm或m)
//lableCm.Width = width;
//addLabel.Children.Add(lableCm);
//Canvas.SetLeft(lableCm, userControlX);
//Canvas.SetTop(lableCm, bY);
//for (var i = 1; i <= LableCount; i++)
//{
// UserControl1 userControl = new UserControl1();
// userControl.Height = space; //子标签的高度等于等间距的高度
// userControl.Width = width; //子标签的宽度等于控件窗体的宽度
// addLabel.Children.Add(userControl); //动态的添加用户控件
// label.addLabels(userControl); //将新创建的标签集合添加到内存标签集合中
// //设置用户控件在Canvas中的位置
// Canvas.SetLeft(userControl, userControlX);
// Canvas.SetTop(userControl, userControlY);
// userControlY += space;
//}
//MakeChangeY(50);
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("UserControl_Loaded:{0}", ex.Message));
}
}
/// <summary>
/// 获取真实的Y轴坐标
/// </summary>
/// <param name="y"></param>
/// <param name="isSelected"></param>
/// <returns></returns>
private double GetReallyY(double y, bool isSelected = false)
{
try
{
var r = label.getLabelData();
var perY = this.FlawsView.ActualHeight / (r.End - r.Start);
var center = 17;
if (isSelected)
{
center -= 5;
}
var data = perY * (y - r.Start) - center;
return data;
}
catch (Exception ex)
{
LogisTrac.WriteLog(string.Format("GetReallyY:{0}", ex.Message));
return 0;
}
}
/// <summary>
/// 获取真实的x轴坐标
/// </summary>
/// <param name="x"></param>
/// <param name="isSelected"></param>
/// <returns></returns>
public double GetReallyX(double x, bool isSelected = false)
{
var perX = this.FlawsView.ActualWidth / 2.2;
var head = 17;
if (isSelected)
{
head -= 5;
}
return perX * x - head;
}
private Point _startPosition;
//滚动条当前位置
private double _startVerticalOffset;
private void scroll_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
{
//获取ScrollViewer滚动条当前位置
_startVerticalOffset = scroll.VerticalOffset;
_startPosition = e.GetTouchPoint(this).Position;
scroll.TouchMove -= Scroll_TouchMove;
scroll.TouchMove += Scroll_TouchMove;
}
private void Scroll_TouchMove(object sender, System.Windows.Input.TouchEventArgs e)
{
//获取相对于ScrollViewer的触摸点位置
TouchPoint endPoint = e.GetTouchPoint(this);
//计算相对位置
double diffOffsetY = endPoint.Position.Y - _startPosition.Y;
//ScrollViewer滚动到指定位置(指定位置=起始位置-移动的偏移量,滚动方向和手势方向相反)
scroll.ScrollToVerticalOffset(_startVerticalOffset - diffOffsetY);
}
private void scroll_TouchUp(object sender, TouchEventArgs e)
{
scroll.TouchMove -= Scroll_TouchMove;
}
}
}