프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowArcControl.cs @ d251456f

이력 | 보기 | 이력해설 | 다운로드 (16.5 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.Line
17
{
18

    
19
    public class ArrowArcControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
20
    {
21
        #region 초기선언
22
        public event PropertyChangedEventHandler PropertyChanged;
23
        private const string PART_ArcPath = "PART_ArcPath";
24
        public Path Base_ArcPath = null;
25
        #endregion
26
        static ArrowArcControl()
27
        {
28
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowArcControl), new FrameworkPropertyMetadata(typeof(ArrowArcControl)));
29
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
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
             //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
34
        }
35

    
36
        public ArrowArcControl()
37
        {
38
            this.DefaultStyleKey = typeof(ArrowArcControl);
39
        }
40

    
41
        public void Dispose()
42
        {
43
            GC.Collect();
44
            GC.SuppressFinalize(this);
45
            Control control = new Control();
46
        }
47
        protected void OnPropertyChanged(string propName)
48
        {
49
            if (PropertyChanged != null)
50
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
51
        }
52

    
53
        #region Dependency Properties
54

    
55
        
56

    
57
        public static readonly DependencyProperty IsSelectedProperty =
58
    DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowArcControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
59

    
60
        public static readonly DependencyProperty ControlTypeProperty =
61
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowArcControl), new FrameworkPropertyMetadata(ControlType.ArcArrow));
62

    
63
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
64
                "OverViewPathData", typeof(Geometry), typeof(ArrowArcControl), new PropertyMetadata(null));
65

    
66
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
67
                "UserID", typeof(string), typeof(ArrowArcControl), new PropertyMetadata(null));
68

    
69
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
70
              "LineSize", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((Double)3, PointValueChanged));
71

    
72
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
73
              "DashSize", typeof(DoubleCollection), typeof(ArrowArcControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged));
74

    
75
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
76
               "StrokeColor", typeof(SolidColorBrush), typeof(ArrowArcControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
77

    
78
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
79
              "PathData", typeof(Geometry), typeof(ArrowArcControl), null);
80

    
81
        //public static readonly DependencyProperty ClockProperty = DependencyProperty.Register(
82
        //       "Clock", typeof(SweepDirection), typeof(ArrowArcControl), new PropertyMetadata(SweepDirection.Clockwise));
83
        public static readonly DependencyProperty ClockProperty = DependencyProperty.Register(
84
               "Clock", typeof(bool), typeof(ArrowArcControl), new PropertyMetadata(false));
85

    
86
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
87
               "StartPoint", typeof(Point), typeof(ArrowArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
88
        public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register(
89
               "MidPoint", typeof(Point), typeof(ArrowArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
90

    
91
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
92
               "EndPoint", typeof(Point), typeof(ArrowArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
93
        
94
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
95
                "PointSet", typeof(List<Point>), typeof(ArrowArcControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
96

    
97
        public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register(
98
                "isTransOn", typeof(bool), typeof(ArrowArcControl), new PropertyMetadata(false));
99

    
100
        public static readonly DependencyProperty AngleProperty =
101
            DependencyProperty.Register("AngleValue", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback
102
                (AngleValueChanged)));
103

    
104
        public static readonly DependencyProperty CenterXProperty =
105
            DependencyProperty.Register("CenterX", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0, OnCenterXYChanged));
106

    
107
        public static readonly DependencyProperty CenterYProperty =
108
            DependencyProperty.Register("CenterY", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0, OnCenterXYChanged));
109
        #endregion
110
        #region PropertyChanged Method
111
        
112
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
113
        {
114
            //var instance = (ArrowArcControl)sender;
115

    
116
            //if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
117
            //{
118

    
119
            //    instance.SetValue(e.Property, e.NewValue);
120

    
121
            //    if (instance.IsSelected)
122
            //    {
123
            //        instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Blue);
124
            //    }
125
            //    else
126
            //    {
127
            //        instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Red);
128
            //    }
129
            //}
130
        }
131

    
132
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
133
        {
134
            var instance = (ArrowArcControl)sender;
135
            if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
136
            {
137
                instance.SetValue(e.Property, e.NewValue);
138
                instance.SetArcPath();
139
            }
140
        }
141
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
142
        {
143
            var instance = (ArrowArcControl)sender;
144
            if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
145
            {
146
                instance.SetValue(e.Property, e.NewValue);
147
                instance.SetArcPath();
148
            }
149
        }
150
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
151
        {
152
            var instance = (ArrowArcControl)sender;
153
            if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
154
            {
155
                instance.SetValue(e.Property, e.NewValue);
156
                instance.SetArcPath();
157
            }
158
        }
159

    
160
      
161

    
162
        #endregion
163
        #region Properties
164
        public string UserID
165
        {
166
            get { return (string)GetValue(UserIDProperty); }
167
            set
168
            {
169
                if (this.UserID != value)
170
                {
171
                    SetValue(UserIDProperty, value);
172
                    OnPropertyChanged("UserID");
173
                }
174
            }
175
        }
176
        public Double LineSize
177
        {
178
            get { return (Double)GetValue(LineSizeProperty); }
179
            set
180
            {
181
                if (this.LineSize != value)
182
                {
183
                    SetValue(LineSizeProperty, value);
184
                }
185
            }
186
        }
187

    
188

    
189
        public bool Clock
190
        {
191
            get { return (bool)GetValue(ClockProperty); }
192
            set
193
            {
194
                if (this.Clock != value)
195
                {
196
                    SetValue(ClockProperty, value);
197
                    OnPropertyChanged("Clock");
198
                }
199
            }
200
        }
201

    
202
        //public SweepDirection Clock
203
        //{
204
        //    get { return (SweepDirection)GetValue(ClockProperty); }
205
        //    set
206
        //    {
207
        //        if (this.Clock != value)
208
        //        {
209
        //            SetValue(ClockProperty, value);
210
        //            OnPropertyChanged("Clock");
211
        //        }
212
        //    }
213
        //}
214
        public DoubleCollection DashSize
215
        {
216
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
217
            set
218
            {
219
                if (this.DashSize != value)
220
                {
221
                    SetValue(DashSizeProperty, value);
222
                }
223
            }
224
        }
225
        public List<Point> PointSet
226
        {
227
            get { return (List<Point>)GetValue(PointSetProperty); }
228
            set { SetValue(PointSetProperty, value); }
229
        }
230
        public double CenterX
231
        {
232
            get { return (double)GetValue(CenterXProperty); }
233
            set { SetValue(CenterXProperty, value); }
234
        }
235
        public double CenterY
236
        {
237
            get { return (double)GetValue(CenterYProperty); }
238
            set { SetValue(CenterYProperty, value); }
239
        }
240
        public SolidColorBrush StrokeColor
241
        {
242
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
243
            set
244
            {
245
                if (this.StrokeColor != value)
246
                {
247
                    SetValue(StrokeColorProperty, value);
248
                }
249
            }
250
        }
251

    
252
        public Geometry OverViewPathData
253
        {
254
            get
255
            {
256
                return (Geometry)GetValue(OverViewPathDataProperty);
257
            }
258
            set
259
            {
260
                SetValue(OverViewPathDataProperty, value);
261
                OnPropertyChanged("OverViewPathData");
262
            }
263
        }
264

    
265
        public Geometry PathData
266
        {
267
            get { return (Geometry)GetValue(PathDataProperty); }
268
            set
269
            {
270
                SetValue(PathDataProperty, value);
271
                OnPropertyChanged("PathData");
272
            }
273
        }
274
        public bool IsSelected
275
        {
276
            get
277
            {
278
                return (bool)GetValue(IsSelectedProperty);
279
            }
280
            set
281
            {
282
                SetValue(IsSelectedProperty, value);
283
            }
284
        }
285

    
286
        public ControlType ControlType
287
        {
288
            get
289
            {
290
                return (ControlType)GetValue(ControlTypeProperty);
291
            }
292
            set
293
            {
294
                SetValue(ControlTypeProperty, value);
295
                OnPropertyChanged("ControlType");
296
            }
297
        }
298
        public double AngleValue
299
        {
300
            get { return (double)GetValue(AngleProperty); }
301
            set { SetValue(AngleProperty, value); }
302
        }
303
        public double Angle
304
        {
305
            get { return (double)GetValue(AngleProperty); }
306
            set
307
            {
308
                if (this.Angle != value)
309
                {
310
                    SetValue(AngleProperty, value);
311
                }
312
            }
313
        }
314
        public Point EndPoint
315
        {
316
            get { return (Point)GetValue(EndPointProperty); }
317
            set
318
            {
319
                SetValue(EndPointProperty, value);
320
                OnPropertyChanged("EndPoint");
321
            }
322
        }
323
        public Point StartPoint
324
        {
325
            get { return (Point)GetValue(StartPointProperty); }
326
            set
327
            {
328
                SetValue(StartPointProperty, value);
329
                OnPropertyChanged("StartPoint");
330
            }
331
        }
332
        public Point MidPoint
333
        {
334
            get { return (Point)GetValue(MidPointProperty); }
335
            set
336
            {
337
                SetValue(MidPointProperty, value);
338
                OnPropertyChanged("MidPoint");
339
            }
340
        }
341
        public bool isTransOn
342
        {
343
            get { return (bool)GetValue(isTransOnProperty); }
344
            set
345
            {
346
                SetValue(isTransOnProperty, value);
347
                OnPropertyChanged("isTransOn");
348
            }
349
        }
350

    
351
        #endregion
352
        #region Object & Variable
353
        PathGeometry pathGeometry = new PathGeometry();
354
        GeometryGroup instanceGroup = new GeometryGroup();
355
        #endregion
356
        public override void OnApplyTemplate()
357
        {
358
            base.OnApplyTemplate();
359
            Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path;
360
            SetArcPath();
361
        }
362
        public void updateControl()
363
        {
364
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
365
            this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
366
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
367
        }
368

    
369
        public void setClock()
370
        {
371
            if (Clock)
372
            {
373
                this.Clock = false;
374
            }
375
            else
376
            {
377
                this.Clock = true;
378
            }
379
        }
380

    
381
        //public void setClock()
382
        //{
383
        //    if(this.Clock == SweepDirection.Clockwise)
384
        //    {
385
        //        this.Clock = SweepDirection.Counterclockwise;
386
        //    }
387
        //    else
388
        //    {
389
        //        this.Clock =SweepDirection.Clockwise;
390
        //    }
391
        //}
392
        public void SetArcPath()
393
        {
394
            this.ApplyTemplate();
395

    
396

    
397
            //강인구 추가
398
            Base_ArcPath.StrokeDashArray.Clear();
399
            if (this.DashSize != null)
400
            {
401
                foreach (var item in this.DashSize)
402
                {
403
                    Base_ArcPath.StrokeDashArray.Add(item);
404
                }
405
                Base_ArcPath.StrokeDashCap = PenLineCap.Square;
406
                instanceGroup.Children.Clear();
407
            }
408
            PathFigure pathFigure = new PathFigure();
409

    
410
            pathFigure.StartPoint = this.StartPoint;
411
            QuadraticBezierSegment qb = new QuadraticBezierSegment();
412

    
413
            if (MidPoint != null)
414
            {
415
                if (MidPoint == new Point(0,0))
416
                {
417
                    double xSharp = 0;
418
                    double ySharp = 0;
419

    
420
                    //Point t_start = new Point(0, 0);
421
                    //Point t_end = new Point(30, 10);
422

    
423
                    var midP = MathSet.getMiddlePoint(StartPoint, EndPoint);
424
                    Point normalV = MathSet.GetNormVectorBetween(StartPoint, EndPoint);
425
                    var dis = MathSet.DistanceTo(StartPoint, EndPoint);
426

    
427
                    if (!this.Clock)
428
                    {
429
                        xSharp = -normalV.Y;
430
                        ySharp = normalV.X;
431
                    }
432
                    else
433
                    {
434
                        xSharp = normalV.Y;
435
                        ySharp = -normalV.X;
436
                    }
437

    
438
                    var pointN = new Point(xSharp * dis, ySharp * dis);
439
                    MidPoint = new Point(pointN.X + midP.X, pointN.Y + midP.Y);
440
                }
441
                qb.Point1 = this.MidPoint;
442
            }
443

    
444
            qb.Point2 = this.EndPoint;
445
            pathFigure.Segments.Add(qb);
446
            pathGeometry.Figures = new PathFigureCollection();
447
            pathGeometry.Figures.Add(pathFigure);
448
            pathFigure.IsFilled = false;
449
            pathFigure.IsClosed = false;
450
            instanceGroup.Children.Add(pathGeometry);
451

    
452
            instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.StartPoint, this.LineSize));
453
            instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.EndPoint, this.LineSize));
454
            this.Base_ArcPath.Fill = this.StrokeColor;
455

    
456
            instanceGroup.FillRule = FillRule.Nonzero;
457
            this.PathData = instanceGroup;
458
            this.OverViewPathData = PathData;
459

    
460
        }
461
        
462
        public void ApplyOverViewData()
463
        {
464
            this.OverViewPathData = this.PathData;
465
        }
466
    }
467
}
클립보드 이미지 추가 (최대 크기: 500 MB)