프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Polygon / PolygonControl.cs @ 6d1a8228

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

1
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using System;
4
using System.Collections.Generic;
5
using System.ComponentModel;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows;
10
using System.Windows.Controls;
11
using System.Windows.Media;
12
using System.Windows.Shapes;
13

    
14
namespace MarkupToPDF.Controls.Polygon
15
{
16
     public class PolygonControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IMarkupControlData, IPath
17
    {
18
        #region Constructure
19

    
20
        static PolygonControl()
21
        {
22
            DefaultStyleKeyProperty.OverrideMetadata(typeof(PolygonControl), new FrameworkPropertyMetadata(typeof(PolygonControl)));
23
            ResourceDictionary dictionary = new ResourceDictionary();
24
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
25
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
26
        }
27

    
28
        public PolygonControl()
29
        {
30
            this.DefaultStyleKey = typeof(PolygonControl);
31
        }
32
        
33
        #endregion
34

    
35
        #region Variable
36
        private const string PART_PolyPath = "PART_PolyPath";
37

    
38
        public Path Base_PolyPath = null;
39

    
40
        #endregion
41

    
42
        #region Internal Method
43
        public override void OnApplyTemplate()
44
        {   
45
            base.OnApplyTemplate();
46

    
47
            Base_PolyPath = GetTemplateChild(PART_PolyPath) as Path;
48

    
49
            if (Base_PolyPath == null)
50
                return;
51

    
52
            this.SetPolyPath();
53
        }
54

    
55

    
56
        #endregion
57

    
58
        #region Method
59

    
60
        public void ApplyOverViewData()
61
        {
62
            this.OverViewPathData = this.PathData;
63
        }
64

    
65
        #endregion
66

    
67
        #region Dependency Properties
68

    
69
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
70
                "UserID", typeof(string), typeof(PolygonControl), new PropertyMetadata(null));
71

    
72
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
73
              "LineSize", typeof(double), typeof(PolygonControl), new PropertyMetadata((Double)3));
74

    
75
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
76
               "StrokeColor", typeof(SolidColorBrush), typeof(PolygonControl), 
77
               new PropertyMetadata(new SolidColorBrush(Colors.Red)));
78

    
79
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
80
                "PathData", typeof(Geometry), typeof(PolygonControl), null);
81

    
82
        //강인구 추가
83
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
84
                "DashSize", typeof(DoubleCollection), typeof(PolygonControl), new PropertyMetadata(new DoubleCollection { 99999999  }, PointValueChanged));
85

    
86
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
87
                "OverViewPathData", typeof(Geometry), typeof(PolygonControl), null);
88
        //강인구 추가
89
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
90
        "Paint", typeof(PaintSet), typeof(PolygonControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
91

    
92
        public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register(
93
               "IsCompleted", typeof(bool), typeof(PolygonControl), null);
94

    
95
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
96
               "StartPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
97

    
98
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
99
               "EndPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
100

    
101
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
102
                "PointSet", typeof(List<Point>), typeof(PolygonControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
103

    
104
        /// <summary>
105
        /// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다.
106
        /// </summary>
107
        //public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register(
108
        //        "PointC", typeof(StylusPointSet), typeof(PolygonControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged));
109

    
110
        public static readonly DependencyProperty AngleProperty =
111
            DependencyProperty.Register("Angle", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback
112
                (AngleValueChanged)));
113

    
114
        public static readonly DependencyProperty CenterXProperty =
115
            DependencyProperty.Register("CenterX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged));
116

    
117
        public static readonly DependencyProperty CenterYProperty =
118
            DependencyProperty.Register("CenterY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged));
119

    
120
        public static readonly DependencyProperty IsSelectedProperty =
121
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(PolygonControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
122

    
123
        public static readonly DependencyProperty ControlTypeProperty =
124
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(PolygonControl), new FrameworkPropertyMetadata(ControlType.PolygonControl));
125

    
126
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
127
                "CanvasX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
128

    
129
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
130
                "CanvasY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
131

    
132
        #endregion
133

    
134
        #region PropertyChanged Method
135
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
136
        {
137
            var instance = (PolygonControl)sender;
138

    
139
            if (e.OldValue != e.NewValue && instance != null)
140
            {
141
                instance.SetValue(e.Property, e.NewValue);
142
                //Canvas.SetLeft(instance, instance.CanvasX);
143
                //Canvas.SetTop(instance, instance.CanvasY);
144
            }
145
        }
146

    
147
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
148
        {
149
            var instance = (PolygonControl)sender;
150

    
151
            if (e.OldValue != e.NewValue && instance != null)
152
            {
153
                instance.SetValue(e.Property, e.NewValue);
154
                //강인구 추가
155
                instance.SetPolyPath();
156
                //instance.SetPolyPath(); 주석처리
157

    
158
            }
159
        }
160
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
161
        {
162
            var instance = (PolygonControl)sender;
163

    
164
            if (e.OldValue != e.NewValue && instance != null)
165
            {
166
                instance.SetValue(e.Property, e.NewValue);
167
                instance.SetPolyPath();
168
            }
169
        }
170
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
171
        {
172
            var instance = (PolygonControl)sender;
173
            if (e.OldValue != e.NewValue && instance != null)
174
            {
175
                instance.SetValue(e.Property, e.NewValue);
176
                instance.SetPolyPath();
177
            }
178
        }
179

    
180
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
181
        {
182
            //var instance = (PolygonControl)sender;
183

    
184
            //if (e.OldValue != e.NewValue && instance.Base_PolyPath != null)
185
            //{
186
            //    instance.SetValue(e.Property, e.NewValue);
187

    
188
            //    if (instance.IsSelected)
189
            //    {
190
            //        instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Blue);
191
            //    }
192
            //    else
193
            //    {
194
            //        instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Transparent);
195
            //    }
196
            //}
197
        }
198

    
199
        #endregion
200

    
201
        #region Properties
202

    
203

    
204
        public bool IsCompleted
205
        {
206
            get { return (bool)GetValue(IsCompletedProperty); }
207
            set
208
            {
209
                SetValue(IsCompletedProperty, value);
210
                OnPropertyChanged("IsCompleted");
211
            }
212
        }
213

    
214

    
215
        public Geometry OverViewPathData
216
        {
217
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
218
            set
219
            {
220
                SetValue(OverViewPathDataProperty, value);
221
                OnPropertyChanged("OverViewPathData");
222
            }
223
        }
224

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

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

    
251
        public bool IsSelected
252
        {
253
            get
254
            {
255
                return (bool)GetValue(IsSelectedProperty);
256
            }
257
            set
258
            {
259
                SetValue(IsSelectedProperty, value);
260
                OnPropertyChanged("IsSelected");
261
            }
262
        }
263

    
264
        public PaintSet Paint
265
        {
266
            get { return (PaintSet)GetValue(PaintProperty); }
267
            set
268
            {
269
                if (this.Paint != value)
270
                {
271
                    SetValue(PaintProperty, value);
272
                    OnPropertyChanged("Paint");
273
                }
274
            }
275
        }
276

    
277
        public ControlType ControlType
278
        {
279
            set
280
            {
281
                SetValue(ControlTypeProperty, value);
282
                OnPropertyChanged("ControlType");
283
            }
284
            get
285
            {
286
                return (ControlType)GetValue(ControlTypeProperty);
287
            }
288
        }
289

    
290
        public Double LineSize
291
        {
292
            get { return (Double)GetValue(LineSizeProperty); }
293
            set
294
            {
295
                if (this.LineSize != value)
296
                {
297
                    SetValue(LineSizeProperty, value);
298
                    OnPropertyChanged("LineSize");
299
                }
300
            }
301
        }
302

    
303
        public DoubleCollection DashSize
304
        {
305
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
306
            set
307
            {
308
                if (this.DashSize != value)
309
                {
310
                    SetValue(DashSizeProperty, value);
311
                    OnPropertyChanged("DashSize");
312
                }
313
            }
314
        }
315
        public string UserID
316
        {
317
            get { return (string)GetValue(UserIDProperty); }
318
            set
319
            {
320
                if (this.UserID != value)
321
                {
322
                    SetValue(UserIDProperty, value);
323
                    OnPropertyChanged("UserID");
324
                }
325
            }
326
        }
327
        public List<Point> PointSet
328
        {
329
            get { return (List<Point>)GetValue(PointSetProperty); }
330
            set { SetValue(PointSetProperty, value);
331
            OnPropertyChanged("PointSet");
332
            }
333
        }        //public StylusPointSet PointC
334
        //{
335
        //    get { return (StylusPointSet)GetValue(StylusPointSetProperty); }
336
        //    set
337
        //    {
338
        //        SetValue(StylusPointSetProperty, value);
339
        //        OnPropertyChanged("PointC");
340
        //    }
341
        //}
342

    
343

    
344
        public double CenterX
345
        {
346
            get { return (double)GetValue(CenterXProperty); }
347
            set { SetValue(CenterXProperty, value);
348
            OnPropertyChanged("CenterX");
349
            }
350
        }
351
        public double CenterY
352
        {
353
            get
354
            {
355
                return (double)GetValue(CenterYProperty);
356
            }
357
            set
358
            {
359
                SetValue(CenterYProperty, value);
360
                OnPropertyChanged("CenterY");
361
            }
362
        }
363
        public SolidColorBrush StrokeColor
364
        {
365
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
366
            set
367
            {
368
                if (this.StrokeColor != value)
369
                {
370
                    SetValue(StrokeColorProperty, value);
371
                    OnPropertyChanged("StrokeColor");
372
                }
373
            }
374
        }
375
        public Geometry PathData
376
        {
377
            get { return (Geometry)GetValue(PathDataProperty); }
378
            set
379
            {
380
                SetValue(PathDataProperty, value);
381
                OnPropertyChanged("PathData");
382
            }
383
        }
384
     
385
        public double Angle
386
        {
387
            get { return (double)GetValue(AngleProperty); }
388
            set
389
            {
390
                if (this.Angle != value)
391
                {
392
                    SetValue(AngleProperty, value);
393
                    OnPropertyChanged("Angle");
394
                }
395
            }
396
        }
397

    
398
        public Point EndPoint
399
        {
400
            get { return (Point)GetValue(EndPointProperty); }
401
            set
402
            {
403
                SetValue(EndPointProperty, value);
404
                OnPropertyChanged("EndPoint");
405
            }
406
        }
407
        public Point StartPoint
408
        {
409
            get { return (Point)GetValue(StartPointProperty); }
410
            set
411
            {
412
                SetValue(StartPointProperty, value);
413
                OnPropertyChanged("StartPoint");
414
            }
415
        }
416
        #endregion
417

    
418
        public void updateControl()
419
        {
420
            //this.PointSet = new List<Point>();
421

    
422
            //this.PointSet.Clear();
423

    
424
            //this.PointSet.AddRange(PointC.pointSet);
425
            //this.PointSet.AddRange(PointSet);
426

    
427
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
428

    
429
            this.EndPoint = new Point(this.PointSet[this.PointSet.Count - 1].X, this.PointSet[this.PointSet.Count - 1].Y);
430

    
431
            SetPolyPath();
432
        }
433

    
434
        public void SetPolyPath()
435
        {
436
            this.ApplyTemplate();
437

    
438
            if (Base_PolyPath != null)
439
            {
440
                Base_PolyPath.StrokeDashArray.Clear();
441
                foreach (var item in this.DashSize)
442
                {
443
                    Base_PolyPath.StrokeDashArray.Add(item);
444
                }
445

    
446
                PathGeometry pathGeometry = new PathGeometry();
447
                PathFigure pathFigure = new PathFigure();
448
                PolyLineSegment instance = new PolyLineSegment();
449
                foreach (var Inneritem in PointSet)
450
                {
451
                    instance.Points.Add(Inneritem);
452
                }
453
               
454
                StartPoint = instance.Points.First();
455
                pathFigure.StartPoint = StartPoint;
456
                EndPoint = instance.Points.Last();
457
                pathFigure.Segments.Add(instance);
458
                pathGeometry.Figures.Add(pathFigure);
459

    
460
                //강인구 추가(Chain이 아닌 Polygon일때만 채우기 및 빗금 하기)
461
                if (ControlType == ControlType.PolygonControl)
462
                {
463
                    switch (this.Paint)
464
                    {
465
                        case PaintSet.None:
466
                            {
467
                                //강인구 추가
468
                                Base_PolyPath.Fill = null;
469
                            }
470
                            break;
471
                        case PaintSet.Fill:
472
                            {
473
                                Base_PolyPath.Fill = this.StrokeColor;
474
                            }
475
                            break;
476
                        case PaintSet.Hatch:
477
                            {
478
                                Base_PolyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, this.LineSize * 0.1);
479
                            }
480
                            break;
481
                        default:
482
                            break;
483
                    }
484
                }
485

    
486
                this.PathData = pathGeometry;
487
                this.OverViewPathData = PathData;
488
            }
489
        }
490

    
491
        public void ChangePaint(PaintSet state)
492
        {
493

    
494
        }
495

    
496
        //public PaintSet Paint { get; set; }
497

    
498

    
499
        #region Dispose
500
        public void Dispose()
501
        {
502
            GC.Collect();
503
            GC.SuppressFinalize(this);
504
        }
505
        #endregion
506

    
507
        #region INotifyPropertyChanged
508
        private void OnPropertyChanged(string name)
509
        {
510
            if (PropertyChanged != null)
511
            {
512
                PropertyChanged(this, new PropertyChangedEventArgs(name));
513
            }
514
        }
515

    
516
        public event PropertyChangedEventHandler PropertyChanged;
517
        #endregion
518
    }
519

    
520
    public class StylusPointSet : INotifyPropertyChanged
521
    {
522
        public StylusPointSet()
523
        {
524
            if (pointSet == null)
525
                pointSet = new List<Point>();
526
        }
527

    
528
        public List<Point> _pointSet;
529

    
530
        public List<Point> pointSet
531
        {
532
            get
533
            {
534
                return _pointSet;
535
            }
536
            set
537
            {
538
                _pointSet = value;
539
                OnPropertyChanged("pointSet");
540
            }
541
        }
542

    
543
        #region INotifyPropertyChanged
544
        private void OnPropertyChanged(string name)
545
        {
546
            if (PropertyChanged != null)
547
            {
548
                PropertyChanged(this, new PropertyChangedEventArgs(name));
549
            }
550
        }
551

    
552
        public event PropertyChangedEventHandler PropertyChanged;
553
        #endregion
554
    }
555
}
클립보드 이미지 추가 (최대 크기: 500 MB)