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