프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / LineControl.cs @ 036650a0

이력 | 보기 | 이력해설 | 다운로드 (19.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.S_Control;
16
using MarkupToPDF.Serialize.Core;
17

    
18
namespace MarkupToPDF.Controls.Line
19
{
20
    [TemplatePart(Name = "PART_LinePath", Type = typeof(Path))]
21
    public class LineControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
22
    {
23
        public event PropertyChangedEventHandler PropertyChanged;
24

    
25
        private const string PART_LinePath = "PART_LinePath";
26
        public Path Base_LinePath = null;
27

    
28
        static LineControl()
29
        {
30
            DefaultStyleKeyProperty.OverrideMetadata(typeof(LineControl), new FrameworkPropertyMetadata(typeof(LineControl)));
31
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
32
            ResourceDictionary dictionary = new ResourceDictionary();
33

    
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 double DimSize
40
        {
41
            get { return (double)GetValue(DimSizeProperty); }
42
            set
43
            {
44
                if (this.DimSize != value)
45
                {
46
                    SetValue(DimSizeProperty, value);
47
                    OnPropertyChanged("DimSize");
48
                }
49
            }
50
        }
51

    
52
        public LineControl()
53
        {
54
            this.DefaultStyleKey = typeof(LineControl);
55
        }
56

    
57
        public void Dispose()
58
        {
59
            GC.Collect();
60
            GC.SuppressFinalize(this);
61
        }
62
        protected void OnPropertyChanged(string propName)
63
        {
64
            if (PropertyChanged != null)
65
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
66
        }
67
        #region Dependency Properties
68

    
69
        public static readonly DependencyProperty IsSelectedProperty =
70
     DependencyProperty.Register("IsSelected", typeof(bool), typeof(LineControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
71

    
72
        public static readonly DependencyProperty ControlTypeProperty =
73
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(LineControl), new FrameworkPropertyMetadata(ControlType.SingleLine));
74

    
75
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
76
                "OverViewPathData", typeof(Geometry), typeof(LineControl), new PropertyMetadata(null));
77

    
78
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
79
                "UserID", typeof(string), typeof(LineControl), new PropertyMetadata(null));
80

    
81
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
82
                "LineSize", typeof(double), typeof(LineControl), new PropertyMetadata((Double)3, PointValueChanged));
83

    
84
        public static readonly DependencyProperty IntervalProperty = DependencyProperty.Register(
85
                "Interval", typeof(double), typeof(LineControl), new PropertyMetadata((Double)10, PointValueChanged));
86

    
87
//강인구 추가
88
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
89
                "DashSize", typeof(DoubleCollection), typeof(LineControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
90
        //public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
91
        //        "DashSize", typeof(DoubleCollection), typeof(LineControl), new PropertyMetadata(new DoubleCollection { 1, 1 }));
92

    
93
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
94
               "StrokeColor", typeof(SolidColorBrush), typeof(LineControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
95

    
96
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
97
              "PathData", typeof(Geometry), typeof(LineControl), null);
98

    
99
        public static readonly DependencyProperty LineStyleProperty = DependencyProperty.Register(
100
               "LineStyleSet", typeof(LineStyleSet), typeof(LineControl), new PropertyMetadata(LineStyleSet.SingleLine));
101

    
102
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
103
               "StartPoint", typeof(Point), typeof(LineControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
104

    
105
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
106
               "EndPoint", typeof(Point), typeof(LineControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
107

    
108
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
109
                "PointSet", typeof(List<Point>), typeof(LineControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
110
        
111
        
112
        public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register(
113
                "MiddlePoint", typeof(Point), typeof(LineControl), new PropertyMetadata(new Point(0, 0)));
114
        public static readonly DependencyProperty DimSizeProperty = DependencyProperty.Register(
115
                "DimSize", typeof(double), typeof(LineControl), new PropertyMetadata((double)5));
116

    
117
        public static readonly DependencyProperty AngleProperty =
118
            DependencyProperty.Register("AngleValue", typeof(double), typeof(LineControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
119

    
120
        public static readonly DependencyProperty CenterXProperty =
121
            DependencyProperty.Register("CenterX", typeof(double), typeof(LineControl), new PropertyMetadata((double)0, OnCenterXYChanged));
122

    
123
        public static readonly DependencyProperty CenterYProperty =
124
            DependencyProperty.Register("CenterY", typeof(double), typeof(LineControl), new PropertyMetadata((double)0, OnCenterXYChanged));
125
        #endregion
126
        #region PropertyChanged Method
127

    
128
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
129
        {
130
            //var instance = (LineControl)sender;
131

    
132
            //if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
133
            //{
134

    
135
            //    instance.SetValue(e.Property, e.NewValue);
136

    
137
            //    if (instance.IsSelected)
138
            //    {
139
            //        instance.Base_LinePath.Stroke = new SolidColorBrush(Colors.Blue);
140
            //    }
141
            //    else
142
            //    {
143
            //        instance.Base_LinePath.Stroke = new SolidColorBrush(Colors.Red); 
144
            //    }
145
            //}
146
        }
147

    
148
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
149
        {
150
            var instance = (LineControl)sender;
151
            if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
152
            {
153
                instance.SetValue(e.Property, e.NewValue);
154
                instance.SetLinePath();
155
            }
156
        }
157
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
158
        {
159
            var instance = (LineControl)sender;
160
            if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
161
            {
162
                instance.SetValue(e.Property, e.NewValue);
163
                instance.SetLinePath();
164
            }
165
        }
166
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
167
        {
168
            var instance = (LineControl)sender;
169
            if (e.OldValue != e.NewValue && instance.Base_LinePath != null)
170
            {
171
                instance.SetValue(e.Property, e.NewValue);
172
                instance.SetLinePath();
173
            }
174
        }
175

    
176
        #endregion
177
        #region Properties
178
        public string UserID
179
        {
180
            get { return (string)GetValue(UserIDProperty); }
181
            set
182
            {
183
                if (this.UserID != value)
184
                {
185
                    SetValue(UserIDProperty, value);
186
                    OnPropertyChanged("UserID");
187
                }
188
            }
189
        }
190

    
191
        public Double Interval
192
        {
193
            get { return (Double)GetValue(IntervalProperty); }
194
            set
195
            {
196
                if (this.Interval != value)
197
                {
198
                    SetValue(IntervalProperty, value);
199
                    OnPropertyChanged("Interval");
200
                }
201
            }
202
        }
203
        public Double LineSize
204
        {
205
            get { return (Double)GetValue(LineSizeProperty); }
206
            set
207
            {
208
                if (this.LineSize != value)
209
                {
210
                    SetValue(LineSizeProperty, value);
211
                }
212
            }
213
        }
214
        public DoubleCollection DashSize
215
        {
216
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
217
            set
218
            {
219
                if (this.DashSize != value)
220
                {
221
                    SetValue(DashSizeProperty, value);
222
                }
223
            }
224
        }
225
        public List<Point> PointSet
226
        {
227
            get { return (List<Point>)GetValue(PointSetProperty); }
228
            set { SetValue(PointSetProperty, value); }
229
        }
230
        public double CenterX
231
        {
232
            get { return (double)GetValue(CenterXProperty); }
233
            set { SetValue(CenterXProperty, value); }
234
        }
235
        public double CenterY
236
        {
237
            get { return (double)GetValue(CenterYProperty); }
238
            set { SetValue(CenterYProperty, value); }
239
        }
240
        public SolidColorBrush StrokeColor
241
        {
242
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
243
            set
244
            {
245
                if (this.StrokeColor != value)
246
                {
247
                    SetValue(StrokeColorProperty, value);
248
                }
249
            }
250
        }
251

    
252

    
253
        public Geometry PathData
254
        {
255
            get { return (Geometry)GetValue(PathDataProperty); }
256
            set
257
            {
258
                SetValue(PathDataProperty, value);
259
                OnPropertyChanged("PathData");
260
            }
261
        }
262

    
263

    
264

    
265
        public Geometry OverViewPathData
266
        {
267
            get
268
            {
269
                return (Geometry)GetValue(OverViewPathDataProperty);
270
            }
271
            set
272
            {
273
                SetValue(OverViewPathDataProperty, value);
274
                OnPropertyChanged("OverViewPathData");
275
            }
276
        }
277

    
278
        public bool IsSelected
279
        {
280
            get
281
            {
282
                return (bool)GetValue(IsSelectedProperty);
283
            }
284
            set
285
            {
286
                SetValue(IsSelectedProperty, value);
287
            }
288
        }
289

    
290
        public LineStyleSet LineStyleSet
291
        {
292
            get
293
            {
294
                return (LineStyleSet)GetValue(LineStyleProperty);
295
            }
296
            set
297
            {
298
                SetValue(LineStyleProperty, value);
299
            }
300
        }
301

    
302
        override public ControlType ControlType
303
        {
304
            get
305
            {
306
                return (ControlType)GetValue(ControlTypeProperty);
307
            }
308
            set
309
            {
310
                SetValue(ControlTypeProperty, value);
311
            }
312
        }
313

    
314
        public double AngleValue
315
        {
316
            get { return (double)GetValue(AngleProperty); }
317
            set { SetValue(AngleProperty, value); }
318
        }
319
        public double Angle
320
        {
321
            get { return (double)GetValue(AngleProperty); }
322
            set
323
            {
324
                if (this.Angle != value)
325
                {
326
                    SetValue(AngleProperty, value);
327
                }
328
            }
329
        }
330
        public Point EndPoint
331
        {
332
            get { return (Point)GetValue(EndPointProperty); }
333
            set
334
            {
335
                SetValue(EndPointProperty, value);
336
                OnPropertyChanged("EndPoint");
337
            }
338
        }
339
        public Point StartPoint
340
        {
341
            get { return (Point)GetValue(StartPointProperty); }
342
            set
343
            {
344
                SetValue(StartPointProperty, value);
345
                OnPropertyChanged("StartPoint");
346
            }
347
        }
348
        GeometryGroup instanceGroup = new GeometryGroup();
349
        LineGeometry connectorGeometry = new LineGeometry();
350

    
351
        #endregion
352
        public override void OnApplyTemplate()
353
        {
354
            base.OnApplyTemplate();
355
            Base_LinePath = GetTemplateChild("PART_LinePath") as Path;
356
            SetLinePath();
357
        }
358
        public void updateControl()
359
        {
360
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
361
            this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
362
        }
363

    
364
        public static List<LineGeometry> DimAllow(Point p1, Point p2, Double lineSize, double DimSize)
365
        {
366
            //lineSize = 2;
367
            List<LineGeometry> GeometrySet = new List<LineGeometry>();
368
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
369

    
370

    
371
            LineGeometry ld = new LineGeometry();
372
            //ld.StartPoint = new Point(p2.X + lineSize, p2.Y - lineSize * 4 - DimSize);
373
            //ld.EndPoint = new Point(p2.X + lineSize, p2.Y + lineSize * 4 + DimSize);
374
            ld.StartPoint = new Point(p2.X + lineSize, p2.Y - lineSize * 4);
375
            ld.EndPoint = new Point(p2.X + lineSize, p2.Y + lineSize * 4 + DimSize);
376

    
377
            RotateTransform transform3 = new RotateTransform();
378
            transform3.Angle = theta;
379
            transform3.CenterX = p2.X;
380
            transform3.CenterY = p2.Y;
381
            ld.Transform = transform3;
382
            GeometrySet.Add(ld);
383

    
384
            LineGeometry ld1 = new LineGeometry();
385
            //ld1.StartPoint = new Point(p1.X - lineSize, p1.Y - lineSize * 4 - DimSize);
386
            //ld1.EndPoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4 + DimSize);
387
            ld1.StartPoint = new Point(p1.X - lineSize, p1.Y - lineSize * 4);
388
            ld1.EndPoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4 + DimSize);
389

    
390
            RotateTransform transform4 = new RotateTransform();
391
            transform4.Angle = theta;
392
            transform4.CenterX = p1.X;
393
            transform4.CenterY = p1.Y;
394
            ld1.Transform = transform4;
395
            GeometrySet.Add(ld1);
396
            return GeometrySet;
397
        }
398

    
399

    
400
        public void ApplyOverViewData()
401
        {
402
            this.OverViewPathData = this.PathData;
403
        }
404

    
405
        public void SetLinePath()
406
        {
407
            this.ApplyTemplate();           
408
            if (this.DashSize != null)
409
            {
410
                Base_LinePath.StrokeDashArray.Clear();
411
                foreach (var item in this.DashSize)
412
                {
413
                    Base_LinePath.StrokeDashArray.Add(item);
414
                }
415
                Base_LinePath.StrokeDashCap = PenLineCap.Square;
416
            }
417

    
418
            PathFigure pathFigure = new PathFigure(); 
419
            pathFigure.StartPoint = this.StartPoint;
420
            LineSegment lineSegment0 = new LineSegment();
421
            lineSegment0.Point = this.EndPoint;
422
            pathFigure.Segments.Add(lineSegment0);
423
            PathGeometry pathGeometry = new PathGeometry();
424
            pathGeometry.Figures = new PathFigureCollection();
425
            pathGeometry.Figures.Add(pathFigure);
426

    
427
            
428

    
429
            instanceGroup.Children.Clear();
430
            switch (LineStyleSet)
431
            {
432
                case LineStyleSet.ArrowLine:
433
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
434
                    break;
435
                case LineStyleSet.TwinLine:
436
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
437
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.EndPoint, this.StartPoint, this.LineSize));
438
                    break;
439
                case LineStyleSet.DimLine:
440
                    List<LineGeometry> metrySet = DimAllow(this.StartPoint, this.EndPoint, this.LineSize, this.DimSize);
441
                    instanceGroup.Children.Add(metrySet[0]);
442
                    instanceGroup.Children.Add(metrySet[1]);
443
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
444
                    instanceGroup.Children.Add(DrawSet.DrawArrow(this.EndPoint, this.StartPoint, this.LineSize));
445
                    break;
446
                case LineStyleSet.CancelLine:
447
                    PathFigure pathFigure_Multi = new PathFigure();
448
                    LineSegment lineSegment1 = new LineSegment();
449

    
450
                    var x = Math.Abs((Math.Abs(this.StartPoint.X) - Math.Abs(this.EndPoint.X)));
451
                    var y = Math.Abs((Math.Abs(this.StartPoint.Y) - Math.Abs(this.EndPoint.Y)));
452

    
453
                    if (x > y)
454
                    {
455
                        pathFigure_Multi.StartPoint = new Point(this.StartPoint.X, this.StartPoint.Y + (this.Interval));
456
                        lineSegment1.Point = new Point(this.EndPoint.X, this.EndPoint.Y + (this.Interval));
457
                    }
458
                    else
459
                    {
460
                        pathFigure_Multi.StartPoint = new Point(this.StartPoint.X + (this.Interval), this.StartPoint.Y);
461
                        lineSegment1.Point = new Point(this.EndPoint.X + (this.Interval), this.EndPoint.Y);
462
                    }
463
                    pathFigure_Multi.Segments.Add(lineSegment1);
464
                    pathGeometry.Figures.Add(pathFigure_Multi);
465

    
466
                    this.PathData = pathGeometry;
467
                    this.OverViewPathData = PathData;
468

    
469
                    break;
470
                default:
471
                    break;
472
            }
473
            
474

    
475
            if (PathData != pathGeometry)
476
            {
477
                connectorGeometry.StartPoint = new Point(this.StartPoint.X, this.StartPoint.Y);
478
                connectorGeometry.EndPoint = new Point(this.EndPoint.X, this.EndPoint.Y);
479

    
480
                instanceGroup.Children.Add(connectorGeometry);
481

    
482
                this.PathData = instanceGroup;
483
                this.OverViewPathData = PathData;
484
            }
485
        }
486

    
487
        /// <summary>
488
        /// Serialize this
489
        /// </summary>
490
        /// <param name="sUserId"></param>
491
        /// <returns></returns>
492
        public override string Serialize()
493
        {
494
            using (S_LineControl STemp = new S_LineControl())
495
            {
496
                STemp.TransformPoint = "0|0";
497
                STemp.PointSet = this.PointSet;
498
                STemp.SizeSet = String.Format("{0}", this.LineSize);
499
                STemp.LineStyleSet = this.LineStyleSet;
500
                //STemp.StrokeColor = "#FF00FF00";
501
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
502
                STemp.StartPoint = this.StartPoint;
503
                STemp.EndPoint = this.EndPoint;
504
                STemp.UserID = this.UserID;
505
                STemp.Opac = this.Opacity;
506
                STemp.DashSize = this.DashSize;
507
                STemp.Interval = this.Interval;
508
                STemp.DimSize = this.DimSize;
509
                STemp.Name = this.GetType().Name.ToString();
510

    
511
                ///강인구 추가(2017.11.02)
512
                ///Memo 추가
513
                STemp.Memo = this.Memo;
514

    
515
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
516
            }
517
        }
518
    }
519
}
클립보드 이미지 추가 (최대 크기: 500 MB)