프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Etc / SymControl.cs @ a4e5d148

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

1 787a4489 KangIngu
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 036650a0 humkyung
using MarkupToPDF.Serialize.Core;
16
using MarkupToPDF.Serialize.S_Control;
17 787a4489 KangIngu
18
namespace MarkupToPDF.Controls.Etc
19
{
20
    [TemplatePart(Name = "PART_SymPath", Type = typeof(Path))]
21
    [TemplatePart(Name = "PART_ViewBox", Type = typeof(Viewbox))]
22
23
    public class SymControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IViewBox, IMarkupCommonData
24
    {
25
        #region 초기선언
26
        public enum SymStyleSet { None, Fill };
27
        private const string PART_ViewBox = "PART_ViewBox";
28
        private const string PART_SymPath = "PART_SymPath";
29
        public Viewbox Base_ViewBox = null;
30
        public Path Base_SymPath = null;
31
        #endregion
32
33
        static SymControl()
34
        {
35
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SymControl), new FrameworkPropertyMetadata(typeof(SymControl)));
36
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
37
            ResourceDictionary dictionary = new ResourceDictionary();
38
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
39
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
40
            System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
41
        }
42
43
        public void Dispose()
44
        {
45
            GC.Collect();
46
            GC.SuppressFinalize(this);
47
        }
48
        public event PropertyChangedEventHandler PropertyChanged;
49
        protected void RaisePropertyChanged(string propName)
50
        {
51
            if (PropertyChanged != null)
52
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
53
        }
54
        #region Dependency Properties
55
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
56
                "UserID", typeof(string), typeof(SymControl), new PropertyMetadata(null));
57
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
58
                "LineSize", typeof(double), typeof(SymControl), new PropertyMetadata((Double)1));
59
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
60
                "StrokeColor", typeof(SolidColorBrush), typeof(SymControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
61
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
62
                "PathData", typeof(Geometry), typeof(SymControl), null);
63
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
64
                "EndPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
65
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
66
                "StartPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
67
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
68
                "TopRightPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), TRPointValueChanged));
69
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
70
                 "LeftBottomPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), LBPointValueChanged));
71
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
72
                 "PointSet", typeof(List<Point>), typeof(SymControl), new PropertyMetadata(new List<Point>()));
73
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(SymControl),
74
            new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
75
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(SymControl),
76
            new PropertyMetadata((double)0, OnCenterXYChanged));
77
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(SymControl),
78
            new PropertyMetadata((double)0, OnCenterXYChanged));
79
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
80
                "Paint", typeof(PaintSet), typeof(SymControl), new PropertyMetadata(PaintSet.None));
81
82
        public static readonly DependencyProperty IsSelectedProperty =
83
     DependencyProperty.Register("IsSelected", typeof(bool), typeof(SymControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
84
85
        public static readonly DependencyProperty ControlTypeProperty =
86
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(SymControl), new FrameworkPropertyMetadata(ControlType.Symbol));
87
        #endregion
88
        #region PropertyChanged Method
89
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
90
        {
91
            var instance = (SymControl)sender;
92
            if (e.OldValue != e.NewValue && instance.Base_SymPath != null)
93
            {
94
                instance.SetValue(e.Property, e.NewValue);
95
                instance.SetSymPath();
96
            }
97
        }
98
99
        public static void TRPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
100
        {
101
            var instance = (SymControl)sender;
102
            if (e.OldValue != e.NewValue && instance.Base_SymPath != null)
103
            {
104
                instance.SetValue(e.Property, e.NewValue);
105
                instance.SetSymPath();
106
            }
107
        }
108
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
109
        {
110
111
        }
112
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
113
        {
114
            var instance = (SymControl)sender;
115
            if (e.OldValue != e.NewValue && instance.Base_SymPath != null)
116
            {
117
                instance.SetValue(e.Property, e.NewValue);
118
                instance.SetSymPath();
119
            }
120
        }
121
122
        public static void LBPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
123
        {
124
            var instance = (SymControl)sender;
125
            if (e.OldValue != e.NewValue && instance.Base_SymPath != null)
126
            {
127
                instance.SetValue(e.Property, e.NewValue);
128
                //instance.EndPoint = new Point(instance.EndPoint.X, ((Point)e.NewValue).Y);
129
                //instance.StartPoint = new Point(((Point)e.NewValue).X, instance.StartPoint.Y);
130
                ////instance.PointSet[0] = instance.StartPoint;
131
                ////instance.PointSet[2] = instance.EndPoint;
132
                instance.SetSymPath();
133
            }
134
        }
135
136
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
137
        {
138
            var instance = (SymControl)sender;
139
            if (e.OldValue != e.NewValue && instance.Base_SymPath != null)
140
            {
141
                instance.SetValue(e.Property, e.NewValue);
142
                instance.SetSymPath();
143
            }
144
        }
145
        #endregion
146
        #region Properties
147
        public string UserID
148
        {
149
            get { return (string)GetValue(UserIDProperty); }
150
            set
151
            {
152
                if (this.UserID != value)
153
                {
154
                    SetValue(UserIDProperty, value);
155
                    RaisePropertyChanged("UserID");
156
                }
157
            }
158
        }
159
        public Double LineSize
160
        {
161
            get { return (Double)GetValue(LineSizeProperty); }
162
            set
163
            {
164
                if (this.LineSize != value)
165
                {
166
                    SetValue(LineSizeProperty, value);
167
                }
168
            }
169
        }
170
        public PaintSet Paint
171
        {
172
            get { return (PaintSet)GetValue(PaintProperty); }
173
            set
174
            {
175
                if (this.Paint != value)
176
                {
177
                    SetValue(PaintProperty, value);
178
                }
179
            }
180
        }
181
        public List<Point> PointSet
182
        {
183
            get { return (List<Point>)GetValue(PointSetProperty); }
184
            set { SetValue(PointSetProperty, value); }
185
        }
186
        public double Angle
187
        {
188
            get { return (double)GetValue(AngleProperty); }
189
            set
190
            {
191
                if (this.Angle != value)
192
                {
193
                    SetValue(AngleProperty, value);
194
                }
195
            }
196
        }
197
        public SolidColorBrush StrokeColor
198
        {
199
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
200
            set
201
            {
202
                if (this.StrokeColor != value)
203
                {
204
                    SetValue(StrokeColorProperty, value);
205
                }
206
            }
207
        }
208
        public Geometry PathData
209
        {
210
            get { return (Geometry)GetValue(PathDataProperty); }
211
            set
212
            {
213
                SetValue(PathDataProperty, value);
214
                RaisePropertyChanged("PathData");
215
            }
216
        }
217
        public Point TopRightPoint
218
        {
219
            get { return (Point)GetValue(TopRightPointProperty); }
220
            set
221
            {
222
                SetValue(TopRightPointProperty, value);
223
                RaisePropertyChanged("TopRightPoint");
224
            }
225
        }
226
        public Point LeftBottomPoint
227
        {
228
            get { return (Point)GetValue(LeftBottomPointProperty); }
229
            set
230
            {
231
                SetValue(LeftBottomPointProperty, value);
232
                RaisePropertyChanged("LeftBottomPoint");
233
            }
234
        }
235
        public Point EndPoint
236
        {
237
            get { return (Point)GetValue(EndPointProperty); }
238
            set
239
            {
240
                SetValue(EndPointProperty, value);
241
                RaisePropertyChanged("EndPoint");
242
            }
243
        }
244
        public Point StartPoint
245
        {
246
            get { return (Point)GetValue(StartPointProperty); }
247
            set
248
            {
249
                SetValue(StartPointProperty, value);
250
                RaisePropertyChanged("StartPoint");
251
            }
252
        }
253
        public double CenterX
254
        {
255
            get { return (double)GetValue(CenterXProperty); }
256
            set { SetValue(CenterXProperty, value); }
257
        }
258
        public double CenterY
259
        {
260
            get { return (double)GetValue(CenterYProperty); }
261
            set { SetValue(CenterYProperty, value); }
262
        }
263
        public double AngleValue
264
        {
265
            get { return (double)GetValue(AngleProperty); }
266
            set { SetValue(AngleProperty, value); }
267
        }
268
        public bool IsSelected
269
        {
270
            get
271
            {
272
                return (bool)GetValue(IsSelectedProperty);
273
            }
274
            set
275
            {
276
                SetValue(IsSelectedProperty, value);
277
            }
278
        }
279
280 036650a0 humkyung
        override public ControlType ControlType
281 787a4489 KangIngu
        {
282
            set
283
            {
284
                SetValue(ControlTypeProperty, value);
285
            }
286
            get
287
            {
288
                return (ControlType)GetValue(ControlTypeProperty);
289
            }
290
        }
291
292
        #endregion
293
        public override void OnApplyTemplate()
294
        {
295
            base.OnApplyTemplate();
296
            Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox;
297
            Base_SymPath = GetTemplateChild(PART_SymPath) as Path;
298
            SetSymPath();
299
        }
300
        public void SetSymPath()
301
        {
302
            this.ApplyTemplate();
303
            switch (this.Paint)
304
            {
305
                case PaintSet.None:
306
                    Base_SymPath.Fill = null;
307
                    break;
308
                case PaintSet.Fill:
309
                    Base_SymPath.Fill = this.StrokeColor;
310
                    break;
311
                default:
312
                    break;
313
            }
314
315
            Point mid = MathSet.FindCentroid(new List<Point>()
316
            {
317
                this.StartPoint,
318
                this.LeftBottomPoint,
319
                this.EndPoint,
320
                this.TopRightPoint,
321
            });
322
323
            double AngleData = this.Angle * -1;
324
325
            PathFigure pathFigure = new PathFigure();
326
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
327
328
            LineSegment lineSegment0 = new LineSegment();
329
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
330
            pathFigure.Segments.Add(lineSegment0);
331
332
            LineSegment lineSegment1 = new LineSegment();
333
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
334
            pathFigure.Segments.Add(lineSegment1);
335
336
            LineSegment lineSegment2 = new LineSegment();
337
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
338
            pathFigure.Segments.Add(lineSegment2);
339
340
            LineSegment lineSegment3 = new LineSegment();
341
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
342
            pathFigure.Segments.Add(lineSegment3);
343
344
            PathGeometry pathGeometry = new PathGeometry();
345
            pathGeometry.Figures = new PathFigureCollection();
346
            pathFigure.IsClosed = true;
347
            pathGeometry.Figures.Add(pathFigure);
348
            this.Base_ViewBox.Width = pathGeometry.Bounds.Width;
349
            this.Base_ViewBox.Height = pathGeometry.Bounds.Height; ;
350
            this.Tag = pathGeometry;
351
352
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2);
353
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2);
354
355
        }
356
        public void updateControl()
357
        {
358
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
359
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
360
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
361
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
362
            this.SetSymPath();
363
        }
364
365
366
        public void ChangePaint(PaintSet state)
367
        {
368
            this.Paint = state;
369
            this.SetSymPath();
370
        }
371 036650a0 humkyung
372
        /// <summary>
373
        /// Serialize this
374
        /// </summary>
375
        /// <param name="sUserId"></param>
376
        /// <returns></returns>
377
        public override string Serialize()
378
        {
379
            using (S_SymControl STemp = new S_SymControl())
380
            {
381
                STemp.TransformPoint = "0|0";
382
                STemp.PointSet = this.PointSet;
383
                STemp.UserID = this.UserID;
384
                STemp.SizeSet = String.Format("{0}", this.LineSize.ToString());
385
                STemp.PaintState = this.Paint;
386
                STemp.PathInfo = this.PathData.ToString();
387
                STemp.StrokeColor = this.StrokeColor.Color.ToString();
388
                STemp.StartPoint = this.StartPoint;
389
                STemp.Angle = this.Angle;
390
                STemp.EndPoint = this.EndPoint;
391
                STemp.LB = this.LeftBottomPoint;
392
                STemp.TR = this.TopRightPoint;
393
                STemp.Opac = this.Opacity;
394
                STemp.Name = this.GetType().Name.ToString();
395
396
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
397
            }
398
        }
399 787a4489 KangIngu
    }
400
}
클립보드 이미지 추가 (최대 크기: 500 MB)