添加项目文件。
This commit is contained in:
162
RevitKits/MetroGauges/LandXMLData/Region.cs
Normal file
162
RevitKits/MetroGauges/LandXMLData/Region.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using System.Xml.Serialization;
|
||||
using ShrlAlgoToolkit.RevitAddins.RvIndependent.MetroGauges.LandXMLData.Interfaces;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.RvIndependent.MetroGauges.LandXMLData
|
||||
{
|
||||
[XmlType("Region")]
|
||||
[Serializable]
|
||||
public class Region : GenerationRange, IComparableStructure<Region>
|
||||
{
|
||||
public Region()
|
||||
{
|
||||
Import = true;
|
||||
Parts = new List<Part>();
|
||||
}
|
||||
|
||||
[XmlIgnore]
|
||||
public string NamePart => Name + (Part != 0 ? " " + Part : string.Empty);
|
||||
|
||||
[XmlIgnore]
|
||||
public string NameRange => string.Concat(Name, ": ", StartStation.ToString(), " - ", EndStation.ToString());
|
||||
|
||||
[XmlIgnore]
|
||||
public string RegionId => string.Concat(RegionIdBase, " (", StartStation.ToString(), "-", EndStation.ToString(), ")");
|
||||
|
||||
[XmlIgnore]
|
||||
internal string RegionIdBase => (Alignment != null ? Alignment.AlignmentId : string.Empty) + AssemblyId;
|
||||
|
||||
[XmlIgnore]
|
||||
public Alignment Alignment { get; internal set; }
|
||||
|
||||
[XmlAttribute("import")]
|
||||
public bool Import { get; set; }
|
||||
|
||||
[XmlAttribute("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[XmlAttribute("part")]
|
||||
public int Part { get; set; }
|
||||
|
||||
[XmlElement("Part")]
|
||||
public List<Part> Parts { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public string AssemblyId { get; set; }
|
||||
|
||||
[XmlAttribute("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool DifferentDescendants(Region region)
|
||||
{
|
||||
if (Parts.Count == region.Parts.Count)
|
||||
{
|
||||
for (int i = 0; i < Parts.Count; i++)
|
||||
{
|
||||
if (!Parts[i].Equals(region.Parts[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DifferentItem(Region region)
|
||||
{
|
||||
return Import != region.Import
|
||||
|| StartStation != region.StartStation
|
||||
|| EndStation != region.EndStation
|
||||
|| GenerationStartStation != region.GenerationStartStation
|
||||
|| GenerationEndStation != region.GenerationEndStation;
|
||||
}
|
||||
|
||||
public bool Equals(Region region)
|
||||
{
|
||||
return !ReferenceEquals(region, null) && !DifferentItem(region) && !DifferentDescendants(region);
|
||||
}
|
||||
|
||||
public void AddPart(
|
||||
DesignShape designShape,
|
||||
PartType type,
|
||||
int fColor,
|
||||
int bColor,
|
||||
bool import = true,
|
||||
double start = double.NegativeInfinity,
|
||||
double end = double.PositiveInfinity
|
||||
)
|
||||
{
|
||||
Part part = Parts.FirstOrDefault(item => item.NameSideSegment == designShape.NameSideSegment);
|
||||
if (part == null)
|
||||
{
|
||||
Part part2 = new Part(designShape);
|
||||
part2.Type = type;
|
||||
part2.FillColorARGB = fColor;
|
||||
part2.BorderColorARGB = bColor;
|
||||
part2.Import = import;
|
||||
part2.Region = this;
|
||||
Part part3 = part2;
|
||||
int id;
|
||||
if (Parts.Count <= 0)
|
||||
{
|
||||
id = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
id = Parts.Max(item => item.Id) + 1;
|
||||
}
|
||||
|
||||
part3.Id = id;
|
||||
AddPart(part2, start, end);
|
||||
return;
|
||||
}
|
||||
|
||||
Range range = part.Ranges.Last();
|
||||
if (range.EndStation < end)
|
||||
{
|
||||
range.EndStation = end;
|
||||
}
|
||||
}
|
||||
|
||||
public void ConnectParts()
|
||||
{
|
||||
foreach (Part part in Parts)
|
||||
{
|
||||
part.Region = this;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as Region);
|
||||
}
|
||||
|
||||
public Part FindPart(Part reference)
|
||||
{
|
||||
return Parts.FirstOrDefault(item => item.NameSideSegment == reference.NameSideSegment);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
internal void AddPart(Part part, double start = double.NegativeInfinity, double end = double.PositiveInfinity)
|
||||
{
|
||||
if (part.Ranges == null)
|
||||
{
|
||||
part.Ranges = new List<Range>();
|
||||
}
|
||||
|
||||
Parts.Add(part);
|
||||
if (part.Ranges.Count == 0)
|
||||
{
|
||||
Range range = new Range { Parent = part };
|
||||
range.SetRange(Math.Max(start, StartStation), Math.Min(end, EndStation));
|
||||
part.AddRange(range);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user