markus / MarkupToPDF / Controls / Line / ArrowArcControl.cs @ a4e5d148
이력 | 보기 | 이력해설 | 다운로드 (17.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.Line |
19 |
{ |
20 |
|
21 |
public class ArrowArcControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl |
22 |
{ |
23 |
#region 초기선언 |
24 |
public event PropertyChangedEventHandler PropertyChanged; |
25 |
private const string PART_ArcPath = "PART_ArcPath"; |
26 |
public Path Base_ArcPath = null; |
27 |
#endregion |
28 |
static ArrowArcControl() |
29 |
{ |
30 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowArcControl), new FrameworkPropertyMetadata(typeof(ArrowArcControl))); |
31 |
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
32 |
ResourceDictionary dictionary = new ResourceDictionary(); |
33 |
dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
34 |
Application.Current.Resources.MergedDictionaries.Add(dictionary); |
35 |
//System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
36 |
} |
37 |
|
38 |
public ArrowArcControl() |
39 |
{ |
40 |
this.DefaultStyleKey = typeof(ArrowArcControl); |
41 |
} |
42 |
|
43 |
public void Dispose() |
44 |
{ |
45 |
GC.Collect(); |
46 |
GC.SuppressFinalize(this); |
47 |
Control control = new Control(); |
48 |
} |
49 |
protected void OnPropertyChanged(string propName) |
50 |
{ |
51 |
if (PropertyChanged != null) |
52 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
53 |
} |
54 |
|
55 |
#region Dependency Properties |
56 |
|
57 |
|
58 |
|
59 |
public static readonly DependencyProperty IsSelectedProperty = |
60 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowArcControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
61 |
|
62 |
public static readonly DependencyProperty ControlTypeProperty = |
63 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowArcControl), new FrameworkPropertyMetadata(ControlType.ArcArrow)); |
64 |
|
65 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
66 |
"OverViewPathData", typeof(Geometry), typeof(ArrowArcControl), new PropertyMetadata(null)); |
67 |
|
68 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
69 |
"UserID", typeof(string), typeof(ArrowArcControl), new PropertyMetadata(null)); |
70 |
|
71 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
72 |
"LineSize", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((Double)3, PointValueChanged)); |
73 |
|
74 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
75 |
"DashSize", typeof(DoubleCollection), typeof(ArrowArcControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged)); |
76 |
|
77 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
78 |
"StrokeColor", typeof(SolidColorBrush), typeof(ArrowArcControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
79 |
|
80 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
81 |
"PathData", typeof(Geometry), typeof(ArrowArcControl), null); |
82 |
|
83 |
//public static readonly DependencyProperty ClockProperty = DependencyProperty.Register( |
84 |
// "Clock", typeof(SweepDirection), typeof(ArrowArcControl), new PropertyMetadata(SweepDirection.Clockwise)); |
85 |
public static readonly DependencyProperty ClockProperty = DependencyProperty.Register( |
86 |
"Clock", typeof(bool), typeof(ArrowArcControl), new PropertyMetadata(false)); |
87 |
|
88 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
89 |
"StartPoint", typeof(Point), typeof(ArrowArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
90 |
public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register( |
91 |
"MidPoint", typeof(Point), typeof(ArrowArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
92 |
|
93 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
94 |
"EndPoint", typeof(Point), typeof(ArrowArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
95 |
|
96 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
97 |
"PointSet", typeof(List<Point>), typeof(ArrowArcControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
98 |
|
99 |
public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register( |
100 |
"isTransOn", typeof(bool), typeof(ArrowArcControl), new PropertyMetadata(false)); |
101 |
|
102 |
public static readonly DependencyProperty AngleProperty = |
103 |
DependencyProperty.Register("AngleValue", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback |
104 |
(AngleValueChanged))); |
105 |
|
106 |
public static readonly DependencyProperty CenterXProperty = |
107 |
DependencyProperty.Register("CenterX", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
108 |
|
109 |
public static readonly DependencyProperty CenterYProperty = |
110 |
DependencyProperty.Register("CenterY", typeof(double), typeof(ArrowArcControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
111 |
#endregion |
112 |
#region PropertyChanged Method |
113 |
|
114 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
115 |
{ |
116 |
//var instance = (ArrowArcControl)sender; |
117 |
|
118 |
//if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
119 |
//{ |
120 |
|
121 |
// instance.SetValue(e.Property, e.NewValue); |
122 |
|
123 |
// if (instance.IsSelected) |
124 |
// { |
125 |
// instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Blue); |
126 |
// } |
127 |
// else |
128 |
// { |
129 |
// instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Red); |
130 |
// } |
131 |
//} |
132 |
} |
133 |
|
134 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
135 |
{ |
136 |
var instance = (ArrowArcControl)sender; |
137 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
138 |
{ |
139 |
instance.SetValue(e.Property, e.NewValue); |
140 |
instance.SetArcPath(); |
141 |
} |
142 |
} |
143 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
144 |
{ |
145 |
var instance = (ArrowArcControl)sender; |
146 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
147 |
{ |
148 |
instance.SetValue(e.Property, e.NewValue); |
149 |
instance.SetArcPath(); |
150 |
} |
151 |
} |
152 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
153 |
{ |
154 |
var instance = (ArrowArcControl)sender; |
155 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
156 |
{ |
157 |
instance.SetValue(e.Property, e.NewValue); |
158 |
instance.SetArcPath(); |
159 |
} |
160 |
} |
161 |
|
162 |
|
163 |
|
164 |
#endregion |
165 |
#region Properties |
166 |
public string UserID |
167 |
{ |
168 |
get { return (string)GetValue(UserIDProperty); } |
169 |
set |
170 |
{ |
171 |
if (this.UserID != value) |
172 |
{ |
173 |
SetValue(UserIDProperty, value); |
174 |
OnPropertyChanged("UserID"); |
175 |
} |
176 |
} |
177 |
} |
178 |
public Double LineSize |
179 |
{ |
180 |
get { return (Double)GetValue(LineSizeProperty); } |
181 |
set |
182 |
{ |
183 |
if (this.LineSize != value) |
184 |
{ |
185 |
SetValue(LineSizeProperty, value); |
186 |
} |
187 |
} |
188 |
} |
189 |
|
190 |
|
191 |
public bool Clock |
192 |
{ |
193 |
get { return (bool)GetValue(ClockProperty); } |
194 |
set |
195 |
{ |
196 |
if (this.Clock != value) |
197 |
{ |
198 |
SetValue(ClockProperty, value); |
199 |
OnPropertyChanged("Clock"); |
200 |
} |
201 |
} |
202 |
} |
203 |
|
204 |
//public SweepDirection Clock |
205 |
//{ |
206 |
// get { return (SweepDirection)GetValue(ClockProperty); } |
207 |
// set |
208 |
// { |
209 |
// if (this.Clock != value) |
210 |
// { |
211 |
// SetValue(ClockProperty, value); |
212 |
// OnPropertyChanged("Clock"); |
213 |
// } |
214 |
// } |
215 |
//} |
216 |
public DoubleCollection DashSize |
217 |
{ |
218 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
219 |
set |
220 |
{ |
221 |
if (this.DashSize != value) |
222 |
{ |
223 |
SetValue(DashSizeProperty, value); |
224 |
} |
225 |
} |
226 |
} |
227 |
public List<Point> PointSet |
228 |
{ |
229 |
get { return (List<Point>)GetValue(PointSetProperty); } |
230 |
set { SetValue(PointSetProperty, value); } |
231 |
} |
232 |
public double CenterX |
233 |
{ |
234 |
get { return (double)GetValue(CenterXProperty); } |
235 |
set { SetValue(CenterXProperty, value); } |
236 |
} |
237 |
public double CenterY |
238 |
{ |
239 |
get { return (double)GetValue(CenterYProperty); } |
240 |
set { SetValue(CenterYProperty, value); } |
241 |
} |
242 |
public SolidColorBrush StrokeColor |
243 |
{ |
244 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
245 |
set |
246 |
{ |
247 |
if (this.StrokeColor != value) |
248 |
{ |
249 |
SetValue(StrokeColorProperty, value); |
250 |
} |
251 |
} |
252 |
} |
253 |
|
254 |
public Geometry OverViewPathData |
255 |
{ |
256 |
get |
257 |
{ |
258 |
return (Geometry)GetValue(OverViewPathDataProperty); |
259 |
} |
260 |
set |
261 |
{ |
262 |
SetValue(OverViewPathDataProperty, value); |
263 |
OnPropertyChanged("OverViewPathData"); |
264 |
} |
265 |
} |
266 |
|
267 |
public Geometry PathData |
268 |
{ |
269 |
get { return (Geometry)GetValue(PathDataProperty); } |
270 |
set |
271 |
{ |
272 |
SetValue(PathDataProperty, value); |
273 |
OnPropertyChanged("PathData"); |
274 |
} |
275 |
} |
276 |
public bool IsSelected |
277 |
{ |
278 |
get |
279 |
{ |
280 |
return (bool)GetValue(IsSelectedProperty); |
281 |
} |
282 |
set |
283 |
{ |
284 |
SetValue(IsSelectedProperty, value); |
285 |
} |
286 |
} |
287 |
|
288 |
override public ControlType ControlType |
289 |
{ |
290 |
get |
291 |
{ |
292 |
return (ControlType)GetValue(ControlTypeProperty); |
293 |
} |
294 |
set |
295 |
{ |
296 |
SetValue(ControlTypeProperty, value); |
297 |
OnPropertyChanged("ControlType"); |
298 |
} |
299 |
} |
300 |
public double AngleValue |
301 |
{ |
302 |
get { return (double)GetValue(AngleProperty); } |
303 |
set { SetValue(AngleProperty, value); } |
304 |
} |
305 |
public double Angle |
306 |
{ |
307 |
get { return (double)GetValue(AngleProperty); } |
308 |
set |
309 |
{ |
310 |
if (this.Angle != value) |
311 |
{ |
312 |
SetValue(AngleProperty, value); |
313 |
} |
314 |
} |
315 |
} |
316 |
public Point EndPoint |
317 |
{ |
318 |
get { return (Point)GetValue(EndPointProperty); } |
319 |
set |
320 |
{ |
321 |
SetValue(EndPointProperty, value); |
322 |
OnPropertyChanged("EndPoint"); |
323 |
} |
324 |
} |
325 |
public Point StartPoint |
326 |
{ |
327 |
get { return (Point)GetValue(StartPointProperty); } |
328 |
set |
329 |
{ |
330 |
SetValue(StartPointProperty, value); |
331 |
OnPropertyChanged("StartPoint"); |
332 |
} |
333 |
} |
334 |
public Point MidPoint |
335 |
{ |
336 |
get { return (Point)GetValue(MidPointProperty); } |
337 |
set |
338 |
{ |
339 |
SetValue(MidPointProperty, value); |
340 |
OnPropertyChanged("MidPoint"); |
341 |
} |
342 |
} |
343 |
public bool isTransOn |
344 |
{ |
345 |
get { return (bool)GetValue(isTransOnProperty); } |
346 |
set |
347 |
{ |
348 |
SetValue(isTransOnProperty, value); |
349 |
OnPropertyChanged("isTransOn"); |
350 |
} |
351 |
} |
352 |
|
353 |
#endregion |
354 |
#region Object & Variable |
355 |
PathGeometry pathGeometry = new PathGeometry(); |
356 |
GeometryGroup instanceGroup = new GeometryGroup(); |
357 |
#endregion |
358 |
public override void OnApplyTemplate() |
359 |
{ |
360 |
base.OnApplyTemplate(); |
361 |
Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path; |
362 |
SetArcPath(); |
363 |
} |
364 |
public void updateControl() |
365 |
{ |
366 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
367 |
this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
368 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
369 |
} |
370 |
|
371 |
public void setClock() |
372 |
{ |
373 |
if (Clock) |
374 |
{ |
375 |
this.Clock = false; |
376 |
} |
377 |
else |
378 |
{ |
379 |
this.Clock = true; |
380 |
} |
381 |
} |
382 |
|
383 |
//public void setClock() |
384 |
//{ |
385 |
// if(this.Clock == SweepDirection.Clockwise) |
386 |
// { |
387 |
// this.Clock = SweepDirection.Counterclockwise; |
388 |
// } |
389 |
// else |
390 |
// { |
391 |
// this.Clock =SweepDirection.Clockwise; |
392 |
// } |
393 |
//} |
394 |
public void SetArcPath() |
395 |
{ |
396 |
this.ApplyTemplate(); |
397 |
|
398 |
|
399 |
//강인구 추가 |
400 |
Base_ArcPath.StrokeDashArray.Clear(); |
401 |
if (this.DashSize != null) |
402 |
{ |
403 |
foreach (var item in this.DashSize) |
404 |
{ |
405 |
Base_ArcPath.StrokeDashArray.Add(item); |
406 |
} |
407 |
Base_ArcPath.StrokeDashCap = PenLineCap.Square; |
408 |
instanceGroup.Children.Clear(); |
409 |
} |
410 |
PathFigure pathFigure = new PathFigure(); |
411 |
|
412 |
pathFigure.StartPoint = this.StartPoint; |
413 |
QuadraticBezierSegment qb = new QuadraticBezierSegment(); |
414 |
|
415 |
if (MidPoint != null) |
416 |
{ |
417 |
if (MidPoint == new Point(0,0)) |
418 |
{ |
419 |
double xSharp = 0; |
420 |
double ySharp = 0; |
421 |
|
422 |
//Point t_start = new Point(0, 0); |
423 |
//Point t_end = new Point(30, 10); |
424 |
|
425 |
var midP = MathSet.getMiddlePoint(StartPoint, EndPoint); |
426 |
Point normalV = MathSet.GetNormVectorBetween(StartPoint, EndPoint); |
427 |
var dis = MathSet.DistanceTo(StartPoint, EndPoint); |
428 |
|
429 |
if (!this.Clock) |
430 |
{ |
431 |
xSharp = -normalV.Y; |
432 |
ySharp = normalV.X; |
433 |
} |
434 |
else |
435 |
{ |
436 |
xSharp = normalV.Y; |
437 |
ySharp = -normalV.X; |
438 |
} |
439 |
|
440 |
var pointN = new Point(xSharp * dis, ySharp * dis); |
441 |
MidPoint = new Point(pointN.X + midP.X, pointN.Y + midP.Y); |
442 |
} |
443 |
qb.Point1 = this.MidPoint; |
444 |
} |
445 |
|
446 |
qb.Point2 = this.EndPoint; |
447 |
pathFigure.Segments.Add(qb); |
448 |
pathGeometry.Figures = new PathFigureCollection(); |
449 |
pathGeometry.Figures.Add(pathFigure); |
450 |
pathFigure.IsFilled = false; |
451 |
pathFigure.IsClosed = false; |
452 |
instanceGroup.Children.Add(pathGeometry); |
453 |
|
454 |
instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.StartPoint, this.LineSize)); |
455 |
instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.EndPoint, this.LineSize)); |
456 |
this.Base_ArcPath.Fill = this.StrokeColor; |
457 |
|
458 |
instanceGroup.FillRule = FillRule.Nonzero; |
459 |
this.PathData = instanceGroup; |
460 |
this.OverViewPathData = PathData; |
461 |
|
462 |
} |
463 |
|
464 |
public void ApplyOverViewData() |
465 |
{ |
466 |
this.OverViewPathData = this.PathData; |
467 |
} |
468 |
|
469 |
/// <summary> |
470 |
/// Serialize this |
471 |
/// </summary> |
472 |
/// <param name="sUserId"></param> |
473 |
/// <returns></returns> |
474 |
public override string Serialize() |
475 |
{ |
476 |
using (S_ArrowArcControl STemp = new S_ArrowArcControl()) |
477 |
{ |
478 |
STemp.TransformPoint = "0|0"; |
479 |
STemp.PointSet = this.PointSet; |
480 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
481 |
//STemp.StrokeColor = "#FF000FFF"; |
482 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
483 |
STemp.StartPoint = this.StartPoint; |
484 |
STemp.UserID = this.UserID; |
485 |
STemp.Opac = this.Opacity; |
486 |
STemp.MidPoint = this.MidPoint; |
487 |
STemp.EndPoint = this.EndPoint; |
488 |
STemp.IsTransOn = this.isTransOn; |
489 |
STemp.DashSize = this.DashSize; |
490 |
STemp.Clock = this.Clock; |
491 |
//STemp.ArcStyleSet = this.ControlType; |
492 |
STemp.Name = this.GetType().Name.ToString(); |
493 |
|
494 |
///강인구 추가(2017.11.02) |
495 |
///Memo 추가 |
496 |
STemp.Memo = this.Memo; |
497 |
|
498 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
499 |
} |
500 |
} |
501 |
} |
502 |
} |