프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (20.8 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
        public double Angle
308
        {
309
            get { return (double)GetValue(AngleProperty); }
310
            set
311
            {
312
                if (this.Angle != value)
313
                {
314
                    SetValue(AngleProperty, value);
315
                }
316
            }
317
        }
318
        public Point EndPoint
319
        {
320
            get { return (Point)GetValue(EndPointProperty); }
321
            set
322
            {
323
                SetValue(EndPointProperty, value);
324
                OnPropertyChanged("EndPoint");
325
            }
326
        }
327
        public Point StartPoint
328
        {
329
            get { return (Point)GetValue(StartPointProperty); }
330
            set
331
            {
332
                SetValue(StartPointProperty, value);
333
                OnPropertyChanged("StartPoint");
334
            }
335
        }
336
        public Point MidPoint
337
        {
338
            get { return (Point)GetValue(MidPointProperty); }
339
            set
340
            {
341
                SetValue(MidPointProperty, value);
342
                OnPropertyChanged("MidPoint");
343
            }
344
        }
345
        public bool isTransOn
346
        {
347
            get { return (bool)GetValue(isTransOnProperty); }
348
            set
349
            {
350
                SetValue(isTransOnProperty, value);
351
                OnPropertyChanged("isTransOn");
352
            }
353
        }
354

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

    
367
        public override void UpdateControl()
368
        {
369
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
370
            this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
371
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
372
        }
373

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

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

    
401

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

    
415
            pathFigure.StartPoint = this.StartPoint;
416
            QuadraticBezierSegment qb = new QuadraticBezierSegment();
417

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

    
425
                    //Point t_start = new Point(0, 0);
426
                    //Point t_end = new Point(30, 10);
427

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

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

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

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

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

    
461
            instanceGroup.FillRule = FillRule.Nonzero;
462
            this.PathData = instanceGroup;
463
            this.OverViewPathData = PathData;
464

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

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

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

    
498
        /// <summary>
499
        /// move control point has same location of given pt along given delta
500
        /// </summary>
501
        /// <author>humkyung</author>
502
        /// <date>2019.06.20</date>
503
        /// <param name="pt"></param>
504
        /// <param name="dx"></param>
505
        /// <param name="dy"></param>
506
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy)
507
        {
508
            Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt);
509
            selected.X += dx;
510
            selected.Y += dy;
511
            for (int i = 0; i < (this as IPath).PointSet.Count; i++)
512
            {
513
                if (pt.Equals((this as IPath).PointSet[i]))
514
                {
515
                    (this as IPath).PointSet[i] = selected;
516
                }
517
            }
518
            this.UpdateControl();
519
        }
520

    
521
        /// <summary>
522
        /// Serialize this
523
        /// </summary>
524
        /// <param name="sUserId"></param>
525
        /// <returns></returns>
526
        public override string Serialize()
527
        {
528
            using (S_ArrowArcControl STemp = new S_ArrowArcControl())
529
            {
530
                STemp.TransformPoint = "0|0";
531
                STemp.PointSet = this.PointSet;
532
                STemp.SizeSet = String.Format("{0}", this.LineSize);
533
                //STemp.StrokeColor = "#FF000FFF";
534
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
535
                STemp.StartPoint = this.StartPoint;
536
                STemp.UserID = this.UserID;
537
                STemp.Opac = this.Opacity;
538
                STemp.MidPoint = this.MidPoint;
539
                STemp.EndPoint = this.EndPoint;
540
                STemp.IsTransOn = this.isTransOn;
541
                STemp.DashSize = this.DashSize;
542
                STemp.Clock = this.Clock;
543
                //STemp.ArcStyleSet = this.ControlType;
544
                STemp.Name = this.GetType().Name.ToString();
545

    
546
                ///강인구 추가(2017.11.02)
547
                ///Memo 추가
548
                STemp.Memo = this.Memo;
549

    
550
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
551
            }
552
        }
553

    
554
        /// <summary>
555
        /// create a arrowarccontrol from given string
556
        /// </summary>
557
        /// <param name="str"></param>
558
        /// <returns></returns>
559
        public static ArrowArcControl FromString(string str, SolidColorBrush brush, string sProjectNo)
560
        {
561
            ArrowArcControl instance = null;
562
            using (S_ArrowArcControl s = JsonSerializerHelper.JsonDeserialize<S_ArrowArcControl>(str))
563
            {
564
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
565
                instance = new ArrowArcControl()
566
                {
567
                    StartPoint = s.StartPoint,
568
                    EndPoint = s.EndPoint,
569
                    DashSize = s.DashSize,
570
                    PointSet = s.PointSet,
571
                    isTransOn = s.IsTransOn,
572
                    MidPoint = s.MidPoint,
573
                    StrokeColor = brush,
574
                    Opacity = s.Opac,
575

    
576
                    Clock = s.Clock,
577
                    LineSize = Convert.ToDouble(data2.First()),
578
                    UserID = s.UserID,
579
                    Memo = s.Memo
580
                };
581
            }
582

    
583
            return instance;
584
        }
585
    }
586
}
클립보드 이미지 추가 (최대 크기: 500 MB)