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