프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Shape / TriControl.cs @ 4913851c

이력 | 보기 | 이력해설 | 다운로드 (18 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.Core;
16
using MarkupToPDF.Serialize.S_Control;
17
using System.Linq;
18

    
19
namespace MarkupToPDF.Controls.Shape
20
{
21
    //[TemplatePart(Name = "PART_TriPath", Type = typeof(Path))]
22
    public class TriControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IMarkupCommonData, IShapeControl, IDashControl
23
    {
24
        public Path Base_TriPath { get; set; }
25
        //public enum PaintSet { None, Fill, Hatch };
26
        private const string PART_TriPath = "PART_TriPath";
27

    
28
        //public Path Base_TriPath = null;
29

    
30
        static TriControl()
31
        {
32
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TriControl), new FrameworkPropertyMetadata(typeof(TriControl)));
33
            ResourceDictionary dictionary = new ResourceDictionary();
34
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
35
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
36
        }
37

    
38
        #region Dependency Properties
39

    
40
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
41
        "OverViewPathData", typeof(Geometry), typeof(TriControl), new PropertyMetadata(null));
42

    
43
        public static readonly DependencyProperty IsSelectedProperty =
44
      DependencyProperty.Register("IsSelected", typeof(bool), typeof(TriControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
45

    
46
        public static readonly DependencyProperty ControlTypeProperty =
47
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TriControl), new FrameworkPropertyMetadata(ControlType.Triangle));
48

    
49
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
50
         "LineSize", typeof(double), typeof(TriControl), new PropertyMetadata((Double)3));
51
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
52
                "UserID", typeof(string), typeof(TriControl), new PropertyMetadata(null));
53
        //강인구 추가
54
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
55
              "DashSize", typeof(DoubleCollection), typeof(TriControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged));
56
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
57
        "PathData", typeof(Geometry), typeof(TriControl), null);
58
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
59
         "StrokeColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
60
        public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register(
61
         "FillColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
62
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
63
            "EndPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
64
        public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register(
65
            "MidPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
66
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
67
            "StartPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
68
        //강인구 추가
69
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
70
                "Paint", typeof(PaintSet), typeof(TriControl), new PropertyMetadata(PaintSet.None, PointValueChanged));
71

    
72
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
73
            "PointSet", typeof(List<Point>), typeof(TriControl), new PropertyMetadata(new List<Point>(), PointValueChanged));
74
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(TriControl), new
75
            PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
76
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(TriControl),
77
            new PropertyMetadata((double)0, OnCenterXYChanged));
78

    
79
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(TriControl),
80
            new PropertyMetadata((double)0, OnCenterXYChanged));
81

    
82
        #endregion
83
        #region PropertyChanged Method
84

    
85
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
86
        {
87
            //var instance = (TriControl)sender;
88

    
89
            //if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
90
            //{
91

    
92
            //    instance.SetValue(e.Property, e.NewValue);
93

    
94
            //    if (instance.IsSelected)
95
            //    {
96
            //        instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
97
            //    }
98
            //    else
99
            //    {
100
            //        instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
101
            //    }
102
            //}
103
        }
104

    
105
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
106
        {
107
            var instance = (TriControl)sender;
108

    
109
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
110
            {
111
                instance.SetValue(e.Property, e.NewValue);
112
                instance.SetTri();
113
            }
114
        }
115

    
116

    
117
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
118
        {
119
            var instance = (TriControl)sender;
120
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
121
            {
122
                instance.SetValue(e.Property, e.NewValue);
123
                instance.SetTri();
124
            }
125
        }
126
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
127
        {
128
            var instance = (TriControl)sender;
129
            if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
130
            {
131
                instance.SetValue(e.Property, e.NewValue);
132
                instance.SetTri();
133
            }
134
        }
135
        #endregion
136
        #region Properties
137

    
138
        public Double LineSize
139
        {
140
            get { return (Double)GetValue(LineSizeProperty); }
141
            set
142
            {
143
                if (this.LineSize != value)
144
                {
145
                    SetValue(LineSizeProperty, value);
146
                }
147
            }
148
        }
149
        public string UserID
150
        {
151
            get { return (string)GetValue(UserIDProperty); }
152
            set
153
            {
154
                if (this.UserID != value)
155
                {
156
                    SetValue(UserIDProperty, value);
157
                    OnPropertyChanged("UserID");
158
                }
159
            }
160
        }
161
        public SolidColorBrush FillColor
162
        {
163
            get { return (SolidColorBrush)GetValue(FillColorProperty); }
164
            set
165
            {
166
                if (this.FillColor != value)
167
                {
168
                    SetValue(FillColorProperty, value);
169
                }
170
            }
171
        }
172
        public DoubleCollection DashSize
173
        {
174
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
175
            set
176
            {
177
                if (this.DashSize != value)
178
                {
179
                    SetValue(DashSizeProperty, value);
180
                }
181
            }
182
        }
183
        public PaintSet Paint
184
        {
185
            get { return (PaintSet)GetValue(PaintProperty); }
186
            set
187
            {
188
                if (this.Paint != value)
189
                {
190
                    SetValue(PaintProperty, value);
191
                }
192
            }
193
        }
194

    
195

    
196
        public override SolidColorBrush StrokeColor
197
        {
198
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
199
            set
200
            {
201
                if (this.StrokeColor != value)
202
                {
203
                    SetValue(StrokeColorProperty, value);
204
                }
205
            }
206
        }
207
        public Geometry OverViewPathData
208
        {
209
            get
210
            {
211
                return (Geometry)GetValue(OverViewPathDataProperty);
212
            }
213
            set
214
            {
215
                SetValue(OverViewPathDataProperty, value);
216
                OnPropertyChanged("OverViewPathData");
217
            }
218
        }
219
        public Geometry PathData
220
        {
221
            get { return (Geometry)GetValue(PathDataProperty); }
222
            set { SetValue(PathDataProperty, value); }
223
        }
224
        public Point EndPoint
225
        {
226
            get { return (Point)GetValue(EndPointProperty); }
227
            set { SetValue(EndPointProperty, value); }
228
        }
229
        public Point StartPoint
230
        {
231
            get { return (Point)GetValue(StartPointProperty); }
232
            set { SetValue(StartPointProperty, value); }
233
        }
234
        public Point MidPoint
235
        {
236
            get { return (Point)GetValue(MidPointProperty); }
237
            set { SetValue(MidPointProperty, value); }
238
        }
239
        public List<Point> PointSet
240
        {
241
            get { return (List<Point>)GetValue(PointSetProperty); }
242
            set { SetValue(PointSetProperty, value); }
243
        }
244

    
245
        public override bool IsSelected
246
        {
247
            get
248
            {
249
                return (bool)GetValue(IsSelectedProperty);
250
            }
251
            set
252
            {
253
                SetValue(IsSelectedProperty, value);
254
            }
255
        }
256

    
257
        public override ControlType ControlType
258
        {
259
            get
260
            {
261
                return (ControlType)GetValue(ControlTypeProperty);
262
            }
263
            set
264
            {
265
                SetValue(ControlTypeProperty, value);
266
            }
267
        }
268

    
269

    
270
        public double Angle
271
        {
272
            get { return (double)GetValue(AngleProperty); }
273
            set
274
            {
275
                if (this.Angle != value)
276
                {
277
                    SetValue(AngleProperty, value);
278
                }
279
            }
280
        }
281
        public double CenterX
282
        {
283
            get { return (double)GetValue(CenterXProperty); }
284
            set { SetValue(CenterXProperty, value); }
285
        }
286
        public double CenterY
287
        {
288
            get { return (double)GetValue(CenterYProperty); }
289
            set { SetValue(CenterYProperty, value); }
290
        }
291
        #endregion
292

    
293
        #region Dependency PropertyChanged
294
        //public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
295
        //{
296
        //    var instance = (TriControl)sender;
297

    
298
        //    if (e.OldValue != e.NewValue && instance.Base_TriPath != null)
299
        //    {
300

    
301
        //        instance.SetValue(e.Property, e.NewValue);
302

    
303
        //        if (instance.IsSelected)
304
        //        {
305
        //            instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue);
306
        //        }
307
        //        else
308
        //        {
309
        //            instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red);
310
        //        }
311
        //    }
312
        //}
313

    
314
        #endregion Dependency PropertyChanged
315

    
316
        public override void OnApplyTemplate()
317
        {
318
            base.OnApplyTemplate();
319
            Base_TriPath = GetTemplateChild(PART_TriPath) as Path;
320

    
321
            if (Base_TriPath == null)
322
            {
323
                return;
324
            }
325

    
326
            this.SetTri();
327
        }
328

    
329
        private void SetTri()
330
        {
331
            this.ApplyTemplate();
332
            Base_TriPath.StrokeDashArray.Clear();
333
            foreach (var item in this.DashSize)
334
            {
335
                Base_TriPath.StrokeDashArray.Add(item);
336
            }
337
            Base_TriPath.StrokeDashCap = PenLineCap.Square;
338
            PathFigure pathFigure = new PathFigure();
339

    
340
            //this.FillColor = this.StrokeColor;
341
            ////Base_TriPath.Fill = this.FillColor;
342
            //Base_TriPath.Fill = Brushes.Red;
343
            //pathFigure.IsFilled = true;
344

    
345
            switch (this.Paint)
346
            {
347
                case PaintSet.None:
348
                    this.FillColor = null;
349
                    pathFigure.IsFilled = false;
350
                    break;
351
                case PaintSet.Fill:
352
                    this.FillColor = this.StrokeColor;
353
                    Base_TriPath.Fill = this.FillColor;
354
                    pathFigure.IsFilled = true;
355
                    break;
356
                case PaintSet.Hatch:
357
                    Base_TriPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor);
358
                    pathFigure.IsFilled = true;
359
                    break;
360
                default:
361
                    break;
362
            }
363
            pathFigure.StartPoint = this.StartPoint;
364

    
365
            List<Point> points = new List<Point>() { this.StartPoint };
366
            if (MidPoint.X != 0 && MidPoint.Y != 0) points.Add(this.MidPoint);
367
            points.Add(this.EndPoint);
368

    
369
            PolyLineSegment polyline = new PolyLineSegment(points , true);
370
            pathFigure.Segments.Add(polyline);
371

    
372
            PathGeometry pathGeometry = new PathGeometry();
373
            pathGeometry.Figures = new PathFigureCollection();
374
            pathFigure.IsClosed = true;
375
            pathGeometry.Figures.Add(pathFigure);
376

    
377
            this.PathData = pathGeometry;
378
            ApplyOverViewData();
379

    
380
        }
381
        public void Dispose()
382
        {
383
            GC.Collect();
384
            GC.SuppressFinalize(this);
385
        }
386
        public event PropertyChangedEventHandler PropertyChanged;
387
        protected void OnPropertyChanged(string propName)
388
        {
389
            if (PropertyChanged != null)
390
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
391
        }
392

    
393
        public void ApplyOverViewData()
394
        {
395
            this.OverViewPathData = this.PathData;
396
        }
397

    
398
        public void updateControl()
399
        {
400
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
401
            this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
402
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
403
        }
404

    
405
        /// <summary>
406
        /// return tricontrols' area
407
        /// </summary>
408
        /// <author>humkyung</author>
409
        /// <date>2019.06.13</date>
410
        public override Rect ItemRect
411
        {
412
            get
413
            {
414
                double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X);
415
                dMinX = Math.Min(this.MidPoint.X, dMinX);
416
                double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y);
417
                dMinY = Math.Min(this.MidPoint.Y, dMinY);
418
                double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X);
419
                dMaxX = Math.Max(this.MidPoint.X, dMaxX);
420
                double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y);
421
                dMaxY = Math.Max(this.MidPoint.Y, dMaxY);
422

    
423
                return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY));
424
            }
425
        }
426

    
427
        /// <summary>
428
        /// Serialize this
429
        /// </summary>
430
        /// <param name="sUserId"></param>
431
        /// <returns></returns>
432
        public override string Serialize()
433
        {
434
            using (S_TriControl STemp = new S_TriControl())
435
            {
436
                STemp.TransformPoint = "0|0";
437
                STemp.Paint = this.Paint;
438
                STemp.SizeSet = String.Format("{0}", this.LineSize);
439
                //STemp.StrokeColor = "#FF00FF00";
440
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
441
                if (this.FillColor != null)
442
                {
443
                    STemp.FillColor = this.FillColor.Color.ToString();
444
                }
445
                STemp.StartPoint = this.StartPoint;
446
                STemp.EndPoint = this.EndPoint;
447
                STemp.MidPoint = this.MidPoint;
448
                STemp.Opac = this.Opacity;
449
                STemp.UserID = this.UserID;
450
                STemp.PointSet = this.PointSet;
451
                STemp.Angle = this.Angle;
452
                STemp.DashSize = this.DashSize;
453
                STemp.Name = this.GetType().Name.ToString();
454
                ///강인구 추가(2017.11.02)
455
                ///Memo 추가
456
                STemp.Memo = this.Memo;
457

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

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

    
490
        //public void ChangePaint(PaintSet state)
491
        //{
492
        //    this.Paint = state;
493
        //    this.SetTri();
494
        //}
495
    }
496
}
클립보드 이미지 추가 (최대 크기: 500 MB)