using System;
using System.ComponentModel;
using System.Xml.Serialization;
using Deltares.Mathematics;
using Deltares.Standard;
using Deltares.Standard.Attributes;
using Deltares.Standard.Units;
namespace Deltares.Stability
{
public class SlidingDualCircle : SlidingCurve
{
private Point2D activeCircle = new Point2D();
private double activeForce0;
private bool hasWig = false;
private Point2D passiveCircle = new Point2D();
private double tangentLine = 0;
private bool leftCircleIsActive = true;
private int leftNumber = -1;
private int rightNumber = -1;
public SlidingDualCircle() {}
// Active Force Uniterated
[Format("F2")]
[Unit(UnitType.Force)]
public double ActiveForce0 { get; set; }
// Passive Force Uniterated
[Format("F2")]
[Unit(UnitType.Force)]
public double PassiveForce0 { get; set; }
// Horizontal Force Uniterated
[Format("F2")]
[Unit(UnitType.Force)]
public double HorizontalForce0 { get; set; }
// Active Force
[Format("F2")]
[Unit(UnitType.Force)]
public double ActiveForce { get; set; }
// Passive Force
[Format("F2")]
[Unit(UnitType.Force)]
public double PassiveForce { get; set; }
// Horizontal Force
[Format("F2")]
[Unit(UnitType.Force)]
public double HorizontalForce { get; set; }
// Active driving moment
[Format("F2")]
[Unit(UnitType.Moment)]
public double DrivingMomentActive { get; set; }
// Active resisting moment
[Format("F2")]
[Unit(UnitType.Moment)]
public double ResistingMomentActive { get; set; }
// Passive driving moment
[Format("F2")]
[Unit(UnitType.Moment)]
public double DrivingMomentPassive { get; set; }
// Passive resisting moment
[Format("F2")]
[Unit(UnitType.Moment)]
public double ResistingMomentPassive { get; set; }
// Active circle center x-coord
[Format("F2")]
[Unit(UnitType.Length)]
public double ActiveCircleCenterX
{
get
{
return activeCircle.X;
}
}
// Active circle center y-coord
[Format("F2")]
[Unit(UnitType.Length)]
public double ActiveCircleCenterY
{
get
{
return activeCircle.Y;
}
}
// Active circle radius
[Format("F2")]
[Unit(UnitType.Length)]
public double ActiveRadius { get; set; }
// Passive circle center x-coord
[Format("F2")]
[Unit(UnitType.Length)]
public double PassiveCircleCenterX
{
get
{
return passiveCircle.X;
}
}
// Passive circle center y-coord
[Format("F2")]
[Unit(UnitType.Length)]
public double PassiveCircleCenterY
{
get
{
return passiveCircle.Y;
}
}
// Passive circle radius
[Format("F2")]
[Unit(UnitType.Length)]
public double PassiveRadius { get; set; }
public Point2D ActiveCircle
{
get
{
return activeCircle;
}
set
{
activeCircle = value;
}
}
public Point2D PassiveCircle
{
get
{
return passiveCircle;
}
set
{
passiveCircle = value;
}
}
public double TangentLine
{
get
{
return tangentLine;
}
set
{
tangentLine = value;
}
}
public bool HasWig
{
get
{
return hasWig;
}
set
{
hasWig = value;
}
}
[XmlIgnore]
[ReadOnly(true)]
public override string Name
{
get
{
return string.Format("({0:F3}, {1:F3}) / {2:F3} / ({3:F3}, {4:F3})", this.ActiveCircleCenterX, this.ActiveCircleCenterY, this.ActiveCircleCenterY - this.ActiveRadius, this.PassiveCircleCenterX, this.PassiveCircleCenterY);
}
set
{
base.Name = value;
}
}
[Browsable(false)]
public bool LeftCircleIsActive
{
get
{
return leftCircleIsActive;
}
set
{
leftCircleIsActive = value;
}
}
///
/// Slice index where horizontal part starts (the first horizontal part is the slice at LeftNumber + 1)
///
public int LeftNumber
{
get
{
if (leftNumber == -1)
{
UpdateHorizontalPart();
}
return leftNumber;
}
}
///
/// Slice index where horizontal part ends (the last horizontal part is the slice at RightNumber - 1)
///
public int RightNumber
{
get
{
if (rightNumber == -1)
{
UpdateHorizontalPart();
}
return rightNumber;
}
}
private void UpdateHorizontalPart()
{
double xPassiveCentre = PassiveCircle.X;
double xActiveCentre = ActiveCircle.X;
double xMidLeft;
double xMidRight;
if ((xActiveCentre < xPassiveCentre + Constants.CAlmostZero))
{
xMidLeft = xActiveCentre;
xMidRight = xPassiveCentre;
}
else
{
xMidLeft = xPassiveCentre;
xMidRight = xActiveCentre;
}
// Find the last and first slicenumbers of the cirkels
// het rechte stuk loopt dus van leftnumber + 1 tot rightnumber - 1
leftNumber = 0;
rightNumber = Slices.Count - 1;
for (int i = 0; i < Slices.Count; i++)
{
if ((Math.Abs(xMidLeft - Slices[i].TopRight.X) < Constants.CSameSliceDist))
{
leftNumber = i;
}
if ((Math.Abs(xMidRight - Slices[i].TopLeft.X) < Constants.CSameSliceDist))
{
rightNumber = i;
}
}
}
}
}