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