프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Polygon / CloudControl.cs @ 036650a0

이력 | 보기 | 이력해설 | 다운로드 (30.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.Collections.Generic;
12
using System.ComponentModel;
13
using MarkupToPDF.Controls.Common;
14
using MarkupToPDF.Common;
15
using MarkupToPDF.Serialize.Core;
16
using MarkupToPDF.Serialize.S_Control;
17

    
18
namespace MarkupToPDF.Controls.Polygon
19
{
20
    public class CloudControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IShapeControl, ICloudControl, IDashControl
21
    {
22
        private const string PART_CloudPath = "PART_CloudPath";
23
        private const string PART_CloudSubPath = "PART_CloudSubPath";
24

    
25
        public Path Base_CloudPath = null;
26
        public Path Base_CloudSubPath = null;
27

    
28
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
29

    
30
        static CloudControl()
31
        {
32
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CloudControl), new FrameworkPropertyMetadata(typeof(CloudControl)));
33
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
34
            ResourceDictionary dictionary = new ResourceDictionary();
35
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
36
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
37
        }
38
        public CloudControl()
39
        {
40
            this.DefaultStyleKey = typeof(CloudControl);
41
        }
42

    
43
        #region Dependency Properties
44
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
45
                "UserID", typeof(string), typeof(CloudControl), new PropertyMetadata(null));
46
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
47
                "LineSize", typeof(double), typeof(CloudControl), new PropertyMetadata((Double)3));
48
        //강인구 추가
49
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
50
                 "DashSize", typeof(DoubleCollection), typeof(CloudControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged));
51
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
52
                "FillColor", typeof(SolidColorBrush), typeof(CloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
53

    
54
        public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register(
55
                "IsCompleted", typeof(bool), typeof(CloudControl), null);
56
        //강인구
57
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
58
                "Paint", typeof(PaintSet), typeof(CloudControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
59

    
60
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
61
                "StrokeColor", typeof(SolidColorBrush), typeof(CloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
62

    
63
        public static readonly DependencyProperty ArcLengthProperty = DependencyProperty.Register(
64
                "ArcLength", typeof(double), typeof(CloudControl), new PropertyMetadata((Double)10, PointValueChanged));
65

    
66
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
67
                "PathData", typeof(Geometry), typeof(CloudControl), null);
68

    
69
        public static readonly DependencyProperty PathSubDataProperty = DependencyProperty.Register(
70
                "PathSubData", typeof(Geometry), typeof(CloudControl), null);
71

    
72
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
73
                "EndPoint", typeof(Point), typeof(CloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
74

    
75
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
76
                "StartPoint", typeof(Point), typeof(CloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
77

    
78
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
79
                "PointSet", typeof(List<Point>), typeof(CloudControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
80
        public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register(
81
                "isTransOn", typeof(bool), typeof(CloudControl), new PropertyMetadata(false));
82
        public static readonly DependencyProperty isChainProperty = DependencyProperty.Register(
83
                "isChain", typeof(bool), typeof(CloudControl), new PropertyMetadata(false));
84
       
85
        /// <summary>
86
        /// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다.
87
        /// </summary>
88
        public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register(
89
               "PointC", typeof(StylusPointSet), typeof(CloudControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged));
90

    
91
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("AngleValue", typeof(double), typeof(CloudControl),
92
            new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
93

    
94
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(CloudControl),
95
            new PropertyMetadata((double)0, OnCenterXYChanged));
96

    
97
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(CloudControl),
98
            new PropertyMetadata((double)0, OnCenterXYChanged));
99

    
100
        public static readonly DependencyProperty IsSelectedProperty =
101
    DependencyProperty.Register("IsSelected", typeof(bool), typeof(CloudControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
102

    
103
        public static readonly DependencyProperty ControlTypeProperty =
104
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(CloudControl), new FrameworkPropertyMetadata(ControlType.PolygonCloud));
105

    
106
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
107
        "OverViewPathData", typeof(Geometry), typeof(ControlType), null);
108

    
109

    
110
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
111
                "CanvasX", typeof(double), typeof(CloudControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
112

    
113
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
114
                "CanvasY", typeof(double), typeof(CloudControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
115

    
116

    
117
        #endregion
118
        #region PropertyChanged Method
119

    
120
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
121
        {
122
            var instance = (CloudControl)sender;
123

    
124
            if (e.OldValue != e.NewValue && instance != null)
125
            {
126
                instance.SetValue(e.Property, e.NewValue);
127
            }
128
        }
129

    
130
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
131
        {
132
            var instance = (CloudControl)sender;
133
            if (e.OldValue != e.NewValue && instance.Base_CloudPath != null)
134
            {
135
                instance.SetValue(e.Property, e.NewValue);
136
                //강인구 추가
137
                instance.SetCloud();
138
                //주석처리
139
            }
140
        }
141
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
142
        {
143
            //var instance = (CloudControl)sender;
144

    
145
            //if (e.OldValue != e.NewValue && instance.Base_CloudPath != null)
146
            //{
147

    
148
            //    instance.SetValue(e.Property, e.NewValue);
149

    
150
            //    if (instance.IsSelected)
151
            //    {
152
            //        instance.Base_CloudPath.Stroke = new SolidColorBrush(Colors.Blue);
153
            //    }
154
            //    else
155
            //    {
156
            //        instance.Base_CloudPath.Stroke = new SolidColorBrush(Colors.Red);
157
            //    }
158
            //}
159
        }
160

    
161
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
162
        {
163
            var instance = (CloudControl)sender;
164
            if (e.OldValue != e.NewValue && instance.Base_CloudPath != null)
165
            {
166
                instance.SetValue(e.Property, e.NewValue);
167
                instance.DrawingCloud();
168
            }
169
        }
170
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
171
        {
172
            var instance = (CloudControl)sender;
173
            if (e.OldValue != e.NewValue && instance.Base_CloudPath != null)
174
            {
175
                instance.SetValue(e.Property, e.NewValue);
176
                instance.DrawingCloud();
177
            }
178
        }
179
        #endregion
180
        #region Properties
181

    
182

    
183
        public bool IsCompleted
184
        {
185
            get { return (bool)GetValue(IsCompletedProperty); }
186
            set
187
            {
188
                SetValue(IsCompletedProperty, value);
189
            }
190
        }
191

    
192
        public Geometry OverViewPathData
193
        {
194
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
195
            set
196
            {
197
                SetValue(OverViewPathDataProperty, value);
198
                OnPropertyChanged("OverViewPathData");
199
            }
200
        }
201

    
202
        public double CanvasX
203
        {
204
            get { return (double)GetValue(CanvasXProperty); }
205
            set
206
            {
207
                if (this.CanvasX != value)
208
                {
209
                    SetValue(CanvasXProperty, value);
210
                }
211
            }
212
        }
213

    
214
        public double CanvasY
215
        {
216
            get { return (double)GetValue(CanvasYProperty); }
217
            set
218
            {
219
                if (this.CanvasY != value)
220
                {
221
                    SetValue(CanvasYProperty, value);
222
                }
223
            }
224
        }
225

    
226
        public bool IsSelected
227
        {
228
            get
229
            {
230
                return (bool)GetValue(IsSelectedProperty);
231
            }
232
            set
233
            {
234
                SetValue(IsSelectedProperty, value);
235
            }
236
        }
237

    
238
        override public ControlType ControlType
239
        {
240
            set
241
            {
242
                SetValue(ControlTypeProperty, value);
243
            }
244
            get
245
            {
246
                return (ControlType)GetValue(ControlTypeProperty);
247
            }
248
        }
249

    
250
        public Double LineSize
251
        {
252
            get { return (Double)GetValue(LineSizeProperty); }
253
            set
254
            {
255
                if (this.LineSize != value)
256
                {
257
                    SetValue(LineSizeProperty, value);
258
                }
259
            }
260
        }
261
        public bool isChain
262
        {
263
            get { return (bool)GetValue(isChainProperty); }
264
            set
265
            {
266
                SetValue(isChainProperty, value);
267
                OnPropertyChanged("isChain");
268
            }
269
        }
270
        public bool isTransOn
271
        {
272
            get { return (bool)GetValue(isTransOnProperty); }
273
            set
274
            {
275
                SetValue(isTransOnProperty, value);
276
                OnPropertyChanged("isTransOn");
277
            }
278
        }
279
        public DoubleCollection DashSize
280
        {
281
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
282
            set
283
            {
284
                if (this.DashSize != value)
285
                {
286
                    SetValue(DashSizeProperty, value);
287
                    OnPropertyChanged("DashSize");
288
                }
289
            }
290
        }
291
        public string UserID
292
        {
293
            get { return (string)GetValue(UserIDProperty); }
294
            set
295
            {
296
                if (this.UserID != value)
297
                {
298
                    SetValue(UserIDProperty, value);
299
                    OnPropertyChanged("UserID");
300
                }
301
            }
302
        }
303
        public PaintSet Paint
304
        {
305
            get { return (PaintSet)GetValue(PaintProperty); }
306
            set
307
            {
308
                if (this.Paint != value)
309
                {
310
                    SetValue(PaintProperty, value);
311
                    OnPropertyChanged("Paint");
312
                }
313
            }
314
        }
315

    
316
        public SolidColorBrush FillColor
317
        {
318
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
319
            set
320
            {
321
                if (this.FillColor != value)
322
                {
323
                    SetValue(FillColorProperty, value);
324
                    OnPropertyChanged("FillColor");
325
                }
326
            }
327
        }
328
        public SolidColorBrush StrokeColor
329
        {
330
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
331
            set
332
            {
333
                if (this.StrokeColor != value)
334
                {
335
                    SetValue(StrokeColorProperty, value);
336
                    OnPropertyChanged("StrokeColor");
337
                }
338
            }
339
        }
340
        public Geometry PathData
341
        {
342
            get 
343
            {
344
                return (Geometry)GetValue(PathDataProperty); 
345
            }
346
            set 
347
            {
348
                SetValue(PathDataProperty, value);
349
                OnPropertyChanged("PathData");
350
            }
351
        }
352
        public Geometry PathSubData
353
        {
354
            get 
355
            {
356
                return (Geometry)GetValue(PathSubDataProperty); 
357
            }
358
            set
359
            {
360
                SetValue(PathSubDataProperty, value);
361
                OnPropertyChanged("PathSubData");
362
            }
363
        }
364
        public Point EndPoint
365
        {
366
            get 
367
            {
368
                return (Point)GetValue(EndPointProperty); 
369
            }
370
            set
371
            {
372
                SetValue(EndPointProperty, value);
373
                OnPropertyChanged("EndPoint");
374
            }
375
        }
376
        public Point StartPoint
377
        {
378
            get 
379
            {
380
                return (Point)GetValue(StartPointProperty); 
381
            }
382
            set
383
            {
384
                SetValue(StartPointProperty, value);
385
                OnPropertyChanged("StartPoint");
386
            }
387
        }
388
        public List<Point> _pointSet;
389

    
390
        public List<Point> PointSet
391
        {
392
            get 
393
            {
394
                return (List<Point>)GetValue(PointSetProperty);
395
            }
396
            set 
397
            {
398
                SetValue(PointSetProperty, value);
399
                OnPropertyChanged("PointSet");
400
            }
401
        }
402

    
403
        public List<Point> pointSet
404
        {
405
            get
406
            {
407
                return _pointSet;
408
            }
409
            set
410
            {
411
                _pointSet = value;
412
                OnPropertyChanged("pointSet");
413
            }
414
        }
415

    
416
        public Double ArcLength
417
        {
418
            get { return (Double)GetValue(ArcLengthProperty); }
419
            set
420
            {
421
                if (this.ArcLength != value)
422
                {
423
                    SetValue(ArcLengthProperty, value);
424
                    OnPropertyChanged("ArcLength");
425
                }
426
            }
427
        }
428

    
429
        private double _toler = 1;
430
        public double Toler
431
        {
432
            get { return _toler; }
433
            set { _toler = value; }
434
        }
435
        //강인구 수정 클라우드 사이즈
436
        //private double _arcLength;
437
        ////private double _arcLength = 30;
438
        //public double ArcLength
439
        //{
440
        //    get { return _arcLength; }
441
        //    set { _arcLength = value; }
442
        //}
443
        private bool _fill = false;
444
        public bool Fill
445
        {
446
            get { return _fill; }
447
            set { _fill = value; }
448
        }
449
        public double Angle
450
        {
451
            get { return (double)GetValue(AngleProperty); }
452
            set
453
            {
454
                if (this.Angle != value)
455
                {
456
                    SetValue(AngleProperty, value);
457
                    OnPropertyChanged("Angle");
458
                }
459
            }
460
        }
461
        public StylusPointSet PointC
462
        {
463
            get { return (StylusPointSet)GetValue(StylusPointSetProperty); }
464
            set
465
            {
466
                SetValue(StylusPointSetProperty, value);
467
                OnPropertyChanged("PointC");
468
            }
469
        }
470
        public double CenterX
471
        {
472
            get
473
            {
474
                return (double)GetValue(CenterXProperty); 
475
            }
476
            set
477
            {
478
                SetValue(CenterXProperty, value);
479
                OnPropertyChanged("CenterX");
480
            }
481
        }
482
        public double CenterY
483
        {
484
            get
485
            { 
486
                return (double)GetValue(CenterYProperty); 
487
            }
488
            set
489
            {
490
                SetValue(CenterYProperty, value);
491
                OnPropertyChanged("CenterY");
492
            }
493
        }
494
        public double AngleValue
495
        {
496
            get 
497
            {
498
                return (double)GetValue(AngleProperty); 
499
            }
500
            set
501
            {
502
                SetValue(AngleProperty, value);
503
                OnPropertyChanged("AngleValue");
504
            }
505
        }
506
        #endregion
507
        #region Data
508
        private PathGeometry _pathGeometry = new PathGeometry();
509
        private PathGeometry _pathSubGeometry = new PathGeometry();
510
        #endregion
511

    
512
        public override void OnApplyTemplate()
513
        {
514
            base.OnApplyTemplate();
515
            Base_CloudPath = GetTemplateChild(PART_CloudPath) as Path;
516
            Base_CloudSubPath = GetTemplateChild(PART_CloudSubPath) as Path;
517
            SetCloud();
518
        }
519
        public void SetCloud()
520
        {
521
            //this.Width = this.Base_CloudPath.Width;
522
            //this.Height = this.Base_CloudPath.Height;
523

    
524
            this.ApplyTemplate();
525

    
526
            Generate();
527

    
528
            if (!isChain)
529
            {
530
                //ClosePath();
531
            }
532
        }
533
        public int Generate()
534
        {
535
            this._pathGeometry = null;
536
            this._pathSubGeometry = null;
537
            switch (this.Paint)
538
            {
539
                case PaintSet.None:
540
                    this.FillColor = null;
541
                    if (Base_CloudSubPath != null)
542
                    {
543
                        Base_CloudPath.Fill = null;
544
                        Base_CloudSubPath.Fill = null;
545
                        Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent);
546
                        //Base_CloudSubPath.StrokeThickness = 3;
547
                    }                    
548
                    break;
549
                case PaintSet.Fill:
550
                    this.FillColor = this.StrokeColor;
551
                    if (Base_CloudSubPath != null)
552
                    {
553
                        if (isChain)
554
                        {
555
                            Base_CloudPath.Fill = null;
556
                            Base_CloudSubPath.Fill = null;
557
                            Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent);
558
                            //Base_CloudSubPath.StrokeThickness = 3;
559
                        }
560
                        else
561
                        {
562
                            Base_CloudSubPath.Stroke = this.StrokeColor;
563
                            //Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent);
564
                            Base_CloudSubPath.StrokeThickness = 0.5;
565
                            Base_CloudPath.Stroke = this.StrokeColor;
566
                            //Base_CloudPath.StrokeThickness = 3;
567
                            Base_CloudPath.Fill = this.FillColor;
568
                            Base_CloudSubPath.Fill = this.FillColor;
569
                        }
570
                    }                   
571
                    break;
572
                case PaintSet.Hatch:
573
                    if (Base_CloudSubPath != null && !isChain)
574
                    {
575
                        if (isChain)
576
                        {
577
                            Base_CloudPath.Fill = null;
578
                            Base_CloudSubPath.Fill = null;
579
                            Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent);
580
                            //Base_CloudSubPath.StrokeThickness = 3;
581
                        }
582
                        else
583
                        {
584
                            Base_CloudPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, this.LineSize * 0.1);
585
                            Base_CloudSubPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, this.LineSize * 0.1);
586
                            Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent);
587
                        }
588
                    }
589
                    break;
590
                default:
591
                    break;
592
            }
593

    
594
            //강인구 추가
595
            if (Base_CloudPath != null)
596
            {
597
                Base_CloudPath.StrokeDashArray.Clear();
598
                Base_CloudSubPath.StrokeDashArray.Clear();
599
                foreach (var item in this.DashSize)
600
                {
601
                    Base_CloudPath.StrokeDashArray.Add(item);
602
                    Base_CloudSubPath.StrokeDashArray.Add(item);
603
                }
604
            }
605

    
606

    
607
            /// set reverse if area is greater 0 - 2012.07.04 added by humkyung
608
            double area = MathSet.AreaOf(this.PointSet);
609
            bool reverse = (area > 0);
610
            /// up to here
611

    
612
            this._pathGeometry = new PathGeometry();
613
            this._pathSubGeometry = new PathGeometry();
614
            int count = this.PointSet.Count;
615

    
616
            if (isTransOn) // true라면 클라우드 컨트롤
617
            {
618
                for (int i = 0; i < (count - 1); i++)
619
                {
620
                    PathFigure pathFigure = CloudControl.GenerateLineWithCloud(this.PointSet[i], this.PointSet[i + 1], this.ArcLength, reverse);
621
                    _pathGeometry.Figures.Add(pathFigure);
622
                }
623
            }
624
            else
625
            {
626
                PathFigure fm = new PathFigure();
627
                fm.StartPoint = this.PointSet[0];
628
                for (int i = 0; i < (count - 1); i++)
629
                {
630
                    fm.Segments.Add(new LineSegment { Point = this.PointSet[i] });
631
                }
632
                _pathGeometry.Figures.Add(fm);
633
            }
634

    
635
            if (this.Paint == PaintSet.Fill || this.Paint == PaintSet.Hatch)
636
            {
637
                PointCollection pd = new PointCollection();
638
                foreach (var item in this.PointSet)
639
                {
640
                    pd.Add(item);
641
                }
642
                _pathSubGeometry.Figures.Add(new PathFigure()
643
                {
644
                    Segments = new PathSegmentCollection()
645
                    {
646
                        new PolyLineSegment()
647
                        {
648
                              Points = pd
649
                        },
650
                    },
651
                    StartPoint = this.PointSet[0]
652
                });
653

    
654
                this.PathSubData = _pathSubGeometry;
655
            }
656
            StartPoint = PointSet[0];
657
            this.PathData = this._pathGeometry;
658
            this.OverViewPathData = PathData;
659
            this.StrokeColor = StrokeColor;
660
            this.LineSize = LineSize;
661
            EndPoint = PointSet[PointSet.Count - 1];
662

    
663
            return 0;
664
        }
665

    
666
        /// <summary>
667
        /// draw arcs between p1 and p2
668
        /// </summary>
669
        /// <author>humkyung</author>
670
        /// <param name="p1"></param>
671
        /// <param name="p2"></param>
672
        /// <param name="reverse"></param>
673
        /// <returns></returns>
674
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double arcLength_, bool reverse)
675
        {
676
            PathFigure pathFigure = new PathFigure();
677
            pathFigure.StartPoint = p1;
678

    
679
            double arcLength = arcLength_;
680
            /// draw arcs which has arcLength between p1 and p2 - 2012.06.21 added by humkyung 
681
            double dx = p2.X - p1.X;
682
            double dy = p2.Y - p1.Y;
683
            double l = MathSet.DistanceTo(p1, p2); /// distance between p1 and p2
684
            double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI;
685
            Point lastPt = new Point(p1.X, p1.Y);
686
            double count = l / arcLength;
687
            /// normalize
688
            dx /= l;
689
            dy /= l;
690
            Double j = 1;
691
            for (j = 1; j < (count - 1); j++)
692
            {
693
                ArcSegment arcSeg = new ArcSegment();
694
                arcSeg.Size = new Size(arcLength * CloudControl._CloudArcDepth, arcLength * CloudControl._CloudArcDepth);						/// x size and y size of arc
695
                arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength);	/// end point of arc
696
                lastPt = arcSeg.Point;  /// save last point
697
                arcSeg.RotationAngle = theta + 90;
698
                if (true == reverse) arcSeg.SweepDirection = SweepDirection.Clockwise;
699
                pathFigure.Segments.Add(arcSeg);
700
            }
701

    
702
            /// draw arc between last point and end point
703
            if ((count > j) || (count > 0))
704
            {
705
                arcLength = MathSet.DistanceTo(lastPt, p2);
706
                ArcSegment arcSeg = new ArcSegment();
707
                arcSeg.Size = new Size(arcLength * CloudControl._CloudArcDepth, arcLength * CloudControl._CloudArcDepth);	/// x size and y size of arc
708
                arcSeg.Point = new Point(p2.X, p2.Y);						/// end point of arc
709
                arcSeg.RotationAngle = theta;
710
                if (true == reverse) arcSeg.SweepDirection = SweepDirection.Clockwise;
711
                pathFigure.Segments.Add(arcSeg);
712

    
713
            }
714

    
715
            pathFigure.IsFilled = true;    
716
            return pathFigure;
717
        }
718

    
719
        /// <summary>
720
        /// close path if it's open
721
        /// </summary>
722
        /// <author>humkyung</author>
723
        /// <returns></returns>
724
        public int ClosePath()
725
        {
726
            if (this.PointSet.Count > 1)
727
            {
728
                double d = MathSet.DistanceTo(this.PointSet[0], this.PointSet[this.PointSet.Count - 1]);
729
                if (d > _toler)
730
                {
731
                    /// set reverse if area is greater 0 - 2012.07.04 added by humkyung
732
                    double area = MathSet.AreaOf(this.PointSet);
733
                    bool reverse = (area > 0);
734
                    /// up to here
735

    
736
                    int count = this.PointSet.Count;
737

    
738
                    if (isTransOn) // true라면 클라우드 컨트롤
739
                    {
740
                        ArcLength = ArcLength == 0 ? 10 : ArcLength;
741

    
742
                        PathFigure pathFigure = CloudControl.GenerateLineWithCloud(this.PointSet[count - 1], this.PointSet[0], this.ArcLength - 5, reverse);
743
                        
744
                        if (this.Paint == PaintSet.Fill)
745
                        {
746
                            pathFigure.IsClosed = true;
747
                        }
748

    
749
                        _pathGeometry.Figures.Add(pathFigure);                        
750
                    }
751
                    else
752
                    {
753

    
754
                        PathFigure fm = new PathFigure();
755
                        fm.StartPoint = this.PointSet[count - 1];
756
                        
757
                        //for (int i = 0; i < (count - 1); i++)
758
                        //{
759
                            _pathGeometry.Figures[_pathGeometry.Figures.Count - 1].Segments.Add(new LineSegment { Point = this.PointSet[0] });
760
                            _pathGeometry.Figures[_pathGeometry.Figures.Count - 1].Segments.Add(new LineSegment { Point = this.PointSet[1] });
761
                            //fm.Segments.Add(new LineSegment { Point = this.PointSet[0] });
762
                        //}
763
                    }                 
764
                }
765
            }
766

    
767
            return 0;
768
        }
769
        public void DrawingCloud()
770
        {
771
            AnotherSetCloud();
772
            if (!isChain)
773
            {
774
                //ClosePath();
775
            }
776
        }
777
        public void AnotherSetCloud()
778
        {
779
            this.StrokeColor = StrokeColor;
780
            this.LineSize = LineSize;
781
            this.SetCloud();
782
            //Generate();
783
            this.Width = this.Base_CloudPath.Width;
784
            this.Height = this.Base_CloudPath.Height;
785
        }
786
        public void Dispose()
787
        {
788
            GC.Collect();
789
            GC.SuppressFinalize(this);
790
        }
791
        public event PropertyChangedEventHandler PropertyChanged;
792
        protected void OnPropertyChanged(string propName)
793
        {
794
            if (PropertyChanged != null)
795
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
796
        }
797
        public void updateControl()
798
        {
799

    
800
            var lastIndex = this.PointSet.Count - 1;
801
            //this.StartPoint = this.PointSet[0];
802
            //this.EndPoint = this.PointSet[lastIndex];
803
            CenterX = MathSet.getMiddlePoint(this.PointSet[0], this.PointSet[lastIndex]).X;
804
            CenterY = MathSet.getMiddlePoint(this.PointSet[0], this.PointSet[lastIndex]).Y;
805
        }
806
        public void ChangePaint(PaintSet state)
807
        {
808
            this.Paint = state;
809
            this.SetCloud();
810
            
811
        }
812

    
813
        /// <summary>
814
        /// Serialize this
815
        /// </summary>
816
        /// <param name="sUserId"></param>
817
        /// <returns></returns>
818
        public override string Serialize()
819
        {
820
            using (S_CloudControl STemp = new S_CloudControl())
821
            {
822
                STemp.TransformPoint = "0|0";
823
                STemp.SizeSet = String.Format("{0}", this.LineSize);
824
                //STemp.StrokeColor = "#FF000FFF";
825
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
826
                STemp.Name = this.GetType().Name.ToString();
827
                STemp.Toler = this.Toler;
828
                STemp.PaintState = this.Paint;
829
                STemp.Opac = this.Opacity;
830
                STemp.UserID = this.UserID;
831
                STemp.IsTrans = this.isTransOn;
832
                STemp.IsChain = this.isChain;
833
                STemp.PointSet = new List<Point>();
834
                STemp.DashSize = this.DashSize;
835
                STemp.StartPoint = this.StartPoint;
836
                STemp.EndPoint = this.EndPoint;
837
                STemp.ArcLength = this.ArcLength;
838
                foreach (var point in this.PointSet)
839
                {
840
                    STemp.PointSet.Add(point);
841
                }
842

    
843
                //STemp.CloudFill = this.Fill;
844
                STemp.ArcLength = this.ArcLength;
845
                ///강인구 추가(2017.11.02)
846
                ///Memo 추가
847
                STemp.Memo = this.Memo;
848

    
849
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
850
            }
851
        }
852

    
853
        #region Method
854
        public void ApplyOverViewData()
855
        {
856
            this.OverViewPathData = this.PathData;
857
        }
858
        #endregion
859
    }
860

    
861
}
클립보드 이미지 추가 (최대 크기: 500 MB)