프로젝트

일반

사용자정보

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

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

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

1
using System;
2
using System.Net;
3
using System.Windows;
4
using System.Windows.Controls;
5
using System.Windows.Documents;
6
using System.Windows.Ink;
7
using System.Windows.Input;
8
using System.Windows.Media;
9
using System.Windows.Media.Animation;
10
using System.Windows.Shapes;
11
using System.ComponentModel;
12
using System.Collections.Generic;
13
using MarkupToPDF.Controls.Common;
14
using MarkupToPDF.Common;
15
using MarkupToPDF.Serialize.Core;
16
using MarkupToPDF.Serialize.S_Control;
17
using System.Linq;
18
using System.ServiceModel.Activation;
19
using System.Windows.Markup;
20

    
21
namespace MarkupToPDF.Controls.Shape
22
{
23
    public class RectCloudControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IDashControl
24
    {
25
        #region 초기 선언
26
        private const string PART_ArcPath = "PART_ArcPath";
27
        private const string PART_BodyPath = "PART_BodyPath";
28
        public event PropertyChangedEventHandler PropertyChanged;
29

    
30
        public Path Base_ArcPath = null;
31
        public Path Base_BodyPath = null;
32

    
33
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
34

    
35
        #endregion
36

    
37
        static RectCloudControl()
38
        {
39
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RectCloudControl), new FrameworkPropertyMetadata(typeof(RectCloudControl)));
40
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
41
            //ResourceDictionary dictionary = new ResourceDictionary();
42
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
43
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
44
        }
45

    
46
        public override void Copy(CommentUserInfo lhs)
47
        {
48
            if (lhs is RectCloudControl rectCloudControl)
49
            {
50
                this.StartPoint = new System.Windows.Point(rectCloudControl.StartPoint.X, rectCloudControl.StartPoint.Y);
51
                this.EndPoint = new System.Windows.Point(rectCloudControl.EndPoint.X, rectCloudControl.EndPoint.Y);
52
                this.LeftBottomPoint = new System.Windows.Point(rectCloudControl.LeftBottomPoint.X, rectCloudControl.LeftBottomPoint.Y);
53
                this.TopRightPoint = new System.Windows.Point(rectCloudControl.TopRightPoint.X, rectCloudControl.TopRightPoint.Y);
54
                this.Paint = rectCloudControl.Paint;
55
                this.Opacity = rectCloudControl.Opacity;
56
                this.DashSize = rectCloudControl.DashSize;
57
                this.PointSet = rectCloudControl.PointSet.ConvertAll(x => new System.Windows.Point(x.X, x.Y));
58
                this.StrokeColor = rectCloudControl.StrokeColor;
59
                this.ArcLength = rectCloudControl.ArcLength;
60
                this.LineSize = rectCloudControl.LineSize;
61
                this.UserID = rectCloudControl.UserID;
62
                this.Memo = rectCloudControl.Memo;
63
                this.ZIndex = rectCloudControl.ZIndex;
64
            }
65
        }
66

    
67
        public override CommentUserInfo Clone()
68
        {
69
            var clone = new RectCloudControl();
70
            clone.Copy(this);
71
            return clone;
72
        }
73

    
74
        #region Dependency Properties
75

    
76
        public static readonly DependencyProperty mousemodeProperty =
77
                DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(RectangleControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
78
        public static readonly DependencyProperty IsSelectedProperty =
79
     DependencyProperty.Register("IsSelected", typeof(bool), typeof(RectCloudControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
80

    
81
        public static readonly DependencyProperty ControlTypeProperty =
82
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(RectCloudControl), new FrameworkPropertyMetadata(ControlType.RectCloud));
83

    
84
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
85
                "OverViewPathData", typeof(Geometry), typeof(RectCloudControl), new PropertyMetadata(null));
86

    
87
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
88
                "LineSize", typeof(double), typeof(RectCloudControl), new PropertyMetadata((Double)3));
89

    
90
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
91
                "UserID", typeof(string), typeof(RectCloudControl), new PropertyMetadata(null));
92

    
93
        //강인구 추가
94
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
95
                 "DashSize", typeof(DoubleCollection), typeof(RectCloudControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged));
96

    
97
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
98
                "FillColor", typeof(SolidColorBrush), typeof(RectCloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
99
        //강인구 추가
100
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
101
                "Paint", typeof(PaintSet), typeof(RectCloudControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
102

    
103
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
104
                "StrokeColor", typeof(SolidColorBrush), typeof(RectCloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
105

    
106
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
107
                "PathData", typeof(Geometry), typeof(RectCloudControl), null);
108

    
109
        public static readonly DependencyProperty PathSubDataProperty = DependencyProperty.Register(
110
                "PathSubData", typeof(Geometry), typeof(RectCloudControl), null);
111

    
112
        public static readonly DependencyProperty ArcLengthProperty = DependencyProperty.Register(
113
        "ArcLength", typeof(double), typeof(RectCloudControl), new PropertyMetadata((Double)10, PointValueChanged));
114

    
115
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
116
                "EndPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
117

    
118
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
119
                "StartPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
120

    
121
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
122
              "TopRightPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
123

    
124
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
125
                "LeftBottomPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
126

    
127
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
128
                "PointSet", typeof(List<Point>), typeof(RectCloudControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
129

    
130
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("AngleValue", typeof(double), typeof(RectCloudControl),
131
            new PropertyMetadata((double)0.0, new PropertyChangedCallback(PointValueChanged)));
132

    
133
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(RectCloudControl),
134
            new PropertyMetadata((double)0, PointValueChanged));
135

    
136
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(RectCloudControl),
137
            new PropertyMetadata((double)0, PointValueChanged));
138

    
139
        #endregion
140

    
141
        #region PropertyChanged Method
142
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
143
        {
144
            var instance = (RectCloudControl)sender;
145
            if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
146
            {
147
                instance.SetValue(e.Property, e.NewValue);
148
                instance.SetRectCloud();
149
            }
150
        }
151
        #endregion
152

    
153
        #region Properties
154

    
155
        public MouseMode mousemode
156
        {
157
            get
158
            {
159
                return (MouseMode)GetValue(mousemodeProperty);
160
            }
161
            set
162
            {
163
                SetValue(mousemodeProperty, value);
164
                OnPropertyChanged("mousemode");
165
            }
166
        }
167
        public Double LineSize
168
        {
169
            get { return (Double)GetValue(LineSizeProperty); }
170
            set
171
            {
172
                if (this.LineSize != value)
173
                {
174
                    SetValue(LineSizeProperty, value);
175
                }
176
            }
177
        }
178
        public DoubleCollection DashSize
179
        {
180
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
181
            set
182
            {
183
                if (this.DashSize != value)
184
                {
185
                    SetValue(DashSizeProperty, value);
186
                }
187
            }
188
        }
189
        public string UserID
190
        {
191
            get { return (string)GetValue(UserIDProperty); }
192
            set
193
            {
194
                if (this.UserID != value)
195
                {
196
                    SetValue(UserIDProperty, value);
197
                    OnPropertyChanged("UserID");
198
                }
199
            }
200
        }
201
        public PaintSet Paint
202
        {
203
            get { return (PaintSet)GetValue(PaintProperty); }
204
            set
205
            {
206
                if (this.Paint != value)
207
                {
208
                    SetValue(PaintProperty, value);
209
                }
210
            }
211
        }
212
        public SolidColorBrush FillColor
213
        {
214
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
215
            set
216
            {
217
                if (this.FillColor != value)
218
                {
219
                    SetValue(FillColorProperty, value);
220
                }
221
            }
222
        }
223
        public override SolidColorBrush StrokeColor
224
        {
225
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
226
            set
227
            {
228
                if (this.StrokeColor != value)
229
                {
230
                    SetValue(StrokeColorProperty, value);
231
                }
232
            }
233
        }
234

    
235
        public Geometry OverViewPathData
236
        {
237
            get
238
            {
239
                return (Geometry)GetValue(OverViewPathDataProperty);
240
            }
241
            set
242
            {
243
                SetValue(OverViewPathDataProperty, value);
244
                OnPropertyChanged("OverViewPathData");
245
            }
246
        }
247

    
248
        public Geometry PathData
249
        {
250
            get { return (Geometry)GetValue(PathDataProperty); }
251
            set { SetValue(PathDataProperty, value); }
252
        }
253
        public Geometry PathSubData
254
        {
255
            get { return (Geometry)GetValue(PathSubDataProperty); }
256
            set { SetValue(PathSubDataProperty, value); }
257
        }
258
        public Point EndPoint
259
        {
260
            get { return (Point)GetValue(EndPointProperty); }
261
            set { SetValue(EndPointProperty, value); }
262
        }
263
        public Point StartPoint
264
        {
265
            get { return (Point)GetValue(StartPointProperty); }
266
            set { SetValue(StartPointProperty, value); }
267
        }
268
        public List<Point> PointSet
269
        {
270
            get { return (List<Point>)GetValue(PointSetProperty); }
271
            set { SetValue(PointSetProperty, value); }
272
        }
273
        public override bool IsSelected
274
        {
275
            get
276
            {
277
                return (bool)GetValue(IsSelectedProperty);
278
            }
279
            set
280
            {
281
                SetValue(IsSelectedProperty, value);
282
            }
283
        }
284

    
285
        public override ControlType ControlType
286
        {
287
            get
288
            {
289
                return (ControlType)GetValue(ControlTypeProperty);
290
            }
291
            set
292
            {
293
                SetValue(ControlTypeProperty, value);
294
            }
295
        }
296

    
297
        public Double ArcLength
298
        {
299
            get { return (Double)GetValue(ArcLengthProperty); }
300
            set
301
            {
302
                if (this.ArcLength != value)
303
                {
304
                    SetValue(ArcLengthProperty, value);
305
                    OnPropertyChanged("ArcLength");
306
                }
307
            }
308
        }
309

    
310

    
311
        private double _toler = 1;
312
        public double Toler
313
        {
314
            get { return _toler; }
315
            set { _toler = value; }
316
        }
317
        //private double _arcLength = 30;
318
        //public double ArcLength
319
        //{
320
        //    get { return _arcLength; }
321
        //    set { _arcLength = value; }
322
        //}
323

    
324
        private bool _fill = false;
325
        public bool Fill
326
        {
327
            get { return _fill; }
328
            set { _fill = value; }
329
        }
330
        public double CommentAngle
331
        {
332
            get { return (double)GetValue(AngleProperty); }
333
            set
334
            {
335
                if (this.CommentAngle != value)
336
                {
337
                    SetValue(AngleProperty, value);
338
                }
339
            }
340
        }
341
        public double CenterX
342
        {
343
            get { return (double)GetValue(CenterXProperty); }
344
            set { SetValue(CenterXProperty, value); }
345
        }
346
        public double CenterY
347
        {
348
            get { return (double)GetValue(CenterYProperty); }
349
            set { SetValue(CenterYProperty, value); }
350
        }
351
        public Point LeftBottomPoint
352
        {
353
            get { return (Point)GetValue(LeftBottomPointProperty); }
354
            set
355
            {
356
                SetValue(LeftBottomPointProperty, value);
357
                OnPropertyChanged("LeftBottomPoint");
358
            }
359
        }
360
        public Point TopRightPoint
361
        {
362
            get { return (Point)GetValue(TopRightPointProperty); }
363
            set
364
            {
365
                SetValue(TopRightPointProperty, value);
366
                OnPropertyChanged("TopRightPoint");
367
            }
368
        }
369
        #endregion
370

    
371
        #region Data
372
        private PathGeometry _pathGeometry = new PathGeometry();
373
        #endregion
374

    
375
        public override void OnApplyTemplate()
376
        {
377
            base.OnApplyTemplate();
378
            Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path;
379
            Base_BodyPath = GetTemplateChild(PART_BodyPath) as Path;
380

    
381
            this.SetRectCloud();
382

    
383
        }
384
        protected void OnPropertyChanged(string propName)
385
        {
386
            if (PropertyChanged != null)
387
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
388
        }
389
        public void Dispose()
390
        {
391
            //GC.Collect();
392
            ////GC.SuppressFinalize(this);
393
            this.Base_ArcPath = null;
394
            this.Base_BodyPath = null;
395
        }
396

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

    
401
            //if (e.OldValue != e.NewValue && instance.Base_BodyPath != null)
402
            //{
403

    
404
            //    instance.SetValue(e.Property, e.NewValue);
405

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

    
417
        private void SetRectCloud()
418
        {
419
            this.ApplyTemplate();
420
            PathFigure pathFigure = new PathFigure();
421

    
422
            Base_ArcPath.StrokeDashArray.Clear();
423
            Base_BodyPath.StrokeDashArray.Clear();
424

    
425
            foreach (var item in this.DashSize)
426
            {
427
                Base_ArcPath.StrokeDashArray.Add(item);
428
                Base_BodyPath.StrokeDashArray.Add(item);
429
            }
430

    
431
            switch (this.Paint)
432
            {
433
                case PaintSet.None:
434
                    //강인구 추가
435
                    pathFigure.IsFilled = false;
436
                    Base_BodyPath.Fill = null;
437
                    Base_BodyPath.Stroke = null;
438
                    break;
439
                case PaintSet.Fill:
440
                    {
441
                        Base_BodyPath.Stroke = this.StrokeColor;
442
                        Base_BodyPath.StrokeThickness = 0.5;
443
                        Base_ArcPath.Stroke = this.StrokeColor;
444

    
445
                        Base_ArcPath.Fill = this.FillColor;
446
                        Base_BodyPath.Fill = this.FillColor;
447
                    }
448
                    //this.FillColor = this.StrokeColor;
449
                    //Base_BodyPath.Fill = this.FillColor;
450
                    //Base_ArcPath.Fill = this.FillColor;
451
                    //Base_BodyPath.Stroke = this.StrokeColor;
452
                    //Base_BodyPath.StrokeThickness = 2;
453
                    //Base_ArcPath.Stroke = this.StrokeColor;
454
                    //Base_ArcPath.StrokeThickness = 2;
455
                    //pathFigure.IsFilled = true;
456
                    break;
457
                case PaintSet.Hatch:
458
                    Base_BodyPath.Stroke = new SolidColorBrush(Colors.Transparent);
459
                    Base_BodyPath.StrokeThickness = 2;
460
                    Base_BodyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
461
                    Base_ArcPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
462
                    pathFigure.IsFilled = true;
463
                    break;
464
                default:
465
                    break;
466
            }
467

    
468
            #region 사각형 만들기
469
            if (this.Paint != PaintSet.None)
470
            {
471
                pathFigure.StartPoint = this.StartPoint;
472

    
473
                List<Point> points = new List<Point>() { this.StartPoint, this.LeftBottomPoint, this.EndPoint, this.TopRightPoint };
474
                PolyLineSegment polyline = new PolyLineSegment(points, true);
475
                pathFigure.Segments.Add(polyline);
476
                
477
                PathGeometry pathGeometry = new PathGeometry();
478
                pathGeometry.Figures = new PathFigureCollection();
479
                pathFigure.IsClosed = true;
480
                pathGeometry.Figures.Add(pathFigure);
481
                //this.FillColor = new SolidColorBrush(Colors.Red);
482
                this.PathSubData = pathGeometry;
483
            }
484
            ArcLength = ArcLength == 0 ? 10 : ArcLength;
485

    
486
            #endregion
487
            #region Cloud 만들기
488
            /// set reverse if area is greater 0 - 2012.07.04 added by humkyung
489
            /// 
490

    
491
            System.Diagnostics.Debug.WriteLine(ArcLength);
492
            double area = MathSet.AreaOf(new List<Point>() { this.StartPoint, this.LeftBottomPoint, this.EndPoint, this.TopRightPoint });
493
            bool reverse = (area > 0);
494
            /// up to here
495
            this._pathGeometry = new PathGeometry();
496
            int count = this.PointSet.Count;
497
            PathFigure pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.StartPoint, this.LeftBottomPoint, this.ArcLength, reverse);
498
            _pathGeometry.Figures.Add(pathSubFigure);
499

    
500
            pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.LeftBottomPoint, this.EndPoint, this.ArcLength, reverse);
501
            _pathGeometry.Figures.Add(pathSubFigure);
502

    
503
            pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.EndPoint, this.TopRightPoint, this.ArcLength, reverse);
504
            _pathGeometry.Figures.Add(pathSubFigure);
505

    
506
            pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.TopRightPoint, this.StartPoint, this.ArcLength, reverse);
507
            _pathGeometry.Figures.Add(pathSubFigure);
508

    
509
            if (this.Paint != PaintSet.None)
510
            {
511
                foreach (var item in _pathGeometry.Figures)
512
                {
513
                    item.IsFilled = true;
514
                }
515
            }
516

    
517
            this.PathData = _pathGeometry;
518
            ApplyOverViewData();
519
            #endregion
520
        }
521

    
522
        public void ChangePaint(PaintSet state)
523
        {
524
            this.Paint = state;
525
            this.SetRectCloud();
526
        }
527

    
528
        public void CloseSettingPoint()
529
        {
530
            this.PointSet[0] = this.StartPoint;
531
            this.PointSet[1] = this.LeftBottomPoint;
532
            this.PointSet[2] = this.EndPoint;
533
            this.PointSet[3] = this.TopRightPoint;
534
        }
535

    
536
        public override void ApplyOverViewData()
537
        {
538
            this.OverViewPathData = this.PathData;
539
        }
540

    
541
        public override void UpdateControl()
542
        {
543
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
544
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
545
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
546
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
547
        }
548

    
549
        /// <summary>
550
        /// call when mouse is moving while drawing control
551
        /// </summary>
552
        /// <author>humkyung</author>
553
        /// <param name="pt"></param>
554
        /// <param name="bAxisLocked"></param>
555
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
556
        {
557
            this.EndPoint = bAxisLocked ? this.GetSquareEndPoint(this.StartPoint, pt) : pt;
558
            this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y);
559
            this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y);
560
            
561
            this.PointSet = new List<Point>
562
            {
563
                this.StartPoint,
564
                this.LeftBottomPoint,
565
                this.EndPoint,
566
                this.TopRightPoint,
567
            };
568
        }
569

    
570
        /// <summary>
571
        /// move control point has same location of given pt along given delta
572
        /// </summary>
573
        /// <author>humkyung</author>
574
        /// <date>2019.06.20</date>
575
        /// <param name="pt"></param>
576
        /// <param name="dx"></param>
577
        /// <param name="dy"></param>
578
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false)
579
        {
580
            IPath path = (this as IPath);
581

    
582
            Point selected = MathSet.getNearPoint(path.PointSet, pt);
583
            selected.X += dx;
584
            selected.Y += dy;
585
            int i = 0;
586
            for (i = 0; i < (this as IPath).PointSet.Count; i++)
587
            {
588
                if (pt.Equals((this as IPath).PointSet[i]))
589
                {
590
                    (this as IPath).PointSet[i] = selected;
591
                    break;
592
                }
593
            }
594

    
595
            var OppositeP = (i + path.PointSet.Count / 2) % path.PointSet.Count;
596
            var PreviousP = (i + (path.PointSet.Count - 1)) % path.PointSet.Count;
597
            var NextP = (i + 1) % path.PointSet.Count;
598

    
599
            if (bAxisLocked)
600
            {
601
                double _dx = path.PointSet[i].X - path.PointSet[OppositeP].X;
602
                double _dy = path.PointSet[i].Y - path.PointSet[OppositeP].Y;
603
                double distance = Math.Max(Math.Abs(_dx), Math.Abs(_dy));
604

    
605
                var PreviousV = path.PointSet[PreviousP] - path.PointSet[OppositeP];
606
                PreviousV.Normalize();
607
                path.PointSet[PreviousP] = path.PointSet[OppositeP] + PreviousV * distance;
608

    
609
                var NextV = path.PointSet[NextP] - path.PointSet[OppositeP];
610
                NextV.Normalize();
611
                path.PointSet[NextP] = path.PointSet[OppositeP] + NextV * distance;
612

    
613
                path.PointSet[i] = path.PointSet[OppositeP] + PreviousV * distance + NextV * distance;
614
            }
615
            else
616
            {
617
                var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[PreviousP]);
618
                var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X,
619
                    path.PointSet[i].Y - path.PointSet[OppositeP].Y);
620

    
621
                Point pPrevious = new Point(path.PointSet[OppositeP].X + PreviousV.X * l, path.PointSet
622
                    [OppositeP].Y + PreviousV.Y * l);
623

    
624
                if (path.PointSet.FindAll(x => x.Equals(pPrevious)).Count() == 0)
625
                {
626
                    path.PointSet[PreviousP] = pPrevious;
627
                }
628

    
629
                var NextV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[NextP]);
630
                l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X, path.PointSet
631
                    [i].Y - path.PointSet[OppositeP].Y);
632

    
633
                Point pNext = new Point(path.PointSet[OppositeP].X + NextV.X * l, path.PointSet[OppositeP].Y + NextV.Y * l);
634
                if (path.PointSet.FindAll(x => x.Equals(pNext)).Count() == 0)
635
                {
636
                    path.PointSet[NextP] = pNext;
637
                }
638
            }
639

    
640
            this.UpdateControl();
641
        }
642

    
643
        /// <summary>
644
        /// return rectcloudcontrols' area
645
        /// </summary>
646
        /// <author>humkyung</author>
647
        /// <date>2019.06.13</date>
648
        public override Rect ItemRect
649
        {
650
            get
651
            {
652
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
653
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
654
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
655
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
656

    
657
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
658
            }
659
        }
660

    
661
        /// <summary>
662
        /// Serialize this
663
        /// </summary>
664
        /// <param name="sUserId"></param>
665
        /// <returns></returns>
666
        public override string Serialize()
667
        {
668
            using (S_RectCloudControl ctrl = new S_RectCloudControl())
669
            {
670
                ctrl.TransformPoint = "0|0";
671
                ctrl.PointSet = this.PointSet;
672
                ctrl.SizeSet = String.Format("{0}", this.LineSize);
673
                //ctrl.StrokeColor = "#FF00FF00";
674
                ctrl.StrokeColor = this.StrokeColor.Color.ToString();
675
                ctrl.StartPoint = this.StartPoint;
676
                ctrl.UserID = this.UserID;
677
                ctrl.Opac = this.Opacity;
678
                ctrl.TR = this.TopRightPoint;
679
                ctrl.LB = this.LeftBottomPoint;
680
                ctrl.EndPoint = this.EndPoint;
681
                ctrl.PaintState = this.Paint;
682
                ctrl.DashSize = this.DashSize;
683
                ctrl.ArcLength = this.ArcLength;
684
                ctrl.Name = this.GetType().Name.ToString();
685
                ///강인구 추가(2017.11.02)
686
                ///Memo 추가
687
                ctrl.Memo = this.Memo;
688

    
689
                ctrl.ZIndex = this.ZIndex;
690

    
691
                return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize()));
692
            }
693
        }
694

    
695
        /// <summary>
696
        /// create a rectcloudcontrol from given string
697
        /// </summary>
698
        /// <param name="str"></param>
699
        /// <returns></returns>
700
        public static RectCloudControl FromString(string str, SolidColorBrush brush, string sProjectNo)
701
        {
702
            using (S_RectCloudControl s = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(str))
703
            {
704
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
705
                return new RectCloudControl()
706
                {
707
                    StartPoint = s.StartPoint,
708
                    EndPoint = s.EndPoint,
709
                    LeftBottomPoint = s.LB,
710
                    Paint = s.PaintState,
711
                    Opacity = s.Opac,
712
                    DashSize = s.DashSize,
713
                    TopRightPoint = s.TR,
714
                    PointSet = s.PointSet,
715
                    StrokeColor = brush,
716
                    ArcLength = s.ArcLength,
717
                    LineSize = Convert.ToDouble(data2.First()),
718
                    UserID = s.UserID,
719
                    Memo = s.Memo,
720
                    ZIndex = s.ZIndex
721
                };
722
            }
723
        }
724
    }
725
}
클립보드 이미지 추가 (최대 크기: 500 MB)