프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / TriControl.cs.bak @ 366f00c2

이력 | 보기 | 이력해설 | 다운로드 (15.1 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
    //[TemplatePart(Name = "PART_TriPath", Type = typeof(Path))]
19
    public class TriControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IMarkupCommonData, IShapeControl, IDashControl
20
    {
21
        public Path Base_TriPath { get; set; }
22
        //public enum PaintSet { None, Fill, Hatch };
23
        private const string PART_TriPath = "PART_TriPath";
24
25
        //public Path Base_TriPath = null;
26
27
        static TriControl()
28
        {
29
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TriControl), new FrameworkPropertyMetadata(typeof(TriControl)));
30
            ResourceDictionary dictionary = new ResourceDictionary();
31
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
32
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
33
        }
34
35
        #region Dependency Properties
36
37
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
38
        "OverViewPathData", typeof(Geometry), typeof(TriControl), new PropertyMetadata(null));
39
40
        public static readonly DependencyProperty IsSelectedProperty =
41
      DependencyProperty.Register("IsSelected", typeof(bool), typeof(TriControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
42
43
        public static readonly DependencyProperty ControlTypeProperty =
44
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TriControl), new FrameworkPropertyMetadata(ControlType.Triangle));
45
46
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
47
         "LineSize", typeof(double), typeof(TriControl), new PropertyMetadata((Double)3));
48
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
49
                "UserID", typeof(string), typeof(TriControl), new PropertyMetadata(null));
50
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
51
              "DashSize", typeof(DoubleCollection), typeof(TriControl), new PropertyMetadata(new DoubleCollection { 1, 1 }));
52
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
53
        "PathData", typeof(Geometry), typeof(TriControl), null);
54
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
55
         "StrokeColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
56
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
57
         "FillColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
58
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
59
            "EndPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
60
        public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register(
61
            "MidPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
62
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
63
            "StartPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
64
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
65
                "Paint", typeof(PaintSet), typeof(TriControl), new PropertyMetadata(PaintSet.None));
66
67
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
68
            "PointSet", typeof(List<Point>), typeof(TriControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
69
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(TriControl), new
70
            PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
71
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(TriControl),
72
            new PropertyMetadata((double)0, OnCenterXYChanged));
73
74
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(TriControl),
75
            new PropertyMetadata((double)0, OnCenterXYChanged));
76
77
        #endregion
78
        #region PropertyChanged Method
79
80
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
81
        {
82
            //var instance = (TriControl)sender;
83
84
            //if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
85
            //{
86
87
            //    instance.SetValue(e.Property, e.NewValue);
88
89
            //    if (instance.IsSelected)
90
            //    {
91
            //        instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
92
            //    }
93
            //    else
94
            //    {
95
            //        instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
96
            //    }
97
            //}
98
        }
99
100
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
101
        {
102
            var instance = (TriControl)sender;
103
104
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
105
            {
106
                instance.SetValue(e.Property, e.NewValue);
107
                instance.SetTri();
108
            }
109
        }
110
111
112
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
113
        {
114
            var instance = (TriControl)sender;
115
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
116
            {
117
                instance.SetValue(e.Property, e.NewValue);
118
                instance.SetTri();
119
            }
120
        }
121
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
122
        {
123
            var instance = (TriControl)sender;
124
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
125
            {
126
                instance.SetValue(e.Property, e.NewValue);
127
                instance.SetTri();
128
            }
129
        }
130
        #endregion
131
        #region Properties
132
133
        public Double LineSize
134
        {
135
            get { return (Double)GetValue(LineSizeProperty); }
136
            set
137
            {
138
                if (this.LineSize != value)
139
                {
140
                    SetValue(LineSizeProperty, value);
141
                }
142
            }
143
        }
144
        public string UserID
145
        {
146
            get { return (string)GetValue(UserIDProperty); }
147
            set
148
            {
149
                if (this.UserID != value)
150
                {
151
                    SetValue(UserIDProperty, value);
152
                    OnPropertyChanged("UserID");
153
                }
154
            }
155
        }
156
        public SolidColorBrush FillColor
157
        {
158
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
159
            set
160
            {
161
                if (this.FillColor != value)
162
                {
163
                    SetValue(FillColorProperty, value);
164
                }
165
            }
166
        }
167
        public DoubleCollection DashSize
168
        {
169
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
170
            set
171
            {
172
                if (this.DashSize != value)
173
                {
174
                    SetValue(DashSizeProperty, value);
175
                }
176
            }
177
        }
178
        public PaintSet Paint
179
        {
180
            get { return (PaintSet)GetValue(PaintProperty); }
181
            set
182
            {
183
                if (this.Paint != value)
184
                {
185
                    SetValue(PaintProperty, value);
186
                }
187
            }
188
        }
189
190
191
        public SolidColorBrush StrokeColor
192
        {
193
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
194
            set
195
            {
196
                if (this.StrokeColor != value)
197
                {
198
                    SetValue(StrokeColorProperty, value);
199
                }
200
            }
201
        }
202
        public Geometry OverViewPathData
203
        {
204
            get
205
            {
206
                return (Geometry)GetValue(OverViewPathDataProperty);
207
            }
208
            set
209
            {
210
                SetValue(OverViewPathDataProperty, value);
211
                OnPropertyChanged("OverViewPathData");
212
            }
213
        }
214
        public Geometry PathData
215
        {
216
            get { return (Geometry)GetValue(PathDataProperty); }
217
            set { SetValue(PathDataProperty, 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 Point MidPoint
230
        {
231
            get { return (Point)GetValue(MidPointProperty); }
232
            set { SetValue(MidPointProperty, value); }
233
        }
234
        public List<Point> PointSet
235
        {
236
            get { return (List<Point>)GetValue(PointSetProperty); }
237
            set { SetValue(PointSetProperty, value); }
238
        }
239
240
        public bool IsSelected
241
        {
242
            get
243
            {
244
                return (bool)GetValue(IsSelectedProperty);
245
            }
246
            set
247
            {
248
                SetValue(IsSelectedProperty, value);
249
            }
250
        }
251
252
        public ControlType ControlType
253
        {
254
            get
255
            {
256
                return (ControlType)GetValue(ControlTypeProperty);
257
            }
258
            set
259
            {
260
                SetValue(ControlTypeProperty, value);
261
            }
262
        }
263
264
265
        public double Angle
266
        {
267
            get { return (double)GetValue(AngleProperty); }
268
            set
269
            {
270
                if (this.Angle != value)
271
                {
272
                    SetValue(AngleProperty, value);
273
                }
274
            }
275
        }
276
        public double CenterX
277
        {
278
            get { return (double)GetValue(CenterXProperty); }
279
            set { SetValue(CenterXProperty, value); }
280
        }
281
        public double CenterY
282
        {
283
            get { return (double)GetValue(CenterYProperty); }
284
            set { SetValue(CenterYProperty, value); }
285
        }
286
        #endregion
287
288
        #region Dependency PropertyChanged
289
        //public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
290
        //{
291
        //    var instance = (TriControl)sender;
292
293
        //    if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
294
        //    {
295
296
        //        instance.SetValue(e.Property, e.NewValue);
297
298
        //        if (instance.IsSelected)
299
        //        {
300
        //            instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
301
        //        }
302
        //        else
303
        //        {
304
        //            instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
305
        //        }
306
        //    }
307
        //}
308
309
        #endregion Dependency PropertyChanged
310
311
        public override void OnApplyTemplate()
312
        {
313
            base.OnApplyTemplate();
314
            Base_TriPath = GetTemplateChild(PART_TriPath) as Path;
315
316
            if (Base_TriPath == null)
317
            {
318
                return;
319
            }
320
321
            this.SetTri();
322
        }
323
        public void SetTri()
324
        {
325
            this.ApplyTemplate();
326
            Base_TriPath.StrokeDashArray.Clear();
327
            foreach (var item in this.DashSize)
328
            {
329
                Base_TriPath.StrokeDashArray.Add(item);
330
            }
331
            Base_TriPath.StrokeDashCap = PenLineCap.Square;
332
            PathFigure pathFigure = new PathFigure();
333
334
            //this.FillColor = this.StrokeColor;
335
            ////Base_TriPath.Fill = this.FillColor;
336
            //Base_TriPath.Fill = Brushes.Red;
337
            //pathFigure.IsFilled = true;
338
339
            switch (this.Paint)
340
            {
341
                case PaintSet.None:
342
                    this.FillColor = null;
343
                    pathFigure.IsFilled = false;
344
                    break;
345
                case PaintSet.Fill:
346
                    this.FillColor = this.StrokeColor;
347
                    Base_TriPath.Fill = this.FillColor;
348
                    pathFigure.IsFilled = true;
349
                    break;
350
                case PaintSet.Hatch:
351
                    Base_TriPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
352
                    pathFigure.IsFilled = true;
353
                    break;
354
                default:
355
                    break;
356
            }
357
            pathFigure.StartPoint = this.StartPoint;
358
359
            LineSegment lineSegment0 = new LineSegment();
360
            lineSegment0.Point = this.StartPoint;
361
            pathFigure.Segments.Add(lineSegment0);
362
363
            LineSegment lineSegment1 = new LineSegment();
364
365
            if (MidPoint.X != 0 && MidPoint.Y != 0)
366
            {
367
                lineSegment1.Point = this.MidPoint;
368
                pathFigure.Segments.Add(lineSegment1);
369
            }
370
            else
371
            {
372
                lineSegment1.Point = this.EndPoint;
373
                pathFigure.Segments.Add(lineSegment1);
374
            }
375
376
            LineSegment lineSegment2 = new LineSegment();
377
            lineSegment2.Point = this.EndPoint;
378
            pathFigure.Segments.Add(lineSegment2);
379
380
381
382
            PathGeometry pathGeometry = new PathGeometry();
383
            pathGeometry.Figures = new PathFigureCollection();
384
            pathFigure.IsClosed = true;
385
            pathGeometry.Figures.Add(pathFigure);
386
            //this.FillColor = new SolidColorBrush(Colors.Red);
387
            //Base_TriPath.StrokeThickness = 3;
388
            //FillColor = Brushes.Red;
389
390
            this.PathData = pathGeometry;
391
            ApplyOverViewData();
392
393
        }
394
        public void Dispose()
395
        {
396
            GC.Collect();
397
            GC.SuppressFinalize(this);
398
        }
399
        public event PropertyChangedEventHandler PropertyChanged;
400
        protected void OnPropertyChanged(string propName)
401
        {
402
            if (PropertyChanged != null)
403
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
404
        }
405
406
        public void ApplyOverViewData()
407
        {
408
            this.OverViewPathData = this.PathData;
409
        }
410
411
        public void updateControl()
412
        {
413
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
414
            this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
415
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
416
        }
417
418
        //public void ChangePaint(PaintSet state)
419
        //{
420
        //    this.Paint = state;
421
        //    this.SetTri();
422
        //}
423
    }
424
}
클립보드 이미지 추가 (최대 크기: 500 MB)