markus / MarkupToPDF / Controls / Etc / SignControl.cs @ b2d0f316
이력 | 보기 | 이력해설 | 다운로드 (23.2 KB)
1 |
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 |
using MarkupToPDF.Serialize.Core; |
17 |
using MarkupToPDF.Serialize.S_Control; |
18 |
using System.Windows.Media.Imaging; |
19 |
using System.Threading.Tasks; |
20 |
using static System.Windows.Forms.AxHost; |
21 |
|
22 |
//강인구 추가 |
23 |
namespace MarkupToPDF.Controls.Etc |
24 |
{ |
25 |
[TemplatePart(Name = "PART_Image", Type = typeof(Image))] |
26 |
public class SignControl : CommentUserInfo, IDisposable, INormal, INotifyPropertyChanged, IViewBox |
27 |
{ |
28 |
#region 초기선언 |
29 |
public string ProjectNO { get; set; } |
30 |
|
31 |
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 |
//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 |
} |
44 |
|
45 |
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 |
this.ZIndex = item.ZIndex; |
61 |
} |
62 |
} |
63 |
|
64 |
public override CommentUserInfo Clone() |
65 |
{ |
66 |
var clone = new SignControl(); |
67 |
clone.Copy(this); |
68 |
return clone; |
69 |
} |
70 |
|
71 |
public void Dispose() |
72 |
{ |
73 |
//GC.Collect(); |
74 |
////GC.SuppressFinalize(this); |
75 |
this.Base_Image = null; |
76 |
} |
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 |
|
153 |
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 |
public override double CommentAngle |
223 |
{ |
224 |
get { return (double)GetValue(AngleProperty); } |
225 |
set |
226 |
{ |
227 |
if (this.CommentAngle != value) |
228 |
{ |
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 |
public override bool IsSelected |
240 |
{ |
241 |
get |
242 |
{ |
243 |
return (bool)GetValue(IsSelectedProperty); |
244 |
} |
245 |
set |
246 |
{ |
247 |
SetValue(IsSelectedProperty, value); |
248 |
} |
249 |
} |
250 |
|
251 |
public override ControlType ControlType |
252 |
{ |
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 |
|
271 |
private void SetImage() |
272 |
{ |
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 |
double AngleData = this.CommentAngle * -1; |
284 |
|
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 |
|
309 |
// 상 하 좌 우 에 마진값 적용 |
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 |
|
315 |
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 |
|
327 |
public override void UpdateControl() |
328 |
{ |
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 |
|
335 |
/// <summary> |
336 |
/// 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 |
public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
342 |
{ |
343 |
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 |
|
362 |
var _sign = Application.Current.FindResource("UserSign"); |
363 |
|
364 |
if (this.StartPoint != this.EndPoint && this.SignImage == null && _sign != null) |
365 |
{ |
366 |
byte[] imageBytes = System.Convert.FromBase64String(_sign.ToString()); |
367 |
|
368 |
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 |
|
384 |
this.PointSet = new List<Point> |
385 |
{ |
386 |
this.StartPoint, |
387 |
this.LeftBottomPoint, |
388 |
this.EndPoint, |
389 |
this.TopRightPoint, |
390 |
}; |
391 |
} |
392 |
|
393 |
/// <summary> |
394 |
/// 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 |
public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
402 |
{ |
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 |
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 |
|
415 |
if (bAxisLocked) |
416 |
{ |
417 |
var PrevV = path.PointSet[PreviousP] - path.PointSet[OppositeP]; |
418 |
double PrevLength = PrevV.Length; |
419 |
PrevV.Normalize(); |
420 |
|
421 |
var NextV = path.PointSet[NextP] - path.PointSet[OppositeP]; |
422 |
double NextVLength = NextV.Length; |
423 |
NextV.Normalize(); |
424 |
|
425 |
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 |
} |
449 |
else |
450 |
{ |
451 |
var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[PreviousP]); |
452 |
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 |
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 |
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 |
path.PointSet[NextP] = new Point(path.PointSet[OppositeP].X + NextV.X * l, path.PointSet[OppositeP].Y + NextV.Y * l); |
460 |
|
461 |
path.PointSet[idx] = selected; |
462 |
} |
463 |
|
464 |
this.UpdateControl(); |
465 |
} |
466 |
|
467 |
/// <summary> |
468 |
/// 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 |
/// Serialize this |
487 |
/// </summary> |
488 |
/// <param name="sUserId"></param> |
489 |
/// <returns></returns> |
490 |
public override string Serialize() |
491 |
{ |
492 |
using (S_SignControl ctrl = new S_SignControl()) |
493 |
{ |
494 |
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 |
|
505 |
///강인구 추가(2017.11.02) |
506 |
///Memo 추가 |
507 |
ctrl.Memo = this.Memo; |
508 |
|
509 |
ctrl.ZIndex = this.ZIndex; |
510 |
|
511 |
return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize())); |
512 |
} |
513 |
} |
514 |
|
515 |
/// <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 |
CommentAngle = s.Angle, |
528 |
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 |
UserNumber = s.UserNumber, |
537 |
Memo = s.Memo, |
538 |
ZIndex = s.ZIndex |
539 |
}; |
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 |
|
550 |
using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) |
551 |
{ |
552 |
stream.WriteAsync(imageBytes, 0, imageBytes.Length); |
553 |
|
554 |
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 |
instance.SignImage = returnImage; |
566 |
} |
567 |
} |
568 |
} |
569 |
|
570 |
return instance; |
571 |
} |
572 |
|
573 |
public double LineSize |
574 |
{ |
575 |
get; |
576 |
set; |
577 |
} |
578 |
public Geometry PathData |
579 |
{ |
580 |
get; |
581 |
set; |
582 |
} |
583 |
} |
584 |
} |