markus / MarkupToPDF / Controls / Shape / TriControl.cs @ 8295a079
이력 | 보기 | 이력해설 | 다운로드 (22.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 |
using System.Linq; |
18 |
|
19 |
namespace MarkupToPDF.Controls.Shape |
20 |
{ |
21 |
//[TemplatePart(Name = "PART_TriPath", Type = typeof(Path))] |
22 |
public class TriControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IShapeControl, IDashControl |
23 |
{ |
24 |
public Path Base_TriPath { get; set; } |
25 |
//public enum PaintSet { None, Fill, Hatch }; |
26 |
private const string PART_TriPath = "PART_TriPath"; |
27 |
|
28 |
//public Path Base_TriPath = null; |
29 |
|
30 |
static TriControl() |
31 |
{ |
32 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(TriControl), new FrameworkPropertyMetadata(typeof(TriControl))); |
33 |
//ResourceDictionary dictionary = new ResourceDictionary(); |
34 |
//dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
35 |
//Application.Current.Resources.MergedDictionaries.Add(dictionary); |
36 |
} |
37 |
|
38 |
public override void Copy(CommentUserInfo lhs) |
39 |
{ |
40 |
if(lhs is TriControl item) |
41 |
{ |
42 |
this.LineSize = item.LineSize; |
43 |
this.MidPoint = new Point(item.MidPoint.X, item.MidPoint.Y); |
44 |
this.StartPoint = new Point(item.StartPoint.X, item.StartPoint.Y); |
45 |
this.Paint = item.Paint; |
46 |
this.EndPoint = new Point(item.EndPoint.X, item.EndPoint.Y); |
47 |
this.Opacity = item.Opacity; |
48 |
this.CommentAngle = item.CommentAngle; |
49 |
this.DashSize = item.DashSize; |
50 |
this.PointSet = item.PointSet.ConvertAll(x => new Point(x.X, x.Y)); |
51 |
this.StrokeColor = item.StrokeColor; |
52 |
this.UserID = item.UserID; |
53 |
this.Memo = item.Memo; |
54 |
} |
55 |
} |
56 |
|
57 |
public override CommentUserInfo Clone() |
58 |
{ |
59 |
var clone = new TriControl(); |
60 |
clone.Copy(this); |
61 |
return clone; |
62 |
} |
63 |
|
64 |
#region Dependency Properties |
65 |
|
66 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
67 |
"OverViewPathData", typeof(Geometry), typeof(TriControl), new PropertyMetadata(null)); |
68 |
|
69 |
public static readonly DependencyProperty IsSelectedProperty = |
70 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(TriControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
71 |
|
72 |
public static readonly DependencyProperty ControlTypeProperty = |
73 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TriControl), new FrameworkPropertyMetadata(ControlType.Triangle)); |
74 |
|
75 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
76 |
"LineSize", typeof(double), typeof(TriControl), new PropertyMetadata((Double)3)); |
77 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
78 |
"UserID", typeof(string), typeof(TriControl), new PropertyMetadata(null)); |
79 |
//강인구 추가 |
80 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
81 |
"DashSize", typeof(DoubleCollection), typeof(TriControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged)); |
82 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
83 |
"PathData", typeof(Geometry), typeof(TriControl), null); |
84 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
85 |
"StrokeColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
86 |
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
87 |
"FillColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
88 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
89 |
"EndPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
90 |
public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register( |
91 |
"MidPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
92 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
93 |
"StartPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
94 |
//강인구 추가 |
95 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
96 |
"Paint", typeof(PaintSet), typeof(TriControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
97 |
|
98 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
99 |
"PointSet", typeof(List<Point>), typeof(TriControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
100 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(TriControl), new |
101 |
PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
102 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(TriControl), |
103 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
104 |
|
105 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(TriControl), |
106 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
107 |
|
108 |
#endregion |
109 |
#region PropertyChanged Method |
110 |
|
111 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
112 |
{ |
113 |
//var instance = (TriControl)sender; |
114 |
|
115 |
//if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
116 |
//{ |
117 |
|
118 |
// instance.SetValue(e.Property, e.NewValue); |
119 |
|
120 |
// if (instance.IsSelected) |
121 |
// { |
122 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue); |
123 |
// } |
124 |
// else |
125 |
// { |
126 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red); |
127 |
// } |
128 |
//} |
129 |
} |
130 |
|
131 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
132 |
{ |
133 |
var instance = (TriControl)sender; |
134 |
|
135 |
if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
136 |
{ |
137 |
instance.SetValue(e.Property, e.NewValue); |
138 |
instance.SetTri(); |
139 |
} |
140 |
} |
141 |
|
142 |
|
143 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
144 |
{ |
145 |
var instance = (TriControl)sender; |
146 |
if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
147 |
{ |
148 |
instance.SetValue(e.Property, e.NewValue); |
149 |
instance.SetTri(); |
150 |
} |
151 |
} |
152 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
153 |
{ |
154 |
var instance = (TriControl)sender; |
155 |
if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
156 |
{ |
157 |
instance.SetValue(e.Property, e.NewValue); |
158 |
instance.SetTri(); |
159 |
} |
160 |
} |
161 |
#endregion |
162 |
#region Properties |
163 |
|
164 |
public Double LineSize |
165 |
{ |
166 |
get { return (Double)GetValue(LineSizeProperty); } |
167 |
set |
168 |
{ |
169 |
if (this.LineSize != value) |
170 |
{ |
171 |
SetValue(LineSizeProperty, value); |
172 |
} |
173 |
} |
174 |
} |
175 |
public string UserID |
176 |
{ |
177 |
get { return (string)GetValue(UserIDProperty); } |
178 |
set |
179 |
{ |
180 |
if (this.UserID != value) |
181 |
{ |
182 |
SetValue(UserIDProperty, value); |
183 |
OnPropertyChanged("UserID"); |
184 |
} |
185 |
} |
186 |
} |
187 |
public SolidColorBrush FillColor |
188 |
{ |
189 |
get { return (SolidColorBrush)GetValue(FillColorProperty); } |
190 |
set |
191 |
{ |
192 |
if (this.FillColor != value) |
193 |
{ |
194 |
SetValue(FillColorProperty, value); |
195 |
} |
196 |
} |
197 |
} |
198 |
public DoubleCollection DashSize |
199 |
{ |
200 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
201 |
set |
202 |
{ |
203 |
if (this.DashSize != value) |
204 |
{ |
205 |
SetValue(DashSizeProperty, value); |
206 |
} |
207 |
} |
208 |
} |
209 |
public PaintSet Paint |
210 |
{ |
211 |
get { return (PaintSet)GetValue(PaintProperty); } |
212 |
set |
213 |
{ |
214 |
if (this.Paint != value) |
215 |
{ |
216 |
SetValue(PaintProperty, value); |
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
|
222 |
public override SolidColorBrush StrokeColor |
223 |
{ |
224 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
225 |
set |
226 |
{ |
227 |
if (this.StrokeColor != value) |
228 |
{ |
229 |
SetValue(StrokeColorProperty, value); |
230 |
} |
231 |
} |
232 |
} |
233 |
public Geometry OverViewPathData |
234 |
{ |
235 |
get |
236 |
{ |
237 |
return (Geometry)GetValue(OverViewPathDataProperty); |
238 |
} |
239 |
set |
240 |
{ |
241 |
SetValue(OverViewPathDataProperty, value); |
242 |
OnPropertyChanged("OverViewPathData"); |
243 |
} |
244 |
} |
245 |
public Geometry PathData |
246 |
{ |
247 |
get { return (Geometry)GetValue(PathDataProperty); } |
248 |
set { SetValue(PathDataProperty, value); } |
249 |
} |
250 |
public Point EndPoint |
251 |
{ |
252 |
get { return (Point)GetValue(EndPointProperty); } |
253 |
set { SetValue(EndPointProperty, value); } |
254 |
} |
255 |
public Point StartPoint |
256 |
{ |
257 |
get { return (Point)GetValue(StartPointProperty); } |
258 |
set { SetValue(StartPointProperty, value); } |
259 |
} |
260 |
public Point MidPoint |
261 |
{ |
262 |
get { return (Point)GetValue(MidPointProperty); } |
263 |
set { SetValue(MidPointProperty, value); } |
264 |
} |
265 |
public List<Point> PointSet |
266 |
{ |
267 |
get { return (List<Point>)GetValue(PointSetProperty); } |
268 |
set { SetValue(PointSetProperty, value); } |
269 |
} |
270 |
|
271 |
public override bool IsSelected |
272 |
{ |
273 |
get |
274 |
{ |
275 |
return (bool)GetValue(IsSelectedProperty); |
276 |
} |
277 |
set |
278 |
{ |
279 |
SetValue(IsSelectedProperty, value); |
280 |
} |
281 |
} |
282 |
|
283 |
public override ControlType ControlType |
284 |
{ |
285 |
get |
286 |
{ |
287 |
return (ControlType)GetValue(ControlTypeProperty); |
288 |
} |
289 |
set |
290 |
{ |
291 |
SetValue(ControlTypeProperty, value); |
292 |
} |
293 |
} |
294 |
|
295 |
|
296 |
public double CommentAngle |
297 |
{ |
298 |
get { return (double)GetValue(AngleProperty); } |
299 |
set |
300 |
{ |
301 |
if (this.CommentAngle != value) |
302 |
{ |
303 |
SetValue(AngleProperty, value); |
304 |
} |
305 |
} |
306 |
} |
307 |
public double CenterX |
308 |
{ |
309 |
get { return (double)GetValue(CenterXProperty); } |
310 |
set { SetValue(CenterXProperty, value); } |
311 |
} |
312 |
public double CenterY |
313 |
{ |
314 |
get { return (double)GetValue(CenterYProperty); } |
315 |
set { SetValue(CenterYProperty, value); } |
316 |
} |
317 |
#endregion |
318 |
|
319 |
#region Dependency PropertyChanged |
320 |
//public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
321 |
//{ |
322 |
// var instance = (TriControl)sender; |
323 |
|
324 |
// if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
325 |
// { |
326 |
|
327 |
// instance.SetValue(e.Property, e.NewValue); |
328 |
|
329 |
// if (instance.IsSelected) |
330 |
// { |
331 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue); |
332 |
// } |
333 |
// else |
334 |
// { |
335 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red); |
336 |
// } |
337 |
// } |
338 |
//} |
339 |
|
340 |
#endregion Dependency PropertyChanged |
341 |
|
342 |
public override void OnApplyTemplate() |
343 |
{ |
344 |
base.OnApplyTemplate(); |
345 |
Base_TriPath = GetTemplateChild(PART_TriPath) as Path; |
346 |
|
347 |
if (Base_TriPath == null) |
348 |
{ |
349 |
return; |
350 |
} |
351 |
|
352 |
this.SetTri(); |
353 |
} |
354 |
|
355 |
private void SetTri() |
356 |
{ |
357 |
this.ApplyTemplate(); |
358 |
|
359 |
Base_TriPath.StrokeDashArray.Clear(); |
360 |
foreach (var item in this.DashSize) |
361 |
{ |
362 |
Base_TriPath.StrokeDashArray.Add(item); |
363 |
} |
364 |
Base_TriPath.StrokeDashCap = PenLineCap.Square; |
365 |
PathFigure pathFigure = new PathFigure(); |
366 |
|
367 |
//this.FillColor = this.StrokeColor; |
368 |
////Base_TriPath.Fill = this.FillColor; |
369 |
//Base_TriPath.Fill = Brushes.Red; |
370 |
//pathFigure.IsFilled = true; |
371 |
|
372 |
switch (this.Paint) |
373 |
{ |
374 |
case PaintSet.None: |
375 |
this.FillColor = null; |
376 |
pathFigure.IsFilled = false; |
377 |
break; |
378 |
case PaintSet.Fill: |
379 |
this.FillColor = this.StrokeColor; |
380 |
Base_TriPath.Fill = this.FillColor; |
381 |
pathFigure.IsFilled = true; |
382 |
break; |
383 |
case PaintSet.Hatch: |
384 |
Base_TriPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor); |
385 |
pathFigure.IsFilled = true; |
386 |
break; |
387 |
default: |
388 |
break; |
389 |
} |
390 |
pathFigure.StartPoint = this.StartPoint; |
391 |
|
392 |
List<Point> points = new List<Point>() { this.StartPoint }; |
393 |
if (MidPoint.X != 0 && MidPoint.Y != 0) points.Add(this.MidPoint); |
394 |
points.Add(this.EndPoint); |
395 |
PolyLineSegment polyline = new PolyLineSegment(points , true); |
396 |
pathFigure.Segments.Add(polyline); |
397 |
//polyline.IsSmoothJoin 끝이 둥글해짐 |
398 |
|
399 |
PathGeometry pathGeometry = new PathGeometry(); |
400 |
pathGeometry.Figures = new PathFigureCollection(); |
401 |
if(points.Count == 3) |
402 |
pathFigure.IsClosed = true; |
403 |
pathGeometry.Figures.Add(pathFigure); |
404 |
|
405 |
this.PathData = pathGeometry; |
406 |
ApplyOverViewData(); |
407 |
|
408 |
} |
409 |
public void Dispose() |
410 |
{ |
411 |
//GC.Collect(); |
412 |
////GC.SuppressFinalize(this); |
413 |
this.Base_TriPath = null; |
414 |
} |
415 |
public event PropertyChangedEventHandler PropertyChanged; |
416 |
protected void OnPropertyChanged(string propName) |
417 |
{ |
418 |
if (PropertyChanged != null) |
419 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
420 |
} |
421 |
|
422 |
public override void ApplyOverViewData() |
423 |
{ |
424 |
this.OverViewPathData = this.PathData; |
425 |
} |
426 |
|
427 |
public override void UpdateControl() |
428 |
{ |
429 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
430 |
this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
431 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
432 |
} |
433 |
|
434 |
/// <summary> |
435 |
/// call when mouse is moving while drawing control |
436 |
/// </summary> |
437 |
/// <param name="pt"></param> |
438 |
/// <param name="bAxisLocked"></param> |
439 |
public override void OnCreatingMouseMove(Point pt, bool bAxisLocked) |
440 |
{ |
441 |
this.EndPoint = pt; |
442 |
|
443 |
if (bAxisLocked) |
444 |
{ |
445 |
Point tmp = this.EndPoint; |
446 |
string angle = MathSet.returnAngleString(this.StartPoint, ref tmp, true); |
447 |
this.EndPoint = tmp; |
448 |
|
449 |
List<Point> Points = this.GetRegularTrianglePoints(this.StartPoint, this.EndPoint); |
450 |
if (2 == Points.Count) |
451 |
{ |
452 |
this.MidPoint = Points[0]; |
453 |
this.EndPoint = Points[1]; |
454 |
} |
455 |
} |
456 |
|
457 |
this.PointSet = new List<Point> |
458 |
{ |
459 |
this.StartPoint, |
460 |
this.MidPoint, |
461 |
this.EndPoint, |
462 |
}; |
463 |
} |
464 |
|
465 |
/// <summary> |
466 |
/// move control point has same location of given pt along given delta |
467 |
/// </summary> |
468 |
/// <author>humkyung</author> |
469 |
/// <date>2019.06.20</date> |
470 |
/// <param name="pt"></param> |
471 |
/// <param name="delta"></param> |
472 |
public override void OnMoveCtrlPoint(Point pt, double dx, double dy, bool bAxisLocked = false) |
473 |
{ |
474 |
Point selected = MathSet.getNearPoint((this as IPath).PointSet, pt); ///TODO: 위험 요소를 가지고 있음. |
475 |
selected.X += dx; |
476 |
selected.Y += dy; |
477 |
|
478 |
int iIndex = (this as IPath).PointSet.FindIndex(x => x == pt); |
479 |
if (bAxisLocked) |
480 |
{ |
481 |
this.StartPoint = selected; |
482 |
|
483 |
int PrevIdx = (iIndex + this.PointSet.Count - 1) % this.PointSet.Count; |
484 |
int NextIdx = (iIndex + 1) % this.PointSet.Count; |
485 |
var end = new Point((PointSet[PrevIdx].X + PointSet[NextIdx].X) * 0.5, (PointSet[PrevIdx].Y + PointSet[NextIdx].Y) * 0.5); |
486 |
|
487 |
List<Point> Points = this.GetRegularTrianglePoints(selected, end); |
488 |
if (2 == Points.Count) |
489 |
{ |
490 |
PointSet[PrevIdx] = Points[0]; |
491 |
PointSet[iIndex] = selected; |
492 |
PointSet[NextIdx] = Points[1]; |
493 |
} |
494 |
} |
495 |
else |
496 |
{ |
497 |
for (int i = 0; i < (this as IPath).PointSet.Count; i++) |
498 |
{ |
499 |
if (i == iIndex) |
500 |
{ |
501 |
if (pt.Equals((this as IPath).PointSet[i])) |
502 |
{ |
503 |
(this as IPath).PointSet[i] = selected; |
504 |
} |
505 |
} |
506 |
} |
507 |
} |
508 |
|
509 |
this.UpdateControl(); |
510 |
} |
511 |
|
512 |
/// <summary> |
513 |
/// return tricontrols' area |
514 |
/// </summary> |
515 |
/// <author>humkyung</author> |
516 |
/// <date>2019.06.13</date> |
517 |
public override Rect ItemRect |
518 |
{ |
519 |
get |
520 |
{ |
521 |
double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X); |
522 |
dMinX = Math.Min(this.MidPoint.X, dMinX); |
523 |
double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y); |
524 |
dMinY = Math.Min(this.MidPoint.Y, dMinY); |
525 |
double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X); |
526 |
dMaxX = Math.Max(this.MidPoint.X, dMaxX); |
527 |
double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y); |
528 |
dMaxY = Math.Max(this.MidPoint.Y, dMaxY); |
529 |
|
530 |
return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
531 |
} |
532 |
} |
533 |
|
534 |
/// <summary> |
535 |
/// Serialize this |
536 |
/// </summary> |
537 |
/// <param name="sUserId"></param> |
538 |
/// <returns></returns> |
539 |
public override string Serialize() |
540 |
{ |
541 |
using (S_TriControl STemp = new S_TriControl()) |
542 |
{ |
543 |
STemp.TransformPoint = "0|0"; |
544 |
STemp.Paint = this.Paint; |
545 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
546 |
//STemp.StrokeColor = "#FF00FF00"; |
547 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
548 |
if (this.FillColor != null) |
549 |
{ |
550 |
STemp.FillColor = this.FillColor.Color.ToString(); |
551 |
} |
552 |
STemp.StartPoint = this.StartPoint; |
553 |
STemp.EndPoint = this.EndPoint; |
554 |
STemp.MidPoint = this.MidPoint; |
555 |
STemp.Opac = this.Opacity; |
556 |
STemp.UserID = this.UserID; |
557 |
STemp.PointSet = this.PointSet; |
558 |
STemp.Angle = this.CommentAngle; |
559 |
STemp.DashSize = this.DashSize; |
560 |
STemp.Name = this.GetType().Name.ToString(); |
561 |
///강인구 추가(2017.11.02) |
562 |
///Memo 추가 |
563 |
STemp.Memo = this.Memo; |
564 |
|
565 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
566 |
} |
567 |
} |
568 |
|
569 |
/// <summary> |
570 |
/// create a tricontrol from given string |
571 |
/// </summary> |
572 |
/// <param name="str"></param> |
573 |
/// <returns></returns> |
574 |
public static TriControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
575 |
{ |
576 |
using (S_TriControl s = JsonSerializerHelper.JsonDeserialize<S_TriControl>(str)) |
577 |
{ |
578 |
string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
579 |
return new TriControl |
580 |
{ |
581 |
LineSize = Convert.ToDouble(data2.First()), |
582 |
MidPoint = s.MidPoint, |
583 |
StartPoint = s.StartPoint, |
584 |
Paint = s.Paint, |
585 |
EndPoint = s.EndPoint, |
586 |
Opacity = s.Opac, |
587 |
CommentAngle = s.Angle, |
588 |
DashSize = s.DashSize, |
589 |
PointSet = s.PointSet, |
590 |
StrokeColor = brush, |
591 |
UserID = s.UserID, |
592 |
Memo = s.Memo |
593 |
}; |
594 |
} |
595 |
} |
596 |
|
597 |
/// <summary> |
598 |
/// 정삼각형을 그리기위한 두 포인트를 계산하여 넘겨줌 |
599 |
/// </summary> |
600 |
/// <author>humkyung</author> |
601 |
/// <date>2018.04.26</date> |
602 |
/// <param name="StartP"></param> |
603 |
/// <param name="EndP"></param> |
604 |
/// <returns></returns> |
605 |
/// <history>humkyung 2018.05.11 apply axis lock</history> |
606 |
private List<Point> GetRegularTrianglePoints(Point StartP, Point EndP, bool bCheckAxis = false) |
607 |
{ |
608 |
List<Point> res = new List<Point>(); |
609 |
|
610 |
double dx = EndP.X - StartP.X; |
611 |
double dy = EndP.Y - StartP.Y; |
612 |
double length = Math.Sqrt(dx * dx + dy * dy); |
613 |
double baseLength = length * Math.Tan(30.0 * Math.PI / 180.0); |
614 |
dx /= length; |
615 |
dy /= length; |
616 |
double tmp = dx; |
617 |
dx = -dy; dy = tmp; /// rotate by 90 degree |
618 |
|
619 |
res.Add(new Point(EndP.X + dx * baseLength, EndP.Y + dy * baseLength)); |
620 |
res.Add(new Point(EndP.X - dx * baseLength, EndP.Y - dy * baseLength)); |
621 |
|
622 |
return res; |
623 |
} |
624 |
} |
625 |
} |