프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowControl_Multi.cs @ 0d00f9c8

이력 | 보기 | 이력해설 | 다운로드 (18.5 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
                if (bAxisLocked || bShiftKeyPressed)
365
                {
366
                    Point tmp = this.EndPoint;
367
                    string angle = MathSet.returnAngleString(this.StartPoint, ref tmp, true);
368
                    this.EndPoint = tmp;
369
                }
370
            }
371
            else
372
            {
373
                if (bAxisLocked || bShiftKeyPressed)
374
                {
375
                    Point tmp = this.EndPoint;
376
                    string angle = MathSet.returnAngleString(this.MiddlePoint, ref tmp, true);
377
                    this.EndPoint = tmp;
378
                }
379
            }
380

    
381
            this.PointSet = new List<Point>
382
            {
383
                this.StartPoint,
384
                this.MiddlePoint,
385
                this.EndPoint,
386
            };
387
        }
388

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

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

    
430
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
431
            }
432
        }
433

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

    
455
                ///강인구 추가(2017.11.02)
456
                ///Memo 추가
457
                STemp.Memo = this.Memo;
458

    
459
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
460
            };
461
        }
462

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

    
489
            return instance;
490
        }
491

    
492
        public void Dispose()
493
        {
494
            GC.Collect();
495
            GC.SuppressFinalize(this);
496
        }
497
    }
498
}
499

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