markus / MarkupToPDF / Controls / Line / ArrowControl_Multi.cs @ b79d6e7f
이력 | 보기 | 이력해설 | 다운로드 (19.8 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 |
using System.Linq; |
18 |
|
19 |
namespace MarkupToPDF.Controls.Line |
20 |
{ |
21 |
public class ArrowControl_Multi : CommentUserInfo, IDisposable, INotifyPropertyChanged, IDashControl |
22 |
{ |
23 |
|
24 |
public event PropertyChangedEventHandler PropertyChanged; |
25 |
private const string PART_ArrowMultiPath = "PART_ArrowMultiPath"; |
26 |
public Path Base_ArrowMultiPath = null; |
27 |
|
28 |
static ArrowControl_Multi() |
29 |
{ |
30 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(typeof(ArrowControl_Multi))); |
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 ArrowControl_Multi() |
39 |
{ |
40 |
//this.DefaultStyleKey = typeof(ArrowControl_Multi); |
41 |
} |
42 |
|
43 |
public override void Copy(CommentUserInfo lhs) |
44 |
{ |
45 |
if (lhs is ArrowControl_Multi item) |
46 |
{ |
47 |
this.LineSize = item.LineSize; |
48 |
this.StartPoint = new Point(item.StartPoint.X, item.StartPoint.Y); |
49 |
this.MiddlePoint = new Point(item.MiddlePoint.X, item.MiddlePoint.Y); |
50 |
this.DashSize = item.DashSize; |
51 |
this.EndPoint = new Point(item.EndPoint.X, item.EndPoint.Y); |
52 |
this.PointSet = item.PointSet.ConvertAll(x => new Point(x.X, x.Y)); |
53 |
this.Opacity = item.Opacity; |
54 |
this.StrokeColor = item.StrokeColor; |
55 |
this.UserID = item.UserID; |
56 |
this.Memo = item.Memo; |
57 |
} |
58 |
} |
59 |
|
60 |
public override CommentUserInfo Clone() |
61 |
{ |
62 |
var clone = new ArrowControl_Multi(); |
63 |
clone.Copy(this); |
64 |
return clone; |
65 |
} |
66 |
|
67 |
#region Dependency Properties |
68 |
|
69 |
public static readonly DependencyProperty IsSelectedProperty = |
70 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
71 |
|
72 |
public static readonly DependencyProperty ControlTypeProperty = |
73 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(ControlType.ArrowMultiLine)); |
74 |
|
75 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
76 |
"OverViewPathData", typeof(Geometry), typeof(ArrowControl_Multi), new PropertyMetadata(null)); |
77 |
|
78 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
79 |
"UserID", typeof(string), typeof(ArrowControl_Multi), new PropertyMetadata(null)); |
80 |
|
81 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
82 |
"LineSize", typeof(double), typeof(ArrowControl_Multi), new PropertyMetadata((Double)3, PointValueChanged)); |
83 |
|
84 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
85 |
"DashSize", typeof(DoubleCollection), typeof(ArrowControl_Multi), new PropertyMetadata(new DoubleCollection { 99999099 }, PointValueChanged)); |
86 |
|
87 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
88 |
"StrokeColor", typeof(SolidColorBrush), typeof(ArrowControl_Multi), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
89 |
|
90 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
91 |
"PathData", typeof(Geometry), typeof(ArrowControl_Multi), null); |
92 |
|
93 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
94 |
"StartPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
95 |
|
96 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
97 |
"EndPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
98 |
public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register( |
99 |
"MiddlePoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
100 |
|
101 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
102 |
"PointSet", typeof(List<Point>), typeof(ArrowControl_Multi), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
103 |
#endregion |
104 |
#region PropertyChanged Method |
105 |
|
106 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
107 |
{ |
108 |
//var instance = (ArrowControl_Multi)sender; |
109 |
|
110 |
//if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null) |
111 |
//{ |
112 |
|
113 |
// instance.SetValue(e.Property, e.NewValue); |
114 |
|
115 |
// if (instance.IsSelected) |
116 |
// { |
117 |
// instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue); |
118 |
// } |
119 |
// else |
120 |
// { |
121 |
// instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red); |
122 |
// } |
123 |
//} |
124 |
} |
125 |
|
126 |
|
127 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
128 |
{ |
129 |
var instance = (ArrowControl_Multi)sender; |
130 |
if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null) |
131 |
{ |
132 |
instance.SetValue(e.Property, e.NewValue); |
133 |
instance.SetArrowMultiPath(); |
134 |
} |
135 |
} |
136 |
#endregion |
137 |
#region Properties |
138 |
public string UserID |
139 |
{ |
140 |
get { return (string)GetValue(UserIDProperty); } |
141 |
set |
142 |
{ |
143 |
if (this.UserID != value) |
144 |
{ |
145 |
SetValue(UserIDProperty, value); |
146 |
OnPropertyChanged("UserID"); |
147 |
} |
148 |
} |
149 |
} |
150 |
public Double LineSize |
151 |
{ |
152 |
get { return (Double)GetValue(LineSizeProperty); } |
153 |
set |
154 |
{ |
155 |
if (this.LineSize != value) |
156 |
{ |
157 |
SetValue(LineSizeProperty, value); |
158 |
} |
159 |
} |
160 |
} |
161 |
|
162 |
public Geometry OverViewPathData |
163 |
{ |
164 |
get |
165 |
{ |
166 |
return (Geometry)GetValue(OverViewPathDataProperty); |
167 |
} |
168 |
set |
169 |
{ |
170 |
SetValue(OverViewPathDataProperty, value); |
171 |
OnPropertyChanged("OverViewPathData"); |
172 |
} |
173 |
} |
174 |
|
175 |
public override bool IsSelected |
176 |
{ |
177 |
get |
178 |
{ |
179 |
return (bool)GetValue(IsSelectedProperty); |
180 |
} |
181 |
set |
182 |
{ |
183 |
SetValue(IsSelectedProperty, value); |
184 |
} |
185 |
} |
186 |
|
187 |
public override ControlType ControlType |
188 |
{ |
189 |
get |
190 |
{ |
191 |
return (ControlType)GetValue(ControlTypeProperty); |
192 |
} |
193 |
set |
194 |
{ |
195 |
SetValue(ControlTypeProperty, value); |
196 |
} |
197 |
} |
198 |
|
199 |
|
200 |
public DoubleCollection DashSize |
201 |
{ |
202 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
203 |
set |
204 |
{ |
205 |
if (this.DashSize != value) |
206 |
{ |
207 |
SetValue(DashSizeProperty, value); |
208 |
} |
209 |
} |
210 |
} |
211 |
public List<Point> PointSet |
212 |
{ |
213 |
get { return (List<Point>)GetValue(PointSetProperty); } |
214 |
set { SetValue(PointSetProperty, value); } |
215 |
} |
216 |
public override SolidColorBrush StrokeColor |
217 |
{ |
218 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
219 |
set |
220 |
{ |
221 |
if (this.StrokeColor != value) |
222 |
{ |
223 |
SetValue(StrokeColorProperty, value); |
224 |
} |
225 |
} |
226 |
} |
227 |
public Geometry PathData |
228 |
{ |
229 |
get { return (Geometry)GetValue(PathDataProperty); } |
230 |
set { SetValue(PathDataProperty, value); } |
231 |
} |
232 |
public Point EndPoint |
233 |
{ |
234 |
get { return (Point)GetValue(EndPointProperty); } |
235 |
set { SetValue(EndPointProperty, value); } |
236 |
} |
237 |
public Point StartPoint |
238 |
{ |
239 |
get { return (Point)GetValue(StartPointProperty); } |
240 |
set { SetValue(StartPointProperty, value); } |
241 |
} |
242 |
public Point MiddlePoint |
243 |
{ |
244 |
get { return (Point)GetValue(MiddlePointProperty); } |
245 |
set |
246 |
{ |
247 |
SetValue(MiddlePointProperty, value); |
248 |
OnPropertyChanged("MiddlePoint"); |
249 |
} |
250 |
} |
251 |
#endregion |
252 |
#region Object & Variable |
253 |
GeometryGroup instanceGroup = new GeometryGroup(); |
254 |
#endregion |
255 |
public override void OnApplyTemplate() |
256 |
{ |
257 |
base.OnApplyTemplate(); |
258 |
Base_ArrowMultiPath = GetTemplateChild(PART_ArrowMultiPath) as Path; |
259 |
SetArrowMultiPath(); |
260 |
} |
261 |
|
262 |
public override void ApplyOverViewData() |
263 |
{ |
264 |
this.OverViewPathData = this.PathData; |
265 |
} |
266 |
|
267 |
public void SetArrowMultiPath() |
268 |
{ |
269 |
|
270 |
|
271 |
Base_ArrowMultiPath.StrokeDashArray.Clear(); |
272 |
foreach (var item in this.DashSize) |
273 |
{ |
274 |
Base_ArrowMultiPath.StrokeDashArray.Add(item); |
275 |
} |
276 |
Base_ArrowMultiPath.StrokeDashCap = PenLineCap.Square; |
277 |
instanceGroup.Children.Clear(); |
278 |
PathFigure pathFigure = new PathFigure(); |
279 |
|
280 |
pathFigure.StartPoint = this.StartPoint; |
281 |
LineSegment lineSegment0 = new LineSegment(); |
282 |
lineSegment0.Point = this.StartPoint; |
283 |
pathFigure.Segments.Add(lineSegment0); |
284 |
|
285 |
|
286 |
|
287 |
//if (this.EndPoint == this.MiddlePoint) |
288 |
if (this.MiddlePoint == new Point(0,0)) |
289 |
{ |
290 |
//instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.MiddlePoint, this.LineSize)); |
291 |
instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize)); |
292 |
} |
293 |
else |
294 |
{ |
295 |
instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.EndPoint, this.LineSize)); |
296 |
LineSegment lineSegment1 = new LineSegment(); |
297 |
lineSegment1.Point = this.MiddlePoint; |
298 |
pathFigure.Segments.Add(lineSegment1); |
299 |
} |
300 |
|
301 |
LineSegment lineSegment2 = new LineSegment(); |
302 |
lineSegment2.Point = this.EndPoint; |
303 |
pathFigure.Segments.Add(lineSegment2); |
304 |
|
305 |
PathGeometry pathGeometry = new PathGeometry(); |
306 |
pathGeometry.Figures.Add(pathFigure); |
307 |
pathFigure.IsFilled = false; |
308 |
instanceGroup.Children.Add(pathGeometry); |
309 |
//this.Base_ArrowMultiPath.Stroke = this.StrokeColor; |
310 |
|
311 |
//if (this.IsSelected) |
312 |
//{ |
313 |
// Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue); |
314 |
//} |
315 |
//else |
316 |
//{ |
317 |
// Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red); |
318 |
//} |
319 |
|
320 |
this.PathData = instanceGroup; |
321 |
OverViewPathData = PathData; |
322 |
} |
323 |
//public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize) |
324 |
//{ |
325 |
// double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI; |
326 |
// PathGeometry pathGeometry = new PathGeometry(); |
327 |
// PathFigure pathFigure = new PathFigure(); |
328 |
// pathFigure.StartPoint = p1; |
329 |
|
330 |
// Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6); |
331 |
// Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6); |
332 |
|
333 |
// //Point lpoint = new Point(p1.X + lineSize, p1.Y + lineSize * 4); |
334 |
// //Point rpoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4); |
335 |
|
336 |
// //Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6); |
337 |
// //Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6); |
338 |
|
339 |
// LineSegment seg1 = new LineSegment(); |
340 |
// seg1.Point = lpoint; |
341 |
// pathFigure.Segments.Add(seg1); |
342 |
|
343 |
// LineSegment seg2 = new LineSegment(); |
344 |
// seg2.Point = rpoint; |
345 |
// pathFigure.Segments.Add(seg2); |
346 |
|
347 |
// LineSegment seg3 = new LineSegment(); |
348 |
// seg3.Point = p1; |
349 |
// pathFigure.Segments.Add(seg3); |
350 |
|
351 |
// pathFigure.IsClosed = true; |
352 |
// pathFigure.IsFilled = true; |
353 |
|
354 |
// pathGeometry.Figures.Add(pathFigure); |
355 |
// pathGeometry.FillRule = FillRule.Nonzero; |
356 |
// RotateTransform transform = new RotateTransform(); |
357 |
// transform.Angle = theta - 90; |
358 |
// transform.CenterX = p1.X; |
359 |
// transform.CenterY = p1.Y; |
360 |
// pathGeometry.Transform = transform; |
361 |
// return pathGeometry; |
362 |
//} |
363 |
|
364 |
protected void OnPropertyChanged(string propName) |
365 |
{ |
366 |
if (PropertyChanged != null) |
367 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
368 |
} |
369 |
|
370 |
public override void UpdateControl() |
371 |
{ |
372 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
373 |
this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
374 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
375 |
} |
376 |
|
377 |
/// <summary> |
378 |
/// call when mouse is moving while drawing control |
379 |
/// </summary> |
380 |
/// <author>humkyung</author> |
381 |
/// <param name="pt"></param> |
382 |
/// <param name="bAxisLocked"></param> |
383 |
public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
384 |
{ |
385 |
this.EndPoint = pt; |
386 |
if (this.MiddlePoint == new Point(0, 0)) |
387 |
{ |
388 |
Point tmp = this.EndPoint; |
389 |
CommentAngle = MathSet.returnAngle(this.StartPoint, ref tmp, bAxisLocked); |
390 |
|
391 |
if (bAxisLocked) |
392 |
{ |
393 |
this.EndPoint = tmp; |
394 |
} |
395 |
} |
396 |
else |
397 |
{ |
398 |
Point tmp = this.EndPoint; |
399 |
CommentAngle = MathSet.returnAngle(this.MiddlePoint, ref tmp, bAxisLocked); |
400 |
|
401 |
if (bAxisLocked) |
402 |
{ |
403 |
|
404 |
this.EndPoint = tmp; |
405 |
} |
406 |
} |
407 |
|
408 |
this.PointSet = new List<Point> |
409 |
{ |
410 |
this.StartPoint, |
411 |
this.MiddlePoint, |
412 |
this.EndPoint, |
413 |
}; |
414 |
} |
415 |
|
416 |
/// <summary> |
417 |
/// move control point has same location of given pt along given delta |
418 |
/// </summary> |
419 |
/// <author>humkyung</author> |
420 |
/// <date>2019.06.20</date> |
421 |
/// <param name="pt"></param> |
422 |
/// <param name="dx"></param> |
423 |
/// <param name="dy"></param> |
424 |
public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
425 |
{ |
426 |
Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt); |
427 |
|
428 |
var tmpPointSet = (this as IPath).PointSet.Where(x => !x.Equals(selected)); |
429 |
Point NearStartpoint = MathSet.getNearPoint(tmpPointSet.ToList(), pt); |
430 |
|
431 |
selected.X += dx; |
432 |
selected.Y += dy; |
433 |
|
434 |
Point tmp = selected; |
435 |
|
436 |
CommentAngle = MathSet.returnAngle(NearStartpoint, ref tmp, bAxisLocked); |
437 |
|
438 |
if (bAxisLocked) |
439 |
{ |
440 |
selected = tmp; |
441 |
} |
442 |
|
443 |
for (int i = 0; i < (this as IPath).PointSet.Count; i++) |
444 |
{ |
445 |
if (pt.Equals((this as IPath).PointSet[i])) |
446 |
{ |
447 |
(this as IPath).PointSet[i] = selected; |
448 |
} |
449 |
} |
450 |
this.UpdateControl(); |
451 |
} |
452 |
|
453 |
/// <summary> |
454 |
/// return ArrowControl_Multi's area |
455 |
/// </summary> |
456 |
/// <author>humkyung</author> |
457 |
/// <date>2019.06.13</date> |
458 |
public override Rect ItemRect |
459 |
{ |
460 |
get |
461 |
{ |
462 |
double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X); |
463 |
dMinX = Math.Min(this.MiddlePoint.X, dMinX); |
464 |
double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y); |
465 |
dMinY = Math.Min(this.MiddlePoint.Y, dMinY); |
466 |
double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X); |
467 |
dMaxX = Math.Max(this.MiddlePoint.X, dMaxX); |
468 |
double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y); |
469 |
dMaxY = Math.Max(this.MiddlePoint.Y, dMaxY); |
470 |
|
471 |
return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
472 |
} |
473 |
} |
474 |
|
475 |
/// <summary> |
476 |
/// Serialize this |
477 |
/// </summary> |
478 |
/// <param name="sUserId"></param> |
479 |
/// <returns></returns> |
480 |
public override string Serialize() |
481 |
{ |
482 |
using (S_ArrowControl_Multi STemp = new S_ArrowControl_Multi()) |
483 |
{ |
484 |
STemp.TransformPoint = "0|0"; |
485 |
STemp.PointSet = this.PointSet; |
486 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
487 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
488 |
STemp.StartPoint = this.StartPoint; |
489 |
STemp.EndPoint = this.EndPoint; |
490 |
STemp.UserID = this.UserID; |
491 |
STemp.Opac = this.Opacity; |
492 |
STemp.DashSize = this.DashSize; |
493 |
STemp.MidPoint = this.MiddlePoint; |
494 |
STemp.Name = this.GetType().Name.ToString(); |
495 |
|
496 |
///강인구 추가(2017.11.02) |
497 |
///Memo 추가 |
498 |
STemp.Memo = this.Memo; |
499 |
|
500 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
501 |
}; |
502 |
} |
503 |
|
504 |
/// <summary> |
505 |
/// create a arrowcontrol_multi from given string |
506 |
/// </summary> |
507 |
/// <param name="str"></param> |
508 |
/// <returns></returns> |
509 |
public static ArrowControl_Multi FromString(string str, SolidColorBrush brush, string sProjectNo) |
510 |
{ |
511 |
ArrowControl_Multi instance = null; |
512 |
using (S_ArrowControl_Multi s = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(str)) |
513 |
{ |
514 |
string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
515 |
instance = new ArrowControl_Multi |
516 |
{ |
517 |
LineSize = Convert.ToDouble(data2.First()), |
518 |
StartPoint = s.StartPoint, |
519 |
MiddlePoint = s.MidPoint, |
520 |
DashSize = s.DashSize, |
521 |
EndPoint = s.EndPoint, |
522 |
PointSet = s.PointSet, |
523 |
Opacity = s.Opac, |
524 |
StrokeColor = brush, |
525 |
UserID = s.UserID, |
526 |
Memo = s.Memo |
527 |
}; |
528 |
} |
529 |
|
530 |
return instance; |
531 |
} |
532 |
|
533 |
public void Dispose() |
534 |
{ |
535 |
//GC.Collect(); |
536 |
////GC.SuppressFinalize(this); |
537 |
this.Base_ArrowMultiPath = null; |
538 |
} |
539 |
} |
540 |
} |
541 |
|