프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / LineControl.cs @ d251456f

이력 | 보기 | 이력해설 | 다운로드 (18.5 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, IDashControl
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 b3fb7321 ljiyeon
                "LineSize", typeof(double), typeof(LineControl), new PropertyMetadata((Double)3, PointValueChanged));
81 787a4489 KangIngu
82
        public static readonly DependencyProperty IntervalProperty = DependencyProperty.Register(
83 5ce56a3a KangIngu
                "Interval", typeof(double), typeof(LineControl), new PropertyMetadata((Double)10, PointValueChanged));
84 787a4489 KangIngu
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 5ce56a3a KangIngu
        public Double Interval
190 787a4489 KangIngu
        {
191 5ce56a3a KangIngu
            get { return (Double)GetValue(IntervalProperty); }
192 787a4489 KangIngu
            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
362
        public static List<LineGeometry> DimAllow(Point p1, Point p2, Double lineSize, double DimSize)
363
        {
364
            //lineSize = 2;
365
            List<LineGeometry> GeometrySet = new List<LineGeometry>();
366
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
367
368
369
            LineGeometry ld = new LineGeometry();
370
            //ld.StartPoint = new Point(p2.X + lineSize, p2.Y - lineSize * 4 - DimSize);
371
            //ld.EndPoint = new Point(p2.X + lineSize, p2.Y + lineSize * 4 + DimSize);
372
            ld.StartPoint = new Point(p2.X + lineSize, p2.Y - lineSize * 4);
373
            ld.EndPoint = new Point(p2.X + lineSize, p2.Y + lineSize * 4 + DimSize);
374
375
            RotateTransform transform3 = new RotateTransform();
376
            transform3.Angle = theta;
377
            transform3.CenterX = p2.X;
378
            transform3.CenterY = p2.Y;
379
            ld.Transform = transform3;
380
            GeometrySet.Add(ld);
381
382
            LineGeometry ld1 = new LineGeometry();
383
            //ld1.StartPoint = new Point(p1.X - lineSize, p1.Y - lineSize * 4 - DimSize);
384
            //ld1.EndPoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4 + DimSize);
385
            ld1.StartPoint = new Point(p1.X - lineSize, p1.Y - lineSize * 4);
386
            ld1.EndPoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4 + DimSize);
387
388
            RotateTransform transform4 = new RotateTransform();
389
            transform4.Angle = theta;
390
            transform4.CenterX = p1.X;
391
            transform4.CenterY = p1.Y;
392
            ld1.Transform = transform4;
393
            GeometrySet.Add(ld1);
394
            return GeometrySet;
395
        }
396
397
398
        public void ApplyOverViewData()
399
        {
400
            this.OverViewPathData = this.PathData;
401
        }
402
403
        public void SetLinePath()
404
        {
405
            this.ApplyTemplate();           
406
            if (this.DashSize != null)
407
            {
408
                Base_LinePath.StrokeDashArray.Clear();
409
                foreach (var item in this.DashSize)
410
                {
411
                    Base_LinePath.StrokeDashArray.Add(item);
412
                }
413
                Base_LinePath.StrokeDashCap = PenLineCap.Square;
414
            }
415
416
            PathFigure pathFigure = new PathFigure(); 
417
            pathFigure.StartPoint = this.StartPoint;
418
            LineSegment lineSegment0 = new LineSegment();
419
            lineSegment0.Point = this.EndPoint;
420
            pathFigure.Segments.Add(lineSegment0);
421
            PathGeometry pathGeometry = new PathGeometry();
422
            pathGeometry.Figures = new PathFigureCollection();
423
            pathGeometry.Figures.Add(pathFigure);
424
425
            
426
427
            instanceGroup.Children.Clear();
428
            switch (LineStyleSet)
429
            {
430
                case LineStyleSet.ArrowLine:
431 d251456f humkyung
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
432 787a4489 KangIngu
                    break;
433
                case LineStyleSet.TwinLine:
434 d251456f humkyung
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
435
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.EndPoint, this.StartPoint, this.LineSize));
436 787a4489 KangIngu
                    break;
437
                case LineStyleSet.DimLine:
438
                    List<LineGeometry> metrySet = DimAllow(this.StartPoint, this.EndPoint, this.LineSize, this.DimSize);
439
                    instanceGroup.Children.Add(metrySet[0]);
440
                    instanceGroup.Children.Add(metrySet[1]);
441 d251456f humkyung
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
442
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.EndPoint, this.StartPoint, this.LineSize));
443 787a4489 KangIngu
                    break;
444
                case LineStyleSet.CancelLine:
445
                    PathFigure pathFigure_Multi = new PathFigure();
446
                    LineSegment lineSegment1 = new LineSegment();
447
448
                    var x = Math.Abs((Math.Abs(this.StartPoint.X) - Math.Abs(this.EndPoint.X)));
449
                    var y = Math.Abs((Math.Abs(this.StartPoint.Y) - Math.Abs(this.EndPoint.Y)));
450
451
                    if (x > y)
452
                    {
453
                        pathFigure_Multi.StartPoint = new Point(this.StartPoint.X, this.StartPoint.Y + (this.Interval));
454
                        lineSegment1.Point = new Point(this.EndPoint.X, this.EndPoint.Y + (this.Interval));
455
                    }
456
                    else
457
                    {
458
                        pathFigure_Multi.StartPoint = new Point(this.StartPoint.X + (this.Interval), this.StartPoint.Y);
459
                        lineSegment1.Point = new Point(this.EndPoint.X + (this.Interval), this.EndPoint.Y);
460
                    }
461
                    pathFigure_Multi.Segments.Add(lineSegment1);
462
                    pathGeometry.Figures.Add(pathFigure_Multi);
463
464
                    this.PathData = pathGeometry;
465
                    this.OverViewPathData = PathData;
466
467
                    break;
468
                default:
469
                    break;
470
            }
471
            
472
473
            if (PathData != pathGeometry)
474
            {
475
                connectorGeometry.StartPoint = new Point(this.StartPoint.X, this.StartPoint.Y);
476
                connectorGeometry.EndPoint = new Point(this.EndPoint.X, this.EndPoint.Y);
477
478
                instanceGroup.Children.Add(connectorGeometry);
479
480
                this.PathData = instanceGroup;
481
                this.OverViewPathData = PathData;
482
            }
483
        }
484
    }
485
}
클립보드 이미지 추가 (최대 크기: 500 MB)