프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Polygon / CloudControl.cs @ 91efe37a

이력 | 보기 | 이력해설 | 다운로드 (33.1 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
using System.Linq;
18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
110

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

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

    
117

    
118
        #endregion
119
        #region PropertyChanged Method
120

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

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

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

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

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

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

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

    
183

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

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

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

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

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

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

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

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

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

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

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

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

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

    
525
            this.ApplyTemplate();
526

    
527
            Generate();
528

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

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

    
607

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

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

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

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

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

    
664
            return 0;
665
        }
666

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

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

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

    
714
            }
715

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

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

    
737
                    int count = this.PointSet.Count;
738

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

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

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

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

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

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

    
814
        /// <summary>
815
        /// return Cloud's area
816
        /// </summary>
817
        /// <author>humkyung</author>
818
        /// <date>2019.06.13</date>
819
        public override Rect ItemRect
820
        {
821
            get
822
            {
823
                double dMinX = double.MaxValue;
824
                double dMinY = double.MaxValue;
825
                double dMaxX = double.MinValue;
826
                double dMaxY = double.MinValue;
827
                foreach (Point pt in this.PointSet)
828
                {
829
                    dMinX = Math.Min(dMinX, pt.X);
830
                    dMinY = Math.Min(dMinY, pt.Y);
831
                    dMaxX = Math.Max(dMaxX, pt.X);
832
                    dMaxY = Math.Max(dMaxY, pt.Y);
833
                }
834

    
835
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
836
            }
837
        }
838

    
839
        /// <summary>
840
        /// Serialize this
841
        /// </summary>
842
        /// <param name="sUserId"></param>
843
        /// <returns></returns>
844
        public override string Serialize()
845
        {
846
            using (S_CloudControl STemp = new S_CloudControl())
847
            {
848
                STemp.TransformPoint = "0|0";
849
                STemp.SizeSet = String.Format("{0}", this.LineSize);
850
                //STemp.StrokeColor = "#FF000FFF";
851
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
852
                STemp.Name = this.GetType().Name.ToString();
853
                STemp.Toler = this.Toler;
854
                STemp.PaintState = this.Paint;
855
                STemp.Opac = this.Opacity;
856
                STemp.UserID = this.UserID;
857
                STemp.IsTrans = this.isTransOn;
858
                STemp.IsChain = this.isChain;
859
                STemp.PointSet = new List<Point>();
860
                STemp.DashSize = this.DashSize;
861
                STemp.StartPoint = this.StartPoint;
862
                STemp.EndPoint = this.EndPoint;
863
                STemp.ArcLength = this.ArcLength;
864
                foreach (var point in this.PointSet)
865
                {
866
                    STemp.PointSet.Add(point);
867
                }
868

    
869
                //STemp.CloudFill = this.Fill;
870
                STemp.ArcLength = this.ArcLength;
871
                ///강인구 추가(2017.11.02)
872
                ///Memo 추가
873
                STemp.Memo = this.Memo;
874

    
875
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
876
            }
877
        }
878

    
879
        /// <summary>
880
        /// create a cloudcontrol from given string
881
        /// </summary>
882
        /// <param name="str"></param>
883
        /// <returns></returns>
884
        public static CloudControl FromString(string str, SolidColorBrush brush, string sProjectNo)
885
        {
886
            CloudControl instance = null;
887
            using (S_CloudControl s = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(str))
888
            {
889
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
890
                instance = new CloudControl
891
                {
892
                    LineSize = Convert.ToDouble(data2.First()),
893
                    Toler = s.Toler,
894
                    PointSet = s.PointSet,
895
                    ArcLength = s.ArcLength,
896
                    Paint = s.PaintState,
897
                    Opacity = s.Opac,
898
                    StrokeColor = brush,
899
                    isTransOn = s.IsTrans,
900
                    isChain = s.IsChain,
901
                    DashSize = s.DashSize,
902
                    UserID = s.UserID,
903

    
904
                    StartPoint = s.StartPoint,
905
                    EndPoint = s.EndPoint,
906
                    Memo = s.Memo
907

    
908
                    //Fill = s.CloudFill,
909
                };
910
            }
911

    
912
            return instance;
913
        }
914

    
915
        #region Method
916
        public void ApplyOverViewData()
917
        {
918
            this.OverViewPathData = this.PathData;
919
        }
920
        #endregion
921
    }
922

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