프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (22.4 KB)

1 787a4489 KangIngu
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 036650a0 humkyung
using MarkupToPDF.Serialize.S_Control;
16
using MarkupToPDF.Serialize.Core;
17 661b7416 humkyung
using System.Linq;
18 787a4489 KangIngu
19
namespace MarkupToPDF.Controls.Line
20
{
21
22
    public class ArcControl : 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 ArcControl()
30
        {
31
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ArcControl), new FrameworkPropertyMetadata(typeof(ArcControl)));
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 ArcControl()
40
        {
41
            this.DefaultStyleKey = typeof(ArcControl);
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(ArcControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
62
63
        public static readonly DependencyProperty ControlTypeProperty =
64
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArcControl), new FrameworkPropertyMetadata(ControlType.ArcLine));
65
66
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
67
                "OverViewPathData", typeof(Geometry), typeof(ArcControl), new PropertyMetadata(null));
68
69
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
70
                "UserID", typeof(string), typeof(ArcControl), new PropertyMetadata(null));
71
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
72
              "LineSize", typeof(double), typeof(ArcControl), new PropertyMetadata((Double)3));
73
74
//강인구 추가
75
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
76
              "DashSize", typeof(DoubleCollection), typeof(ArcControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged));
77
78
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
79
               "StrokeColor", typeof(SolidColorBrush), typeof(ArcControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
80
81
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
82
              "PathData", typeof(Geometry), typeof(ArcControl), null);
83
84
        //public static readonly DependencyProperty ClockProperty = DependencyProperty.Register(
85
        //       "Clock", typeof(SweepDirection), typeof(ArcControl), new PropertyMetadata(SweepDirection.Clockwise));
86
        public static readonly DependencyProperty ClockProperty = DependencyProperty.Register(
87
               "Clock", typeof(bool), typeof(ArcControl), new PropertyMetadata(false));
88
89
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
90
               "StartPoint", typeof(Point), typeof(ArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
91
        public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register(
92
               "MidPoint", typeof(Point), typeof(ArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
93
94
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
95
               "EndPoint", typeof(Point), typeof(ArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
96
        
97
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
98
                "PointSet", typeof(List<Point>), typeof(ArcControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
99
100
        public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register(
101
                "isTransOn", typeof(bool), typeof(ArcControl), new PropertyMetadata(false));
102
103
        public static readonly DependencyProperty AngleProperty =
104
            DependencyProperty.Register("AngleValue", typeof(double), typeof(ArcControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback
105
                (AngleValueChanged)));
106
107
        public static readonly DependencyProperty CenterXProperty =
108
            DependencyProperty.Register("CenterX", typeof(double), typeof(ArcControl), new PropertyMetadata((double)0, OnCenterXYChanged));
109
110
        public static readonly DependencyProperty CenterYProperty =
111
            DependencyProperty.Register("CenterY", typeof(double), typeof(ArcControl), 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 = (ArcControl)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
136
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
137
        {
138
            var instance = (ArcControl)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 = (ArcControl)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 = (ArcControl)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 4913851c humkyung
        public override SolidColorBrush StrokeColor
245 787a4489 KangIngu
        {
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 959b3ef2 humkyung
        public override bool IsSelected
279 787a4489 KangIngu
        {
280
            get
281
            {
282
                return (bool)GetValue(IsSelectedProperty);
283
            }
284
            set
285
            {
286
                SetValue(IsSelectedProperty, value);
287
            }
288
        }
289
290 5529d2a2 humkyung
        public override ControlType ControlType
291 787a4489 KangIngu
        {
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
        public 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 661b7416 humkyung
        private void SetArcPath()
397 787a4489 KangIngu
        {
398
            this.ApplyTemplate();
399
400
401
            //강인구 추가
402
            Base_ArcPath.StrokeDashArray.Clear();
403
            foreach (var item in this.DashSize)
404
            {
405
                Base_ArcPath.StrokeDashArray.Add(item);
406
            }
407
            instanceGroup.Children.Clear();
408
409
410
            PathFigure pathFigure = new PathFigure();
411
412
            pathFigure.StartPoint = this.StartPoint;
413
            QuadraticBezierSegment qb = new QuadraticBezierSegment();
414
415
416
          
417
418
419
            
420
            
421
422
423
            if (MidPoint != null)
424
            {
425
                if (MidPoint == new Point(0,0))
426
                {
427
                    double xSharp = 0;
428
                    double ySharp = 0;
429
430
                    //Point t_start = new Point(0, 0);
431
                    //Point t_end = new Point(30, 10);
432
433
                    var midP = MathSet.getMiddlePoint(StartPoint, EndPoint);
434
                    Point normalV = MathSet.GetNormVectorBetween(StartPoint, EndPoint);
435
                    var dis = MathSet.DistanceTo(StartPoint, EndPoint);
436
437
                    if (!this.Clock)
438
                    {
439
                        xSharp = -normalV.Y;
440
                        ySharp = normalV.X;
441
                    }
442
                    else
443
                    {
444
                        xSharp = normalV.Y;
445
                        ySharp = -normalV.X;
446
                    }
447
448
                    var pointN = new Point(xSharp * dis, ySharp * dis);
449
                    MidPoint = new Point(pointN.X + midP.X, pointN.Y + midP.Y);
450
                }
451
                ////System.Diagnostics.Debug.WriteLine(this.MidPoint.ToString());
452
                //qb.Point1 = new Point(200, 200);
453
                //qb.Point1 = this.MidPoint;
454
                qb.Point1 = this.MidPoint;
455
            }
456
457
            qb.Point2 = this.EndPoint;
458
            pathFigure.Segments.Add(qb);
459
            pathGeometry.Figures = new PathFigureCollection();
460
            pathGeometry.Figures.Add(pathFigure);
461
            pathFigure.IsFilled = false;
462
            pathFigure.IsClosed = false;
463
            instanceGroup.Children.Add(pathGeometry);
464
465
            //Arc Arrow
466
            //if(ControlType == ControlType.ArcArrow)
467
            if (isTransOn)
468
            {
469
                //isTransOn = true;
470 d251456f humkyung
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.StartPoint, this.LineSize));
471
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.EndPoint, this.MidPoint, this.LineSize));
472 787a4489 KangIngu
                this.Base_ArcPath.Fill = this.StrokeColor;
473
            }
474
            //Base_ArcPath.StrokeThickness = 3;
475
476
            instanceGroup.FillRule = FillRule.Nonzero;
477
            this.PathData = instanceGroup;
478
            this.OverViewPathData = PathData;
479
480
        }
481
482
        public static PathGeometry ConverseAllow(Point p2, Point p1, double lineSize)
483
        {
484
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
485
            PathGeometry pathGeometry2 = new PathGeometry();
486
            PathFigure pathFigure2 = new PathFigure();
487
            pathFigure2.StartPoint = p2;
488
489
            Point lpoint2 = new Point(p2.X + lineSize * 2, p2.Y + lineSize * 4);
490
            Point rpoint2 = new Point(p2.X - lineSize * 2, p2.Y + lineSize * 4);
491
            LineSegment seg1_1 = new LineSegment();
492
            seg1_1.Point = lpoint2;
493
            pathFigure2.Segments.Add(seg1_1);
494
495
            LineSegment seg2_1 = new LineSegment();
496
            seg2_1.Point = rpoint2;
497
            pathFigure2.Segments.Add(seg2_1);
498
499
            LineSegment seg3_1 = new LineSegment();
500
            seg3_1.Point = p2;
501
            pathFigure2.Segments.Add(seg3_1);
502
503
            LineSegment seg4_1 = new LineSegment();
504
505
            seg4_1.Point = new Point(lpoint2.X, lpoint2.Y);
506
            pathFigure2.Segments.Add(seg4_1);
507
508
            //pathFigure2.IsFilled = true;
509
            //pathFigure2.IsClosed = true;
510
511
            RotateTransform transform2 = new RotateTransform();
512
            transform2.Angle = theta + 90;
513
            transform2.CenterX = p2.X;
514
            transform2.CenterY = p2.Y;
515
            pathGeometry2.Figures.Add(pathFigure2);
516
            pathGeometry2.Transform = transform2;
517
            return pathGeometry2;
518
        }
519
520 f513c215 humkyung
        public override void ApplyOverViewData()
521 787a4489 KangIngu
        {
522
            this.OverViewPathData = this.PathData;
523
        }
524 036650a0 humkyung
525
        /// <summary>
526 a6272c57 humkyung
        /// call when mouse is moving while drawing control
527
        /// </summary>
528
        /// <author>humkyung</author>
529
        /// <param name="pt"></param>
530
        /// <param name="bAxisLocked"></param>
531
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked, bool bShiftKeyPressed)
532
        {
533
            this.isTransOn = false;
534
            this.EndPoint = pt;
535
            this.MidPoint = new Point(0, 0);
536
537
            if (bAxisLocked || bShiftKeyPressed)
538
            {
539
                Point tmp = this.EndPoint;
540
                string angle = MathSet.returnAngleString(this.StartPoint, ref tmp, true);
541
                this.EndPoint = tmp;
542
            }
543
544
            this.PointSet = new List<Point>
545
            {
546
                this.StartPoint,
547
                this.MidPoint,
548
                this.EndPoint,
549
            };
550
        }
551
552
        /// <summary>
553 91efe37a humkyung
        /// return Arc's area
554
        /// </summary>
555
        /// <author>humkyung</author>
556
        /// <date>2019.06.13</date>
557
        public override Rect ItemRect
558
        {
559
            get
560
            {
561
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
562
                dMinX = Math.Min(this.MidPoint.X, dMinX);
563
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
564
                dMinY = Math.Min(this.MidPoint.Y, dMinY);
565
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
566
                dMaxX = Math.Max(this.MidPoint.X, dMaxX);
567
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
568
                dMaxY = Math.Max(this.MidPoint.Y, dMaxY);
569
570
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
571
            }
572
        }
573
574
        /// <summary>
575 036650a0 humkyung
        /// Serialize this
576
        /// </summary>
577
        /// <param name="sUserId"></param>
578
        /// <returns></returns>
579
        public override string Serialize()
580
        {
581
            using (S_ArcControl STemp = new S_ArcControl())
582
            {
583
                STemp.TransformPoint = "0|0";
584
                STemp.PointSet = this.PointSet;
585
                STemp.SizeSet = String.Format("{0}", this.LineSize);
586
                //STemp.StrokeColor = "#FF000FFF";
587
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
588
                STemp.StartPoint = this.StartPoint;
589
                STemp.UserID = this.UserID;
590
                STemp.Opac = this.Opacity;
591
                STemp.MidPoint = this.MidPoint;
592
                STemp.EndPoint = this.EndPoint;
593
                STemp.IsTransOn = this.isTransOn;
594
                STemp.DashSize = this.DashSize;
595
                STemp.Clock = this.Clock;
596
                //STemp.ArcStyleSet = instance.ControlType;
597
                STemp.Name = this.GetType().Name.ToString();
598
599
                ///강인구 추가(2017.11.02)
600
                ///Memo 추가
601
                STemp.Memo = this.Memo;
602
603
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
604
            }
605
        }
606 661b7416 humkyung
607
        /// <summary>
608
        /// create a arccontrol from given string
609
        /// </summary>
610
        /// <param name="str"></param>
611
        /// <returns></returns>
612
        public static ArcControl FromString(string str, SolidColorBrush brush, string sProjectNo)
613
        {
614
            ArcControl instance = null;
615
            using (S_ArcControl s = JsonSerializerHelper.JsonDeserialize<S_ArcControl>(str))
616
            {
617
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
618
                instance = new ArcControl()
619
                {
620
                    StartPoint = s.StartPoint,
621
                    EndPoint = s.EndPoint,
622
                    DashSize = s.DashSize,
623
                    PointSet = s.PointSet,
624
                    isTransOn = s.IsTransOn,
625
                    MidPoint = s.MidPoint,
626
                    StrokeColor = brush,
627
                    Opacity = s.Opac,
628
                    Clock = s.Clock,
629
                    LineSize = Convert.ToDouble(data2.First()),
630
                    UserID = s.UserID,
631
                    Memo = s.Memo
632
                };
633
            }
634
635
            return instance;
636
        }
637 787a4489 KangIngu
    }
638
}
클립보드 이미지 추가 (최대 크기: 500 MB)