markus / MarkupToPDF / Controls / Etc / SymControl.cs @ 8118ba81
이력 | 보기 | 이력해설 | 다운로드 (23.2 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 | 7b34fb3a | swate0609 | using MarkupToPDF.Controls.Shape; |
19 | using System.Windows.Markup; |
||
20 | 787a4489 | KangIngu | |
21 | namespace MarkupToPDF.Controls.Etc |
||
22 | { |
||
23 | [TemplatePart(Name = "PART_SymPath", Type = typeof(Path))] |
||
24 | [TemplatePart(Name = "PART_ViewBox", Type = typeof(Viewbox))] |
||
25 | |||
26 | public class SymControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IViewBox, IMarkupCommonData |
||
27 | { |
||
28 | #region 초기선언 |
||
29 | public enum SymStyleSet { None, Fill }; |
||
30 | private const string PART_ViewBox = "PART_ViewBox"; |
||
31 | private const string PART_SymPath = "PART_SymPath"; |
||
32 | public Viewbox Base_ViewBox = null; |
||
33 | public Path Base_SymPath = null; |
||
34 | #endregion |
||
35 | |||
36 | static SymControl() |
||
37 | { |
||
38 | DefaultStyleKeyProperty.OverrideMetadata(typeof(SymControl), new FrameworkPropertyMetadata(typeof(SymControl))); |
||
39 | //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
||
40 | a6f7f9b6 | djkim | //ResourceDictionary dictionary = new ResourceDictionary(); |
41 | //dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
42 | //Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
43 | //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
||
44 | 787a4489 | KangIngu | } |
45 | 7b34fb3a | swate0609 | public override void Copy(CommentUserInfo lhs) |
46 | { |
||
47 | e1b36bc0 | humkyung | if(lhs is SymControl item) |
48 | 7b34fb3a | swate0609 | { |
49 | e1b36bc0 | humkyung | this.LineSize = item.LineSize; |
50 | this.PointSet = item.PointSet.ConvertAll(x => new System.Windows.Point(x.X, x.Y)); |
||
51 | this.Paint = item.Paint; |
||
52 | this.StartPoint = new System.Windows.Point(item.StartPoint.X, item.StartPoint.Y); |
||
53 | this.EndPoint = new System.Windows.Point(item.EndPoint.X, item.EndPoint.Y); |
||
54 | this.LeftBottomPoint = new System.Windows.Point(item.LeftBottomPoint.X, item.LeftBottomPoint.Y); |
||
55 | this.TopRightPoint = new System.Windows.Point(item.TopRightPoint.X, item.TopRightPoint.Y); |
||
56 | this.StrokeColor = item.StrokeColor; |
||
57 | this.CommentAngle = item.CommentAngle; |
||
58 | this.UserID = item.UserID; |
||
59 | |||
60 | this.PathData = item.PathData.Clone(); |
||
61 | this.Opacity = item.Opacity; |
||
62 | this.Memo = item.Memo; |
||
63 | this.ZIndex = item.ZIndex; |
||
64 | GroupID = item.GroupID; |
||
65 | 7b34fb3a | swate0609 | } |
66 | } |
||
67 | |||
68 | public override CommentUserInfo Clone() |
||
69 | { |
||
70 | var clone = new SymControl(); |
||
71 | clone.Copy(this); |
||
72 | return clone; |
||
73 | } |
||
74 | 787a4489 | KangIngu | |
75 | public void Dispose() |
||
76 | { |
||
77 | a6f7f9b6 | djkim | //GC.Collect(); |
78 | 24c5e56c | taeseongkim | ////GC.SuppressFinalize(this); |
79 | a6f7f9b6 | djkim | this.Base_SymPath = null; |
80 | this.Base_ViewBox = null; |
||
81 | 787a4489 | KangIngu | } |
82 | public event PropertyChangedEventHandler PropertyChanged; |
||
83 | protected void RaisePropertyChanged(string propName) |
||
84 | { |
||
85 | if (PropertyChanged != null) |
||
86 | PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
||
87 | } |
||
88 | #region Dependency Properties |
||
89 | public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
||
90 | "UserID", typeof(string), typeof(SymControl), new PropertyMetadata(null)); |
||
91 | public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
||
92 | "LineSize", typeof(double), typeof(SymControl), new PropertyMetadata((Double)1)); |
||
93 | public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
||
94 | "StrokeColor", typeof(SolidColorBrush), typeof(SymControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
||
95 | public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
||
96 | "PathData", typeof(Geometry), typeof(SymControl), null); |
||
97 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
98 | "EndPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
99 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
100 | "StartPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
101 | public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
||
102 | "TopRightPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), TRPointValueChanged)); |
||
103 | public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
||
104 | "LeftBottomPoint", typeof(Point), typeof(SymControl), new PropertyMetadata(new Point(0, 0), LBPointValueChanged)); |
||
105 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
106 | "PointSet", typeof(List<Point>), typeof(SymControl), new PropertyMetadata(new List<Point>())); |
||
107 | public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(SymControl), |
||
108 | new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
||
109 | public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(SymControl), |
||
110 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
111 | public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(SymControl), |
||
112 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
113 | public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
||
114 | "Paint", typeof(PaintSet), typeof(SymControl), new PropertyMetadata(PaintSet.None)); |
||
115 | |||
116 | public static readonly DependencyProperty IsSelectedProperty = |
||
117 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(SymControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
118 | |||
119 | public static readonly DependencyProperty ControlTypeProperty = |
||
120 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(SymControl), new FrameworkPropertyMetadata(ControlType.Symbol)); |
||
121 | #endregion |
||
122 | #region PropertyChanged Method |
||
123 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
124 | { |
||
125 | var instance = (SymControl)sender; |
||
126 | if (e.OldValue != e.NewValue && instance.Base_SymPath != null) |
||
127 | { |
||
128 | instance.SetValue(e.Property, e.NewValue); |
||
129 | instance.SetSymPath(); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | public static void TRPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
134 | { |
||
135 | var instance = (SymControl)sender; |
||
136 | if (e.OldValue != e.NewValue && instance.Base_SymPath != null) |
||
137 | { |
||
138 | instance.SetValue(e.Property, e.NewValue); |
||
139 | instance.SetSymPath(); |
||
140 | } |
||
141 | } |
||
142 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
143 | { |
||
144 | |||
145 | } |
||
146 | public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
147 | { |
||
148 | var instance = (SymControl)sender; |
||
149 | if (e.OldValue != e.NewValue && instance.Base_SymPath != null) |
||
150 | { |
||
151 | instance.SetValue(e.Property, e.NewValue); |
||
152 | instance.SetSymPath(); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | public static void LBPointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
157 | { |
||
158 | var instance = (SymControl)sender; |
||
159 | if (e.OldValue != e.NewValue && instance.Base_SymPath != null) |
||
160 | { |
||
161 | instance.SetValue(e.Property, e.NewValue); |
||
162 | //instance.EndPoint = new Point(instance.EndPoint.X, ((Point)e.NewValue).Y); |
||
163 | //instance.StartPoint = new Point(((Point)e.NewValue).X, instance.StartPoint.Y); |
||
164 | ////instance.PointSet[0] = instance.StartPoint; |
||
165 | ////instance.PointSet[2] = instance.EndPoint; |
||
166 | instance.SetSymPath(); |
||
167 | } |
||
168 | } |
||
169 | |||
170 | public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
171 | { |
||
172 | var instance = (SymControl)sender; |
||
173 | if (e.OldValue != e.NewValue && instance.Base_SymPath != null) |
||
174 | { |
||
175 | instance.SetValue(e.Property, e.NewValue); |
||
176 | instance.SetSymPath(); |
||
177 | } |
||
178 | } |
||
179 | #endregion |
||
180 | #region Properties |
||
181 | public string UserID |
||
182 | { |
||
183 | get { return (string)GetValue(UserIDProperty); } |
||
184 | set |
||
185 | { |
||
186 | if (this.UserID != value) |
||
187 | { |
||
188 | SetValue(UserIDProperty, value); |
||
189 | RaisePropertyChanged("UserID"); |
||
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 PaintSet Paint |
||
205 | { |
||
206 | get { return (PaintSet)GetValue(PaintProperty); } |
||
207 | set |
||
208 | { |
||
209 | if (this.Paint != value) |
||
210 | { |
||
211 | SetValue(PaintProperty, value); |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | public List<Point> PointSet |
||
216 | { |
||
217 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
218 | set { SetValue(PointSetProperty, value); } |
||
219 | } |
||
220 | 554aae3b | humkyung | |
221 | fa48eb85 | taeseongkim | public override double CommentAngle |
222 | 787a4489 | KangIngu | { |
223 | get { return (double)GetValue(AngleProperty); } |
||
224 | set |
||
225 | { |
||
226 | fa48eb85 | taeseongkim | if (this.CommentAngle != value) |
227 | 787a4489 | KangIngu | { |
228 | SetValue(AngleProperty, value); |
||
229 | } |
||
230 | } |
||
231 | } |
||
232 | public SolidColorBrush StrokeColor |
||
233 | { |
||
234 | get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
||
235 | set |
||
236 | { |
||
237 | if (this.StrokeColor != value) |
||
238 | { |
||
239 | SetValue(StrokeColorProperty, value); |
||
240 | } |
||
241 | } |
||
242 | } |
||
243 | public Geometry PathData |
||
244 | { |
||
245 | get { return (Geometry)GetValue(PathDataProperty); } |
||
246 | set |
||
247 | { |
||
248 | SetValue(PathDataProperty, value); |
||
249 | RaisePropertyChanged("PathData"); |
||
250 | } |
||
251 | } |
||
252 | public Point TopRightPoint |
||
253 | { |
||
254 | get { return (Point)GetValue(TopRightPointProperty); } |
||
255 | set |
||
256 | { |
||
257 | SetValue(TopRightPointProperty, value); |
||
258 | RaisePropertyChanged("TopRightPoint"); |
||
259 | } |
||
260 | } |
||
261 | public Point LeftBottomPoint |
||
262 | { |
||
263 | get { return (Point)GetValue(LeftBottomPointProperty); } |
||
264 | set |
||
265 | { |
||
266 | SetValue(LeftBottomPointProperty, value); |
||
267 | RaisePropertyChanged("LeftBottomPoint"); |
||
268 | } |
||
269 | } |
||
270 | public Point EndPoint |
||
271 | { |
||
272 | get { return (Point)GetValue(EndPointProperty); } |
||
273 | set |
||
274 | { |
||
275 | SetValue(EndPointProperty, value); |
||
276 | RaisePropertyChanged("EndPoint"); |
||
277 | } |
||
278 | } |
||
279 | public Point StartPoint |
||
280 | { |
||
281 | get { return (Point)GetValue(StartPointProperty); } |
||
282 | set |
||
283 | { |
||
284 | SetValue(StartPointProperty, value); |
||
285 | RaisePropertyChanged("StartPoint"); |
||
286 | } |
||
287 | } |
||
288 | public double CenterX |
||
289 | { |
||
290 | get { return (double)GetValue(CenterXProperty); } |
||
291 | set { SetValue(CenterXProperty, value); } |
||
292 | } |
||
293 | public double CenterY |
||
294 | { |
||
295 | get { return (double)GetValue(CenterYProperty); } |
||
296 | set { SetValue(CenterYProperty, value); } |
||
297 | } |
||
298 | public double AngleValue |
||
299 | { |
||
300 | get { return (double)GetValue(AngleProperty); } |
||
301 | set { SetValue(AngleProperty, value); } |
||
302 | } |
||
303 | 959b3ef2 | humkyung | public override bool IsSelected |
304 | 787a4489 | KangIngu | { |
305 | get |
||
306 | { |
||
307 | return (bool)GetValue(IsSelectedProperty); |
||
308 | } |
||
309 | set |
||
310 | { |
||
311 | SetValue(IsSelectedProperty, value); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | 5529d2a2 | humkyung | public override ControlType ControlType |
316 | 787a4489 | KangIngu | { |
317 | set |
||
318 | { |
||
319 | SetValue(ControlTypeProperty, value); |
||
320 | } |
||
321 | get |
||
322 | { |
||
323 | return (ControlType)GetValue(ControlTypeProperty); |
||
324 | } |
||
325 | } |
||
326 | |||
327 | #endregion |
||
328 | public override void OnApplyTemplate() |
||
329 | { |
||
330 | base.OnApplyTemplate(); |
||
331 | Base_ViewBox = GetTemplateChild(PART_ViewBox) as Viewbox; |
||
332 | Base_SymPath = GetTemplateChild(PART_SymPath) as Path; |
||
333 | SetSymPath(); |
||
334 | } |
||
335 | 661b7416 | humkyung | |
336 | private void SetSymPath() |
||
337 | 787a4489 | KangIngu | { |
338 | this.ApplyTemplate(); |
||
339 | switch (this.Paint) |
||
340 | { |
||
341 | case PaintSet.None: |
||
342 | Base_SymPath.Fill = null; |
||
343 | break; |
||
344 | case PaintSet.Fill: |
||
345 | Base_SymPath.Fill = this.StrokeColor; |
||
346 | break; |
||
347 | default: |
||
348 | break; |
||
349 | } |
||
350 | |||
351 | Point mid = MathSet.FindCentroid(new List<Point>() |
||
352 | { |
||
353 | this.StartPoint, |
||
354 | this.LeftBottomPoint, |
||
355 | this.EndPoint, |
||
356 | this.TopRightPoint, |
||
357 | }); |
||
358 | |||
359 | fa48eb85 | taeseongkim | double AngleData = this.CommentAngle * -1; |
360 | 787a4489 | KangIngu | |
361 | PathFigure pathFigure = new PathFigure(); |
||
362 | pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
363 | |||
364 | LineSegment lineSegment0 = new LineSegment(); |
||
365 | lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
366 | pathFigure.Segments.Add(lineSegment0); |
||
367 | |||
368 | LineSegment lineSegment1 = new LineSegment(); |
||
369 | lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData); |
||
370 | pathFigure.Segments.Add(lineSegment1); |
||
371 | |||
372 | LineSegment lineSegment2 = new LineSegment(); |
||
373 | lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData); |
||
374 | pathFigure.Segments.Add(lineSegment2); |
||
375 | |||
376 | LineSegment lineSegment3 = new LineSegment(); |
||
377 | lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData); |
||
378 | pathFigure.Segments.Add(lineSegment3); |
||
379 | |||
380 | PathGeometry pathGeometry = new PathGeometry(); |
||
381 | pathGeometry.Figures = new PathFigureCollection(); |
||
382 | pathFigure.IsClosed = true; |
||
383 | pathGeometry.Figures.Add(pathFigure); |
||
384 | this.Base_ViewBox.Width = pathGeometry.Bounds.Width; |
||
385 | 5a223b60 | humkyung | this.Base_ViewBox.Height = pathGeometry.Bounds.Height; |
386 | 787a4489 | KangIngu | this.Tag = pathGeometry; |
387 | |||
388 | Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_ViewBox.Width / 2); |
||
389 | Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_ViewBox.Height / 2); |
||
390 | |||
391 | } |
||
392 | 0d00f9c8 | humkyung | |
393 | public override void UpdateControl() |
||
394 | 787a4489 | KangIngu | { |
395 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
396 | this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
||
397 | this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
||
398 | this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
||
399 | this.SetSymPath(); |
||
400 | } |
||
401 | |||
402 | |||
403 | public void ChangePaint(PaintSet state) |
||
404 | { |
||
405 | this.Paint = state; |
||
406 | this.SetSymPath(); |
||
407 | } |
||
408 | 036650a0 | humkyung | |
409 | /// <summary> |
||
410 | a6272c57 | humkyung | /// call when mouse is moving while drawing control |
411 | /// </summary> |
||
412 | /// <author>humkyung</author> |
||
413 | /// <param name="pt"></param> |
||
414 | /// <param name="bAxisLocked"></param> |
||
415 | 233ef333 | taeseongkim | public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
416 | a6272c57 | humkyung | { |
417 | 49a6d7c3 | humkyung | if (bAxisLocked) |
418 | { |
||
419 | double _dx = pt.X - this.StartPoint.X; |
||
420 | double _dy = pt.Y - this.StartPoint.Y; |
||
421 | double dist = Math.Max(Math.Abs(_dx), Math.Abs(_dy)); |
||
422 | var dir = new Vector(_dx, _dy); |
||
423 | dir.Normalize(); |
||
424 | |||
425 | this.LeftBottomPoint = new Point(this.StartPoint.X, this.StartPoint.Y + (dir.Y > 0 ? 1 : -1) * dist); |
||
426 | this.TopRightPoint = new Point(this.StartPoint.X + (dir.X > 0 ? 1 : -1) * dist, this.StartPoint.Y); |
||
427 | this.EndPoint = new Point(this.TopRightPoint.X, this.LeftBottomPoint.Y); |
||
428 | } |
||
429 | else |
||
430 | { |
||
431 | this.EndPoint = pt; |
||
432 | this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y); |
||
433 | this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y); |
||
434 | } |
||
435 | a6272c57 | humkyung | |
436 | this.StrokeColor = new SolidColorBrush(Colors.Red); |
||
437 | |||
438 | if (this.StartPoint != this.EndPoint) |
||
439 | { |
||
440 | if (this.PathData == null) |
||
441 | { |
||
442 | using (StringToPathConverter Convert = new StringToPathConverter()) |
||
443 | { |
||
444 | this.PathData = Convert.Convert("M-5,5L0,0L20,30L40,-20 "); |
||
445 | } |
||
446 | } |
||
447 | } |
||
448 | |||
449 | this.PointSet = new List<Point> |
||
450 | { |
||
451 | this.StartPoint, |
||
452 | this.LeftBottomPoint, |
||
453 | this.EndPoint, |
||
454 | this.TopRightPoint, |
||
455 | }; |
||
456 | } |
||
457 | |||
458 | /// <summary> |
||
459 | d2114d3b | humkyung | /// move control point has same location of given pt along given delta |
460 | /// </summary> |
||
461 | /// <author>humkyung</author> |
||
462 | /// <date>2019.06.20</date> |
||
463 | /// <param name="pt"></param> |
||
464 | /// <param name="dx"></param> |
||
465 | /// <param name="dy"></param> |
||
466 | 233ef333 | taeseongkim | public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
467 | d2114d3b | humkyung | { |
468 | IPath path = (this as IPath); |
||
469 | |||
470 | Point selected = MathSet.getNearPoint(path.PointSet, pt); |
||
471 | selected.X += dx; |
||
472 | selected.Y += dy; |
||
473 | int i = 0; |
||
474 | for (i = 0; i < (this as IPath).PointSet.Count; i++) |
||
475 | { |
||
476 | if (pt.Equals((this as IPath).PointSet[i])) |
||
477 | { |
||
478 | path.PointSet[i] = selected; |
||
479 | break; |
||
480 | } |
||
481 | } |
||
482 | |||
483 | var ReverseP = (i + path.PointSet.Count / 2) % path.PointSet.Count; |
||
484 | var PreviousP = (i + (path.PointSet.Count - 1)) % path.PointSet.Count; |
||
485 | var NextP = (i + 1) % path.PointSet.Count; |
||
486 | |||
487 | var distance = MathSet.DistanceTo(path.PointSet[ReverseP], path.PointSet[i]); |
||
488 | |||
489 | var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[ReverseP], path.PointSet[PreviousP]); |
||
490 | var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[i].X - path.PointSet[ReverseP].X, |
||
491 | path.PointSet[i].Y - path.PointSet[ReverseP].Y); |
||
492 | path.PointSet[PreviousP] = new Point(path.PointSet[ReverseP].X + PreviousV.X * l, path.PointSet[ReverseP].Y + PreviousV.Y * l); |
||
493 | |||
494 | var NextV = MathSet.GetNormVectorBetween(path.PointSet[ReverseP], path.PointSet[NextP]); |
||
495 | l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[i].X - path.PointSet[ReverseP].X, path.PointSet |
||
496 | [i].Y - path.PointSet[ReverseP].Y); |
||
497 | path.PointSet[NextP] = new Point(path.PointSet[ReverseP].X + NextV.X * l, path.PointSet[ReverseP].Y + NextV.Y * l); |
||
498 | |||
499 | 0d00f9c8 | humkyung | this.UpdateControl(); |
500 | d2114d3b | humkyung | } |
501 | |||
502 | /// <summary> |
||
503 | 91efe37a | humkyung | /// return SymControl's area |
504 | /// </summary> |
||
505 | /// <author>humkyung</author> |
||
506 | /// <date>2019.06.13</date> |
||
507 | public override Rect ItemRect |
||
508 | { |
||
509 | get |
||
510 | { |
||
511 | double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X); |
||
512 | double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y); |
||
513 | double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X); |
||
514 | double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y); |
||
515 | |||
516 | return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
||
517 | } |
||
518 | } |
||
519 | |||
520 | /// <summary> |
||
521 | 036650a0 | humkyung | /// Serialize this |
522 | /// </summary> |
||
523 | /// <param name="sUserId"></param> |
||
524 | /// <returns></returns> |
||
525 | public override string Serialize() |
||
526 | { |
||
527 | b2d0f316 | humkyung | using (S_SymControl ctrl = new S_SymControl()) |
528 | 036650a0 | humkyung | { |
529 | b2d0f316 | humkyung | ctrl.TransformPoint = "0|0"; |
530 | ctrl.PointSet = this.PointSet; |
||
531 | ctrl.UserID = this.UserID; |
||
532 | ctrl.SizeSet = String.Format("{0}", this.LineSize.ToString()); |
||
533 | ctrl.PaintState = this.Paint; |
||
534 | ctrl.PathInfo = this.PathData.ToString(); |
||
535 | ctrl.StrokeColor = this.StrokeColor.Color.ToString(); |
||
536 | ctrl.StartPoint = this.StartPoint; |
||
537 | ctrl.Angle = this.CommentAngle; |
||
538 | ctrl.EndPoint = this.EndPoint; |
||
539 | ctrl.LB = this.LeftBottomPoint; |
||
540 | ctrl.TR = this.TopRightPoint; |
||
541 | ctrl.Opac = this.Opacity; |
||
542 | ctrl.Name = this.GetType().Name.ToString(); |
||
543 | ctrl.ZIndex = this.ZIndex; |
||
544 | e1b36bc0 | humkyung | ctrl.GroupID = this.GroupID; |
545 | b2d0f316 | humkyung | |
546 | return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize())); |
||
547 | 036650a0 | humkyung | } |
548 | } |
||
549 | 661b7416 | humkyung | |
550 | /// <summary> |
||
551 | /// create a symcontrol from given string |
||
552 | /// </summary> |
||
553 | /// <param name="str"></param> |
||
554 | /// <returns></returns> |
||
555 | public static SymControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
||
556 | { |
||
557 | SymControl instance = null; |
||
558 | using (S_SymControl s = JsonSerializerHelper.JsonDeserialize<S_SymControl>(str)) |
||
559 | { |
||
560 | string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
561 | Common.StringToPathConverter sm = new Common.StringToPathConverter(); |
||
562 | instance = new SymControl |
||
563 | { |
||
564 | LineSize = Convert.ToDouble(data2.First()), |
||
565 | PointSet = s.PointSet, |
||
566 | Paint = s.PaintState, |
||
567 | StartPoint = s.StartPoint, |
||
568 | StrokeColor = brush, |
||
569 | EndPoint = s.EndPoint, |
||
570 | fa48eb85 | taeseongkim | CommentAngle = s.Angle, |
571 | 661b7416 | humkyung | UserID = s.UserID, |
572 | LeftBottomPoint = s.LB, |
||
573 | TopRightPoint = s.TR, |
||
574 | PathData = sm.Convert(s.PathInfo.ToString()), |
||
575 | Opacity = s.Opac, |
||
576 | b2d0f316 | humkyung | Memo = s.Memo, |
577 | e1b36bc0 | humkyung | ZIndex = s.ZIndex, |
578 | GroupID = s.GroupID |
||
579 | 661b7416 | humkyung | }; |
580 | } |
||
581 | |||
582 | return instance; |
||
583 | } |
||
584 | 787a4489 | KangIngu | } |
585 | } |