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