111 lines
2.6 KiB
C#
111 lines
2.6 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace EnvelopeGenerator.Web.Models;
|
|
|
|
public record Annotation
|
|
{
|
|
public required string Name { get; init; }
|
|
|
|
#region Bound Annotation
|
|
[JsonIgnore]
|
|
public string? HorBoundAnnotName { get; init; }
|
|
|
|
[JsonIgnore]
|
|
public string? VerBoundAnnotName { get; init; }
|
|
#endregion
|
|
|
|
#region Layout
|
|
internal double _marginLeft = default;
|
|
|
|
internal double _marginTop = default;
|
|
|
|
internal double _width = default;
|
|
|
|
internal double _height = default;
|
|
|
|
[JsonIgnore]
|
|
public double MarginLeft
|
|
{
|
|
get => _marginLeft;
|
|
init => _marginLeft = value;
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public double MarginLeftRatio { get; init; } = 1;
|
|
|
|
[JsonIgnore]
|
|
public double MarginTop
|
|
{
|
|
get => _marginTop;
|
|
init => _marginTop = value;
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public double MarginTopRatio { get; init; } = 1;
|
|
|
|
public double Width
|
|
{
|
|
get => _width;
|
|
init => _width = value;
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public double WidthRatio { get; init; } = 1;
|
|
|
|
public double Height
|
|
{
|
|
get => _height;
|
|
init => _height = value;
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public double HeightRatio { get; init; } = 1;
|
|
#endregion
|
|
|
|
#region Position
|
|
public double Left => MarginLeft + (HorBoundAnnot?.HorBoundary ?? 0);
|
|
|
|
public double Top => MarginTop + (VerBoundAnnot?.VerBoundary ?? 0);
|
|
#endregion
|
|
|
|
#region Boundary
|
|
[JsonIgnore]
|
|
public double HorBoundary => Left + Width;
|
|
|
|
[JsonIgnore]
|
|
public double VerBoundary => Top + Height;
|
|
#endregion
|
|
|
|
#region BoundAnnot
|
|
[JsonIgnore]
|
|
public Annotation? HorBoundAnnot { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public Annotation? VerBoundAnnot { get; set; }
|
|
#endregion
|
|
|
|
[JsonIgnore]
|
|
internal Annotation Default
|
|
{
|
|
set
|
|
{
|
|
// To set default value, annotation must have default (0) value but default must has non-default value
|
|
if (_marginLeft == default && value.MarginLeft != default)
|
|
_marginLeft = value.MarginLeft * MarginLeftRatio;
|
|
|
|
if (_marginTop == default && value.MarginTop != default)
|
|
_marginTop = value.MarginTop * MarginTopRatio;
|
|
|
|
if (_width == default && value.Width != default)
|
|
_width = value.Width * WidthRatio;
|
|
|
|
if (_height == default && value.Height != default)
|
|
_height = value.Height * HeightRatio;
|
|
|
|
ClientCoefficient = value.ClientCoefficient;
|
|
}
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public double ClientCoefficient { get; set; } = 1;
|
|
}; |