프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Etc / SignControl.cs @ 8118ba81

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