markus / MarkupToPDF / Controls / Shape / RectCloudControl.cs @ e1b36bc0
이력 | 보기 | 이력해설 | 다운로드 (27.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.Core; |
16 |
using MarkupToPDF.Serialize.S_Control; |
17 |
using System.Linq; |
18 |
using System.ServiceModel.Activation; |
19 |
using System.Windows.Markup; |
20 |
|
21 |
namespace MarkupToPDF.Controls.Shape |
22 |
{ |
23 |
public class RectCloudControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IDashControl |
24 |
{ |
25 |
#region 초기 선언 |
26 |
private const string PART_ArcPath = "PART_ArcPath"; |
27 |
private const string PART_BodyPath = "PART_BodyPath"; |
28 |
public event PropertyChangedEventHandler PropertyChanged; |
29 |
|
30 |
public Path Base_ArcPath = null; |
31 |
public Path Base_BodyPath = null; |
32 |
|
33 |
private const double _CloudArcDepth = 0.8; /// 2018.05.14 added by humkyung |
34 |
|
35 |
#endregion |
36 |
|
37 |
static RectCloudControl() |
38 |
{ |
39 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(RectCloudControl), new FrameworkPropertyMetadata(typeof(RectCloudControl))); |
40 |
//Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
41 |
//ResourceDictionary dictionary = new ResourceDictionary(); |
42 |
//dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
43 |
//Application.Current.Resources.MergedDictionaries.Add(dictionary); |
44 |
} |
45 |
|
46 |
public override void Copy(CommentUserInfo lhs) |
47 |
{ |
48 |
if (lhs is RectCloudControl item) |
49 |
{ |
50 |
this.StartPoint = new System.Windows.Point(item.StartPoint.X, item.StartPoint.Y); |
51 |
this.EndPoint = new System.Windows.Point(item.EndPoint.X, item.EndPoint.Y); |
52 |
this.LeftBottomPoint = new System.Windows.Point(item.LeftBottomPoint.X, item.LeftBottomPoint.Y); |
53 |
this.TopRightPoint = new System.Windows.Point(item.TopRightPoint.X, item.TopRightPoint.Y); |
54 |
this.Paint = item.Paint; |
55 |
this.Opacity = item.Opacity; |
56 |
this.DashSize = item.DashSize; |
57 |
this.PointSet = item.PointSet.ConvertAll(x => new System.Windows.Point(x.X, x.Y)); |
58 |
this.StrokeColor = item.StrokeColor; |
59 |
this.ArcLength = item.ArcLength; |
60 |
this.LineSize = item.LineSize; |
61 |
this.UserID = item.UserID; |
62 |
this.Memo = item.Memo; |
63 |
this.ZIndex = item.ZIndex; |
64 |
this.GroupID = item.GroupID; |
65 |
} |
66 |
} |
67 |
|
68 |
public override CommentUserInfo Clone() |
69 |
{ |
70 |
var clone = new RectCloudControl(); |
71 |
clone.Copy(this); |
72 |
return clone; |
73 |
} |
74 |
|
75 |
#region Dependency Properties |
76 |
|
77 |
public static readonly DependencyProperty mousemodeProperty = |
78 |
DependencyProperty.Register("mousemode", typeof(MouseMode), typeof(RectangleControl), new PropertyMetadata(MouseMode.None, PointValueChanged)); |
79 |
public static readonly DependencyProperty IsSelectedProperty = |
80 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(RectCloudControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
81 |
|
82 |
public static readonly DependencyProperty ControlTypeProperty = |
83 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(RectCloudControl), new FrameworkPropertyMetadata(ControlType.RectCloud)); |
84 |
|
85 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
86 |
"OverViewPathData", typeof(Geometry), typeof(RectCloudControl), new PropertyMetadata(null)); |
87 |
|
88 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
89 |
"LineSize", typeof(double), typeof(RectCloudControl), new PropertyMetadata((Double)3)); |
90 |
|
91 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
92 |
"UserID", typeof(string), typeof(RectCloudControl), new PropertyMetadata(null)); |
93 |
|
94 |
//강인구 추가 |
95 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
96 |
"DashSize", typeof(DoubleCollection), typeof(RectCloudControl), new PropertyMetadata(new DoubleCollection { 99999999 }, PointValueChanged)); |
97 |
|
98 |
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
99 |
"FillColor", typeof(SolidColorBrush), typeof(RectCloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
100 |
//강인구 추가 |
101 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
102 |
"Paint", typeof(PaintSet), typeof(RectCloudControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
103 |
|
104 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
105 |
"StrokeColor", typeof(SolidColorBrush), typeof(RectCloudControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
106 |
|
107 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
108 |
"PathData", typeof(Geometry), typeof(RectCloudControl), null); |
109 |
|
110 |
public static readonly DependencyProperty PathSubDataProperty = DependencyProperty.Register( |
111 |
"PathSubData", typeof(Geometry), typeof(RectCloudControl), null); |
112 |
|
113 |
public static readonly DependencyProperty ArcLengthProperty = DependencyProperty.Register( |
114 |
"ArcLength", typeof(double), typeof(RectCloudControl), new PropertyMetadata((Double)10, PointValueChanged)); |
115 |
|
116 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
117 |
"EndPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
118 |
|
119 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
120 |
"StartPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
121 |
|
122 |
public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
123 |
"TopRightPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
124 |
|
125 |
public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
126 |
"LeftBottomPoint", typeof(Point), typeof(RectCloudControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
127 |
|
128 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
129 |
"PointSet", typeof(List<Point>), typeof(RectCloudControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
130 |
|
131 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("AngleValue", typeof(double), typeof(RectCloudControl), |
132 |
new PropertyMetadata((double)0.0, new PropertyChangedCallback(PointValueChanged))); |
133 |
|
134 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(RectCloudControl), |
135 |
new PropertyMetadata((double)0, PointValueChanged)); |
136 |
|
137 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(RectCloudControl), |
138 |
new PropertyMetadata((double)0, PointValueChanged)); |
139 |
|
140 |
#endregion |
141 |
|
142 |
#region PropertyChanged Method |
143 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
144 |
{ |
145 |
var instance = (RectCloudControl)sender; |
146 |
if (e.OldValue != e.NewValue && instance.Base_ArcPath != null) |
147 |
{ |
148 |
instance.SetValue(e.Property, e.NewValue); |
149 |
instance.SetRectCloud(); |
150 |
} |
151 |
} |
152 |
#endregion |
153 |
|
154 |
#region Properties |
155 |
|
156 |
public MouseMode mousemode |
157 |
{ |
158 |
get |
159 |
{ |
160 |
return (MouseMode)GetValue(mousemodeProperty); |
161 |
} |
162 |
set |
163 |
{ |
164 |
SetValue(mousemodeProperty, value); |
165 |
OnPropertyChanged("mousemode"); |
166 |
} |
167 |
} |
168 |
public Double LineSize |
169 |
{ |
170 |
get { return (Double)GetValue(LineSizeProperty); } |
171 |
set |
172 |
{ |
173 |
if (this.LineSize != value) |
174 |
{ |
175 |
SetValue(LineSizeProperty, value); |
176 |
} |
177 |
} |
178 |
} |
179 |
public DoubleCollection DashSize |
180 |
{ |
181 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
182 |
set |
183 |
{ |
184 |
if (this.DashSize != value) |
185 |
{ |
186 |
SetValue(DashSizeProperty, value); |
187 |
} |
188 |
} |
189 |
} |
190 |
public string UserID |
191 |
{ |
192 |
get { return (string)GetValue(UserIDProperty); } |
193 |
set |
194 |
{ |
195 |
if (this.UserID != value) |
196 |
{ |
197 |
SetValue(UserIDProperty, value); |
198 |
OnPropertyChanged("UserID"); |
199 |
} |
200 |
} |
201 |
} |
202 |
public PaintSet Paint |
203 |
{ |
204 |
get { return (PaintSet)GetValue(PaintProperty); } |
205 |
set |
206 |
{ |
207 |
if (this.Paint != value) |
208 |
{ |
209 |
SetValue(PaintProperty, value); |
210 |
} |
211 |
} |
212 |
} |
213 |
public SolidColorBrush FillColor |
214 |
{ |
215 |
get { return (SolidColorBrush)GetValue(FillColorProperty); } |
216 |
set |
217 |
{ |
218 |
if (this.FillColor != value) |
219 |
{ |
220 |
SetValue(FillColorProperty, value); |
221 |
} |
222 |
} |
223 |
} |
224 |
public override SolidColorBrush StrokeColor |
225 |
{ |
226 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
227 |
set |
228 |
{ |
229 |
if (this.StrokeColor != value) |
230 |
{ |
231 |
SetValue(StrokeColorProperty, value); |
232 |
} |
233 |
} |
234 |
} |
235 |
|
236 |
public Geometry OverViewPathData |
237 |
{ |
238 |
get |
239 |
{ |
240 |
return (Geometry)GetValue(OverViewPathDataProperty); |
241 |
} |
242 |
set |
243 |
{ |
244 |
SetValue(OverViewPathDataProperty, value); |
245 |
OnPropertyChanged("OverViewPathData"); |
246 |
} |
247 |
} |
248 |
|
249 |
public Geometry PathData |
250 |
{ |
251 |
get { return (Geometry)GetValue(PathDataProperty); } |
252 |
set { SetValue(PathDataProperty, value); } |
253 |
} |
254 |
public Geometry PathSubData |
255 |
{ |
256 |
get { return (Geometry)GetValue(PathSubDataProperty); } |
257 |
set { SetValue(PathSubDataProperty, value); } |
258 |
} |
259 |
public Point EndPoint |
260 |
{ |
261 |
get { return (Point)GetValue(EndPointProperty); } |
262 |
set { SetValue(EndPointProperty, value); } |
263 |
} |
264 |
public Point StartPoint |
265 |
{ |
266 |
get { return (Point)GetValue(StartPointProperty); } |
267 |
set { SetValue(StartPointProperty, value); } |
268 |
} |
269 |
public List<Point> PointSet |
270 |
{ |
271 |
get { return (List<Point>)GetValue(PointSetProperty); } |
272 |
set { SetValue(PointSetProperty, value); } |
273 |
} |
274 |
public override bool IsSelected |
275 |
{ |
276 |
get |
277 |
{ |
278 |
return (bool)GetValue(IsSelectedProperty); |
279 |
} |
280 |
set |
281 |
{ |
282 |
SetValue(IsSelectedProperty, value); |
283 |
} |
284 |
} |
285 |
|
286 |
public override ControlType ControlType |
287 |
{ |
288 |
get |
289 |
{ |
290 |
return (ControlType)GetValue(ControlTypeProperty); |
291 |
} |
292 |
set |
293 |
{ |
294 |
SetValue(ControlTypeProperty, value); |
295 |
} |
296 |
} |
297 |
|
298 |
public Double ArcLength |
299 |
{ |
300 |
get { return (Double)GetValue(ArcLengthProperty); } |
301 |
set |
302 |
{ |
303 |
if (this.ArcLength != value) |
304 |
{ |
305 |
SetValue(ArcLengthProperty, value); |
306 |
OnPropertyChanged("ArcLength"); |
307 |
} |
308 |
} |
309 |
} |
310 |
|
311 |
|
312 |
private double _toler = 1; |
313 |
public double Toler |
314 |
{ |
315 |
get { return _toler; } |
316 |
set { _toler = value; } |
317 |
} |
318 |
//private double _arcLength = 30; |
319 |
//public double ArcLength |
320 |
//{ |
321 |
// get { return _arcLength; } |
322 |
// set { _arcLength = value; } |
323 |
//} |
324 |
|
325 |
private bool _fill = false; |
326 |
public bool Fill |
327 |
{ |
328 |
get { return _fill; } |
329 |
set { _fill = value; } |
330 |
} |
331 |
public double CommentAngle |
332 |
{ |
333 |
get { return (double)GetValue(AngleProperty); } |
334 |
set |
335 |
{ |
336 |
if (this.CommentAngle != value) |
337 |
{ |
338 |
SetValue(AngleProperty, value); |
339 |
} |
340 |
} |
341 |
} |
342 |
public double CenterX |
343 |
{ |
344 |
get { return (double)GetValue(CenterXProperty); } |
345 |
set { SetValue(CenterXProperty, value); } |
346 |
} |
347 |
public double CenterY |
348 |
{ |
349 |
get { return (double)GetValue(CenterYProperty); } |
350 |
set { SetValue(CenterYProperty, value); } |
351 |
} |
352 |
public Point LeftBottomPoint |
353 |
{ |
354 |
get { return (Point)GetValue(LeftBottomPointProperty); } |
355 |
set |
356 |
{ |
357 |
SetValue(LeftBottomPointProperty, value); |
358 |
OnPropertyChanged("LeftBottomPoint"); |
359 |
} |
360 |
} |
361 |
public Point TopRightPoint |
362 |
{ |
363 |
get { return (Point)GetValue(TopRightPointProperty); } |
364 |
set |
365 |
{ |
366 |
SetValue(TopRightPointProperty, value); |
367 |
OnPropertyChanged("TopRightPoint"); |
368 |
} |
369 |
} |
370 |
#endregion |
371 |
|
372 |
#region Data |
373 |
private PathGeometry _pathGeometry = new PathGeometry(); |
374 |
#endregion |
375 |
|
376 |
public override void OnApplyTemplate() |
377 |
{ |
378 |
base.OnApplyTemplate(); |
379 |
Base_ArcPath = GetTemplateChild(PART_ArcPath) as Path; |
380 |
Base_BodyPath = GetTemplateChild(PART_BodyPath) as Path; |
381 |
|
382 |
this.SetRectCloud(); |
383 |
|
384 |
} |
385 |
protected void OnPropertyChanged(string propName) |
386 |
{ |
387 |
if (PropertyChanged != null) |
388 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
389 |
} |
390 |
public void Dispose() |
391 |
{ |
392 |
//GC.Collect(); |
393 |
////GC.SuppressFinalize(this); |
394 |
this.Base_ArcPath = null; |
395 |
this.Base_BodyPath = null; |
396 |
} |
397 |
|
398 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
399 |
{ |
400 |
//var instance = (RectCloudControl)sender; |
401 |
|
402 |
//if (e.OldValue != e.NewValue && instance.Base_BodyPath != null) |
403 |
//{ |
404 |
|
405 |
// instance.SetValue(e.Property, e.NewValue); |
406 |
|
407 |
// if (instance.IsSelected) |
408 |
// { |
409 |
// instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Blue); |
410 |
// } |
411 |
// else |
412 |
// { |
413 |
// instance.Base_ArcPath.Stroke = new SolidColorBrush(Colors.Red); |
414 |
// } |
415 |
//} |
416 |
} |
417 |
|
418 |
private void SetRectCloud() |
419 |
{ |
420 |
this.ApplyTemplate(); |
421 |
PathFigure pathFigure = new PathFigure(); |
422 |
|
423 |
Base_ArcPath.StrokeDashArray.Clear(); |
424 |
Base_BodyPath.StrokeDashArray.Clear(); |
425 |
|
426 |
foreach (var item in this.DashSize) |
427 |
{ |
428 |
Base_ArcPath.StrokeDashArray.Add(item); |
429 |
Base_BodyPath.StrokeDashArray.Add(item); |
430 |
} |
431 |
|
432 |
switch (this.Paint) |
433 |
{ |
434 |
case PaintSet.None: |
435 |
//강인구 추가 |
436 |
pathFigure.IsFilled = false; |
437 |
Base_BodyPath.Fill = null; |
438 |
Base_BodyPath.Stroke = null; |
439 |
break; |
440 |
case PaintSet.Fill: |
441 |
{ |
442 |
Base_BodyPath.Stroke = this.StrokeColor; |
443 |
Base_BodyPath.StrokeThickness = 0.5; |
444 |
Base_ArcPath.Stroke = this.StrokeColor; |
445 |
|
446 |
Base_ArcPath.Fill = this.FillColor; |
447 |
Base_BodyPath.Fill = this.FillColor; |
448 |
} |
449 |
//this.FillColor = this.StrokeColor; |
450 |
//Base_BodyPath.Fill = this.FillColor; |
451 |
//Base_ArcPath.Fill = this.FillColor; |
452 |
//Base_BodyPath.Stroke = this.StrokeColor; |
453 |
//Base_BodyPath.StrokeThickness = 2; |
454 |
//Base_ArcPath.Stroke = this.StrokeColor; |
455 |
//Base_ArcPath.StrokeThickness = 2; |
456 |
//pathFigure.IsFilled = true; |
457 |
break; |
458 |
case PaintSet.Hatch: |
459 |
Base_BodyPath.Stroke = new SolidColorBrush(Colors.Transparent); |
460 |
Base_BodyPath.StrokeThickness = 2; |
461 |
Base_BodyPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor); |
462 |
Base_ArcPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor); |
463 |
pathFigure.IsFilled = true; |
464 |
break; |
465 |
default: |
466 |
break; |
467 |
} |
468 |
|
469 |
#region 사각형 만들기 |
470 |
if (this.Paint != PaintSet.None) |
471 |
{ |
472 |
pathFigure.StartPoint = this.StartPoint; |
473 |
|
474 |
List<Point> points = new List<Point>() { this.StartPoint, this.LeftBottomPoint, this.EndPoint, this.TopRightPoint }; |
475 |
PolyLineSegment polyline = new PolyLineSegment(points, true); |
476 |
pathFigure.Segments.Add(polyline); |
477 |
|
478 |
PathGeometry pathGeometry = new PathGeometry(); |
479 |
pathGeometry.Figures = new PathFigureCollection(); |
480 |
pathFigure.IsClosed = true; |
481 |
pathGeometry.Figures.Add(pathFigure); |
482 |
//this.FillColor = new SolidColorBrush(Colors.Red); |
483 |
this.PathSubData = pathGeometry; |
484 |
} |
485 |
ArcLength = ArcLength == 0 ? 10 : ArcLength; |
486 |
|
487 |
#endregion |
488 |
#region Cloud 만들기 |
489 |
/// set reverse if area is greater 0 - 2012.07.04 added by humkyung |
490 |
/// |
491 |
|
492 |
System.Diagnostics.Debug.WriteLine(ArcLength); |
493 |
double area = MathSet.AreaOf(new List<Point>() { this.StartPoint, this.LeftBottomPoint, this.EndPoint, this.TopRightPoint }); |
494 |
bool reverse = (area > 0); |
495 |
/// up to here |
496 |
this._pathGeometry = new PathGeometry(); |
497 |
int count = this.PointSet.Count; |
498 |
PathFigure pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.StartPoint, this.LeftBottomPoint, this.ArcLength, reverse); |
499 |
_pathGeometry.Figures.Add(pathSubFigure); |
500 |
|
501 |
pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.LeftBottomPoint, this.EndPoint, this.ArcLength, reverse); |
502 |
_pathGeometry.Figures.Add(pathSubFigure); |
503 |
|
504 |
pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.EndPoint, this.TopRightPoint, this.ArcLength, reverse); |
505 |
_pathGeometry.Figures.Add(pathSubFigure); |
506 |
|
507 |
pathSubFigure = Polygon.CloudControl.GenerateLineWithCloud(this.TopRightPoint, this.StartPoint, this.ArcLength, reverse); |
508 |
_pathGeometry.Figures.Add(pathSubFigure); |
509 |
|
510 |
if (this.Paint != PaintSet.None) |
511 |
{ |
512 |
foreach (var item in _pathGeometry.Figures) |
513 |
{ |
514 |
item.IsFilled = true; |
515 |
} |
516 |
} |
517 |
|
518 |
this.PathData = _pathGeometry; |
519 |
ApplyOverViewData(); |
520 |
#endregion |
521 |
} |
522 |
|
523 |
public void ChangePaint(PaintSet state) |
524 |
{ |
525 |
this.Paint = state; |
526 |
this.SetRectCloud(); |
527 |
} |
528 |
|
529 |
public void CloseSettingPoint() |
530 |
{ |
531 |
this.PointSet[0] = this.StartPoint; |
532 |
this.PointSet[1] = this.LeftBottomPoint; |
533 |
this.PointSet[2] = this.EndPoint; |
534 |
this.PointSet[3] = this.TopRightPoint; |
535 |
} |
536 |
|
537 |
public override void ApplyOverViewData() |
538 |
{ |
539 |
this.OverViewPathData = this.PathData; |
540 |
} |
541 |
|
542 |
public override void UpdateControl() |
543 |
{ |
544 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
545 |
this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
546 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
547 |
this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
548 |
} |
549 |
|
550 |
/// <summary> |
551 |
/// call when mouse is moving while drawing control |
552 |
/// </summary> |
553 |
/// <author>humkyung</author> |
554 |
/// <param name="pt"></param> |
555 |
/// <param name="bAxisLocked"></param> |
556 |
public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
557 |
{ |
558 |
this.EndPoint = bAxisLocked ? this.GetSquareEndPoint(this.StartPoint, pt) : pt; |
559 |
this.LeftBottomPoint = new Point(this.StartPoint.X, this.EndPoint.Y); |
560 |
this.TopRightPoint = new Point(this.EndPoint.X, this.StartPoint.Y); |
561 |
|
562 |
this.PointSet = new List<Point> |
563 |
{ |
564 |
this.StartPoint, |
565 |
this.LeftBottomPoint, |
566 |
this.EndPoint, |
567 |
this.TopRightPoint, |
568 |
}; |
569 |
} |
570 |
|
571 |
/// <summary> |
572 |
/// move control point has same location of given pt along given delta |
573 |
/// </summary> |
574 |
/// <author>humkyung</author> |
575 |
/// <date>2019.06.20</date> |
576 |
/// <param name="pt"></param> |
577 |
/// <param name="dx"></param> |
578 |
/// <param name="dy"></param> |
579 |
public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
580 |
{ |
581 |
IPath path = (this as IPath); |
582 |
|
583 |
Point selected = MathSet.getNearPoint(path.PointSet, pt); |
584 |
selected.X += dx; |
585 |
selected.Y += dy; |
586 |
int i = 0; |
587 |
for (i = 0; i < (this as IPath).PointSet.Count; i++) |
588 |
{ |
589 |
if (pt.Equals((this as IPath).PointSet[i])) |
590 |
{ |
591 |
(this as IPath).PointSet[i] = selected; |
592 |
break; |
593 |
} |
594 |
} |
595 |
|
596 |
var OppositeP = (i + path.PointSet.Count / 2) % path.PointSet.Count; |
597 |
var PreviousP = (i + (path.PointSet.Count - 1)) % path.PointSet.Count; |
598 |
var NextP = (i + 1) % path.PointSet.Count; |
599 |
|
600 |
if (bAxisLocked) |
601 |
{ |
602 |
double _dx = path.PointSet[i].X - path.PointSet[OppositeP].X; |
603 |
double _dy = path.PointSet[i].Y - path.PointSet[OppositeP].Y; |
604 |
double distance = Math.Max(Math.Abs(_dx), Math.Abs(_dy)); |
605 |
|
606 |
var PreviousV = path.PointSet[PreviousP] - path.PointSet[OppositeP]; |
607 |
PreviousV.Normalize(); |
608 |
path.PointSet[PreviousP] = path.PointSet[OppositeP] + PreviousV * distance; |
609 |
|
610 |
var NextV = path.PointSet[NextP] - path.PointSet[OppositeP]; |
611 |
NextV.Normalize(); |
612 |
path.PointSet[NextP] = path.PointSet[OppositeP] + NextV * distance; |
613 |
|
614 |
path.PointSet[i] = path.PointSet[OppositeP] + PreviousV * distance + NextV * distance; |
615 |
} |
616 |
else |
617 |
{ |
618 |
var PreviousV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[PreviousP]); |
619 |
var l = MathSet.DotProduct(PreviousV.X, PreviousV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X, |
620 |
path.PointSet[i].Y - path.PointSet[OppositeP].Y); |
621 |
|
622 |
Point pPrevious = new Point(path.PointSet[OppositeP].X + PreviousV.X * l, path.PointSet |
623 |
[OppositeP].Y + PreviousV.Y * l); |
624 |
|
625 |
if (path.PointSet.FindAll(x => x.Equals(pPrevious)).Count() == 0) |
626 |
{ |
627 |
path.PointSet[PreviousP] = pPrevious; |
628 |
} |
629 |
|
630 |
var NextV = MathSet.GetNormVectorBetween(path.PointSet[OppositeP], path.PointSet[NextP]); |
631 |
l = MathSet.DotProduct(NextV.X, NextV.Y, path.PointSet[i].X - path.PointSet[OppositeP].X, path.PointSet |
632 |
[i].Y - path.PointSet[OppositeP].Y); |
633 |
|
634 |
Point pNext = new Point(path.PointSet[OppositeP].X + NextV.X * l, path.PointSet[OppositeP].Y + NextV.Y * l); |
635 |
if (path.PointSet.FindAll(x => x.Equals(pNext)).Count() == 0) |
636 |
{ |
637 |
path.PointSet[NextP] = pNext; |
638 |
} |
639 |
} |
640 |
|
641 |
this.UpdateControl(); |
642 |
} |
643 |
|
644 |
/// <summary> |
645 |
/// return rectcloudcontrols' area |
646 |
/// </summary> |
647 |
/// <author>humkyung</author> |
648 |
/// <date>2019.06.13</date> |
649 |
public override Rect ItemRect |
650 |
{ |
651 |
get |
652 |
{ |
653 |
double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X); |
654 |
double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y); |
655 |
double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X); |
656 |
double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y); |
657 |
|
658 |
return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
659 |
} |
660 |
} |
661 |
|
662 |
/// <summary> |
663 |
/// Serialize this |
664 |
/// </summary> |
665 |
/// <param name="sUserId"></param> |
666 |
/// <returns></returns> |
667 |
public override string Serialize() |
668 |
{ |
669 |
using (S_RectCloudControl ctrl = new S_RectCloudControl()) |
670 |
{ |
671 |
ctrl.TransformPoint = "0|0"; |
672 |
ctrl.PointSet = this.PointSet; |
673 |
ctrl.SizeSet = String.Format("{0}", this.LineSize); |
674 |
//ctrl.StrokeColor = "#FF00FF00"; |
675 |
ctrl.StrokeColor = this.StrokeColor.Color.ToString(); |
676 |
ctrl.StartPoint = this.StartPoint; |
677 |
ctrl.UserID = this.UserID; |
678 |
ctrl.Opac = this.Opacity; |
679 |
ctrl.TR = this.TopRightPoint; |
680 |
ctrl.LB = this.LeftBottomPoint; |
681 |
ctrl.EndPoint = this.EndPoint; |
682 |
ctrl.PaintState = this.Paint; |
683 |
ctrl.DashSize = this.DashSize; |
684 |
ctrl.ArcLength = this.ArcLength; |
685 |
ctrl.Name = this.GetType().Name.ToString(); |
686 |
///강인구 추가(2017.11.02) |
687 |
///Memo 추가 |
688 |
ctrl.Memo = this.Memo; |
689 |
|
690 |
ctrl.ZIndex = this.ZIndex; |
691 |
ctrl.GroupID = this.GroupID; |
692 |
|
693 |
return "|DZ|" + JsonSerializerHelper.CompressString((ctrl.JsonSerialize())); |
694 |
} |
695 |
} |
696 |
|
697 |
/// <summary> |
698 |
/// create a rectcloudcontrol from given string |
699 |
/// </summary> |
700 |
/// <param name="str"></param> |
701 |
/// <returns></returns> |
702 |
public static RectCloudControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
703 |
{ |
704 |
using (S_RectCloudControl s = JsonSerializerHelper.JsonDeserialize<S_RectCloudControl>(str)) |
705 |
{ |
706 |
string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
707 |
return new RectCloudControl() |
708 |
{ |
709 |
StartPoint = s.StartPoint, |
710 |
EndPoint = s.EndPoint, |
711 |
LeftBottomPoint = s.LB, |
712 |
Paint = s.PaintState, |
713 |
Opacity = s.Opac, |
714 |
DashSize = s.DashSize, |
715 |
TopRightPoint = s.TR, |
716 |
PointSet = s.PointSet, |
717 |
StrokeColor = brush, |
718 |
ArcLength = s.ArcLength, |
719 |
LineSize = Convert.ToDouble(data2.First()), |
720 |
UserID = s.UserID, |
721 |
Memo = s.Memo, |
722 |
ZIndex = s.ZIndex, |
723 |
GroupID = s.GroupID |
724 |
}; |
725 |
} |
726 |
} |
727 |
} |
728 |
} |