프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Cad / OverlapWhiteControl.cs @ 24c5e56c

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

1 684ef11c ljiyeon
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 036650a0 humkyung
using MarkupToPDF.Serialize.Core;
14
using MarkupToPDF.Serialize.S_Control;
15 684ef11c ljiyeon
16
namespace MarkupToPDF.Controls.Cad
17
{
18
19
    //강인구 추가 IShapeControl
20
    public class OverlapWhiteControl : 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 959b3ef2 humkyung
        public override bool IsSelected
195 684ef11c ljiyeon
        {
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 fa48eb85 taeseongkim
        public double CommentAngle
266 684ef11c ljiyeon
        {
267
            get { return (double)GetValue(AngleProperty); }
268
            set
269
            {
270 fa48eb85 taeseongkim
                if (this.CommentAngle != value)
271 684ef11c ljiyeon
                {
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(OverlapWhiteControl), new PropertyMetadata(null));
296
297
        public static readonly DependencyProperty mousemodeProperty =
298
                DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(OverlapWhiteControl), new PropertyMetadata(MouseMode.None, PointValueChanged));
299
300
        public static readonly DependencyProperty IsSelectedProperty =
301
          DependencyProperty.Register("IsSelected", typeof(bool), typeof(OverlapWhiteControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
302
303
        public static readonly DependencyProperty ControlTypeProperty =
304
                DependencyProperty.Register("ControlType", typeof(ControlType), typeof(OverlapWhiteControl), new FrameworkPropertyMetadata(ControlType.OverlapWhite));
305
306
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
307
                "StrokeColor", typeof(SolidColorBrush), typeof(OverlapWhiteControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
308
309
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
310
              "LineSize", typeof(double), typeof(OverlapWhiteControl), new PropertyMetadata((Double)3));
311
312
        //강인구 추가
313
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
314
                "DashSize", typeof(DoubleCollection), typeof(OverlapWhiteControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
315
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
316
               "PathData", typeof(Geometry), typeof(OverlapWhiteControl), null);
317
318
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
319
               "OverViewPathData", typeof(Geometry), typeof(OverlapWhiteControl), null);
320
321
        //강인구 추가
322
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
323
        "Paint", typeof(PaintSet), typeof(OverlapWhiteControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
324
325
326
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
327
                "FillColor", typeof(SolidColorBrush), typeof(OverlapWhiteControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
328
329
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
330
                 "CanvasX", typeof(double), typeof(OverlapWhiteControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
331
332
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
333
                "CanvasY", typeof(double), typeof(OverlapWhiteControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
334
335
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
336
               "TopRightPoint", typeof(Point), typeof(OverlapWhiteControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
337
338
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
339
                 "LeftBottomPoint", typeof(Point), typeof(OverlapWhiteControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
340
341
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
342
            "StartPoint", typeof(Point), typeof(OverlapWhiteControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
343
344
        public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(
345
        "SetPoint", typeof(Point), typeof(OverlapWhiteControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
346
347
        public static readonly DependencyProperty OriginPointProperty = DependencyProperty.Register(
348
        "OriginPoint", typeof(Point), typeof(OverlapWhiteControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
349
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
350
            "Angle", typeof(double), typeof(OverlapWhiteControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
351
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
352
         "PointSet", typeof(List<Point>), typeof(OverlapWhiteControl), new PropertyMetadata(new List<Point>()));
353
354
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
355
              "EndPoint", typeof(Point), typeof(OverlapWhiteControl), 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 = (OverlapWhiteControl)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 = (OverlapWhiteControl)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 = (OverlapWhiteControl)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 = (OverlapWhiteControl)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 = (OverlapWhiteControl)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
                //강인구 추가
434
                Base_RectPath.StrokeDashArray.Clear();
435
                if (DashSize != null)
436
                {
437
                    foreach (var item in this.DashSize)
438
                    {
439
                        Base_RectPath.StrokeDashArray.Add(item);
440
                    }
441
                    Base_RectPath.StrokeDashCap = PenLineCap.Square;
442
                }
443
444
                PathFigure pathFigure = new PathFigure
445
                {
446
                    IsClosed = true
447
                };
448
449
                if (ControlType == ControlType.OverlapWhite)
450
                {
451
                    switch (this.Paint)
452
                    {
453
                        case PaintSet.None:
454
                            this.FillColor = null;
455
                            pathFigure.IsFilled = false;
456
                            break;
457
                        default:
458
                            {
459
460
                            }
461
                            break;
462
                    }
463
                }
464
465
                pathFigure.StartPoint = this.StartPoint;
466
467
                LineSegment lineSegment1 = new LineSegment();
468
                lineSegment1.Point = this.LeftBottomPoint;
469
                pathFigure.Segments.Add(lineSegment1);
470
471
                LineSegment lineSegment2 = new LineSegment();
472
                lineSegment2.Point = this.EndPoint;
473
                pathFigure.Segments.Add(lineSegment2);
474
475
                LineSegment lineSegment3 = new LineSegment();
476
                lineSegment3.Point = this.TopRightPoint;
477
                pathFigure.Segments.Add(lineSegment3);
478
479
                LineSegment lineSegment0 = new LineSegment();
480
                lineSegment0.Point = this.StartPoint;
481
                pathFigure.Segments.Add(lineSegment0);
482
483
                PathGeometry pathGeometry = new PathGeometry();
484
                pathGeometry.Figures = new PathFigureCollection();
485
                pathGeometry.Figures.Add(pathFigure);
486
487
488
                //Base_RectPath.StrokeThickness = 3;
489
                this.FillColor = null;
490
                this.PathData = pathGeometry;
491
                ApplyOverViewData();
492
                //OverViewPathData = PathData;
493
                //AdornerControl adornerControl = new Adorner.AdornerControl();
494
                ////adornerControl
495
496
                //adornerControl.Content = pathGeometry;
497
498
            }
499
        }
500
501 f513c215 humkyung
        public override void ApplyOverViewData()
502 684ef11c ljiyeon
        {
503
            this.OverViewPathData = this.PathData;
504
        }
505
506
        #region Internal Method
507
508
509
        static OverlapWhiteControl()
510
        {
511
            DefaultStyleKeyProperty.OverrideMetadata(typeof(OverlapWhiteControl), new FrameworkPropertyMetadata(typeof(OverlapWhiteControl)));
512 a6f7f9b6 djkim
            //ResourceDictionary dictionary = new ResourceDictionary();
513
            //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
514
            //Application.Current.Resources.MergedDictionaries.Add(dictionary);
515 684ef11c ljiyeon
        }
516
517
518
        public override void OnApplyTemplate()
519
        {
520
            base.OnApplyTemplate();
521
522
            Base_RectPath = GetTemplateChild(PART_RectPath) as Path;
523
524
525
            if (Base_RectPath == null)
526
                return;
527
528
            SetRectPath();
529
            Base_RectPath.Focus();
530
        }
531
532
        public void updateControl()
533
        {
534
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
535
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
536
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
537
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
538
        }
539
540
        private void OnPropertyChanged(string name)
541
        {
542
            if (PropertyChanged != null)
543
            {
544
                PropertyChanged(this, new PropertyChangedEventArgs(name));
545
            }
546
        }
547
548
        public void ChangePaint(PaintSet state)
549
        {
550
            this.Paint = state;
551
            this.SetRectPath();
552
        }
553
554 036650a0 humkyung
        /// <summary>
555 a6272c57 humkyung
        /// call when mouse is moving while drawing control
556
        /// </summary>
557
        /// <author>humkyung</author>
558
        /// <param name="pt"></param>
559
        /// <param name="bAxisLocked"></param>
560 233ef333 taeseongkim
        public override void OnCreatingMouseMove(Point pt, bool bAxisLocked)
561 a6272c57 humkyung
        {
562 233ef333 taeseongkim
            this.EndPoint = bAxisLocked ? this.GetSquareEndPoint(this.StartPoint, pt) : pt;
563 a6272c57 humkyung
            this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y);
564
            this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y);
565
566
            this.PointSet = new List<Point>
567
            {
568
                this.StartPoint,
569
                this.LeftBottomPoint,
570
                this.EndPoint,
571
                this.TopRightPoint,
572
            };
573
574
            this.updateControl();
575
        }
576
577
        /// <summary>
578 91efe37a humkyung
        /// return OverlapWhiteControl's area
579
        /// </summary>
580
        /// <author>humkyung</author>
581
        /// <date>2019.06.13</date>
582
        public override Rect ItemRect
583
        {
584
            get
585
            {
586
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
587
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
588
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
589
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
590
591
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
592
            }
593
        }
594
595
        /// <summary>
596 036650a0 humkyung
        /// Serialize this
597
        /// </summary>
598
        /// <param name="sUserId"></param>
599
        /// <returns></returns>
600
        public override string Serialize()
601
        {
602
            using (S_OverlapWhiteControl STemp = new S_OverlapWhiteControl())
603
            {
604
                STemp.TransformPoint = "0|0";
605
                STemp.SizeSet = String.Format("{0}", this.LineSize);
606
                STemp.PaintState = this.Paint;
607
                STemp.PointSet = this.PointSet;
608
                //STemp.StrokeColor = "#FF00FF00";
609
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
610
                if (this.FillColor != null)
611
                {
612
                    STemp.FillColor = this.FillColor.Color.ToString();
613
                }
614
                STemp.StartPoint = this.StartPoint;
615
                STemp.UserID = this.UserID;
616
                STemp.EndPoint = this.EndPoint;
617
                STemp.LB = this.LeftBottomPoint;
618
                STemp.TR = this.TopRightPoint;
619
                STemp.DashSize = this.DashSize;
620
                STemp.Opac = this.Opacity;
621
                STemp.Name = this.GetType().Name.ToString();
622
                STemp.Memo = this.Memo;
623
624
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
625
            };
626
        }
627
628 661b7416 humkyung
        /// <summary>
629
        /// create a OverlapWhiteControl from given string
630
        /// </summary>
631
        /// <param name="str"></param>
632
        /// <returns></returns>
633
        public static OverlapWhiteControl FromString(string str, SolidColorBrush brush, string sProjectNo)
634
        {
635
            using (S_OverlapWhiteControl s = JsonSerializerHelper.JsonDeserialize<S_OverlapWhiteControl>(str))
636
            {
637
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
638
                return new OverlapWhiteControl
639
                {
640
                    LineSize = Convert.ToDouble(data2.First()),
641
                    Paint = s.PaintState,
642
                    StartPoint = s.StartPoint,
643
                    EndPoint = s.EndPoint,
644 fa48eb85 taeseongkim
                    CommentAngle = s.Angle,
645 661b7416 humkyung
                    StrokeColor = Brushes.White,
646
                    DashSize = s.DashSize,
647
                    Opacity = s.Opac,
648
                    LeftBottomPoint = s.LB,
649
                    TopRightPoint = s.TR,
650
                    PointSet = s.PointSet,
651
                    UserID = s.UserID,
652
                    FillColor = Brushes.White,
653
                    Memo = s.Memo
654
                };
655
            }
656
        }
657
658 684ef11c ljiyeon
        public event PropertyChangedEventHandler PropertyChanged;
659
660
        public void Dispose()
661
        {
662 a6f7f9b6 djkim
            //GC.Collect();
663 24c5e56c taeseongkim
            ////GC.SuppressFinalize(this);
664 a6f7f9b6 djkim
            this.Base_RectPath = null;
665 684ef11c ljiyeon
        }
666
        #endregion Internal Method
667
    }
668
}
클립보드 이미지 추가 (최대 크기: 500 MB)