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