markus / MarkupToPDF / Controls / Etc / DateControl.cs @ fd19a116
이력 | 보기 | 이력해설 | 다운로드 (24.8 KB)
1 | 787a4489 | KangIngu | using System; |
---|---|---|---|
2 | using System.Net; |
||
3 | using System.Windows; |
||
4 | using System.Windows.Controls; |
||
5 | using System.Windows.Documents; |
||
6 | using System.Windows.Ink; |
||
7 | using System.Windows.Input; |
||
8 | using System.Windows.Media; |
||
9 | using System.Windows.Media.Animation; |
||
10 | using System.Windows.Shapes; |
||
11 | using System.ComponentModel; |
||
12 | using System.Collections.Generic; |
||
13 | using MarkupToPDF.Controls.Common; |
||
14 | using MarkupToPDF.Common; |
||
15 | 036650a0 | humkyung | using MarkupToPDF.Serialize.Core; |
16 | using MarkupToPDF.Serialize.S_Control; |
||
17 | 661b7416 | humkyung | using System.Linq; |
18 | 873011c4 | humkyung | using System.Windows.Markup; |
19 | 787a4489 | KangIngu | |
20 | namespace MarkupToPDF.Controls.Etc |
||
21 | { |
||
22 | 873011c4 | humkyung | public class DateControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IViewBox |
23 | 787a4489 | KangIngu | { |
24 | private const string PART_ViewBox = "PART_ViewBox"; |
||
25 | private const string PART_TextBox = "PART_TextBox"; |
||
26 | e1b36bc0 | humkyung | public Viewbox Base_ViewBox { get; set; } = null; |
27 | public TextBlock Base_TextBox { get; set; } = null; |
||
28 | 787a4489 | KangIngu | |
29 | static DateControl() |
||
30 | { |
||
31 | DefaultStyleKeyProperty.OverrideMetadata(typeof(DateControl), new FrameworkPropertyMetadata(typeof(DateControl))); |
||
32 | //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
||
33 | a6f7f9b6 | djkim | //ResourceDictionary dictionary = new ResourceDictionary(); |
34 | //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
35 | //Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
36 | //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
||
37 | 787a4489 | KangIngu | } |
38 | |||
39 | public DateControl() |
||
40 | { |
||
41 | a6f7f9b6 | djkim | //this.DefaultStyleKey = typeof(DateControl); |
42 | 787a4489 | KangIngu | } |
43 | |||
44 | 7b34fb3a | swate0609 | public override void Copy(CommentUserInfo lhs) |
45 | { |
||
46 | b79d6e7f | humkyung | if(lhs is DateControl item) |
47 | 7b34fb3a | swate0609 | { |
48 | b79d6e7f | humkyung | CommentAngle = item.CommentAngle; |
49 | StartPoint = new Point(item.StartPoint.X, item.StartPoint.Y); |
||
50 | EndPoint = new Point(item.EndPoint.X, item.EndPoint.Y); |
||
51 | LeftBottomPoint = new Point(item.LeftBottomPoint.X, item.LeftBottomPoint.Y); |
||
52 | TopRightPoint = new Point(item.TopRightPoint.X, item.TopRightPoint.Y); |
||
53 | Opacity = item.Opacity; |
||
54 | FontColor = item.FontColor; |
||
55 | LineSize = item.LineSize; |
||
56 | Text = item.Text; |
||
57 | PointSet = item.PointSet.ConvertAll(x => new Point(x.X, x.Y)); |
||
58 | UserID = item.UserID; |
||
59 | Memo = item.Memo; |
||
60 | b2d0f316 | humkyung | ZIndex = item.ZIndex; |
61 | e1b36bc0 | humkyung | GroupID = item.GroupID; |
62 | 7b34fb3a | swate0609 | } |
63 | } |
||
64 | |||
65 | 873011c4 | humkyung | /// <summary> |
66 | /// 복사본을 생성한다. |
||
67 | /// </summary> |
||
68 | /// <returns></returns> |
||
69 | public override CommentUserInfo Clone() |
||
70 | { |
||
71 | 7b34fb3a | swate0609 | |
72 | var clone = new DateControl(); |
||
73 | clone.Copy(this); |
||
74 | return clone; |
||
75 | 873011c4 | humkyung | } |
76 | 787a4489 | KangIngu | |
77 | #region Dependency Properties |
||
78 | |||
79 | |||
80 | public static readonly DependencyProperty IsSelectedProperty = |
||
81 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(DateControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
82 | |||
83 | public static readonly DependencyProperty ControlTypeProperty = |
||
84 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(DateControl), new FrameworkPropertyMetadata(ControlType.Date)); |
||
85 | |||
86 | public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
||
87 | "OverViewPathData", typeof(Geometry), typeof(DateControl), null); |
||
88 | |||
89 | public static readonly DependencyProperty OverViewStartPointProperty = DependencyProperty.Register( |
||
90 | "OverViewStartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null)); |
||
91 | |||
92 | public static readonly DependencyProperty OverViewEndPointProperty = DependencyProperty.Register( |
||
93 | "OverViewEndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(null)); |
||
94 | |||
95 | |||
96 | public static readonly DependencyProperty TextProperty = DependencyProperty.Register( |
||
97 | "Text", typeof(string), typeof(DateControl), new PropertyMetadata(null)); |
||
98 | public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
||
99 | "UserID", typeof(string), typeof(DateControl), new PropertyMetadata(null)); |
||
100 | public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register( |
||
101 | "FontColor", typeof(SolidColorBrush), typeof(DateControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
||
102 | //[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] |
||
103 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
104 | "StartPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
105 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
106 | "EndPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
||
107 | public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
||
108 | "LineSize", typeof(double), typeof(DateControl), new PropertyMetadata((double)3)); |
||
109 | public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
||
110 | "TopRightPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), TRPointValueChanged)); |
||
111 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
112 | "PointSet", typeof(List<Point>), typeof(DateControl), new PropertyMetadata(new List<Point>())); |
||
113 | public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
||
114 | "LeftBottomPoint", typeof(Point), typeof(DateControl), new PropertyMetadata(new Point(0, 0), LBPointValueChanged)); |
||
115 | public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
||
116 | "PathData", typeof(Geometry), typeof(DateControl), null); |
||
117 | public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DateControl), |
||
118 | new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
||
119 | |||
120 | public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(DateControl), |
||
121 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
122 | |||
123 | public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(DateControl), |
||
124 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
125 | |||
126 | #endregion |
||
127 | #region PropertyChanged Method |
||
128 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
129 | { |
||
130 | //var instance = (DateControl)sender; |
||
131 | |||
132 | //if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
||
133 | //{ |
||
134 | |||
135 | // instance.SetValue(e.Property, e.NewValue); |
||
136 | |||
137 | // if (instance.IsSelected) |
||
138 | // { |
||
139 | // //instance.Base_ViewBox.Style. = new SolidColorBrush(Colors.Blue); |
||
140 | // } |
||
141 | // else |
||
142 | // { |
||
143 | // //instance.Base_ViewBox.Stroke = new SolidColorBrush(Colors.Red); |
||
144 | // } |
||
145 | //} |
||
146 | } |
||
147 | |||
148 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
149 | { |
||
150 | var instance = (DateControl)sender; |
||
151 | if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
||
152 | { |
||
153 | instance.SetValue(e.Property, e.NewValue); |
||
154 | instance.SetDate(); |
||
155 | } |
||
156 | } |
||
157 | public static void LBPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
158 | { |
||
159 | var instance = (DateControl)sender; |
||
160 | if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
||
161 | { |
||
162 | instance.SetValue(e.Property, e.NewValue); |
||
163 | //instance.EndPoint = new Point(instance.EndPoint.X, ((Point)e.NewValue).Y); |
||
164 | //instance.StartPoint = new Point(((Point)e.NewValue).X, instance.StartPoint.Y); |
||
165 | ////instance.PointSet[0] = instance.StartPoint; |
||
166 | ////instance.PointSet[2] = instance.EndPoint; |
||
167 | instance.SetDate(); |
||
168 | } |
||
169 | } |
||
170 | public static void TRPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
171 | { |
||
172 | var instance = (DateControl)sender; |
||
173 | if (e.OldValue != e.NewValue && instance.Base_TextBox != null) |
||
174 | { |
||
175 | instance.SetValue(e.Property, e.NewValue); |
||
176 | instance.SetDate(); |
||
177 | } |
||
178 | } |
||
179 | public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
180 | { |
||
181 | var instance = (DateControl)sender; |
||
182 | if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
||
183 | { |
||
184 | instance.SetValue(e.Property, e.NewValue); |
||
185 | instance.SetDate(); |
||
186 | } |
||
187 | } |
||
188 | |||
189 | public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
190 | { |
||
191 | var instance = (DateControl)sender; |
||
192 | if (e.OldValue != e.NewValue && instance.Base_ViewBox != null) |
||
193 | { |
||
194 | instance.SetValue(e.Property, e.NewValue); |
||
195 | instance.SetDate(); |
||
196 | } |
||
197 | } |
||
198 | #endregion |
||
199 | #region Properties |
||
200 | public double LineSize |
||
201 | { |
||
202 | get { return (double)GetValue(LineSizeProperty); } |
||
203 | set |
||
204 | { |
||
205 | if (this.LineSize != value) |
||
206 | { |
||
207 | SetValue(LineSizeProperty, value); |
||
208 | OnPropertyChanged("LineSize"); |
||
209 | } |
||
210 | } |
||
211 | } |
||
212 | public string UserID |
||
213 | { |
||
214 | get { return (string)GetValue(UserIDProperty); } |
||
215 | set |
||
216 | { |
||
217 | if (this.UserID != value) |
||
218 | { |
||
219 | SetValue(UserIDProperty, value); |
||
220 | OnPropertyChanged("UserID"); |
||
221 | } |
||
222 | } |
||
223 | } |
||
224 | 554aae3b | humkyung | |
225 | fa48eb85 | taeseongkim | public override double CommentAngle |
226 | 787a4489 | KangIngu | { |
227 | get { return (double)GetValue(AngleProperty); } |
||
228 | set |
||
229 | { |
||
230 | fa48eb85 | taeseongkim | if (this.CommentAngle != value) |
231 | 787a4489 | KangIngu | { |
232 | SetValue(AngleProperty, value); |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | |||
237 | 959b3ef2 | humkyung | public override bool IsSelected |
238 | 787a4489 | KangIngu | { |
239 | get |
||
240 | { |
||
241 | return (bool)GetValue(IsSelectedProperty); |
||
242 | } |
||
243 | set |
||
244 | { |
||
245 | SetValue(IsSelectedProperty, value); |
||
246 | OnPropertyChanged("IsSelected"); |
||
247 | } |
||
248 | } |
||
249 | |||
250 | 5529d2a2 | humkyung | public override ControlType ControlType |
251 | 787a4489 | KangIngu | { |
252 | set |
||
253 | { |
||
254 | SetValue(ControlTypeProperty, value); |
||
255 | OnPropertyChanged("ControlType"); |
||
256 | } |
||
257 | get |
||
258 | { |
||
259 | return (ControlType)GetValue(ControlTypeProperty); |
||
260 | } |
||
261 | } |
||
262 | |||
263 | public Geometry OverViewPathData |
||
264 | { |
||
265 | get { return (Geometry)GetValue(OverViewPathDataProperty); } |
||
266 | set |
||
267 | { |
||
268 | SetValue(OverViewPathDataProperty, value); |
||
269 | OnPropertyChanged("OverViewPathData"); |
||
270 | } |
||
271 | } |
||
272 | |||
273 | public List<Point> PointSet |
||
274 | { |
||
275 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
276 | set { SetValue(PointSetProperty, value); } |
||
277 | } |
||
278 | public Point TopRightPoint |
||
279 | { |
||
280 | get { return (Point)GetValue(TopRightPointProperty); } |
||
281 | set |
||
282 | { |
||
283 | SetValue(TopRightPointProperty, value); |
||
284 | OnPropertyChanged("TopRightPoint"); |
||
285 | } |
||
286 | } |
||
287 | public Point LeftBottomPoint |
||
288 | { |
||
289 | get { return (Point)GetValue(LeftBottomPointProperty); } |
||
290 | set |
||
291 | { |
||
292 | SetValue(LeftBottomPointProperty, value); |
||
293 | OnPropertyChanged("LeftBottomPoint"); |
||
294 | } |
||
295 | } |
||
296 | public double CenterX |
||
297 | { |
||
298 | get { return (double)GetValue(CenterXProperty); } |
||
299 | set { SetValue(CenterXProperty, value); } |
||
300 | } |
||
301 | public double CenterY |
||
302 | { |
||
303 | get { return (double)GetValue(CenterYProperty); } |
||
304 | set { SetValue(CenterYProperty, value); } |
||
305 | } |
||
306 | public string Text |
||
307 | { |
||
308 | get { return (string)GetValue(TextProperty); } |
||
309 | set |
||
310 | { |
||
311 | if (this.Text != value) |
||
312 | { |
||
313 | SetValue(TextProperty, value); |
||
314 | OnPropertyChanged("Text"); |
||
315 | } |
||
316 | } |
||
317 | } |
||
318 | public Geometry PathData |
||
319 | { |
||
320 | get { return (Geometry)GetValue(PathDataProperty); } |
||
321 | set |
||
322 | { |
||
323 | SetValue(PathDataProperty, value); |
||
324 | OnPropertyChanged("PathData"); |
||
325 | } |
||
326 | } |
||
327 | public SolidColorBrush FontColor |
||
328 | { |
||
329 | get { return (SolidColorBrush)GetValue(FontColorProperty); } |
||
330 | set |
||
331 | { |
||
332 | if (this.FontColor != value) |
||
333 | { |
||
334 | SetValue(FontColorProperty, value); |
||
335 | OnPropertyChanged("FontColor"); |
||
336 | } |
||
337 | |||
338 | } |
||
339 | } |
||
340 | public Point EndPoint |
||
341 | { |
||
342 | get { return (Point)GetValue(EndPointProperty); } |
||
343 | set |
||
344 | { |
||
345 | if (this.EndPoint != value) |
||
346 | { |
||
347 | SetValue(EndPointProperty, value); |
||
348 | OnPropertyChanged("EndPoint"); |
||
349 | } |
||
350 | } |
||
351 | } |
||
352 | public Point StartPoint |
||
353 | { |
||
354 | get { return (Point)GetValue(StartPointProperty); } |
||
355 | set |
||
356 | { |
||
357 | if (this.StartPoint != value) |
||
358 | { |
||
359 | SetValue(StartPointProperty, value); |
||
360 | OnPropertyChanged("StartPoint"); |
||
361 | } |
||
362 | } |
||
363 | } |
||
364 | |||
365 | public Point OverViewStartPoint |
||
366 | { |
||
367 | get { return (Point)GetValue(OverViewStartPointProperty); } |
||
368 | set { SetValue(OverViewStartPointProperty, value); } |
||
369 | } |
||
370 | |||
371 | public Point OverViewEndPoint |
||
372 | { |
||
373 | get { return (Point)GetValue(OverViewEndPointProperty); } |
||
374 | set { SetValue(OverViewEndPointProperty, value); } |
||
375 | } |
||
376 | |||
377 | //public int MyProperty { get; set; } |
||
378 | |||
379 | |||
380 | #endregion |
||
381 | #region Data |
||
382 | e1b36bc0 | humkyung | GeometryGroup instanceGroup { get; } = new GeometryGroup(); |
383 | FormattedText text { get; set; } |
||
384 | 787a4489 | KangIngu | #endregion |
385 | public override void OnApplyTemplate() |
||
386 | { |
||
387 | base.OnApplyTemplate(); |
||
388 | Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox; |
||
389 | Base_TextBox = GetTemplateChild(PART_TextBox) as TextBlock; |
||
390 | Base_TextBox.Visibility = System.Windows.Visibility.Hidden; |
||
391 | SetDate(); |
||
392 | } |
||
393 | 661b7416 | humkyung | |
394 | private void SetDate() |
||
395 | 787a4489 | KangIngu | { |
396 | if (Text == null) |
||
397 | { |
||
398 | Text = DateTime.Now.ToString("yyyy-MM-dd"); |
||
399 | } |
||
400 | this.ApplyTemplate(); |
||
401 | instanceGroup.Children.Clear(); |
||
402 | Base_TextBox.Visibility = System.Windows.Visibility.Visible; |
||
403 | Point mid = MathSet.FindCentroid(new List<Point>() |
||
404 | { |
||
405 | this.StartPoint, |
||
406 | this.LeftBottomPoint, |
||
407 | this.EndPoint, |
||
408 | this.TopRightPoint, |
||
409 | }); |
||
410 | |||
411 | fa48eb85 | taeseongkim | double AngleData = this.CommentAngle * -1; |
412 | 787a4489 | KangIngu | |
413 | PathFigure pathFigure = new PathFigure(); |
||
414 | pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
415 | |||
416 | LineSegment lineSegment0 = new LineSegment(); |
||
417 | lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
418 | pathFigure.Segments.Add(lineSegment0); |
||
419 | |||
420 | LineSegment lineSegment1 = new LineSegment(); |
||
421 | lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData); |
||
422 | pathFigure.Segments.Add(lineSegment1); |
||
423 | |||
424 | LineSegment lineSegment2 = new LineSegment(); |
||
425 | lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData); |
||
426 | pathFigure.Segments.Add(lineSegment2); |
||
427 | |||
428 | LineSegment lineSegment3 = new LineSegment(); |
||
429 | lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData); |
||
430 | pathFigure.Segments.Add(lineSegment3); |
||
431 | |||
432 | PathGeometry pathGeometry = new PathGeometry(); |
||
433 | pathGeometry.Figures = new PathFigureCollection(); |
||
434 | pathFigure.IsClosed = true; |
||
435 | pathGeometry.Figures.Add(pathFigure); |
||
436 | |||
437 | //CenterX = MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2; |
||
438 | //CenterY = MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2; |
||
439 | |||
440 | instanceGroup.Children.Add(pathGeometry); |
||
441 | |||
442 | e1b36bc0 | humkyung | double emSize = MathSet.DistanceTo(this.StartPoint, this.LeftBottomPoint); |
443 | if (emSize == 0) emSize = 16; |
||
444 | 787a4489 | KangIngu | text = new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture, |
445 | e1b36bc0 | humkyung | FlowDirection.LeftToRight, new Typeface("Tahoma"), emSize, Brushes.Black); |
446 | 787a4489 | KangIngu | |
447 | e1b36bc0 | humkyung | this.Base_ViewBox.Width = text.Width; |
448 | this.Base_ViewBox.Height = text.Height; |
||
449 | this.Tag = pathGeometry; |
||
450 | 787a4489 | KangIngu | |
451 | e1b36bc0 | humkyung | Canvas.SetLeft(this, mid.X - this.Base_ViewBox.Width * 0.5); |
452 | Canvas.SetTop(this, mid.Y - this.Base_ViewBox.Height * 0.5); |
||
453 | Canvas.SetRight(this, mid.X + this.Base_ViewBox.Width * 0.5); |
||
454 | Canvas.SetBottom(this, mid.Y + this.Base_ViewBox.Height * 0.5); |
||
455 | 787a4489 | KangIngu | |
456 | e1b36bc0 | humkyung | instanceGroup.Children.Add(text.BuildGeometry(new Point(0, 0))); |
457 | 787a4489 | KangIngu | |
458 | e1b36bc0 | humkyung | PathData = instanceGroup; |
459 | 787a4489 | KangIngu | } |
460 | |||
461 | public event PropertyChangedEventHandler PropertyChanged; |
||
462 | protected void OnPropertyChanged(string propName) |
||
463 | { |
||
464 | if (PropertyChanged != null) |
||
465 | PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
||
466 | } |
||
467 | |||
468 | public void Dispose() |
||
469 | { |
||
470 | a6f7f9b6 | djkim | //GC.Collect(); |
471 | 24c5e56c | taeseongkim | ////GC.SuppressFinalize(this); |
472 | a6f7f9b6 | djkim | this.Base_TextBox = null; |
473 | this.Base_ViewBox = null; |
||
474 | 787a4489 | KangIngu | } |
475 | |||
476 | f513c215 | humkyung | public override void ApplyOverViewData() |
477 | 787a4489 | KangIngu | { |
478 | //this.OverViewPathData = this.PathData; |
||
479 | this.OverViewStartPoint = this.StartPoint; |
||
480 | this.OverViewEndPoint = this.EndPoint; |
||
481 | } |
||
482 | |||
483 | 0d00f9c8 | humkyung | public override void UpdateControl() |
484 | 787a4489 | KangIngu | { |
485 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
486 | this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
||
487 | this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
||
488 | this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
||
489 | this.SetDate(); |
||
490 | } |
||
491 | 036650a0 | humkyung | |
492 | /// <summary> |
||
493 | a6272c57 | humkyung | /// call when mouse is moving while drawing control |
494 | /// </summary> |
||
495 | /// <author>humkyung</author> |
||
496 | /// <param name="pt"></param> |
||
497 | /// <param name="bAxisLocked"></param> |
||
498 | 233ef333 | taeseongkim | public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
499 | a6272c57 | humkyung | { |
500 | this.EndPoint = pt; |
||
501 | this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y); |
||
502 | this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y); |
||
503 | |||
504 | this.PointSet = new List<Point> |
||
505 | { |
||
506 | this.StartPoint, |
||
507 | this.LeftBottomPoint, |
||
508 | this.EndPoint, |
||
509 | this.TopRightPoint, |
||
510 | }; |
||
511 | } |
||
512 | |||
513 | /// <summary> |
||
514 | d2114d3b | humkyung | /// move control point has same location of given pt along given delta |
515 | /// </summary> |
||
516 | /// <author>humkyung</author> |
||
517 | /// <date>2019.06.20</date> |
||
518 | /// <param name="pt"></param> |
||
519 | /// <param name="dx"></param> |
||
520 | /// <param name="dy"></param> |
||
521 | 233ef333 | taeseongkim | public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
522 | d2114d3b | humkyung | { |
523 | IPath path = (this as IPath); |
||
524 | |||
525 | Point selected = MathSet.getNearPoint(path.PointSet, pt); |
||
526 | selected.X += dx; |
||
527 | selected.Y += dy; |
||
528 | int i = 0; |
||
529 | for (i = 0; i < (this as IPath).PointSet.Count; i++) |
||
530 | { |
||
531 | if (pt.Equals((this as IPath).PointSet[i])) |
||
532 | { |
||
533 | path.PointSet[i] = selected; |
||
534 | break; |
||
535 | } |
||
536 | } |
||
537 | |||
538 | var ReverseP = (i + path.PointSet.Count / 2) % path.PointSet.Count; |
||
539 | var PreviousP = (i + (path.PointSet.Count - 1)) % path.PointSet.Count; |
||
540 | var NextP = (i + 1) % path.PointSet.Count; |
||
541 | |||
542 | var distance = MathSet.DistanceTo(path.PointSet[ReverseP], path.PointSet[i]); |
||
543 | |||
544 | var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[ReverseP], path.PointSet[PreviousP]); |
||
545 | var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[i].X - path.PointSet[ReverseP].X, |
||
546 | path.PointSet[i].Y - path.PointSet[ReverseP].Y); |
||
547 | path.PointSet[PreviousP] = new Point(path.PointSet[ReverseP].X + PreviousV.X * l, path.PointSet[ReverseP].Y + PreviousV.Y * l); |
||
548 | |||
549 | var NextV = MathSet.GetNormVectorBetween(path.PointSet[ReverseP], path.PointSet[NextP]); |
||
550 | l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[i].X - path.PointSet[ReverseP].X, path.PointSet |
||
551 | [i].Y - path.PointSet[ReverseP].Y); |
||
552 | path.PointSet[NextP] = new Point(path.PointSet[ReverseP].X + NextV.X * l, path.PointSet[ReverseP].Y + NextV.Y * l); |
||
553 | |||
554 | 0d00f9c8 | humkyung | this.UpdateControl(); |
555 | d2114d3b | humkyung | } |
556 | |||
557 | /// <summary> |
||
558 | 91efe37a | humkyung | /// return DateControl's area |
559 | /// </summary> |
||
560 | /// <author>humkyung</author> |
||
561 | /// <date>2019.06.13</date> |
||
562 | public override Rect ItemRect |
||
563 | { |
||
564 | get |
||
565 | { |
||
566 | double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X); |
||
567 | double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y); |
||
568 | double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X); |
||
569 | double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y); |
||
570 | |||
571 | return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
||
572 | } |
||
573 | } |
||
574 | |||
575 | /// <summary> |
||
576 | 036650a0 | humkyung | /// Serialize this |
577 | /// </summary> |
||
578 | /// <param name="sUserId"></param> |
||
579 | /// <returns></returns> |
||
580 | public override string Serialize() |
||
581 | { |
||
582 | b2d0f316 | humkyung | using (S_DateControl ctrl = new S_DateControl()) |
583 | 036650a0 | humkyung | { |
584 | b2d0f316 | humkyung | ctrl.Angle = this.CommentAngle; |
585 | e1b36bc0 | humkyung | ctrl.StartPoint = this.StartPoint; |
586 | b2d0f316 | humkyung | ctrl.EndPoint = this.EndPoint; |
587 | e1b36bc0 | humkyung | ctrl.PointSet = this.PointSet; |
588 | |||
589 | b2d0f316 | humkyung | ctrl.UserID = this.UserID; |
590 | ctrl.LB = this.LeftBottomPoint; |
||
591 | ctrl.Name = this.GetType().Name; |
||
592 | e1b36bc0 | humkyung | |
593 | b2d0f316 | humkyung | ctrl.Opac = this.Opacity; |
594 | ctrl.TR = this.TopRightPoint; |
||
595 | ctrl.TransformPoint = "0|0"; |
||
596 | ctrl.FontColor = this.FontColor.Color.ToString(); |
||
597 | //ctrl.FontColor = "#FFFFFF00"; |
||
598 | ctrl.SizeSet = String.Format("{0}", this.LineSize); |
||
599 | ctrl.Text = this.Text; |
||
600 | 036650a0 | humkyung | ///강인구 추가(2017.11.02) |
601 | ///Memo 추가 |
||
602 | b2d0f316 | humkyung | ctrl.Memo = this.Memo; |
603 | fd19a116 | humkyung | ctrl.Index = this.Index; |
604 | b2d0f316 | humkyung | ctrl.ZIndex = this.ZIndex; |
605 | e1b36bc0 | humkyung | ctrl.GroupID = this.GroupID; |
606 | b2d0f316 | humkyung | |
607 | return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize())); |
||
608 | 036650a0 | humkyung | } |
609 | } |
||
610 | 661b7416 | humkyung | |
611 | /// <summary> |
||
612 | /// create a datecontrol from given string |
||
613 | /// </summary> |
||
614 | /// <param name="str"></param> |
||
615 | /// <returns></returns> |
||
616 | public static DateControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
||
617 | { |
||
618 | using (S_DateControl s = JsonSerializerHelper.JsonDeserialize<S_DateControl>(str)) |
||
619 | { |
||
620 | string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
621 | return new DateControl |
||
622 | { |
||
623 | fa48eb85 | taeseongkim | CommentAngle = s.Angle, |
624 | 661b7416 | humkyung | StartPoint = s.StartPoint, |
625 | EndPoint = s.EndPoint, |
||
626 | LeftBottomPoint = s.LB, |
||
627 | TopRightPoint = s.TR, |
||
628 | Opacity = s.Opac, |
||
629 | FontColor = brush, |
||
630 | LineSize = Convert.ToDouble(data2.First()), |
||
631 | Text = s.Text, |
||
632 | PointSet = s.PointSet, |
||
633 | UserID = s.UserID, |
||
634 | b2d0f316 | humkyung | Memo = s.Memo, |
635 | fd19a116 | humkyung | Index = s.Index, |
636 | e1b36bc0 | humkyung | ZIndex = s.ZIndex, |
637 | GroupID = s.GroupID |
||
638 | 661b7416 | humkyung | }; |
639 | } |
||
640 | } |
||
641 | 787a4489 | KangIngu | } |
642 | } |