프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Etc / SymControlN.cs @ 02275aa2

이력 | 보기 | 이력해설 | 다운로드 (13.7 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
16
namespace MarkupToPDF.Controls.Etc
17
{
18
    [TemplatePart(Name = "PART_ViewBox", Type = typeof(Viewbox))]
19
20
21
    public class SymControlN : CommentUserInfo, INotifyPropertyChanged , IViewBox, IMarkupCommonData
22
    {
23
        private const string PART_ViewBox = "PART_ViewBox";
24
        public Viewbox Base_ViewBox = null;
25
26
        static SymControlN()
27
        {
28
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SymControlN), new FrameworkPropertyMetadata(typeof(SymControlN)));
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 event PropertyChangedEventHandler PropertyChanged;
37
        protected void RaisePropertyChanged(string propName)
38
        {
39
            if (PropertyChanged != null)
40
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
41
        }
42
        #region 내장 프로퍼티
43
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
44
                "UserID", typeof(string), typeof(SymControlN), new PropertyMetadata(null));
45
         public static readonly DependencyProperty PathXathDataProperty = DependencyProperty.Register(
46
                "PathXathData", typeof(string), typeof(SymControlN), new PropertyMetadata(null));
47
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
48
                "LineSize", typeof(double), typeof(SymControlN), new PropertyMetadata((Double)1));
49
         public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
50
                "EndPoint", typeof(Point), typeof(SymControlN), new PropertyMetadata(new Point(0, 0), PointValueChanged));
51
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
52
                "StartPoint", typeof(Point), typeof(SymControlN), new PropertyMetadata(new Point(0, 0), PointValueChanged));
53
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
54
                "TopRightPoint", typeof(Point), typeof(SymControlN), new PropertyMetadata(new Point(0, 0), PointValueChanged));
55
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
56
                 "StrokeColor", typeof(SolidColorBrush), typeof(SymControlN), new PropertyMetadata(new SolidColorBrush(Colors.Red)));        
57
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
58
                 "LeftBottomPoint", typeof(Point), typeof(SymControlN), new PropertyMetadata(new Point(0, 0), PointValueChanged));
59
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
60
                 "PointSet", typeof(List<Point>), typeof(SymControlN), new PropertyMetadata(new List<Point>()));
61
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
62
                 "PathData", typeof(Geometry), typeof(SymControlN), null);
63
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(SymControlN),
64
          new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
65
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(SymControlN),
66
            new PropertyMetadata((double)0, OnCenterXYChanged));
67
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(SymControlN),
68
            new PropertyMetadata((double)0, OnCenterXYChanged));
69
70
        public static readonly DependencyProperty IsSelectedProperty =
71
     DependencyProperty.Register("IsSelected", typeof(bool), typeof(SymControlN), new FrameworkPropertyMetadata(false, IsSelectedChanged));
72
73
        public static readonly DependencyProperty ControlTypeProperty =
74 d7123191 KangIngu
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(SymControlN), new FrameworkPropertyMetadata(ControlType.Stamp));
75 787a4489 KangIngu
        #endregion
76
77
        #region PropertyChanged Method
78
79
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
80
        {
81
82
        }
83
84
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
85
        {
86
            var instance = (SymControlN)sender;
87
            if (e.OldValue != e.NewValue && instance.Base_ViewBox != null)
88
            {
89
                instance.SetValue(e.Property, e.NewValue);
90
                instance.SetViewBox();
91
            }
92
        }
93
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
94
        {
95
            var instance = (SymControlN)sender;
96
            if (e.OldValue != e.NewValue && instance.Base_ViewBox != null)
97
            {
98
                instance.SetValue(e.Property, e.NewValue);
99
                instance.SetViewBox();
100
            }
101
        }
102
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
103
        {
104
            var instance = (SymControlN)sender;
105
            if (e.OldValue != e.NewValue && instance.Base_ViewBox != null)
106
            {
107
                instance.SetValue(e.Property, e.NewValue);
108
                instance.SetViewBox();
109
            }
110
        }
111
        #endregion
112
113
        #region Properties
114
        public string UserID
115
        {
116
            get { return (string)GetValue(UserIDProperty); }
117
            set
118
            {
119
                if (this.UserID != value)
120
                {
121
                    SetValue(UserIDProperty, value);
122
                    RaisePropertyChanged("UserID");
123
                }
124
            }
125
        }
126
        public SolidColorBrush StrokeColor
127
        {
128
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
129
            set
130
            {
131
                if (this.StrokeColor != value)
132
                {
133
                    SetValue(StrokeColorProperty, value);
134
                }
135
            }
136
        }
137
138
        public string PathXathData
139
        {
140
            get
141
            {
142
                return (string)GetValue(PathXathDataProperty);
143
            }
144
            set
145
            {
146
                SetValue(PathXathDataProperty, value);
147
                RaisePropertyChanged("PathXathData");
148
            }
149
            
150
        }
151
        public List<Point> PointSet
152
        {
153
            get { return (List<Point>)GetValue(PointSetProperty); }
154
            set { SetValue(PointSetProperty, value); }
155
        }
156
        public Point TopRightPoint
157
        {
158
            get { return (Point)GetValue(TopRightPointProperty); }
159
            set
160
            {
161
                SetValue(TopRightPointProperty, value);
162
                RaisePropertyChanged("TopRightPoint");
163
            }
164
        }
165
        public Point LeftBottomPoint
166
        {
167
            get { return (Point)GetValue(LeftBottomPointProperty); }
168
            set
169
            {
170
                SetValue(LeftBottomPointProperty, value);
171
                RaisePropertyChanged("LeftBottomPoint");
172
            }
173
        }
174
        public Point EndPoint
175
        {
176
            get { return (Point)GetValue(EndPointProperty); }
177
            set
178
            {
179
                SetValue(EndPointProperty, value);
180
                RaisePropertyChanged("EndPoint");
181
            }
182
        }
183
        public Point StartPoint
184
        {
185
            get { return (Point)GetValue(StartPointProperty); }
186
            set
187
            {
188
                SetValue(StartPointProperty, value);
189
                RaisePropertyChanged("StartPoint");
190
            }
191
        }
192
        #endregion
193
194
        public override void OnApplyTemplate()
195
        {
196
            base.OnApplyTemplate();
197
            Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox;
198
            SetViewBox();
199
        }
200
201
        public void SetViewBox()
202
        {
203
            this.ApplyTemplate();
204
            Point mid = MathSet.FindCentroid(new List<Point>()
205
            {
206
                this.StartPoint,
207
                this.LeftBottomPoint,
208
                this.EndPoint,
209
                this.TopRightPoint,                
210
            });
211
            double AngleData = 0;
212
213
            PathFigure pathFigure = new PathFigure();
214
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
215
216
            LineSegment lineSegment0 = new LineSegment();
217
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
218
            pathFigure.Segments.Add(lineSegment0);
219
220
            LineSegment lineSegment1 = new LineSegment();
221
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
222
            pathFigure.Segments.Add(lineSegment1);
223
224
            LineSegment lineSegment2 = new LineSegment();
225
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
226
            pathFigure.Segments.Add(lineSegment2);
227
228
            LineSegment lineSegment3 = new LineSegment();
229
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
230
            pathFigure.Segments.Add(lineSegment3);
231
232
            PathGeometry pathGeometry = new PathGeometry();
233
            pathGeometry.Figures = new PathFigureCollection();
234
            pathFigure.IsClosed = true;
235
            pathGeometry.Figures.Add(pathFigure);
236
            this.Base_ViewBox.Width = pathGeometry.Bounds.Width;
237
            this.Base_ViewBox.Height = pathGeometry.Bounds.Height; ;
238
            this.Tag = pathGeometry;
239
240
            if(Base_ViewBox.Child == null)
241
            {
242
                SetChild();
243
            }
244
245
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2);
246
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2);
247
        }
248
249
        public void SetChild()
250
        {
251 b200de5a KangIngu
            //string appovalData = "eJyycS/KTFHwS8xNtVVKBAMlhYrcnLxiW6WMkpICK3394uSM1NzEYr3czOSi/OL8tBK95Pxc/fLMvLQKfSMDAzP9isTcHP2CotTi1LySxJLM/DwlOxuQqXpOicnZ6UX5pXkpdjbB+TmZKc75OflFTkWlxRkKYKatkrIbFCgp+BckJmeWVNoqGegZKino29noYxgSlJpckpiXnpOqEFxSlFqSnGGr5JaZk6ME4uZnp0KNMwACmFBIRmZydl5qMdA7pjAxn8y8VK/8zDxbpSCQsUpQ38MNV1IIz0wpAZptZADU45GamZ5RYqtkYamk4JyYVwYMCZ/UNKCArpGeKVwoJL8AJqIP8T00DILyy11S0zLzMkEBUwz0AjIfbrgWWBt2OWM9U3zSBviljfBJaiGFM7pDQ1IrSpxy8pOzFUAsWyXHgIAg/zBXFyUFt/y8knCoCa4VJUWJTvk5KRDh4MwqYEgaG4B4RamQaEOJFY/8oswqoMLEHMeczPS8XGCSsVVyBpKpRUoKYalFJZnJWKVgTrRVgqQNdNc5VSqkJKbmZOYS4TwjWjrPGBGkMAoAAAD//w==";
252 787a4489 KangIngu
253 b200de5a KangIngu
            //var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(appovalData);
254
            //xamlData = xamlData.Replace("daelim", "DAELIM");
255
            ////object obj = System.Windows.Markup.XamlReader.Load(xamlData);
256 787a4489 KangIngu
257 b200de5a KangIngu
            //System.IO.MemoryStream stream = new System.IO.MemoryStream();
258
            //System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
259
            //writer.Write(xamlData);
260
            //writer.Flush();
261
            //stream.Position = 0;
262 787a4489 KangIngu
263 b200de5a KangIngu
            //object obj = System.Windows.Markup.XamlReader.Load(stream);
264
            //UIElement ob = obj as UIElement;
265 787a4489 KangIngu
266 b200de5a KangIngu
            //PathXathData = appovalData;
267
            //Base_ViewBox.Child = ob;
268 787a4489 KangIngu
        }
269
270
        public bool IsSelected
271
        {
272
            get
273
            {
274
                return (bool)GetValue(IsSelectedProperty);
275
            }
276
            set
277
            {
278
                SetValue(IsSelectedProperty, value);
279
            }
280
        }
281
282
        public ControlType ControlType
283
        {
284
            set
285
            {
286
                SetValue(ControlTypeProperty, value);
287
            }
288
            get
289
            {
290
                return (ControlType)GetValue(ControlTypeProperty);
291
            }
292
        }
293
294
        public double Angle
295
        {
296
            get { return (double)GetValue(AngleProperty); }
297
            set
298
            {
299
                if (this.Angle != value)
300
                {
301
                    SetValue(AngleProperty, value);
302
                }
303
            }
304
        }
305
306
307
        public Double LineSize
308
        {
309
            get { return (Double)GetValue(LineSizeProperty); }
310
            set
311
            {
312
                if (this.LineSize != value)
313
                {
314
                    SetValue(LineSizeProperty, value);
315
                }
316
            }
317
        }
318
        public Geometry PathData
319
        {
320
            get { return (Geometry)GetValue(PathDataProperty); }
321
            set
322
            {
323
                SetValue(PathDataProperty, value);
324
                RaisePropertyChanged("PathData");
325
            }
326
        }
327
328
        public void updateControl()
329
        {
330
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
331
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
332
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
333
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
334
            this.SetViewBox();
335
        }
336
    }
337
}
338
클립보드 이미지 추가 (최대 크기: 500 MB)