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