프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowArcControl.cs @ 0d00f9c8

이력 | 보기 | 이력해설 | 다운로드 (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
        }
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

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

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

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

    
400

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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