프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / CircleControl.cs.bak @ 959b3ef2

이력 | 보기 | 이력해설 | 다운로드 (16.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.Windows;
7
using System.Windows.Media;
8
using System.Windows.Shapes;
9

    
10
namespace MarkupToPDF.Controls.Shape
11
{
12
    [TemplatePart(Name = "PART_CirclePath", Type = typeof(Path))]
13
    public class CircleControl : CommentUserInfo, IDisposable, IPath, INotifyPropertyChanged, IMarkupCommonData, IShapeControl, ICircleControl
14
    {
15
        private const string PART_CirclePath = "PART_CirclePath";
16
        public Path Base_CirclePath = null;
17

    
18
        static CircleControl()
19
        {
20
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CircleControl), new FrameworkPropertyMetadata(typeof(CircleControl)));
21
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
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
        #region Dependency Properties
28

    
29
        public static readonly DependencyProperty IsSelectedProperty =
30
      DependencyProperty.Register("IsSelected", typeof(bool), typeof(CircleControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
31

    
32
        public static readonly DependencyProperty ControlTypeProperty =
33
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(CircleControl), new FrameworkPropertyMetadata(ControlType.Circle));
34

    
35

    
36

    
37

    
38
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
39
                "OverViewPathData", typeof(Geometry), typeof(CircleControl), new PropertyMetadata(null));
40

    
41
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
42
                "LineSize", typeof(double), typeof(CircleControl), new PropertyMetadata((Double)3));
43
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
44
                "UserID", typeof(string), typeof(CircleControl), new PropertyMetadata(null));
45
				
46
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
47
                "FillColor", typeof(SolidColorBrush), typeof(CircleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
48

    
49
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
50
                "StrokeColor", typeof(SolidColorBrush), typeof(CircleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
51

    
52
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
53
                "PathData", typeof(Geometry), typeof(CircleControl), null);
54
        //강인구 추가
55
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
56
                "Paint", typeof(PaintSet), typeof(CircleControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
57

    
58
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
59
                "EndPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
60

    
61
        //강인구 추가
62
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
63
                "DashSize", typeof(DoubleCollection), typeof(CircleControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
64

    
65
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
66
              "TopRightPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
67

    
68
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
69
                 "LeftBottomPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
70

    
71
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
72
                "StartPoint", typeof(Point), typeof(CircleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
73
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
74
                 "PointSet", typeof(List<Point>), typeof(CircleControl), new PropertyMetadata(new List<Point>()));
75
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(CircleControl),
76
            new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
77
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(CircleControl),
78
            new PropertyMetadata((double)0, OnCenterXYChanged));
79
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(CircleControl),
80
            new PropertyMetadata((double)0, OnCenterXYChanged));
81
        public static readonly DependencyProperty mousemodeProperty =
82
                        DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(CircleControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
83
        #endregion
84
        #region PropertyChanged Method
85

    
86
         public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
87
        {
88
            //var instance = (CircleControl)sender;
89

    
90
            //if (e.OldValue != e.NewValue && instance.Base_CirclePath != null)
91
            //{
92

    
93
            //    instance.SetValue(e.Property, e.NewValue);
94

    
95
            //    if (instance.IsSelected)
96
            //    {
97
            //        instance.Base_CirclePath.Stroke = new SolidColorBrush(Colors.Blue);
98
            //    }
99
            //    else
100
            //    {
101
            //        instance.Base_CirclePath.Stroke = new SolidColorBrush(Colors.Red);
102
            //    }
103
            //}
104
        }
105

    
106
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
107
        {
108
            var instance = (CircleControl)sender;
109
            if (e.OldValue != e.NewValue && instance.Base_CirclePath != null)
110
            {
111
                instance.SetValue(e.Property, e.NewValue);
112
                instance.SetCircle();
113
            }
114
        }
115

    
116
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
117
        {
118
            var instance = (CircleControl)sender;
119
            if (e.OldValue != e.NewValue && instance.Base_CirclePath != null)
120
            {
121
                instance.SetValue(e.Property, e.NewValue);
122
                instance.SetCircle();
123
            }
124
        }
125

    
126

    
127
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
128
        {
129
            var instance = (CircleControl)sender;
130
            if (e.OldValue != e.NewValue && instance.Base_CirclePath != null)
131
            {
132
                instance.SetValue(e.Property, e.NewValue);
133
                instance.SetCircle();
134
            }
135
        }
136
        #endregion
137
        #region Properties
138
        public string UserID
139
        {
140
            get { return (string)GetValue(UserIDProperty); }
141
            set
142
            {
143
                if (this.UserID != value)
144
                {
145
                    SetValue(UserIDProperty, value);
146
                    OnPropertyChanged("UserID");
147
                }
148
            }
149
        }
150
        public MouseMode mousemode
151
        {
152
            get
153
            {
154
                return (MouseMode)GetValue(mousemodeProperty);
155
            }
156
            set
157
            {
158
                SetValue(mousemodeProperty, value);
159
                OnPropertyChanged("mousemode");
160
            }
161
        }
162

    
163
        public Double LineSize
164
        {
165
            get { return (Double)GetValue(LineSizeProperty); }
166
            set
167
            {
168
                if (this.LineSize != value)
169
                {
170
                    SetValue(LineSizeProperty, value);
171
                }
172
            }
173
        }
174
        public DoubleCollection DashSize
175
        {
176
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
177
            set
178
            {
179
                if (this.DashSize != value)
180
                {
181
                    SetValue(DashSizeProperty, value);
182
                }
183
            }
184
        }
185
        public SolidColorBrush FillColor
186
        {
187
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
188
            set
189
            {
190
                if (this.FillColor != value)
191
                {
192
                    SetValue(FillColorProperty, value);
193
                }
194
            }
195
        }
196
        public Point TopRightPoint
197
        {
198
            get { return (Point)GetValue(TopRightPointProperty); }
199
            set
200
            {
201
                SetValue(TopRightPointProperty, value);
202
                OnPropertyChanged("TopRightPoint");
203
            }
204
        }
205
        public Point LeftBottomPoint
206
        {
207
            get { return (Point)GetValue(LeftBottomPointProperty); }
208
            set
209
            {
210
                SetValue(LeftBottomPointProperty, value);
211
                OnPropertyChanged("LeftBottomPoint");
212
            }
213
        }
214
        public SolidColorBrush StrokeColor
215
        {
216
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
217
            set
218
            {
219
                if (this.StrokeColor != value)
220
                {
221
                    SetValue(StrokeColorProperty, value);
222
                }
223
            }
224
        }
225
        public Geometry PathData
226
        {
227
            get { return (Geometry)GetValue(PathDataProperty); }
228
            set { SetValue(PathDataProperty, value); }
229
        }
230

    
231
        public Geometry OverViewPathData
232
        {
233
            get
234
            {
235
                return (Geometry)GetValue(OverViewPathDataProperty);
236
            }
237
            set
238
            {
239
                SetValue(OverViewPathDataProperty, value);
240
                OnPropertyChanged("OverViewPathData");
241
            }
242
        }
243
        public PaintSet Paint
244
        {
245
            get { return (PaintSet)GetValue(PaintProperty); }
246
            set
247
            {
248
                if (this.Paint != value)
249
                {
250
                    SetValue(PaintProperty, value);
251
                }
252
            }
253
        }
254
        public Point EndPoint
255
        {
256
            get { return (Point)GetValue(EndPointProperty); }
257
            set { SetValue(EndPointProperty, value); }
258
        }
259
        public Point StartPoint
260
        {
261
            get { return (Point)GetValue(StartPointProperty); }
262
            set { SetValue(StartPointProperty, value); }
263
        }
264
        //public double CenterX
265
        //{
266
        //    get { return (double)GetValue(CenterXProperty); }
267
        //    set { SetValue(CenterXProperty, value); }
268
        //}
269
        //public double CenterY
270
        //{
271
        //    get { return (double)GetValue(CenterYProperty); }
272
        //    set { SetValue(CenterYProperty, value); }
273
        //}
274
        public double AngleValue
275
        {
276
            get { return (double)GetValue(AngleProperty); }
277
            set { SetValue(AngleProperty, value); }
278
        }
279
        public double Angle
280
        {
281
            get { return (double)GetValue(AngleProperty); }
282
            set
283
            {
284
                if (this.Angle != value)
285
                {
286
                    SetValue(AngleProperty, value);
287
                }
288
            }
289
        }
290
        public List<Point> PointSet
291
        {
292
            get { return (List<Point>)GetValue(PointSetProperty); }
293
            set { SetValue(PointSetProperty, value); }
294
        }
295

    
296
        public bool IsSelected
297
        {
298
            get
299
            {
300
                return (bool)GetValue(IsSelectedProperty);
301
            }
302
            set
303
            {
304
                SetValue(IsSelectedProperty, value);
305
            }
306
        }
307

    
308
        public ControlType ControlType
309
        {
310
            get
311
            {
312
                return (ControlType)GetValue(ControlTypeProperty);
313
            }
314
            set
315
            {
316
                SetValue(ControlTypeProperty, value);
317
            }
318
        }
319

    
320
        public double CenterX
321
        {
322
            get { return (double)GetValue(CenterXProperty); }
323
            set { SetValue(CenterXProperty, value); }
324
        }
325
        public double CenterY
326
        {
327
            get { return (double)GetValue(CenterYProperty); }
328
            set { SetValue(CenterYProperty, value); }
329
        }
330
        #endregion
331
        #region Object & Variable
332
        EllipseGeometry instance = new EllipseGeometry();
333
        GeometryGroup CircleGroup = new GeometryGroup();
334

    
335
        #endregion
336
        public override void OnApplyTemplate()
337
        {
338
            base.OnApplyTemplate();
339
            Base_CirclePath = GetTemplateChild(PART_CirclePath) as Path;
340

    
341
            if (Base_CirclePath == null)
342
            {
343
                return;
344
            }
345
            this.SetCircle();
346
        }
347
        public void Dispose()
348
        {
349
            GC.Collect();
350
            GC.SuppressFinalize(this);
351
        }
352

    
353
        public event PropertyChangedEventHandler PropertyChanged;
354
        protected void OnPropertyChanged(string propName)
355
        {
356
            if (PropertyChanged != null)
357
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
358
        }
359
        public void SetCircle()
360
        {
361
            Base_CirclePath.StrokeDashArray.Clear();
362
            foreach (var item in this.DashSize)
363
            {
364
                Base_CirclePath.StrokeDashArray.Add(item);
365
            }
366
            Base_CirclePath.StrokeDashCap = PenLineCap.Square;
367

    
368
            Point middle = MathSet.getMiddlePoint(this.EndPoint, this.StartPoint);
369

    
370
            instance.RadiusX = (MathSet.DistanceTo(this.LeftBottomPoint, this.EndPoint) / 2);
371
            instance.RadiusY = (MathSet.DistanceTo(this.EndPoint, this.TopRightPoint) / 2);
372
            instance.Center = middle;
373
            switch (this.Paint)
374
            {
375
                case PaintSet.None:
376
                    this.FillColor = null;
377
                    Base_CirclePath.Fill = this.FillColor;
378
                    break;
379
                case PaintSet.Fill:
380
                    this.FillColor = this.StrokeColor;
381
                    Base_CirclePath.Fill = this.FillColor;
382
                    break;
383
                case PaintSet.Hatch:
384
                    Base_CirclePath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
385
                    break;
386
                default:
387
                    break;
388
            }
389

    
390

    
391
            CircleGroup.Children.Clear();
392
            CircleGroup.FillRule = FillRule.Nonzero;
393
            CircleGroup.Children.Add(instance);
394

    
395
            try
396
            {                
397
                //강인구 수정(원 테두리가 잘리는것 방지)
398
                //this.Width = Math.Abs(this.CircleGroup.Bounds.Right + 2);
399
                //this.Height = Math.Abs(this.CircleGroup.Bounds.Bottom + 2);
400
                this.Width = Math.Abs(this.CircleGroup.Bounds.Right + 20);
401
                this.Height = Math.Abs(this.CircleGroup.Bounds.Bottom + 20);
402
            }
403
            catch (Exception)
404
            {
405
                
406
            }            
407
            CenterX = Math.Abs(this.CircleGroup.Bounds.X / 2);
408
            CenterY = Math.Abs(this.CircleGroup.Bounds.Y / 2);
409
            this.PathData = CircleGroup;
410
            ApplyOverViewData();
411
        }
412
        public void updateControl()
413
        {
414
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
415
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
416
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
417
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
418
        }
419

    
420
        public void SetCenterXY()
421
        {
422
            CenterX = MathSet.getMiddlePoint(this.StartPoint, this.EndPoint).X;
423
            CenterY = MathSet.getMiddlePoint(this.StartPoint, this.EndPoint).Y;
424
        }
425

    
426
        public void ApplyOverViewData()
427
        {
428
            this.OverViewPathData = this.PathData;
429
        }
430

    
431
        public void ChangePaint(PaintSet state)
432
        {
433
            this.Paint = state;
434
            this.SetCircle();
435
        }
436
    }
437
}
클립보드 이미지 추가 (최대 크기: 500 MB)