namespace HStation.Service
{
///
/// 连接列表拓展
///
public static class RevitConnectListExtensions
{
///
/// 获取中心位置
///
public static Model.RevitPosition GetCenterPosition(this List list)
{
if (list == null || list.Count < 1)
{
return default;
}
var pts = list.Select(x => x.Position).ToList();
return pts.GetCenter();
}
///
/// 获取开始连接
///
public static Model.RevitConnect GetStartConnect(this List list)
{
if (list == null || list.Count < 1)
{
return default;
}
var start = list.FirstOrDefault(x => !string.IsNullOrEmpty(x.Id) && x.Direction == Direction.Inlet);
if (start == null)
{
start = list.FirstOrDefault(x => !string.IsNullOrEmpty(x.Id) && x.Direction == Direction.None);
}
return start;
}
///
/// 获取结束连接
///
public static Model.RevitConnect GetEndConnect(this List list)
{
if (list == null || list.Count < 1)
{
return default;
}
var end = list.FirstOrDefault(x => !string.IsNullOrEmpty(x.Id) && x.Direction == Direction.Outlet);
if (end == null)
{
end = list.LastOrDefault(x => !string.IsNullOrEmpty(x.Id) && x.Direction == Direction.None);
}
return end;
}
///
/// 获取开始连接列表
///
public static List GetStartConnects(this List list)
{
if (list == null || list.Count < 1)
{
return new List();
}
var starts = list.Where(x => x.Direction == Direction.Inlet).ToList();
return starts;
}
///
/// 获取结束连接列表
///
public static List GetEndConnects(this List list)
{
if (list == null || list.Count < 1)
{
return new List();
}
var ends = list.Where(x => x.Direction == Direction.Outlet).ToList();
return ends;
}
///
/// 获取无方向连接列表
///
public static List GetNoneConnects(this List list)
{
if (list == null || list.Count < 1)
{
return new List();
}
var nones = list.Where(x => x.Direction == Direction.None).ToList();
return nones;
}
}
}