프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (19.9 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, 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
        public override void Copy(CommentUserInfo lhs)
44
        {
45
            if (lhs is ArrowControl_Multi item)
46
            {
47
                this.LineSize = item.LineSize;
48
                this.StartPoint = new Point(item.StartPoint.X, item.StartPoint.Y);
49
                this.MiddlePoint = new Point(item.MiddlePoint.X, item.MiddlePoint.Y);
50
                this.DashSize = item.DashSize;
51
                this.EndPoint = new Point(item.EndPoint.X, item.EndPoint.Y);
52
                this.PointSet = item.PointSet.ConvertAll(x => new Point(x.X, x.Y));
53
                this.Opacity = item.Opacity;
54
                this.StrokeColor = item.StrokeColor;
55
                this.UserID = item.UserID;
56
                this.Memo = item.Memo;
57
                this.ZIndex = item.ZIndex;
58
            }
59
        }
60

    
61
        public override CommentUserInfo Clone()
62
        {
63
            var clone = new ArrowControl_Multi();
64
            clone.Copy(this);
65
            return clone;
66
        }
67

    
68
        #region Dependency Properties
69

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

    
73
        public static readonly DependencyProperty ControlTypeProperty =
74
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(ControlType.ArrowMultiLine));
75

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

    
79
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
80
                "UserID", typeof(string), typeof(ArrowControl_Multi), new PropertyMetadata(null));
81
				
82
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
83
              "LineSize", typeof(double), typeof(ArrowControl_Multi), new PropertyMetadata((Double)3, PointValueChanged));
84

    
85
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
86
               "DashSize", typeof(DoubleCollection), typeof(ArrowControl_Multi), new PropertyMetadata(new DoubleCollection { 99999099 }, PointValueChanged));
87

    
88
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
89
              "StrokeColor", typeof(SolidColorBrush), typeof(ArrowControl_Multi), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
90

    
91
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
92
              "PathData", typeof(Geometry), typeof(ArrowControl_Multi), null);
93

    
94
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
95
               "StartPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
96

    
97
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
98
               "EndPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(100, 100), PointValueChanged));
99
        public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register(
100
                "MiddlePoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
101

    
102
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
103
               "PointSet", typeof(List<Point>), typeof(ArrowControl_Multi), new PropertyMetadata(new List<Point>(), PointValueChanged));
104
        #endregion
105
        #region PropertyChanged Method
106

    
107
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
108
        {
109
            //var instance = (ArrowControl_Multi)sender;
110

    
111
            //if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
112
            //{
113

    
114
            //    instance.SetValue(e.Property, e.NewValue);
115

    
116
            //    if (instance.IsSelected)
117
            //    {
118
            //        instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue);
119
            //    }
120
            //    else
121
            //    {
122
            //        instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red);
123
            //    }
124
            //}
125
        }
126

    
127

    
128
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
129
        {
130
            var instance = (ArrowControl_Multi)sender;
131
            if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
132
            {
133
                instance.SetValue(e.Property, e.NewValue);
134
                instance.SetArrowMultiPath();
135
            }
136
        }
137
        #endregion
138
        #region Properties
139
        public string UserID
140
        {
141
            get { return (string)GetValue(UserIDProperty); }
142
            set
143
            {
144
                if (this.UserID != value)
145
                {
146
                    SetValue(UserIDProperty, value);
147
                    OnPropertyChanged("UserID");
148
                }
149
            }
150
        }
151
        public Double LineSize
152
        {
153
            get { return (Double)GetValue(LineSizeProperty); }
154
            set
155
            {
156
                if (this.LineSize != value)
157
                {
158
                    SetValue(LineSizeProperty, value);
159
                }
160
            }
161
        }
162

    
163
        public Geometry OverViewPathData
164
        {
165
            get
166
            {
167
                return (Geometry)GetValue(OverViewPathDataProperty);
168
            }
169
            set
170
            {
171
                SetValue(OverViewPathDataProperty, value);
172
                OnPropertyChanged("OverViewPathData");
173
            }
174
        }
175

    
176
        public override bool IsSelected
177
        {
178
            get
179
            {
180
                return (bool)GetValue(IsSelectedProperty);
181
            }
182
            set
183
            {
184
                SetValue(IsSelectedProperty, value);
185
            }
186
        }
187

    
188
        public override ControlType ControlType
189
        {
190
            get
191
            {
192
                return (ControlType)GetValue(ControlTypeProperty);
193
            }
194
            set
195
            {
196
                SetValue(ControlTypeProperty, value);
197
            }
198
        }
199

    
200

    
201
        public DoubleCollection DashSize
202
        {
203
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
204
            set
205
            {
206
                if (this.DashSize != value)
207
                {
208
                    SetValue(DashSizeProperty, value);
209
                }
210
            }
211
        }
212
        public List<Point> PointSet
213
        {
214
            get { return (List<Point>)GetValue(PointSetProperty); }
215
            set { SetValue(PointSetProperty, value); }
216
        }
217
        public override SolidColorBrush StrokeColor
218
        {
219
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
220
            set
221
            {
222
                if (this.StrokeColor != value)
223
                {
224
                    SetValue(StrokeColorProperty, value);
225
                }
226
            }
227
        }
228
        public Geometry PathData
229
        {
230
            get { return (Geometry)GetValue(PathDataProperty); }
231
            set { SetValue(PathDataProperty, value); }
232
        }
233
        public Point EndPoint
234
        {
235
            get { return (Point)GetValue(EndPointProperty); }
236
            set { SetValue(EndPointProperty, value); }
237
        }
238
        public Point StartPoint
239
        {
240
            get { return (Point)GetValue(StartPointProperty); }
241
            set { SetValue(StartPointProperty, value); }
242
        }
243
        public Point MiddlePoint
244
        {
245
            get { return (Point)GetValue(MiddlePointProperty); }
246
            set
247
            {
248
                SetValue(MiddlePointProperty, value);
249
                OnPropertyChanged("MiddlePoint");
250
            }
251
        }
252
        #endregion
253
        #region Object & Variable
254
        GeometryGroup instanceGroup = new GeometryGroup();
255
        #endregion
256
        public override void OnApplyTemplate()
257
        {
258
            base.OnApplyTemplate();
259
            Base_ArrowMultiPath = GetTemplateChild(PART_ArrowMultiPath) as Path;
260
            SetArrowMultiPath();
261
        }
262

    
263
        public override void ApplyOverViewData()
264
        {
265
            this.OverViewPathData = this.PathData;
266
        }
267

    
268
        public void SetArrowMultiPath()
269
        {
270

    
271
            
272
            Base_ArrowMultiPath.StrokeDashArray.Clear();
273
            foreach (var item in this.DashSize)
274
            {
275
                Base_ArrowMultiPath.StrokeDashArray.Add(item);
276
            }
277
            Base_ArrowMultiPath.StrokeDashCap = PenLineCap.Square;
278
            instanceGroup.Children.Clear();
279
            PathFigure pathFigure = new PathFigure();
280

    
281
            pathFigure.StartPoint = this.StartPoint;
282
            LineSegment lineSegment0 = new LineSegment();
283
            lineSegment0.Point = this.StartPoint;
284
            pathFigure.Segments.Add(lineSegment0);
285

    
286
            
287

    
288
            //if (this.EndPoint == this.MiddlePoint)
289
            if (this.MiddlePoint == new Point(0,0))
290
            {
291
                //instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.MiddlePoint, this.LineSize));
292
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
293
            }
294
            else
295
            {
296
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.EndPoint, this.LineSize));
297
                LineSegment lineSegment1 = new LineSegment();
298
                lineSegment1.Point = this.MiddlePoint;
299
                pathFigure.Segments.Add(lineSegment1);
300
            }
301

    
302
            LineSegment lineSegment2 = new LineSegment();
303
            lineSegment2.Point = this.EndPoint;
304
            pathFigure.Segments.Add(lineSegment2);
305

    
306
            PathGeometry pathGeometry = new PathGeometry();
307
            pathGeometry.Figures.Add(pathFigure);
308
            pathFigure.IsFilled = false;
309
            instanceGroup.Children.Add(pathGeometry);
310
            //this.Base_ArrowMultiPath.Stroke = this.StrokeColor;
311

    
312
            //if (this.IsSelected)
313
            //{
314
            //    Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue);
315
            //}
316
            //else
317
            //{
318
            //    Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red);
319
            //}
320

    
321
            this.PathData = instanceGroup;
322
            OverViewPathData = PathData;
323
        }
324
        //public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize)
325
        //{
326
        //    double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
327
        //    PathGeometry pathGeometry = new PathGeometry();
328
        //    PathFigure pathFigure = new PathFigure();
329
        //    pathFigure.StartPoint = p1;
330

    
331
        //    Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
332
        //    Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
333

    
334
        //    //Point lpoint = new Point(p1.X + lineSize, p1.Y + lineSize * 4);
335
        //    //Point rpoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4);
336

    
337
        //    //Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
338
        //    //Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
339

    
340
        //    LineSegment seg1 = new LineSegment();
341
        //    seg1.Point = lpoint;
342
        //    pathFigure.Segments.Add(seg1);
343

    
344
        //    LineSegment seg2 = new LineSegment();
345
        //    seg2.Point = rpoint;
346
        //    pathFigure.Segments.Add(seg2);
347

    
348
        //    LineSegment seg3 = new LineSegment();
349
        //    seg3.Point = p1;
350
        //    pathFigure.Segments.Add(seg3);
351

    
352
        //    pathFigure.IsClosed = true;
353
        //    pathFigure.IsFilled = true;
354

    
355
        //    pathGeometry.Figures.Add(pathFigure);
356
        //    pathGeometry.FillRule = FillRule.Nonzero;
357
        //    RotateTransform transform = new RotateTransform();
358
        //    transform.Angle = theta - 90;
359
        //    transform.CenterX = p1.X;
360
        //    transform.CenterY = p1.Y;
361
        //    pathGeometry.Transform = transform;
362
        //    return pathGeometry;
363
        //}
364

    
365
        protected void OnPropertyChanged(string propName)
366
        {
367
            if (PropertyChanged != null)
368
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
369
        }
370

    
371
        public override void UpdateControl()
372
        {
373
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
374
            this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
375
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
376
        }
377

    
378
        /// <summary>
379
        /// call when mouse is moving while drawing control
380
        /// </summary>
381
        /// <author>humkyung</author>
382
        /// <param name="pt"></param>
383
        /// <param name="bAxisLocked"></param>
384
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
385
        {
386
            this.EndPoint = pt;
387
            if (this.MiddlePoint == new Point(0, 0))
388
            {
389
                Point tmp = this.EndPoint;
390
                CommentAngle = MathSet.returnAngle(this.StartPoint, ref tmp, bAxisLocked);
391

    
392
                if (bAxisLocked)
393
                {
394
                    this.EndPoint = tmp;
395
                }
396
            }
397
            else
398
            {
399
                Point tmp = this.EndPoint;
400
                CommentAngle = MathSet.returnAngle(this.MiddlePoint, ref tmp, bAxisLocked);
401

    
402
                if (bAxisLocked)
403
                {
404
                
405
                    this.EndPoint = tmp;
406
                }
407
            }
408

    
409
            this.PointSet = new List<Point>
410
            {
411
                this.StartPoint,
412
                this.MiddlePoint,
413
                this.EndPoint,
414
            };
415
        }
416

    
417
        /// <summary>
418
        /// move control point has same location of given pt along given delta
419
        /// </summary>
420
        /// <author>humkyung</author>
421
        /// <date>2019.06.20</date>
422
        /// <param name="pt"></param>
423
        /// <param name="dx"></param>
424
        /// <param name="dy"></param>
425
        public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false)
426
        {
427
            Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt);
428

    
429
            var tmpPointSet = (this as IPath).PointSet.Where(x => !x.Equals(selected));
430
            Point NearStartpoint = MathSet.getNearPoint(tmpPointSet.ToList(), pt);
431

    
432
            selected.X += dx;
433
            selected.Y += dy;
434

    
435
            Point tmp = selected;
436

    
437
            CommentAngle = MathSet.returnAngle(NearStartpoint, ref tmp, bAxisLocked);
438

    
439
            if (bAxisLocked)
440
            {
441
                selected = tmp;
442
            }
443

    
444
            for (int i = 0; i < (this as IPath).PointSet.Count; i++)
445
            {
446
                if (pt.Equals((this as IPath).PointSet[i]))
447
                {
448
                    (this as IPath).PointSet[i] = selected;
449
                }
450
            }
451
            this.UpdateControl();
452
        }
453

    
454
        /// <summary>
455
        /// return ArrowControl_Multi's area
456
        /// </summary>
457
        /// <author>humkyung</author>
458
        /// <date>2019.06.13</date>
459
        public override Rect ItemRect
460
        {
461
            get
462
            {
463
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
464
                dMinX = Math.Min(this.MiddlePoint.X, dMinX);
465
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
466
                dMinY = Math.Min(this.MiddlePoint.Y, dMinY);
467
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
468
                dMaxX = Math.Max(this.MiddlePoint.X, dMaxX);
469
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
470
                dMaxY = Math.Max(this.MiddlePoint.Y, dMaxY);
471

    
472
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
473
            }
474
        }
475

    
476
        /// <summary>
477
        /// Serialize this
478
        /// </summary>
479
        /// <param name="sUserId"></param>
480
        /// <returns></returns>
481
        public override string Serialize()
482
        {
483
            using (S_ArrowControl_Multi ctrl = new S_ArrowControl_Multi())
484
            {
485
                ctrl.TransformPoint = "0|0";
486
                ctrl.PointSet = this.PointSet;
487
                ctrl.SizeSet = String.Format("{0}", this.LineSize);
488
                ctrl.StrokeColor = this.StrokeColor.Color.ToString();
489
                ctrl.StartPoint = this.StartPoint;
490
                ctrl.EndPoint = this.EndPoint;
491
                ctrl.UserID = this.UserID;
492
                ctrl.Opac = this.Opacity;
493
                ctrl.DashSize = this.DashSize;
494
                ctrl.MidPoint = this.MiddlePoint;
495
                ctrl.Name = this.GetType().Name.ToString();
496

    
497
                ///강인구 추가(2017.11.02)
498
                ///Memo 추가
499
                ctrl.Memo = this.Memo;
500

    
501
                ctrl.ZIndex = this.ZIndex;
502

    
503
                return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize()));
504
            };
505
        }
506

    
507
        /// <summary>
508
        /// create a arrowcontrol_multi from given string
509
        /// </summary>
510
        /// <param name="str"></param>
511
        /// <returns></returns>
512
        public static ArrowControl_Multi FromString(string str, SolidColorBrush brush, string sProjectNo)
513
        {
514
            ArrowControl_Multi instance = null;
515
            using (S_ArrowControl_Multi s = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(str))
516
            {
517
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
518
                instance = new ArrowControl_Multi
519
                {
520
                    LineSize = Convert.ToDouble(data2.First()),
521
                    StartPoint = s.StartPoint,
522
                    MiddlePoint = s.MidPoint,
523
                    DashSize = s.DashSize,
524
                    EndPoint = s.EndPoint,
525
                    PointSet = s.PointSet,
526
                    Opacity = s.Opac,
527
                    StrokeColor = brush,
528
                    UserID = s.UserID,
529
                    Memo = s.Memo,
530
                    ZIndex = s.ZIndex
531
                };
532
            }
533

    
534
            return instance;
535
        }
536

    
537
        public void Dispose()
538
        {
539
            //GC.Collect();
540
            ////GC.SuppressFinalize(this);
541
            this.Base_ArrowMultiPath = null;
542
        }
543
    }
544
}
545

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