using System; using System.ComponentModel; using System.Xml.Serialization; using Deltares.Geometry; using Deltares.Geotechnics; using Deltares.Geotechnics.Soils; 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 { [Serializable] [TypeConverter(typeof(ExpandableObjectConverter))] public class TreeOnSlope : GeometryObject, IVisibleEnabled { private readonly GeometryPoint treeOnSlopePoint; private double angleOfDistribution; private StabilityModel stabilityModel; private double widthOfRootZone; private double windForce; public TreeOnSlope() { windForce = 0.0; widthOfRootZone = 5; angleOfDistribution = 0.0; treeOnSlopePoint = new GeometryPoint(); } [Browsable(false)] public GeometryPoint TreeOnSlopePoint { get { return treeOnSlopePoint; } } [Unit(UnitType.Force)] [Minimum(-100000)] [Maximum(100000)] [PropertyOrder(0)] [Label("Wind force")] [Format("F3")] public double WindForce { get { return windForce; } set { if (value != windForce) { DataEventPublisher.BeforeChange(this, "WindForce"); windForce = value; DataEventPublisher.AfterChange(this, "WindForce"); } } } [Unit(UnitType.Length)] [Minimum(0.2)] [Maximum(1000)] [PropertyOrder(3)] [Label("Width of root zone")] [Format("F3")] public double WidthOfRootZone { get { return widthOfRootZone; } set { if (value != widthOfRootZone) { DataEventPublisher.BeforeChange(this, "WidthOfRootZone"); widthOfRootZone = value; DataEventPublisher.AfterChange(this, "WidthOfRootZone"); } } } [Unit(UnitType.Angle)] [Minimum(-90)] [Maximum(90)] [PropertyOrder(4)] [Label("Angle of distribution")] [Format("F3")] public double AngleOfDistribution { get { return angleOfDistribution; } set { if (value != angleOfDistribution) { DataEventPublisher.BeforeChange(this, "AngleOfDistribution"); angleOfDistribution = value; DataEventPublisher.AfterChange(this, "AngleOfDistribution"); } } } [Unit(UnitType.Length)] [Minimum(-1.000e+06)] [Maximum(1.000e+06)] [PropertyOrder(1)] [Label("X")] [Description("X Coordinate")] [Format("F3")] public double X { get { return treeOnSlopePoint.X; } set { if (value != treeOnSlopePoint.X) { DataEventPublisher.BeforeChange(this, "X"); treeOnSlopePoint.X = value; DataEventPublisher.Changed(this); } } } [Unit(UnitType.Length)] [Minimum(-1.000e+06)] [Maximum(1.000e+06)] [PropertyOrder(5)] [Label("Y")] [Format("F3")] [Browsable(false)] public double Y { get { return treeOnSlopePoint.Y; } set { if (value != treeOnSlopePoint.Y) { DataEventPublisher.BeforeChange(this, "Y"); treeOnSlopePoint.Y = value; DataEventPublisher.Changed(this); } } } [Browsable(true)] [AmbientValue(5)] [Unit(UnitType.Length)] [Minimum(-1000000)] [Maximum(1000000)] [PropertyOrder(2)] [Label("Z")] [Format("F3")] public double Z { get { return treeOnSlopePoint.Z; } set { if (value != treeOnSlopePoint.Z) { DataEventPublisher.BeforeChange(this, "Z"); treeOnSlopePoint.Z = value; DataEventPublisher.Changed(this); } } } [XmlIgnore] [Browsable(false)] public StabilityModel StabilityModel { get { return stabilityModel; } set { stabilityModel = value; } } public override GeometryBounds GetGeometryBounds() { // Using width of root zone for determining crown size. This is not correct, but leads to sufficient behaviour for the moment. double crownSize = WidthOfRootZone/2; return new GeometryBounds(treeOnSlopePoint.X - crownSize, treeOnSlopePoint.X + crownSize, treeOnSlopePoint.Z - crownSize, treeOnSlopePoint.Z + crownSize); } public override bool ContainsPoint(Point3D point, double tolerance) { return Routines2D.DoesPointExistInLine(new Point2D(X, Z), new Point2D(X, Z), point.GetPointXZ(), tolerance); } #region IVisibleEnabled Members public bool IsEnabled(string property) { return true; } public bool IsVisible(string property) { switch (property) { case "Name": return false; case "WindForce": return StabilityModel.ModelOption == ModelOptions.Bishop || StabilityModel.ModelOption == ModelOptions.Fellenius; default: return StabilityModel.ModelOption == ModelOptions.Bishop || StabilityModel.ModelOption == ModelOptions.Fellenius; } } #endregion } }