프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowControl_Multi.cs @ d5e3aa15

이력 | 보기 | 이력해설 | 다운로드 (18.6 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
using System.Linq;
18

    
19
namespace MarkupToPDF.Controls.Line
20
{
21
    public class ArrowControl_Multi : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
22
    {
23

    
24
        public event PropertyChangedEventHandler PropertyChanged;
25
        private const string PART_ArrowMultiPath = "PART_ArrowMultiPath";
26
        public Path Base_ArrowMultiPath = null;
27

    
28
        static ArrowControl_Multi()
29
        {
30
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(typeof(ArrowControl_Multi)));
31
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
32
            //ResourceDictionary dictionary = new ResourceDictionary();
33
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
34
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
35
            //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
36
        }
37

    
38
        public ArrowControl_Multi()
39
        {
40
            //this.DefaultStyleKey = typeof(ArrowControl_Multi);
41
        }
42
      
43
        #region Dependency Properties
44

    
45
        public static readonly DependencyProperty IsSelectedProperty =
46
DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(false, IsSelectedChanged));
47

    
48
        public static readonly DependencyProperty ControlTypeProperty =
49
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(ControlType.ArrowMultiLine));
50

    
51
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
52
                "OverViewPathData", typeof(Geometry), typeof(ArrowControl_Multi), new PropertyMetadata(null));
53

    
54
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
55
                "UserID", typeof(string), typeof(ArrowControl_Multi), new PropertyMetadata(null));
56
				
57
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
58
              "LineSize", typeof(double), typeof(ArrowControl_Multi), new PropertyMetadata((Double)3, PointValueChanged));
59

    
60
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
61
               "DashSize", typeof(DoubleCollection), typeof(ArrowControl_Multi), new PropertyMetadata(new DoubleCollection { 99999099 }, PointValueChanged));
62

    
63
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
64
              "StrokeColor", typeof(SolidColorBrush), typeof(ArrowControl_Multi), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
65

    
66
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
67
              "PathData", typeof(Geometry), typeof(ArrowControl_Multi), null);
68

    
69
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
70
               "StartPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
71

    
72
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
73
               "EndPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(100, 100), PointValueChanged));
74
        public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register(
75
                "MiddlePoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
76

    
77
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
78
               "PointSet", typeof(List<Point>), typeof(ArrowControl_Multi), new PropertyMetadata(new List<Point>(), PointValueChanged));
79
        #endregion
80
        #region PropertyChanged Method
81

    
82
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
83
        {
84
            //var instance = (ArrowControl_Multi)sender;
85

    
86
            //if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
87
            //{
88

    
89
            //    instance.SetValue(e.Property, e.NewValue);
90

    
91
            //    if (instance.IsSelected)
92
            //    {
93
            //        instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue);
94
            //    }
95
            //    else
96
            //    {
97
            //        instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red);
98
            //    }
99
            //}
100
        }
101

    
102

    
103
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
104
        {
105
            var instance = (ArrowControl_Multi)sender;
106
            if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
107
            {
108
                instance.SetValue(e.Property, e.NewValue);
109
                instance.SetArrowMultiPath();
110
            }
111
        }
112
        #endregion
113
        #region Properties
114
        public string UserID
115
        {
116
            get { return (string)GetValue(UserIDProperty); }
117
            set
118
            {
119
                if (this.UserID != value)
120
                {
121
                    SetValue(UserIDProperty, value);
122
                    OnPropertyChanged("UserID");
123
                }
124
            }
125
        }
126
        public Double LineSize
127
        {
128
            get { return (Double)GetValue(LineSizeProperty); }
129
            set
130
            {
131
                if (this.LineSize != value)
132
                {
133
                    SetValue(LineSizeProperty, value);
134
                }
135
            }
136
        }
137

    
138
        public Geometry OverViewPathData
139
        {
140
            get
141
            {
142
                return (Geometry)GetValue(OverViewPathDataProperty);
143
            }
144
            set
145
            {
146
                SetValue(OverViewPathDataProperty, value);
147
                OnPropertyChanged("OverViewPathData");
148
            }
149
        }
150

    
151
        public override bool IsSelected
152
        {
153
            get
154
            {
155
                return (bool)GetValue(IsSelectedProperty);
156
            }
157
            set
158
            {
159
                SetValue(IsSelectedProperty, value);
160
            }
161
        }
162

    
163
        public override ControlType ControlType
164
        {
165
            get
166
            {
167
                return (ControlType)GetValue(ControlTypeProperty);
168
            }
169
            set
170
            {
171
                SetValue(ControlTypeProperty, value);
172
            }
173
        }
174

    
175

    
176
        public DoubleCollection DashSize
177
        {
178
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
179
            set
180
            {
181
                if (this.DashSize != value)
182
                {
183
                    SetValue(DashSizeProperty, value);
184
                }
185
            }
186
        }
187
        public List<Point> PointSet
188
        {
189
            get { return (List<Point>)GetValue(PointSetProperty); }
190
            set { SetValue(PointSetProperty, value); }
191
        }
192
        public override SolidColorBrush StrokeColor
193
        {
194
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
195
            set
196
            {
197
                if (this.StrokeColor != value)
198
                {
199
                    SetValue(StrokeColorProperty, value);
200
                }
201
            }
202
        }
203
        public Geometry PathData
204
        {
205
            get { return (Geometry)GetValue(PathDataProperty); }
206
            set { SetValue(PathDataProperty, value); }
207
        }
208
        public Point EndPoint
209
        {
210
            get { return (Point)GetValue(EndPointProperty); }
211
            set { SetValue(EndPointProperty, value); }
212
        }
213
        public Point StartPoint
214
        {
215
            get { return (Point)GetValue(StartPointProperty); }
216
            set { SetValue(StartPointProperty, value); }
217
        }
218
        public Point MiddlePoint
219
        {
220
            get { return (Point)GetValue(MiddlePointProperty); }
221
            set
222
            {
223
                SetValue(MiddlePointProperty, value);
224
                OnPropertyChanged("MiddlePoint");
225
            }
226
        }
227
        #endregion
228
        #region Object & Variable
229
        GeometryGroup instanceGroup = new GeometryGroup();
230
        #endregion
231
        public override void OnApplyTemplate()
232
        {
233
            base.OnApplyTemplate();
234
            Base_ArrowMultiPath = GetTemplateChild(PART_ArrowMultiPath) as Path;
235
            SetArrowMultiPath();
236
        }
237

    
238
        public override void ApplyOverViewData()
239
        {
240
            this.OverViewPathData = this.PathData;
241
        }
242

    
243
        public void SetArrowMultiPath()
244
        {
245

    
246
            
247
            Base_ArrowMultiPath.StrokeDashArray.Clear();
248
            foreach (var item in this.DashSize)
249
            {
250
                Base_ArrowMultiPath.StrokeDashArray.Add(item);
251
            }
252
            Base_ArrowMultiPath.StrokeDashCap = PenLineCap.Square;
253
            instanceGroup.Children.Clear();
254
            PathFigure pathFigure = new PathFigure();
255

    
256
            pathFigure.StartPoint = this.StartPoint;
257
            LineSegment lineSegment0 = new LineSegment();
258
            lineSegment0.Point = this.StartPoint;
259
            pathFigure.Segments.Add(lineSegment0);
260

    
261
            
262

    
263
            //if (this.EndPoint == this.MiddlePoint)
264
            if (this.MiddlePoint == new Point(0,0))
265
            {
266
                //instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.MiddlePoint, this.LineSize));
267
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
268
            }
269
            else
270
            {
271
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.EndPoint, this.LineSize));
272
                LineSegment lineSegment1 = new LineSegment();
273
                lineSegment1.Point = this.MiddlePoint;
274
                pathFigure.Segments.Add(lineSegment1);
275
            }
276

    
277
            LineSegment lineSegment2 = new LineSegment();
278
            lineSegment2.Point = this.EndPoint;
279
            pathFigure.Segments.Add(lineSegment2);
280

    
281
            PathGeometry pathGeometry = new PathGeometry();
282
            pathGeometry.Figures.Add(pathFigure);
283
            pathFigure.IsFilled = false;
284
            instanceGroup.Children.Add(pathGeometry);
285
            //this.Base_ArrowMultiPath.Stroke = this.StrokeColor;
286

    
287
            //if (this.IsSelected)
288
            //{
289
            //    Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue);
290
            //}
291
            //else
292
            //{
293
            //    Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red);
294
            //}
295

    
296
            this.PathData = instanceGroup;
297
            OverViewPathData = PathData;
298
        }
299
        //public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize)
300
        //{
301
        //    double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
302
        //    PathGeometry pathGeometry = new PathGeometry();
303
        //    PathFigure pathFigure = new PathFigure();
304
        //    pathFigure.StartPoint = p1;
305

    
306
        //    Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
307
        //    Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
308

    
309
        //    //Point lpoint = new Point(p1.X + lineSize, p1.Y + lineSize * 4);
310
        //    //Point rpoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4);
311

    
312
        //    //Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
313
        //    //Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
314

    
315
        //    LineSegment seg1 = new LineSegment();
316
        //    seg1.Point = lpoint;
317
        //    pathFigure.Segments.Add(seg1);
318

    
319
        //    LineSegment seg2 = new LineSegment();
320
        //    seg2.Point = rpoint;
321
        //    pathFigure.Segments.Add(seg2);
322

    
323
        //    LineSegment seg3 = new LineSegment();
324
        //    seg3.Point = p1;
325
        //    pathFigure.Segments.Add(seg3);
326

    
327
        //    pathFigure.IsClosed = true;
328
        //    pathFigure.IsFilled = true;
329

    
330
        //    pathGeometry.Figures.Add(pathFigure);
331
        //    pathGeometry.FillRule = FillRule.Nonzero;
332
        //    RotateTransform transform = new RotateTransform();
333
        //    transform.Angle = theta - 90;
334
        //    transform.CenterX = p1.X;
335
        //    transform.CenterY = p1.Y;
336
        //    pathGeometry.Transform = transform;
337
        //    return pathGeometry;
338
        //}
339

    
340
        protected void OnPropertyChanged(string propName)
341
        {
342
            if (PropertyChanged != null)
343
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
344
        }
345

    
346
        public override void UpdateControl()
347
        {
348
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
349
            this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
350
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
351
        }
352

    
353
        /// <summary>
354
        /// call when mouse is moving while drawing control
355
        /// </summary>
356
        /// <author>humkyung</author>
357
        /// <param name="pt"></param>
358
        /// <param name="bAxisLocked"></param>
359
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked, bool bShiftKeyPressed)
360
        {
361
            this.EndPoint = pt;
362
            if (this.MiddlePoint == new Point(0, 0))
363
            {
364
                Point tmp = this.EndPoint;
365
                Angle = MathSet.returnAngle(this.StartPoint, ref tmp, bShiftKeyPressed);
366

    
367
                if (bAxisLocked || bShiftKeyPressed)
368
                {
369
                    this.EndPoint = tmp;
370
                }
371
            }
372
            else
373
            {
374
                Point tmp = this.EndPoint;
375
                Angle = MathSet.returnAngle(this.MiddlePoint, ref tmp, bShiftKeyPressed);
376

    
377
                if (bAxisLocked || bShiftKeyPressed)
378
                {
379
                
380
                    this.EndPoint = tmp;
381
                }
382
            }
383

    
384
            this.PointSet = new List<Point>
385
            {
386
                this.StartPoint,
387
                this.MiddlePoint,
388
                this.EndPoint,
389
            };
390
        }
391

    
392
        /// <summary>
393
        /// move control point has same location of given pt along given delta
394
        /// </summary>
395
        /// <author>humkyung</author>
396
        /// <date>2019.06.20</date>
397
        /// <param name="pt"></param>
398
        /// <param name="dx"></param>
399
        /// <param name="dy"></param>
400
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy)
401
        {
402
            Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt);
403
            selected.X += dx;
404
            selected.Y += dy;
405
            for (int i = 0; i < (this as IPath).PointSet.Count; i++)
406
            {
407
                if (pt.Equals((this as IPath).PointSet[i]))
408
                {
409
                    (this as IPath).PointSet[i] = selected;
410
                }
411
            }
412
            this.UpdateControl();
413
        }
414

    
415
        /// <summary>
416
        /// return ArrowControl_Multi's area
417
        /// </summary>
418
        /// <author>humkyung</author>
419
        /// <date>2019.06.13</date>
420
        public override Rect ItemRect
421
        {
422
            get
423
            {
424
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
425
                dMinX = Math.Min(this.MiddlePoint.X, dMinX);
426
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
427
                dMinY = Math.Min(this.MiddlePoint.Y, dMinY);
428
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
429
                dMaxX = Math.Max(this.MiddlePoint.X, dMaxX);
430
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
431
                dMaxY = Math.Max(this.MiddlePoint.Y, dMaxY);
432

    
433
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
434
            }
435
        }
436

    
437
        /// <summary>
438
        /// Serialize this
439
        /// </summary>
440
        /// <param name="sUserId"></param>
441
        /// <returns></returns>
442
        public override string Serialize()
443
        {
444
            using (S_ArrowControl_Multi STemp = new S_ArrowControl_Multi())
445
            {
446
                STemp.TransformPoint = "0|0";
447
                STemp.PointSet = this.PointSet;
448
                STemp.SizeSet = String.Format("{0}", this.LineSize);
449
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
450
                STemp.StartPoint = this.StartPoint;
451
                STemp.EndPoint = this.EndPoint;
452
                STemp.UserID = this.UserID;
453
                STemp.Opac = this.Opacity;
454
                STemp.DashSize = this.DashSize;
455
                STemp.MidPoint = this.MiddlePoint;
456
                STemp.Name = this.GetType().Name.ToString();
457

    
458
                ///강인구 추가(2017.11.02)
459
                ///Memo 추가
460
                STemp.Memo = this.Memo;
461

    
462
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
463
            };
464
        }
465

    
466
        /// <summary>
467
        /// create a arrowcontrol_multi from given string
468
        /// </summary>
469
        /// <param name="str"></param>
470
        /// <returns></returns>
471
        public static ArrowControl_Multi FromString(string str, SolidColorBrush brush, string sProjectNo)
472
        {
473
            ArrowControl_Multi instance = null;
474
            using (S_ArrowControl_Multi s = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(str))
475
            {
476
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
477
                instance = new ArrowControl_Multi
478
                {
479
                    LineSize = Convert.ToDouble(data2.First()),
480
                    StartPoint = s.StartPoint,
481
                    MiddlePoint = s.MidPoint,
482
                    DashSize = s.DashSize,
483
                    EndPoint = s.EndPoint,
484
                    PointSet = s.PointSet,
485
                    Opacity = s.Opac,
486
                    StrokeColor = brush,
487
                    UserID = s.UserID,
488
                    Memo = s.Memo
489
                };
490
            }
491

    
492
            return instance;
493
        }
494

    
495
        public void Dispose()
496
        {
497
            //GC.Collect();
498
            //GC.SuppressFinalize(this);
499
            this.Base_ArrowMultiPath = null;
500
        }
501
    }
502
}
503

    
클립보드 이미지 추가 (최대 크기: 500 MB)