using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.Msagl.Core.Geometry;
using Microsoft.Msagl.Core.Geometry.Curves;
using Microsoft.Msagl.Core.Layout;
namespace Microsoft.Msagl.Prototype.LayoutEditing{
///
/// holds the data needed to restore the edge after the editing
///
public class EdgeRestoreData : RestoreData {
Point labelCenter;
[SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "p")]
internal EdgeRestoreData(Edge edge) {
if (edge.UnderlyingPolyline == null) {
var asCurve = (edge.Curve as Curve) ?? new Curve(new List {edge.Curve});
edge.UnderlyingPolyline =
SmoothedPolyline.FromPoints(
new[] {edge.Source.Center}.Concat(Polyline.PolylineFromCurve(asCurve)).
Concat(new[] {edge.Target.Center}));
}
UnderlyingPolyline = edge.UnderlyingPolyline.Clone();
Curve = edge.Curve.Clone();
if (edge.EdgeGeometry.SourceArrowhead != null)
ArrowheadAtSourcePosition = edge.EdgeGeometry.SourceArrowhead.TipPosition;
if (edge.EdgeGeometry.TargetArrowhead != null)
ArrowheadAtTargetPosition = edge.EdgeGeometry.TargetArrowhead.TipPosition;
if (edge.Label != null && edge.UnderlyingPolyline != null) {
labelCenter = edge.Label.Center;
Curve untrimmedCurve = edge.UnderlyingPolyline.CreateCurve();
LabelAttachmentParameter = untrimmedCurve.ClosestParameter(labelCenter);
LabelOffsetFromTheAttachmentPoint = labelCenter - untrimmedCurve[LabelAttachmentParameter];
}
}
///
/// the underlying polyline
///
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Polyline")]
public SmoothedPolyline UnderlyingPolyline { get; set; }
///
/// the initial center
///
public Point LabelCenter {
get { return labelCenter; }
set { labelCenter = value; }
}
///
/// the edge original curve
///
public ICurve Curve { get; set; }
///
/// the arrow head position at source
///
public Point ArrowheadAtSourcePosition { get; set; }
///
/// the arrow head position at target
///
public Point ArrowheadAtTargetPosition { get; set; }
///
///
///
public Point LabelOffsetFromTheAttachmentPoint { get; set; }
///
/// the closest point to the label center
///
public double LabelAttachmentParameter { get; set; }
}
}