프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowArcControl.cs @ 24c5e56c

이력 | 보기 | 이력해설 | 다운로드 (22.1 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
            this.Base_ArcPath = null;
50
        }
51
        protected void OnPropertyChanged(string propName)
52
        {
53
            if (PropertyChanged != null)
54
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
55
        }
56

    
57
        #region Dependency Properties
58

    
59
        
60

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
164
      
165

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

    
192

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

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

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

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

    
290
        public override ControlType ControlType
291
        {
292
            get
293
            {
294
                return (ControlType)GetValue(ControlTypeProperty);
295
            }
296
            set
297
            {
298
                SetValue(ControlTypeProperty, value);
299
                OnPropertyChanged("ControlType");
300
            }
301
        }
302
        public double AngleValue
303
        {
304
            get { return (double)GetValue(AngleProperty); }
305
            set { SetValue(AngleProperty, value); }
306
        }
307

    
308

    
309
        //public double Angle
310
        //{
311
        //    get { return (double)GetValue(AngleProperty); }
312
        //    set
313
        //    {
314
        //        if (this.Angle != value)
315
        //        {
316
        //            SetValue(AngleProperty, value);
317
        //        }
318
        //    }
319
        //}
320

    
321
        public Point EndPoint
322
        {
323
            get { return (Point)GetValue(EndPointProperty); }
324
            set
325
            {
326
                SetValue(EndPointProperty, value);
327
                OnPropertyChanged("EndPoint");
328
            }
329
        }
330
        public Point StartPoint
331
        {
332
            get { return (Point)GetValue(StartPointProperty); }
333
            set
334
            {
335
                SetValue(StartPointProperty, value);
336
                OnPropertyChanged("StartPoint");
337
            }
338
        }
339
        public Point MiddlePoint
340
        {
341
            get { return (Point)GetValue(MidPointProperty); }
342
            set
343
            {
344
                SetValue(MidPointProperty, value);
345
                OnPropertyChanged("MiddlePoint");
346
            }
347
        }
348
        public bool isTransOn
349
        {
350
            get { return (bool)GetValue(isTransOnProperty); }
351
            set
352
            {
353
                SetValue(isTransOnProperty, value);
354
                OnPropertyChanged("isTransOn");
355
            }
356
        }
357

    
358
        #endregion
359
        #region Object & Variable
360
        PathGeometry pathGeometry = new PathGeometry();
361
        GeometryGroup instanceGroup = new GeometryGroup();
362
        #endregion
363
        public override void OnApplyTemplate()
364
        {
365
            base.OnApplyTemplate();
366
            Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path;
367
            SetArcPath();
368
        }
369

    
370
        public override void UpdateControl()
371
        {
372
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
373
            this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
374
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
375
        }
376

    
377
        public void setClock()
378
        {
379
            if (Clock)
380
            {
381
                this.Clock = false;
382
            }
383
            else
384
            {
385
                this.Clock = true;
386
            }
387
        }
388

    
389
        //public void setClock()
390
        //{
391
        //    if(this.Clock == SweepDirection.Clockwise)
392
        //    {
393
        //        this.Clock = SweepDirection.Counterclockwise;
394
        //    }
395
        //    else
396
        //    {
397
        //        this.Clock =SweepDirection.Clockwise;
398
        //    }
399
        //}
400
        public void SetArcPath()
401
        {
402
            this.ApplyTemplate();
403

    
404

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

    
418
            pathFigure.StartPoint = this.StartPoint;
419
            QuadraticBezierSegment qb = new QuadraticBezierSegment();
420

    
421
            if (MiddlePoint != null)
422
            {
423
                if (MiddlePoint == new Point(0,0))
424
                {
425
                    double xSharp = 0;
426
                    double ySharp = 0;
427

    
428
                    //Point t_start = new Point(0, 0);
429
                    //Point t_end = new Point(30, 10);
430

    
431
                    var midP = MathSet.getMiddlePoint(StartPoint, EndPoint);
432
                    Point normalV = MathSet.GetNormVectorBetween(StartPoint, EndPoint);
433
                    var dis = MathSet.DistanceTo(StartPoint, EndPoint);
434

    
435
                    if (!this.Clock)
436
                    {
437
                        xSharp = -normalV.Y;
438
                        ySharp = normalV.X;
439
                    }
440
                    else
441
                    {
442
                        xSharp = normalV.Y;
443
                        ySharp = -normalV.X;
444
                    }
445

    
446
                    var pointN = new Point(xSharp * dis, ySharp * dis);
447
                    MiddlePoint = new Point(pointN.X + midP.X, pointN.Y + midP.Y);
448
                }
449
                qb.Point1 = this.MiddlePoint;
450
            }
451

    
452
            qb.Point2 = this.EndPoint;
453
            pathFigure.Segments.Add(qb);
454
            pathGeometry.Figures = new PathFigureCollection();
455
            pathGeometry.Figures.Add(pathFigure);
456
            pathFigure.IsFilled = false;
457
            pathFigure.IsClosed = false;
458
            instanceGroup.Children.Add(pathGeometry);
459

    
460
            instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.StartPoint, this.LineSize));
461
            instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.EndPoint, this.LineSize));
462
            this.Base_ArcPath.Fill = this.StrokeColor;
463

    
464
            instanceGroup.FillRule = FillRule.Nonzero;
465
            this.PathData = instanceGroup;
466
            this.OverViewPathData = PathData;
467

    
468
        }
469
        
470
        public override void ApplyOverViewData()
471
        {
472
            this.OverViewPathData = this.PathData;
473
        }
474

    
475
        /// <summary>
476
        /// call when mouse is moving while drawing control
477
        /// </summary>
478
        /// <author>humkyung</author>
479
        /// <param name="pt"></param>
480
        /// <param name="bAxisLocked"></param>
481
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
482
        {
483
            this.isTransOn = false;
484
            this.MiddlePoint = new Point(0, 0);
485
            this.EndPoint = pt;
486
         
487
            Point tmp = this.EndPoint;
488
            CommentAngle = MathSet.returnAngle(this.StartPoint, ref tmp, bAxisLocked);
489

    
490
            if (bAxisLocked)
491
            {
492
                this.EndPoint = tmp;
493
            }
494

    
495
            this.PointSet = new List<Point>
496
            {
497
                this.StartPoint,
498
                this.MiddlePoint,
499
                this.EndPoint,
500
            };
501
        }
502

    
503
        /// <summary>
504
        /// move control point has same location of given pt along given delta
505
        /// </summary>
506
        /// <author>humkyung</author>
507
        /// <date>2019.06.20</date>
508
        /// <param name="pt"></param>
509
        /// <param name="dx"></param>
510
        /// <param name="dy"></param>
511
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false)
512
        {
513
            Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt);
514

    
515
            var tmpPointSet = (this as IPath).PointSet.Where(x => !x.Equals(selected));
516
            Point NearStartpoint = MathSet.getNearPoint(tmpPointSet.ToList(), pt);
517

    
518
            selected.X += dx;
519
            selected.Y += dy;
520

    
521
            Point tmp = selected;
522

    
523
            CommentAngle = MathSet.returnAngle(NearStartpoint, ref tmp, bAxisLocked);
524

    
525
            if (bAxisLocked)
526
            {
527
                selected = tmp;
528
            }
529

    
530
            for (int i = 0; i < (this as IPath).PointSet.Count; i++)
531
            {
532
                if (pt.Equals((this as IPath).PointSet[i]))
533
                {
534
                    (this as IPath).PointSet[i] = selected;
535
                }
536
            }
537
            this.UpdateControl();
538
        }
539

    
540

    
541
        /// <summary>
542
        /// return ArrowControl_Multi's area
543
        /// </summary>
544
        /// <author>humkyung</author>
545
        /// <date>2019.06.13</date>
546
        public override Rect ItemRect
547
        {
548
            get
549
            {
550
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
551
                dMinX = Math.Min(this.MiddlePoint.X, dMinX);
552
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
553
                dMinY = Math.Min(this.MiddlePoint.Y, dMinY);
554
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
555
                dMaxX = Math.Max(this.MiddlePoint.X, dMaxX);
556
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
557
                dMaxY = Math.Max(this.MiddlePoint.Y, dMaxY);
558

    
559
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
560
            }
561
        }
562

    
563
        /// <summary>
564
        /// Serialize this
565
        /// </summary>
566
        /// <param name="sUserId"></param>
567
        /// <returns></returns>
568
        public override string Serialize()
569
        {
570
            using (S_ArrowArcControl STemp = new S_ArrowArcControl())
571
            {
572
                STemp.TransformPoint = "0|0";
573
                STemp.PointSet = this.PointSet;
574
                STemp.SizeSet = String.Format("{0}", this.LineSize);
575
                //STemp.StrokeColor = "#FF000FFF";
576
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
577
                STemp.StartPoint = this.StartPoint;
578
                STemp.UserID = this.UserID;
579
                STemp.Opac = this.Opacity;
580
                STemp.MiddlePoint = this.MiddlePoint;
581
                STemp.EndPoint = this.EndPoint;
582
                STemp.IsTransOn = this.isTransOn;
583
                STemp.DashSize = this.DashSize;
584
                STemp.Clock = this.Clock;
585
                //STemp.ArcStyleSet = this.ControlType;
586
                STemp.Name = this.GetType().Name.ToString();
587

    
588
                ///강인구 추가(2017.11.02)
589
                ///Memo 추가
590
                STemp.Memo = this.Memo;
591

    
592
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
593
            }
594
        }
595

    
596
        /// <summary>
597
        /// create a arrowarccontrol from given string
598
        /// </summary>
599
        /// <param name="str"></param>
600
        /// <returns></returns>
601
        public static ArrowArcControl FromString(string str, SolidColorBrush brush, string sProjectNo)
602
        {
603
            ArrowArcControl instance = null;
604
            using (S_ArrowArcControl s = JsonSerializerHelper.JsonDeserialize<S_ArrowArcControl>(str))
605
            {
606
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
607
                instance = new ArrowArcControl()
608
                {
609
                    StartPoint = s.StartPoint,
610
                    EndPoint = s.EndPoint,
611
                    DashSize = s.DashSize,
612
                    PointSet = s.PointSet,
613
                    isTransOn = s.IsTransOn,
614
                    MiddlePoint = s.MiddlePoint,
615
                    StrokeColor = brush,
616
                    Opacity = s.Opac,
617

    
618
                    Clock = s.Clock,
619
                    LineSize = Convert.ToDouble(data2.First()),
620
                    UserID = s.UserID,
621
                    Memo = s.Memo
622
                };
623
            }
624

    
625
            return instance;
626
        }
627
    }
628
}
클립보드 이미지 추가 (최대 크기: 500 MB)