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