프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Cad / CoordinateControl.cs @ fa48eb85

이력 | 보기 | 이력해설 | 다운로드 (22.5 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Windows;
8
using System.Windows.Shapes;
9
using System.Windows.Controls;
10
using System.Windows.Media;
11
using MarkupToPDF.Controls.Common;
12
using MarkupToPDF.Common;
13
using MarkupToPDF.Serialize.Core;
14
using MarkupToPDF.Serialize.S_Control;
15

    
16
namespace MarkupToPDF.Controls.Cad
17
{
18

    
19
    //강인구 추가 IShapeControl
20
    public class CoordinateControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IShapeControl, IDashControl
21
    {
22
        public Path Base_RectPath { get; set; }
23
        private const string PART_RectPath = "PART_RectPath";
24

    
25
        #region Property
26

    
27

    
28
        public MouseMode mousemode
29
        {
30
            get
31
            {
32
                return (MouseMode)GetValue(mousemodeProperty);
33
            }
34
            set
35
            {
36
                SetValue(mousemodeProperty, value);
37
                OnPropertyChanged("mousemode");
38
            }
39
        }
40

    
41
        public SolidColorBrush StrokeColor
42
        {
43
            get
44
            {
45
                return (SolidColorBrush)GetValue(StrokeColorProperty);
46
            }
47
            set
48
            {
49
                SetValue(StrokeColorProperty, value);
50
                OnPropertyChanged("StrokeColor");
51
            }
52
        }
53

    
54
        public Double LineSize
55
        {
56
            get
57
            {
58
                return (Double)GetValue(LineSizeProperty);
59
            }
60
            set
61
            {
62
                SetValue(LineSizeProperty, value);
63
                OnPropertyChanged("LineSize");
64
            }
65
        }
66

    
67
        public Geometry PathData
68
        {
69
            get
70
            {
71
                return (Geometry)GetValue(PathDataProperty);
72
            }
73
            set
74
            {
75
                SetValue(PathDataProperty, value);
76
                OnPropertyChanged("PathData");
77
            }
78

    
79
        }
80

    
81
        public Geometry OverViewPathData
82
        {
83
            get
84
            {
85
                return (Geometry)GetValue(OverViewPathDataProperty);
86
            }
87
            set
88
            {
89
                SetValue(OverViewPathDataProperty, value);
90
                OnPropertyChanged("OverViewPathData");
91
            }
92
        }
93

    
94
        public SolidColorBrush FillColor
95
        {
96
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
97
            set
98
            {
99
                SetValue(FillColorProperty, value);
100
                OnPropertyChanged("FillColor");
101
            }
102
        }
103
        //강인구 추가
104
        public DoubleCollection DashSize
105
        {
106
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
107
            set
108
            {
109
                if (this.DashSize != value)
110
                {
111
                    SetValue(DashSizeProperty, value);
112
                }
113
            }
114
        }
115

    
116
        public Point StartPoint
117
        {
118
            get
119
            {
120
                return (Point)GetValue(StartPointProperty);
121
            }
122
            set
123
            {
124
                SetValue(StartPointProperty, value);
125
                OnPropertyChanged("StartPoint");
126
            }
127
        }
128

    
129
        public Point SetPoint
130
        {
131
            get
132
            {
133
                return (Point)GetValue(SetPointProperty);
134
            }
135
            set
136
            {
137
                SetValue(SetPointProperty, value);
138
                OnPropertyChanged("SetPoint");
139
            }
140
        }
141

    
142
        public Point OriginPoint
143
        {
144
            get
145
            {
146
                return (Point)GetValue(OriginPointProperty);
147
            }
148
            set
149
            {
150
                SetValue(OriginPointProperty, value);
151
                OnPropertyChanged("OriginPoint");
152
            }
153
        }
154

    
155
        public Point TopRightPoint
156
        {
157
            get
158
            {
159
                return (Point)GetValue(TopRightPointProperty);
160
            }
161
            set
162
            {
163
                SetValue(TopRightPointProperty, value);
164
                OnPropertyChanged("TopRightPoint");
165
            }
166
        }
167

    
168
        public Point LeftBottomPoint
169
        {
170
            get
171
            {
172
                return (Point)GetValue(LeftBottomPointProperty);
173
            }
174
            set
175
            {
176
                SetValue(LeftBottomPointProperty, value);
177
                OnPropertyChanged("LeftBottomPoint");
178
            }
179
        }
180

    
181
        public Point EndPoint
182
        {
183
            get
184
            {
185
                return (Point)GetValue(EndPointProperty);
186
            }
187
            set
188
            {
189
                SetValue(EndPointProperty, value);
190
                OnPropertyChanged("EndPoint");
191
            }
192
        }
193

    
194
        public override bool IsSelected
195
        {
196
            get
197
            {
198
                return (bool)GetValue(IsSelectedProperty);
199
            }
200
            set
201
            {
202
                SetValue(IsSelectedProperty, value);
203
                OnPropertyChanged("IsSelected");
204
            }
205
        }
206

    
207
        public ControlType ControlType
208
        {
209
            set
210
            {
211
                SetValue(ControlTypeProperty, value);
212
                OnPropertyChanged("ControlType");
213
            }
214
            get
215
            {
216
                return (ControlType)GetValue(ControlTypeProperty);
217
            }
218
        }
219

    
220
        public List<Point> PointSet
221
        {
222
            get { return (List<Point>)GetValue(PointSetProperty); }
223
            set { SetValue(PointSetProperty, value); }
224
        }
225

    
226

    
227
        public double CanvasX
228
        {
229
            get { return (double)GetValue(CanvasXProperty); }
230
            set
231
            {
232
                if (this.CanvasX != value)
233
                {
234
                    SetValue(CanvasXProperty, value);
235
                    OnPropertyChanged("CanvasX");
236
                }
237
            }
238
        }
239

    
240
        public double CanvasY
241
        {
242
            get { return (double)GetValue(CanvasYProperty); }
243
            set
244
            {
245
                if (this.CanvasY != value)
246
                {
247
                    SetValue(CanvasYProperty, value);
248
                    OnPropertyChanged("CanvasY");
249
                }
250
            }
251
        }
252

    
253
        public PaintSet Paint
254
        {
255
            get { return (PaintSet)GetValue(PaintProperty); }
256
            set
257
            {
258
                if (this.Paint != value)
259
                {
260
                    SetValue(PaintProperty, value);
261
                }
262
            }
263
        }
264

    
265
        public double CommentAngle
266
        {
267
            get { return (double)GetValue(AngleProperty); }
268
            set
269
            {
270
                if (this.CommentAngle != value)
271
                {
272
                    SetValue(AngleProperty, value);
273
                }
274
            }
275
        }
276
        public string UserID
277
        {
278
            get { return (string)GetValue(UserIDProperty); }
279
            set
280
            {
281
                if (this.UserID != value)
282
                {
283
                    SetValue(UserIDProperty, value);
284
                    OnPropertyChanged("UserID");
285
                }
286
            }
287
        }
288

    
289
        #endregion
290

    
291
        #region Dependency Property
292

    
293

    
294
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
295
        "UserID", typeof(string), typeof(CoordinateControl), new PropertyMetadata(null));
296

    
297
        public static readonly DependencyProperty mousemodeProperty =
298
                DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(CoordinateControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
299

    
300
        public static readonly DependencyProperty IsSelectedProperty =
301
          DependencyProperty.Register("IsSelected", typeof(bool), typeof(CoordinateControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
302

    
303
        public static readonly DependencyProperty ControlTypeProperty =
304
                DependencyProperty.Register("ControlType", typeof(ControlType), typeof(CoordinateControl), new FrameworkPropertyMetadata(ControlType.Coordinate));
305

    
306
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
307
                "StrokeColor", typeof(SolidColorBrush), typeof(CoordinateControl), new PropertyMetadata(new SolidColorBrush(Colors.Black)));
308

    
309
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
310
              "LineSize", typeof(double), typeof(CoordinateControl), new PropertyMetadata((Double)10));
311

    
312
        //강인구 추가
313
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
314
                "DashSize", typeof(DoubleCollection), typeof(CoordinateControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
315
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
316
               "PathData", typeof(Geometry), typeof(CoordinateControl), null);
317

    
318
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
319
               "OverViewPathData", typeof(Geometry), typeof(CoordinateControl), null);
320

    
321
        //강인구 추가
322
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
323
        "Paint", typeof(PaintSet), typeof(CoordinateControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
324

    
325

    
326
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
327
                "FillColor", typeof(SolidColorBrush), typeof(CoordinateControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
328

    
329
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
330
                 "CanvasX", typeof(double), typeof(CoordinateControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
331

    
332
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
333
                "CanvasY", typeof(double), typeof(CoordinateControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
334

    
335
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
336
               "TopRightPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
337

    
338
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
339
                 "LeftBottomPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
340

    
341
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
342
            "StartPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
343

    
344
        public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(
345
        "SetPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
346

    
347
        public static readonly DependencyProperty OriginPointProperty = DependencyProperty.Register(
348
        "OriginPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
349
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
350
            "Angle", typeof(double), typeof(CoordinateControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
351
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
352
         "PointSet", typeof(List<Point>), typeof(CoordinateControl), new PropertyMetadata(new List<Point>()));
353

    
354
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
355
              "EndPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
356

    
357
        #endregion  Dependency Property
358

    
359
        #region Dependency PropertyChanged
360
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
361
        {
362
            var instance = (CoordinateControl)sender;
363

    
364
            if (e.OldValue != e.NewValue && instance != null)
365
            {
366
                instance.SetValue(e.Property, e.NewValue);
367
                Canvas.SetLeft(instance, instance.SetPoint.X);
368
                Canvas.SetTop(instance, instance.SetPoint.Y);
369
                //Canvas.SetLeft(instance, instance.CanvasX);
370
                //Canvas.SetTop(instance, instance.CanvasY);
371
            }
372
        }
373

    
374

    
375
        public static void OnUpdateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
376
        {
377
            var instance = (CoordinateControl)sender;
378

    
379
            if (e.OldValue != e.NewValue && instance != null)
380
            {
381
                instance.SetValue(e.Property, e.NewValue);
382
                instance.SetRectPath();
383
            }
384
        }
385

    
386
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
387
        {
388
            var instance = (CoordinateControl)sender;
389
            if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
390
            {
391
                instance.SetValue(e.Property, e.NewValue);
392
                instance.SetRectPath();
393
            }
394
        }
395

    
396
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
397
        {
398
            //var instance = (CoordinateControl)sender;
399

    
400
            //if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
401
            //{
402
            //    instance.SetValue(e.Property, e.NewValue);
403

    
404
            //    if (instance.IsSelected)
405
            //    {
406
            //        instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Blue);
407
            //    }
408
            //    else
409
            //    {
410
            //        instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Red);
411
            //    }
412
            //}
413
        }
414

    
415
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
416
        {
417
            var instance = (CoordinateControl)sender;
418

    
419
            if (e.OldValue != e.NewValue && instance.Base_RectPath != null)
420
            {
421
                instance.SetValue(e.Property, e.NewValue);
422
                instance.SetRectPath();
423
            }
424
        }
425
        #endregion Dependency PropertyChanged
426

    
427
        public void SetRectPath()
428
        {
429
            this.ApplyTemplate();
430

    
431
            if (Base_RectPath != null)
432
            {
433
                Base_RectPath.StrokeDashArray.Clear();
434
                if (DashSize != null)
435
                {
436
                    foreach (var item in this.DashSize)
437
                    {
438
                        Base_RectPath.StrokeDashArray.Add(item);
439
                    }
440
                    Base_RectPath.StrokeDashCap = PenLineCap.Square;
441
                }
442

    
443
                PathFigure pathFigure = new PathFigure
444
                {
445
                    IsClosed = true
446
                };
447

    
448
                if (ControlType == ControlType.Coordinate)
449
                {
450
                    switch (this.Paint)
451
                    {
452
                        case PaintSet.None:
453
                            this.FillColor = null;
454
                            pathFigure.IsFilled = false;
455
                            break;
456
                        default:
457
                            {
458

    
459
                            }
460
                            break;
461
                    }
462
                }
463

    
464
                pathFigure.StartPoint = this.StartPoint;
465

    
466
                LineSegment lineSegment1 = new LineSegment();
467
                lineSegment1.Point = this.LeftBottomPoint;
468
                pathFigure.Segments.Add(lineSegment1);
469

    
470
                LineSegment lineSegment2 = new LineSegment();
471
                lineSegment2.Point = this.EndPoint;
472
                pathFigure.Segments.Add(lineSegment2);
473

    
474
                LineSegment lineSegment3 = new LineSegment();
475
                lineSegment3.Point = this.TopRightPoint;
476
                pathFigure.Segments.Add(lineSegment3);
477

    
478
                LineSegment lineSegment0 = new LineSegment();
479
                lineSegment0.Point = this.StartPoint;
480
                pathFigure.Segments.Add(lineSegment0);
481

    
482
                PathGeometry pathGeometry = new PathGeometry();
483
                pathGeometry.Figures = new PathFigureCollection();
484
                pathGeometry.Figures.Add(pathFigure);
485

    
486

    
487
                //Base_RectPath.StrokeThickness = 3;
488
                this.FillColor = null;
489
                this.PathData = pathGeometry;
490
                ApplyOverViewData();
491
                //OverViewPathData = PathData;
492
                //AdornerControl adornerControl = new Adorner.AdornerControl();
493
                ////adornerControl
494

    
495
                //adornerControl.Content = pathGeometry;
496

    
497
            }
498
        }
499

    
500
        public override void ApplyOverViewData()
501
        {
502
            this.OverViewPathData = this.PathData;
503
        }
504

    
505
        #region Internal Method
506

    
507

    
508
        static CoordinateControl()
509
        {
510
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CoordinateControl), new FrameworkPropertyMetadata(typeof(CoordinateControl)));
511
            //ResourceDictionary dictionary = new ResourceDictionary();
512
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
513
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
514
        }
515

    
516

    
517
        public override void OnApplyTemplate()
518
        {
519
            base.OnApplyTemplate();
520

    
521
            Base_RectPath = GetTemplateChild(PART_RectPath) as Path;
522

    
523

    
524
            if (Base_RectPath == null)
525
                return;
526

    
527
            SetRectPath();
528
            Base_RectPath.Focus();
529
        }
530

    
531
        public void updateControl()
532
        {
533
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
534
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
535
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
536
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
537
        }
538

    
539
        private void OnPropertyChanged(string name)
540
        {
541
            if (PropertyChanged != null)
542
            {
543
                PropertyChanged(this, new PropertyChangedEventArgs(name));
544
            }
545
        }
546

    
547
        public void ChangePaint(PaintSet state)
548
        {
549
            this.Paint = state;
550
            this.SetRectPath();
551
        }
552

    
553
        /// <summary>
554
        /// call when mouse is moving while drawing control
555
        /// </summary>
556
        /// <author>humkyung</author>
557
        /// <param name="pt"></param>
558
        /// <param name="bAxisLocked"></param>
559
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked, bool bShiftKeyPressed)
560
        {
561
            this.EndPoint = bShiftKeyPressed ? this.GetSquareEndPoint(this.StartPoint, pt) : pt;
562
            this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y);
563
            this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y);
564

    
565
            this.PointSet = new List<Point>
566
            {
567
                this.StartPoint,
568
                this.LeftBottomPoint,
569
                this.EndPoint,
570
                this.TopRightPoint,
571
            };
572

    
573
            this.updateControl();
574
        }
575

    
576
        /// <summary>
577
        /// return CoordinateControl's area
578
        /// </summary>
579
        /// <author>humkyung</author>
580
        /// <date>2019.06.13</date>
581
        public override Rect ItemRect
582
        {
583
            get
584
            {
585
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
586
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
587
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
588
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
589

    
590
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
591
            }
592
        }
593

    
594
        /// <summary>
595
        /// Serialize this
596
        /// </summary>
597
        /// <param name="sUserId"></param>
598
        /// <returns></returns>
599
        public override string Serialize()
600
        {
601
            using (S_CoordinateControl STemp = new S_CoordinateControl())
602
            {
603
                STemp.TransformPoint = "0|0";
604
                STemp.SizeSet = String.Format("{0}", this.LineSize);
605
                STemp.PaintState = this.Paint;
606
                STemp.PointSet = this.PointSet;
607
                //STemp.StrokeColor = "#FF00FF00";
608
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
609
                if (this.FillColor != null)
610
                {
611
                    STemp.FillColor = this.FillColor.Color.ToString();
612
                }
613
                STemp.StartPoint = this.StartPoint;
614
                STemp.UserID = this.UserID;
615
                STemp.EndPoint = this.EndPoint;
616
                STemp.LB = this.LeftBottomPoint;
617
                STemp.TR = this.TopRightPoint;
618
                STemp.DashSize = this.DashSize;
619
                STemp.Opac = this.Opacity;
620
                STemp.Name = this.GetType().Name.ToString();
621
                STemp.Memo = this.Memo;
622

    
623
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
624
            };
625
        }
626

    
627
        /// <summary>
628
        /// create a CoordinateControl from given string
629
        /// </summary>
630
        /// <param name="str"></param>
631
        /// <returns></returns>
632
        public static CoordinateControl FromString(string str, SolidColorBrush brush, string sProjectNo)
633
        {
634
            using (S_CoordinateControl s = JsonSerializerHelper.JsonDeserialize<S_CoordinateControl>(str))
635
            {
636
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
637
                return new CoordinateControl
638
                {
639
                    LineSize = Convert.ToDouble(data2.First()),
640
                    Paint = s.PaintState,
641
                    StartPoint = s.StartPoint,
642
                    EndPoint = s.EndPoint,
643
                    CommentAngle = s.Angle,
644
                    StrokeColor = Brushes.Yellow,
645
                    DashSize = s.DashSize,
646
                    Opacity = s.Opac,
647
                    LeftBottomPoint = s.LB,
648
                    TopRightPoint = s.TR,
649
                    PointSet = s.PointSet,
650
                    UserID = s.UserID,
651
                    //  FillColor = Brushes.Yellow,
652
                    Memo = s.Memo
653
                };
654
            }
655
        }
656

    
657
        public event PropertyChangedEventHandler PropertyChanged;
658

    
659
        public void Dispose()
660
        {
661
            //GC.Collect();
662
            //GC.SuppressFinalize(this);
663
            this.Base_RectPath = null;
664
        }
665
        #endregion Internal Method
666
    }
667
}
클립보드 이미지 추가 (최대 크기: 500 MB)