프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / RectCloudControl.cs.bak @ 1b0edce7

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

1 787a4489 KangIngu
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
16
namespace MarkupToPDF.Controls.Shape
17
{
18
    public class RectCloudControl : CommentUserInfo, IDisposable, IPath, INotifyPropertyChanged,  IMarkupCommonData, IShapeControl, IDashControl
19
    {
20
        #region 초기 선언
21
        private const string PART_ArcPath = "PART_ArcPath";
22
        private const string PART_BodyPath = "PART_BodyPath";
23
        public event PropertyChangedEventHandler PropertyChanged;
24
25
        public Path Base_ArcPath = null;
26
        public Path Base_BodyPath = null;
27
28
        #endregion
29
30
        static RectCloudControl()
31
        {
32
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RectCloudControl), new FrameworkPropertyMetadata(typeof(RectCloudControl)));
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
39
        #region Dependency Properties
40
41
        public static readonly DependencyProperty mousemodeProperty =
42
                DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(RectangleControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
43
        public static readonly DependencyProperty IsSelectedProperty =
44
     DependencyProperty.Register("IsSelected", typeof(bool), typeof(RectCloudControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
45
46
        public static readonly DependencyProperty ControlTypeProperty =
47
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(RectCloudControl), new FrameworkPropertyMetadata(ControlType.RectCloud));
48
49
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
50
                "OverViewPathData", typeof(Geometry), typeof(RectCloudControl), new PropertyMetadata(null));
51
52
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
53
                "LineSize", typeof(double), typeof(RectCloudControl), new PropertyMetadata((Double)3));
54
55
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
56
                "UserID", typeof(string), typeof(RectCloudControl), new PropertyMetadata(null));
57
58
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
59
                 "DashSize", typeof(DoubleCollection), typeof(RectCloudControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged));
60
61
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
62
                "FillColor", typeof(SolidColorBrush), typeof(RectCloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
63
64
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
65
                "Paint", typeof(PaintSet), typeof(RectCloudControl), new PropertyMetadata(PaintSet.None));
66
67
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
68
                "StrokeColor", typeof(SolidColorBrush), typeof(RectCloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
69
70
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
71
                "PathData", typeof(Geometry), typeof(RectCloudControl), null);
72
73
        public static readonly DependencyProperty PathSubDataProperty = DependencyProperty.Register(
74
                "PathSubData", typeof(Geometry), typeof(RectCloudControl), null);
75
76
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
77
                "EndPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
78
79
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
80
                "StartPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
81
82
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
83
              "TopRightPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
84
85
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
86
                "LeftBottomPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
87
88
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
89
                "PointSet", typeof(List<Point>), typeof(RectCloudControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
90
91
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("AngleValue", typeof(double), typeof(RectCloudControl),
92
            new PropertyMetadata((double)0.0, new PropertyChangedCallback(PointValueChanged)));
93
94
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(RectCloudControl),
95
            new PropertyMetadata((double)0, PointValueChanged));
96
97
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(RectCloudControl),
98
            new PropertyMetadata((double)0, PointValueChanged));
99
100
        #endregion
101
102
        #region PropertyChanged Method
103
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
104
        {
105
            var instance = (RectCloudControl)sender;
106
            if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
107
            {
108
                instance.SetValue(e.Property, e.NewValue);
109
                instance.SetRectCloud();
110
            }
111
        }
112
        #endregion
113
114
        #region Properties
115
116
        public MouseMode mousemode
117
        {
118
            get
119
            {
120
                return (MouseMode)GetValue(mousemodeProperty);
121
            }
122
            set
123
            {
124
                SetValue(mousemodeProperty, value);
125
                OnPropertyChanged("mousemode");
126
            }
127
        }
128
        public Double LineSize
129
        {
130
            get { return (Double)GetValue(LineSizeProperty); }
131
            set
132
            {
133
                if (this.LineSize != value)
134
                {
135
                    SetValue(LineSizeProperty, value);
136
                }
137
            }
138
        }
139
        public DoubleCollection DashSize
140
        {
141
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
142
            set
143
            {
144
                if (this.DashSize != value)
145
                {
146
                    SetValue(DashSizeProperty, value);
147
                }
148
            }
149
        }
150
        public string UserID
151
        {
152
            get { return (string)GetValue(UserIDProperty); }
153
            set
154
            {
155
                if (this.UserID != value)
156
                {
157
                    SetValue(UserIDProperty, value);
158
                    OnPropertyChanged("UserID");
159
                }
160
            }
161
        }
162
        public PaintSet Paint
163
        {
164
            get { return (PaintSet)GetValue(PaintProperty); }
165
            set
166
            {
167
                if (this.Paint != value)
168
                {
169
                    SetValue(PaintProperty, value);
170
                }
171
            }
172
        }
173
        public SolidColorBrush FillColor
174
        {
175
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
176
            set
177
            {
178
                if (this.FillColor != value)
179
                {
180
                    SetValue(FillColorProperty, value);
181
                }
182
            }
183
        }
184
        public SolidColorBrush StrokeColor
185
        {
186
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
187
            set
188
            {
189
                if (this.StrokeColor != value)
190
                {
191
                    SetValue(StrokeColorProperty, value);
192
                }
193
            }
194
        }
195
196
        public Geometry OverViewPathData
197
        {
198
            get
199
            {
200
                return (Geometry)GetValue(OverViewPathDataProperty);
201
            }
202
            set
203
            {
204
                SetValue(OverViewPathDataProperty, value);
205
                OnPropertyChanged("OverViewPathData");
206
            }
207
        }
208
209
        public Geometry PathData
210
        {
211
            get { return (Geometry)GetValue(PathDataProperty); }
212
            set { SetValue(PathDataProperty, value); }
213
        }
214
        public Geometry PathSubData
215
        {
216
            get { return (Geometry)GetValue(PathSubDataProperty); }
217
            set { SetValue(PathSubDataProperty, value); }
218
        }
219
        public Point EndPoint
220
        {
221
            get { return (Point)GetValue(EndPointProperty); }
222
            set { SetValue(EndPointProperty, value); }
223
        }
224
        public Point StartPoint
225
        {
226
            get { return (Point)GetValue(StartPointProperty); }
227
            set { SetValue(StartPointProperty, value); }
228
        }
229
        public List<Point> PointSet
230
        {
231
            get { return (List<Point>)GetValue(PointSetProperty); }
232
            set { SetValue(PointSetProperty, value); }
233
        }
234
        public bool IsSelected
235
        {
236
            get
237
            {
238
                return (bool)GetValue(IsSelectedProperty);
239
            }
240
            set
241
            {
242
                SetValue(IsSelectedProperty, value);
243
            }
244
        }
245
        public ControlType ControlType
246
        {
247
            get
248
            {
249
                return (ControlType)GetValue(ControlTypeProperty);
250
            }
251
            set
252
            {
253
                SetValue(ControlTypeProperty, value);
254
            }
255
        }
256
257
258
        private double _toler = 1;
259
        public double Toler
260
        {
261
            get { return _toler; }
262
            set { _toler = value; }
263
        }
264
        private double _arcLength = 30;
265
        public double ArcLength
266
        {
267
            get { return _arcLength; }
268
            set { _arcLength = value; }
269
        }
270
271
        private bool _fill = false;
272
        public bool Fill
273
        {
274
            get { return _fill; }
275
            set { _fill = value; }
276
        }
277
        public double Angle
278
        {
279
            get { return (double)GetValue(AngleProperty); }
280
            set
281
            {
282
                if (this.Angle != value)
283
                {
284
                    SetValue(AngleProperty, value);
285
                }
286
            }
287
        }
288
        public double CenterX
289
        {
290
            get { return (double)GetValue(CenterXProperty); }
291
            set { SetValue(CenterXProperty, value); }
292
        }
293
        public double CenterY
294
        {
295
            get { return (double)GetValue(CenterYProperty); }
296
            set { SetValue(CenterYProperty, value); }
297
        }
298
        public Point LeftBottomPoint
299
        {
300
            get { return (Point)GetValue(LeftBottomPointProperty); }
301
            set
302
            {
303
                SetValue(LeftBottomPointProperty, value);
304
                OnPropertyChanged("LeftBottomPoint");
305
            }
306
        }
307
        public Point TopRightPoint
308
        {
309
            get { return (Point)GetValue(TopRightPointProperty); }
310
            set
311
            {
312
                SetValue(TopRightPointProperty, value);
313
                OnPropertyChanged("TopRightPoint");
314
            }
315
        }
316
        #endregion
317
318
        #region Data
319
        private PathGeometry _pathGeometry = new PathGeometry();
320
        #endregion
321
322
        public override void OnApplyTemplate()
323
        {
324
            base.OnApplyTemplate();
325
            Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path;
326
            Base_BodyPath = GetTemplateChild(PART_BodyPath) as Path;
327
328
            this.SetRectCloud();
329
330
        }
331
        protected void OnPropertyChanged(string propName)
332
        {
333
            if (PropertyChanged != null)
334
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
335
        }
336
        public void Dispose()
337
        {
338
            GC.Collect();
339
            GC.SuppressFinalize(this);
340
        }
341
342
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
343
        {
344
            //var instance = (RectCloudControl)sender;
345
346
            //if (e.OldValue != e.NewValue && instance.Base_BodyPath != null)
347
            //{
348
349
            //    instance.SetValue(e.Property, e.NewValue);
350
351
            //    if (instance.IsSelected)
352
            //    {
353
            //        instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Blue);
354
            //    }
355
            //    else
356
            //    {
357
            //        instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Red);
358
            //    }
359
            //}
360
        }
361
362
        public void SetRectCloud()
363
        {
364
            this.ApplyTemplate();
365
            PathFigure pathFigure = new PathFigure();
366
367
            Base_ArcPath.StrokeDashArray.Clear();
368
            Base_BodyPath.StrokeDashArray.Clear();
369
370
            foreach (var item in this.DashSize)
371
            {
372
                Base_ArcPath.StrokeDashArray.Add(item);
373
                Base_BodyPath.StrokeDashArray.Add(item);
374
            }
375
376
            switch (this.Paint)
377
            {
378
                case PaintSet.None:
379
                    pathFigure.IsFilled = false;
380
                    break;
381
                case PaintSet.Fill:
382
                    {
383
                        Base_BodyPath.Stroke = this.StrokeColor;
384
                        Base_BodyPath.StrokeThickness = 0.5;
385
                        Base_ArcPath.Stroke = this.StrokeColor;
386
387
                        Base_ArcPath.Fill = this.FillColor;
388
                        Base_BodyPath.Fill = this.FillColor;
389
                    }
390
                    //this.FillColor = this.StrokeColor;
391
                    //Base_BodyPath.Fill = this.FillColor;
392
                    //Base_ArcPath.Fill = this.FillColor;
393
                    //Base_BodyPath.Stroke = this.StrokeColor;
394
                    //Base_BodyPath.StrokeThickness = 2;
395
                    //Base_ArcPath.Stroke = this.StrokeColor;
396
                    //Base_ArcPath.StrokeThickness = 2;
397
                    //pathFigure.IsFilled = true;
398
                    break;
399
                case PaintSet.Hatch:
400
                    Base_BodyPath.Stroke = new SolidColorBrush(Colors.Transparent);
401
                    Base_BodyPath.StrokeThickness = 2;
402
                    Base_BodyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
403
                    Base_ArcPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
404
                    pathFigure.IsFilled = true;
405
                    break;
406
                default:
407
                    break;
408
            }
409
410
            #region 사각형 만들기
411
            if (this.Paint != PaintSet.None)
412
            {
413
414
415
                pathFigure.StartPoint = this.StartPoint;
416
417
                LineSegment lineSegment0 = new LineSegment();
418
                lineSegment0.Point = this.StartPoint;
419
                pathFigure.Segments.Add(lineSegment0);
420
421
                LineSegment lineSegment1 = new LineSegment();
422
                lineSegment1.Point = this.LeftBottomPoint;
423
                pathFigure.Segments.Add(lineSegment1);
424
425
                LineSegment lineSegment2 = new LineSegment();
426
                lineSegment2.Point = this.EndPoint;
427
                pathFigure.Segments.Add(lineSegment2);
428
429
                LineSegment lineSegment3 = new LineSegment();
430
                lineSegment3.Point = this.TopRightPoint;
431
                pathFigure.Segments.Add(lineSegment3);
432
433
                PathGeometry pathGeometry = new PathGeometry();
434
                pathGeometry.Figures = new PathFigureCollection();
435
                pathFigure.IsClosed = true;
436
                pathGeometry.Figures.Add(pathFigure);
437
                //this.FillColor = new SolidColorBrush(Colors.Red);
438
                this.PathSubData = pathGeometry;
439
            }
440
441
442
            #endregion
443
            #region Cloud 만들기
444
            /// set reverse if area is greater 0 - 2012.07.04 added by humkyung
445
            /// 
446
447
            double size = MathSet.DistanceTo(this.StartPoint, this.EndPoint);
448
            ArcLength = (size * 0.05);
449
            if (ArcLength <= 10)
450
            {
451
                ArcLength = 10;
452
            }
453
454
            //ArcLength = 10;
455
456
            System.Diagnostics.Debug.WriteLine(ArcLength);
457
            double area = MathSet.AreaOf(new List<Point>() { this.StartPoint, this.LeftBottomPoint, this.EndPoint, this.TopRightPoint });
458
            bool reverse = (area > 0);
459
            /// up to here
460
            this._pathGeometry = new PathGeometry();
461
            int count = this.PointSet.Count;
462
            PathFigure pathSubFigure = RectCloudControl.GenerateLineWithCloud(this.StartPoint, this.LeftBottomPoint, this.ArcLength, reverse);
463
            _pathGeometry.Figures.Add(pathSubFigure);
464
465
            pathSubFigure = RectCloudControl.GenerateLineWithCloud(this.LeftBottomPoint, this.EndPoint, this.ArcLength, reverse);
466
            _pathGeometry.Figures.Add(pathSubFigure);
467
468
            pathSubFigure = RectCloudControl.GenerateLineWithCloud(this.EndPoint, this.TopRightPoint, this.ArcLength, reverse);
469
            _pathGeometry.Figures.Add(pathSubFigure);
470
471
            pathSubFigure = RectCloudControl.GenerateLineWithCloud(this.TopRightPoint, this.StartPoint, this.ArcLength, reverse);
472
            _pathGeometry.Figures.Add(pathSubFigure);
473
474
            if (this.Paint != PaintSet.None)
475
            {
476
                foreach (var item in _pathGeometry.Figures)
477
                {
478
                    item.IsFilled = true;
479
                }
480
            }
481
482
483
            //for (int i = 0; i < (count - 1); i++)
484
            //{
485
            //    PathFigure pathSubFigure = CloudControl.GenerateLineWithCloud(this.PointSet[i], this.PointSet[i + 1], this.ArcLength, reverse);
486
            //    _pathGeometry.Figures.Add(pathSubFigure);
487
            //}
488
489
            //Base_ArcPath.StrokeThickness = 3;
490
            //Base_BodyPath.StrokeThickness = 3;
491
492
            this.PathData = _pathGeometry;
493
            ApplyOverViewData();
494
            #endregion
495
        }
496
497
        public void ChangePaint(PaintSet state)
498
        {
499
            this.Paint = state;
500
            this.SetRectCloud();
501
        }
502
503
        public void CloseSettingPoint()
504
        {
505
            this.PointSet[0] = this.StartPoint;
506
            this.PointSet[1] = this.LeftBottomPoint;
507
            this.PointSet[2] = this.EndPoint;
508
            this.PointSet[3] = this.TopRightPoint;
509
        }
510
511
        public void ApplyOverViewData()
512
        {
513
            this.OverViewPathData = this.PathData;
514
        }
515
516
        public void updateControl()
517
        {
518
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
519
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
520
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
521
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
522
        }
523
524
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double arcLength_, bool reverse)
525
        {
526
            PathFigure pathFigure = new PathFigure();
527
            pathFigure.StartPoint = p1;
528
529
            double arcLength = arcLength_;
530
            /// draw arcs which has arcLength between p1 and p2 - 2012.06.21 added by humkyung 
531
            double dx = p2.X - p1.X;
532
            double dy = p2.Y - p1.Y;
533
            double l = MathSet.DistanceTo(p1, p2); /// distance between p1 and p2
534
            double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI;
535
            Point lastPt = new Point(p1.X, p1.Y);
536
            double count = l / arcLength;
537
            /// normalize
538
            dx /= l;
539
            dy /= l;
540
            Double j = 1;
541
            for (j = 1; j < (count - 1); j++)
542
            {
543
                ArcSegment arcSeg = new ArcSegment();
544
                arcSeg.Size = new Size(arcLength * 0.8, arcLength * 0.8);						/// x size and y size of arc
545
                arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength);	/// end point of arc
546
                lastPt = arcSeg.Point;  /// save last point
547
                arcSeg.RotationAngle = theta + 90;
548
                if (true == reverse) arcSeg.SweepDirection = SweepDirection.Clockwise;
549
                pathFigure.Segments.Add(arcSeg);
550
            }
551
552
            /// draw arc between last point and end point
553
            if ((count > j) || (count > 0))
554
            {
555
                arcLength = MathSet.DistanceTo(lastPt, p2);
556
                ArcSegment arcSeg = new ArcSegment();
557
                arcSeg.Size = new Size(arcLength * 0.8, arcLength * 0.8);	/// x size and y size of arc
558
                arcSeg.Point = new Point(p2.X, p2.Y);						/// end point of arc
559
                arcSeg.RotationAngle = theta;
560
                if (true == reverse) arcSeg.SweepDirection = SweepDirection.Clockwise;
561
                pathFigure.Segments.Add(arcSeg);
562
            }
563
            pathFigure.IsClosed = false;
564
            pathFigure.IsFilled = false;
565
            /// up to here
566
            //pathFigure.IsFilled = true;
567
            return pathFigure;
568
        }
569
    }
570
}
클립보드 이미지 추가 (최대 크기: 500 MB)