프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / TriControl.cs @ 6d1a8228

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

1
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
        //강인구 추가
51
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
52
              "DashSize", typeof(DoubleCollection), typeof(TriControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
53
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
54
        "PathData", typeof(Geometry), typeof(TriControl), null);
55
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
56
         "StrokeColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
57
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
58
         "FillColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
59
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
60
            "EndPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
61
        public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register(
62
            "MidPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
63
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
64
            "StartPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
65
        //강인구 추가
66
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
67
                "Paint", typeof(PaintSet), typeof(TriControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
68

    
69
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
70
            "PointSet", typeof(List<Point>), typeof(TriControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
71
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(TriControl), new
72
            PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
73
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(TriControl),
74
            new PropertyMetadata((double)0, OnCenterXYChanged));
75

    
76
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(TriControl),
77
            new PropertyMetadata((double)0, OnCenterXYChanged));
78

    
79
        #endregion
80
        #region PropertyChanged Method
81

    
82
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
83
        {
84
            //var instance = (TriControl)sender;
85

    
86
            //if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
87
            //{
88

    
89
            //    instance.SetValue(e.Property, e.NewValue);
90

    
91
            //    if (instance.IsSelected)
92
            //    {
93
            //        instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
94
            //    }
95
            //    else
96
            //    {
97
            //        instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
98
            //    }
99
            //}
100
        }
101

    
102
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
103
        {
104
            var instance = (TriControl)sender;
105

    
106
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
107
            {
108
                instance.SetValue(e.Property, e.NewValue);
109
                instance.SetTri();
110
            }
111
        }
112

    
113

    
114
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
115
        {
116
            var instance = (TriControl)sender;
117
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
118
            {
119
                instance.SetValue(e.Property, e.NewValue);
120
                instance.SetTri();
121
            }
122
        }
123
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
124
        {
125
            var instance = (TriControl)sender;
126
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
127
            {
128
                instance.SetValue(e.Property, e.NewValue);
129
                instance.SetTri();
130
            }
131
        }
132
        #endregion
133
        #region Properties
134

    
135
        public Double LineSize
136
        {
137
            get { return (Double)GetValue(LineSizeProperty); }
138
            set
139
            {
140
                if (this.LineSize != value)
141
                {
142
                    SetValue(LineSizeProperty, value);
143
                }
144
            }
145
        }
146
        public string UserID
147
        {
148
            get { return (string)GetValue(UserIDProperty); }
149
            set
150
            {
151
                if (this.UserID != value)
152
                {
153
                    SetValue(UserIDProperty, value);
154
                    OnPropertyChanged("UserID");
155
                }
156
            }
157
        }
158
        public SolidColorBrush FillColor
159
        {
160
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
161
            set
162
            {
163
                if (this.FillColor != value)
164
                {
165
                    SetValue(FillColorProperty, value);
166
                }
167
            }
168
        }
169
        public DoubleCollection DashSize
170
        {
171
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
172
            set
173
            {
174
                if (this.DashSize != value)
175
                {
176
                    SetValue(DashSizeProperty, value);
177
                }
178
            }
179
        }
180
        public PaintSet Paint
181
        {
182
            get { return (PaintSet)GetValue(PaintProperty); }
183
            set
184
            {
185
                if (this.Paint != value)
186
                {
187
                    SetValue(PaintProperty, value);
188
                }
189
            }
190
        }
191

    
192

    
193
        public SolidColorBrush StrokeColor
194
        {
195
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
196
            set
197
            {
198
                if (this.StrokeColor != value)
199
                {
200
                    SetValue(StrokeColorProperty, value);
201
                }
202
            }
203
        }
204
        public Geometry OverViewPathData
205
        {
206
            get
207
            {
208
                return (Geometry)GetValue(OverViewPathDataProperty);
209
            }
210
            set
211
            {
212
                SetValue(OverViewPathDataProperty, value);
213
                OnPropertyChanged("OverViewPathData");
214
            }
215
        }
216
        public Geometry PathData
217
        {
218
            get { return (Geometry)GetValue(PathDataProperty); }
219
            set { SetValue(PathDataProperty, value); }
220
        }
221
        public Point EndPoint
222
        {
223
            get { return (Point)GetValue(EndPointProperty); }
224
            set { SetValue(EndPointProperty, value); }
225
        }
226
        public Point StartPoint
227
        {
228
            get { return (Point)GetValue(StartPointProperty); }
229
            set { SetValue(StartPointProperty, value); }
230
        }
231
        public Point MidPoint
232
        {
233
            get { return (Point)GetValue(MidPointProperty); }
234
            set { SetValue(MidPointProperty, value); }
235
        }
236
        public List<Point> PointSet
237
        {
238
            get { return (List<Point>)GetValue(PointSetProperty); }
239
            set { SetValue(PointSetProperty, value); }
240
        }
241

    
242
        public bool IsSelected
243
        {
244
            get
245
            {
246
                return (bool)GetValue(IsSelectedProperty);
247
            }
248
            set
249
            {
250
                SetValue(IsSelectedProperty, value);
251
            }
252
        }
253

    
254
        public ControlType ControlType
255
        {
256
            get
257
            {
258
                return (ControlType)GetValue(ControlTypeProperty);
259
            }
260
            set
261
            {
262
                SetValue(ControlTypeProperty, value);
263
            }
264
        }
265

    
266

    
267
        public double Angle
268
        {
269
            get { return (double)GetValue(AngleProperty); }
270
            set
271
            {
272
                if (this.Angle != value)
273
                {
274
                    SetValue(AngleProperty, value);
275
                }
276
            }
277
        }
278
        public double CenterX
279
        {
280
            get { return (double)GetValue(CenterXProperty); }
281
            set { SetValue(CenterXProperty, value); }
282
        }
283
        public double CenterY
284
        {
285
            get { return (double)GetValue(CenterYProperty); }
286
            set { SetValue(CenterYProperty, value); }
287
        }
288
        #endregion
289

    
290
        #region Dependency PropertyChanged
291
        //public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
292
        //{
293
        //    var instance = (TriControl)sender;
294

    
295
        //    if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
296
        //    {
297

    
298
        //        instance.SetValue(e.Property, e.NewValue);
299

    
300
        //        if (instance.IsSelected)
301
        //        {
302
        //            instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
303
        //        }
304
        //        else
305
        //        {
306
        //            instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
307
        //        }
308
        //    }
309
        //}
310

    
311
        #endregion Dependency PropertyChanged
312

    
313
        public override void OnApplyTemplate()
314
        {
315
            base.OnApplyTemplate();
316
            Base_TriPath = GetTemplateChild(PART_TriPath) as Path;
317

    
318
            if (Base_TriPath == null)
319
            {
320
                return;
321
            }
322

    
323
            this.SetTri();
324
        }
325

    
326
        public void SetTri()
327
        {
328
            this.ApplyTemplate();
329
            Base_TriPath.StrokeDashArray.Clear();
330
            foreach (var item in this.DashSize)
331
            {
332
                Base_TriPath.StrokeDashArray.Add(item);
333
            }
334
            Base_TriPath.StrokeDashCap = PenLineCap.Square;
335
            PathFigure pathFigure = new PathFigure();
336

    
337
            //this.FillColor = this.StrokeColor;
338
            ////Base_TriPath.Fill = this.FillColor;
339
            //Base_TriPath.Fill = Brushes.Red;
340
            //pathFigure.IsFilled = true;
341

    
342
            switch (this.Paint)
343
            {
344
                case PaintSet.None:
345
                    this.FillColor = null;
346
                    pathFigure.IsFilled = false;
347
                    break;
348
                case PaintSet.Fill:
349
                    this.FillColor = this.StrokeColor;
350
                    Base_TriPath.Fill = this.FillColor;
351
                    pathFigure.IsFilled = true;
352
                    break;
353
                case PaintSet.Hatch:
354
                    Base_TriPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
355
                    pathFigure.IsFilled = true;
356
                    break;
357
                default:
358
                    break;
359
            }
360
            pathFigure.StartPoint = this.StartPoint;
361

    
362
            List<Point> points = new List<Point>() { this.StartPoint };
363
            if (MidPoint.X != 0 && MidPoint.Y != 0) points.Add(this.MidPoint);
364
            points.Add(this.EndPoint);
365

    
366
            PolyLineSegment polyline = new PolyLineSegment(points , true);
367
            pathFigure.Segments.Add(polyline);
368

    
369
            PathGeometry pathGeometry = new PathGeometry();
370
            pathGeometry.Figures = new PathFigureCollection();
371
            pathFigure.IsClosed = true;
372
            pathGeometry.Figures.Add(pathFigure);
373

    
374
            this.PathData = pathGeometry;
375
            ApplyOverViewData();
376

    
377
        }
378
        public void Dispose()
379
        {
380
            GC.Collect();
381
            GC.SuppressFinalize(this);
382
        }
383
        public event PropertyChangedEventHandler PropertyChanged;
384
        protected void OnPropertyChanged(string propName)
385
        {
386
            if (PropertyChanged != null)
387
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
388
        }
389

    
390
        public void ApplyOverViewData()
391
        {
392
            this.OverViewPathData = this.PathData;
393
        }
394

    
395
        public void updateControl()
396
        {
397
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
398
            this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
399
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
400
        }
401

    
402
        //public void ChangePaint(PaintSet state)
403
        //{
404
        //    this.Paint = state;
405
        //    this.SetTri();
406
        //}
407
    }
408
}
클립보드 이미지 추가 (최대 크기: 500 MB)