프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Line / ArrowControl_Multi.cs @ b3fb7321

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

    
16
namespace MarkupToPDF.Controls.Line
17
{
18

    
19
    public class ArrowControl_Multi : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
20
    {
21

    
22
        public event PropertyChangedEventHandler PropertyChanged;
23
        private const string PART_ArrowMultiPath = "PART_ArrowMultiPath";
24
        public Path Base_ArrowMultiPath = null;
25

    
26
        static ArrowControl_Multi()
27
        {
28
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(typeof(ArrowControl_Multi)));
29
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
30
            ResourceDictionary dictionary = new ResourceDictionary();
31
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
32
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
33
            System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
34
        }
35

    
36
        public ArrowControl_Multi()
37
        {
38
            this.DefaultStyleKey = typeof(ArrowControl_Multi);
39
        }
40
      
41
        #region Dependency Properties
42

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

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

    
49
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
50
                "OverViewPathData", typeof(Geometry), typeof(ArrowControl_Multi), new PropertyMetadata(null));
51

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

    
58
        public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register(
59
               "DashSize", typeof(DoubleCollection), typeof(ArrowControl_Multi), new PropertyMetadata(new DoubleCollection { 99999099 }, PointValueChanged));
60

    
61
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
62
              "StrokeColor", typeof(SolidColorBrush), typeof(ArrowControl_Multi), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
63

    
64
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
65
              "PathData", typeof(Geometry), typeof(ArrowControl_Multi), null);
66

    
67
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
68
               "StartPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged));
69

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

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

    
80
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
81
        {
82
            //var instance = (ArrowControl_Multi)sender;
83

    
84
            //if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null)
85
            //{
86

    
87
            //    instance.SetValue(e.Property, e.NewValue);
88

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

    
100

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

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

    
149
        public bool IsSelected
150
        {
151
            get
152
            {
153
                return (bool)GetValue(IsSelectedProperty);
154
            }
155
            set
156
            {
157
                SetValue(IsSelectedProperty, value);
158
            }
159
        }
160

    
161
        public ControlType ControlType
162
        {
163
            get
164
            {
165
                return (ControlType)GetValue(ControlTypeProperty);
166
            }
167
            set
168
            {
169
                SetValue(ControlTypeProperty, value);
170
            }
171
        }
172

    
173

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

    
236
        public void ApplyOverViewData()
237
        {
238
            this.OverViewPathData = this.PathData;
239
        }
240

    
241
        public void SetArrowMultiPath()
242
        {
243

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

    
254
            pathFigure.StartPoint = this.StartPoint;
255
            LineSegment lineSegment0 = new LineSegment();
256
            lineSegment0.Point = this.StartPoint;
257
            pathFigure.Segments.Add(lineSegment0);
258

    
259
            
260

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

    
275
            LineSegment lineSegment2 = new LineSegment();
276
            lineSegment2.Point = this.EndPoint;
277
            pathFigure.Segments.Add(lineSegment2);
278

    
279
            PathGeometry pathGeometry = new PathGeometry();
280
            pathGeometry.Figures.Add(pathFigure);
281
            pathFigure.IsFilled = false;
282
            instanceGroup.Children.Add(pathGeometry);
283
            //this.Base_ArrowMultiPath.Stroke = this.StrokeColor;
284

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

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

    
304
        //    Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
305
        //    Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
306

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

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

    
313
        //    LineSegment seg1 = new LineSegment();
314
        //    seg1.Point = lpoint;
315
        //    pathFigure.Segments.Add(seg1);
316

    
317
        //    LineSegment seg2 = new LineSegment();
318
        //    seg2.Point = rpoint;
319
        //    pathFigure.Segments.Add(seg2);
320

    
321
        //    LineSegment seg3 = new LineSegment();
322
        //    seg3.Point = p1;
323
        //    pathFigure.Segments.Add(seg3);
324

    
325
        //    pathFigure.IsClosed = true;
326
        //    pathFigure.IsFilled = true;
327

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

    
338
        public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize)
339
        {
340
            double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;
341
            PathGeometry pathGeometry = new PathGeometry();
342
            PathFigure pathFigure = new PathFigure();
343
            pathFigure.StartPoint = p1;
344
            //lineSize = 2;
345
            Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6);
346
            Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6);
347

    
348
            LineSegment seg1 = new LineSegment();
349
            seg1.Point = lpoint;
350
            pathFigure.Segments.Add(seg1);
351

    
352
            LineSegment seg2 = new LineSegment();
353
            seg2.Point = rpoint;
354
            pathFigure.Segments.Add(seg2);
355

    
356
            LineSegment seg3 = new LineSegment();
357
            seg3.Point = p1;
358
            pathFigure.Segments.Add(seg3);
359

    
360
            pathFigure.IsClosed = true;
361
            pathFigure.IsFilled = true;
362

    
363
            pathGeometry.Figures.Add(pathFigure);
364
            pathGeometry.FillRule = FillRule.Nonzero;
365
            RotateTransform transform = new RotateTransform();
366
            transform.Angle = theta - 90;
367
            transform.CenterX = p1.X;
368
            transform.CenterY = p1.Y;
369
            pathGeometry.Transform = transform;
370
            return pathGeometry;
371
        }
372
        protected void OnPropertyChanged(string propName)
373
        {
374
            if (PropertyChanged != null)
375
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
376
        }
377
        public void updateControl()
378
        {
379
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
380
            this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
381
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
382
        }
383
        public void Dispose()
384
        {
385
            GC.Collect();
386
            GC.SuppressFinalize(this);
387
        }
388
    }
389
}
390

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