NavisworksTransport/src/PathPlanning/GridCellBuilder.cs

138 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Autodesk.Navisworks.Api;
namespace NavisworksTransport.PathPlanning
{
/// <summary>
/// GridCell工厂类提供常用GridCell类型的便捷创建方法
/// 避免手动设置大量属性,减少错误,提高代码可读性
/// </summary>
public static class GridCellBuilder
{
/// <summary>
/// 创建通道类型的GridCell
/// </summary>
/// <param name="worldPosition">世界坐标位置</param>
/// <param name="channel">关联的通道ModelItem</param>
/// <param name="speedLimit">预计算的限速值</param>
/// <param name="cost">遍历成本0表示使用默认值</param>
/// <returns>配置完整的通道GridCell</returns>
public static GridCell Channel(Point3D worldPosition, ModelItem channel, double speedLimit, double cost = 0)
{
return new GridCell
{
CellType = "通道",
IsInChannel = true,
ChannelType = ChannelType.Corridor,
RelatedModelItem = channel,
SpeedLimit = speedLimit,
HeightLayers = new System.Collections.Generic.List<HeightLayer>(),
Cost = cost // 会在PlaceCell时由ApplyCellValidationRules处理
};
}
/// <summary>
/// 创建门类型的GridCell
/// </summary>
/// <param name="worldPosition">世界坐标位置</param>
/// <param name="door">关联的门ModelItem</param>
/// <param name="speedLimit">预计算的限速值</param>
/// <param name="cost">遍历成本0表示使用默认值</param>
/// <returns>配置完整的门GridCell</returns>
public static GridCell Door(Point3D worldPosition, ModelItem door, double speedLimit, double cost = 0)
{
return new GridCell
{
CellType = "门",
IsInChannel = false,
ChannelType = ChannelType.Other,
RelatedModelItem = door,
SpeedLimit = speedLimit,
HeightLayers = new System.Collections.Generic.List<HeightLayer>(),
Cost = cost
};
}
/// <summary>
/// 创建障碍物类型的GridCell
/// </summary>
/// <param name="worldPosition">世界坐标位置</param>
/// <param name="obstacle">关联的障碍物ModelItem</param>
/// <returns>配置完整的障碍物GridCell</returns>
public static GridCell Obstacle(Point3D worldPosition, ModelItem obstacle)
{
return new GridCell
{
CellType = "障碍物",
IsInChannel = false,
ChannelType = ChannelType.Other,
RelatedModelItem = obstacle,
SpeedLimit = 0,
HeightLayers = new System.Collections.Generic.List<HeightLayer>(),
Cost = double.MaxValue // 障碍物成本最大
};
}
/// <summary>
/// 创建电梯类型的GridCell
/// </summary>
/// <param name="worldPosition">世界坐标位置</param>
/// <param name="elevator">关联的电梯ModelItem</param>
/// <param name="speedLimit">预计算的限速值</param>
/// <param name="cost">遍历成本0表示使用默认值</param>
/// <returns>配置完整的电梯GridCell</returns>
public static GridCell Elevator(Point3D worldPosition, ModelItem elevator, double speedLimit, double cost = 0)
{
return new GridCell
{
CellType = "电梯",
IsInChannel = false,
ChannelType = ChannelType.Other,
RelatedModelItem = elevator,
SpeedLimit = speedLimit,
HeightLayers = new System.Collections.Generic.List<HeightLayer>(),
Cost = cost
};
}
/// <summary>
/// 创建楼梯类型的GridCell
/// </summary>
/// <param name="worldPosition">世界坐标位置</param>
/// <param name="stairs">关联的楼梯ModelItem</param>
/// <param name="speedLimit">预计算的限速值</param>
/// <param name="cost">遍历成本0表示使用默认值</param>
/// <returns>配置完整的楼梯GridCell</returns>
public static GridCell Stairs(Point3D worldPosition, ModelItem stairs, double speedLimit, double cost = 0)
{
return new GridCell
{
CellType = "楼梯",
IsInChannel = false,
ChannelType = ChannelType.Other,
RelatedModelItem = stairs,
SpeedLimit = speedLimit,
HeightLayers = new System.Collections.Generic.List<HeightLayer>(),
Cost = cost
};
}
/// <summary>
/// 创建空白/未知类型的GridCell
/// </summary>
/// <param name="worldPosition">世界坐标位置</param>
/// <returns>配置完整的空白GridCell</returns>
public static GridCell Empty(Point3D worldPosition)
{
return new GridCell
{
CellType = "空洞",
IsInChannel = false,
ChannelType = ChannelType.Other,
RelatedModelItem = null,
SpeedLimit = 0,
HeightLayers = new System.Collections.Generic.List<HeightLayer>(),
Cost = double.MaxValue
};
}
}
}