Add primitive visual property

This commit is contained in:
RedikultsevEvg
2025-08-03 23:37:50 +05:00
parent 6e8f4bcc58
commit 466c57feef
52 changed files with 742 additions and 138 deletions

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.VisualProperties
{
public interface IHasVisualProperty
{
IPrimitiveVisualProperty VisualProperty { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
using StructureHelperCommon.Infrastructures.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperCommon.Models.VisualProperties
{
/// <summary>
/// Implements visual settings for graphical primetives
/// </summary>
public interface IPrimitiveVisualProperty : ISaveable, ICloneable
{
/// <summary>
/// Flag of visibility
/// </summary>
bool IsVisible { get; set; }
/// <summary>
/// Color of primitive
/// </summary>
Color Color { get; set; }
/// <summary>
/// Index by z-coordinate
/// </summary>
int ZIndex { get; set; }
/// <summary>
/// Opacity of filling
/// </summary>
double Opacity { get; set; }
}
}

View File

@@ -0,0 +1,54 @@
using StructureHelperCommon.Services.ColorServices;
using System;
using System.Windows.Media;
namespace StructureHelperCommon.Models.VisualProperties
{
/// <inheritdoc/>
public class PrimitiveVisualProperty : IPrimitiveVisualProperty
{
private double opacity = 0;
/// <inheritdoc/>
public Guid Id { get; }
/// <inheritdoc/>
public bool IsVisible { get; set; } = true;
/// <inheritdoc/>
public Color Color { get; set; } = ColorProcessor.GetRandomColor();
/// <inheritdoc/>
public int ZIndex { get; set; } = 0;
/// <inheritdoc/>
public double Opacity
{
get => opacity;
set
{
if (value < 0)
{
opacity = 1;
return;
}
if (value > 1)
{
opacity = 1;
return;
}
opacity = value;
}
}
public PrimitiveVisualProperty(Guid id)
{
Id = id;
}
public object Clone()
{
var logic = new PrimitiveVisualPropertyUpdateStrategy();
PrimitiveVisualProperty newItem = new(Guid.NewGuid());
logic.Update(newItem, this);
return newItem;
}
}
}

View File

@@ -0,0 +1,20 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Services;
namespace StructureHelperCommon.Models.VisualProperties
{
public class PrimitiveVisualPropertyUpdateStrategy : IUpdateStrategy<IPrimitiveVisualProperty>
{
public void Update(IPrimitiveVisualProperty targetObject, IPrimitiveVisualProperty sourceObject)
{
CheckObject.IsNull(sourceObject, ErrorStrings.SourceObject);
CheckObject.IsNull(targetObject, ErrorStrings.TargetObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
targetObject.IsVisible = sourceObject.IsVisible;
targetObject.Color = sourceObject.Color;
targetObject.Opacity = sourceObject.Opacity;
targetObject.ZIndex = sourceObject.ZIndex;
}
}
}