markus / MarkupToPDF / Controls / Cad / CoordinateControl.cs @ 90e7968d
이력 | 보기 | 이력해설 | 다운로드 (18.3 KB)
1 | 684ef11c | ljiyeon | 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 CoordinateControl : 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(CoordinateControl), new PropertyMetadata(null)); |
||
294 | |||
295 | public static readonly DependencyProperty mousemodeProperty = |
||
296 | DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(CoordinateControl), new PropertyMetadata(MouseMode.None, PointValueChanged)); |
||
297 | |||
298 | public static readonly DependencyProperty IsSelectedProperty = |
||
299 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(CoordinateControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
300 | |||
301 | public static readonly DependencyProperty ControlTypeProperty = |
||
302 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(CoordinateControl), new FrameworkPropertyMetadata(ControlType.Coordinate)); |
||
303 | |||
304 | public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
||
305 | "StrokeColor", typeof(SolidColorBrush), typeof(CoordinateControl), new PropertyMetadata(new SolidColorBrush(Colors.Black))); |
||
306 | |||
307 | public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
||
308 | "LineSize", typeof(double), typeof(CoordinateControl), new PropertyMetadata((Double)10)); |
||
309 | |||
310 | //강인구 추가 |
||
311 | public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
||
312 | "DashSize", typeof(DoubleCollection), typeof(CoordinateControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged)); |
||
313 | public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
||
314 | "PathData", typeof(Geometry), typeof(CoordinateControl), null); |
||
315 | |||
316 | public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
||
317 | "OverViewPathData", typeof(Geometry), typeof(CoordinateControl), null); |
||
318 | |||
319 | //강인구 추가 |
||
320 | public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
||
321 | "Paint", typeof(PaintSet), typeof(CoordinateControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
||
322 | |||
323 | |||
324 | public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
||
325 | "FillColor", typeof(SolidColorBrush), typeof(CoordinateControl), new PropertyMetadata(new SolidColorBrush(Colors.White))); |
||
326 | |||
327 | public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
||
328 | "CanvasX", typeof(double), typeof(CoordinateControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
||
329 | |||
330 | public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
||
331 | "CanvasY", typeof(double), typeof(CoordinateControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
||
332 | |||
333 | public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
||
334 | "TopRightPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
335 | |||
336 | public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
||
337 | "LeftBottomPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
338 | |||
339 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
340 | "StartPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
341 | |||
342 | public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register( |
||
343 | "SetPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
344 | |||
345 | public static readonly DependencyProperty OriginPointProperty = DependencyProperty.Register( |
||
346 | "OriginPoint", typeof(Point), typeof(CoordinateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
347 | public static readonly DependencyProperty AngleProperty = DependencyProperty.Register( |
||
348 | "Angle", typeof(double), typeof(CoordinateControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
||
349 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
350 | "PointSet", typeof(List<Point>), typeof(CoordinateControl), new PropertyMetadata(new List<Point>())); |
||
351 | |||
352 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
353 | "EndPoint", typeof(Point), typeof(CoordinateControl), 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 = (CoordinateControl)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 = (CoordinateControl)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 = (CoordinateControl)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 = (CoordinateControl)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 = (CoordinateControl)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 | 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.Coordinate) |
||
447 | { |
||
448 | switch (this.Paint) |
||
449 | { |
||
450 | case PaintSet.None: |
||
451 | this.FillColor = null; |
||
452 | pathFigure.IsFilled = false; |
||
453 | break; |
||
454 | default: |
||
455 | { |
||
456 | |||
457 | } |
||
458 | break; |
||
459 | } |
||
460 | } |
||
461 | |||
462 | pathFigure.StartPoint = this.StartPoint; |
||
463 | |||
464 | LineSegment lineSegment1 = new LineSegment(); |
||
465 | lineSegment1.Point = this.LeftBottomPoint; |
||
466 | pathFigure.Segments.Add(lineSegment1); |
||
467 | |||
468 | LineSegment lineSegment2 = new LineSegment(); |
||
469 | lineSegment2.Point = this.EndPoint; |
||
470 | pathFigure.Segments.Add(lineSegment2); |
||
471 | |||
472 | LineSegment lineSegment3 = new LineSegment(); |
||
473 | lineSegment3.Point = this.TopRightPoint; |
||
474 | pathFigure.Segments.Add(lineSegment3); |
||
475 | |||
476 | LineSegment lineSegment0 = new LineSegment(); |
||
477 | lineSegment0.Point = this.StartPoint; |
||
478 | pathFigure.Segments.Add(lineSegment0); |
||
479 | |||
480 | PathGeometry pathGeometry = new PathGeometry(); |
||
481 | pathGeometry.Figures = new PathFigureCollection(); |
||
482 | pathGeometry.Figures.Add(pathFigure); |
||
483 | |||
484 | |||
485 | //Base_RectPath.StrokeThickness = 3; |
||
486 | this.FillColor = null; |
||
487 | this.PathData = pathGeometry; |
||
488 | ApplyOverViewData(); |
||
489 | //OverViewPathData = PathData; |
||
490 | //AdornerControl adornerControl = new Adorner.AdornerControl(); |
||
491 | ////adornerControl |
||
492 | |||
493 | //adornerControl.Content = pathGeometry; |
||
494 | |||
495 | } |
||
496 | } |
||
497 | |||
498 | public void ApplyOverViewData() |
||
499 | { |
||
500 | this.OverViewPathData = this.PathData; |
||
501 | } |
||
502 | |||
503 | #region Internal Method |
||
504 | |||
505 | |||
506 | static CoordinateControl() |
||
507 | { |
||
508 | DefaultStyleKeyProperty.OverrideMetadata(typeof(CoordinateControl), new FrameworkPropertyMetadata(typeof(CoordinateControl))); |
||
509 | ResourceDictionary dictionary = new ResourceDictionary(); |
||
510 | dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
511 | Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
512 | } |
||
513 | |||
514 | |||
515 | public override void OnApplyTemplate() |
||
516 | { |
||
517 | base.OnApplyTemplate(); |
||
518 | |||
519 | Base_RectPath = GetTemplateChild(PART_RectPath) as Path; |
||
520 | |||
521 | |||
522 | if (Base_RectPath == null) |
||
523 | return; |
||
524 | |||
525 | SetRectPath(); |
||
526 | Base_RectPath.Focus(); |
||
527 | } |
||
528 | |||
529 | public void updateControl() |
||
530 | { |
||
531 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
532 | this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
||
533 | this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
||
534 | this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
||
535 | } |
||
536 | |||
537 | private void OnPropertyChanged(string name) |
||
538 | { |
||
539 | if (PropertyChanged != null) |
||
540 | { |
||
541 | PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||
542 | } |
||
543 | } |
||
544 | |||
545 | public void ChangePaint(PaintSet state) |
||
546 | { |
||
547 | this.Paint = state; |
||
548 | this.SetRectPath(); |
||
549 | } |
||
550 | |||
551 | public event PropertyChangedEventHandler PropertyChanged; |
||
552 | |||
553 | public void Dispose() |
||
554 | { |
||
555 | GC.Collect(); |
||
556 | GC.SuppressFinalize(this); |
||
557 | } |
||
558 | #endregion Internal Method |
||
559 | } |
||
560 | } |