using System.ComponentModel;
using System.Drawing;
using System.Xml.Serialization;
using Deltares.Geometry;
using Deltares.Mathematics;
using Deltares.Standard;
using Deltares.Standard.Attributes;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.Units;
using Deltares.Standard.Validation;
namespace Deltares.Stability
{
public class SlipCircleGrid : GeometryObject, IVisibleEnabled
{
private const int NumberIntervalCorrection = 1;
private double gridXLeft = 0;
private int gridXNumber = 1;
private double gridXRight = 0;
private double gridZBottom = 0;
private int gridZNumber = 1;
private double gridZTop = 0;
private ISlipCircleGridOwner owner = null;
public SlipCircleGrid()
{
Color = Color.Black;
}
///
/// gets and sets the Left X Value of the Grid
///
[Unit(UnitType.Length)]
[Minimum(-1.000e+06)]
[Maximum(1.000e+06)]
[Format("F3")]
public double GridXLeft
{
get
{
return gridXLeft;
}
set
{
DataEventPublisher.BeforeChange(this, "GridXLeft");
gridXLeft = value;
DataEventPublisher.AfterChange(this, "GridXLeft");
}
}
///
/// Gets and sets the Right X Value of the Grid
///
[Unit(UnitType.Length)]
[Minimum(-1.000e+06)]
[Maximum(1.000e+06)]
[PropertyOrder(1)]
[Format("F3")]
public double GridXRight
{
get
{
return gridXRight;
}
set
{
DataEventPublisher.BeforeChange(this, "GridXRight");
gridXRight = value;
DataEventPublisher.AfterChange(this, "GridXRight");
}
}
///
/// Gets and sets the Top Z Value of the Grid
///
[Unit(UnitType.Length)]
[Minimum(-1.000e+06)]
[Maximum(100000)]
[Format("F3")]
public double GridZTop
{
get
{
return gridZTop;
}
set
{
DataEventPublisher.BeforeChange(this, "GridZTop");
gridZTop = value;
DataEventPublisher.AfterChange(this, "GridZTop");
}
}
///
/// Gets and sets the Bottom Z Value of the Grid
///
[Unit(UnitType.Length)]
[Minimum(-1.000e+06)]
[Maximum(100000)]
[PropertyOrder(4)]
[Format("F3")]
public double GridZBottom
{
get
{
return gridZBottom;
}
set
{
DataEventPublisher.BeforeChange(this, "GridZBottom");
gridZBottom = value;
DataEventPublisher.AfterChange(this, "GridZBottom");
}
}
///
/// Gets and sets the Number in X Of Grid
///
[Minimum(1)]
[Maximum(50)]
public int GridXNumber
{
get
{
return gridXNumber;
}
set
{
DataEventPublisher.BeforeChange(this, "GridXNumber");
gridXNumber = value;
DataEventPublisher.AfterChange(this, "GridXNumber");
}
}
///
/// Gets and sets the Number in Z Of Grid
///
[Minimum(1)]
[Maximum(50)]
[PropertyOrder(5)]
public int GridZNumber
{
get
{
return gridZNumber;
}
set
{
DataEventPublisher.BeforeChange(this, "GridZNumber");
gridZNumber = value;
DataEventPublisher.AfterChange(this, "GridZNumber");
}
}
///
/// Gets or sets the grid Z point distance (GridZNumber) with a correction for the conversion from/to an interval value
///
/// Use this property instead of the GridZNumber for setting and getting values with calculation kernel
public int ZIntervalNumber
{
get
{
return GridZNumber - NumberIntervalCorrection;
}
set
{
GridZNumber = value + NumberIntervalCorrection;
}
}
///
/// Gets or sets the grid X point distance (GridXNumber) with a correction for the conversion from/to an interval value
///
/// Use this property instead of the GridXNumber for setting and getting values with calculation kernel
[Browsable(false)]
public int XIntervalNumber
{
get
{
return GridXNumber - NumberIntervalCorrection;
}
set
{
GridXNumber = value + NumberIntervalCorrection;
}
}
///
/// Gets or sets the color for the grid.
///
public Color Color { get; set; }
///
/// Gets or sets the class read only modus
///
public bool IsReadOnly { get; set; }
[Browsable(false)]
[XmlIgnore]
public ISlipCircleGridOwner Owner
{
get
{
return owner;
}
set
{
owner = value;
}
}
public override GeometryBounds GetGeometryBounds()
{
return new GeometryBounds(GridXLeft, GridXRight, GridZBottom, GridZTop);
}
public override bool ContainsPoint(Point3D point, double tolerance)
{
GeometryBounds bounds = GetGeometryBounds();
if (GridXNumber == 1 || GridZNumber == 1)
{
bounds = new GeometryBounds(bounds.Left - tolerance, bounds.Right + tolerance, bounds.Top - tolerance, bounds.Bottom + tolerance);
}
return bounds.ContainsPoint(point.X, point.Z);
}
///
/// Determines whether the specified property is visible.
///
/// The property.
///
/// true if the specified property is visible; otherwise, false.
///
public bool IsVisible(string property)
{
switch (property)
{
case "Name":
return false;
case "GridXNumber":
return Owner != null && Owner.StabilityModel != null && Owner.StabilityModel.SearchAlgorithm == SearchAlgorithm.Grid;
case "GridZNumber":
return Owner != null && Owner.StabilityModel != null && Owner.StabilityModel.SearchAlgorithm == SearchAlgorithm.Grid;
default:
return true;
}
}
///
/// Determines whether the specified property is enabled.
///
/// The property.
///
/// true if the specified property is enabled; otherwise, false.
///
public bool IsEnabled(string property)
{
return !IsReadOnly;
}
}
}