프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / CircleControl.cs @ f6cecf63

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

1
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using MarkupToPDF.Serialize.Core;
4
using MarkupToPDF.Serialize.S_Control;
5
using System;
6
using System.Collections.Generic;
7
using System.ComponentModel;
8
using System.Windows;
9
using System.Windows.Media;
10
using System.Windows.Shapes;
11

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

    
20
        static CircleControl()
21
        {
22
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CircleControl), new FrameworkPropertyMetadata(typeof(CircleControl)));
23
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
24
            ResourceDictionary dictionary = new ResourceDictionary();
25
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
26
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
27
        }
28

    
29
        #region Dependency Properties
30

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

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

    
37

    
38

    
39

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

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

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

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

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

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

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

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

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

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

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

    
95
            //    instance.SetValue(e.Property, e.NewValue);
96

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

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

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

    
128

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

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

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

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

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

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

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

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

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

    
370
            Point middle = MathSet.getMiddlePoint(this.EndPoint, this.StartPoint);
371

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

    
392

    
393
            CircleGroup.Children.Clear();
394
            CircleGroup.FillRule = FillRule.Nonzero;
395
            CircleGroup.Children.Add(instance);
396

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

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

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

    
433
        public void ChangePaint(PaintSet state)
434
        {
435
            this.Paint = state;
436
            this.SetCircle();
437
        }
438

    
439
        /// <summary>
440
        /// Serialize this
441
        /// </summary>
442
        /// <param name="sUserId"></param>
443
        /// <returns></returns>
444
        public override string Serialize()
445
        {
446
            using (S_CircleControl STemp = new S_CircleControl())
447
            {
448
                STemp.TransformPoint = "0|0";
449
                STemp.SizeSet = String.Format("{0}", this.LineSize);
450
                STemp.PaintState = this.Paint;
451
                //STemp.StrokeColor = "#FF00FF00";
452
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
453
                if (this.FillColor != null)
454
                {
455
                    STemp.FillColor = this.FillColor.Color.ToString();
456
                }
457
                STemp.StartPoint = this.StartPoint;
458
                STemp.UserID = this.UserID;
459
                STemp.EndPoint = this.EndPoint;
460
                STemp.TRP = this.TopRightPoint;
461
                STemp.LBP = this.LeftBottomPoint;
462
                STemp.Opac = this.Opacity;
463
                STemp.Angle = this.Angle;
464
                STemp.PointSet = this.PointSet;
465
                STemp.DashSize = this.DashSize;
466
                STemp.Name = this.GetType().Name.ToString();
467
                ///강인구 추가(2017.11.02)
468
                ///Memo 추가
469
                STemp.Memo = this.Memo;
470

    
471
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
472
            };
473
        }
474
    }
475
}
클립보드 이미지 추가 (최대 크기: 500 MB)