프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / RectangleControl.cs @ b2d0f316

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

1
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
using MarkupToPDF.Serialize.Core;
14
using MarkupToPDF.Serialize.S_Control;
15
using System.Windows.Input;
16
using System.Windows.Markup;
17
using System.Runtime.CompilerServices;
18

    
19
namespace MarkupToPDF.Controls.Shape
20
{
21
//강인구 추가 IShapeControl
22
    public class RectangleControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IDashControl
23
    {
24
        public Path Base_RectPath { get; set; }
25
        private const string PART_RectPath = "PART_RectPath";
26

    
27
        #region Property
28

    
29

    
30
        public MouseMode mousemode
31
        {
32
            get
33
            {
34
                return (MouseMode)GetValue(mousemodeProperty);
35
            }
36
            set
37
            {
38
                SetValue(mousemodeProperty, value);
39
                OnPropertyChanged("mousemode");
40
            }
41
        }
42

    
43
        public override SolidColorBrush StrokeColor
44
        {
45
            get
46
            {
47
                return (SolidColorBrush)GetValue(StrokeColorProperty);
48
            }
49
            set
50
            {
51
                SetValue(StrokeColorProperty, value);
52
                OnPropertyChanged("StrokeColor");
53
            }
54
        }
55

    
56
        public Double LineSize
57
        {
58
            get
59
            {
60
                return (Double)GetValue(LineSizeProperty);
61
            }
62
            set
63
            {
64
                SetValue(LineSizeProperty, value);
65
                OnPropertyChanged("LineSize");
66
            }
67
        }
68

    
69
        public Geometry PathData
70
        {
71
            get
72
            {
73
                return (Geometry)GetValue(PathDataProperty);
74
            }
75
            set
76
            {
77
                SetValue(PathDataProperty, value);
78
                OnPropertyChanged("PathData");
79
            }
80

    
81
        }
82

    
83
        public Geometry OverViewPathData
84
        {
85
            get
86
            {
87
                return (Geometry)GetValue(OverViewPathDataProperty);
88
            }
89
            set
90
            {
91
                SetValue(OverViewPathDataProperty, value);
92
                OnPropertyChanged("OverViewPathData");
93
            }
94
        }
95

    
96
        public SolidColorBrush FillColor
97
        {
98
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
99
            set
100
            {
101
                SetValue(FillColorProperty, value);
102
                OnPropertyChanged("FillColor");
103
            }
104
        }
105
		//강인구 추가
106
        public DoubleCollection DashSize
107
        {
108
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
109
            set
110
            {
111
                if (this.DashSize != value)
112
                {
113
                    SetValue(DashSizeProperty, value);
114
                }
115
            }
116
        }
117

    
118
        public Point StartPoint
119
        {
120
            get
121
            {
122
                return (Point)GetValue(StartPointProperty);
123
            }
124
            set
125
            {
126
                SetValue(StartPointProperty, value);
127
                OnPropertyChanged("StartPoint");
128
            }
129
        }
130

    
131
        public Point SetPoint
132
        {
133
            get
134
            {
135
                return (Point)GetValue(SetPointProperty);
136
            }
137
            set
138
            {
139
                SetValue(SetPointProperty, value);
140
                OnPropertyChanged("SetPoint");
141
            }
142
        }
143

    
144
        public Point OriginPoint
145
        {
146
            get
147
            {
148
                return (Point)GetValue(OriginPointProperty);
149
            }
150
            set
151
            {
152
                SetValue(OriginPointProperty, value);
153
                OnPropertyChanged("OriginPoint");
154
            }
155
        }
156

    
157
        public Point TopRightPoint
158
        {
159
            get
160
            {
161
                return (Point)GetValue(TopRightPointProperty);
162
            }
163
            set
164
            {
165
                SetValue(TopRightPointProperty, value);
166
                OnPropertyChanged("TopRightPoint");
167
            }
168
        }
169

    
170
        public Point LeftBottomPoint
171
        {
172
            get
173
            {
174
                return (Point)GetValue(LeftBottomPointProperty);
175
            }
176
            set
177
            {
178
                SetValue(LeftBottomPointProperty, value);
179
                OnPropertyChanged("LeftBottomPoint");
180
            }
181
        }
182

    
183
        public Point EndPoint
184
        {
185
            get
186
            {
187
                return (Point)GetValue(EndPointProperty);
188
            }
189
            set
190
            {
191
                SetValue(EndPointProperty, value);
192
                OnPropertyChanged("EndPoint");
193
            }
194
        }
195

    
196
        public override bool IsSelected
197
        {
198
            get
199
            {
200
                return (bool)GetValue(IsSelectedProperty);
201
            }
202
            set
203
            {
204
                SetValue(IsSelectedProperty, value);
205
                OnPropertyChanged("IsSelected");
206
            }
207
        }
208

    
209
        public override ControlType ControlType
210
        {
211
            set
212
            {
213
                SetValue(ControlTypeProperty, value);
214
                OnPropertyChanged("ControlType");
215
            }
216
            get
217
            {
218
                return (ControlType)GetValue(ControlTypeProperty);
219
            }
220
        }
221

    
222
        public List<Point> PointSet
223
        {
224
            get { return (List<Point>)GetValue(PointSetProperty); }
225
            set { SetValue(PointSetProperty, value); }
226
        }
227

    
228

    
229
        public double CanvasX
230
        {
231
            get { return (double)GetValue(CanvasXProperty); }
232
            set
233
            {
234
                if (this.CanvasX != value)
235
                {
236
                    SetValue(CanvasXProperty, value);
237
                    OnPropertyChanged("CanvasX");
238
                }
239
            }
240
        }
241

    
242
        public double CanvasY
243
        {
244
            get { return (double)GetValue(CanvasYProperty); }
245
            set
246
            {
247
                if (this.CanvasY != value)
248
                {
249
                    SetValue(CanvasYProperty, value);
250
                    OnPropertyChanged("CanvasY");
251
                }
252
            }
253
        }
254

    
255
        public PaintSet Paint
256
        {
257
            get { return (PaintSet)GetValue(PaintProperty); }
258
            set
259
            {
260
                if (this.Paint != value)
261
                {
262
                    SetValue(PaintProperty, value);
263
                }
264
            }
265
        }
266

    
267
        public double CommentAngle
268
        {
269
            get { return (double)GetValue(AngleProperty); }
270
            set
271
            {
272
                if (this.CommentAngle != value)
273
                {
274
                    SetValue(AngleProperty, value);
275
                }
276
            }
277
        }
278
        public string UserID
279
        {
280
            get { return (string)GetValue(UserIDProperty); }
281
            set
282
            {
283
                if (this.UserID != value)
284
                {
285
                    SetValue(UserIDProperty, value);
286
                    OnPropertyChanged("UserID");
287
                }
288
            }
289
        }
290

    
291
        #endregion
292

    
293
        #region Dependency Property
294

    
295

    
296
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
297
        "UserID", typeof(string), typeof(RectangleControl), new PropertyMetadata(null));
298

    
299
        public static readonly DependencyProperty mousemodeProperty =
300
                DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(RectCloudControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
301

    
302
        public static readonly DependencyProperty IsSelectedProperty =
303
          DependencyProperty.Register("IsSelected", typeof(bool), typeof(RectangleControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
304

    
305
        public static readonly DependencyProperty ControlTypeProperty =
306
                DependencyProperty.Register("ControlType", typeof(ControlType), typeof(RectangleControl), new FrameworkPropertyMetadata(ControlType.Rectangle));
307

    
308
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
309
                "StrokeColor", typeof(SolidColorBrush), typeof(RectangleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
310

    
311
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
312
              "LineSize", typeof(double), typeof(RectangleControl), new PropertyMetadata((Double)3));
313

    
314
        //강인구 추가
315
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
316
                "DashSize", typeof(DoubleCollection), typeof(RectangleControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
317
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
318
               "PathData", typeof(Geometry), typeof(RectangleControl), null);
319

    
320
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
321
               "OverViewPathData", typeof(Geometry), typeof(RectangleControl), null);
322

    
323
        //강인구 추가
324
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
325
        "Paint", typeof(PaintSet), typeof(RectangleControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
326

    
327

    
328
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
329
                "FillColor", typeof(SolidColorBrush), typeof(RectangleControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
330

    
331
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
332
                 "CanvasX", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
333

    
334
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
335
                "CanvasY", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
336

    
337
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
338
               "TopRightPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
339

    
340
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
341
                 "LeftBottomPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
342

    
343
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
344
            "StartPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
345

    
346
        public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(
347
        "SetPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
348

    
349
        public static readonly DependencyProperty OriginPointProperty = DependencyProperty.Register(
350
        "OriginPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
351
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
352
            "Angle", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
353
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
354
         "PointSet", typeof(List<Point>), typeof(RectangleControl), new PropertyMetadata(new List<Point>()));
355

    
356
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
357
              "EndPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
358

    
359
        #endregion  Dependency Property
360

    
361
        #region Dependency PropertyChanged
362
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
363
        {
364
            var instance = (RectangleControl)sender;
365

    
366
            if (e.OldValue != e.NewValue && instance != null)
367
            {
368
                instance.SetValue(e.Property, e.NewValue);
369
                Canvas.SetLeft(instance, instance.SetPoint.X);
370
                Canvas.SetTop(instance, instance.SetPoint.Y);
371
                //Canvas.SetLeft(instance, instance.CanvasX);
372
                //Canvas.SetTop(instance, instance.CanvasY);
373
            }
374
        }
375

    
376

    
377
        public static void OnUpdateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
378
        {
379
            var instance = (RectangleControl)sender;
380

    
381
            if (e.OldValue != e.NewValue && instance != null)
382
            {
383
                instance.SetValue(e.Property, e.NewValue);
384
                instance.SetRectPath();
385
            }
386
        }
387

    
388
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
389
        {
390
            var instance = (RectangleControl)sender;
391
            if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
392
            {
393
                instance.SetValue(e.Property, e.NewValue);
394
                instance.SetRectPath();
395
            }
396
        }
397

    
398
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
399
        {
400
            //var instance = (RectangleControl)sender;
401

    
402
            //if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
403
            //{
404
            //    instance.SetValue(e.Property, e.NewValue);
405

    
406
            //    if (instance.IsSelected)
407
            //    {
408
            //        instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Blue);
409
            //    }
410
            //    else
411
            //    {
412
            //        instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Red);
413
            //    }
414
            //}
415
        }
416

    
417
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
418
        {
419
            var instance = (RectangleControl)sender;
420

    
421
            if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
422
            {
423
                instance.SetValue(e.Property, e.NewValue);
424
                instance.SetRectPath();
425
            }
426
        }
427
        #endregion Dependency PropertyChanged
428

    
429
        private void SetRectPath()
430
        {
431
            this.ApplyTemplate();
432

    
433
            if (Base_RectPath != null)
434
            {
435
                //강인구 추가
436
                Base_RectPath.StrokeDashArray.Clear();
437
                if (DashSize != null)
438
                {
439
                    foreach (var item in this.DashSize)
440
                    {
441
                        Base_RectPath.StrokeDashArray.Add(item);
442
                    }
443
                    Base_RectPath.StrokeDashCap = PenLineCap.Square;
444
                }
445

    
446
                PathFigure pathFigure = new PathFigure
447
                {
448
                    IsClosed = true
449
                };
450

    
451
                if ((this.ControlType == ControlType.Rectangle) || (this.ControlType == ControlType.Mark))
452
                {
453
                    switch (this.Paint)
454
                    {
455
                        case PaintSet.None:
456
                            this.FillColor = null;
457
                            pathFigure.IsFilled = false;
458
                            break;
459
                        case PaintSet.Fill:
460
                            this.FillColor = this.StrokeColor;
461
                            Base_RectPath.Fill = this.FillColor;
462
                            pathFigure.IsFilled = true;
463
                            break;
464
                        case PaintSet.Hatch:
465
                            Base_RectPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
466
                            pathFigure.IsFilled = true;
467
                            break;
468
                        default:
469
                            {
470

    
471
                            }
472
                            break;
473
                    }
474
                }
475

    
476
                pathFigure.StartPoint = this.StartPoint;
477

    
478
                List<Point> points = new List<Point>() { this.LeftBottomPoint, this.EndPoint, this.TopRightPoint, this.StartPoint };
479
                PolyLineSegment polyline = new PolyLineSegment(points, true);
480
                pathFigure.Segments.Add(polyline);
481

    
482
                PathGeometry pathGeometry = new PathGeometry();
483
                pathGeometry.Figures = new PathFigureCollection();
484
                pathGeometry.Figures.Add(pathFigure);
485

    
486
                //Base_RectPath.StrokeThickness = 3;
487
                this.FillColor = null;
488
                this.PathData = pathGeometry;
489
                ApplyOverViewData();
490
                //OverViewPathData = PathData;
491
                //AdornerControl adornerControl = new Adorner.AdornerControl();
492
                ////adornerControl
493

    
494
                //adornerthis.Content = pathGeometry;
495

    
496
            }
497
        }
498

    
499
        public override void ApplyOverViewData()
500
        {
501
            this.OverViewPathData = this.PathData;
502
        }
503

    
504
        #region Internal Method
505

    
506

    
507
        static RectangleControl()
508
        {
509
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RectangleControl), new FrameworkPropertyMetadata(typeof(RectangleControl)));
510
            //ResourceDictionary dictionary = new ResourceDictionary();
511
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
512
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
513
        }
514

    
515
        public override void Copy(CommentUserInfo lhs)
516
        {
517
            if (lhs is RectangleControl rectangleControl)
518
            {
519
                this.LineSize = rectangleControl.LineSize;
520
                this.Paint = rectangleControl.Paint;
521
                this.StartPoint = new System.Windows.Point(rectangleControl.StartPoint.X, rectangleControl.StartPoint.Y);
522
                this.EndPoint = new System.Windows.Point(rectangleControl.EndPoint.X, rectangleControl.EndPoint.Y);
523
                this.LeftBottomPoint = new System.Windows.Point(rectangleControl.LeftBottomPoint.X, rectangleControl.LeftBottomPoint.Y);
524
                this.TopRightPoint = new System.Windows.Point(rectangleControl.TopRightPoint.X, rectangleControl.TopRightPoint.Y);
525
                this.CommentAngle = rectangleControl.CommentAngle;
526
                this.StrokeColor = rectangleControl.StrokeColor;
527
                this.DashSize = rectangleControl.DashSize;
528
                this.Opacity = rectangleControl.Opacity;
529
                this.PointSet = rectangleControl.PointSet.ConvertAll(x => new System.Windows.Point(x.X, x.Y));
530
                this.UserID = rectangleControl.UserID;
531
                this.Memo = rectangleControl.Memo;
532
                this.ZIndex = rectangleControl.ZIndex;
533
            }
534
        }
535

    
536
        public override CommentUserInfo Clone()
537
        {
538
            var clone = new RectangleControl();
539
            clone.Copy(this);
540
            return clone;
541
        }
542

    
543

    
544
        public override void OnApplyTemplate()
545
        {
546
            base.OnApplyTemplate();
547

    
548
            Base_RectPath = GetTemplateChild(PART_RectPath) as Path;
549

    
550

    
551
            if (Base_RectPath == null)
552
                return;
553

    
554
            SetRectPath();
555
            Base_RectPath.Focus();
556
        }
557

    
558
        public override void UpdateControl()
559
        {
560
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
561
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
562
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
563
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
564
        }
565

    
566
        private void OnPropertyChanged(string name)
567
        {
568
            if (PropertyChanged != null)
569
            {
570
                PropertyChanged(this, new PropertyChangedEventArgs(name));
571
            }
572
        }
573

    
574
        public void ChangePaint(PaintSet state)
575
        {
576
            this.Paint = state;
577
            this.SetRectPath();
578
        }
579

    
580
        public event PropertyChangedEventHandler PropertyChanged;
581

    
582
        /// <summary>
583
        /// call when mouse is moving while drawing control
584
        /// </summary>
585
        /// <author>humkyung</author>
586
        /// <param name="pt"></param>
587
        /// <param name="bAxisLocked"></param>
588
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
589
        {
590
            this.EndPoint = bAxisLocked ? this.GetSquareEndPoint(this.StartPoint, pt) : pt;
591
            this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y);
592
            this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y);
593

    
594
            this.PointSet = new List<Point>
595
            {
596
                this.StartPoint,
597
                this.LeftBottomPoint,
598
                this.EndPoint,
599
                this.TopRightPoint,
600
            };
601
        }
602

    
603
        /// <summary>
604
        /// move control point has same location of given pt along given delta
605
        /// </summary>
606
        /// <author>humkyung</author>
607
        /// <date>2019.06.20</date>
608
        /// <param name="pt"></param>
609
        /// <param name="dx"></param>
610
        /// <param name="dy"></param>
611
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false)
612
        {
613
            IPath path = (this as IPath);
614

    
615
            Point selected = MathSet.getNearPoint(path.PointSet, pt);
616
            selected.X += dx;
617
            selected.Y += dy;
618
            int i = 0;
619
            for (i = 0; i < (this as IPath).PointSet.Count; i++)
620
            {
621
                if (pt.Equals((this as IPath).PointSet[i]))
622
                {
623
                    (this as IPath).PointSet[i] = selected;
624
                    break;
625
                }
626
            }
627

    
628

    
629
            var OppositeP = (i + path.PointSet.Count / 2) % path.PointSet.Count;
630
            var PreviousP = (i + (path.PointSet.Count - 1)) % path.PointSet.Count;
631
            var NextP = (i + 1) % path.PointSet.Count;
632
            if (bAxisLocked)
633
            {
634
                double _dx = path.PointSet[i].X - path.PointSet[OppositeP].X;
635
                double _dy = path.PointSet[i].Y - path.PointSet[OppositeP].Y;
636
                double distance = Math.Max(Math.Abs(_dx), Math.Abs(_dy));
637

    
638
                var PreviousV = path.PointSet[PreviousP] - path.PointSet[OppositeP];
639
                PreviousV.Normalize();
640
                path.PointSet[PreviousP] = path.PointSet[OppositeP] + PreviousV * distance;
641

    
642
                var NextV = path.PointSet[NextP] - path.PointSet[OppositeP];
643
                NextV.Normalize();
644
                path.PointSet[NextP] = path.PointSet[OppositeP] + NextV * distance;
645

    
646
                path.PointSet[i] = path.PointSet[OppositeP] + PreviousV * distance + NextV * distance;
647
            }
648
            else
649
            {
650
                var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[PreviousP]);
651
                var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X,
652
                    path.PointSet[i].Y - path.PointSet[OppositeP].Y);
653

    
654
                Point pPrevious = new Point(path.PointSet[OppositeP].X + PreviousV.X * l, path.PointSet
655
                    [OppositeP].Y + PreviousV.Y * l);
656

    
657
                if (path.PointSet.FindAll(x => x.Equals(pPrevious)).Count() == 0)
658
                {
659
                    path.PointSet[PreviousP] = pPrevious;
660
                }
661
                //path.PointSet[PreviousP] = pPrevious;
662

    
663
                var NextV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[NextP]);
664
                l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X, path.PointSet
665
                    [i].Y - path.PointSet[OppositeP].Y);
666

    
667
                Point pNext = new Point(path.PointSet[OppositeP].X + NextV.X * l, path.PointSet[OppositeP].Y + NextV.Y * l);
668

    
669
                if(path.PointSet.FindAll(x => x.Equals(pNext)).Count() == 0)
670
                {
671
                    path.PointSet[NextP] = pNext;
672
                }
673
                //path.PointSet[NextP] = pNext;
674

    
675
            }
676

    
677
            this.UpdateControl();
678
        }
679

    
680
        /// <summary>
681
        /// return rectanglecontrols' area
682
        /// </summary>
683
        public override Rect ItemRect
684
        {
685
            get
686
            {
687
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
688
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
689
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
690
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
691

    
692
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
693
            }
694
        }
695

    
696
        /// <summary>
697
        /// Serialize this
698
        /// </summary>
699
        /// <param name="sUserId"></param>
700
        /// <returns></returns>
701
        public override string Serialize()
702
        {
703
            using (S_RectControl ctrl = new S_RectControl())
704
            {
705
                ctrl.TransformPoint = "0|0";
706
                ctrl.SizeSet = String.Format("{0}", this.LineSize);
707
                ctrl.PaintState = this.Paint;
708
                ctrl.PointSet = this.PointSet;
709
                //ctrl.StrokeColor = "#FF00FF00";
710
                ctrl.StrokeColor = this.StrokeColor.Color.ToString();
711
                if (this.FillColor != null)
712
                {
713
                    ctrl.FillColor = this.FillColor.Color.ToString();
714
                }
715
                ctrl.StartPoint = this.StartPoint;
716
                ctrl.UserID = this.UserID;
717
                //ctrl.Angle = this.a;
718
                ctrl.EndPoint = this.EndPoint;
719
                ctrl.LB = this.LeftBottomPoint;
720
                ctrl.TR = this.TopRightPoint;
721
                ctrl.DashSize = this.DashSize;
722
                ctrl.Opac = this.Opacity;
723
                ctrl.Name = this.GetType().Name.ToString();
724
                ///강인구 추가(2017.11.02)
725
                ///Memo 추가
726
                ctrl.Memo = this.Memo;
727

    
728
                ctrl.ZIndex = this.ZIndex;
729

    
730
                return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize()));
731
            };
732
        }
733

    
734
        /// <summary>
735
        /// create a rectanglecontrol from given string
736
        /// </summary>
737
        /// <param name="item"></param>
738
        /// <returns></returns>
739
        public static RectangleControl FromString(string str, SolidColorBrush brush, string sProjectNo)
740
        {
741
            using (S_RectControl s = JsonSerializerHelper.JsonDeserialize<S_RectControl>(str))
742
            {
743
                string[] data2 = s.SizeSet.Split(CommentUserInfo.delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
744
                return new RectangleControl
745
                {
746
                    LineSize = Convert.ToDouble(data2.First()),
747
                    Paint = s.PaintState,
748
                    StartPoint = s.StartPoint,
749
                    EndPoint = s.EndPoint,
750
                    CommentAngle = s.Angle,
751
                    StrokeColor = brush,
752
                    DashSize = s.DashSize,
753
                    Opacity = s.Opac,
754
                    LeftBottomPoint = s.LB,
755
                    TopRightPoint = s.TR,
756
                    PointSet = s.PointSet,
757
                    UserID = s.UserID,
758
                    Memo = s.Memo,
759
                    ZIndex = s.ZIndex
760
                };
761
            }
762
        }
763

    
764
        public void Dispose()
765
        {
766
            //GC.Collect();
767
            ////GC.SuppressFinalize(this);
768
            this.Base_RectPath = null;
769
        }
770
        #endregion Internal Method
771
    }
772
}
클립보드 이미지 추가 (최대 크기: 500 MB)