프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Polygon / InkControl.cs.bak @ 366f00c2

이력 | 보기 | 이력해설 | 다운로드 (19.2 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 InkControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IMarkupControlData, IPath
17
    {
18
        #region Constructure
19

    
20
        static InkControl()
21
        {
22
            DefaultStyleKeyProperty.OverrideMetadata(typeof(InkControl), new FrameworkPropertyMetadata(typeof(InkControl)));
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 InkControl()
29
        {
30
            this.DefaultStyleKey = typeof(InkControl);
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(InkControl), new PropertyMetadata(null));
71

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
124
        public static readonly DependencyProperty ControlTypeProperty =
125
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(InkControl), new FrameworkPropertyMetadata(ControlType.Ink));
126

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

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

    
133
        #endregion
134

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

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

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

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

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

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

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

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

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

    
200
        #endregion
201

    
202
        #region Properties
203

    
204

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

    
215

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

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

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

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

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

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

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

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

    
348

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

    
392
        public double Angle
393
        {
394
            get { return (double)GetValue(AngleProperty); }
395
            set
396
            {
397
                if (this.Angle != value)
398
                {
399
                    SetValue(AngleProperty, value);
400
                    OnPropertyChanged("Angle");
401
                }
402
            }
403
        }
404

    
405
        public Point EndPoint
406
        {
407
            get { return (Point)GetValue(EndPointProperty); }
408
            set
409
            {
410
                SetValue(EndPointProperty, value);
411
                OnPropertyChanged("EndPoint");
412
            }
413
        }
414
        public Point StartPoint
415
        {
416
            get { return (Point)GetValue(StartPointProperty); }
417
            set
418
            {
419
                SetValue(StartPointProperty, value);
420
                OnPropertyChanged("StartPoint");
421
            }
422
        }
423
        #endregion
424

    
425
        public void updateControl()
426
        {
427
            this.PointSet = new List<Point>();
428

    
429
            //this.PointSet.Clear();
430

    
431
            //this.PointSet.AddRange(PointC.pointSet);
432
            //this.PointSet.AddRange(PointSet);
433

    
434
            //강인구 추가(Ink Control)
435

    
436

    
437
            foreach (var item in PointC)
438
            {
439
                PointSet.AddRange(item.pointSet);
440
            }
441

    
442
            ////////////////////////////////////////
443

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

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

    
448
            //SetPolyPath();
449
        }
450

    
451
        public void SetPolyPath()
452
        {
453
            this.ApplyTemplate();
454

    
455
            if (Base_PolyPath != null)
456
            {
457
                Base_PolyPath.StrokeDashArray.Clear();
458

    
459
                if (DashSize != null)
460
                {
461
                    foreach (var item in this.DashSize)
462
                    {
463
                        Base_PolyPath.StrokeDashArray.Add(item);
464
                    }
465
                }
466

    
467
                PathGeometry pathGeometry = new PathGeometry();
468
                if (PointC != null && PointC.Count > 0)
469
                {
470
                    foreach (var item in PointC)
471
                    {
472
                        PathFigure pathFigure_ = new PathFigure();
473
                        pathFigure_.StartPoint = item.pointSet[0];
474
                        System.Diagnostics.Debug.WriteLine("SP : " + pathFigure_.StartPoint);
475
                        PolyLineSegment instance_ = new PolyLineSegment();
476
                        foreach (var Inneritem in item.pointSet)
477
                        {
478
                            instance_.Points.Add(Inneritem);
479
                        }
480
                        pathFigure_.Segments.Add(instance_);
481
                        pathGeometry.Figures.Add(pathFigure_);
482
                    }
483
                    this.PathData = pathGeometry;
484
                    return;
485
                }
486

    
487
                PathFigure pathFigure = new PathFigure();
488
                PolyLineSegment instance = new PolyLineSegment();
489

    
490

    
491
                foreach (var Inneritem in PointSet)
492
                {
493
                    instance.Points.Add(Inneritem);
494
                }
495

    
496

    
497
                StartPoint = instance.Points.First();
498
                pathFigure.StartPoint = StartPoint;
499
                EndPoint = instance.Points.Last();
500
                pathFigure.Segments.Add(instance);
501
                pathGeometry.Figures.Add(pathFigure);
502

    
503
                //강인구 추가(Chain이 아닌 Polygon일때만 채우기 및 빗금 하기)
504
                if (ControlType == ControlType.Ink)
505
                {
506
                    switch (this.Paint)
507
                    {
508
                        case PaintSet.None:
509
                            {
510
                                //강인구 추가
511
                                Base_PolyPath.Fill = null;
512
                            }
513
                            break;
514
                        case PaintSet.Fill:
515
                            {
516
                                Base_PolyPath.Fill = this.StrokeColor;
517
                            }
518
                            break;
519
                        case PaintSet.Hatch:
520
                            {
521
                                Base_PolyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, this.LineSize * 0.1);
522
                            }
523
                            break;
524
                        default:
525
                            break;
526
                    }
527
                }
528

    
529
                this.PathData = pathGeometry;
530
                this.OverViewPathData = PathData;
531
            }
532
        }
533

    
534
        public void ChangePaint(PaintSet state)
535
        {
536

    
537
        }
538

    
539
        //public PaintSet Paint { get; set; }
540

    
541

    
542
        #region Dispose
543
        public void Dispose()
544
        {
545
            GC.Collect();
546
            GC.SuppressFinalize(this);
547
        }
548
        #endregion
549

    
550
        #region INotifyPropertyChanged
551
        private void OnPropertyChanged(string name)
552
        {
553
            if (PropertyChanged != null)
554
            {
555
                PropertyChanged(this, new PropertyChangedEventArgs(name));
556
            }
557
        }
558

    
559
        public event PropertyChangedEventHandler PropertyChanged;
560
        #endregion
561
    }
562

    
563
    //public class StylusPointSet : INotifyPropertyChanged
564
    //{
565
    //    public StylusPointSet()
566
    //    {
567
    //        if (pointSet == null)
568
    //            pointSet = new List<Point>();
569
    //    }
570

    
571
    //    public List<Point> _pointSet;
572

    
573
    //    public List<Point> pointSet
574
    //    {
575
    //        get
576
    //        {
577
    //            return _pointSet;
578
    //        }
579
    //        set
580
    //        {
581
    //            _pointSet = value;
582
    //            OnPropertyChanged("pointSet");
583
    //        }
584
    //    }
585

    
586
    //    #region INotifyPropertyChanged
587
    //    private void OnPropertyChanged(string name)
588
    //    {
589
    //        if (PropertyChanged != null)
590
    //        {
591
    //            PropertyChanged(this, new PropertyChangedEventArgs(name));
592
    //        }
593
    //    }
594

    
595
    //    public event PropertyChangedEventHandler PropertyChanged;
596
    //    #endregion
597
    //}
598
}
클립보드 이미지 추가 (최대 크기: 500 MB)