markus / MarkupToPDF / Controls / Polygon / PolygonControl.cs @ e1b36bc0
이력 | 보기 | 이력해설 | 다운로드 (25.6 KB)
1 |
using iTextSharp.text; |
---|---|
2 |
using MarkupToPDF.Common; |
3 |
using MarkupToPDF.Controls.Common; |
4 |
using MarkupToPDF.Serialize.Core; |
5 |
using MarkupToPDF.Serialize.S_Control; |
6 |
using System; |
7 |
using System.Collections.Generic; |
8 |
using System.ComponentModel; |
9 |
using System.Linq; |
10 |
using System.Text; |
11 |
using System.Threading.Tasks; |
12 |
using System.Windows; |
13 |
using System.Windows.Controls; |
14 |
using System.Windows.Forms; |
15 |
using System.Windows.Input; |
16 |
using System.Windows.Media; |
17 |
using System.Windows.Shapes; |
18 |
|
19 |
namespace MarkupToPDF.Controls.Polygon |
20 |
{ |
21 |
public class PolygonControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IMarkupControlData |
22 |
{ |
23 |
#region Constructure |
24 |
|
25 |
static PolygonControl() |
26 |
{ |
27 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(PolygonControl), new FrameworkPropertyMetadata(typeof(PolygonControl))); |
28 |
//ResourceDictionary dictionary = new ResourceDictionary(); |
29 |
//dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
30 |
//Application.Current.Resources.MergedDictionaries.Add(dictionary); |
31 |
} |
32 |
|
33 |
public PolygonControl() |
34 |
{ |
35 |
//this.DefaultStyleKey = typeof(PolygonControl); |
36 |
} |
37 |
|
38 |
public override void Copy(CommentUserInfo lhs) |
39 |
{ |
40 |
if(lhs is PolygonControl item) |
41 |
{ |
42 |
this.LineSize = item.LineSize; |
43 |
this.IsCompleted = item.IsCompleted; |
44 |
this.Opacity = item.Opacity; |
45 |
this.StrokeColor = item.StrokeColor; |
46 |
this.ControlType = item.ControlType; |
47 |
this.DashSize = item.DashSize; |
48 |
this.StartPoint = new Point(item.StartPoint.X, item.StartPoint.Y); |
49 |
this.EndPoint = new Point(item.EndPoint.X, item.EndPoint.Y); |
50 |
this.PointSet = item.PointSet.ConvertAll(x => new Point(x.X, x.Y)); |
51 |
this.UserID = item.UserID; |
52 |
this.Paint = item.Paint; |
53 |
this.Memo = item.Memo; |
54 |
this.ZIndex = item.ZIndex; |
55 |
this.GroupID = item.GroupID; |
56 |
} |
57 |
} |
58 |
|
59 |
public override CommentUserInfo Clone() |
60 |
{ |
61 |
var clone = new PolygonControl(); |
62 |
clone.Copy(this); |
63 |
return clone; |
64 |
} |
65 |
|
66 |
#endregion |
67 |
|
68 |
#region Variable |
69 |
private const string PART_PolyPath = "PART_PolyPath"; |
70 |
|
71 |
public Path Base_PolyPath = null; |
72 |
|
73 |
#endregion |
74 |
|
75 |
#region Internal Method |
76 |
public override void OnApplyTemplate() |
77 |
{ |
78 |
base.OnApplyTemplate(); |
79 |
|
80 |
Base_PolyPath = GetTemplateChild(PART_PolyPath) as Path; |
81 |
|
82 |
if (Base_PolyPath == null) |
83 |
return; |
84 |
|
85 |
this.SetPolyPath(); |
86 |
} |
87 |
|
88 |
|
89 |
#endregion |
90 |
|
91 |
#region Method |
92 |
|
93 |
public override void ApplyOverViewData() |
94 |
{ |
95 |
this.OverViewPathData = this.PathData; |
96 |
} |
97 |
|
98 |
#endregion |
99 |
|
100 |
#region Dependency Properties |
101 |
|
102 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
103 |
"UserID", typeof(string), typeof(PolygonControl), new PropertyMetadata(null)); |
104 |
|
105 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
106 |
"LineSize", typeof(double), typeof(PolygonControl), new PropertyMetadata((Double)3)); |
107 |
|
108 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
109 |
"StrokeColor", typeof(SolidColorBrush), typeof(PolygonControl), |
110 |
new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
111 |
|
112 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
113 |
"PathData", typeof(Geometry), typeof(PolygonControl), null); |
114 |
|
115 |
//강인구 추가 |
116 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
117 |
"DashSize", typeof(DoubleCollection), typeof(PolygonControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged)); |
118 |
|
119 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
120 |
"OverViewPathData", typeof(Geometry), typeof(PolygonControl), null); |
121 |
//강인구 추가 |
122 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
123 |
"Paint", typeof(PaintSet), typeof(PolygonControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
124 |
|
125 |
public static readonly DependencyProperty IsCompletedProperty = DependencyProperty.Register( |
126 |
"IsCompleted", typeof(bool), typeof(PolygonControl), null); |
127 |
|
128 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
129 |
"StartPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
130 |
|
131 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
132 |
"EndPoint", typeof(Point), typeof(PolygonControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
133 |
|
134 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
135 |
"PointSet", typeof(List<Point>), typeof(PolygonControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
136 |
|
137 |
/// <summary> |
138 |
/// StylusPointSet을 List<Point>로 대체하면 PointValueChanged가 작동안한다. |
139 |
/// </summary> |
140 |
//public static readonly DependencyProperty StylusPointSetProperty = DependencyProperty.Register( |
141 |
// "PointC", typeof(StylusPointSet), typeof(PolygonControl), new PropertyMetadata(new StylusPointSet(), PointValueChanged)); |
142 |
|
143 |
public static readonly DependencyProperty AngleProperty = |
144 |
DependencyProperty.Register("Angle", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback |
145 |
(AngleValueChanged))); |
146 |
|
147 |
public static readonly DependencyProperty CenterXProperty = |
148 |
DependencyProperty.Register("CenterX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
149 |
|
150 |
public static readonly DependencyProperty CenterYProperty = |
151 |
DependencyProperty.Register("CenterY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
152 |
|
153 |
public static readonly DependencyProperty IsSelectedProperty = |
154 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(PolygonControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
155 |
|
156 |
public static readonly DependencyProperty ControlTypeProperty = |
157 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(PolygonControl), new FrameworkPropertyMetadata(ControlType.PolygonControl)); |
158 |
|
159 |
public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
160 |
"CanvasX", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
161 |
|
162 |
public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
163 |
"CanvasY", typeof(double), typeof(PolygonControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
164 |
|
165 |
#endregion |
166 |
|
167 |
#region PropertyChanged Method |
168 |
public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
169 |
{ |
170 |
var instance = (PolygonControl)sender; |
171 |
|
172 |
if (e.OldValue != e.NewValue && instance != null) |
173 |
{ |
174 |
instance.SetValue(e.Property, e.NewValue); |
175 |
//Canvas.SetLeft(instance, instance.CanvasX); |
176 |
//Canvas.SetTop(instance, instance.CanvasY); |
177 |
} |
178 |
} |
179 |
|
180 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
181 |
{ |
182 |
var instance = (PolygonControl)sender; |
183 |
|
184 |
if (e.OldValue != e.NewValue && instance != null) |
185 |
{ |
186 |
instance.SetValue(e.Property, e.NewValue); |
187 |
//강인구 추가 |
188 |
instance.SetPolyPath(); |
189 |
//instance.SetPolyPath(); 주석처리 |
190 |
|
191 |
} |
192 |
} |
193 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
194 |
{ |
195 |
var instance = (PolygonControl)sender; |
196 |
|
197 |
if (e.OldValue != e.NewValue && instance != null) |
198 |
{ |
199 |
instance.SetValue(e.Property, e.NewValue); |
200 |
instance.SetPolyPath(); |
201 |
} |
202 |
} |
203 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
204 |
{ |
205 |
var instance = (PolygonControl)sender; |
206 |
if (e.OldValue != e.NewValue && instance != null) |
207 |
{ |
208 |
instance.SetValue(e.Property, e.NewValue); |
209 |
instance.SetPolyPath(); |
210 |
} |
211 |
} |
212 |
|
213 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
214 |
{ |
215 |
//var instance = (PolygonControl)sender; |
216 |
|
217 |
//if (e.OldValue != e.NewValue && instance.Base_PolyPath != null) |
218 |
//{ |
219 |
// instance.SetValue(e.Property, e.NewValue); |
220 |
|
221 |
// if (instance.IsSelected) |
222 |
// { |
223 |
// instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Blue); |
224 |
// } |
225 |
// else |
226 |
// { |
227 |
// instance.Base_PolyPath.Stroke = new SolidColorBrush(Colors.Transparent); |
228 |
// } |
229 |
//} |
230 |
} |
231 |
|
232 |
#endregion |
233 |
|
234 |
#region Properties |
235 |
|
236 |
|
237 |
public bool IsCompleted |
238 |
{ |
239 |
get { return (bool)GetValue(IsCompletedProperty); } |
240 |
set |
241 |
{ |
242 |
SetValue(IsCompletedProperty, value); |
243 |
OnPropertyChanged("IsCompleted"); |
244 |
} |
245 |
} |
246 |
|
247 |
|
248 |
public Geometry OverViewPathData |
249 |
{ |
250 |
get { return (Geometry)GetValue(OverViewPathDataProperty); } |
251 |
set |
252 |
{ |
253 |
SetValue(OverViewPathDataProperty, value); |
254 |
OnPropertyChanged("OverViewPathData"); |
255 |
} |
256 |
} |
257 |
|
258 |
public double CanvasX |
259 |
{ |
260 |
get { return (double)GetValue(CanvasXProperty); } |
261 |
set |
262 |
{ |
263 |
if (this.CanvasX != value) |
264 |
{ |
265 |
SetValue(CanvasXProperty, value); |
266 |
OnPropertyChanged("CanvasX"); |
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
public double CanvasY |
272 |
{ |
273 |
get { return (double)GetValue(CanvasYProperty); } |
274 |
set |
275 |
{ |
276 |
if (this.CanvasY != value) |
277 |
{ |
278 |
SetValue(CanvasYProperty, value); |
279 |
OnPropertyChanged("CanvasY"); |
280 |
} |
281 |
} |
282 |
} |
283 |
|
284 |
public override bool IsSelected |
285 |
{ |
286 |
get |
287 |
{ |
288 |
return (bool)GetValue(IsSelectedProperty); |
289 |
} |
290 |
set |
291 |
{ |
292 |
SetValue(IsSelectedProperty, value); |
293 |
OnPropertyChanged("IsSelected"); |
294 |
} |
295 |
} |
296 |
|
297 |
public PaintSet Paint |
298 |
{ |
299 |
get { return (PaintSet)GetValue(PaintProperty); } |
300 |
set |
301 |
{ |
302 |
if (this.Paint != value) |
303 |
{ |
304 |
SetValue(PaintProperty, value); |
305 |
OnPropertyChanged("Paint"); |
306 |
} |
307 |
} |
308 |
} |
309 |
|
310 |
public override ControlType ControlType |
311 |
{ |
312 |
set |
313 |
{ |
314 |
SetValue(ControlTypeProperty, value); |
315 |
OnPropertyChanged("ControlType"); |
316 |
} |
317 |
get |
318 |
{ |
319 |
return (ControlType)GetValue(ControlTypeProperty); |
320 |
} |
321 |
} |
322 |
|
323 |
public Double LineSize |
324 |
{ |
325 |
get { return (Double)GetValue(LineSizeProperty); } |
326 |
set |
327 |
{ |
328 |
if (this.LineSize != value) |
329 |
{ |
330 |
SetValue(LineSizeProperty, value); |
331 |
OnPropertyChanged("LineSize"); |
332 |
} |
333 |
} |
334 |
} |
335 |
|
336 |
public DoubleCollection DashSize |
337 |
{ |
338 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
339 |
set |
340 |
{ |
341 |
if (this.DashSize != value) |
342 |
{ |
343 |
SetValue(DashSizeProperty, value); |
344 |
OnPropertyChanged("DashSize"); |
345 |
} |
346 |
} |
347 |
} |
348 |
public string UserID |
349 |
{ |
350 |
get { return (string)GetValue(UserIDProperty); } |
351 |
set |
352 |
{ |
353 |
if (this.UserID != value) |
354 |
{ |
355 |
SetValue(UserIDProperty, value); |
356 |
OnPropertyChanged("UserID"); |
357 |
} |
358 |
} |
359 |
} |
360 |
public List<Point> PointSet |
361 |
{ |
362 |
get { return (List<Point>)GetValue(PointSetProperty); } |
363 |
set { SetValue(PointSetProperty, value); |
364 |
OnPropertyChanged("PointSet"); |
365 |
} |
366 |
} //public StylusPointSet PointC |
367 |
//{ |
368 |
// get { return (StylusPointSet)GetValue(StylusPointSetProperty); } |
369 |
// set |
370 |
// { |
371 |
// SetValue(StylusPointSetProperty, value); |
372 |
// OnPropertyChanged("PointC"); |
373 |
// } |
374 |
//} |
375 |
|
376 |
|
377 |
public double CenterX |
378 |
{ |
379 |
get { return (double)GetValue(CenterXProperty); } |
380 |
set { SetValue(CenterXProperty, value); |
381 |
OnPropertyChanged("CenterX"); |
382 |
} |
383 |
} |
384 |
public double CenterY |
385 |
{ |
386 |
get |
387 |
{ |
388 |
return (double)GetValue(CenterYProperty); |
389 |
} |
390 |
set |
391 |
{ |
392 |
SetValue(CenterYProperty, value); |
393 |
OnPropertyChanged("CenterY"); |
394 |
} |
395 |
} |
396 |
public override SolidColorBrush StrokeColor |
397 |
{ |
398 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
399 |
set |
400 |
{ |
401 |
if (this.StrokeColor != value) |
402 |
{ |
403 |
SetValue(StrokeColorProperty, value); |
404 |
OnPropertyChanged("StrokeColor"); |
405 |
} |
406 |
} |
407 |
} |
408 |
public Geometry PathData |
409 |
{ |
410 |
get { return (Geometry)GetValue(PathDataProperty); } |
411 |
set |
412 |
{ |
413 |
SetValue(PathDataProperty, value); |
414 |
OnPropertyChanged("PathData"); |
415 |
} |
416 |
} |
417 |
|
418 |
//public double Angle |
419 |
//{ |
420 |
// get { return (double)GetValue(AngleProperty); } |
421 |
// set |
422 |
// { |
423 |
// if (this.Angle != value) |
424 |
// { |
425 |
// SetValue(AngleProperty, value); |
426 |
// OnPropertyChanged("Angle"); |
427 |
// } |
428 |
// } |
429 |
//} |
430 |
|
431 |
public Point EndPoint |
432 |
{ |
433 |
get { return (Point)GetValue(EndPointProperty); } |
434 |
set |
435 |
{ |
436 |
SetValue(EndPointProperty, value); |
437 |
OnPropertyChanged("EndPoint"); |
438 |
} |
439 |
} |
440 |
public Point StartPoint |
441 |
{ |
442 |
get { return (Point)GetValue(StartPointProperty); } |
443 |
set |
444 |
{ |
445 |
SetValue(StartPointProperty, value); |
446 |
OnPropertyChanged("StartPoint"); |
447 |
} |
448 |
} |
449 |
#endregion |
450 |
|
451 |
public override void UpdateControl() |
452 |
{ |
453 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
454 |
this.EndPoint = new Point(this.PointSet[this.PointSet.Count - 1].X, this.PointSet[this.PointSet.Count - 1].Y); |
455 |
|
456 |
SetPolyPath(); |
457 |
} |
458 |
|
459 |
private void SetPolyPath() |
460 |
{ |
461 |
if (Base_PolyPath != null) |
462 |
{ |
463 |
Base_PolyPath.StrokeDashArray.Clear(); |
464 |
foreach (var item in this.DashSize) |
465 |
{ |
466 |
Base_PolyPath.StrokeDashArray.Add(item); |
467 |
} |
468 |
|
469 |
PathGeometry pathGeometry = new PathGeometry(); |
470 |
PathFigure pathFigure = new PathFigure(); |
471 |
PolyLineSegment instance = new PolyLineSegment(this.PointSet, true); |
472 |
|
473 |
StartPoint = instance.Points.First(); |
474 |
pathFigure.StartPoint = StartPoint; |
475 |
EndPoint = instance.Points.Last(); |
476 |
pathFigure.Segments.Add(instance); |
477 |
pathGeometry.Figures.Add(pathFigure); |
478 |
|
479 |
//강인구 추가(Chain이 아닌 Polygon일때만 채우기 및 빗금 하기) |
480 |
if (ControlType == ControlType.PolygonControl) |
481 |
{ |
482 |
switch (this.Paint) |
483 |
{ |
484 |
case PaintSet.None: |
485 |
{ |
486 |
pathFigure.IsFilled = false; |
487 |
//강인구 추가 |
488 |
Base_PolyPath.Fill = null; |
489 |
} |
490 |
break; |
491 |
case PaintSet.Fill: |
492 |
{ |
493 |
Base_PolyPath.Fill = this.StrokeColor; |
494 |
} |
495 |
break; |
496 |
case PaintSet.Hatch: |
497 |
{ |
498 |
var size = this.LineSize > 5 ? 5 : this.LineSize; |
499 |
Base_PolyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor, 3 * 0.1); |
500 |
} |
501 |
break; |
502 |
default: |
503 |
break; |
504 |
} |
505 |
} |
506 |
|
507 |
this.PathData = pathGeometry; |
508 |
this.ApplyOverViewData(); |
509 |
} |
510 |
} |
511 |
|
512 |
public void ChangePaint(PaintSet state) |
513 |
{ |
514 |
|
515 |
} |
516 |
|
517 |
/// <summary> |
518 |
/// call when mouse is moving while drawing control |
519 |
/// </summary> |
520 |
/// <author>humkyung</author> |
521 |
/// <param name="pt"></param> |
522 |
/// <param name="bAxisLocked"></param> |
523 |
public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
524 |
{ |
525 |
this.PointSet.RemoveAt(this.PointSet.Count - 1); |
526 |
|
527 |
Point tmp = pt; |
528 |
|
529 |
if (bAxisLocked) |
530 |
{ |
531 |
CommentAngle = MathSet.returnAngle(this.PointSet[this.PointSet.Count - 1], ref tmp, bAxisLocked); |
532 |
} |
533 |
|
534 |
if (this.PointSet.Count > 2 && StartPoint == tmp) |
535 |
{ |
536 |
this.IsCompleted = true; |
537 |
|
538 |
//var firstPoint = this.PointSet.First(); |
539 |
//this.PointSet.Add(firstPoint); |
540 |
|
541 |
//this.ApplyOverViewData(); |
542 |
|
543 |
UpdateControl(); |
544 |
} |
545 |
else |
546 |
{ |
547 |
|
548 |
this.PointSet.Add(tmp); |
549 |
|
550 |
this.UpdateControl(); |
551 |
} |
552 |
} |
553 |
|
554 |
/// <summary> |
555 |
/// move control point has same location of given pt along given delta |
556 |
/// </summary> |
557 |
/// <author>humkyung</author> |
558 |
/// <date>2019.06.20</date> |
559 |
/// <param name="pt"></param> |
560 |
/// <param name="dx"></param> |
561 |
/// <param name="dy"></param> |
562 |
public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
563 |
{ |
564 |
var pointSet = (this as IPath).PointSet; |
565 |
|
566 |
Point selected = MathSet.getNearPoint(pointSet, pt); |
567 |
|
568 |
Point NearStartpoint = MathSet.getNearPoint(pointSet, pt); |
569 |
|
570 |
var tmpPointSet = pointSet.Select((x,inx)=> new { x,inx}); |
571 |
|
572 |
var selectPoint = tmpPointSet.Where(x => x.x.Equals(pt)); |
573 |
|
574 |
if(selectPoint.Count() > 0) |
575 |
{ |
576 |
if (tmpPointSet.Count() > selectPoint.First().inx + 1) |
577 |
{ |
578 |
NearStartpoint = pointSet[selectPoint.First().inx + 1]; |
579 |
} |
580 |
else |
581 |
{ |
582 |
NearStartpoint = pointSet[selectPoint.First().inx - 1]; |
583 |
} |
584 |
} |
585 |
|
586 |
selected.X += dx; |
587 |
selected.Y += dy; |
588 |
|
589 |
Point tmp = selected; |
590 |
|
591 |
CommentAngle = MathSet.returnAngle(NearStartpoint, ref tmp, bAxisLocked); |
592 |
|
593 |
if (bAxisLocked) |
594 |
{ |
595 |
selected = tmp; |
596 |
} |
597 |
|
598 |
for (int i = 0; i < (this as IPath).PointSet.Count; i++) |
599 |
{ |
600 |
if (pt.Equals((this as IPath).PointSet[i])) |
601 |
{ |
602 |
(this as IPath).PointSet[i] = selected; |
603 |
} |
604 |
} |
605 |
this.UpdateControl(); |
606 |
} |
607 |
|
608 |
/// <summary> |
609 |
/// return Polygon's area |
610 |
/// </summary> |
611 |
/// <author>humkyung</author> |
612 |
/// <date>2019.06.13</date> |
613 |
public override Rect ItemRect |
614 |
{ |
615 |
get |
616 |
{ |
617 |
double dMinX = double.MaxValue; |
618 |
double dMinY = double.MaxValue; |
619 |
double dMaxX = double.MinValue; |
620 |
double dMaxY = double.MinValue; |
621 |
foreach (Point pt in this.PointSet) |
622 |
{ |
623 |
dMinX = Math.Min(dMinX, pt.X); |
624 |
dMinY = Math.Min(dMinY, pt.Y); |
625 |
dMaxX = Math.Max(dMaxX, pt.X); |
626 |
dMaxY = Math.Max(dMaxY, pt.Y); |
627 |
} |
628 |
|
629 |
return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
630 |
} |
631 |
} |
632 |
|
633 |
/// <summary> |
634 |
/// Serialize this |
635 |
/// </summary> |
636 |
/// <param name="sUserId"></param> |
637 |
/// <returns></returns> |
638 |
public override string Serialize() |
639 |
{ |
640 |
using (S_PolyControl ctrl = new S_PolyControl()) |
641 |
{ |
642 |
ctrl.TransformPoint = "0|0"; |
643 |
ctrl.SizeSet = String.Format("{0}", this.LineSize); |
644 |
ctrl.StrokeColor = this.StrokeColor.Color.ToString(); |
645 |
//ctrl.StrokeColor = "#FF000FFF"; |
646 |
ctrl.Name = this.GetType().Name.ToString(); |
647 |
//ctrl.Toler = this.Toler; |
648 |
ctrl.PaintState = this.Paint; |
649 |
ctrl.Opac = this.Opacity; |
650 |
ctrl.UserID = this.UserID; |
651 |
ctrl.PaintState = this.Paint; |
652 |
//강인구 추가(Chain인지 Polygon인지 구분) |
653 |
ctrl.Type = this.ControlType; |
654 |
//ctrl.IsTrans = this.isTransOn; |
655 |
//ctrl.IsChain = this.isChain; |
656 |
ctrl.PointSet = new List<Point>(); |
657 |
ctrl.DashSize = this.DashSize; |
658 |
ctrl.StartPoint = this.StartPoint; |
659 |
ctrl.EndPoint = this.EndPoint; |
660 |
ctrl.IsCompleted = this.IsCompleted; |
661 |
foreach (var point in this.PointSet) |
662 |
{ |
663 |
ctrl.PointSet.Add(point); |
664 |
} |
665 |
///강인구 추가(2017.11.02) |
666 |
///Memo 추가 |
667 |
ctrl.Memo = this.Memo; |
668 |
|
669 |
ctrl.ZIndex = this.ZIndex; |
670 |
ctrl.GroupID = this.GroupID; |
671 |
|
672 |
return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize())); |
673 |
} |
674 |
} |
675 |
|
676 |
/// <summary> |
677 |
/// create a polygoncontrol from given string |
678 |
/// </summary> |
679 |
/// <param name="str"></param> |
680 |
/// <returns></returns> |
681 |
public static PolygonControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
682 |
{ |
683 |
using (S_PolyControl s = JsonSerializerHelper.JsonDeserialize<S_PolyControl>(str)) |
684 |
{ |
685 |
string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
686 |
return new PolygonControl |
687 |
{ |
688 |
LineSize = Convert.ToDouble(data2.First()), |
689 |
//Toler = s.Toler, |
690 |
IsCompleted = s.IsCompleted, |
691 |
//PointSet = new List<Point>(), |
692 |
Opacity = s.Opac, |
693 |
StrokeColor = brush, |
694 |
//강인구 추가(Chain인지 Polygon인지 구분) |
695 |
ControlType = s.Type, |
696 |
DashSize = s.DashSize, |
697 |
StartPoint = s.StartPoint, |
698 |
EndPoint = s.EndPoint, |
699 |
PointSet = s.PointSet, |
700 |
UserID = s.UserID, |
701 |
Paint = s.PaintState, |
702 |
Memo = s.Memo, |
703 |
ZIndex = s.ZIndex, |
704 |
GroupID = s.GroupID |
705 |
}; |
706 |
} |
707 |
} |
708 |
|
709 |
|
710 |
#region Dispose |
711 |
public void Dispose() |
712 |
{ |
713 |
//GC.Collect(); |
714 |
////GC.SuppressFinalize(this); |
715 |
this.Base_PolyPath = null; |
716 |
} |
717 |
#endregion |
718 |
|
719 |
#region INotifyPropertyChanged |
720 |
private void OnPropertyChanged(string name) |
721 |
{ |
722 |
if (PropertyChanged != null) |
723 |
{ |
724 |
PropertyChanged(this, new PropertyChangedEventArgs(name)); |
725 |
} |
726 |
} |
727 |
|
728 |
public event PropertyChangedEventHandler PropertyChanged; |
729 |
#endregion |
730 |
} |
731 |
|
732 |
public class StylusPointSet : INotifyPropertyChanged |
733 |
{ |
734 |
public StylusPointSet() |
735 |
{ |
736 |
if (pointSet == null) |
737 |
pointSet = new List<Point>(); |
738 |
} |
739 |
|
740 |
public List<Point> _pointSet; |
741 |
|
742 |
public List<Point> pointSet |
743 |
{ |
744 |
get |
745 |
{ |
746 |
return _pointSet; |
747 |
} |
748 |
set |
749 |
{ |
750 |
_pointSet = value; |
751 |
OnPropertyChanged("pointSet"); |
752 |
} |
753 |
} |
754 |
|
755 |
#region INotifyPropertyChanged |
756 |
private void OnPropertyChanged(string name) |
757 |
{ |
758 |
if (PropertyChanged != null) |
759 |
{ |
760 |
PropertyChanged(this, new PropertyChangedEventArgs(name)); |
761 |
} |
762 |
} |
763 |
|
764 |
public event PropertyChangedEventHandler PropertyChanged; |
765 |
#endregion |
766 |
} |
767 |
} |