-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrawListManagerWpf.xaml.cs
1633 lines (1339 loc) · 64.9 KB
/
DrawListManagerWpf.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using Aveva.Pdms.Database;
using Aveva.Pdms.Geometry;
using Aveva.Pdms.Graphics;
using Aveva.Pdms.Maths.Geometry;
using Aveva.Pdms.Shared;
using Aveva.Pdms.Utilities.CommandLine;
using Aveva.PDMS.Database.Filters;
using Brushes = System.Windows.Media.Brushes;
using cmd = Aveva.Pdms.Utilities.CommandLine.Command;
using FontFamily = System.Windows.Media.FontFamily;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.Forms.MessageBox;
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
using Point = System.Windows.Point;
using Rectangle = System.Windows.Shapes.Rectangle;
using SelectionChangedEventArgs = System.Windows.Controls.SelectionChangedEventArgs;
using TextBox = System.Windows.Controls.TextBox;
namespace Polymetal.Pdms.Design.DrawListManager
{
/// <summary>
/// Логика взаимодействия для DrawListManagerWpf.xaml
/// </summary>
public partial class DrawListManagerWpf : Window
{
private const double Minz = -5000.0;
private const double Maxz = 25000.0;
internal static double Scale;
private static readonly List<List<D2Point>> CoordList = new List<List<D2Point>>();
private static readonly List<D2FiniteLine> Horizontal = new List<D2FiniteLine>();
private static readonly List<D2FiniteLine> Vertical = new List<D2FiniteLine>();
private bool _clickSelect;
private Rectangle _selRect;
private readonly Rectangle _limitrect = new Rectangle();
internal static int ZLength;
internal static double ZCentr;
private Point _orig;
private bool _exec = true;
private readonly SettingsForm _sf = new SettingsForm();
private readonly List<LimitsBox> _limits = new List<LimitsBox>();
private readonly DrawList _dList = Aveva.Pdms.Graphics.DrawListManager.Instance.CurrentDrawList;
private PickPoint.PointSelectedEventHandler _selectedpoint;
private int Selit;
private LimitsBox LimitBoxR;
private LimitsBox _lb;
private double HeightOfLb;
private double WidthOfLb;
private Position2D P1 = Position2D.Create();
private Position2D P2 = Position2D.Create();
private Position2D P3 = Position2D.Create();
private Position2D P4 = Position2D.Create();
internal static readonly Dictionary<string, Rectangle> LimitsInfo = new Dictionary<string, Rectangle>();
internal static readonly Dictionary<string, Rectangle> SmallRectsInfo = new Dictionary<string, Rectangle>();
private List<ExistLimits> existLimitsLst=new List<ExistLimits>();
private List<TabItem> lstaddTabItem=new List<TabItem>();
public DrawListManagerWpf()
{
InitializeComponent();
SetSliderInitializeValue();
LimitOfAxes();
Height = 680;
Width = 680;
}
#region Slider
#region Events
void Slider_MouseUp(object sender, MouseButtonEventArgs e)
{
ScrollingOfValues(LowerSlider, UpperSlider);
}
private void LowerSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (Math.Abs(UpperSlider.Value - LowerSlider.Value) < 100)
UpperSlider.Value = LowerSlider.Value + 100;
UpperSlider.Value = Math.Max(UpperSlider.Value, LowerSlider.Value);
LowerSliderValue.Text = ((int)Math.Floor(LowerSlider.Value)).ToString();
}
private void UpperSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (Math.Abs(UpperSlider.Value - LowerSlider.Value) < 100)
LowerSlider.Value = UpperSlider.Value - 100;
LowerSlider.Value = Math.Min(UpperSlider.Value, LowerSlider.Value);
UpperSliderValue.Text = ((int)Math.Ceiling(UpperSlider.Value)).ToString();
}
private void TextChangedev(object sender, TextChangedEventArgs e)
{
var textBox = (TextBox)sender;
var text = textBox.Text;
var tempText = "";
for (var i = 0; i < text.Length; i++)
{
var ch = text[i];
if (ch < 58 && ch > 47 || ch.Equals('-') && i == 0)
{
tempText += ch;
}
}
var selStart = textBox.SelectionStart;
textBox.Text = tempText;
textBox.Select(selStart > textBox.Text.Length ? textBox.Text.Length : selStart, 0);
}
private void UpperSliderValue_OnKeyUp(object sender, KeyEventArgs e)
{
int newval;
if (!int.TryParse(UpperSliderValue.Text, out newval)) return;
if (newval >= Minz & newval <= Maxz)
{
UpperSlider.Value = newval;
}
else
{
MessageBox.Show(@"Введены недопустимые значения. Значения должны быть от -5000 до 25000", @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
UpperSlider.Value = UpperSlider.Maximum;
}
}
private void LowerSliderValue_OnKeyUp(object sender, KeyEventArgs e)
{
int newval;
if (!int.TryParse(LowerSliderValue.Text, out newval)) return;
if (newval >= Minz & newval <= Maxz)
{
LowerSlider.Value = newval;
}
else
{
MessageBox.Show(@"Введены недопустимые значения. Значения должны быть от -5000 до 25000", @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
LowerSlider.Value = LowerSlider.Minimum;
}
}
private void UpperSliderValue_OnMouseEnter(object sender, MouseEventArgs e)
{
UpperSliderValue.ToolTip = "Введите верхнюю границу LimitBox";
}
private void LowerSliderValue_OnMouseEnter(object sender, MouseEventArgs e)
{
LowerSliderValue.ToolTip = "Введите нижнюю границу LimitBox";
}
#endregion
#region Helpers
private void ScrollingOfValues(RangeBase min, RangeBase max)
{
if (max.Value - min.Value < 100) return;
ZLength = (int)Math.Abs(max.Value - min.Value);
ZCentr = min.Value + ZLength / 2.0;
foreach (var pair in LimitsInfo)
{
Command.CreateCommand("AID CLEAR BOX " + pair.Key).Run();
LimitsBoxes(pair.Value, ZCentr, ZLength, pair.Key, Selit);
}
}
private void SetSliderInitializeValue()
{
LowerSlider.ValueChanged += LowerSlider_ValueChanged;
UpperSlider.ValueChanged += UpperSlider_ValueChanged;
LowerSlider.Minimum = Minz;
LowerSlider.Maximum = Maxz - 100;
UpperSlider.Minimum = Minz + 100;
UpperSlider.Maximum = Maxz;
LowerSlider.Value = 0;
UpperSlider.Value = 3000;
ZLength = (int)Math.Abs(UpperSlider.Value - LowerSlider.Value);
ZCentr = LowerSlider.Value + ZLength / 2.0;
LowerSliderValue.Text = LowerSlider.Value.ToString(CultureInfo.InvariantCulture);
UpperSliderValue.Text = UpperSlider.Value.ToString(CultureInfo.InvariantCulture);
}
private void GetExistLimit()
{
try
{
var world = DbElement.GetElement("/*");
foreach (var site in world.Members(DbElementTypeInstance.SITE))
{
var curMDB = MDB.CurrentMDB.Name.Replace("-", "");
var splName = site.GetAsString(DbAttributeInstance.FLNN).Split('-')[0];
if (!(site.GetAsString(DbAttributeInstance.PURP).ToUpper().Equals("AXES") && curMDB.Equals(splName)))
continue;
foreach (DbElement member in site.Members().Where(member => member.GetAsString(DbAttributeInstance.NAME) == "/TMPL_DRWL"))
{
existLimitsLst = new List<ExistLimits>();
existLimitsLst = GetAllExistLimits(member);
}
}
CreateTabItem(existLimitsLst);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void CreateTabItem(List<ExistLimits> lstLimits)
{
foreach (TabItem tabItem in lstaddTabItem)
{
TabControlDrwLst.Items.Remove(tabItem);
}
lstaddTabItem.Clear();
List<DbElement> distList = lstLimits.Select(existLimitse => existLimitse.MarkHeight).Distinct().ToList();
foreach (DbElement element in distList)
{
TabItem addtab = new TabItem
{
Header = element.GetAsString(DbAttributeInstance.DESC),
Content = new TabNewUserControl(CoordList, Horizontal, Vertical, Scale, HeightOfLb, WidthOfLb,
P2, SmallRectsInfo, lstLimits.Where(x => x.MarkHeight == element).ToList())
};
TabControlDrwLst.Items.Add(addtab);
lstaddTabItem.Add(addtab);
}
}
private List<ExistLimits> GetAllExistLimits(DbElement zoneExist)
{
try
{
return (from equiElement in zoneExist.Members()
where equiElement.GetAsString(DbAttributeInstance.TYPE) == "EQUI"
from subEquiElement in equiElement.Members()
where subEquiElement.GetAsString(DbAttributeInstance.TYPE) == "SUBE"
from boxElement in subEquiElement.Members()
where boxElement.GetAsString(DbAttributeInstance.TYPE) == "BOX"
select new ExistLimits
{
BoxElementRegion = boxElement, RegionMark = subEquiElement, MarkHeight = equiElement
}).ToList();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return null;
}
private void LimitOfAxes()
{
var world = DbElement.GetElement("/*");
foreach (var site in world.Members(DbElementTypeInstance.SITE))
{
var curMDB = MDB.CurrentMDB.Name.Replace("-", "");
var splName = site.GetAsString(DbAttributeInstance.FLNN).Split('-')[0];
if (!(site.GetAsString(DbAttributeInstance.PURP).ToUpper().Equals("AXES") && curMDB.Equals(splName)))
continue;
Spatial.Instance.LimitsBox(site, out LimitBoxR);
P1.X = LimitBoxR.Minimum.X;
P1.Y = LimitBoxR.Minimum.Y;
P2.X = LimitBoxR.Minimum.X;
P2.Y = LimitBoxR.Maximum.Y;
P3.X = LimitBoxR.Maximum.X;
P3.Y = LimitBoxR.Maximum.Y;
P4.X = LimitBoxR.Maximum.X;
P4.Y = LimitBoxR.Minimum.Y;
WidthOfLb = P1.Distance(P4);
HeightOfLb = P1.Distance(P2);
if (WidthOfLb > HeightOfLb)
{
var koef = WidthOfLb / HeightOfLb;
Height = this.MinHeight;
Width = (Height * (int)koef);
}
else if (WidthOfLb < HeightOfLb)
{
var koef = HeightOfLb / WidthOfLb;
Width = this.MinWidth;
Height = (Width * (int)koef);
}
else
{
Width = 750;
Height = 750;
}
}
}
private void SelectedItemTab1(int selecteditem)
{
if (textBoxVX.Text.Equals("") || textBoxVY.Text.Equals("") || textBoxVZ.Text.Equals("") ||
textBoxPX.Text.Equals("") || textBoxPY.Text.Equals("") || textBoxPZ.Text.Equals(""))
{
MessageBox.Show(@"Введите значения в соответствующие поля", @"Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning);
button1.IsEnabled = false;
button2.IsEnabled = false;
return;
}
if (Convert.ToInt32(textBoxVX.Text) == 0 || Convert.ToInt32(textBoxVX.Text) < 0)
{
MessageBox.Show(@"Нулевой/отрицательный объем недопустим. Введите значения больше нуля", @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBoxVX.Text = "";
button1.IsEnabled = false;
button2.IsEnabled = false;
return;
}
else if (Convert.ToInt32(textBoxVY.Text) == 0 || Convert.ToInt32(textBoxVY.Text) < 0)
{
MessageBox.Show(@"Нулевой/отрицательный объем недопустим. Введите значения больше нуля", @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
textBoxVY.Text = "";
button1.IsEnabled = false;
button2.IsEnabled = false;
return;
}
else if (Convert.ToInt32(textBoxVZ.Text) == 0 || Convert.ToInt32(textBoxVZ.Text) < 0)
{
MessageBox.Show(@"Нулевой/отрицательный объем недопустим. Введите значения больше нуля", @"Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
textBoxVZ.Text = "";
button1.IsEnabled = false;
button2.IsEnabled = false;
return;
}
button1.IsEnabled = true;
button2.IsEnabled = true;
var p1 = Position.Create();
p1.X = Convert.ToInt32(textBoxPX.Text) - Convert.ToInt32(textBoxVX.Text) / 2;
p1.Y = Convert.ToInt32(textBoxPY.Text) - Convert.ToInt32(textBoxVY.Text) / 2;
p1.Z = Convert.ToInt32(textBoxPZ.Text) - Convert.ToInt32(textBoxVZ.Text) / 2;
var p2 = Position.Create();
p2.X = Convert.ToInt32(textBoxPX.Text) + Convert.ToInt32(textBoxVX.Text) / 2;
p2.Y = Convert.ToInt32(textBoxPY.Text) + Convert.ToInt32(textBoxVY.Text) / 2;
p2.Z = Convert.ToInt32(textBoxPZ.Text) + Convert.ToInt32(textBoxVZ.Text) / 2;
_lb = LimitsBox.Create(p1, p2);
if (_lb != null)
{
switch (selecteditem)
{
case 0:
cmd.CreateCommand("AID CLEAR BOX 666").Run();
cmd.CreateCommand("AID BOX NUMBER 666 AT " + _lb.Centre() +
" XLENGTH " + Math.Round(_lb.Maximum.X - _lb.Minimum.X).ToString() +
" YLENGTH " + Math.Round(_lb.Maximum.Y - _lb.Minimum.Y).ToString() +
" ZLENGTH " + Math.Round(_lb.Maximum.Z - _lb.Minimum.Z).ToString() +
" FILL OFF").Run();
break;
case 1:
cmd.CreateCommand("AID CLEAR BOX 666").Run();
break;
case 2:
cmd.CreateCommand("AID CLEAR BOX 666").Run();
cmd.CreateCommand("AID BOX NUMBER 666 AT " + _lb.Centre() +
" XLENGTH " + Math.Round(_lb.Maximum.X - _lb.Minimum.X).ToString() +
" YLENGTH " + Math.Round(_lb.Maximum.Y - _lb.Minimum.Y).ToString() +
" ZLENGTH " + Math.Round(_lb.Maximum.Z - _lb.Minimum.Z).ToString() +
" FILL ON").Run();
break;
default:
cmd.CreateCommand("AID CLEAR BOX 666").Run();
cmd.CreateCommand("AID BOX NUMBER 666 AT " + _lb.Centre() +
" XLENGTH " + Math.Round(_lb.Maximum.X - _lb.Minimum.X).ToString() +
" YLENGTH " + Math.Round(_lb.Maximum.Y - _lb.Minimum.Y).ToString() +
" ZLENGTH " + Math.Round(_lb.Maximum.Z - _lb.Minimum.Z).ToString() +
" FILL OFF").Run();
break;
}
}
else
{
MessageBox.Show(@"Нет LimitBox для построения", @"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LimitsList()
{
foreach (var smallrect in SmallRectsInfo)
{
if (!smallrect.Value.Fill.Equals(Brushes.Red)) continue;
foreach (var rect in LimitsInfo)
{
if (!smallrect.Key.Equals(rect.Key)) continue;
var widthOfRect =
(int)
Math.Sqrt(Math.Pow((rect.Value.Margin.Left - rect.Value.Margin.Right), 2.0) +
Math.Pow((rect.Value.Margin.Top - rect.Value.Margin.Top), 2.0));
var heightOfRect =
(int)
Math.Sqrt(Math.Pow((rect.Value.Margin.Left - rect.Value.Margin.Left), 2.0) +
Math.Pow((rect.Value.Margin.Top - rect.Value.Margin.Bottom), 2.0));
var centerOfLb = Position.Create();
var koefA = (LimitBoxR.Minimum.X - 10 / Scale) * Scale;
var koefB = (LimitBoxR.Maximum.Y - 10 / Scale) * Scale;
centerOfLb.X = ((rect.Value.Margin.Left + rect.Value.Margin.Right) / 2.0 + koefA) /
Scale;
centerOfLb.Y = (((rect.Value.Margin.Top + rect.Value.Margin.Bottom) / 2.0 - koefB - 20) /
Scale) *
Math.Cos(Math.PI);
centerOfLb.Z = ZCentr;
var p1 = Position.Create(centerOfLb.X - widthOfRect / 2.0 / Scale,
centerOfLb.Y - heightOfRect / 2.0 / Scale, centerOfLb.Z - ZLength);
var p2 = Position.Create(centerOfLb.X + widthOfRect / 2.0 / Scale,
centerOfLb.Y + heightOfRect / 2.0 / Scale, centerOfLb.Z + ZLength);
var lb = LimitsBox.Create(p1, p2);
_limits.Add(lb);
}
}
}
#endregion
#region Dependency Properties
public double MinimumValue
{
get { return (double)GetValue(MinimumValueProperty); }
set { SetValue(MinimumValueProperty, value); }
}
public static readonly DependencyProperty MinimumValueProperty =
DependencyProperty.Register("MinimumValue", typeof(double), typeof(Slider), new UIPropertyMetadata(0d));
public double LowerValue
{
get { return (double)GetValue(LowerValueProperty); }
set { SetValue(LowerValueProperty, value); }
}
public static readonly DependencyProperty LowerValueProperty =
DependencyProperty.Register("LowerValue", typeof(double), typeof(Slider), new UIPropertyMetadata(0d));
public double UpperValue
{
get { return (double)GetValue(UpperValueProperty); }
set { SetValue(UpperValueProperty, value); }
}
public static readonly DependencyProperty UpperValueProperty =
DependencyProperty.Register("UpperValue", typeof(double), typeof(Slider), new UIPropertyMetadata(0d));
public double MaximumValue
{
get { return (double)GetValue(MaximumValueProperty); }
set { SetValue(MaximumValueProperty, value); }
}
public static readonly DependencyProperty MaximumValueProperty =
DependencyProperty.Register("MaximumValue", typeof(double), typeof(Slider), new UIPropertyMetadata(1d));
#endregion
#endregion
#region canvas
#region Events
private void DrwstEditWind_Loaded(object sender, RoutedEventArgs e)
{
DrawingLimits();
ScrollingOfValues(LowerSlider, UpperSlider);
}
private void DrawingLb_SizeChanged(object sender, SizeChangedEventArgs e)
{
DrawingLimits();
}
private void DrawingLb_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed) return;
if (_orig.X.Equals(0.0) && _orig.Y.Equals(0.0)) return;
GetSelRectangle(_orig, e.GetPosition(canvas), _selRect);
foreach (var rec in canvas.Children)
{
if (!(rec.GetType().Name.Equals("Rectangle"))) continue;
var rect = (Rectangle)rec;
if (!rect.Name.StartsWith("NewRect")) continue;
var brush = _clickSelect ? Brushes.Transparent : Brushes.Red;
if (_selRect.IntersectsWith(rect))
{
rect.Fill = brush;
}
else
{
rect.Fill = (SmallRectsInfo.Any(x => x.Value.Equals(rect))) ? Brushes.Red : Brushes.Transparent;
}
Mouse.Capture(_limitrect);
}
}
private void DrawingLb_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
try
{
if (canvas.Children.Contains(_selRect)) canvas.Children.Remove(_selRect);
if (_orig.X.Equals(0.0) && _orig.Y.Equals(0.0)) return;
if (_orig != e.GetPosition(canvas))
{
foreach (var rect in canvas.Children)
{
if (!(rect.GetType().Name.Equals("Rectangle"))) continue;
var wrect = (Rectangle)rect;
if (!wrect.Name.StartsWith("NewRect")) continue;
var key = wrect.Name.Replace("NewRect", "");
if (!_selRect.IntersectsWith((wrect))) continue;
if (_clickSelect)
{
LimitsInfo.Remove(key);
SmallRectsInfo.Remove(key);
wrect.Fill = Brushes.Transparent;
Command.CreateCommand("AID CLEAR BOX " + key).Run();
}
else
{
wrect.Fill = Brushes.Red;
foreach (var elem in canvas.Children)
{
if (!(elem.GetType().Name.Equals("Rectangle"))) continue;
var rectan = (Rectangle)elem;
if (!rectan.Name.StartsWith("Rect")) continue;
var rectname = rectan.Name.Replace("Rect", "");
if (!rectname.Equals(key)) continue;
DictionaryFilling(LimitsInfo, key, rectan);
DictionaryFilling(SmallRectsInfo, key, wrect);
LimitsBoxes(rectan, ZCentr, ZLength, key, Selit);
}
}
}
}
else
{
var mouseClickPos = new PointF
{
X = (float)e.GetPosition(canvas).X,
Y = (float)e.GetPosition(canvas).Y
};
var impIndex = 0;
var xMin = 0.0;
var xMax = 0.0;
var yMin = 0.0;
var yMax = 0.0;
for (var i = 0; i < CoordList.Count; i++)
{
xMin = CoordList[i][0].X;
xMax = CoordList[i][1].X;
yMin = CoordList[i][0].Y;
yMax = CoordList[i][2].Y;
if (!(xMin <= mouseClickPos.X) || !(mouseClickPos.X <= xMax) || !(yMin <= mouseClickPos.Y) ||
!(mouseClickPos.Y <= yMax)) continue;
impIndex = i + 1;
break;
}
if (yMin.Equals(0.0) || yMax.Equals(0.0) || xMin.Equals(0.0) || xMax.Equals(0.0)) return;
var index = "NewRect" + "0" + impIndex + "0";
var indexwn = "0" + impIndex + "0";
foreach (var khm in canvas.Children)
{
if (!(khm.GetType().Name.Equals("Rectangle"))) continue;
var nkhm = (Rectangle)khm;
if (nkhm.Name != index) continue;
if (!nkhm.Fill.Equals(Brushes.Transparent))
{
nkhm.Fill = Brushes.Transparent;
LimitsInfo.Remove(indexwn);
SmallRectsInfo.Remove(indexwn);
Command.CreateCommand("AID CLEAR BOX " + indexwn).Run();
}
else
{
nkhm.Fill = Brushes.Red;
foreach (var elem in canvas.Children)
{
if (!(elem.GetType().Name.Equals("Rectangle"))) continue;
var rectan = (Rectangle)elem;
if (!rectan.Name.StartsWith("Rect")) continue;
var rectname = rectan.Name.Replace("Rect", "");
if (!rectname.Equals(indexwn)) continue;
DictionaryFilling(LimitsInfo, indexwn, rectan);
DictionaryFilling(SmallRectsInfo, indexwn, nkhm);
LimitsBoxes(rectan, ZCentr, ZLength, indexwn, Selit);
}
}
}
}
_orig.X = 0;
_orig.Y = 0;
Mouse.Capture(null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void DrawingLb_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
_selRect = new Rectangle();
bool clickonrect = false;
_orig.X = e.GetPosition(canvas).X;
_orig.Y = e.GetPosition(canvas).Y;
for (var i = 0; i < CoordList.Count; i++)
{
var xMin = CoordList[i][0].X;
var xMax = CoordList[i][1].X;
var yMin = CoordList[i][0].Y;
var yMax = CoordList[i][2].Y;
if (!(xMin <= _orig.X) || !(_orig.X <= xMax) || !(yMin <= _orig.Y) ||
!(_orig.Y <= yMax)) continue;
clickonrect = true;
break;
}
if (!clickonrect) return;
canvas.Children.Add(_selRect);
foreach (var pr in canvas.Children)
{
if (!(pr.GetType().Name.Equals("Rectangle"))) continue;
var wpr = (Rectangle)pr;
if (!wpr.Name.StartsWith("Rect")) continue;
var wpri = wpr.Name.Replace("Rect", "");
foreach (var ppr in canvas.Children)
{
if (!(ppr.GetType().Name.Equals("Rectangle"))) continue;
var wppr = (Rectangle)ppr;
if (!wppr.Name.StartsWith("NewRect")) continue;
var wppri = wppr.Name.Replace("NewRect", "");
if (!wppri.Equals(wpri)) continue;
if (wpr.Margin.Left <= _orig.X && _orig.X <= wpr.Margin.Right &&
wpr.Margin.Top <= _orig.Y &&
_orig.Y <= wpr.Margin.Bottom)
{
_clickSelect = wppr.Fill.Equals(Brushes.Red);
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Canvas_OnMouseEnter(object sender, MouseEventArgs e)
{
if (_limitrect.Margin.Left <= e.GetPosition(canvas).X && e.GetPosition(canvas).X <= _limitrect.Margin.Right &&
_limitrect.Margin.Top <= e.GetPosition(canvas).Y && e.GetPosition(canvas).Y <= _limitrect.Margin.Bottom)
{
canvas.ToolTip = "Выберите LimitBox для построения на DrawList";
}
}
private void DrawingLb_Loaded(object sender, RoutedEventArgs e)
{
DrawingLimits();
}
#endregion
#region Functions
internal void RemAll()
{
foreach (var elem in canvas.Children)
{
if (!(elem.GetType().Name.Equals("Rectangle"))) continue;
var rect = (Rectangle)elem;
if (!rect.Name.StartsWith("NewRect")) continue;
rect.Fill = Brushes.Transparent;
LimitsInfo.Clear();
SmallRectsInfo.Clear();
}
}
private static void DictionaryFilling(Dictionary<string, Rectangle> dict, string index, Rectangle rect)
{
if (!dict.ContainsKey(index)) dict.Add(index, rect);
else
{
dict.Remove(index);
dict.Add(index, rect);
}
}
internal void LimitsBoxes(Rectangle rect, double cent, int length, string index, int selectedindex)
{
var widthOfRect =
(int)
Math.Sqrt(Math.Pow((rect.Margin.Left - rect.Margin.Right), 2.0) +
Math.Pow((rect.Margin.Top - rect.Margin.Top), 2.0));
var heightOfRect =
(int)
Math.Sqrt(Math.Pow((rect.Margin.Left - rect.Margin.Left), 2.0) +
Math.Pow((rect.Margin.Top - rect.Margin.Bottom), 2.0));
var centerOfLb = Position.Create();
var koefA = (LimitBoxR.Minimum.X - 10 / Scale) * Scale;
var koefB = (LimitBoxR.Maximum.Y - 10 / Scale) * Scale;
centerOfLb.X = ((rect.Margin.Left + rect.Margin.Right) / 2.0 + koefA) / Scale;
centerOfLb.Y = (((rect.Margin.Top + rect.Margin.Bottom) / 2.0 - koefB - 20) /
Scale) *
Math.Cos(Math.PI);
centerOfLb.Z = cent;
switch (selectedindex)
{
case 0:
Command.CreateCommand("AID CLEAR BOX " + index).Run();
Command.CreateCommand("AID BOX NUMBER " + index + " AT " + centerOfLb +
" XLENGTH " + (widthOfRect / Scale).ToString().Replace(',', '.') +
" YLENGTH " + (heightOfRect / Scale).ToString().Replace(',', '.') +
" ZLENGTH " + length.ToString()).Run();
break;
case 1:
Command.CreateCommand("AID CLEAR ALL BOX").Run();
break;
default:
Command.CreateCommand("AID CLEAR BOX " + index).Run();
Command.CreateCommand("AID BOX NUMBER " + index + " AT " + centerOfLb +
" XLENGTH " + (widthOfRect / Scale).ToString().Replace(',', '.') +
" YLENGTH " + (heightOfRect / Scale).ToString().Replace(',', '.') +
" ZLENGTH " + length.ToString() +
" FILL OFF").Run();
break;
}
}
private static bool IsLinesIntersects(D2FiniteLine vertic, D2FiniteLine horizont, out D2Point pt)
{
pt = D2Point.Create();
double begx1, begy1, endx1, endy1;
double begx2, begy2, endx2, endy2;
var origin = D2Point.Create(0.0, 0.0);
var vertdistfre = vertic.End().Ddistance(origin);
var vertdistfrs = vertic.Start().Ddistance(origin);
var hordistfre = horizont.End().Ddistance(origin);
var hordistfrs = horizont.Start().Ddistance(origin);
if (vertdistfrs > vertdistfre)
{
begx1 = vertic.End().X;
begy1 = vertic.End().Y;
endx1 = vertic.Start().X;
endy1 = vertic.Start().Y;
}
else
{
begx1 = vertic.Start().X;
begy1 = vertic.Start().Y;
endx1 = vertic.End().X;
endy1 = vertic.End().Y;
}
if (hordistfrs > hordistfre)
{
begx2 = horizont.End().X;
begy2 = horizont.End().Y;
endx2 = horizont.Start().X;
endy2 = horizont.Start().Y;
}
else
{
begx2 = horizont.Start().X;
begy2 = horizont.Start().Y;
endx2 = horizont.End().X;
endy2 = horizont.End().Y;
}
var ua = ((endx2 - begx2) * (begy1 - begy2) - (endy2 - begy2) * (begx1 - begx2)) /
((endy2 - begy2) * (endx1 - begx1) - (endx2 - begx2) * (endy1 - begy1));
var x = begx1 + ua * (endx1 - begx1);
var y = begy1 + ua * (endy1 - begy1);
if (begx1.Equals(begx2) && begy1.Equals(begy2) || endx1.Equals(endx2) && endy1.Equals(endy2))
{
pt.X = x;
pt.Y = y;
return true;
}
var lengthx1 = endx1 - begx1;
var lengthx2 = endx2 - begx2; //Длина проекций на ось х
var lengthy1 = endy1 - begy1;
var lengthy2 = endy2 - begy2; //Длина проекций на ось у
var lengthxx = begx1 - begx2;
var lengthyy = begy1 - begy2;
int div, mul;
if ((div = (int)(lengthy2 * lengthx1 - lengthx2 * lengthy1)) == 0) //Линии параллельны
{
pt = null;
return false;
}
if (div > 0)
{
//Проверка на пересечение отрезков за их границами
if ((mul = (int)(lengthx1 * lengthyy - lengthy1 * lengthxx)) < 0 || mul > div)
{
pt = null;
return false;
}
if ((mul = (int)(lengthx2 * lengthyy - lengthy2 * lengthxx)) < 0 || mul > div)
{
pt = null;
return false;
}
}
if ((mul = -(int)(lengthx1 * lengthyy - lengthy1 * lengthxx)) < 0 || mul > -div)
{
pt = null;
return false;
}
if ((mul = -(int)(lengthx2 * lengthyy - lengthy2 * lengthxx)) < 0 || mul > -div)
{
pt = null;
return false;
}
pt.X = x;
pt.Y = y;
return true;
}
private static void GetSelRectangle(Point orig, Point location, Rectangle rect)
{
var deltaX = location.X - orig.X;
var deltaY = location.Y - orig.Y;
if (deltaX.Equals(0.0) || deltaY.Equals(0.0)) return;
rect.Width = Math.Abs(deltaX);
rect.Height = Math.Abs(deltaY);
rect.Margin =
new Thickness(Math.Min(orig.X, location.X), Math.Min(orig.Y, location.Y),
Math.Max(orig.X, location.X), Math.Max(orig.Y, location.Y));
rect.Fill = Brushes.Blue;
rect.Opacity = 0.3;
}
private void DrawingLimits()
{
canvas.Children.Clear();
Vertical.Clear();
Horizontal.Clear();
CoordList.Clear();
var world = DbElement.GetElement("/*");
foreach (var site in world.Members(DbElementTypeInstance.SITE))
{
var curMDB = MDB.CurrentMDB.Name.Replace("-", "");
var splName = site.GetAsString(DbAttributeInstance.FLNN).Split('-')[0];
if (!(site.GetAsString(DbAttributeInstance.PURP).ToUpper().Equals("AXES") && curMDB.Equals(splName)))
continue;
var collection = new DBElementCollection(site, new TypeFilter(DbElementTypeInstance.SCTN));
var widthOfHost = canvas.ActualWidth - 20;
var heightOfHost = canvas.ActualHeight - 20;
Scale = widthOfHost / WidthOfLb;
var widthOfRect = WidthOfLb * Scale;
var heightOfRect = HeightOfLb * Scale;
if (heightOfRect > (heightOfHost))
{
Scale = heightOfHost / HeightOfLb;
widthOfRect = WidthOfLb * Scale;
heightOfRect = HeightOfLb * Scale;
}