markus / MarkupToPDF / Controls / Line / ArcControl.cs @ 036650a0
이력 | 보기 | 이력해설 | 다운로드 (19.4 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.S_Control; |
16 |
using MarkupToPDF.Serialize.Core; |
17 |
|
18 |
namespace MarkupToPDF.Controls.Line |
19 |
{ |
20 |
|
21 |
public class ArcControl : 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 ArcControl() |
29 |
{ |
30 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(ArcControl), new FrameworkPropertyMetadata(typeof(ArcControl))); |
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 ArcControl() |
39 |
{ |
40 |
this.DefaultStyleKey = typeof(ArcControl); |
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(ArcControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
61 |
|
62 |
public static readonly DependencyProperty ControlTypeProperty = |
63 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArcControl), new FrameworkPropertyMetadata(ControlType.ArcLine)); |
64 |
|
65 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
66 |
"OverViewPathData", typeof(Geometry), typeof(ArcControl), new PropertyMetadata(null)); |
67 |
|
68 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
69 |
"UserID", typeof(string), typeof(ArcControl), new PropertyMetadata(null)); |
70 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
71 |
"LineSize", typeof(double), typeof(ArcControl), new PropertyMetadata((Double)3)); |
72 |
|
73 |
//강인구 추가 |
74 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
75 |
"DashSize", typeof(DoubleCollection), typeof(ArcControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged)); |
76 |
|
77 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
78 |
"StrokeColor", typeof(SolidColorBrush), typeof(ArcControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
79 |
|
80 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
81 |
"PathData", typeof(Geometry), typeof(ArcControl), null); |
82 |
|
83 |
//public static readonly DependencyProperty ClockProperty = DependencyProperty.Register( |
84 |
// "Clock", typeof(SweepDirection), typeof(ArcControl), new PropertyMetadata(SweepDirection.Clockwise)); |
85 |
public static readonly DependencyProperty ClockProperty = DependencyProperty.Register( |
86 |
"Clock", typeof(bool), typeof(ArcControl), new PropertyMetadata(false)); |
87 |
|
88 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
89 |
"StartPoint", typeof(Point), typeof(ArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
90 |
public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register( |
91 |
"MidPoint", typeof(Point), typeof(ArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
92 |
|
93 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
94 |
"EndPoint", typeof(Point), typeof(ArcControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
95 |
|
96 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
97 |
"PointSet", typeof(List<Point>), typeof(ArcControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
98 |
|
99 |
public static readonly DependencyProperty isTransOnProperty = DependencyProperty.Register( |
100 |
"isTransOn", typeof(bool), typeof(ArcControl), new PropertyMetadata(false)); |
101 |
|
102 |
public static readonly DependencyProperty AngleProperty = |
103 |
DependencyProperty.Register("AngleValue", typeof(double), typeof(ArcControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback |
104 |
(AngleValueChanged))); |
105 |
|
106 |
public static readonly DependencyProperty CenterXProperty = |
107 |
DependencyProperty.Register("CenterX", typeof(double), typeof(ArcControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
108 |
|
109 |
public static readonly DependencyProperty CenterYProperty = |
110 |
DependencyProperty.Register("CenterY", typeof(double), typeof(ArcControl), 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 = (ArcControl)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 |
|
135 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
136 |
{ |
137 |
var instance = (ArcControl)sender; |
138 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
139 |
{ |
140 |
instance.SetValue(e.Property, e.NewValue); |
141 |
instance.SetArcPath(); |
142 |
} |
143 |
} |
144 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
145 |
{ |
146 |
var instance = (ArcControl)sender; |
147 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
148 |
{ |
149 |
instance.SetValue(e.Property, e.NewValue); |
150 |
instance.SetArcPath(); |
151 |
} |
152 |
} |
153 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
154 |
{ |
155 |
var instance = (ArcControl)sender; |
156 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
157 |
{ |
158 |
instance.SetValue(e.Property, e.NewValue); |
159 |
instance.SetArcPath(); |
160 |
} |
161 |
} |
162 |
|
163 |
|
164 |
|
165 |
#endregion |
166 |
#region Properties |
167 |
public string UserID |
168 |
{ |
169 |
get { return (string)GetValue(UserIDProperty); } |
170 |
set |
171 |
{ |
172 |
if (this.UserID != value) |
173 |
{ |
174 |
SetValue(UserIDProperty, value); |
175 |
OnPropertyChanged("UserID"); |
176 |
} |
177 |
} |
178 |
} |
179 |
public Double LineSize |
180 |
{ |
181 |
get { return (Double)GetValue(LineSizeProperty); } |
182 |
set |
183 |
{ |
184 |
if (this.LineSize != value) |
185 |
{ |
186 |
SetValue(LineSizeProperty, value); |
187 |
} |
188 |
} |
189 |
} |
190 |
|
191 |
|
192 |
public bool Clock |
193 |
{ |
194 |
get { return (bool)GetValue(ClockProperty); } |
195 |
set |
196 |
{ |
197 |
if (this.Clock != value) |
198 |
{ |
199 |
SetValue(ClockProperty, value); |
200 |
OnPropertyChanged("Clock"); |
201 |
} |
202 |
} |
203 |
} |
204 |
|
205 |
//public SweepDirection Clock |
206 |
//{ |
207 |
// get { return (SweepDirection)GetValue(ClockProperty); } |
208 |
// set |
209 |
// { |
210 |
// if (this.Clock != value) |
211 |
// { |
212 |
// SetValue(ClockProperty, value); |
213 |
// OnPropertyChanged("Clock"); |
214 |
// } |
215 |
// } |
216 |
//} |
217 |
public DoubleCollection DashSize |
218 |
{ |
219 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
220 |
set |
221 |
{ |
222 |
if (this.DashSize != value) |
223 |
{ |
224 |
SetValue(DashSizeProperty, value); |
225 |
} |
226 |
} |
227 |
} |
228 |
public List<Point> PointSet |
229 |
{ |
230 |
get { return (List<Point>)GetValue(PointSetProperty); } |
231 |
set { SetValue(PointSetProperty, value); } |
232 |
} |
233 |
public double CenterX |
234 |
{ |
235 |
get { return (double)GetValue(CenterXProperty); } |
236 |
set { SetValue(CenterXProperty, value); } |
237 |
} |
238 |
public double CenterY |
239 |
{ |
240 |
get { return (double)GetValue(CenterYProperty); } |
241 |
set { SetValue(CenterYProperty, value); } |
242 |
} |
243 |
public SolidColorBrush StrokeColor |
244 |
{ |
245 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
246 |
set |
247 |
{ |
248 |
if (this.StrokeColor != value) |
249 |
{ |
250 |
SetValue(StrokeColorProperty, value); |
251 |
} |
252 |
} |
253 |
} |
254 |
|
255 |
public Geometry OverViewPathData |
256 |
{ |
257 |
get |
258 |
{ |
259 |
return (Geometry)GetValue(OverViewPathDataProperty); |
260 |
} |
261 |
set |
262 |
{ |
263 |
SetValue(OverViewPathDataProperty, value); |
264 |
OnPropertyChanged("OverViewPathData"); |
265 |
} |
266 |
} |
267 |
|
268 |
public Geometry PathData |
269 |
{ |
270 |
get { return (Geometry)GetValue(PathDataProperty); } |
271 |
set |
272 |
{ |
273 |
SetValue(PathDataProperty, value); |
274 |
OnPropertyChanged("PathData"); |
275 |
} |
276 |
} |
277 |
public bool IsSelected |
278 |
{ |
279 |
get |
280 |
{ |
281 |
return (bool)GetValue(IsSelectedProperty); |
282 |
} |
283 |
set |
284 |
{ |
285 |
SetValue(IsSelectedProperty, value); |
286 |
} |
287 |
} |
288 |
|
289 |
override public ControlType ControlType |
290 |
{ |
291 |
get |
292 |
{ |
293 |
return (ControlType)GetValue(ControlTypeProperty); |
294 |
} |
295 |
set |
296 |
{ |
297 |
SetValue(ControlTypeProperty, value); |
298 |
OnPropertyChanged("ControlType"); |
299 |
} |
300 |
} |
301 |
public double AngleValue |
302 |
{ |
303 |
get { return (double)GetValue(AngleProperty); } |
304 |
set { SetValue(AngleProperty, value); } |
305 |
} |
306 |
public double Angle |
307 |
{ |
308 |
get { return (double)GetValue(AngleProperty); } |
309 |
set |
310 |
{ |
311 |
if (this.Angle != value) |
312 |
{ |
313 |
SetValue(AngleProperty, value); |
314 |
} |
315 |
} |
316 |
} |
317 |
public Point EndPoint |
318 |
{ |
319 |
get { return (Point)GetValue(EndPointProperty); } |
320 |
set |
321 |
{ |
322 |
SetValue(EndPointProperty, value); |
323 |
OnPropertyChanged("EndPoint"); |
324 |
} |
325 |
} |
326 |
public Point StartPoint |
327 |
{ |
328 |
get { return (Point)GetValue(StartPointProperty); } |
329 |
set |
330 |
{ |
331 |
SetValue(StartPointProperty, value); |
332 |
OnPropertyChanged("StartPoint"); |
333 |
} |
334 |
} |
335 |
public Point MidPoint |
336 |
{ |
337 |
get { return (Point)GetValue(MidPointProperty); } |
338 |
set |
339 |
{ |
340 |
SetValue(MidPointProperty, value); |
341 |
OnPropertyChanged("MidPoint"); |
342 |
} |
343 |
} |
344 |
public bool isTransOn |
345 |
{ |
346 |
get { return (bool)GetValue(isTransOnProperty); } |
347 |
set |
348 |
{ |
349 |
SetValue(isTransOnProperty, value); |
350 |
OnPropertyChanged("isTransOn"); |
351 |
} |
352 |
} |
353 |
|
354 |
#endregion |
355 |
#region Object & Variable |
356 |
PathGeometry pathGeometry = new PathGeometry(); |
357 |
GeometryGroup instanceGroup = new GeometryGroup(); |
358 |
#endregion |
359 |
public override void OnApplyTemplate() |
360 |
{ |
361 |
base.OnApplyTemplate(); |
362 |
Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path; |
363 |
SetArcPath(); |
364 |
} |
365 |
public void updateControl() |
366 |
{ |
367 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
368 |
this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
369 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
370 |
} |
371 |
|
372 |
public void setClock() |
373 |
{ |
374 |
if (Clock) |
375 |
{ |
376 |
this.Clock = false; |
377 |
} |
378 |
else |
379 |
{ |
380 |
this.Clock = true; |
381 |
} |
382 |
} |
383 |
|
384 |
//public void setClock() |
385 |
//{ |
386 |
// if(this.Clock == SweepDirection.Clockwise) |
387 |
// { |
388 |
// this.Clock = SweepDirection.Counterclockwise; |
389 |
// } |
390 |
// else |
391 |
// { |
392 |
// this.Clock =SweepDirection.Clockwise; |
393 |
// } |
394 |
//} |
395 |
public void SetArcPath() |
396 |
{ |
397 |
this.ApplyTemplate(); |
398 |
|
399 |
|
400 |
//강인구 추가 |
401 |
Base_ArcPath.StrokeDashArray.Clear(); |
402 |
foreach (var item in this.DashSize) |
403 |
{ |
404 |
Base_ArcPath.StrokeDashArray.Add(item); |
405 |
} |
406 |
instanceGroup.Children.Clear(); |
407 |
|
408 |
|
409 |
PathFigure pathFigure = new PathFigure(); |
410 |
|
411 |
pathFigure.StartPoint = this.StartPoint; |
412 |
QuadraticBezierSegment qb = new QuadraticBezierSegment(); |
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
if (MidPoint != null) |
423 |
{ |
424 |
if (MidPoint == new Point(0,0)) |
425 |
{ |
426 |
double xSharp = 0; |
427 |
double ySharp = 0; |
428 |
|
429 |
//Point t_start = new Point(0, 0); |
430 |
//Point t_end = new Point(30, 10); |
431 |
|
432 |
var midP = MathSet.getMiddlePoint(StartPoint, EndPoint); |
433 |
Point normalV = MathSet.GetNormVectorBetween(StartPoint, EndPoint); |
434 |
var dis = MathSet.DistanceTo(StartPoint, EndPoint); |
435 |
|
436 |
if (!this.Clock) |
437 |
{ |
438 |
xSharp = -normalV.Y; |
439 |
ySharp = normalV.X; |
440 |
} |
441 |
else |
442 |
{ |
443 |
xSharp = normalV.Y; |
444 |
ySharp = -normalV.X; |
445 |
} |
446 |
|
447 |
var pointN = new Point(xSharp * dis, ySharp * dis); |
448 |
MidPoint = new Point(pointN.X + midP.X, pointN.Y + midP.Y); |
449 |
} |
450 |
////System.Diagnostics.Debug.WriteLine(this.MidPoint.ToString()); |
451 |
//qb.Point1 = new Point(200, 200); |
452 |
//qb.Point1 = this.MidPoint; |
453 |
qb.Point1 = this.MidPoint; |
454 |
} |
455 |
|
456 |
qb.Point2 = this.EndPoint; |
457 |
pathFigure.Segments.Add(qb); |
458 |
pathGeometry.Figures = new PathFigureCollection(); |
459 |
pathGeometry.Figures.Add(pathFigure); |
460 |
pathFigure.IsFilled = false; |
461 |
pathFigure.IsClosed = false; |
462 |
instanceGroup.Children.Add(pathGeometry); |
463 |
|
464 |
//Arc Arrow |
465 |
//if(ControlType == ControlType.ArcArrow) |
466 |
if (isTransOn) |
467 |
{ |
468 |
//isTransOn = true; |
469 |
instanceGroup.Children.Add(DrawSet.DrawArrow(this.MidPoint, this.StartPoint, this.LineSize)); |
470 |
instanceGroup.Children.Add(DrawSet.DrawArrow(this.EndPoint, this.MidPoint, this.LineSize)); |
471 |
this.Base_ArcPath.Fill = this.StrokeColor; |
472 |
} |
473 |
//Base_ArcPath.StrokeThickness = 3; |
474 |
|
475 |
instanceGroup.FillRule = FillRule.Nonzero; |
476 |
this.PathData = instanceGroup; |
477 |
this.OverViewPathData = PathData; |
478 |
|
479 |
} |
480 |
|
481 |
public static PathGeometry ConverseAllow(Point p2, Point p1, double lineSize) |
482 |
{ |
483 |
double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI; |
484 |
PathGeometry pathGeometry2 = new PathGeometry(); |
485 |
PathFigure pathFigure2 = new PathFigure(); |
486 |
pathFigure2.StartPoint = p2; |
487 |
|
488 |
Point lpoint2 = new Point(p2.X + lineSize * 2, p2.Y + lineSize * 4); |
489 |
Point rpoint2 = new Point(p2.X - lineSize * 2, p2.Y + lineSize * 4); |
490 |
LineSegment seg1_1 = new LineSegment(); |
491 |
seg1_1.Point = lpoint2; |
492 |
pathFigure2.Segments.Add(seg1_1); |
493 |
|
494 |
LineSegment seg2_1 = new LineSegment(); |
495 |
seg2_1.Point = rpoint2; |
496 |
pathFigure2.Segments.Add(seg2_1); |
497 |
|
498 |
LineSegment seg3_1 = new LineSegment(); |
499 |
seg3_1.Point = p2; |
500 |
pathFigure2.Segments.Add(seg3_1); |
501 |
|
502 |
LineSegment seg4_1 = new LineSegment(); |
503 |
|
504 |
seg4_1.Point = new Point(lpoint2.X, lpoint2.Y); |
505 |
pathFigure2.Segments.Add(seg4_1); |
506 |
|
507 |
//pathFigure2.IsFilled = true; |
508 |
//pathFigure2.IsClosed = true; |
509 |
|
510 |
RotateTransform transform2 = new RotateTransform(); |
511 |
transform2.Angle = theta + 90; |
512 |
transform2.CenterX = p2.X; |
513 |
transform2.CenterY = p2.Y; |
514 |
pathGeometry2.Figures.Add(pathFigure2); |
515 |
pathGeometry2.Transform = transform2; |
516 |
return pathGeometry2; |
517 |
} |
518 |
|
519 |
public void ApplyOverViewData() |
520 |
{ |
521 |
this.OverViewPathData = this.PathData; |
522 |
} |
523 |
|
524 |
/// <summary> |
525 |
/// Serialize this |
526 |
/// </summary> |
527 |
/// <param name="sUserId"></param> |
528 |
/// <returns></returns> |
529 |
public override string Serialize() |
530 |
{ |
531 |
using (S_ArcControl STemp = new S_ArcControl()) |
532 |
{ |
533 |
STemp.TransformPoint = "0|0"; |
534 |
STemp.PointSet = this.PointSet; |
535 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
536 |
//STemp.StrokeColor = "#FF000FFF"; |
537 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
538 |
STemp.StartPoint = this.StartPoint; |
539 |
STemp.UserID = this.UserID; |
540 |
STemp.Opac = this.Opacity; |
541 |
STemp.MidPoint = this.MidPoint; |
542 |
STemp.EndPoint = this.EndPoint; |
543 |
STemp.IsTransOn = this.isTransOn; |
544 |
STemp.DashSize = this.DashSize; |
545 |
STemp.Clock = this.Clock; |
546 |
//STemp.ArcStyleSet = instance.ControlType; |
547 |
STemp.Name = this.GetType().Name.ToString(); |
548 |
|
549 |
///강인구 추가(2017.11.02) |
550 |
///Memo 추가 |
551 |
STemp.Memo = this.Memo; |
552 |
|
553 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
554 |
} |
555 |
} |
556 |
} |
557 |
} |