프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / LineControl.cs.bak @ ac4f1e13

이력 | 보기 | 이력해설 | 다운로드 (21.2 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
16
namespace MarkupToPDF.Controls.Line
17
{
18
    [TemplatePart(Name = "PART_LinePath", Type = typeof(Path))]
19
    public class LineControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IPath
20
    {
21
        public event PropertyChangedEventHandler PropertyChanged;
22
23
        private const string PART_LinePath = "PART_LinePath";
24
        public Path Base_LinePath = null;
25
26
        static LineControl()
27
        {
28
            DefaultStyleKeyProperty.OverrideMetadata(typeof(LineControl), new FrameworkPropertyMetadata(typeof(LineControl)));
29
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
30
            ResourceDictionary dictionary = new ResourceDictionary();
31
32
            dictionary.Source = new Uri("/MarkupToPDF;component/Themes/generic.xaml", UriKind.RelativeOrAbsolute);
33
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
34
             //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
35
                     }
36
37
        public double DimSize
38
        {
39
            get { return (double)GetValue(DimSizeProperty); }
40
            set
41
            {
42
                if (this.DimSize != value)
43
                {
44
                    SetValue(DimSizeProperty, value);
45
                    OnPropertyChanged("DimSize");
46
                }
47
            }
48
        }
49
50
        public LineControl()
51
        {
52
            this.DefaultStyleKey = typeof(LineControl);
53
        }
54
55
        public void Dispose()
56
        {
57
            GC.Collect();
58
            GC.SuppressFinalize(this);
59
        }
60
        protected void OnPropertyChanged(string propName)
61
        {
62
            if (PropertyChanged != null)
63
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
64
        }
65
        #region Dependency Properties
66
67
        public static readonly DependencyProperty IsSelectedProperty =
68
     DependencyProperty.Register("IsSelected", typeof(bool), typeof(LineControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
69
70
        public static readonly DependencyProperty ControlTypeProperty =
71
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(LineControl), new FrameworkPropertyMetadata(ControlType.SingleLine));
72
73
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
74
                "OverViewPathData", typeof(Geometry), typeof(LineControl), new PropertyMetadata(null));
75
76
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
77
                "UserID", typeof(string), typeof(LineControl), new PropertyMetadata(null));
78
79
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
80
                "LineSize", typeof(double), typeof(LineControl), new PropertyMetadata((Double)3));
81
82
        public static readonly DependencyProperty IntervalProperty = DependencyProperty.Register(
83
                "Interval", typeof(double), typeof(LineControl), new PropertyMetadata((double)10));
84
85
//강인구 추가
86
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
87
                "DashSize", typeof(DoubleCollection), typeof(LineControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
88
        //public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
89
        //        "DashSize", typeof(DoubleCollection), typeof(LineControl), new PropertyMetadata(new DoubleCollection { 1, 1 }));
90
91
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
92
               "StrokeColor", typeof(SolidColorBrush), typeof(LineControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
93
94
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
95
              "PathData", typeof(Geometry), typeof(LineControl), null);
96
97
        public static readonly DependencyProperty LineStyleProperty = DependencyProperty.Register(
98
               "LineStyleSet", typeof(LineStyleSet), typeof(LineControl), new PropertyMetadata(LineStyleSet.SingleLine));
99
100
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
101
               "StartPoint", typeof(Point), typeof(LineControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
102
103
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
104
               "EndPoint", typeof(Point), typeof(LineControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
105
106
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
107
                "PointSet", typeof(List<Point>), typeof(LineControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
108
        
109
        
110
        public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register(
111
                "MiddlePoint", typeof(Point), typeof(LineControl), new PropertyMetadata(new Point(0, 0)));
112
        public static readonly DependencyProperty DimSizeProperty = DependencyProperty.Register(
113
                "DimSize", typeof(double), typeof(LineControl), new PropertyMetadata((double)5));
114
115
        public static readonly DependencyProperty AngleProperty =
116
            DependencyProperty.Register("AngleValue", typeof(double), typeof(LineControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
117
118
        public static readonly DependencyProperty CenterXProperty =
119
            DependencyProperty.Register("CenterX", typeof(double), typeof(LineControl), new PropertyMetadata((double)0, OnCenterXYChanged));
120
121
        public static readonly DependencyProperty CenterYProperty =
122
            DependencyProperty.Register("CenterY", typeof(double), typeof(LineControl), new PropertyMetadata((double)0, OnCenterXYChanged));
123
        #endregion
124
        #region PropertyChanged Method
125
126
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
127
        {
128
            //var instance = (LineControl)sender;
129
130
            //if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
131
            //{
132
133
            //    instance.SetValue(e.Property, e.NewValue);
134
135
            //    if (instance.IsSelected)
136
            //    {
137
            //        instance.Base_LinePath.Stroke = new SolidColorBrush(Colors.Blue);
138
            //    }
139
            //    else
140
            //    {
141
            //        instance.Base_LinePath.Stroke = new SolidColorBrush(Colors.Red); 
142
            //    }
143
            //}
144
        }
145
146
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
147
        {
148
            var instance = (LineControl)sender;
149
            if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
150
            {
151
                instance.SetValue(e.Property, e.NewValue);
152
                instance.SetLinePath();
153
            }
154
        }
155
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
156
        {
157
            var instance = (LineControl)sender;
158
            if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
159
            {
160
                instance.SetValue(e.Property, e.NewValue);
161
                instance.SetLinePath();
162
            }
163
        }
164
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
165
        {
166
            var instance = (LineControl)sender;
167
            if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
168
            {
169
                instance.SetValue(e.Property, e.NewValue);
170
                instance.SetLinePath();
171
            }
172
        }
173
174
        #endregion
175
        #region Properties
176
        public string UserID
177
        {
178
            get { return (string)GetValue(UserIDProperty); }
179
            set
180
            {
181
                if (this.UserID != value)
182
                {
183
                    SetValue(UserIDProperty, value);
184
                    OnPropertyChanged("UserID");
185
                }
186
            }
187
        }
188
189
        public double Interval
190
        {
191
            get { return (double)GetValue(IntervalProperty); }
192
            set
193
            {
194
                if (this.Interval != value)
195
                {
196
                    SetValue(IntervalProperty, value);
197
                    OnPropertyChanged("Interval");
198
                }
199
            }
200
        }
201
        public Double LineSize
202
        {
203
            get { return (Double)GetValue(LineSizeProperty); }
204
            set
205
            {
206
                if (this.LineSize != value)
207
                {
208
                    SetValue(LineSizeProperty, value);
209
                }
210
            }
211
        }
212
        public DoubleCollection DashSize
213
        {
214
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
215
            set
216
            {
217
                if (this.DashSize != value)
218
                {
219
                    SetValue(DashSizeProperty, value);
220
                }
221
            }
222
        }
223
        public List<Point> PointSet
224
        {
225
            get { return (List<Point>)GetValue(PointSetProperty); }
226
            set { SetValue(PointSetProperty, value); }
227
        }
228
        public double CenterX
229
        {
230
            get { return (double)GetValue(CenterXProperty); }
231
            set { SetValue(CenterXProperty, value); }
232
        }
233
        public double CenterY
234
        {
235
            get { return (double)GetValue(CenterYProperty); }
236
            set { SetValue(CenterYProperty, value); }
237
        }
238
        public SolidColorBrush StrokeColor
239
        {
240
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
241
            set
242
            {
243
                if (this.StrokeColor != value)
244
                {
245
                    SetValue(StrokeColorProperty, value);
246
                }
247
            }
248
        }
249
250
251
        public Geometry PathData
252
        {
253
            get { return (Geometry)GetValue(PathDataProperty); }
254
            set
255
            {
256
                SetValue(PathDataProperty, value);
257
                OnPropertyChanged("PathData");
258
            }
259
        }
260
261
262
263
        public Geometry OverViewPathData
264
        {
265
            get
266
            {
267
                return (Geometry)GetValue(OverViewPathDataProperty);
268
            }
269
            set
270
            {
271
                SetValue(OverViewPathDataProperty, value);
272
                OnPropertyChanged("OverViewPathData");
273
            }
274
        }
275
276
        public bool IsSelected
277
        {
278
            get
279
            {
280
                return (bool)GetValue(IsSelectedProperty);
281
            }
282
            set
283
            {
284
                SetValue(IsSelectedProperty, value);
285
            }
286
        }
287
288
        public LineStyleSet LineStyleSet
289
        {
290
            get
291
            {
292
                return (LineStyleSet)GetValue(LineStyleProperty);
293
            }
294
            set
295
            {
296
                SetValue(LineStyleProperty, value);
297
            }
298
        }
299
300
        public ControlType ControlType
301
        {
302
            get
303
            {
304
                return (ControlType)GetValue(ControlTypeProperty);
305
            }
306
            set
307
            {
308
                SetValue(ControlTypeProperty, value);
309
            }
310
        }
311
312
        public double AngleValue
313
        {
314
            get { return (double)GetValue(AngleProperty); }
315
            set { SetValue(AngleProperty, value); }
316
        }
317
        public double Angle
318
        {
319
            get { return (double)GetValue(AngleProperty); }
320
            set
321
            {
322
                if (this.Angle != value)
323
                {
324
                    SetValue(AngleProperty, value);
325
                }
326
            }
327
        }
328
        public Point EndPoint
329
        {
330
            get { return (Point)GetValue(EndPointProperty); }
331
            set
332
            {
333
                SetValue(EndPointProperty, value);
334
                OnPropertyChanged("EndPoint");
335
            }
336
        }
337
        public Point StartPoint
338
        {
339
            get { return (Point)GetValue(StartPointProperty); }
340
            set
341
            {
342
                SetValue(StartPointProperty, value);
343
                OnPropertyChanged("StartPoint");
344
            }
345
        }
346
        GeometryGroup instanceGroup = new GeometryGroup();
347
        LineGeometry connectorGeometry = new LineGeometry();
348
349
        #endregion
350
        public override void OnApplyTemplate()
351
        {
352
            base.OnApplyTemplate();
353
            Base_LinePath = GetTemplateChild("PART_LinePath") as Path;
354
            SetLinePath();
355
        }
356
        public void updateControl()
357
        {
358
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
359
            this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
360
        }
361
        public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize)
362
        {
363
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
364
            PathGeometry pathGeometry = new PathGeometry();
365
            PathFigure pathFigure = new PathFigure();
366
            pathFigure.StartPoint = new Point(p1.X, p1.Y);
367
            //lineSize = 2;
368
            Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
369
            Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
370
            LineSegment seg1 = new LineSegment();
371
            seg1.Point = lpoint;
372
            pathFigure.Segments.Add(seg1);
373
            LineSegment seg2 = new LineSegment();
374
            seg2.Point = rpoint;
375
            pathFigure.Segments.Add(seg2);
376
377
            LineSegment seg3 = new LineSegment();
378
            seg3.Point = p1;
379
            pathFigure.Segments.Add(seg3);
380
381
            pathFigure.IsClosed = true;
382
            pathFigure.IsFilled = true;
383
            pathGeometry.Figures.Add(pathFigure);
384
            pathGeometry.FillRule = FillRule.Nonzero;
385
            RotateTransform transform = new RotateTransform();
386
            transform.Angle = theta - 90;
387
            transform.CenterX = p1.X;
388
            transform.CenterY = p1.Y;
389
            pathGeometry.Transform = transform;
390
            return pathGeometry;
391
        }
392
393
394
        public static PathGeometry ConverseAllow(Point p2, Point p1, double lineSize)
395
        {
396
            //lineSize = 2;
397
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
398
            PathGeometry pathGeometry2 = new PathGeometry();
399
            PathFigure pathFigure2 = new PathFigure();
400
            pathFigure2.StartPoint = p2;
401
402
            Point lpoint2 = new Point(p2.X + lineSize * 3, p2.Y + lineSize * 6);
403
            Point rpoint2 = new Point(p2.X - lineSize * 3, p2.Y + lineSize * 6);
404
            LineSegment seg1_1 = new LineSegment();
405
            seg1_1.Point = lpoint2;
406
            pathFigure2.Segments.Add(seg1_1);
407
408
            LineSegment seg2_1 = new LineSegment();
409
            seg2_1.Point = rpoint2;
410
            pathFigure2.Segments.Add(seg2_1);
411
412
            LineSegment seg3_1 = new LineSegment();
413
            seg3_1.Point = p2;
414
            pathFigure2.Segments.Add(seg3_1);
415
416
            LineSegment seg4_1 = new LineSegment();
417
418
            seg4_1.Point = new Point(lpoint2.X, lpoint2.Y);
419
            pathFigure2.Segments.Add(seg4_1);
420
            RotateTransform transform2 = new RotateTransform();
421
            transform2.Angle = theta + 90;
422
            transform2.CenterX = p2.X;
423
            transform2.CenterY = p2.Y;
424
            pathGeometry2.Figures.Add(pathFigure2);
425
            pathGeometry2.Transform = transform2;
426
            return pathGeometry2;
427
        }
428
        public static List<LineGeometry> DimAllow(Point p1, Point p2, Double lineSize, double DimSize)
429
        {
430
            //lineSize = 2;
431
            List<LineGeometry> GeometrySet = new List<LineGeometry>();
432
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
433
434
435
            LineGeometry ld = new LineGeometry();
436
            //ld.StartPoint = new Point(p2.X + lineSize, p2.Y - lineSize * 4 - DimSize);
437
            //ld.EndPoint = new Point(p2.X + lineSize, p2.Y + lineSize * 4 + DimSize);
438
            ld.StartPoint = new Point(p2.X + lineSize, p2.Y - lineSize * 4);
439
            ld.EndPoint = new Point(p2.X + lineSize, p2.Y + lineSize * 4 + DimSize);
440
441
            RotateTransform transform3 = new RotateTransform();
442
            transform3.Angle = theta;
443
            transform3.CenterX = p2.X;
444
            transform3.CenterY = p2.Y;
445
            ld.Transform = transform3;
446
            GeometrySet.Add(ld);
447
448
            LineGeometry ld1 = new LineGeometry();
449
            //ld1.StartPoint = new Point(p1.X - lineSize, p1.Y - lineSize * 4 - DimSize);
450
            //ld1.EndPoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4 + DimSize);
451
            ld1.StartPoint = new Point(p1.X - lineSize, p1.Y - lineSize * 4);
452
            ld1.EndPoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4 + DimSize);
453
454
            RotateTransform transform4 = new RotateTransform();
455
            transform4.Angle = theta;
456
            transform4.CenterX = p1.X;
457
            transform4.CenterY = p1.Y;
458
            ld1.Transform = transform4;
459
            GeometrySet.Add(ld1);
460
            return GeometrySet;
461
        }
462
463
464
        public void ApplyOverViewData()
465
        {
466
            this.OverViewPathData = this.PathData;
467
        }
468
469
        public void SetLinePath()
470
        {
471
            this.ApplyTemplate();           
472
            if (this.DashSize != null)
473
            {
474
                Base_LinePath.StrokeDashArray.Clear();
475
                foreach (var item in this.DashSize)
476
                {
477
                    Base_LinePath.StrokeDashArray.Add(item);
478
                }
479
                Base_LinePath.StrokeDashCap = PenLineCap.Square;
480
            }
481
482
            PathFigure pathFigure = new PathFigure(); 
483
            pathFigure.StartPoint = this.StartPoint;
484
            LineSegment lineSegment0 = new LineSegment();
485
            lineSegment0.Point = this.EndPoint;
486
            pathFigure.Segments.Add(lineSegment0);
487
            PathGeometry pathGeometry = new PathGeometry();
488
            pathGeometry.Figures = new PathFigureCollection();
489
            pathGeometry.Figures.Add(pathFigure);
490
491
            
492
493
            instanceGroup.Children.Clear();
494
            switch (LineStyleSet)
495
            {
496
                case LineStyleSet.ArrowLine:
497
                    instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.EndPoint, this.LineSize));
498
                    break;
499
                case LineStyleSet.TwinLine:
500
                    instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.EndPoint, this.LineSize));
501
                    instanceGroup.Children.Add(ConverseAllow(this.StartPoint, this.EndPoint, this.LineSize));
502
                    break;
503
                case LineStyleSet.DimLine:
504
                    List<LineGeometry> metrySet = DimAllow(this.StartPoint, this.EndPoint, this.LineSize, this.DimSize);
505
                    instanceGroup.Children.Add(metrySet[0]);
506
                    instanceGroup.Children.Add(metrySet[1]);
507
                    instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.EndPoint, this.LineSize));
508
                    instanceGroup.Children.Add(ConverseAllow(this.StartPoint, this.EndPoint, this.LineSize));
509
                    break;
510
                case LineStyleSet.CancelLine:
511
                    PathFigure pathFigure_Multi = new PathFigure();
512
                    LineSegment lineSegment1 = new LineSegment();
513
514
                    var x = Math.Abs((Math.Abs(this.StartPoint.X) - Math.Abs(this.EndPoint.X)));
515
                    var y = Math.Abs((Math.Abs(this.StartPoint.Y) - Math.Abs(this.EndPoint.Y)));
516
517
                    if (x > y)
518
                    {
519
                        pathFigure_Multi.StartPoint = new Point(this.StartPoint.X, this.StartPoint.Y + (this.Interval));
520
                        lineSegment1.Point = new Point(this.EndPoint.X, this.EndPoint.Y + (this.Interval));
521
                    }
522
                    else
523
                    {
524
                        pathFigure_Multi.StartPoint = new Point(this.StartPoint.X + (this.Interval), this.StartPoint.Y);
525
                        lineSegment1.Point = new Point(this.EndPoint.X + (this.Interval), this.EndPoint.Y);
526
                    }
527
                    pathFigure_Multi.Segments.Add(lineSegment1);
528
                    pathGeometry.Figures.Add(pathFigure_Multi);
529
530
                    
531
532
                    this.PathData = pathGeometry;
533
                    this.OverViewPathData = PathData;
534
535
                    break;
536
                default:
537
                    break;
538
            }
539
            
540
541
            if (PathData != pathGeometry)
542
            {
543
                connectorGeometry.StartPoint = new Point(this.StartPoint.X, this.StartPoint.Y);
544
                connectorGeometry.EndPoint = new Point(this.EndPoint.X, this.EndPoint.Y);
545
546
                instanceGroup.Children.Add(connectorGeometry);
547
548
                this.PathData = instanceGroup;
549
                this.OverViewPathData = PathData;
550
            }
551
        }
552
    }
553
}
클립보드 이미지 추가 (최대 크기: 500 MB)