markus / MarkupToPDF / Controls / Shape / RectangleControl.cs @ 036650a0
이력 | 보기 | 이력해설 | 다운로드 (19.9 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.Windows; |
8 |
using System.Windows.Shapes; |
9 |
using System.Windows.Controls; |
10 |
using System.Windows.Media; |
11 |
using MarkupToPDF.Controls.Common; |
12 |
using MarkupToPDF.Common; |
13 |
using MarkupToPDF.Serialize.Core; |
14 |
using MarkupToPDF.Serialize.S_Control; |
15 |
|
16 |
namespace MarkupToPDF.Controls.Shape |
17 |
{ |
18 |
//강인구 추가 IShapeControl |
19 |
public class RectangleControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IShapeControl, IDashControl |
20 |
{ |
21 |
public Path Base_RectPath { get; set; } |
22 |
private const string PART_RectPath = "PART_RectPath"; |
23 |
|
24 |
#region Property |
25 |
|
26 |
|
27 |
public MouseMode mousemode |
28 |
{ |
29 |
get |
30 |
{ |
31 |
return (MouseMode)GetValue(mousemodeProperty); |
32 |
} |
33 |
set |
34 |
{ |
35 |
SetValue(mousemodeProperty, value); |
36 |
OnPropertyChanged("mousemode"); |
37 |
} |
38 |
} |
39 |
|
40 |
public SolidColorBrush StrokeColor |
41 |
{ |
42 |
get |
43 |
{ |
44 |
return (SolidColorBrush)GetValue(StrokeColorProperty); |
45 |
} |
46 |
set |
47 |
{ |
48 |
SetValue(StrokeColorProperty, value); |
49 |
OnPropertyChanged("StrokeColor"); |
50 |
} |
51 |
} |
52 |
|
53 |
public Double LineSize |
54 |
{ |
55 |
get |
56 |
{ |
57 |
return (Double)GetValue(LineSizeProperty); |
58 |
} |
59 |
set |
60 |
{ |
61 |
SetValue(LineSizeProperty, value); |
62 |
OnPropertyChanged("LineSize"); |
63 |
} |
64 |
} |
65 |
|
66 |
public Geometry PathData |
67 |
{ |
68 |
get |
69 |
{ |
70 |
return (Geometry)GetValue(PathDataProperty); |
71 |
} |
72 |
set |
73 |
{ |
74 |
SetValue(PathDataProperty, value); |
75 |
OnPropertyChanged("PathData"); |
76 |
} |
77 |
|
78 |
} |
79 |
|
80 |
public Geometry OverViewPathData |
81 |
{ |
82 |
get |
83 |
{ |
84 |
return (Geometry)GetValue(OverViewPathDataProperty); |
85 |
} |
86 |
set |
87 |
{ |
88 |
SetValue(OverViewPathDataProperty, value); |
89 |
OnPropertyChanged("OverViewPathData"); |
90 |
} |
91 |
} |
92 |
|
93 |
public SolidColorBrush FillColor |
94 |
{ |
95 |
get { return (SolidColorBrush)GetValue(FillColorProperty); } |
96 |
set |
97 |
{ |
98 |
SetValue(FillColorProperty, value); |
99 |
OnPropertyChanged("FillColor"); |
100 |
} |
101 |
} |
102 |
//강인구 추가 |
103 |
public DoubleCollection DashSize |
104 |
{ |
105 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
106 |
set |
107 |
{ |
108 |
if (this.DashSize != value) |
109 |
{ |
110 |
SetValue(DashSizeProperty, value); |
111 |
} |
112 |
} |
113 |
} |
114 |
|
115 |
public Point StartPoint |
116 |
{ |
117 |
get |
118 |
{ |
119 |
return (Point)GetValue(StartPointProperty); |
120 |
} |
121 |
set |
122 |
{ |
123 |
SetValue(StartPointProperty, value); |
124 |
OnPropertyChanged("StartPoint"); |
125 |
} |
126 |
} |
127 |
|
128 |
public Point SetPoint |
129 |
{ |
130 |
get |
131 |
{ |
132 |
return (Point)GetValue(SetPointProperty); |
133 |
} |
134 |
set |
135 |
{ |
136 |
SetValue(SetPointProperty, value); |
137 |
OnPropertyChanged("SetPoint"); |
138 |
} |
139 |
} |
140 |
|
141 |
public Point OriginPoint |
142 |
{ |
143 |
get |
144 |
{ |
145 |
return (Point)GetValue(OriginPointProperty); |
146 |
} |
147 |
set |
148 |
{ |
149 |
SetValue(OriginPointProperty, value); |
150 |
OnPropertyChanged("OriginPoint"); |
151 |
} |
152 |
} |
153 |
|
154 |
public Point TopRightPoint |
155 |
{ |
156 |
get |
157 |
{ |
158 |
return (Point)GetValue(TopRightPointProperty); |
159 |
} |
160 |
set |
161 |
{ |
162 |
SetValue(TopRightPointProperty, value); |
163 |
OnPropertyChanged("TopRightPoint"); |
164 |
} |
165 |
} |
166 |
|
167 |
public Point LeftBottomPoint |
168 |
{ |
169 |
get |
170 |
{ |
171 |
return (Point)GetValue(LeftBottomPointProperty); |
172 |
} |
173 |
set |
174 |
{ |
175 |
SetValue(LeftBottomPointProperty, value); |
176 |
OnPropertyChanged("LeftBottomPoint"); |
177 |
} |
178 |
} |
179 |
|
180 |
public Point EndPoint |
181 |
{ |
182 |
get |
183 |
{ |
184 |
return (Point)GetValue(EndPointProperty); |
185 |
} |
186 |
set |
187 |
{ |
188 |
SetValue(EndPointProperty, value); |
189 |
OnPropertyChanged("EndPoint"); |
190 |
} |
191 |
} |
192 |
|
193 |
public bool IsSelected |
194 |
{ |
195 |
get |
196 |
{ |
197 |
return (bool)GetValue(IsSelectedProperty); |
198 |
} |
199 |
set |
200 |
{ |
201 |
SetValue(IsSelectedProperty, value); |
202 |
OnPropertyChanged("IsSelected"); |
203 |
} |
204 |
} |
205 |
|
206 |
override public ControlType ControlType |
207 |
{ |
208 |
set |
209 |
{ |
210 |
SetValue(ControlTypeProperty, value); |
211 |
OnPropertyChanged("ControlType"); |
212 |
} |
213 |
get |
214 |
{ |
215 |
return (ControlType)GetValue(ControlTypeProperty); |
216 |
} |
217 |
} |
218 |
|
219 |
public List<Point> PointSet |
220 |
{ |
221 |
get { return (List<Point>)GetValue(PointSetProperty); } |
222 |
set { SetValue(PointSetProperty, value); } |
223 |
} |
224 |
|
225 |
|
226 |
public double CanvasX |
227 |
{ |
228 |
get { return (double)GetValue(CanvasXProperty); } |
229 |
set |
230 |
{ |
231 |
if (this.CanvasX != value) |
232 |
{ |
233 |
SetValue(CanvasXProperty, value); |
234 |
OnPropertyChanged("CanvasX"); |
235 |
} |
236 |
} |
237 |
} |
238 |
|
239 |
public double CanvasY |
240 |
{ |
241 |
get { return (double)GetValue(CanvasYProperty); } |
242 |
set |
243 |
{ |
244 |
if (this.CanvasY != value) |
245 |
{ |
246 |
SetValue(CanvasYProperty, value); |
247 |
OnPropertyChanged("CanvasY"); |
248 |
} |
249 |
} |
250 |
} |
251 |
|
252 |
public PaintSet Paint |
253 |
{ |
254 |
get { return (PaintSet)GetValue(PaintProperty); } |
255 |
set |
256 |
{ |
257 |
if (this.Paint != value) |
258 |
{ |
259 |
SetValue(PaintProperty, value); |
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
public double Angle |
265 |
{ |
266 |
get { return (double)GetValue(AngleProperty); } |
267 |
set |
268 |
{ |
269 |
if (this.Angle != value) |
270 |
{ |
271 |
SetValue(AngleProperty, value); |
272 |
} |
273 |
} |
274 |
} |
275 |
public string UserID |
276 |
{ |
277 |
get { return (string)GetValue(UserIDProperty); } |
278 |
set |
279 |
{ |
280 |
if (this.UserID != value) |
281 |
{ |
282 |
SetValue(UserIDProperty, value); |
283 |
OnPropertyChanged("UserID"); |
284 |
} |
285 |
} |
286 |
} |
287 |
|
288 |
#endregion |
289 |
|
290 |
#region Dependency Property |
291 |
|
292 |
|
293 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
294 |
"UserID", typeof(string), typeof(RectangleControl), new PropertyMetadata(null)); |
295 |
|
296 |
public static readonly DependencyProperty mousemodeProperty = |
297 |
DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(RectCloudControl), new PropertyMetadata(MouseMode.None, PointValueChanged)); |
298 |
|
299 |
public static readonly DependencyProperty IsSelectedProperty = |
300 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(RectangleControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
301 |
|
302 |
public static readonly DependencyProperty ControlTypeProperty = |
303 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(RectangleControl), new FrameworkPropertyMetadata(ControlType.Rectangle)); |
304 |
|
305 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
306 |
"StrokeColor", typeof(SolidColorBrush), typeof(RectangleControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
307 |
|
308 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
309 |
"LineSize", typeof(double), typeof(RectangleControl), new PropertyMetadata((Double)3)); |
310 |
|
311 |
//강인구 추가 |
312 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
313 |
"DashSize", typeof(DoubleCollection), typeof(RectangleControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged)); |
314 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
315 |
"PathData", typeof(Geometry), typeof(RectangleControl), null); |
316 |
|
317 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
318 |
"OverViewPathData", typeof(Geometry), typeof(RectangleControl), null); |
319 |
|
320 |
//강인구 추가 |
321 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
322 |
"Paint", typeof(PaintSet), typeof(RectangleControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
323 |
|
324 |
|
325 |
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
326 |
"FillColor", typeof(SolidColorBrush), typeof(RectangleControl), new PropertyMetadata(new SolidColorBrush(Colors.White))); |
327 |
|
328 |
public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
329 |
"CanvasX", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
330 |
|
331 |
public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
332 |
"CanvasY", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
333 |
|
334 |
public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
335 |
"TopRightPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
336 |
|
337 |
public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
338 |
"LeftBottomPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
339 |
|
340 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
341 |
"StartPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
342 |
|
343 |
public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register( |
344 |
"SetPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
345 |
|
346 |
public static readonly DependencyProperty OriginPointProperty = DependencyProperty.Register( |
347 |
"OriginPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
348 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register( |
349 |
"Angle", typeof(double), typeof(RectangleControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
350 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
351 |
"PointSet", typeof(List<Point>), typeof(RectangleControl), new PropertyMetadata(new List<Point>())); |
352 |
|
353 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
354 |
"EndPoint", typeof(Point), typeof(RectangleControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
355 |
|
356 |
#endregion Dependency Property |
357 |
|
358 |
#region Dependency PropertyChanged |
359 |
public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
360 |
{ |
361 |
var instance = (RectangleControl)sender; |
362 |
|
363 |
if (e.OldValue != e.NewValue && instance != null) |
364 |
{ |
365 |
instance.SetValue(e.Property, e.NewValue); |
366 |
Canvas.SetLeft(instance, instance.SetPoint.X); |
367 |
Canvas.SetTop(instance, instance.SetPoint.Y); |
368 |
//Canvas.SetLeft(instance, instance.CanvasX); |
369 |
//Canvas.SetTop(instance, instance.CanvasY); |
370 |
} |
371 |
} |
372 |
|
373 |
|
374 |
public static void OnUpdateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
375 |
{ |
376 |
var instance = (RectangleControl)sender; |
377 |
|
378 |
if (e.OldValue != e.NewValue && instance != null) |
379 |
{ |
380 |
instance.SetValue(e.Property, e.NewValue); |
381 |
instance.SetRectPath(); |
382 |
} |
383 |
} |
384 |
|
385 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
386 |
{ |
387 |
var instance = (RectangleControl)sender; |
388 |
if (e.OldValue != e.NewValue && instance.Base_RectPath != null) |
389 |
{ |
390 |
instance.SetValue(e.Property, e.NewValue); |
391 |
instance.SetRectPath(); |
392 |
} |
393 |
} |
394 |
|
395 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
396 |
{ |
397 |
//var instance = (RectangleControl)sender; |
398 |
|
399 |
//if (e.OldValue != e.NewValue && instance.Base_RectPath != null) |
400 |
//{ |
401 |
// instance.SetValue(e.Property, e.NewValue); |
402 |
|
403 |
// if (instance.IsSelected) |
404 |
// { |
405 |
// instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Blue); |
406 |
// } |
407 |
// else |
408 |
// { |
409 |
// instance.Base_RectPath.Stroke = new SolidColorBrush(Colors.Red); |
410 |
// } |
411 |
//} |
412 |
} |
413 |
|
414 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
415 |
{ |
416 |
var instance = (RectangleControl)sender; |
417 |
|
418 |
if (e.OldValue != e.NewValue && instance.Base_RectPath != null) |
419 |
{ |
420 |
instance.SetValue(e.Property, e.NewValue); |
421 |
instance.SetRectPath(); |
422 |
} |
423 |
} |
424 |
#endregion Dependency PropertyChanged |
425 |
|
426 |
public void SetRectPath() |
427 |
{ |
428 |
this.ApplyTemplate(); |
429 |
|
430 |
if (Base_RectPath != null) |
431 |
{ |
432 |
//강인구 추가 |
433 |
Base_RectPath.StrokeDashArray.Clear(); |
434 |
if (DashSize != null) |
435 |
{ |
436 |
foreach (var item in this.DashSize) |
437 |
{ |
438 |
Base_RectPath.StrokeDashArray.Add(item); |
439 |
} |
440 |
Base_RectPath.StrokeDashCap = PenLineCap.Square; |
441 |
} |
442 |
|
443 |
PathFigure pathFigure = new PathFigure |
444 |
{ |
445 |
IsClosed = true |
446 |
}; |
447 |
|
448 |
if (ControlType == ControlType.Rectangle) |
449 |
{ |
450 |
switch (this.Paint) |
451 |
{ |
452 |
case PaintSet.None: |
453 |
this.FillColor = null; |
454 |
pathFigure.IsFilled = false; |
455 |
break; |
456 |
case PaintSet.Fill: |
457 |
this.FillColor = this.StrokeColor; |
458 |
Base_RectPath.Fill = this.FillColor; |
459 |
pathFigure.IsFilled = true; |
460 |
break; |
461 |
case PaintSet.Hatch: |
462 |
Base_RectPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor); |
463 |
pathFigure.IsFilled = true; |
464 |
break; |
465 |
default: |
466 |
{ |
467 |
|
468 |
} |
469 |
break; |
470 |
} |
471 |
} |
472 |
|
473 |
pathFigure.StartPoint = this.StartPoint; |
474 |
|
475 |
List<Point> points = new List<Point>() { this.LeftBottomPoint, this.EndPoint, this.TopRightPoint, this.StartPoint }; |
476 |
PolyLineSegment polyline = new PolyLineSegment(points, true); |
477 |
pathFigure.Segments.Add(polyline); |
478 |
|
479 |
PathGeometry pathGeometry = new PathGeometry(); |
480 |
pathGeometry.Figures = new PathFigureCollection(); |
481 |
pathGeometry.Figures.Add(pathFigure); |
482 |
|
483 |
//Base_RectPath.StrokeThickness = 3; |
484 |
this.FillColor = null; |
485 |
this.PathData = pathGeometry; |
486 |
ApplyOverViewData(); |
487 |
//OverViewPathData = PathData; |
488 |
//AdornerControl adornerControl = new Adorner.AdornerControl(); |
489 |
////adornerControl |
490 |
|
491 |
//adornerControl.Content = pathGeometry; |
492 |
|
493 |
} |
494 |
} |
495 |
|
496 |
public void ApplyOverViewData() |
497 |
{ |
498 |
this.OverViewPathData = this.PathData; |
499 |
} |
500 |
|
501 |
#region Internal Method |
502 |
|
503 |
|
504 |
static RectangleControl() |
505 |
{ |
506 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(RectangleControl), new FrameworkPropertyMetadata(typeof(RectangleControl))); |
507 |
ResourceDictionary dictionary = new ResourceDictionary(); |
508 |
dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
509 |
Application.Current.Resources.MergedDictionaries.Add(dictionary); |
510 |
} |
511 |
|
512 |
|
513 |
public override void OnApplyTemplate() |
514 |
{ |
515 |
base.OnApplyTemplate(); |
516 |
|
517 |
Base_RectPath = GetTemplateChild(PART_RectPath) as Path; |
518 |
|
519 |
|
520 |
if (Base_RectPath == null) |
521 |
return; |
522 |
|
523 |
SetRectPath(); |
524 |
Base_RectPath.Focus(); |
525 |
} |
526 |
|
527 |
public void updateControl() |
528 |
{ |
529 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
530 |
this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
531 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
532 |
this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
533 |
} |
534 |
|
535 |
private void OnPropertyChanged(string name) |
536 |
{ |
537 |
if (PropertyChanged != null) |
538 |
{ |
539 |
PropertyChanged(this, new PropertyChangedEventArgs(name)); |
540 |
} |
541 |
} |
542 |
|
543 |
public void ChangePaint(PaintSet state) |
544 |
{ |
545 |
this.Paint = state; |
546 |
this.SetRectPath(); |
547 |
} |
548 |
|
549 |
public event PropertyChangedEventHandler PropertyChanged; |
550 |
|
551 |
/// <summary> |
552 |
/// Serialize this |
553 |
/// </summary> |
554 |
/// <param name="sUserId"></param> |
555 |
/// <returns></returns> |
556 |
public override string Serialize() |
557 |
{ |
558 |
using (S_RectControl STemp = new S_RectControl()) |
559 |
{ |
560 |
STemp.TransformPoint = "0|0"; |
561 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
562 |
STemp.PaintState = this.Paint; |
563 |
STemp.PointSet = this.PointSet; |
564 |
//STemp.StrokeColor = "#FF00FF00"; |
565 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
566 |
if (this.FillColor != null) |
567 |
{ |
568 |
STemp.FillColor = this.FillColor.Color.ToString(); |
569 |
} |
570 |
STemp.StartPoint = this.StartPoint; |
571 |
STemp.UserID = this.UserID; |
572 |
//STemp.Angle = this.a; |
573 |
STemp.EndPoint = this.EndPoint; |
574 |
STemp.LB = this.LeftBottomPoint; |
575 |
STemp.TR = this.TopRightPoint; |
576 |
STemp.DashSize = this.DashSize; |
577 |
STemp.Opac = this.Opacity; |
578 |
STemp.Name = this.GetType().Name.ToString(); |
579 |
///강인구 추가(2017.11.02) |
580 |
///Memo 추가 |
581 |
STemp.Memo = this.Memo; |
582 |
|
583 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
584 |
}; |
585 |
} |
586 |
|
587 |
public void Dispose() |
588 |
{ |
589 |
GC.Collect(); |
590 |
GC.SuppressFinalize(this); |
591 |
} |
592 |
#endregion Internal Method |
593 |
} |
594 |
} |