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