|
@@ -11,70 +11,177 @@ using SAGA.RevitUtils.Extends;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Windows.Media.Media3D;
|
|
|
+using Autodesk.Revit.DB.Mechanical;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using SAGA.MBI.RequestData;
|
|
|
+using SAGA.RevitUtils;
|
|
|
+
|
|
|
namespace SAGA.GplotRelationComputerManage
|
|
|
{
|
|
|
- public class ComputerVerticalPipe
|
|
|
+ /// <summary>
|
|
|
+ /// 计算上下文
|
|
|
+ /// </summary>
|
|
|
+ public class PipeCalcContext
|
|
|
{
|
|
|
- public void Computer(Dictionary<Level, List<Pipe>> dicPipes)
|
|
|
+ public PipeCalcContext()
|
|
|
{
|
|
|
- List<VerticalPipe> pipes = new List<VerticalPipe>();
|
|
|
- foreach (var dicPipe in dicPipes)
|
|
|
+ VerticalPipes = new List<VerticalPipe>();
|
|
|
+ Levels = new List<LevelData>();
|
|
|
+ }
|
|
|
+ #region 空间缓存信息
|
|
|
+ /// <summary>
|
|
|
+ /// 缓存空间对象
|
|
|
+ /// </summary>
|
|
|
+ private Dictionary<string, RoomItem> m_Rooms = null;
|
|
|
+ /// <summary>
|
|
|
+ /// 获取根据指定bimId,获取空间信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="bimId"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public RoomItem GetRoomItem(string bimId)
|
|
|
+ {
|
|
|
+ if (m_Rooms == null)
|
|
|
{
|
|
|
- var vps = ConvertTo(dicPipe.Key,dicPipe.Value);
|
|
|
- pipes.AddRange(vps);
|
|
|
+ m_Rooms = new Dictionary<string, RoomItem>();
|
|
|
+ var str = new string[] { MBIBuiltInCategory.Si };//元空间为Si
|
|
|
+ List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
|
|
|
+ foreach (var data in datas)
|
|
|
+ {
|
|
|
+ var roomItem = MBIItemFactory.Create<RoomItem>(data);
|
|
|
+ m_Rooms[roomItem.BimId] = roomItem;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- var levels = dicPipes.Keys.ToList();
|
|
|
- levels.Sort((l1, l2) => l1.Elevation.CompareTo(l2.Elevation));
|
|
|
- var levelDatas = levels.Select(t => new LevelData()
|
|
|
- {
|
|
|
- Id = t.Id.ToString(),
|
|
|
- Name = t.Name.Replace("-saga",""),
|
|
|
- Elevation = t.Elevation
|
|
|
- }).ToList();
|
|
|
+ m_Rooms.TryGetValue(bimId, out RoomItem resultItem);
|
|
|
+ return resultItem;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- var datas = new VerticalPipeData()
|
|
|
+ #endregion
|
|
|
+ #region 空间缓存约束
|
|
|
+ public string GetSpaceDisplay(Space space)
|
|
|
+ {
|
|
|
+ if (space == null)
|
|
|
+ return string.Empty;
|
|
|
+ string bimId = space.GetBimId();
|
|
|
+ var room = GetRoomItem(bimId);
|
|
|
+ string useName = space.Name;
|
|
|
+ if (room != null&&!string.IsNullOrWhiteSpace(room.LocalName))
|
|
|
{
|
|
|
- Datas = pipes,
|
|
|
- Levels = levelDatas
|
|
|
- };
|
|
|
+ useName = room.LocalName;
|
|
|
+ }
|
|
|
|
|
|
- //保存数据到本地
|
|
|
- DrawDataServer.SaveAsFile(datas);
|
|
|
+ //此类缓存所有空间信息
|
|
|
+ //本地名称为null的话要使用Name
|
|
|
+ return useName;
|
|
|
+ }
|
|
|
+ public string GetSpaceDisplay(Space space,out string tip)
|
|
|
+ {
|
|
|
+ tip = string.Empty;
|
|
|
+ if (space == null)
|
|
|
+ return string.Empty;
|
|
|
+ string bimId = space.GetBimId();
|
|
|
+ var room = GetRoomItem(bimId);
|
|
|
+ string useName = space.Name;
|
|
|
+ tip =$"空间模型名称:BIMID编码";
|
|
|
+ if (room != null && !string.IsNullOrWhiteSpace(room.LocalName))
|
|
|
+ {
|
|
|
+ tip = $"空间本地名称:BIMID编码";
|
|
|
+ useName = room.LocalName;
|
|
|
+ }
|
|
|
+
|
|
|
+ //此类缓存所有空间信息
|
|
|
+ //本地名称为null的话要使用Name
|
|
|
+ return useName;
|
|
|
}
|
|
|
+ #endregion
|
|
|
|
|
|
- private List<VerticalPipe> ConvertTo(Level refLevel,List<Pipe> data)
|
|
|
+ public List<VerticalPipe> VerticalPipes { get; private set; }
|
|
|
+ public List<LevelData> Levels { get; private set; }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class ComputerVerticalPipe
|
|
|
+ {
|
|
|
+ public Document Document { get; private set; }
|
|
|
+ public ComputerVerticalPipe(Document document)
|
|
|
+ {
|
|
|
+ Document = document;
|
|
|
+ }
|
|
|
+ #region 修订函数
|
|
|
+ /// <summary>
|
|
|
+ /// 计算立管信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="refLevel"></param>
|
|
|
+ /// <param name="pipes"></param>
|
|
|
+ /// <param name="context"></param>
|
|
|
+ public void ComputerVerticalPipes(Level refLevel, List<Pipe> pipes, PipeCalcContext context)
|
|
|
{
|
|
|
var result = new List<VerticalPipe>();
|
|
|
-
|
|
|
- foreach (var pipe in data)
|
|
|
+ var spaces = Document.GetElements<SpatialElement>(BuiltInCategory.OST_MEPSpaces).OfType<Space>();
|
|
|
+ foreach (var pipe in pipes)
|
|
|
{
|
|
|
- var level =refLevel;
|
|
|
-
|
|
|
+ if (pipe == null)
|
|
|
+ continue;
|
|
|
+ var level = refLevel;
|
|
|
var vp = new VerticalPipe
|
|
|
{
|
|
|
- Id = pipe.Id.IntegerValue.ToString(),
|
|
|
- LevelName = level.Name.Replace("-saga",""),
|
|
|
+ Id=pipe.Id.IntegerValue.ToString(),
|
|
|
+ LevelName = level.Name.Replace("-saga", ""),
|
|
|
LevelElevation = level.Elevation,
|
|
|
UpPoint3D = Convert3DToWin(pipe.GetVerticalTopPoint()),
|
|
|
DownPoint3D = Convert3DToWin(pipe.GetVerticalBottomPoint()),
|
|
|
PipeSytemType = pipe.GetParameterString(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM)
|
|
|
};
|
|
|
+ //获取立管关联控件
|
|
|
+ var locationCurve = pipe.GetLocationCurve();
|
|
|
+ var midPoint = (locationCurve.StartPoint() + locationCurve.EndPoint()) / 2;
|
|
|
+ Space refSpace = spaces.FirstOrDefault(s => s.IsPointInSpace(midPoint));//关联
|
|
|
+ var display = context.GetSpaceDisplay(refSpace, out string tip);
|
|
|
+ vp.Display = $"{display}:{pipe.Id.IntegerValue.ToString()}";
|
|
|
+ vp.DisplayTip = tip ?? string.Empty;
|
|
|
result.Add(vp);
|
|
|
}
|
|
|
+ LevelData levelData = new LevelData()
|
|
|
+ {
|
|
|
+ Id = refLevel.Id.ToString(),
|
|
|
+ Name = refLevel.Name.Replace("-saga", ""),
|
|
|
+ Elevation = refLevel.Elevation
|
|
|
+ };
|
|
|
+ context.VerticalPipes.AddRange(result);
|
|
|
+ context.Levels.Add(levelData);
|
|
|
+ }
|
|
|
|
|
|
- return result;
|
|
|
+ /// <summary>
|
|
|
+ /// 计算整体信息
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="context"></param>
|
|
|
+ public static void Computer(PipeCalcContext context)
|
|
|
+ {
|
|
|
+ var verticalPipes = context.VerticalPipes;
|
|
|
+ if (verticalPipes == null)
|
|
|
+ return;
|
|
|
+ List<VerticalPipe> pipes = new List<VerticalPipe>(verticalPipes);
|
|
|
+ var levels = new List<LevelData>(context.Levels);
|
|
|
+ levels.Sort((l1, l2) => l1.Elevation.CompareTo(l2.Elevation));
|
|
|
+
|
|
|
+ var datas = new VerticalPipeData()
|
|
|
+ {
|
|
|
+ Datas = pipes,
|
|
|
+ Levels = levels
|
|
|
+ };
|
|
|
+ //保存数据到本地
|
|
|
+ DrawDataServer.SaveAsFile(datas);
|
|
|
}
|
|
|
+ #endregion
|
|
|
|
|
|
|
|
|
|
|
|
- Point3D Convert3DToWin(XYZ xyz)
|
|
|
+ private static Point3D Convert3DToWin(XYZ xyz)
|
|
|
{
|
|
|
return new Point3D(xyz.X, xyz.Y, xyz.Z);
|
|
|
}
|
|
|
|
|
|
- XYZ Convert3DToRevit(Point3D point)
|
|
|
+ private static XYZ Convert3DToRevit(Point3D point)
|
|
|
{
|
|
|
return new XYZ(point.X, point.Y, point.Z);
|
|
|
}
|