프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowControl_Multi.cs @ 959b3ef2

이력 | 보기 | 이력해설 | 다운로드 (15.6 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

    
22
    public class ArrowControl_Multi : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
23
    {
24

    
25
        public event PropertyChangedEventHandler PropertyChanged;
26
        private const string PART_ArrowMultiPath = "PART_ArrowMultiPath";
27
        public Path Base_ArrowMultiPath = null;
28

    
29
        static ArrowControl_Multi()
30
        {
31
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(typeof(ArrowControl_Multi)));
32
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
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
            System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
37
        }
38

    
39
        public ArrowControl_Multi()
40
        {
41
            this.DefaultStyleKey = typeof(ArrowControl_Multi);
42
        }
43
      
44
        #region Dependency Properties
45

    
46
        public static readonly DependencyProperty IsSelectedProperty =
47
DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(false, IsSelectedChanged));
48

    
49
        public static readonly DependencyProperty ControlTypeProperty =
50
    DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(ControlType.ArrowMultiLine));
51

    
52
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
53
                "OverViewPathData", typeof(Geometry), typeof(ArrowControl_Multi), new PropertyMetadata(null));
54

    
55
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
56
                "UserID", typeof(string), typeof(ArrowControl_Multi), new PropertyMetadata(null));
57
				
58
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
59
              "LineSize", typeof(double), typeof(ArrowControl_Multi), new PropertyMetadata((Double)3, PointValueChanged));
60

    
61
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
62
               "DashSize", typeof(DoubleCollection), typeof(ArrowControl_Multi), new PropertyMetadata(new DoubleCollection { 99999099 }, PointValueChanged));
63

    
64
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
65
              "StrokeColor", typeof(SolidColorBrush), typeof(ArrowControl_Multi), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
66

    
67
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
68
              "PathData", typeof(Geometry), typeof(ArrowControl_Multi), null);
69

    
70
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
71
               "StartPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
72

    
73
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
74
               "EndPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(100, 100), PointValueChanged));
75
        public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register(
76
                "MiddlePoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
77

    
78
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
79
               "PointSet", typeof(List<Point>), typeof(ArrowControl_Multi), new PropertyMetadata(new List<Point>(), PointValueChanged));
80
        #endregion
81
        #region PropertyChanged Method
82

    
83
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
84
        {
85
            //var instance = (ArrowControl_Multi)sender;
86

    
87
            //if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
88
            //{
89

    
90
            //    instance.SetValue(e.Property, e.NewValue);
91

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

    
103

    
104
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
105
        {
106
            var instance = (ArrowControl_Multi)sender;
107
            if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
108
            {
109
                instance.SetValue(e.Property, e.NewValue);
110
                instance.SetArrowMultiPath();
111
            }
112
        }
113
        #endregion
114
        #region Properties
115
        public string UserID
116
        {
117
            get { return (string)GetValue(UserIDProperty); }
118
            set
119
            {
120
                if (this.UserID != value)
121
                {
122
                    SetValue(UserIDProperty, value);
123
                    OnPropertyChanged("UserID");
124
                }
125
            }
126
        }
127
        public Double LineSize
128
        {
129
            get { return (Double)GetValue(LineSizeProperty); }
130
            set
131
            {
132
                if (this.LineSize != value)
133
                {
134
                    SetValue(LineSizeProperty, value);
135
                }
136
            }
137
        }
138

    
139
        public Geometry OverViewPathData
140
        {
141
            get
142
            {
143
                return (Geometry)GetValue(OverViewPathDataProperty);
144
            }
145
            set
146
            {
147
                SetValue(OverViewPathDataProperty, value);
148
                OnPropertyChanged("OverViewPathData");
149
            }
150
        }
151

    
152
        public override bool IsSelected
153
        {
154
            get
155
            {
156
                return (bool)GetValue(IsSelectedProperty);
157
            }
158
            set
159
            {
160
                SetValue(IsSelectedProperty, value);
161
            }
162
        }
163

    
164
        public override ControlType ControlType
165
        {
166
            get
167
            {
168
                return (ControlType)GetValue(ControlTypeProperty);
169
            }
170
            set
171
            {
172
                SetValue(ControlTypeProperty, value);
173
            }
174
        }
175

    
176

    
177
        public DoubleCollection DashSize
178
        {
179
            get { return (DoubleCollection)GetValue(DashSizeProperty); }
180
            set
181
            {
182
                if (this.DashSize != value)
183
                {
184
                    SetValue(DashSizeProperty, value);
185
                }
186
            }
187
        }
188
        public List<Point> PointSet
189
        {
190
            get { return (List<Point>)GetValue(PointSetProperty); }
191
            set { SetValue(PointSetProperty, value); }
192
        }
193
        public SolidColorBrush StrokeColor
194
        {
195
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
196
            set
197
            {
198
                if (this.StrokeColor != value)
199
                {
200
                    SetValue(StrokeColorProperty, value);
201
                }
202
            }
203
        }
204
        public Geometry PathData
205
        {
206
            get { return (Geometry)GetValue(PathDataProperty); }
207
            set { SetValue(PathDataProperty, value); }
208
        }
209
        public Point EndPoint
210
        {
211
            get { return (Point)GetValue(EndPointProperty); }
212
            set { SetValue(EndPointProperty, value); }
213
        }
214
        public Point StartPoint
215
        {
216
            get { return (Point)GetValue(StartPointProperty); }
217
            set { SetValue(StartPointProperty, value); }
218
        }
219
        public Point MiddlePoint
220
        {
221
            get { return (Point)GetValue(MiddlePointProperty); }
222
            set
223
            {
224
                SetValue(MiddlePointProperty, value);
225
                OnPropertyChanged("MiddlePoint");
226
            }
227
        }
228
        #endregion
229
        #region Object & Variable
230
        GeometryGroup instanceGroup = new GeometryGroup();
231
        #endregion
232
        public override void OnApplyTemplate()
233
        {
234
            base.OnApplyTemplate();
235
            Base_ArrowMultiPath = GetTemplateChild(PART_ArrowMultiPath) as Path;
236
            SetArrowMultiPath();
237
        }
238

    
239
        public void ApplyOverViewData()
240
        {
241
            this.OverViewPathData = this.PathData;
242
        }
243

    
244
        public void SetArrowMultiPath()
245
        {
246

    
247
            
248
            Base_ArrowMultiPath.StrokeDashArray.Clear();
249
            foreach (var item in this.DashSize)
250
            {
251
                Base_ArrowMultiPath.StrokeDashArray.Add(item);
252
            }
253
            Base_ArrowMultiPath.StrokeDashCap = PenLineCap.Square;
254
            instanceGroup.Children.Clear();
255
            PathFigure pathFigure = new PathFigure();
256

    
257
            pathFigure.StartPoint = this.StartPoint;
258
            LineSegment lineSegment0 = new LineSegment();
259
            lineSegment0.Point = this.StartPoint;
260
            pathFigure.Segments.Add(lineSegment0);
261

    
262
            
263

    
264
            //if (this.EndPoint == this.MiddlePoint)
265
            if (this.MiddlePoint == new Point(0,0))
266
            {
267
                //instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.MiddlePoint, this.LineSize));
268
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize));
269
            }
270
            else
271
            {
272
                instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.EndPoint, this.LineSize));
273
                LineSegment lineSegment1 = new LineSegment();
274
                lineSegment1.Point = this.MiddlePoint;
275
                pathFigure.Segments.Add(lineSegment1);
276
            }
277

    
278
            LineSegment lineSegment2 = new LineSegment();
279
            lineSegment2.Point = this.EndPoint;
280
            pathFigure.Segments.Add(lineSegment2);
281

    
282
            PathGeometry pathGeometry = new PathGeometry();
283
            pathGeometry.Figures.Add(pathFigure);
284
            pathFigure.IsFilled = false;
285
            instanceGroup.Children.Add(pathGeometry);
286
            //this.Base_ArrowMultiPath.Stroke = this.StrokeColor;
287

    
288
            //if (this.IsSelected)
289
            //{
290
            //    Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue);
291
            //}
292
            //else
293
            //{
294
            //    Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red);
295
            //}
296

    
297
            this.PathData = instanceGroup;
298
            OverViewPathData = PathData;
299
        }
300
        //public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize)
301
        //{
302
        //    double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
303
        //    PathGeometry pathGeometry = new PathGeometry();
304
        //    PathFigure pathFigure = new PathFigure();
305
        //    pathFigure.StartPoint = p1;
306

    
307
        //    Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
308
        //    Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
309

    
310
        //    //Point lpoint = new Point(p1.X + lineSize, p1.Y + lineSize * 4);
311
        //    //Point rpoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4);
312

    
313
        //    //Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
314
        //    //Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
315

    
316
        //    LineSegment seg1 = new LineSegment();
317
        //    seg1.Point = lpoint;
318
        //    pathFigure.Segments.Add(seg1);
319

    
320
        //    LineSegment seg2 = new LineSegment();
321
        //    seg2.Point = rpoint;
322
        //    pathFigure.Segments.Add(seg2);
323

    
324
        //    LineSegment seg3 = new LineSegment();
325
        //    seg3.Point = p1;
326
        //    pathFigure.Segments.Add(seg3);
327

    
328
        //    pathFigure.IsClosed = true;
329
        //    pathFigure.IsFilled = true;
330

    
331
        //    pathGeometry.Figures.Add(pathFigure);
332
        //    pathGeometry.FillRule = FillRule.Nonzero;
333
        //    RotateTransform transform = new RotateTransform();
334
        //    transform.Angle = theta - 90;
335
        //    transform.CenterX = p1.X;
336
        //    transform.CenterY = p1.Y;
337
        //    pathGeometry.Transform = transform;
338
        //    return pathGeometry;
339
        //}
340

    
341
        protected void OnPropertyChanged(string propName)
342
        {
343
            if (PropertyChanged != null)
344
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
345
        }
346
        public 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
        /// Serialize this
355
        /// </summary>
356
        /// <param name="sUserId"></param>
357
        /// <returns></returns>
358
        public override string Serialize()
359
        {
360
            using (S_ArrowControl_Multi STemp = new S_ArrowControl_Multi())
361
            {
362
                STemp.TransformPoint = "0|0";
363
                STemp.PointSet = this.PointSet;
364
                STemp.SizeSet = String.Format("{0}", this.LineSize);
365
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
366
                STemp.StartPoint = this.StartPoint;
367
                STemp.EndPoint = this.EndPoint;
368
                STemp.UserID = this.UserID;
369
                STemp.Opac = this.Opacity;
370
                STemp.DashSize = this.DashSize;
371
                STemp.MidPoint = this.MiddlePoint;
372
                STemp.Name = this.GetType().Name.ToString();
373

    
374
                ///강인구 추가(2017.11.02)
375
                ///Memo 추가
376
                STemp.Memo = this.Memo;
377

    
378
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
379
            };
380
        }
381

    
382
        /// <summary>
383
        /// create a arrowcontrol_multi from given string
384
        /// </summary>
385
        /// <param name="str"></param>
386
        /// <returns></returns>
387
        public static ArrowControl_Multi FromString(string str, SolidColorBrush brush, string sProjectNo)
388
        {
389
            ArrowControl_Multi instance = null;
390
            using (S_ArrowControl_Multi s = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(str))
391
            {
392
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
393
                instance = new ArrowControl_Multi
394
                {
395
                    LineSize = Convert.ToDouble(data2.First()),
396
                    StartPoint = s.StartPoint,
397
                    MiddlePoint = s.MidPoint,
398
                    DashSize = s.DashSize,
399
                    EndPoint = s.EndPoint,
400
                    PointSet = s.PointSet,
401
                    Opacity = s.Opac,
402
                    StrokeColor = brush,
403
                    UserID = s.UserID,
404
                    Memo = s.Memo
405
                };
406
            }
407

    
408
            return instance;
409
        }
410

    
411
        public void Dispose()
412
        {
413
            GC.Collect();
414
            GC.SuppressFinalize(this);
415
        }
416
    }
417
}
418

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