Add primitive visual property
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user