55 lines
2.3 KiB
C#
55 lines
2.3 KiB
C#
namespace EnvelopeGenerator.Web.Models;
|
|
|
|
public class AnnotationParams
|
|
{
|
|
private Annotation? DefaultAnnotation { get; init; }
|
|
|
|
private readonly Dictionary<string, Annotation> _annots = new();
|
|
|
|
public required Dictionary<string, Annotation> Annots
|
|
{
|
|
get => _annots;
|
|
init
|
|
{
|
|
_annots = value;
|
|
|
|
foreach (var name in _annots.Keys)
|
|
{
|
|
#region set default values
|
|
if(DefaultAnnotation is not null)
|
|
{
|
|
// To set default value, annotation must have default (0) value but default must has non-default value
|
|
if (_annots[name]._left == default && DefaultAnnotation.Left != default)
|
|
_annots[name]._left = DefaultAnnotation.Left;
|
|
|
|
if (_annots[name]._top == default && DefaultAnnotation.Top != default)
|
|
_annots[name]._top = DefaultAnnotation.Top;
|
|
|
|
if (_annots[name]._width == default && DefaultAnnotation.Width != default)
|
|
_annots[name]._width = DefaultAnnotation.Width;
|
|
|
|
if (_annots[name]._height == default && DefaultAnnotation.Height != default)
|
|
_annots[name]._height = DefaultAnnotation.Height;
|
|
}
|
|
#endregion
|
|
|
|
#region set bound annotations
|
|
// horizontal
|
|
if (_annots[name].HorBoundAnnotName is string horBoundAnnotName)
|
|
if (_annots.TryGetValue(horBoundAnnotName, out var horBoundAnnot))
|
|
_annots[name].HorBoundAnnot = horBoundAnnot;
|
|
else
|
|
throw new InvalidOperationException($"{horBoundAnnotName} added as bound anotation. However, it is not defined.");
|
|
|
|
// vertical
|
|
if (_annots[name].VerBoundAnnotName is string verBoundAnnotName)
|
|
if (_annots.TryGetValue(verBoundAnnotName, out var verBoundAnnot))
|
|
_annots[name].VerBoundAnnot = verBoundAnnot;
|
|
else
|
|
throw new InvalidOperationException($"{verBoundAnnotName} added as bound anotation. However, it is not defined.");
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
}
|