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