markus / MarkupToPDF / Controls / Polygon / PolygonControl.cs @ 40b3ce25
이력 | 보기 | 이력해설 | 다운로드 (18.1 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 | //강인구 추가 |
||
83 | public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
||
84 | "DashSize", typeof(DoubleCollection), typeof(PolygonControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged)); |
||
85 | |||
86 | public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
||
87 | "OverViewPathData", typeof(Geometry), typeof(PolygonControl), null); |
||
88 | //강인구 추가 |
||
89 | public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
||
90 | "Paint", typeof(PaintSet), typeof(PolygonControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
||
91 | |||
92 | public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register( |
||
93 | "IsCompleted", typeof(bool), typeof(PolygonControl), null); |
||
94 | |||
95 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
96 | "StartPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
97 | |||
98 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
99 | "EndPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
||
100 | |||
101 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
102 | "PointSet", typeof(List<Point>), typeof(PolygonControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
||
103 | |||
104 | /// <summary> |
||
105 | /// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다. |
||
106 | /// </summary> |
||
107 | //public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register( |
||
108 | // "PointC", typeof(StylusPointSet), typeof(PolygonControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged)); |
||
109 | |||
110 | public static readonly DependencyProperty AngleProperty = |
||
111 | DependencyProperty.Register("Angle", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback |
||
112 | (AngleValueChanged))); |
||
113 | |||
114 | public static readonly DependencyProperty CenterXProperty = |
||
115 | DependencyProperty.Register("CenterX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
116 | |||
117 | public static readonly DependencyProperty CenterYProperty = |
||
118 | DependencyProperty.Register("CenterY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
119 | |||
120 | public static readonly DependencyProperty IsSelectedProperty = |
||
121 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(PolygonControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
122 | |||
123 | public static readonly DependencyProperty ControlTypeProperty = |
||
124 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(PolygonControl), new FrameworkPropertyMetadata(ControlType.PolygonControl)); |
||
125 | |||
126 | public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
||
127 | "CanvasX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
||
128 | |||
129 | public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
||
130 | "CanvasY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
||
131 | |||
132 | #endregion |
||
133 | |||
134 | #region PropertyChanged Method |
||
135 | public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
136 | { |
||
137 | var instance = (PolygonControl)sender; |
||
138 | |||
139 | if (e.OldValue != e.NewValue && instance != null) |
||
140 | { |
||
141 | instance.SetValue(e.Property, e.NewValue); |
||
142 | //Canvas.SetLeft(instance, instance.CanvasX); |
||
143 | //Canvas.SetTop(instance, instance.CanvasY); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
148 | { |
||
149 | var instance = (PolygonControl)sender; |
||
150 | |||
151 | if (e.OldValue != e.NewValue && instance != null) |
||
152 | { |
||
153 | instance.SetValue(e.Property, e.NewValue); |
||
154 | //강인구 추가 |
||
155 | instance.SetPolyPath(); |
||
156 | //instance.SetPolyPath(); 주석처리 |
||
157 | |||
158 | } |
||
159 | } |
||
160 | public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
161 | { |
||
162 | var instance = (PolygonControl)sender; |
||
163 | |||
164 | if (e.OldValue != e.NewValue && instance != null) |
||
165 | { |
||
166 | instance.SetValue(e.Property, e.NewValue); |
||
167 | instance.SetPolyPath(); |
||
168 | } |
||
169 | } |
||
170 | public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
171 | { |
||
172 | var instance = (PolygonControl)sender; |
||
173 | if (e.OldValue != e.NewValue && instance != null) |
||
174 | { |
||
175 | instance.SetValue(e.Property, e.NewValue); |
||
176 | instance.SetPolyPath(); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
181 | { |
||
182 | //var instance = (PolygonControl)sender; |
||
183 | |||
184 | //if (e.OldValue != e.NewValue && instance.Base_PolyPath != null) |
||
185 | //{ |
||
186 | // instance.SetValue(e.Property, e.NewValue); |
||
187 | |||
188 | // if (instance.IsSelected) |
||
189 | // { |
||
190 | // instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Blue); |
||
191 | // } |
||
192 | // else |
||
193 | // { |
||
194 | // instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Transparent); |
||
195 | // } |
||
196 | //} |
||
197 | } |
||
198 | |||
199 | #endregion |
||
200 | |||
201 | #region Properties |
||
202 | |||
203 | |||
204 | public bool IsCompleted |
||
205 | { |
||
206 | get { return (bool)GetValue(IsCompletedProperty); } |
||
207 | set |
||
208 | { |
||
209 | SetValue(IsCompletedProperty, value); |
||
210 | OnPropertyChanged("IsCompleted"); |
||
211 | } |
||
212 | } |
||
213 | |||
214 | |||
215 | public Geometry OverViewPathData |
||
216 | { |
||
217 | get { return (Geometry)GetValue(OverViewPathDataProperty); } |
||
218 | set |
||
219 | { |
||
220 | SetValue(OverViewPathDataProperty, value); |
||
221 | OnPropertyChanged("OverViewPathData"); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | public double CanvasX |
||
226 | { |
||
227 | get { return (double)GetValue(CanvasXProperty); } |
||
228 | set |
||
229 | { |
||
230 | if (this.CanvasX != value) |
||
231 | { |
||
232 | SetValue(CanvasXProperty, value); |
||
233 | OnPropertyChanged("CanvasX"); |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | |||
238 | public double CanvasY |
||
239 | { |
||
240 | get { return (double)GetValue(CanvasYProperty); } |
||
241 | set |
||
242 | { |
||
243 | if (this.CanvasY != value) |
||
244 | { |
||
245 | SetValue(CanvasYProperty, value); |
||
246 | OnPropertyChanged("CanvasY"); |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | |||
251 | public bool IsSelected |
||
252 | { |
||
253 | get |
||
254 | { |
||
255 | return (bool)GetValue(IsSelectedProperty); |
||
256 | } |
||
257 | set |
||
258 | { |
||
259 | SetValue(IsSelectedProperty, value); |
||
260 | OnPropertyChanged("IsSelected"); |
||
261 | } |
||
262 | } |
||
263 | |||
264 | public PaintSet Paint |
||
265 | { |
||
266 | get { return (PaintSet)GetValue(PaintProperty); } |
||
267 | set |
||
268 | { |
||
269 | if (this.Paint != value) |
||
270 | { |
||
271 | SetValue(PaintProperty, value); |
||
272 | OnPropertyChanged("Paint"); |
||
273 | } |
||
274 | } |
||
275 | } |
||
276 | |||
277 | public ControlType ControlType |
||
278 | { |
||
279 | set |
||
280 | { |
||
281 | SetValue(ControlTypeProperty, value); |
||
282 | OnPropertyChanged("ControlType"); |
||
283 | } |
||
284 | get |
||
285 | { |
||
286 | return (ControlType)GetValue(ControlTypeProperty); |
||
287 | } |
||
288 | } |
||
289 | |||
290 | public Double LineSize |
||
291 | { |
||
292 | get { return (Double)GetValue(LineSizeProperty); } |
||
293 | set |
||
294 | { |
||
295 | if (this.LineSize != value) |
||
296 | { |
||
297 | SetValue(LineSizeProperty, value); |
||
298 | OnPropertyChanged("LineSize"); |
||
299 | } |
||
300 | } |
||
301 | } |
||
302 | |||
303 | public DoubleCollection DashSize |
||
304 | { |
||
305 | get { return (DoubleCollection)GetValue(DashSizeProperty); } |
||
306 | set |
||
307 | { |
||
308 | if (this.DashSize != value) |
||
309 | { |
||
310 | SetValue(DashSizeProperty, value); |
||
311 | OnPropertyChanged("DashSize"); |
||
312 | } |
||
313 | } |
||
314 | } |
||
315 | public string UserID |
||
316 | { |
||
317 | get { return (string)GetValue(UserIDProperty); } |
||
318 | set |
||
319 | { |
||
320 | if (this.UserID != value) |
||
321 | { |
||
322 | SetValue(UserIDProperty, value); |
||
323 | OnPropertyChanged("UserID"); |
||
324 | } |
||
325 | } |
||
326 | } |
||
327 | public List<Point> PointSet |
||
328 | { |
||
329 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
330 | set { SetValue(PointSetProperty, value); |
||
331 | OnPropertyChanged("PointSet"); |
||
332 | } |
||
333 | } //public StylusPointSet PointC |
||
334 | //{ |
||
335 | // get { return (StylusPointSet)GetValue(StylusPointSetProperty); } |
||
336 | // set |
||
337 | // { |
||
338 | // SetValue(StylusPointSetProperty, value); |
||
339 | // OnPropertyChanged("PointC"); |
||
340 | // } |
||
341 | //} |
||
342 | |||
343 | |||
344 | public double CenterX |
||
345 | { |
||
346 | get { return (double)GetValue(CenterXProperty); } |
||
347 | set { SetValue(CenterXProperty, value); |
||
348 | OnPropertyChanged("CenterX"); |
||
349 | } |
||
350 | } |
||
351 | public double CenterY |
||
352 | { |
||
353 | get |
||
354 | { |
||
355 | return (double)GetValue(CenterYProperty); |
||
356 | } |
||
357 | set |
||
358 | { |
||
359 | SetValue(CenterYProperty, value); |
||
360 | OnPropertyChanged("CenterY"); |
||
361 | } |
||
362 | } |
||
363 | public SolidColorBrush StrokeColor |
||
364 | { |
||
365 | get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
||
366 | set |
||
367 | { |
||
368 | if (this.StrokeColor != value) |
||
369 | { |
||
370 | SetValue(StrokeColorProperty, value); |
||
371 | OnPropertyChanged("StrokeColor"); |
||
372 | } |
||
373 | } |
||
374 | } |
||
375 | public Geometry PathData |
||
376 | { |
||
377 | get { return (Geometry)GetValue(PathDataProperty); } |
||
378 | set |
||
379 | { |
||
380 | SetValue(PathDataProperty, value); |
||
381 | OnPropertyChanged("PathData"); |
||
382 | } |
||
383 | } |
||
384 | |||
385 | public double Angle |
||
386 | { |
||
387 | get { return (double)GetValue(AngleProperty); } |
||
388 | set |
||
389 | { |
||
390 | if (this.Angle != value) |
||
391 | { |
||
392 | SetValue(AngleProperty, value); |
||
393 | OnPropertyChanged("Angle"); |
||
394 | } |
||
395 | } |
||
396 | } |
||
397 | |||
398 | public Point EndPoint |
||
399 | { |
||
400 | get { return (Point)GetValue(EndPointProperty); } |
||
401 | set |
||
402 | { |
||
403 | SetValue(EndPointProperty, value); |
||
404 | OnPropertyChanged("EndPoint"); |
||
405 | } |
||
406 | } |
||
407 | public Point StartPoint |
||
408 | { |
||
409 | get { return (Point)GetValue(StartPointProperty); } |
||
410 | set |
||
411 | { |
||
412 | SetValue(StartPointProperty, value); |
||
413 | OnPropertyChanged("StartPoint"); |
||
414 | } |
||
415 | } |
||
416 | #endregion |
||
417 | |||
418 | public void updateControl() |
||
419 | { |
||
420 | //this.PointSet = new List<Point>(); |
||
421 | |||
422 | //this.PointSet.Clear(); |
||
423 | |||
424 | //this.PointSet.AddRange(PointC.pointSet); |
||
425 | //this.PointSet.AddRange(PointSet); |
||
426 | |||
427 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
428 | |||
429 | this.EndPoint = new Point(this.PointSet[this.PointSet.Count - 1].X, this.PointSet[this.PointSet.Count - 1].Y); |
||
430 | |||
431 | SetPolyPath(); |
||
432 | } |
||
433 | |||
434 | public void SetPolyPath() |
||
435 | { |
||
436 | this.ApplyTemplate(); |
||
437 | |||
438 | if (Base_PolyPath != null) |
||
439 | { |
||
440 | Base_PolyPath.StrokeDashArray.Clear(); |
||
441 | foreach (var item in this.DashSize) |
||
442 | { |
||
443 | Base_PolyPath.StrokeDashArray.Add(item); |
||
444 | } |
||
445 | |||
446 | PathGeometry pathGeometry = new PathGeometry(); |
||
447 | PathFigure pathFigure = new PathFigure(); |
||
448 | PolyLineSegment instance = new PolyLineSegment(); |
||
449 | |||
450 | |||
451 | foreach (var Inneritem in PointSet) |
||
452 | { |
||
453 | instance.Points.Add(Inneritem); |
||
454 | } |
||
455 | |||
456 | |||
457 | StartPoint = instance.Points.First(); |
||
458 | pathFigure.StartPoint = StartPoint; |
||
459 | EndPoint = instance.Points.Last(); |
||
460 | pathFigure.Segments.Add(instance); |
||
461 | pathGeometry.Figures.Add(pathFigure); |
||
462 | |||
463 | //강인구 추가(Chain이 아닌 Polygon일때만 채우기 및 빗금 하기) |
||
464 | if (ControlType == ControlType.PolygonControl) |
||
465 | { |
||
466 | switch (this.Paint) |
||
467 | { |
||
468 | case PaintSet.None: |
||
469 | { |
||
470 | //강인구 추가 |
||
471 | Base_PolyPath.Fill = null; |
||
472 | } |
||
473 | break; |
||
474 | case PaintSet.Fill: |
||
475 | { |
||
476 | Base_PolyPath.Fill = this.StrokeColor; |
||
477 | } |
||
478 | break; |
||
479 | case PaintSet.Hatch: |
||
480 | { |
||
481 | Base_PolyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, this.LineSize * 0.1); |
||
482 | } |
||
483 | break; |
||
484 | default: |
||
485 | break; |
||
486 | } |
||
487 | } |
||
488 | |||
489 | this.PathData = pathGeometry; |
||
490 | this.OverViewPathData = PathData; |
||
491 | } |
||
492 | } |
||
493 | |||
494 | public void ChangePaint(PaintSet state) |
||
495 | { |
||
496 | |||
497 | } |
||
498 | |||
499 | //public PaintSet Paint { get; set; } |
||
500 | |||
501 | |||
502 | #region Dispose |
||
503 | public void Dispose() |
||
504 | { |
||
505 | GC.Collect(); |
||
506 | GC.SuppressFinalize(this); |
||
507 | } |
||
508 | #endregion |
||
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 | |||
523 | public class StylusPointSet : INotifyPropertyChanged |
||
524 | { |
||
525 | public StylusPointSet() |
||
526 | { |
||
527 | if (pointSet == null) |
||
528 | pointSet = new List<Point>(); |
||
529 | } |
||
530 | |||
531 | public List<Point> _pointSet; |
||
532 | |||
533 | public List<Point> pointSet |
||
534 | { |
||
535 | get |
||
536 | { |
||
537 | return _pointSet; |
||
538 | } |
||
539 | set |
||
540 | { |
||
541 | _pointSet = value; |
||
542 | OnPropertyChanged("pointSet"); |
||
543 | } |
||
544 | } |
||
545 | |||
546 | #region INotifyPropertyChanged |
||
547 | private void OnPropertyChanged(string name) |
||
548 | { |
||
549 | if (PropertyChanged != null) |
||
550 | { |
||
551 | PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||
552 | } |
||
553 | } |
||
554 | |||
555 | public event PropertyChangedEventHandler PropertyChanged; |
||
556 | #endregion |
||
557 | } |
||
558 | } |