프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Shape / RectangleControl.cs @ 1af0f150

이력 | 보기 | 이력해설 | 다운로드 (27.2 KB)

1 787a4489 KangIngu
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows;
8
using System.Windows.Shapes;
9
using System.Windows.Controls;
10
using System.Windows.Media;
11
using MarkupToPDF.Controls.Common;
12
using MarkupToPDF.Common;
13 036650a0 humkyung
using MarkupToPDF.Serialize.Core;
14
using MarkupToPDF.Serialize.S_Control;
15 a6272c57 humkyung
using System.Windows.Input;
16 7b34fb3a swate0609
using System.Windows.Markup;
17 787a4489 KangIngu
18
namespace MarkupToPDF.Controls.Shape
19
{
20
//강인구 추가 IShapeControl
21 e65e8c5c humkyung
    public class RectangleControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IDashControl
22 787a4489 KangIngu
    {
23
        public Path Base_RectPath { get; set; }
24
        private const string PART_RectPath = "PART_RectPath";
25
26
        #region Property
27
28
29
        public MouseMode mousemode
30
        {
31
            get
32
            {
33
                return (MouseMode)GetValue(mousemodeProperty);
34
            }
35
            set
36
            {
37
                SetValue(mousemodeProperty, value);
38
                OnPropertyChanged("mousemode");
39
            }
40
        }
41
42 4913851c humkyung
        public override SolidColorBrush StrokeColor
43 787a4489 KangIngu
        {
44
            get
45
            {
46
                return (SolidColorBrush)GetValue(StrokeColorProperty);
47
            }
48
            set
49
            {
50
                SetValue(StrokeColorProperty, value);
51
                OnPropertyChanged("StrokeColor");
52
            }
53
        }
54
55
        public Double LineSize
56
        {
57
            get
58
            {
59
                return (Double)GetValue(LineSizeProperty);
60
            }
61
            set
62
            {
63
                SetValue(LineSizeProperty, value);
64
                OnPropertyChanged("LineSize");
65
            }
66
        }
67
68
        public Geometry PathData
69
        {
70
            get
71
            {
72
                return (Geometry)GetValue(PathDataProperty);
73
            }
74
            set
75
            {
76
                SetValue(PathDataProperty, value);
77
                OnPropertyChanged("PathData");
78
            }
79
80
        }
81
82
        public Geometry OverViewPathData
83
        {
84
            get
85
            {
86
                return (Geometry)GetValue(OverViewPathDataProperty);
87
            }
88
            set
89
            {
90
                SetValue(OverViewPathDataProperty, value);
91
                OnPropertyChanged("OverViewPathData");
92
            }
93
        }
94
95
        public SolidColorBrush FillColor
96
        {
97
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
98
            set
99
            {
100
                SetValue(FillColorProperty, value);
101
                OnPropertyChanged("FillColor");
102
            }
103
        }
104
		//강인구 추가
105
        public DoubleCollection DashSize
106
        {
107
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
108
            set
109
            {
110
                if (this.DashSize != value)
111
                {
112
                    SetValue(DashSizeProperty, value);
113
                }
114
            }
115
        }
116
117
        public Point StartPoint
118
        {
119
            get
120
            {
121
                return (Point)GetValue(StartPointProperty);
122
            }
123
            set
124
            {
125
                SetValue(StartPointProperty, value);
126
                OnPropertyChanged("StartPoint");
127
            }
128
        }
129
130
        public Point SetPoint
131
        {
132
            get
133
            {
134
                return (Point)GetValue(SetPointProperty);
135
            }
136
            set
137
            {
138
                SetValue(SetPointProperty, value);
139
                OnPropertyChanged("SetPoint");
140
            }
141
        }
142
143
        public Point OriginPoint
144
        {
145
            get
146
            {
147
                return (Point)GetValue(OriginPointProperty);
148
            }
149
            set
150
            {
151
                SetValue(OriginPointProperty, value);
152
                OnPropertyChanged("OriginPoint");
153
            }
154
        }
155
156
        public Point TopRightPoint
157
        {
158
            get
159
            {
160
                return (Point)GetValue(TopRightPointProperty);
161
            }
162
            set
163
            {
164
                SetValue(TopRightPointProperty, value);
165
                OnPropertyChanged("TopRightPoint");
166
            }
167
        }
168
169
        public Point LeftBottomPoint
170
        {
171
            get
172
            {
173
                return (Point)GetValue(LeftBottomPointProperty);
174
            }
175
            set
176
            {
177
                SetValue(LeftBottomPointProperty, value);
178
                OnPropertyChanged("LeftBottomPoint");
179
            }
180
        }
181
182
        public Point EndPoint
183
        {
184
            get
185
            {
186
                return (Point)GetValue(EndPointProperty);
187
            }
188
            set
189
            {
190
                SetValue(EndPointProperty, value);
191
                OnPropertyChanged("EndPoint");
192
            }
193
        }
194
195 959b3ef2 humkyung
        public override bool IsSelected
196 787a4489 KangIngu
        {
197
            get
198
            {
199
                return (bool)GetValue(IsSelectedProperty);
200
            }
201
            set
202
            {
203
                SetValue(IsSelectedProperty, value);
204
                OnPropertyChanged("IsSelected");
205
            }
206
        }
207
208 5529d2a2 humkyung
        public override ControlType ControlType
209 787a4489 KangIngu
        {
210
            set
211
            {
212
                SetValue(ControlTypeProperty, value);
213
                OnPropertyChanged("ControlType");
214
            }
215
            get
216
            {
217
                return (ControlType)GetValue(ControlTypeProperty);
218
            }
219
        }
220
221
        public List<Point> PointSet
222
        {
223
            get { return (List<Point>)GetValue(PointSetProperty); }
224
            set { SetValue(PointSetProperty, value); }
225
        }
226
227
228
        public double CanvasX
229
        {
230
            get { return (double)GetValue(CanvasXProperty); }
231
            set
232
            {
233
                if (this.CanvasX != value)
234
                {
235
                    SetValue(CanvasXProperty, value);
236
                    OnPropertyChanged("CanvasX");
237
                }
238
            }
239
        }
240
241
        public double CanvasY
242
        {
243
            get { return (double)GetValue(CanvasYProperty); }
244
            set
245
            {
246
                if (this.CanvasY != value)
247
                {
248
                    SetValue(CanvasYProperty, value);
249
                    OnPropertyChanged("CanvasY");
250
                }
251
            }
252
        }
253
254
        public PaintSet Paint
255
        {
256
            get { return (PaintSet)GetValue(PaintProperty); }
257
            set
258
            {
259
                if (this.Paint != value)
260
                {
261
                    SetValue(PaintProperty, value);
262
                }
263
            }
264
        }
265
266 fa48eb85 taeseongkim
        public double CommentAngle
267 787a4489 KangIngu
        {
268
            get { return (double)GetValue(AngleProperty); }
269
            set
270
            {
271 fa48eb85 taeseongkim
                if (this.CommentAngle != value)
272 787a4489 KangIngu
                {
273
                    SetValue(AngleProperty, value);
274
                }
275
            }
276
        }
277
        public string UserID
278
        {
279
            get { return (string)GetValue(UserIDProperty); }
280
            set
281
            {
282
                if (this.UserID != value)
283
                {
284
                    SetValue(UserIDProperty, value);
285
                    OnPropertyChanged("UserID");
286
                }
287
            }
288
        }
289
290
        #endregion
291
292
        #region Dependency Property
293
294
295
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
296
        "UserID", typeof(string), typeof(RectangleControl), new PropertyMetadata(null));
297
298
        public static readonly DependencyProperty mousemodeProperty =
299
                DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(RectCloudControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
300
301
        public static readonly DependencyProperty IsSelectedProperty =
302
          DependencyProperty.Register("IsSelected", typeof(bool), typeof(RectangleControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
303
304
        public static readonly DependencyProperty ControlTypeProperty =
305
                DependencyProperty.Register("ControlType", typeof(ControlType), typeof(RectangleControl), new FrameworkPropertyMetadata(ControlType.Rectangle));
306
307
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
308
                "StrokeColor", typeof(SolidColorBrush), typeof(RectangleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
309
310
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
311
              "LineSize", typeof(double), typeof(RectangleControl), new PropertyMetadata((Double)3));
312
313
        //강인구 추가
314
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
315
                "DashSize", typeof(DoubleCollection), typeof(RectangleControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
316
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
317
               "PathData", typeof(Geometry), typeof(RectangleControl), null);
318
319
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
320
               "OverViewPathData", typeof(Geometry), typeof(RectangleControl), null);
321
322
        //강인구 추가
323
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
324
        "Paint", typeof(PaintSet), typeof(RectangleControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
325
326
327
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
328
                "FillColor", typeof(SolidColorBrush), typeof(RectangleControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
329
330
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
331
                 "CanvasX", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
332
333
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
334
                "CanvasY", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
335
336
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
337
               "TopRightPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
338
339
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
340
                 "LeftBottomPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
341
342
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
343
            "StartPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
344
345
        public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(
346
        "SetPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
347
348
        public static readonly DependencyProperty OriginPointProperty = DependencyProperty.Register(
349
        "OriginPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
350
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
351
            "Angle", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
352
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
353
         "PointSet", typeof(List<Point>), typeof(RectangleControl), new PropertyMetadata(new List<Point>()));
354
355
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
356
              "EndPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
357
358
        #endregion  Dependency Property
359
360
        #region Dependency PropertyChanged
361
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
362
        {
363
            var instance = (RectangleControl)sender;
364
365
            if (e.OldValue != e.NewValue && instance != null)
366
            {
367
                instance.SetValue(e.Property, e.NewValue);
368
                Canvas.SetLeft(instance, instance.SetPoint.X);
369
                Canvas.SetTop(instance, instance.SetPoint.Y);
370
                //Canvas.SetLeft(instance, instance.CanvasX);
371
                //Canvas.SetTop(instance, instance.CanvasY);
372
            }
373
        }
374
375
376
        public static void OnUpdateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
377
        {
378
            var instance = (RectangleControl)sender;
379
380
            if (e.OldValue != e.NewValue && instance != null)
381
            {
382
                instance.SetValue(e.Property, e.NewValue);
383
                instance.SetRectPath();
384
            }
385
        }
386
387
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
388
        {
389
            var instance = (RectangleControl)sender;
390
            if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
391
            {
392
                instance.SetValue(e.Property, e.NewValue);
393
                instance.SetRectPath();
394
            }
395
        }
396
397
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
398
        {
399
            //var instance = (RectangleControl)sender;
400
401
            //if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
402
            //{
403
            //    instance.SetValue(e.Property, e.NewValue);
404
405
            //    if (instance.IsSelected)
406
            //    {
407
            //        instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Blue);
408
            //    }
409
            //    else
410
            //    {
411
            //        instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Red);
412
            //    }
413
            //}
414
        }
415
416
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
417
        {
418
            var instance = (RectangleControl)sender;
419
420
            if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
421
            {
422
                instance.SetValue(e.Property, e.NewValue);
423
                instance.SetRectPath();
424
            }
425
        }
426
        #endregion Dependency PropertyChanged
427
428 661b7416 humkyung
        private void SetRectPath()
429 787a4489 KangIngu
        {
430
            this.ApplyTemplate();
431
432
            if (Base_RectPath != null)
433
            {
434
                //강인구 추가
435
                Base_RectPath.StrokeDashArray.Clear();
436
                if (DashSize != null)
437
                {
438
                    foreach (var item in this.DashSize)
439
                    {
440
                        Base_RectPath.StrokeDashArray.Add(item);
441
                    }
442
                    Base_RectPath.StrokeDashCap = PenLineCap.Square;
443
                }
444
445
                PathFigure pathFigure = new PathFigure
446
                {
447
                    IsClosed = true
448
                };
449
450 a6272c57 humkyung
                if ((this.ControlType == ControlType.Rectangle) || (this.ControlType == ControlType.Mark))
451 787a4489 KangIngu
                {
452
                    switch (this.Paint)
453
                    {
454
                        case PaintSet.None:
455
                            this.FillColor = null;
456
                            pathFigure.IsFilled = false;
457
                            break;
458
                        case PaintSet.Fill:
459
                            this.FillColor = this.StrokeColor;
460
                            Base_RectPath.Fill = this.FillColor;
461
                            pathFigure.IsFilled = true;
462
                            break;
463
                        case PaintSet.Hatch:
464
                            Base_RectPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
465
                            pathFigure.IsFilled = true;
466
                            break;
467
                        default:
468
                            {
469
470
                            }
471
                            break;
472
                    }
473
                }
474
475
                pathFigure.StartPoint = this.StartPoint;
476
477 6d1a8228 humkyung
                List<Point> points = new List<Point>() { this.LeftBottomPoint, this.EndPoint, this.TopRightPoint, this.StartPoint };
478
                PolyLineSegment polyline = new PolyLineSegment(points, true);
479
                pathFigure.Segments.Add(polyline);
480 787a4489 KangIngu
481
                PathGeometry pathGeometry = new PathGeometry();
482
                pathGeometry.Figures = new PathFigureCollection();
483
                pathGeometry.Figures.Add(pathFigure);
484
485
                //Base_RectPath.StrokeThickness = 3;
486
                this.FillColor = null;
487
                this.PathData = pathGeometry;
488
                ApplyOverViewData();
489
                //OverViewPathData = PathData;
490
                //AdornerControl adornerControl = new Adorner.AdornerControl();
491
                ////adornerControl
492
493 a6272c57 humkyung
                //adornerthis.Content = pathGeometry;
494 787a4489 KangIngu
495
            }
496
        }
497
498 f513c215 humkyung
        public override void ApplyOverViewData()
499 787a4489 KangIngu
        {
500
            this.OverViewPathData = this.PathData;
501
        }
502
503
        #region Internal Method
504
505
506
        static RectangleControl()
507
        {
508
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RectangleControl), new FrameworkPropertyMetadata(typeof(RectangleControl)));
509 a6f7f9b6 djkim
            //ResourceDictionary dictionary = new ResourceDictionary();
510
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
511
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
512 787a4489 KangIngu
        }
513
514 7b34fb3a swate0609
        public override void Copy(CommentUserInfo lhs)
515
        {
516
            if (lhs is RectangleControl rectangleControl)
517
            {
518
                this.LineSize = rectangleControl.LineSize;
519
                this.Paint = rectangleControl.Paint;
520
                this.StartPoint = new System.Windows.Point(rectangleControl.StartPoint.X, rectangleControl.StartPoint.Y);
521
                this.EndPoint = new System.Windows.Point(rectangleControl.EndPoint.X, rectangleControl.EndPoint.Y);
522
                this.LeftBottomPoint = new System.Windows.Point(rectangleControl.LeftBottomPoint.X, rectangleControl.LeftBottomPoint.Y);
523
                this.TopRightPoint = new System.Windows.Point(rectangleControl.TopRightPoint.X, rectangleControl.TopRightPoint.Y);
524
                this.CommentAngle = rectangleControl.CommentAngle;
525
                this.StrokeColor = rectangleControl.StrokeColor;
526
                this.DashSize = rectangleControl.DashSize;
527
                this.Opacity = rectangleControl.Opacity;
528
                this.PointSet = rectangleControl.PointSet.ConvertAll(x => new System.Windows.Point(x.X, x.Y));
529
                this.UserID = rectangleControl.UserID;
530
                this.Memo = rectangleControl.Memo;
531
            }
532
        }
533
534
        public override CommentUserInfo Clone()
535
        {
536
            var clone = new RectangleControl();
537
            clone.Copy(this);
538
            return clone;
539
        }
540
541 787a4489 KangIngu
542
        public override void OnApplyTemplate()
543
        {
544
            base.OnApplyTemplate();
545
546
            Base_RectPath = GetTemplateChild(PART_RectPath) as Path;
547
548
549
            if (Base_RectPath == null)
550
                return;
551
552
            SetRectPath();
553
            Base_RectPath.Focus();
554
        }
555
556 0d00f9c8 humkyung
        public override void UpdateControl()
557 787a4489 KangIngu
        {
558
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
559
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
560
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
561
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
562
        }
563
564
        private void OnPropertyChanged(string name)
565
        {
566
            if (PropertyChanged != null)
567
            {
568
                PropertyChanged(this, new PropertyChangedEventArgs(name));
569
            }
570
        }
571
572
        public void ChangePaint(PaintSet state)
573
        {
574
            this.Paint = state;
575
            this.SetRectPath();
576
        }
577
578
        public event PropertyChangedEventHandler PropertyChanged;
579
580 036650a0 humkyung
        /// <summary>
581 a6272c57 humkyung
        /// call when mouse is moving while drawing control
582
        /// </summary>
583
        /// <author>humkyung</author>
584
        /// <param name="pt"></param>
585
        /// <param name="bAxisLocked"></param>
586 233ef333 taeseongkim
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
587 a6272c57 humkyung
        {
588 233ef333 taeseongkim
            this.EndPoint = bAxisLocked ? this.GetSquareEndPoint(this.StartPoint, pt) : pt;
589 a6272c57 humkyung
            this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y);
590
            this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y);
591
592
            this.PointSet = new List<Point>
593
            {
594
                this.StartPoint,
595
                this.LeftBottomPoint,
596
                this.EndPoint,
597
                this.TopRightPoint,
598
            };
599
        }
600
601
        /// <summary>
602 d2114d3b humkyung
        /// move control point has same location of given pt along given delta
603
        /// </summary>
604
        /// <author>humkyung</author>
605
        /// <date>2019.06.20</date>
606
        /// <param name="pt"></param>
607
        /// <param name="dx"></param>
608
        /// <param name="dy"></param>
609 233ef333 taeseongkim
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false)
610 d2114d3b humkyung
        {
611
            IPath path = (this as IPath);
612
613
            Point selected = MathSet.getNearPoint(path.PointSet, pt);
614
            selected.X += dx;
615
            selected.Y += dy;
616
            int i = 0;
617
            for (i = 0; i < (this as IPath).PointSet.Count; i++)
618
            {
619
                if (pt.Equals((this as IPath).PointSet[i]))
620
                {
621
                    (this as IPath).PointSet[i] = selected;
622
                    break;
623
                }
624
            }
625
626 56f4174c swate0609
627 ca7b7b56 humkyung
            var OppositeP = (i + path.PointSet.Count / 2) % path.PointSet.Count;
628
            var PreviousP = (i + (path.PointSet.Count - 1)) % path.PointSet.Count;
629
            var NextP = (i + 1) % path.PointSet.Count;
630
            if (bAxisLocked)
631
            {
632 56f4174c swate0609
                double _dx = path.PointSet[i].X - path.PointSet[OppositeP].X;
633
                double _dy = path.PointSet[i].Y - path.PointSet[OppositeP].Y;
634 ca7b7b56 humkyung
                double distance = Math.Max(Math.Abs(_dx), Math.Abs(_dy));
635
636
                var PreviousV = path.PointSet[PreviousP] - path.PointSet[OppositeP];
637
                PreviousV.Normalize();
638
                path.PointSet[PreviousP] = path.PointSet[OppositeP] + PreviousV * distance;
639
640 56f4174c swate0609
                var NextV = path.PointSet[NextP] - path.PointSet[OppositeP];
641 ca7b7b56 humkyung
                NextV.Normalize();
642
                path.PointSet[NextP] = path.PointSet[OppositeP] + NextV * distance;
643
644
                path.PointSet[i] = path.PointSet[OppositeP] + PreviousV * distance + NextV * distance;
645
            }
646
            else
647
            {
648
                var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[PreviousP]);
649
                var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X,
650
                    path.PointSet[i].Y - path.PointSet[OppositeP].Y);
651 56f4174c swate0609
652
                Point pPrevious = new Point(path.PointSet[OppositeP].X + PreviousV.X * l, path.PointSet
653 ca7b7b56 humkyung
                    [OppositeP].Y + PreviousV.Y * l);
654
655 56f4174c swate0609
                if (path.PointSet.FindAll(x => x.Equals(pPrevious)).Count() == 0)
656
                {
657
                    path.PointSet[PreviousP] = pPrevious;
658
                }
659
                //path.PointSet[PreviousP] = pPrevious;
660
661 ca7b7b56 humkyung
                var NextV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[NextP]);
662
                l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X, path.PointSet
663
                    [i].Y - path.PointSet[OppositeP].Y);
664 56f4174c swate0609
665
                Point pNext = new Point(path.PointSet[OppositeP].X + NextV.X * l, path.PointSet[OppositeP].Y + NextV.Y * l);
666
667
                if(path.PointSet.FindAll(x => x.Equals(pNext)).Count() == 0)
668
                {
669
                    path.PointSet[NextP] = pNext;
670
                }
671
                //path.PointSet[NextP] = pNext;
672
673 ca7b7b56 humkyung
            }
674 d2114d3b humkyung
675 0d00f9c8 humkyung
            this.UpdateControl();
676 d2114d3b humkyung
        }
677
678
        /// <summary>
679 91efe37a humkyung
        /// return rectanglecontrols' area
680
        /// </summary>
681
        public override Rect ItemRect
682
        {
683
            get
684
            {
685
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
686
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
687
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
688
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
689
690
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
691
            }
692
        }
693
694
        /// <summary>
695 036650a0 humkyung
        /// Serialize this
696
        /// </summary>
697
        /// <param name="sUserId"></param>
698
        /// <returns></returns>
699
        public override string Serialize()
700
        {
701
            using (S_RectControl STemp = new S_RectControl())
702
            {
703
                STemp.TransformPoint = "0|0";
704
                STemp.SizeSet = String.Format("{0}", this.LineSize);
705
                STemp.PaintState = this.Paint;
706
                STemp.PointSet = this.PointSet;
707
                //STemp.StrokeColor = "#FF00FF00";
708
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
709
                if (this.FillColor != null)
710
                {
711
                    STemp.FillColor = this.FillColor.Color.ToString();
712
                }
713
                STemp.StartPoint = this.StartPoint;
714
                STemp.UserID = this.UserID;
715
                //STemp.Angle = this.a;
716
                STemp.EndPoint = this.EndPoint;
717
                STemp.LB = this.LeftBottomPoint;
718
                STemp.TR = this.TopRightPoint;
719
                STemp.DashSize = this.DashSize;
720
                STemp.Opac = this.Opacity;
721
                STemp.Name = this.GetType().Name.ToString();
722
                ///강인구 추가(2017.11.02)
723
                ///Memo 추가
724
                STemp.Memo = this.Memo;
725
726
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
727
            };
728
        }
729
730 661b7416 humkyung
        /// <summary>
731
        /// create a rectanglecontrol from given string
732
        /// </summary>
733
        /// <param name="item"></param>
734
        /// <returns></returns>
735
        public static RectangleControl FromString(string str, SolidColorBrush brush, string sProjectNo)
736
        {
737
            using (S_RectControl s = JsonSerializerHelper.JsonDeserialize<S_RectControl>(str))
738
            {
739
                string[] data2 = s.SizeSet.Split(CommentUserInfo.delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
740
                return new RectangleControl
741
                {
742
                    LineSize = Convert.ToDouble(data2.First()),
743
                    Paint = s.PaintState,
744
                    StartPoint = s.StartPoint,
745
                    EndPoint = s.EndPoint,
746 fa48eb85 taeseongkim
                    CommentAngle = s.Angle,
747 661b7416 humkyung
                    StrokeColor = brush,
748
                    DashSize = s.DashSize,
749
                    Opacity = s.Opac,
750
                    LeftBottomPoint = s.LB,
751
                    TopRightPoint = s.TR,
752
                    PointSet = s.PointSet,
753
                    UserID = s.UserID,
754
                    Memo = s.Memo
755
                };
756
            }
757
        }
758
759 787a4489 KangIngu
        public void Dispose()
760
        {
761 a6f7f9b6 djkim
            //GC.Collect();
762 24c5e56c taeseongkim
            ////GC.SuppressFinalize(this);
763 a6f7f9b6 djkim
            this.Base_RectPath = null;
764 787a4489 KangIngu
        }
765
        #endregion Internal Method
766
    }
767
}
클립보드 이미지 추가 (최대 크기: 500 MB)