프로젝트

일반

사용자정보

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

markus / MarkupToPDF_Old / Controls / Polygon / PolygonControl.cs @ 5538eb5a

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

1 787a4489 KangIngu
using MarkupToPDF.Controls.Common;
2
using System;
3
using System.Collections.Generic;
4
using System.ComponentModel;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8
using System.Windows;
9
using System.Windows.Controls;
10
using System.Windows.Media;
11
using System.Windows.Shapes;
12
13
namespace MarkupToPDF.Controls.Polygon
14
{
15
     public class PolygonControl : Control, IDisposable, INotifyPropertyChanged, IShapeControl, IMarkupControlData
16
    {
17
        #region Constructure
18
19
        static PolygonControl()
20
        {
21
            DefaultStyleKeyProperty.OverrideMetadata(typeof(PolygonControl), new FrameworkPropertyMetadata(typeof(PolygonControl)));
22
            ResourceDictionary dictionary = new ResourceDictionary();
23
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
24
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
25
        }
26
27
        public PolygonControl()
28
        {
29
            this.DefaultStyleKey = typeof(PolygonControl);
30
        }
31
        
32
        #endregion
33
34
        #region Variable
35
        private const string PART_PolyPath = "PART_PolyPath";
36
37
        public Path Base_PolyPath = null;
38
39
        #endregion
40
41
        #region Internal Method
42
        public override void OnApplyTemplate()
43
        {   
44
            base.OnApplyTemplate();
45
46
            Base_PolyPath = GetTemplateChild(PART_PolyPath) as Path;
47
48
            if (Base_PolyPath == null)
49
                return;
50
        }
51
52
53
        #endregion
54
55
        #region Method
56
57
        public void ApplyOverViewData()
58
        {
59
            this.OverViewPathData = this.PathData;
60
        }
61
62
        #endregion
63
64
        #region Dependency Properties
65
66
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
67
                "UserID", typeof(string), typeof(PolygonControl), new PropertyMetadata(null));
68
69
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
70
              "LineSize", typeof(double), typeof(PolygonControl), new PropertyMetadata((Double)3));
71
72
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
73
               "StrokeColor", typeof(SolidColorBrush), typeof(PolygonControl), 
74
               new PropertyMetadata(new SolidColorBrush(Colors.Red)));
75
76
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
77
                "PathData", typeof(Geometry), typeof(PolygonControl), null);
78
79
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
80
                "OverViewPathData", typeof(Geometry), typeof(PolygonControl), null);
81
82
        public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register(
83
               "IsCompleted", typeof(bool), typeof(PolygonControl), null);
84
85
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
86
               "StartPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
87
88
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
89
               "EndPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
90
91
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
92
                "PointSet", typeof(List<Point>), typeof(PolygonControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
93
94
        /// <summary>
95
        /// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다.
96
        /// </summary>
97
        //public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register(
98
        //        "PointC", typeof(StylusPointSet), typeof(PolygonControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged));
99
100
        public static readonly DependencyProperty AngleProperty =
101
            DependencyProperty.Register("Angle", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback
102
                (AngleValueChanged)));
103
104
        public static readonly DependencyProperty CenterXProperty =
105
            DependencyProperty.Register("CenterX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged));
106
107
        public static readonly DependencyProperty CenterYProperty =
108
            DependencyProperty.Register("CenterY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged));
109
110
        public static readonly DependencyProperty IsSelectedProperty =
111
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(PolygonControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
112
113
        public static readonly DependencyProperty ControlTypeProperty =
114
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(PolygonControl), new FrameworkPropertyMetadata(ControlType.PolygonControl));
115
116
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
117
                "CanvasX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
118
119
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
120
                "CanvasY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
121
122
        #endregion
123
124
        #region PropertyChanged Method
125
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
126
        {
127
            var instance = (PolygonControl)sender;
128
129
            if (e.OldValue != e.NewValue && instance != null)
130
            {
131
                instance.SetValue(e.Property, e.NewValue);
132
                //Canvas.SetLeft(instance, instance.CanvasX);
133
                //Canvas.SetTop(instance, instance.CanvasY);
134
            }
135
        }
136
137
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
138
        {
139
            var instance = (PolygonControl)sender;
140
141
            if (e.OldValue != e.NewValue && instance != null)
142
            {
143
                instance.SetValue(e.Property, e.NewValue);
144
                instance.SetPolyPath();
145
            }
146
        }
147
        public static void AngleValueChanged(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
                instance.SetPolyPath();
155
            }
156
        }
157
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
158
        {
159
            var instance = (PolygonControl)sender;
160
            if (e.OldValue != e.NewValue && instance != null)
161
            {
162
                instance.SetValue(e.Property, e.NewValue);
163
                instance.SetPolyPath();
164
            }
165
        }
166
167
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
168
        {
169
            var instance = (PolygonControl)sender;
170
171
            if (e.OldValue != e.NewValue && instance.Base_PolyPath != null)
172
            {
173
                instance.SetValue(e.Property, e.NewValue);
174
175
                if (instance.IsSelected)
176
                {
177
                    instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Blue);
178
                }
179
                else
180
                {
181
                    instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Transparent);
182
                }
183
            }
184
        }
185
186
        #endregion
187
188
        #region Properties
189
190
191
        public bool IsCompleted
192
        {
193
            get { return (bool)GetValue(IsCompletedProperty); }
194
            set
195
            {
196
                SetValue(IsCompletedProperty, value);
197
                OnPropertyChanged("IsCompleted");
198
            }
199
        }
200
201
202
        public Geometry OverViewPathData
203
        {
204
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
205
            set
206
            {
207
                SetValue(OverViewPathDataProperty, value);
208
                OnPropertyChanged("OverViewPathData");
209
            }
210
        }
211
212
        public double CanvasX
213
        {
214
            get { return (double)GetValue(CanvasXProperty); }
215
            set
216
            {
217
                if (this.CanvasX != value)
218
                {
219
                    SetValue(CanvasXProperty, value);
220
                    OnPropertyChanged("CanvasX");
221
                }
222
            }
223
        }
224
225
        public double CanvasY
226
        {
227
            get { return (double)GetValue(CanvasYProperty); }
228
            set
229
            {
230
                if (this.CanvasY != value)
231
                {
232
                    SetValue(CanvasYProperty, value);
233
                    OnPropertyChanged("CanvasY");
234
                }
235
            }
236
        } 
237
238
        public bool IsSelected
239
        {
240
            get
241
            {
242
                return (bool)GetValue(IsSelectedProperty);
243
            }
244
            set
245
            {
246
                SetValue(IsSelectedProperty, value);
247
                OnPropertyChanged("IsSelected");
248
            }
249
        }
250
251
        public ControlType ControlType
252
        {
253
            set
254
            {
255
                SetValue(ControlTypeProperty, value);
256
                OnPropertyChanged("ControlType");
257
            }
258
            get
259
            {
260
                return (ControlType)GetValue(ControlTypeProperty);
261
            }
262
        }
263
264
        public Double LineSize
265
        {
266
            get { return (Double)GetValue(LineSizeProperty); }
267
            set
268
            {
269
                if (this.LineSize != value)
270
                {
271
                    SetValue(LineSizeProperty, value);
272
                    OnPropertyChanged("LineSize");
273
                }
274
            }
275
        }
276
        public string UserID
277
        {
278
            get { return (string)GetValue(UserIDProperty); }
279
            set
280
            {
281
                if (this.UserID != value)
282
                {
283
                    SetValue(UserIDProperty, value);
284
                    OnPropertyChanged("UserID");
285
                }
286
            }
287
        }
288
        public List<Point> PointSet
289
        {
290
            get { return (List<Point>)GetValue(PointSetProperty); }
291
            set { SetValue(PointSetProperty, value);
292
            OnPropertyChanged("PointSet");
293
            }
294
        }        //public StylusPointSet PointC
295
        //{
296
        //    get { return (StylusPointSet)GetValue(StylusPointSetProperty); }
297
        //    set
298
        //    {
299
        //        SetValue(StylusPointSetProperty, value);
300
        //        OnPropertyChanged("PointC");
301
        //    }
302
        //}
303
304
305
        public double CenterX
306
        {
307
            get { return (double)GetValue(CenterXProperty); }
308
            set { SetValue(CenterXProperty, value);
309
            OnPropertyChanged("CenterX");
310
            }
311
        }
312
        public double CenterY
313
        {
314
            get
315
            {
316
                return (double)GetValue(CenterYProperty);
317
            }
318
            set
319
            {
320
                SetValue(CenterYProperty, value);
321
                OnPropertyChanged("CenterY");
322
            }
323
        }
324
        public SolidColorBrush StrokeColor
325
        {
326
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
327
            set
328
            {
329
                if (this.StrokeColor != value)
330
                {
331
                    SetValue(StrokeColorProperty, value);
332
                    OnPropertyChanged("StrokeColor");
333
                }
334
            }
335
        }
336
        public Geometry PathData
337
        {
338
            get { return (Geometry)GetValue(PathDataProperty); }
339
            set
340
            {
341
                SetValue(PathDataProperty, value);
342
                OnPropertyChanged("PathData");
343
            }
344
        }
345
     
346
        public double Angle
347
        {
348
            get { return (double)GetValue(AngleProperty); }
349
            set
350
            {
351
                if (this.Angle != value)
352
                {
353
                    SetValue(AngleProperty, value);
354
                    OnPropertyChanged("Angle");
355
                }
356
            }
357
        }
358
359
        public Point EndPoint
360
        {
361
            get { return (Point)GetValue(EndPointProperty); }
362
            set
363
            {
364
                SetValue(EndPointProperty, value);
365
                OnPropertyChanged("EndPoint");
366
            }
367
        }
368
        public Point StartPoint
369
        {
370
            get { return (Point)GetValue(StartPointProperty); }
371
            set
372
            {
373
                SetValue(StartPointProperty, value);
374
                OnPropertyChanged("StartPoint");
375
            }
376
        }
377
        #endregion
378
379
        public void updateControl()
380
        {
381
            this.PointSet = new List<Point>();
382
383
            this.PointSet.Clear();
384
385
            //this.PointSet.AddRange(PointC.pointSet);
386
            this.PointSet.AddRange(PointSet);
387
388
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
389
390
            this.EndPoint = new Point(this.PointSet[this.PointSet.Count - 1].X, this.PointSet[this.PointSet.Count - 1].Y);
391
392
            SetPolyPath();
393
        }
394
395
        public void SetPolyPath()
396
        {
397
            this.ApplyTemplate();
398
399
            if (Base_PolyPath != null)
400
            {
401
                PathGeometry pathGeometry = new PathGeometry();
402
                PathFigure pathFigure = new PathFigure();
403
                PolyLineSegment instance = new PolyLineSegment();
404
405
                foreach (var Inneritem in PointSet)
406
                {
407
                    instance.Points.Add(Inneritem);
408
                }
409
410
                StartPoint = instance.Points.First();
411
412
                pathFigure.StartPoint = StartPoint;
413
414
                EndPoint = instance.Points.Last();
415
416
                pathFigure.Segments.Add(instance);
417
418
                pathGeometry.Figures.Add(pathFigure);
419
420
                this.StrokeColor = new SolidColorBrush(Colors.Red);
421
                this.PathData = pathGeometry;
422
                this.OverViewPathData = PathData;
423
            }
424
        }
425
426
        public void ChangePaint(PaintSet state)
427
        {
428
429
        }
430
431
        public PaintSet Paint { get; set; }
432
433
434
        #region Dispose
435
        public void Dispose()
436
        {
437
            GC.Collect();
438
            GC.SuppressFinalize(this);
439
        }
440
        #endregion
441
442
        #region INotifyPropertyChanged
443
        private void OnPropertyChanged(string name)
444
        {
445
            if (PropertyChanged != null)
446
            {
447
                PropertyChanged(this, new PropertyChangedEventArgs(name));
448
            }
449
        }
450
451
        public event PropertyChangedEventHandler PropertyChanged;
452
        #endregion
453
    }
454
455
    public class StylusPointSet : INotifyPropertyChanged
456
    {
457
        public StylusPointSet()
458
        {
459
            if (pointSet == null)
460
                pointSet = new List<Point>();
461
        }
462
463
        public List<Point> _pointSet;
464
465
        public List<Point> pointSet
466
        {
467
            get
468
            {
469
                return _pointSet;
470
            }
471
            set
472
            {
473
                _pointSet = value;
474
                OnPropertyChanged("pointSet");
475
            }
476
        }
477
478
        #region INotifyPropertyChanged
479
        private void OnPropertyChanged(string name)
480
        {
481
            if (PropertyChanged != null)
482
            {
483
                PropertyChanged(this, new PropertyChangedEventArgs(name));
484
            }
485
        }
486
487
        public event PropertyChangedEventHandler PropertyChanged;
488
        #endregion
489
    }
490
}
클립보드 이미지 추가 (최대 크기: 500 MB)