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