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