markus / MarkupToPDF / Controls / Polygon / CloudControl.cs @ 92c9cab8
이력 | 보기 | 이력해설 | 다운로드 (40.4 KB)
1 |
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.Collections.Generic; |
12 |
using System.ComponentModel; |
13 |
using MarkupToPDF.Controls.Common; |
14 |
using MarkupToPDF.Common; |
15 |
using MarkupToPDF.Serialize.Core; |
16 |
using MarkupToPDF.Serialize.S_Control; |
17 |
using System.Linq; |
18 |
|
19 |
namespace MarkupToPDF.Controls.Polygon |
20 |
{ |
21 |
public class CloudControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IShapeControl, ICloudControl, IDashControl |
22 |
{ |
23 |
private const string PART_CloudPath = "PART_CloudPath"; |
24 |
private const string PART_CloudSubPath = "PART_CloudSubPath"; |
25 |
|
26 |
public Path Base_CloudPath = null; |
27 |
public Path Base_CloudSubPath = null; |
28 |
|
29 |
private const double _CloudArcDepth =0.8; /// 2018.05.14 added by humkyung |
30 |
|
31 |
static CloudControl() |
32 |
{ |
33 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(CloudControl), new FrameworkPropertyMetadata(typeof(CloudControl))); |
34 |
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
35 |
//ResourceDictionary dictionary = new ResourceDictionary(); |
36 |
//dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
37 |
//Application.Current.Resources.MergedDictionaries.Add(dictionary); |
38 |
} |
39 |
public CloudControl() |
40 |
{ |
41 |
//this.DefaultStyleKey = typeof(CloudControl); |
42 |
} |
43 |
|
44 |
#region Dependency Properties |
45 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
46 |
"UserID", typeof(string), typeof(CloudControl), new PropertyMetadata(null)); |
47 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
48 |
"LineSize", typeof(double), typeof(CloudControl), new PropertyMetadata((Double)3)); |
49 |
//강인구 추가 |
50 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
51 |
"DashSize", typeof(DoubleCollection), typeof(CloudControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged)); |
52 |
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
53 |
"FillColor", typeof(SolidColorBrush), typeof(CloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
54 |
|
55 |
public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register( |
56 |
"IsCompleted", typeof(bool), typeof(CloudControl), null); |
57 |
//강인구 |
58 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
59 |
"Paint", typeof(PaintSet), typeof(CloudControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
60 |
|
61 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
62 |
"StrokeColor", typeof(SolidColorBrush), typeof(CloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
63 |
|
64 |
public static readonly DependencyProperty ArcLengthProperty = DependencyProperty.Register( |
65 |
"ArcLength", typeof(double), typeof(CloudControl), new PropertyMetadata((Double)10, PointValueChanged)); |
66 |
|
67 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
68 |
"PathData", typeof(Geometry), typeof(CloudControl), null); |
69 |
|
70 |
public static readonly DependencyProperty PathSubDataProperty = DependencyProperty.Register( |
71 |
"PathSubData", typeof(Geometry), typeof(CloudControl), null); |
72 |
|
73 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
74 |
"EndPoint", typeof(Point), typeof(CloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
75 |
|
76 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
77 |
"StartPoint", typeof(Point), typeof(CloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
78 |
|
79 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
80 |
"PointSet", typeof(List<Point>), typeof(CloudControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
81 |
public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register( |
82 |
"isTransOn", typeof(bool), typeof(CloudControl), new PropertyMetadata(false)); |
83 |
public static readonly DependencyProperty isChainProperty = DependencyProperty.Register( |
84 |
"isChain", typeof(bool), typeof(CloudControl), new PropertyMetadata(false)); |
85 |
|
86 |
/// <summary> |
87 |
/// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다. |
88 |
/// </summary> |
89 |
public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register( |
90 |
"PointC", typeof(StylusPointSet), typeof(CloudControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged)); |
91 |
|
92 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("AngleValue", typeof(double), typeof(CloudControl), |
93 |
new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
94 |
|
95 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(CloudControl), |
96 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
97 |
|
98 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(CloudControl), |
99 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
100 |
|
101 |
public static readonly DependencyProperty IsSelectedProperty = |
102 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(CloudControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
103 |
|
104 |
public static readonly DependencyProperty ControlTypeProperty = |
105 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(CloudControl), new FrameworkPropertyMetadata(ControlType.PolygonCloud)); |
106 |
|
107 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
108 |
"OverViewPathData", typeof(Geometry), typeof(ControlType), null); |
109 |
|
110 |
|
111 |
public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
112 |
"CanvasX", typeof(double), typeof(CloudControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
113 |
|
114 |
public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
115 |
"CanvasY", typeof(double), typeof(CloudControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
116 |
|
117 |
|
118 |
#endregion |
119 |
#region PropertyChanged Method |
120 |
|
121 |
public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
122 |
{ |
123 |
var instance = (CloudControl)sender; |
124 |
|
125 |
if (e.OldValue != e.NewValue && instance != null) |
126 |
{ |
127 |
instance.SetValue(e.Property, e.NewValue); |
128 |
} |
129 |
} |
130 |
|
131 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
132 |
{ |
133 |
var instance = (CloudControl)sender; |
134 |
if (e.OldValue != e.NewValue && instance.Base_CloudPath != null) |
135 |
{ |
136 |
instance.SetValue(e.Property, e.NewValue); |
137 |
//강인구 추가 |
138 |
instance.SetCloud(); |
139 |
//주석처리 |
140 |
} |
141 |
} |
142 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
143 |
{ |
144 |
//var instance = (CloudControl)sender; |
145 |
|
146 |
//if (e.OldValue != e.NewValue && instance.Base_CloudPath != null) |
147 |
//{ |
148 |
|
149 |
// instance.SetValue(e.Property, e.NewValue); |
150 |
|
151 |
// if (instance.IsSelected) |
152 |
// { |
153 |
// instance.Base_CloudPath.Stroke = new SolidColorBrush(Colors.Blue); |
154 |
// } |
155 |
// else |
156 |
// { |
157 |
// instance.Base_CloudPath.Stroke = new SolidColorBrush(Colors.Red); |
158 |
// } |
159 |
//} |
160 |
} |
161 |
|
162 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
163 |
{ |
164 |
var instance = (CloudControl)sender; |
165 |
if (e.OldValue != e.NewValue && instance.Base_CloudPath != null) |
166 |
{ |
167 |
instance.SetValue(e.Property, e.NewValue); |
168 |
instance.DrawingCloud(); |
169 |
} |
170 |
} |
171 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
172 |
{ |
173 |
var instance = (CloudControl)sender; |
174 |
if (e.OldValue != e.NewValue && instance.Base_CloudPath != null) |
175 |
{ |
176 |
instance.SetValue(e.Property, e.NewValue); |
177 |
instance.DrawingCloud(); |
178 |
} |
179 |
} |
180 |
#endregion |
181 |
#region Properties |
182 |
|
183 |
|
184 |
public bool IsCompleted |
185 |
{ |
186 |
get { return (bool)GetValue(IsCompletedProperty); } |
187 |
set |
188 |
{ |
189 |
SetValue(IsCompletedProperty, value); |
190 |
} |
191 |
} |
192 |
|
193 |
public Geometry OverViewPathData |
194 |
{ |
195 |
get { return (Geometry)GetValue(OverViewPathDataProperty); } |
196 |
set |
197 |
{ |
198 |
SetValue(OverViewPathDataProperty, value); |
199 |
OnPropertyChanged("OverViewPathData"); |
200 |
} |
201 |
} |
202 |
|
203 |
public double CanvasX |
204 |
{ |
205 |
get { return (double)GetValue(CanvasXProperty); } |
206 |
set |
207 |
{ |
208 |
if (this.CanvasX != value) |
209 |
{ |
210 |
SetValue(CanvasXProperty, value); |
211 |
} |
212 |
} |
213 |
} |
214 |
|
215 |
public double CanvasY |
216 |
{ |
217 |
get { return (double)GetValue(CanvasYProperty); } |
218 |
set |
219 |
{ |
220 |
if (this.CanvasY != value) |
221 |
{ |
222 |
SetValue(CanvasYProperty, value); |
223 |
} |
224 |
} |
225 |
} |
226 |
|
227 |
public override bool IsSelected |
228 |
{ |
229 |
get |
230 |
{ |
231 |
return (bool)GetValue(IsSelectedProperty); |
232 |
} |
233 |
set |
234 |
{ |
235 |
SetValue(IsSelectedProperty, value); |
236 |
} |
237 |
} |
238 |
|
239 |
public override ControlType ControlType |
240 |
{ |
241 |
set |
242 |
{ |
243 |
SetValue(ControlTypeProperty, value); |
244 |
} |
245 |
get |
246 |
{ |
247 |
return (ControlType)GetValue(ControlTypeProperty); |
248 |
} |
249 |
} |
250 |
|
251 |
public Double LineSize |
252 |
{ |
253 |
get { return (Double)GetValue(LineSizeProperty); } |
254 |
set |
255 |
{ |
256 |
if (this.LineSize != value) |
257 |
{ |
258 |
SetValue(LineSizeProperty, value); |
259 |
} |
260 |
} |
261 |
} |
262 |
public bool isChain |
263 |
{ |
264 |
get { return (bool)GetValue(isChainProperty); } |
265 |
set |
266 |
{ |
267 |
SetValue(isChainProperty, value); |
268 |
OnPropertyChanged("isChain"); |
269 |
} |
270 |
} |
271 |
public bool isTransOn |
272 |
{ |
273 |
get { return (bool)GetValue(isTransOnProperty); } |
274 |
set |
275 |
{ |
276 |
SetValue(isTransOnProperty, value); |
277 |
OnPropertyChanged("isTransOn"); |
278 |
} |
279 |
} |
280 |
public DoubleCollection DashSize |
281 |
{ |
282 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
283 |
set |
284 |
{ |
285 |
if (this.DashSize != value) |
286 |
{ |
287 |
SetValue(DashSizeProperty, value); |
288 |
OnPropertyChanged("DashSize"); |
289 |
} |
290 |
} |
291 |
} |
292 |
public string UserID |
293 |
{ |
294 |
get { return (string)GetValue(UserIDProperty); } |
295 |
set |
296 |
{ |
297 |
if (this.UserID != value) |
298 |
{ |
299 |
SetValue(UserIDProperty, value); |
300 |
OnPropertyChanged("UserID"); |
301 |
} |
302 |
} |
303 |
} |
304 |
public PaintSet Paint |
305 |
{ |
306 |
get { return (PaintSet)GetValue(PaintProperty); } |
307 |
set |
308 |
{ |
309 |
if (this.Paint != value) |
310 |
{ |
311 |
SetValue(PaintProperty, value); |
312 |
OnPropertyChanged("Paint"); |
313 |
} |
314 |
} |
315 |
} |
316 |
|
317 |
public SolidColorBrush FillColor |
318 |
{ |
319 |
get { return (SolidColorBrush)GetValue(FillColorProperty); } |
320 |
set |
321 |
{ |
322 |
if (this.FillColor != value) |
323 |
{ |
324 |
SetValue(FillColorProperty, value); |
325 |
OnPropertyChanged("FillColor"); |
326 |
} |
327 |
} |
328 |
} |
329 |
public override SolidColorBrush StrokeColor |
330 |
{ |
331 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
332 |
set |
333 |
{ |
334 |
if (this.StrokeColor != value) |
335 |
{ |
336 |
SetValue(StrokeColorProperty, value); |
337 |
OnPropertyChanged("StrokeColor"); |
338 |
} |
339 |
} |
340 |
} |
341 |
public Geometry PathData |
342 |
{ |
343 |
get |
344 |
{ |
345 |
return (Geometry)GetValue(PathDataProperty); |
346 |
} |
347 |
set |
348 |
{ |
349 |
SetValue(PathDataProperty, value); |
350 |
OnPropertyChanged("PathData"); |
351 |
} |
352 |
} |
353 |
public Geometry PathSubData |
354 |
{ |
355 |
get |
356 |
{ |
357 |
return (Geometry)GetValue(PathSubDataProperty); |
358 |
} |
359 |
set |
360 |
{ |
361 |
SetValue(PathSubDataProperty, value); |
362 |
OnPropertyChanged("PathSubData"); |
363 |
} |
364 |
} |
365 |
public Point EndPoint |
366 |
{ |
367 |
get |
368 |
{ |
369 |
return (Point)GetValue(EndPointProperty); |
370 |
} |
371 |
set |
372 |
{ |
373 |
SetValue(EndPointProperty, value); |
374 |
OnPropertyChanged("EndPoint"); |
375 |
} |
376 |
} |
377 |
public Point StartPoint |
378 |
{ |
379 |
get |
380 |
{ |
381 |
return (Point)GetValue(StartPointProperty); |
382 |
} |
383 |
set |
384 |
{ |
385 |
SetValue(StartPointProperty, value); |
386 |
OnPropertyChanged("StartPoint"); |
387 |
} |
388 |
} |
389 |
public List<Point> _pointSet; |
390 |
|
391 |
public List<Point> PointSet |
392 |
{ |
393 |
get |
394 |
{ |
395 |
return (List<Point>)GetValue(PointSetProperty); |
396 |
} |
397 |
set |
398 |
{ |
399 |
SetValue(PointSetProperty, value); |
400 |
OnPropertyChanged("PointSet"); |
401 |
} |
402 |
} |
403 |
|
404 |
public List<Point> pointSet |
405 |
{ |
406 |
get |
407 |
{ |
408 |
return _pointSet; |
409 |
} |
410 |
set |
411 |
{ |
412 |
_pointSet = value; |
413 |
OnPropertyChanged("pointSet"); |
414 |
} |
415 |
} |
416 |
|
417 |
public Double ArcLength |
418 |
{ |
419 |
get { return (Double)GetValue(ArcLengthProperty); } |
420 |
set |
421 |
{ |
422 |
if (this.ArcLength != value) |
423 |
{ |
424 |
SetValue(ArcLengthProperty, value); |
425 |
OnPropertyChanged("ArcLength"); |
426 |
} |
427 |
} |
428 |
} |
429 |
|
430 |
private double _toler = 1; |
431 |
public double Toler |
432 |
{ |
433 |
get { return _toler; } |
434 |
set { _toler = value; } |
435 |
} |
436 |
//강인구 수정 클라우드 사이즈 |
437 |
//private double _arcLength; |
438 |
////private double _arcLength = 30; |
439 |
//public double ArcLength |
440 |
//{ |
441 |
// get { return _arcLength; } |
442 |
// set { _arcLength = value; } |
443 |
//} |
444 |
private bool _fill = false; |
445 |
public bool Fill |
446 |
{ |
447 |
get { return _fill; } |
448 |
set { _fill = value; } |
449 |
} |
450 |
//public double Angle |
451 |
//{ |
452 |
// get { return (double)GetValue(AngleProperty); } |
453 |
// set |
454 |
// { |
455 |
// if (this.Angle != value) |
456 |
// { |
457 |
// SetValue(AngleProperty, value); |
458 |
// OnPropertyChanged("Angle"); |
459 |
// } |
460 |
// } |
461 |
//} |
462 |
public StylusPointSet PointC |
463 |
{ |
464 |
get { return (StylusPointSet)GetValue(StylusPointSetProperty); } |
465 |
set |
466 |
{ |
467 |
SetValue(StylusPointSetProperty, value); |
468 |
OnPropertyChanged("PointC"); |
469 |
} |
470 |
} |
471 |
public double CenterX |
472 |
{ |
473 |
get |
474 |
{ |
475 |
return (double)GetValue(CenterXProperty); |
476 |
} |
477 |
set |
478 |
{ |
479 |
SetValue(CenterXProperty, value); |
480 |
OnPropertyChanged("CenterX"); |
481 |
} |
482 |
} |
483 |
public double CenterY |
484 |
{ |
485 |
get |
486 |
{ |
487 |
return (double)GetValue(CenterYProperty); |
488 |
} |
489 |
set |
490 |
{ |
491 |
SetValue(CenterYProperty, value); |
492 |
OnPropertyChanged("CenterY"); |
493 |
} |
494 |
} |
495 |
public double AngleValue |
496 |
{ |
497 |
get |
498 |
{ |
499 |
return (double)GetValue(AngleProperty); |
500 |
} |
501 |
set |
502 |
{ |
503 |
SetValue(AngleProperty, value); |
504 |
OnPropertyChanged("AngleValue"); |
505 |
} |
506 |
} |
507 |
#endregion |
508 |
#region Data |
509 |
private PathGeometry _pathGeometry = new PathGeometry(); |
510 |
private PathGeometry _pathSubGeometry = new PathGeometry(); |
511 |
#endregion |
512 |
|
513 |
public override void OnApplyTemplate() |
514 |
{ |
515 |
base.OnApplyTemplate(); |
516 |
Base_CloudPath = GetTemplateChild(PART_CloudPath) as Path; |
517 |
Base_CloudSubPath = GetTemplateChild(PART_CloudSubPath) as Path; |
518 |
SetCloud(); |
519 |
} |
520 |
public void SetCloud() |
521 |
{ |
522 |
//this.Width = this.Base_CloudPath.Width; |
523 |
//this.Height = this.Base_CloudPath.Height; |
524 |
|
525 |
this.ApplyTemplate(); |
526 |
|
527 |
Generate(); |
528 |
|
529 |
if (!isChain) |
530 |
{ |
531 |
//ClosePath(); |
532 |
} |
533 |
} |
534 |
public int Generate() |
535 |
{ |
536 |
this._pathGeometry = null; |
537 |
this._pathSubGeometry = null; |
538 |
switch (this.Paint) |
539 |
{ |
540 |
case PaintSet.None: |
541 |
this.FillColor = null; |
542 |
if (Base_CloudSubPath != null) |
543 |
{ |
544 |
Base_CloudPath.Fill = null; |
545 |
Base_CloudSubPath.Fill = null; |
546 |
Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent); |
547 |
//Base_CloudSubPath.StrokeThickness = 3; |
548 |
} |
549 |
break; |
550 |
case PaintSet.Fill: |
551 |
this.FillColor = this.StrokeColor; |
552 |
if (Base_CloudSubPath != null) |
553 |
{ |
554 |
if (isChain) |
555 |
{ |
556 |
Base_CloudPath.Fill = null; |
557 |
Base_CloudSubPath.Fill = null; |
558 |
Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent); |
559 |
//Base_CloudSubPath.StrokeThickness = 3; |
560 |
} |
561 |
else |
562 |
{ |
563 |
Base_CloudSubPath.Stroke = this.StrokeColor; |
564 |
//Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent); |
565 |
Base_CloudSubPath.StrokeThickness = 0.5; |
566 |
Base_CloudPath.Stroke = this.StrokeColor; |
567 |
//Base_CloudPath.StrokeThickness = 3; |
568 |
Base_CloudPath.Fill = this.FillColor; |
569 |
Base_CloudSubPath.Fill = this.FillColor; |
570 |
} |
571 |
} |
572 |
break; |
573 |
case PaintSet.Hatch: |
574 |
if (Base_CloudSubPath != null && !isChain) |
575 |
{ |
576 |
if (isChain) |
577 |
{ |
578 |
Base_CloudPath.Fill = null; |
579 |
Base_CloudSubPath.Fill = null; |
580 |
Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent); |
581 |
//Base_CloudSubPath.StrokeThickness = 3; |
582 |
} |
583 |
else |
584 |
{ |
585 |
var size = this.LineSize > 5 ? 5 : this.LineSize; |
586 |
Base_CloudPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, size * 0.1); |
587 |
Base_CloudSubPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, size * 0.1); |
588 |
Base_CloudSubPath.Stroke = new SolidColorBrush(Colors.Transparent); |
589 |
} |
590 |
} |
591 |
break; |
592 |
default: |
593 |
break; |
594 |
} |
595 |
|
596 |
//강인구 추가 |
597 |
if (Base_CloudPath != null) |
598 |
{ |
599 |
Base_CloudPath.StrokeDashArray.Clear(); |
600 |
Base_CloudSubPath.StrokeDashArray.Clear(); |
601 |
foreach (var item in this.DashSize) |
602 |
{ |
603 |
Base_CloudPath.StrokeDashArray.Add(item); |
604 |
Base_CloudSubPath.StrokeDashArray.Add(item); |
605 |
} |
606 |
} |
607 |
|
608 |
|
609 |
/// set reverse if area is greater 0 - 2012.07.04 added by humkyung |
610 |
double area = MathSet.AreaOf(this.PointSet); |
611 |
bool reverse = (area > 0); |
612 |
/// up to here |
613 |
|
614 |
this._pathGeometry = new PathGeometry { FillRule = FillRule.Nonzero}; |
615 |
this._pathSubGeometry = new PathGeometry { FillRule = FillRule.Nonzero }; |
616 |
|
617 |
if (isTransOn) // true라면 클라우드 컨트롤 |
618 |
{ |
619 |
//PathFigure pathFigure = CloudControl.GeneratePolyWithCloud(this.PointSet, this.ArcLength, reverse); |
620 |
//_pathGeometry.Figures.Add(pathFigure); |
621 |
|
622 |
for (int i = 0; i < this.PointSet.Count - 1; i++) |
623 |
{ |
624 |
var stPoint = this.PointSet[i]; |
625 |
|
626 |
Point edPoint = this.PointSet[i + 1]; |
627 |
|
628 |
//if (i < this.PointSet.Count() - 1) |
629 |
//{ |
630 |
// edPoint = this.PointSet[i + 1]; |
631 |
//} |
632 |
//else |
633 |
//{ |
634 |
// edPoint = this.PointSet[0]; |
635 |
//} |
636 |
|
637 |
PathFigure pathFigure = CloudControl.GenerateLineWithCloud(stPoint, edPoint, this.ArcLength, reverse); |
638 |
_pathGeometry.Figures.Add(pathFigure); |
639 |
} |
640 |
} |
641 |
else |
642 |
{ |
643 |
PathFigure fm = new PathFigure(); |
644 |
fm.StartPoint = this.PointSet[0]; |
645 |
for (int i = 0; i < this.PointSet.Count() - 2; i++) |
646 |
{ |
647 |
fm.Segments.Add(new LineSegment { Point = this.PointSet[i] }); |
648 |
} |
649 |
_pathGeometry.Figures.Add(fm); |
650 |
} |
651 |
|
652 |
if (this.Paint == PaintSet.Fill || this.Paint == PaintSet.Hatch) |
653 |
{ |
654 |
PointCollection pd = new PointCollection(); |
655 |
foreach (var item in this.PointSet) |
656 |
{ |
657 |
pd.Add(item); |
658 |
} |
659 |
_pathSubGeometry.Figures.Add(new PathFigure() |
660 |
{ |
661 |
Segments = new PathSegmentCollection() |
662 |
{ |
663 |
new PolyLineSegment() |
664 |
{ |
665 |
Points = pd |
666 |
}, |
667 |
}, |
668 |
StartPoint = this.PointSet[0] |
669 |
}); |
670 |
|
671 |
this.PathSubData = _pathSubGeometry; |
672 |
} |
673 |
StartPoint = PointSet[0]; |
674 |
this.PathData = this._pathGeometry; |
675 |
|
676 |
this.OverViewPathData = PathData; |
677 |
this.StrokeColor = StrokeColor; |
678 |
this.LineSize = LineSize; |
679 |
EndPoint = PointSet[PointSet.Count - 1]; |
680 |
|
681 |
return 0; |
682 |
} |
683 |
|
684 |
/// <summary> |
685 |
/// draw arcs between p1 and p2 |
686 |
/// </summary> |
687 |
/// <author>humkyung</author> |
688 |
/// <param name="p1"></param> |
689 |
/// <param name="p2"></param> |
690 |
/// <param name="reverse"></param> |
691 |
/// <returns></returns> |
692 |
public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double arcLength_, bool reverse) |
693 |
{ |
694 |
PathFigure pathFigure = new PathFigure(); |
695 |
|
696 |
var radius = arcLength_; |
697 |
double overlap = 5.5D / 6D; |
698 |
|
699 |
double delta = 2 * radius * overlap; |
700 |
|
701 |
pathFigure.StartPoint = p1; |
702 |
pathFigure.IsClosed = false; |
703 |
pathFigure.IsFilled = false; |
704 |
var prev = p2; |
705 |
|
706 |
var curr = p1; |
707 |
|
708 |
var dx = curr.X - prev.X; |
709 |
var dy = curr.Y - prev.Y; |
710 |
|
711 |
var len = Math.Sqrt(dx * dx + dy * dy); |
712 |
|
713 |
dx = dx / len; |
714 |
dy = dy / len; |
715 |
|
716 |
var length = 0D; |
717 |
|
718 |
for (int a = 0; a <= Math.Round(len / delta); a++) |
719 |
{ |
720 |
if (length > len) |
721 |
{ |
722 |
length = len; |
723 |
} |
724 |
|
725 |
ArcSegment arcSeg = new ArcSegment(); |
726 |
|
727 |
var x = prev.X + length * dx; |
728 |
var y = prev.Y + length * dy; |
729 |
|
730 |
if(!double.IsNaN(x) && !double.IsNaN(y)) |
731 |
{ |
732 |
arcSeg.Point = new Point(x, y); |
733 |
arcSeg.Size = new Size(radius, radius); |
734 |
arcSeg.IsLargeArc = true; |
735 |
|
736 |
if(reverse) |
737 |
{ |
738 |
arcSeg.SweepDirection = SweepDirection.Counterclockwise; |
739 |
} |
740 |
else |
741 |
{ |
742 |
arcSeg.SweepDirection = SweepDirection.Clockwise; |
743 |
} |
744 |
|
745 |
if (length == 0) |
746 |
{ |
747 |
pathFigure.StartPoint = arcSeg.Point; |
748 |
} |
749 |
pathFigure.Segments.Add(arcSeg); |
750 |
|
751 |
} |
752 |
|
753 |
length += delta; |
754 |
} |
755 |
pathFigure.IsFilled = false; |
756 |
return pathFigure; |
757 |
} |
758 |
|
759 |
/// <summary> |
760 |
/// draw arcs between p1 and p2 |
761 |
/// </summary> |
762 |
/// <author>humkyung</author> |
763 |
/// <param name="p1"></param> |
764 |
/// <param name="p2"></param> |
765 |
/// <param name="reverse"></param> |
766 |
/// <returns></returns> |
767 |
public static PathFigure GeneratePolyWithCloud(List<Point> points,double arcLength_, bool reverse) |
768 |
{ |
769 |
PathFigure pathFigure = new PathFigure(); |
770 |
|
771 |
var radius = arcLength_; |
772 |
double overlap = 5.5D / 6D; |
773 |
|
774 |
double delta = 2 * radius * overlap; |
775 |
|
776 |
if(points.Count() > 1) |
777 |
{ |
778 |
pathFigure.StartPoint = points[0]; |
779 |
pathFigure.IsClosed = false; |
780 |
pathFigure.IsFilled = false; |
781 |
Point prevArcPoint = points[0]; |
782 |
|
783 |
for (int i = 0; i < points.Count -1; i++) |
784 |
{ |
785 |
Point curr = points[i]; |
786 |
Point prev = points[i + 1]; |
787 |
|
788 |
|
789 |
var dx = curr.X - prev.X; |
790 |
var dy = curr.Y - prev.Y; |
791 |
|
792 |
var len = Math.Sqrt(dx * dx + dy * dy); |
793 |
|
794 |
dx = dx / len; |
795 |
dy = dy / len; |
796 |
|
797 |
var length = 0D; |
798 |
|
799 |
for (int a = 0; a <= Math.Round(len / delta); a++) |
800 |
{ |
801 |
if (length > len) |
802 |
{ |
803 |
length = len; |
804 |
} |
805 |
|
806 |
ArcSegment arcSeg = new ArcSegment(); |
807 |
|
808 |
var x = prev.X + length * dx; |
809 |
var y = prev.Y + length * dy; |
810 |
|
811 |
if (!double.IsNaN(x) && !double.IsNaN(y)) |
812 |
{ |
813 |
arcSeg.Point = new Point(x, y); |
814 |
arcSeg.Size = new Size(radius, radius); |
815 |
arcSeg.IsLargeArc = true; |
816 |
|
817 |
|
818 |
if (reverse) |
819 |
{ |
820 |
arcSeg.SweepDirection = SweepDirection.Counterclockwise; |
821 |
} |
822 |
else |
823 |
{ |
824 |
arcSeg.SweepDirection = SweepDirection.Clockwise; |
825 |
} |
826 |
|
827 |
//if (length == 0) |
828 |
//{ |
829 |
// pathFigure.StartPoint = arcSeg.Point; |
830 |
//} |
831 |
|
832 |
|
833 |
|
834 |
pathFigure.Segments.Add(arcSeg); |
835 |
|
836 |
System.Diagnostics.Debug.WriteLine($"{prevArcPoint} { arcSeg.Point}"); |
837 |
prevArcPoint = arcSeg.Point; |
838 |
|
839 |
} |
840 |
|
841 |
length += delta; |
842 |
} |
843 |
|
844 |
} |
845 |
} |
846 |
|
847 |
pathFigure.IsFilled = false; |
848 |
return pathFigure; |
849 |
} |
850 |
|
851 |
/// <summary> |
852 |
/// draw arcs between p1 and p2 |
853 |
/// </summary> |
854 |
/// <author>humkyung</author> |
855 |
/// <param name="p1"></param> |
856 |
/// <param name="p2"></param> |
857 |
/// <param name="reverse"></param> |
858 |
/// <returns></returns> |
859 |
public static PathFigure GenerateLineWithCloudOld(Point p1, Point p2, double arcLength_, bool reverse) |
860 |
{ |
861 |
PathFigure pathFigure = new PathFigure(); |
862 |
pathFigure.StartPoint = p1; |
863 |
|
864 |
double arcLength = arcLength_; |
865 |
/// draw arcs which has arcLength between p1 and p2 - 2012.06.21 added by humkyung |
866 |
double dx = p2.X - p1.X; |
867 |
double dy = p2.Y - p1.Y; |
868 |
double l = MathSet.DistanceTo(p1, p2); /// distance between p1 and p2 |
869 |
double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI; |
870 |
Point lastPt = new Point(p1.X, p1.Y); |
871 |
double count = l / arcLength; |
872 |
/// normalize |
873 |
dx /= l; |
874 |
dy /= l; |
875 |
Double j = 1; |
876 |
for (j = 1; j < (count - 1); j++) |
877 |
{ |
878 |
ArcSegment arcSeg = new ArcSegment(); |
879 |
arcSeg.Size = new Size(arcLength * CloudControl._CloudArcDepth, arcLength * CloudControl._CloudArcDepth); /// x size and y size of arc |
880 |
arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength); /// end point of arc |
881 |
lastPt = arcSeg.Point; /// save last point |
882 |
//arcSeg.RotationAngle = theta + 90; |
883 |
if (true == reverse) arcSeg.SweepDirection = SweepDirection.Clockwise; |
884 |
|
885 |
pathFigure.Segments.Add(arcSeg); |
886 |
} |
887 |
|
888 |
/// draw arc between last point and end point |
889 |
if ((count > j) || (count > 0)) |
890 |
{ |
891 |
arcLength = MathSet.DistanceTo(lastPt, p2); |
892 |
ArcSegment arcSeg = new ArcSegment(); |
893 |
arcSeg.Size = new Size(arcLength * CloudControl._CloudArcDepth, arcLength * CloudControl._CloudArcDepth); /// x size and y size of arc |
894 |
arcSeg.Point = new Point(p2.X, p2.Y);/// end point of arc |
895 |
//arcSeg.RotationAngle = theta; |
896 |
if (true == reverse) arcSeg.SweepDirection = SweepDirection.Clockwise; |
897 |
pathFigure.Segments.Add(arcSeg); |
898 |
|
899 |
} |
900 |
|
901 |
pathFigure.IsFilled = true; |
902 |
return pathFigure; |
903 |
} |
904 |
|
905 |
/// <summary> |
906 |
/// close path if it's open |
907 |
/// </summary> |
908 |
/// <author>humkyung</author> |
909 |
/// <returns></returns> |
910 |
public int ClosePath() |
911 |
{ |
912 |
if (this.PointSet.Count > 1) |
913 |
{ |
914 |
double d = MathSet.DistanceTo(this.PointSet[0], this.PointSet[this.PointSet.Count - 1]); |
915 |
if (d > _toler) |
916 |
{ |
917 |
/// set reverse if area is greater 0 - 2012.07.04 added by humkyung |
918 |
double area = MathSet.AreaOf(this.PointSet); |
919 |
bool reverse = (area > 0); |
920 |
/// up to here |
921 |
|
922 |
int count = this.PointSet.Count; |
923 |
|
924 |
if (isTransOn) // true라면 클라우드 컨트롤 |
925 |
{ |
926 |
ArcLength = ArcLength == 0 ? 10 : ArcLength; |
927 |
|
928 |
PathFigure pathFigure = CloudControl.GenerateLineWithCloud(this.PointSet[count - 1], this.PointSet[0], this.ArcLength - 5, reverse); |
929 |
|
930 |
if (this.Paint == PaintSet.Fill) |
931 |
{ |
932 |
pathFigure.IsClosed = true; |
933 |
} |
934 |
|
935 |
_pathGeometry.Figures.Add(pathFigure); |
936 |
} |
937 |
else |
938 |
{ |
939 |
|
940 |
PathFigure fm = new PathFigure(); |
941 |
fm.StartPoint = this.PointSet[count - 1]; |
942 |
|
943 |
//for (int i = 0; i < (count - 1); i++) |
944 |
//{ |
945 |
_pathGeometry.Figures[_pathGeometry.Figures.Count - 1].Segments.Add(new LineSegment { Point = this.PointSet[0] }); |
946 |
_pathGeometry.Figures[_pathGeometry.Figures.Count - 1].Segments.Add(new LineSegment { Point = this.PointSet[1] }); |
947 |
//fm.Segments.Add(new LineSegment { Point = this.PointSet[0] }); |
948 |
//} |
949 |
} |
950 |
} |
951 |
} |
952 |
|
953 |
return 0; |
954 |
} |
955 |
public void DrawingCloud() |
956 |
{ |
957 |
AnotherSetCloud(); |
958 |
if (!isChain) |
959 |
{ |
960 |
//ClosePath(); |
961 |
} |
962 |
} |
963 |
public void AnotherSetCloud() |
964 |
{ |
965 |
this.StrokeColor = StrokeColor; |
966 |
this.LineSize = LineSize; |
967 |
this.SetCloud(); |
968 |
//Generate(); |
969 |
this.Width = this.Base_CloudPath.Width; |
970 |
this.Height = this.Base_CloudPath.Height; |
971 |
} |
972 |
public void Dispose() |
973 |
{ |
974 |
//GC.Collect(); |
975 |
////GC.SuppressFinalize(this); |
976 |
this.Base_CloudPath = null; |
977 |
this.Base_CloudSubPath = null; |
978 |
} |
979 |
public event PropertyChangedEventHandler PropertyChanged; |
980 |
protected void OnPropertyChanged(string propName) |
981 |
{ |
982 |
if (PropertyChanged != null) |
983 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
984 |
} |
985 |
|
986 |
public override void UpdateControl() |
987 |
{ |
988 |
var lastIndex = this.PointSet.Count - 1; |
989 |
//this.StartPoint = this.PointSet[0]; |
990 |
//this.EndPoint = this.PointSet[lastIndex]; |
991 |
CenterX = MathSet.getMiddlePoint(this.PointSet[0], this.PointSet[lastIndex]).X; |
992 |
CenterY = MathSet.getMiddlePoint(this.PointSet[0], this.PointSet[lastIndex]).Y; |
993 |
} |
994 |
public void ChangePaint(PaintSet state) |
995 |
{ |
996 |
this.Paint = state; |
997 |
this.SetCloud(); |
998 |
|
999 |
} |
1000 |
|
1001 |
/// <summary> |
1002 |
/// call when mouse is moving while drawing control |
1003 |
/// </summary> |
1004 |
/// <param name="pt"></param> |
1005 |
/// <param name="bAxisLocked"></param> |
1006 |
public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
1007 |
{ |
1008 |
this.isTransOn = true; |
1009 |
this.PointSet.RemoveAt(this.PointSet.Count - 1); |
1010 |
|
1011 |
Point tmp = pt; |
1012 |
|
1013 |
if (bAxisLocked) |
1014 |
{ |
1015 |
CommentAngle = MathSet.returnAngle(this.StartPoint, ref tmp, bAxisLocked); |
1016 |
} |
1017 |
|
1018 |
this.PointSet.Add(tmp); |
1019 |
|
1020 |
this.SetCloud(); |
1021 |
} |
1022 |
|
1023 |
/// <summary> |
1024 |
/// move control point has same location of given pt along given delta |
1025 |
/// </summary> |
1026 |
/// <author>humkyung</author> |
1027 |
/// <date>2019.06.20</date> |
1028 |
/// <param name="pt"></param> |
1029 |
/// <param name="dx"></param> |
1030 |
/// <param name="dy"></param> |
1031 |
public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
1032 |
{ |
1033 |
Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt); |
1034 |
selected.X += dx; |
1035 |
selected.Y += dy; |
1036 |
for (int i = 0; i < (this as IPath).PointSet.Count; i++) |
1037 |
{ |
1038 |
if (pt.Equals((this as IPath).PointSet[i])) |
1039 |
{ |
1040 |
(this as IPath).PointSet[i] = selected; |
1041 |
break; |
1042 |
} |
1043 |
} |
1044 |
this.UpdateControl(); |
1045 |
this.DrawingCloud(); |
1046 |
} |
1047 |
|
1048 |
/// <summary> |
1049 |
/// return Cloud's area |
1050 |
/// </summary> |
1051 |
/// <author>humkyung</author> |
1052 |
/// <date>2019.06.13</date> |
1053 |
public override Rect ItemRect |
1054 |
{ |
1055 |
get |
1056 |
{ |
1057 |
double dMinX = double.MaxValue; |
1058 |
double dMinY = double.MaxValue; |
1059 |
double dMaxX = double.MinValue; |
1060 |
double dMaxY = double.MinValue; |
1061 |
foreach (Point pt in this.PointSet) |
1062 |
{ |
1063 |
dMinX = Math.Min(dMinX, pt.X); |
1064 |
dMinY = Math.Min(dMinY, pt.Y); |
1065 |
dMaxX = Math.Max(dMaxX, pt.X); |
1066 |
dMaxY = Math.Max(dMaxY, pt.Y); |
1067 |
} |
1068 |
|
1069 |
return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
1070 |
} |
1071 |
} |
1072 |
|
1073 |
/// <summary> |
1074 |
/// Serialize this |
1075 |
/// </summary> |
1076 |
/// <param name="sUserId"></param> |
1077 |
/// <returns></returns> |
1078 |
public override string Serialize() |
1079 |
{ |
1080 |
using (S_CloudControl STemp = new S_CloudControl()) |
1081 |
{ |
1082 |
STemp.TransformPoint = "0|0"; |
1083 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
1084 |
//STemp.StrokeColor = "#FF000FFF"; |
1085 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
1086 |
STemp.Name = this.GetType().Name.ToString(); |
1087 |
STemp.Toler = this.Toler; |
1088 |
STemp.PaintState = this.Paint; |
1089 |
STemp.Opac = this.Opacity; |
1090 |
STemp.UserID = this.UserID; |
1091 |
STemp.IsTrans = this.isTransOn; |
1092 |
STemp.IsChain = this.isChain; |
1093 |
STemp.PointSet = new List<Point>(); |
1094 |
STemp.DashSize = this.DashSize; |
1095 |
STemp.StartPoint = this.StartPoint; |
1096 |
STemp.EndPoint = this.EndPoint; |
1097 |
STemp.ArcLength = this.ArcLength; |
1098 |
foreach (var point in this.PointSet) |
1099 |
{ |
1100 |
STemp.PointSet.Add(point); |
1101 |
} |
1102 |
|
1103 |
//STemp.CloudFill = this.Fill; |
1104 |
STemp.ArcLength = this.ArcLength; |
1105 |
///강인구 추가(2017.11.02) |
1106 |
///Memo 추가 |
1107 |
STemp.Memo = this.Memo; |
1108 |
|
1109 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
1110 |
} |
1111 |
} |
1112 |
|
1113 |
/// <summary> |
1114 |
/// create a cloudcontrol from given string |
1115 |
/// </summary> |
1116 |
/// <param name="str"></param> |
1117 |
/// <returns></returns> |
1118 |
public static CloudControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
1119 |
{ |
1120 |
CloudControl instance = null; |
1121 |
using (S_CloudControl s = JsonSerializerHelper.JsonDeserialize<S_CloudControl>(str)) |
1122 |
{ |
1123 |
string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
1124 |
instance = new CloudControl |
1125 |
{ |
1126 |
LineSize = Convert.ToDouble(data2.First()), |
1127 |
Toler = s.Toler, |
1128 |
PointSet = s.PointSet, |
1129 |
ArcLength = s.ArcLength, |
1130 |
Paint = s.PaintState, |
1131 |
Opacity = s.Opac, |
1132 |
StrokeColor = brush, |
1133 |
isTransOn = s.IsTrans, |
1134 |
isChain = s.IsChain, |
1135 |
DashSize = s.DashSize, |
1136 |
UserID = s.UserID, |
1137 |
|
1138 |
StartPoint = s.StartPoint, |
1139 |
EndPoint = s.EndPoint, |
1140 |
Memo = s.Memo |
1141 |
|
1142 |
//Fill = s.CloudFill, |
1143 |
}; |
1144 |
} |
1145 |
|
1146 |
return instance; |
1147 |
} |
1148 |
|
1149 |
#region Method |
1150 |
public override void ApplyOverViewData() |
1151 |
{ |
1152 |
this.OverViewPathData = this.PathData; |
1153 |
} |
1154 |
#endregion |
1155 |
} |
1156 |
|
1157 |
} |