프로젝트

일반

사용자정보

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

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

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

    
18
namespace MarkupToPDF.Controls.Line
19
{
20
    public class ArrowControl_Multi : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl
21
    {
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
101

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

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

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

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

    
174

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

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

    
242
        public void SetArrowMultiPath()
243
        {
244

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

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

    
260
            
261

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

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

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

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

    
295
            this.PathData = instanceGroup;
296
            OverViewPathData = PathData;
297
        }
298

    
299
        protected void OnPropertyChanged(string propName)
300
        {
301
            if (PropertyChanged != null)
302
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
303
        }
304
        public void updateControl()
305
        {
306
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
307
            this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
308
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
309
        }
310

    
311
        /// <summary>
312
        /// Serialize this
313
        /// </summary>
314
        /// <param name="sUserId"></param>
315
        /// <returns></returns>
316
        public override string Serialize()
317
        {
318
            using (S_ArrowControl_Multi STemp = new S_ArrowControl_Multi())
319
            {
320
                STemp.TransformPoint = "0|0";
321
                STemp.PointSet = this.PointSet;
322
                STemp.SizeSet = String.Format("{0}", this.LineSize);
323
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
324
                STemp.StartPoint = this.StartPoint;
325
                STemp.EndPoint = this.EndPoint;
326
                STemp.UserID = this.UserID;
327
                STemp.Opac = this.Opacity;
328
                STemp.DashSize = this.DashSize;
329
                STemp.MidPoint = this.MiddlePoint;
330
                STemp.Name = this.GetType().Name.ToString();
331

    
332
                ///강인구 추가(2017.11.02)
333
                ///Memo 추가
334
                STemp.Memo = this.Memo;
335

    
336
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
337
            };
338
        }
339

    
340
        public void Dispose()
341
        {
342
            GC.Collect();
343
            GC.SuppressFinalize(this);
344
        }
345
    }
346
}
347

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