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