프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (19.9 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
using MarkupToPDF.Serialize.Core;
16
using MarkupToPDF.Serialize.S_Control;
17
using System.Linq;
18

    
19
namespace MarkupToPDF.Controls.Line
20
{
21

    
22
    public class ArrowArcControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
23
    {
24
        #region 초기선언
25
        public event PropertyChangedEventHandler PropertyChanged;
26
        private const string PART_ArcPath = "PART_ArcPath";
27
        public Path Base_ArcPath = null;
28
        #endregion
29
        static ArrowArcControl()
30
        {
31
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowArcControl), new FrameworkPropertyMetadata(typeof(ArrowArcControl)));
32
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
33
            ResourceDictionary dictionary = new ResourceDictionary();
34
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
35
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
36
             //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
37
        }
38

    
39
        public ArrowArcControl()
40
        {
41
            this.DefaultStyleKey = typeof(ArrowArcControl);
42
        }
43

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

    
56
        #region Dependency Properties
57

    
58
        
59

    
60
        public static readonly DependencyProperty IsSelectedProperty =
61
    DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowArcControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
62

    
63
        public static readonly DependencyProperty ControlTypeProperty =
64
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowArcControl), new FrameworkPropertyMetadata(ControlType.ArcArrow));
65

    
66
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
67
                "OverViewPathData", typeof(Geometry), typeof(ArrowArcControl), new PropertyMetadata(null));
68

    
69
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
70
                "UserID", typeof(string), typeof(ArrowArcControl), new PropertyMetadata(null));
71

    
72
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
73
              "LineSize", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((Double)3, PointValueChanged));
74

    
75
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
76
              "DashSize", typeof(DoubleCollection), typeof(ArrowArcControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged));
77

    
78
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
79
               "StrokeColor", typeof(SolidColorBrush), typeof(ArrowArcControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
80

    
81
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
82
              "PathData", typeof(Geometry), typeof(ArrowArcControl), null);
83

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

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

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

    
100
        public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register(
101
                "isTransOn", typeof(bool), typeof(ArrowArcControl), new PropertyMetadata(false));
102

    
103
        public static readonly DependencyProperty AngleProperty =
104
            DependencyProperty.Register("AngleValue", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback
105
                (AngleValueChanged)));
106

    
107
        public static readonly DependencyProperty CenterXProperty =
108
            DependencyProperty.Register("CenterX", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0, OnCenterXYChanged));
109

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

    
119
            //if (e.OldValue != e.NewValue && instance.Base_ArcPath != null)
120
            //{
121

    
122
            //    instance.SetValue(e.Property, e.NewValue);
123

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

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

    
163
      
164

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

    
191

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

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

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

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

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

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

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

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

    
399

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

    
413
            pathFigure.StartPoint = this.StartPoint;
414
            QuadraticBezierSegment qb = new QuadraticBezierSegment();
415

    
416
            if (MidPoint != null)
417
            {
418
                if (MidPoint == new Point(0,0))
419
                {
420
                    double xSharp = 0;
421
                    double ySharp = 0;
422

    
423
                    //Point t_start = new Point(0, 0);
424
                    //Point t_end = new Point(30, 10);
425

    
426
                    var midP = MathSet.getMiddlePoint(StartPoint, EndPoint);
427
                    Point normalV = MathSet.GetNormVectorBetween(StartPoint, EndPoint);
428
                    var dis = MathSet.DistanceTo(StartPoint, EndPoint);
429

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

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

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

    
455
            instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.StartPoint, this.LineSize));
456
            instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.EndPoint, this.LineSize));
457
            this.Base_ArcPath.Fill = this.StrokeColor;
458

    
459
            instanceGroup.FillRule = FillRule.Nonzero;
460
            this.PathData = instanceGroup;
461
            this.OverViewPathData = PathData;
462

    
463
        }
464
        
465
        public override void ApplyOverViewData()
466
        {
467
            this.OverViewPathData = this.PathData;
468
        }
469

    
470
        /// <summary>
471
        /// call when mouse is moving while drawing control
472
        /// </summary>
473
        /// <author>humkyung</author>
474
        /// <param name="pt"></param>
475
        /// <param name="bAxisLocked"></param>
476
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked, bool bShiftKeyPressed)
477
        {
478
            this.isTransOn = false;
479
            this.MidPoint = new Point(0, 0);
480
            this.EndPoint = pt;
481
            if (bAxisLocked || bShiftKeyPressed)
482
            {
483
                Point tmp = this.EndPoint;
484
                string angle = MathSet.returnAngleString(this.StartPoint, ref tmp, true);
485
                this.EndPoint = tmp;
486
            }
487

    
488
            this.PointSet = new List<Point>
489
            {
490
                this.StartPoint,
491
                this.MidPoint,
492
                this.EndPoint,
493
            };
494
        }
495

    
496
        /// <summary>
497
        /// Serialize this
498
        /// </summary>
499
        /// <param name="sUserId"></param>
500
        /// <returns></returns>
501
        public override string Serialize()
502
        {
503
            using (S_ArrowArcControl STemp = new S_ArrowArcControl())
504
            {
505
                STemp.TransformPoint = "0|0";
506
                STemp.PointSet = this.PointSet;
507
                STemp.SizeSet = String.Format("{0}", this.LineSize);
508
                //STemp.StrokeColor = "#FF000FFF";
509
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
510
                STemp.StartPoint = this.StartPoint;
511
                STemp.UserID = this.UserID;
512
                STemp.Opac = this.Opacity;
513
                STemp.MidPoint = this.MidPoint;
514
                STemp.EndPoint = this.EndPoint;
515
                STemp.IsTransOn = this.isTransOn;
516
                STemp.DashSize = this.DashSize;
517
                STemp.Clock = this.Clock;
518
                //STemp.ArcStyleSet = this.ControlType;
519
                STemp.Name = this.GetType().Name.ToString();
520

    
521
                ///강인구 추가(2017.11.02)
522
                ///Memo 추가
523
                STemp.Memo = this.Memo;
524

    
525
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
526
            }
527
        }
528

    
529
        /// <summary>
530
        /// create a arrowarccontrol from given string
531
        /// </summary>
532
        /// <param name="str"></param>
533
        /// <returns></returns>
534
        public static ArrowArcControl FromString(string str, SolidColorBrush brush, string sProjectNo)
535
        {
536
            ArrowArcControl instance = null;
537
            using (S_ArrowArcControl s = JsonSerializerHelper.JsonDeserialize<S_ArrowArcControl>(str))
538
            {
539
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
540
                instance = new ArrowArcControl()
541
                {
542
                    StartPoint = s.StartPoint,
543
                    EndPoint = s.EndPoint,
544
                    DashSize = s.DashSize,
545
                    PointSet = s.PointSet,
546
                    isTransOn = s.IsTransOn,
547
                    MidPoint = s.MidPoint,
548
                    StrokeColor = brush,
549
                    Opacity = s.Opac,
550

    
551
                    Clock = s.Clock,
552
                    LineSize = Convert.ToDouble(data2.First()),
553
                    UserID = s.UserID,
554
                    Memo = s.Memo
555
                };
556
            }
557

    
558
            return instance;
559
        }
560
    }
561
}
클립보드 이미지 추가 (최대 크기: 500 MB)