188 lines
5.6 KiB
C#
188 lines
5.6 KiB
C#
using System.Xml.Serialization;
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.RvIndependent.MetroGauges.LandXMLData;
|
|
|
|
[XmlType("CrossSect")]
|
|
[Serializable]
|
|
public class CrossSection : Point3D
|
|
{
|
|
public CrossSection()
|
|
{
|
|
DesignShapes = new List<DesignShape>();
|
|
Surfaces = new List<SectionSurface>();
|
|
Import = true;
|
|
}
|
|
|
|
[XmlIgnore]
|
|
public IEnumerable<string> PointCodes
|
|
{
|
|
get { return DesignShapes.SelectMany(item => item.PointCodes); }
|
|
}
|
|
|
|
[XmlIgnore]
|
|
public IEnumerable<string> SurfaceNames => (from item in DesignShapes select item.Name).Distinct();
|
|
|
|
[XmlAttribute("import")]
|
|
public bool Import { get; set; }
|
|
|
|
[XmlAttribute("sta")]
|
|
public double Station { get; set; }
|
|
|
|
[XmlAttribute("we")]
|
|
public double WayElevation { get; set; }
|
|
|
|
[XmlAttribute("ge")]
|
|
public double GroundElevation { get; set; }
|
|
|
|
[XmlAttribute("r")]
|
|
public int Region { get; set; }
|
|
|
|
[XmlElement("DesignCrossSectSurf")]
|
|
public List<DesignShape> DesignShapes { get; set; }
|
|
|
|
[XmlElement("CrossSectSurf")]
|
|
public List<SectionSurface> Surfaces { get; set; }
|
|
|
|
[XmlAttribute("AssemblyID")]
|
|
public string AssemblyID { get; set; }
|
|
|
|
[XmlAttribute("name")]
|
|
public string Name { get; set; }
|
|
|
|
public void ConnectShapes()
|
|
{
|
|
foreach (var designShape in DesignShapes)
|
|
{
|
|
designShape.CrossSection = this;
|
|
}
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
var crossSection = obj as CrossSection;
|
|
return !(crossSection == null) && ValuesEqual(this, crossSection);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
public CrossSectionPoint GetLeftPoint()
|
|
{
|
|
return GetPointAtOffset(DesignShapes.Min(item => item.CrossSectionPoints.Min(point => point.First)));
|
|
}
|
|
|
|
public CrossSectionPoint GetPointAtOffset(double offset)
|
|
{
|
|
CrossSectionPoint crossSectionPoint = null;
|
|
foreach (var designShape in DesignShapes)
|
|
{
|
|
crossSectionPoint = designShape.CrossSectionPoints.Find(item => item.First == offset);
|
|
if (crossSectionPoint != null)
|
|
{
|
|
return crossSectionPoint;
|
|
}
|
|
}
|
|
|
|
return crossSectionPoint;
|
|
}
|
|
|
|
public CrossSectionPoint GetPointByName(string pointCode, bool onLeft)
|
|
{
|
|
CrossSectionPoint crossSectionPoint = null;
|
|
var side = onLeft ? Side.Left : Side.Right;
|
|
foreach (var designShape in from item in DesignShapes where item.Side == side select item)
|
|
{
|
|
crossSectionPoint = designShape.CrossSectionPoints.Find(item => item.Code == pointCode);
|
|
if (crossSectionPoint != null)
|
|
{
|
|
return crossSectionPoint;
|
|
}
|
|
}
|
|
|
|
foreach (var designShape2 in from item in DesignShapes where item.Side == Side.Both select item)
|
|
{
|
|
crossSectionPoint = onLeft
|
|
? designShape2.CrossSectionPoints.Find(item => item.Code == pointCode && item.First <= 0.0)
|
|
: designShape2.CrossSectionPoints.Find(item => item.Code == pointCode && item.First >= 0.0);
|
|
|
|
if (crossSectionPoint != null)
|
|
{
|
|
return crossSectionPoint;
|
|
}
|
|
}
|
|
|
|
return crossSectionPoint;
|
|
}
|
|
|
|
public CrossSectionPoint GetPointByNames(IList<string> pointCodes, bool onLeft)
|
|
{
|
|
CrossSectionPoint crossSectionPoint = null;
|
|
for (var i = 0; i < pointCodes.Count; i++)
|
|
{
|
|
var text = pointCodes[i];
|
|
crossSectionPoint = GetPointByName(text, onLeft);
|
|
if (crossSectionPoint != null)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
pointCodes.RemoveAt(i);
|
|
pointCodes.Insert(0, text);
|
|
}
|
|
|
|
return crossSectionPoint;
|
|
}
|
|
}
|
|
|
|
return crossSectionPoint;
|
|
}
|
|
|
|
public IEnumerable<string> GetPointCodes(Side side)
|
|
{
|
|
if (side == Side.Both)
|
|
{
|
|
return PointCodes.Distinct();
|
|
}
|
|
|
|
var list = (from item in DesignShapes where item.Side == side select item).SelectMany(item => item.PointCodes).Distinct().ToList();
|
|
list.AddRange((from item in DesignShapes where item.Side == Side.Both select item).SelectMany(item => item.GetPointCodes(side)).Distinct());
|
|
return list.Distinct();
|
|
}
|
|
|
|
public CrossSectionPoint GetRightPoint()
|
|
{
|
|
return GetPointAtOffset(DesignShapes.Max(item => item.CrossSectionPoints.Max(point => point.First)));
|
|
}
|
|
|
|
public static bool operator ==(CrossSection p1, CrossSection p2)
|
|
{
|
|
var flag = LamdXMLEx.ReferenceComparison(p1, p2);
|
|
return flag != null ? flag.Value : ValuesEqual(p1, p2);
|
|
}
|
|
|
|
public static bool operator !=(CrossSection p1, CrossSection p2)
|
|
{
|
|
var flag = LamdXMLEx.ReferenceComparison(p1, p2);
|
|
return !(flag == null ? ValuesEqual(p1, p2) : flag.Value);
|
|
}
|
|
|
|
public void Transform(GeometryTransformations transformations)
|
|
{
|
|
foreach (var designShape in DesignShapes)
|
|
{
|
|
designShape.Transform(transformations);
|
|
}
|
|
|
|
Station *= transformations.ScaleFactor;
|
|
GroundElevation = (GroundElevation * transformations.ScaleFactor) + transformations.Dz;
|
|
WayElevation = (WayElevation * transformations.ScaleFactor) + transformations.Dz;
|
|
transformations.Transform(this);
|
|
}
|
|
|
|
public static bool ValuesEqual(CrossSection p1, CrossSection p2)
|
|
{
|
|
return p1.Region == p2.Region && p1.Name == p2.Name && Point3D.ValuesEqual(p1, p2);
|
|
}
|
|
}
|