markus / MarkupToPDF / Controls / Polygon / PolygonControl.cs.bak @ f6cecf63
이력 | 보기 | 이력해설 | 다운로드 (16.7 KB)
1 | 787a4489 | KangIngu | using MarkupToPDF.Common; |
---|---|---|---|
2 | using MarkupToPDF.Controls.Common; |
||
3 | using System; |
||
4 | using System.Collections.Generic; |
||
5 | using System.ComponentModel; |
||
6 | using System.Linq; |
||
7 | using System.Text; |
||
8 | using System.Threading.Tasks; |
||
9 | using System.Windows; |
||
10 | using System.Windows.Controls; |
||
11 | using System.Windows.Media; |
||
12 | using System.Windows.Shapes; |
||
13 | |||
14 | namespace MarkupToPDF.Controls.Polygon |
||
15 | { |
||
16 | public class PolygonControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IMarkupControlData, IPath |
||
17 | { |
||
18 | #region Constructure |
||
19 | |||
20 | static PolygonControl() |
||
21 | { |
||
22 | DefaultStyleKeyProperty.OverrideMetadata(typeof(PolygonControl), new FrameworkPropertyMetadata(typeof(PolygonControl))); |
||
23 | ResourceDictionary dictionary = new ResourceDictionary(); |
||
24 | dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
25 | Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
26 | } |
||
27 | |||
28 | public PolygonControl() |
||
29 | { |
||
30 | this.DefaultStyleKey = typeof(PolygonControl); |
||
31 | } |
||
32 | |||
33 | #endregion |
||
34 | |||
35 | #region Variable |
||
36 | private const string PART_PolyPath = "PART_PolyPath"; |
||
37 | |||
38 | public Path Base_PolyPath = null; |
||
39 | |||
40 | #endregion |
||
41 | |||
42 | #region Internal Method |
||
43 | public override void OnApplyTemplate() |
||
44 | { |
||
45 | base.OnApplyTemplate(); |
||
46 | |||
47 | Base_PolyPath = GetTemplateChild(PART_PolyPath) as Path; |
||
48 | |||
49 | if (Base_PolyPath == null) |
||
50 | return; |
||
51 | |||
52 | this.SetPolyPath(); |
||
53 | } |
||
54 | |||
55 | |||
56 | #endregion |
||
57 | |||
58 | #region Method |
||
59 | |||
60 | public void ApplyOverViewData() |
||
61 | { |
||
62 | this.OverViewPathData = this.PathData; |
||
63 | } |
||
64 | |||
65 | #endregion |
||
66 | |||
67 | #region Dependency Properties |
||
68 | |||
69 | public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
||
70 | "UserID", typeof(string), typeof(PolygonControl), new PropertyMetadata(null)); |
||
71 | |||
72 | public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
||
73 | "LineSize", typeof(double), typeof(PolygonControl), new PropertyMetadata((Double)3)); |
||
74 | |||
75 | public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
||
76 | "StrokeColor", typeof(SolidColorBrush), typeof(PolygonControl), |
||
77 | new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
||
78 | |||
79 | public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
||
80 | "PathData", typeof(Geometry), typeof(PolygonControl), null); |
||
81 | |||
82 | public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
||
83 | "OverViewPathData", typeof(Geometry), typeof(PolygonControl), null); |
||
84 | |||
85 | public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
||
86 | "Paint", typeof(PaintSet), typeof(PolygonControl), new PropertyMetadata(PaintSet.None)); |
||
87 | |||
88 | public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register( |
||
89 | "IsCompleted", typeof(bool), typeof(PolygonControl), null); |
||
90 | |||
91 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
92 | "StartPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
93 | |||
94 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
95 | "EndPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
||
96 | |||
97 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
98 | "PointSet", typeof(List<Point>), typeof(PolygonControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
||
99 | |||
100 | /// <summary> |
||
101 | /// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다. |
||
102 | /// </summary> |
||
103 | //public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register( |
||
104 | // "PointC", typeof(StylusPointSet), typeof(PolygonControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged)); |
||
105 | |||
106 | public static readonly DependencyProperty AngleProperty = |
||
107 | DependencyProperty.Register("Angle", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback |
||
108 | (AngleValueChanged))); |
||
109 | |||
110 | public static readonly DependencyProperty CenterXProperty = |
||
111 | DependencyProperty.Register("CenterX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
112 | |||
113 | public static readonly DependencyProperty CenterYProperty = |
||
114 | DependencyProperty.Register("CenterY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
115 | |||
116 | public static readonly DependencyProperty IsSelectedProperty = |
||
117 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(PolygonControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
118 | |||
119 | public static readonly DependencyProperty ControlTypeProperty = |
||
120 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(PolygonControl), new FrameworkPropertyMetadata(ControlType.PolygonControl)); |
||
121 | |||
122 | public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
||
123 | "CanvasX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
||
124 | |||
125 | public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
||
126 | "CanvasY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
||
127 | |||
128 | #endregion |
||
129 | |||
130 | #region PropertyChanged Method |
||
131 | public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
132 | { |
||
133 | var instance = (PolygonControl)sender; |
||
134 | |||
135 | if (e.OldValue != e.NewValue && instance != null) |
||
136 | { |
||
137 | instance.SetValue(e.Property, e.NewValue); |
||
138 | //Canvas.SetLeft(instance, instance.CanvasX); |
||
139 | //Canvas.SetTop(instance, instance.CanvasY); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
144 | { |
||
145 | var instance = (PolygonControl)sender; |
||
146 | |||
147 | if (e.OldValue != e.NewValue && instance != null) |
||
148 | { |
||
149 | instance.SetValue(e.Property, e.NewValue); |
||
150 | //instance.SetPolyPath(); 주석처리 |
||
151 | } |
||
152 | } |
||
153 | public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
154 | { |
||
155 | var instance = (PolygonControl)sender; |
||
156 | |||
157 | if (e.OldValue != e.NewValue && instance != null) |
||
158 | { |
||
159 | instance.SetValue(e.Property, e.NewValue); |
||
160 | instance.SetPolyPath(); |
||
161 | } |
||
162 | } |
||
163 | public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
164 | { |
||
165 | var instance = (PolygonControl)sender; |
||
166 | if (e.OldValue != e.NewValue && instance != null) |
||
167 | { |
||
168 | instance.SetValue(e.Property, e.NewValue); |
||
169 | instance.SetPolyPath(); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
174 | { |
||
175 | //var instance = (PolygonControl)sender; |
||
176 | |||
177 | //if (e.OldValue != e.NewValue && instance.Base_PolyPath != null) |
||
178 | //{ |
||
179 | // instance.SetValue(e.Property, e.NewValue); |
||
180 | |||
181 | // if (instance.IsSelected) |
||
182 | // { |
||
183 | // instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Blue); |
||
184 | // } |
||
185 | // else |
||
186 | // { |
||
187 | // instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Transparent); |
||
188 | // } |
||
189 | //} |
||
190 | } |
||
191 | |||
192 | #endregion |
||
193 | |||
194 | #region Properties |
||
195 | |||
196 | |||
197 | public bool IsCompleted |
||
198 | { |
||
199 | get { return (bool)GetValue(IsCompletedProperty); } |
||
200 | set |
||
201 | { |
||
202 | SetValue(IsCompletedProperty, value); |
||
203 | OnPropertyChanged("IsCompleted"); |
||
204 | } |
||
205 | } |
||
206 | |||
207 | |||
208 | public Geometry OverViewPathData |
||
209 | { |
||
210 | get { return (Geometry)GetValue(OverViewPathDataProperty); } |
||
211 | set |
||
212 | { |
||
213 | SetValue(OverViewPathDataProperty, value); |
||
214 | OnPropertyChanged("OverViewPathData"); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | public double CanvasX |
||
219 | { |
||
220 | get { return (double)GetValue(CanvasXProperty); } |
||
221 | set |
||
222 | { |
||
223 | if (this.CanvasX != value) |
||
224 | { |
||
225 | SetValue(CanvasXProperty, value); |
||
226 | OnPropertyChanged("CanvasX"); |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | |||
231 | public double CanvasY |
||
232 | { |
||
233 | get { return (double)GetValue(CanvasYProperty); } |
||
234 | set |
||
235 | { |
||
236 | if (this.CanvasY != value) |
||
237 | { |
||
238 | SetValue(CanvasYProperty, value); |
||
239 | OnPropertyChanged("CanvasY"); |
||
240 | } |
||
241 | } |
||
242 | } |
||
243 | |||
244 | public bool IsSelected |
||
245 | { |
||
246 | get |
||
247 | { |
||
248 | return (bool)GetValue(IsSelectedProperty); |
||
249 | } |
||
250 | set |
||
251 | { |
||
252 | SetValue(IsSelectedProperty, value); |
||
253 | OnPropertyChanged("IsSelected"); |
||
254 | } |
||
255 | } |
||
256 | |||
257 | public PaintSet Paint |
||
258 | { |
||
259 | get { return (PaintSet)GetValue(PaintProperty); } |
||
260 | set |
||
261 | { |
||
262 | if (this.Paint != value) |
||
263 | { |
||
264 | SetValue(PaintProperty, value); |
||
265 | OnPropertyChanged("Paint"); |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | |||
270 | public ControlType ControlType |
||
271 | { |
||
272 | set |
||
273 | { |
||
274 | SetValue(ControlTypeProperty, value); |
||
275 | OnPropertyChanged("ControlType"); |
||
276 | } |
||
277 | get |
||
278 | { |
||
279 | return (ControlType)GetValue(ControlTypeProperty); |
||
280 | } |
||
281 | } |
||
282 | |||
283 | public Double LineSize |
||
284 | { |
||
285 | get { return (Double)GetValue(LineSizeProperty); } |
||
286 | set |
||
287 | { |
||
288 | if (this.LineSize != value) |
||
289 | { |
||
290 | SetValue(LineSizeProperty, value); |
||
291 | OnPropertyChanged("LineSize"); |
||
292 | } |
||
293 | } |
||
294 | } |
||
295 | public string UserID |
||
296 | { |
||
297 | get { return (string)GetValue(UserIDProperty); } |
||
298 | set |
||
299 | { |
||
300 | if (this.UserID != value) |
||
301 | { |
||
302 | SetValue(UserIDProperty, value); |
||
303 | OnPropertyChanged("UserID"); |
||
304 | } |
||
305 | } |
||
306 | } |
||
307 | public List<Point> PointSet |
||
308 | { |
||
309 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
310 | set { SetValue(PointSetProperty, value); |
||
311 | OnPropertyChanged("PointSet"); |
||
312 | } |
||
313 | } //public StylusPointSet PointC |
||
314 | //{ |
||
315 | // get { return (StylusPointSet)GetValue(StylusPointSetProperty); } |
||
316 | // set |
||
317 | // { |
||
318 | // SetValue(StylusPointSetProperty, value); |
||
319 | // OnPropertyChanged("PointC"); |
||
320 | // } |
||
321 | //} |
||
322 | |||
323 | |||
324 | public double CenterX |
||
325 | { |
||
326 | get { return (double)GetValue(CenterXProperty); } |
||
327 | set { SetValue(CenterXProperty, value); |
||
328 | OnPropertyChanged("CenterX"); |
||
329 | } |
||
330 | } |
||
331 | public double CenterY |
||
332 | { |
||
333 | get |
||
334 | { |
||
335 | return (double)GetValue(CenterYProperty); |
||
336 | } |
||
337 | set |
||
338 | { |
||
339 | SetValue(CenterYProperty, value); |
||
340 | OnPropertyChanged("CenterY"); |
||
341 | } |
||
342 | } |
||
343 | public SolidColorBrush StrokeColor |
||
344 | { |
||
345 | get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
||
346 | set |
||
347 | { |
||
348 | if (this.StrokeColor != value) |
||
349 | { |
||
350 | SetValue(StrokeColorProperty, value); |
||
351 | OnPropertyChanged("StrokeColor"); |
||
352 | } |
||
353 | } |
||
354 | } |
||
355 | public Geometry PathData |
||
356 | { |
||
357 | get { return (Geometry)GetValue(PathDataProperty); } |
||
358 | set |
||
359 | { |
||
360 | SetValue(PathDataProperty, value); |
||
361 | OnPropertyChanged("PathData"); |
||
362 | } |
||
363 | } |
||
364 | |||
365 | public double Angle |
||
366 | { |
||
367 | get { return (double)GetValue(AngleProperty); } |
||
368 | set |
||
369 | { |
||
370 | if (this.Angle != value) |
||
371 | { |
||
372 | SetValue(AngleProperty, value); |
||
373 | OnPropertyChanged("Angle"); |
||
374 | } |
||
375 | } |
||
376 | } |
||
377 | |||
378 | public Point EndPoint |
||
379 | { |
||
380 | get { return (Point)GetValue(EndPointProperty); } |
||
381 | set |
||
382 | { |
||
383 | SetValue(EndPointProperty, value); |
||
384 | OnPropertyChanged("EndPoint"); |
||
385 | } |
||
386 | } |
||
387 | public Point StartPoint |
||
388 | { |
||
389 | get { return (Point)GetValue(StartPointProperty); } |
||
390 | set |
||
391 | { |
||
392 | SetValue(StartPointProperty, value); |
||
393 | OnPropertyChanged("StartPoint"); |
||
394 | } |
||
395 | } |
||
396 | #endregion |
||
397 | |||
398 | public void updateControl() |
||
399 | { |
||
400 | //this.PointSet = new List<Point>(); |
||
401 | |||
402 | //this.PointSet.Clear(); |
||
403 | |||
404 | //this.PointSet.AddRange(PointC.pointSet); |
||
405 | //this.PointSet.AddRange(PointSet); |
||
406 | |||
407 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
408 | |||
409 | this.EndPoint = new Point(this.PointSet[this.PointSet.Count - 1].X, this.PointSet[this.PointSet.Count - 1].Y); |
||
410 | |||
411 | SetPolyPath(); |
||
412 | } |
||
413 | |||
414 | public void SetPolyPath() |
||
415 | { |
||
416 | this.ApplyTemplate(); |
||
417 | |||
418 | if (Base_PolyPath != null) |
||
419 | { |
||
420 | PathGeometry pathGeometry = new PathGeometry(); |
||
421 | PathFigure pathFigure = new PathFigure(); |
||
422 | PolyLineSegment instance = new PolyLineSegment(); |
||
423 | |||
424 | foreach (var Inneritem in PointSet) |
||
425 | { |
||
426 | instance.Points.Add(Inneritem); |
||
427 | } |
||
428 | |||
429 | StartPoint = instance.Points.First(); |
||
430 | pathFigure.StartPoint = StartPoint; |
||
431 | EndPoint = instance.Points.Last(); |
||
432 | pathFigure.Segments.Add(instance); |
||
433 | pathGeometry.Figures.Add(pathFigure); |
||
434 | |||
435 | switch (this.Paint) |
||
436 | { |
||
437 | case PaintSet.None: |
||
438 | break; |
||
439 | case PaintSet.Fill: |
||
440 | { |
||
441 | Base_PolyPath.Fill = this.StrokeColor; |
||
442 | } |
||
443 | break; |
||
444 | case PaintSet.Hatch: |
||
445 | { |
||
446 | Base_PolyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, this.LineSize * 0.1); |
||
447 | } |
||
448 | break; |
||
449 | default: |
||
450 | break; |
||
451 | } |
||
452 | |||
453 | this.PathData = pathGeometry; |
||
454 | this.OverViewPathData = PathData; |
||
455 | } |
||
456 | } |
||
457 | |||
458 | public void ChangePaint(PaintSet state) |
||
459 | { |
||
460 | |||
461 | } |
||
462 | |||
463 | //public PaintSet Paint { get; set; } |
||
464 | |||
465 | |||
466 | #region Dispose |
||
467 | public void Dispose() |
||
468 | { |
||
469 | GC.Collect(); |
||
470 | GC.SuppressFinalize(this); |
||
471 | } |
||
472 | #endregion |
||
473 | |||
474 | #region INotifyPropertyChanged |
||
475 | private void OnPropertyChanged(string name) |
||
476 | { |
||
477 | if (PropertyChanged != null) |
||
478 | { |
||
479 | PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||
480 | } |
||
481 | } |
||
482 | |||
483 | public event PropertyChangedEventHandler PropertyChanged; |
||
484 | #endregion |
||
485 | } |
||
486 | |||
487 | public class StylusPointSet : INotifyPropertyChanged |
||
488 | { |
||
489 | public StylusPointSet() |
||
490 | { |
||
491 | if (pointSet == null) |
||
492 | pointSet = new List<Point>(); |
||
493 | } |
||
494 | |||
495 | public List<Point> _pointSet; |
||
496 | |||
497 | public List<Point> pointSet |
||
498 | { |
||
499 | get |
||
500 | { |
||
501 | return _pointSet; |
||
502 | } |
||
503 | set |
||
504 | { |
||
505 | _pointSet = value; |
||
506 | OnPropertyChanged("pointSet"); |
||
507 | } |
||
508 | } |
||
509 | |||
510 | #region INotifyPropertyChanged |
||
511 | private void OnPropertyChanged(string name) |
||
512 | { |
||
513 | if (PropertyChanged != null) |
||
514 | { |
||
515 | PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||
516 | } |
||
517 | } |
||
518 | |||
519 | public event PropertyChangedEventHandler PropertyChanged; |
||
520 | #endregion |
||
521 | } |
||
522 | } |