整理代码
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
using ShrlAlgo.RvKits.RvIndependent.MetroGauges.LandXMLData.Interfaces;
|
||||
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace ShrlAlgo.RvKits.RvIndependent.MetroGauges.LandXMLData
|
||||
{
|
||||
[XmlType("Part")]
|
||||
[Serializable]
|
||||
public class Part : ObjectWithNameSideSegment, IGenerationRangeInstance, IGenerationRange, IInstance, IComparableStructure<Part>
|
||||
{
|
||||
public Part()
|
||||
{
|
||||
Ranges = new List<Range>();
|
||||
_instance = -1;
|
||||
}
|
||||
|
||||
public Part(ObjectWithNameSideSegment reference)
|
||||
: base(reference)
|
||||
{
|
||||
Ranges = new List<Range>();
|
||||
}
|
||||
|
||||
protected int _instance;
|
||||
|
||||
[XmlIgnore]
|
||||
public string FullName => Type + " - " + NameSideSegment;
|
||||
|
||||
[XmlIgnore]
|
||||
public double GenerationLength => GenerationEndStation - GenerationStartStation;
|
||||
|
||||
[XmlIgnore]
|
||||
public double Length => EndStation - StartStation;
|
||||
|
||||
[XmlIgnore]
|
||||
public string PartId => (Region != null ? Region.RegionId : string.Empty) + " " + Id;
|
||||
|
||||
[XmlIgnore]
|
||||
public IEnumerable<DesignShape> Shapes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Region == null)
|
||||
{
|
||||
return new DesignShape[0];
|
||||
}
|
||||
|
||||
if (Region.Alignment == null)
|
||||
{
|
||||
return new DesignShape[0];
|
||||
}
|
||||
|
||||
return from section in Region.Alignment.CrossSections
|
||||
where section.Region == Region.Id
|
||||
select section.DesignShapes.FirstOrDefault(shape => shape.NameSideSegment == NameSideSegment) into shape
|
||||
where shape != null
|
||||
select shape;
|
||||
}
|
||||
}
|
||||
|
||||
[XmlAttribute("import")]
|
||||
public bool Import { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public int Id { get; set; }
|
||||
|
||||
[XmlAttribute("bARGB")]
|
||||
public int BorderColorARGB { get; set; }
|
||||
|
||||
[XmlAttribute("fARGB")]
|
||||
public int FillColorARGB { get; set; }
|
||||
|
||||
[XmlElement("Range")]
|
||||
public List<Range> Ranges { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public PartType Type { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public Region Region { get; internal set; }
|
||||
|
||||
public bool DifferentDescendants(Part part)
|
||||
{
|
||||
if (Ranges.Count == part.Ranges.Count)
|
||||
{
|
||||
for (int i = 0; i < Ranges.Count; i++)
|
||||
{
|
||||
if (!Ranges[i].Equals(part.Ranges[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DifferentItem(Part part)
|
||||
{
|
||||
return Import != part.Import
|
||||
|| StartStation != part.StartStation
|
||||
|| EndStation != part.EndStation
|
||||
|| GenerationStartStation != part.GenerationStartStation
|
||||
|| GenerationEndStation != part.GenerationEndStation;
|
||||
}
|
||||
|
||||
public bool Equals(Part part)
|
||||
{
|
||||
return !ReferenceEquals(part, null) && !DifferentItem(part) && !DifferentDescendants(part);
|
||||
}
|
||||
|
||||
[XmlAttribute("end")]
|
||||
public double EndStation { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public double GenerationEndStation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Ranges != null && Ranges.Count > 0)
|
||||
{
|
||||
return Ranges.Last().GenerationEndStation;
|
||||
}
|
||||
|
||||
return double.NaN;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Ranges != null && Ranges.Count > 0)
|
||||
{
|
||||
Ranges.Last().GenerationEndStation = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public double GenerationStartStation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Ranges != null && Ranges.Count > 0)
|
||||
{
|
||||
return Ranges.First().GenerationStartStation;
|
||||
}
|
||||
|
||||
return double.NaN;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (Ranges != null && Ranges.Count > 0)
|
||||
{
|
||||
Ranges.First().GenerationStartStation = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Tuple<double, double> GetGenerationScopeIntersection(IGenerationRange parent)
|
||||
{
|
||||
return new Tuple<double, double>(
|
||||
Math.Max(parent.GenerationStartStation, GenerationStartStation),
|
||||
Math.Min(parent.GenerationEndStation, GenerationEndStation)
|
||||
);
|
||||
}
|
||||
|
||||
[XmlAttribute("start")]
|
||||
public double StartStation { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public int Instance
|
||||
{
|
||||
get => _instance;
|
||||
set => _instance = value;
|
||||
}
|
||||
|
||||
public void AddRange(Range range)
|
||||
{
|
||||
if (range != null)
|
||||
{
|
||||
if (Ranges.Count == 1 && Ranges.First().GenerationStartStation == StartStation && Ranges.Last().GenerationEndStation == EndStation)
|
||||
{
|
||||
Ranges.Clear();
|
||||
}
|
||||
|
||||
Ranges.Add(range);
|
||||
if (range.Part == 0 && (GenerationStartStation != range.GenerationStartStation || GenerationEndStation != range.GenerationEndStation))
|
||||
{
|
||||
range.Part = Ranges.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ConnectRange()
|
||||
{
|
||||
foreach (Range range in Ranges)
|
||||
{
|
||||
range.Parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as Part);
|
||||
}
|
||||
|
||||
public Range FindRange(Range reference)
|
||||
{
|
||||
return Ranges.FirstOrDefault(item => item.NameSideSegmentPart == reference.NameSideSegmentPart);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user