|
@@ -7,11 +7,15 @@
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text.RegularExpressions;
|
|
|
+using System.Windows.Media;
|
|
|
using Autodesk.Revit.DB;
|
|
|
using Autodesk.Revit.DB.Mechanical;
|
|
|
using Autodesk.Revit.DB.Plumbing;
|
|
|
using SAGA.DotNetUtils.Data;
|
|
|
+using SAGA.GplotRelationComputerManage.ColdRoom;
|
|
|
using SAGA.Models;
|
|
|
+using SAGA.Models.GplotElement;
|
|
|
+using SAGA.Models.Graphs;
|
|
|
using SAGA.RevitUtils;
|
|
|
using SAGA.RevitUtils.Extends;
|
|
|
using SAGA.RevitUtils.MEP;
|
|
@@ -21,6 +25,7 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
public class FloorSystemItem
|
|
|
{
|
|
|
#region 构造函数
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 初始化解析类
|
|
|
/// </summary>
|
|
@@ -30,17 +35,23 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
Document = doc;
|
|
|
InitData();
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
+
|
|
|
#region 属性相关
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 关联模型信息
|
|
|
/// </summary>
|
|
|
public Document Document { get; private set; }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 使用关联标高
|
|
|
/// </summary>
|
|
|
public Level UseLevel { get; private set; }
|
|
|
+
|
|
|
private bool m_IsInited;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 初始化数据
|
|
|
/// </summary>
|
|
@@ -51,13 +62,16 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
UseLevel = Document.GetUseView()?.GenLevel;
|
|
|
m_IsInited = true;
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 开始节点获取
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 缓存信息
|
|
|
/// </summary>
|
|
|
private List<StringFlag<ElementTreeNode>> m_StartNodes;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 按系统获取开始节点
|
|
|
/// </summary>
|
|
@@ -67,11 +81,14 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
if (m_StartNodes != null)
|
|
|
{
|
|
|
//返回没有处理过的节点信息
|
|
|
- return m_StartNodes.Where(s=>!s.Handled).ToList();
|
|
|
+ return m_StartNodes.Where(s => !s.Handled).ToList();
|
|
|
}
|
|
|
+
|
|
|
List<StringFlag<ElementTreeNode>> startNodes = new List<StringFlag<ElementTreeNode>>();
|
|
|
var doc = Document;
|
|
|
+
|
|
|
#region 立管处理
|
|
|
+
|
|
|
/*
|
|
|
* 暂时认定,一个立管之关联一个系统
|
|
|
*/
|
|
@@ -94,7 +111,8 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
var specialValves = doc.FilterElements(filter).Where(f => SystemCalcUtil.IsStart(f));
|
|
|
foreach (var familyInstance in specialValves)
|
|
|
{
|
|
|
- var connector = familyInstance.GetAllConnectors().FirstOrDefault(c => Regex.IsMatch(c.Description, AppSetting.EndFlag));
|
|
|
+ var connector = familyInstance.GetAllConnectors()
|
|
|
+ .FirstOrDefault(c => Regex.IsMatch(c.Description, AppSetting.EndFlag));
|
|
|
if (connector == null)
|
|
|
continue;
|
|
|
var node = SystemParseManager.CreateTreeNode(familyInstance, connector, e => e is MEPCurve);
|
|
@@ -104,18 +122,22 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
var systemTypeName = useMepCurve.GetSystemTypeName();
|
|
|
startNodes.Add(new StringFlag<ElementTreeNode>(systemTypeName, node));
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
return m_StartNodes = startNodes;
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 设备节点获取
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 模型中包含的设备
|
|
|
/// </summary>
|
|
|
public Dictionary<string, List<FamilyInstance>> RevitEquipments { get; private set; }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 通过设备类型获取相关设备
|
|
|
/// </summary>
|
|
@@ -132,21 +154,25 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
var familyName = familyInstance.GetFamily().Name;
|
|
|
if (string.IsNullOrEmpty(familyName))
|
|
|
continue;
|
|
|
- var match=Regex.Match(familyName, @"^(?:((?:[A-Z][A-Z]){2,3})\s*-\s*\S*)");
|
|
|
+ var match = Regex.Match(familyName, @"^(?:((?:[A-Z][A-Z]){2,3})\s*-\s*\S*)");
|
|
|
if (match.Success)
|
|
|
{
|
|
|
original.Add(new StringFlag<FamilyInstance>(match.Groups[1].ToString(), familyInstance));
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
- RevitEquipments= original.GroupBy(f => f.Flag).ToDictionary(g=>g.Key,g=>g.ToList().Select(f=>f.Instance).ToList());
|
|
|
+
|
|
|
+ RevitEquipments = original.GroupBy(f => f.Flag)
|
|
|
+ .ToDictionary(g => g.Key, g => g.ToList().Select(f => f.Instance).ToList());
|
|
|
}
|
|
|
|
|
|
RevitEquipments.TryGetValue(category, out List<FamilyInstance> result);
|
|
|
- return result??new List<FamilyInstance>();
|
|
|
+ return result ?? new List<FamilyInstance>();
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 数据解析方法
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 解析当前楼层系统数据
|
|
|
/// </summary>
|
|
@@ -172,12 +198,15 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
}
|
|
|
|
|
|
#region 水系统解析
|
|
|
- public void ParsePipe(SystemComputerContext context,RelationTypeShell relationSetting)
|
|
|
+
|
|
|
+ public void ParsePipe(SystemComputerContext context, RelationTypeShell relationSetting)
|
|
|
{
|
|
|
Domain useDomain = Domain.DomainPiping;
|
|
|
List<FloorDrawRecord> drawRecords = new List<FloorDrawRecord>();
|
|
|
List<FloorRelationRecord> relationRecords = new List<FloorRelationRecord>();
|
|
|
+ List<Element> roomStartElements = new List<Element>();
|
|
|
#region 计算拓扑树形结构
|
|
|
+
|
|
|
/*
|
|
|
* 1、遍历开始点的限制:特殊阀门,指定标注的Connector;立管,已连接连接件;空间,相交风管元素;
|
|
|
* 2、根据拓扑图关联的对象信息,找到系统关联的设备生成节点。如果没有遍历到要独立生成
|
|
@@ -192,7 +221,10 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
var useRelation = relationSetting.GetFirstMatchSystem(startNode.Flag);
|
|
|
if (useRelation == null)
|
|
|
continue;
|
|
|
-
|
|
|
+ if (startNode.Instance.Current is FamilyInstance)
|
|
|
+ {
|
|
|
+ roomStartElements.Add(startNode.Instance.Current);
|
|
|
+ }
|
|
|
if (useIds.Any(id => id == startNode.Instance.Current.Id.IntegerValue))
|
|
|
{
|
|
|
continue;
|
|
@@ -202,7 +234,8 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
{
|
|
|
verticalMepCurves.Add(mepCurve);
|
|
|
}
|
|
|
- var tempIds=SystemParseManager.BuildSystemNode(startNode.Instance, useDomain,
|
|
|
+
|
|
|
+ var tempIds = SystemParseManager.BuildSystemNode(startNode.Instance, useDomain,
|
|
|
(m => !startNode.Flag.Equals(m.GetSystemTypeName())));
|
|
|
startNode.Instance.PipeSystemTypeName = startNode.Flag;
|
|
|
BuildElementNodeData(context, startNode.Instance);
|
|
@@ -210,7 +243,9 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
startNode.Handled = true;
|
|
|
|
|
|
//可以清空Leaves的子节点
|
|
|
+
|
|
|
#region 整理原始数据
|
|
|
+
|
|
|
//判断是否有设备节点,不进行数据处理
|
|
|
var useNode = startNode.Instance;
|
|
|
//var firstEquipment = useNode.FirstOrDefault(t => MBIInfoUtil.IsEquipment(t.Current));
|
|
@@ -225,20 +260,29 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
|
|
|
var relationRecord = BuildFloorRelationRecord(relationSetting, useNode);
|
|
|
relationRecords.Add(relationRecord);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ #region 解析机房数据
|
|
|
+
|
|
|
+ var useEquipments = ParseMachineRoomData(context, relationSetting, roomStartElements);
|
|
|
+ useEquipments=useEquipments.Distinct().ToList();
|
|
|
+ #endregion
|
|
|
+
|
|
|
//获取没有使用过的对象节点
|
|
|
List<FamilyInstance> singleInstances =
|
|
|
relationSetting.RelationItem.Objects.SelectMany(o => GetEquipments(o.Type)).ToList();
|
|
|
for (int i = 0; i < singleInstances.Count; i++)
|
|
|
{
|
|
|
- var useInstance = singleInstances[i];
|
|
|
- if (useIds.Any(id => id == useInstance.Id.IntegerValue))
|
|
|
+ var useInstance = singleInstances[i];
|
|
|
+ if (useIds.Any(id => id == useInstance.Id.IntegerValue)|| useEquipments.Any(id=>id==useInstance.Id.ToString()))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
var connectors = useInstance.GetAllConnectors();
|
|
|
foreach (var connector in connectors)
|
|
|
{
|
|
@@ -246,6 +290,7 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
var startNode = SystemParseManager.CreateTreeNode(useInstance, connector, e => e is MEPCurve);
|
|
|
var useMepCurve = startNode.GetLeaves().FirstOrDefault()?.Current as MEPCurve;
|
|
|
if (useMepCurve == null)
|
|
@@ -255,13 +300,16 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
+
|
|
|
//var startNode = new ElementTreeNode() { Current = useInstance };
|
|
|
var tempIds = SystemParseManager.BuildSystemNode(startNode, useDomain,
|
|
|
(m => !systemTypeName.Equals(m.GetSystemTypeName())));
|
|
|
startNode.PipeSystemTypeName = systemTypeName;
|
|
|
BuildElementNodeData(context, startNode);
|
|
|
useIds.AddRange(tempIds);
|
|
|
+
|
|
|
#region 生成绘图,计算数据
|
|
|
+
|
|
|
//解析数据,找管道定系统,管道找不到,系统名为"关联类型-未知"
|
|
|
var drawRecord = BuildFloorDrawRecord(relationSetting, startNode);
|
|
|
drawRecord.SystemName = systemTypeName;
|
|
@@ -269,6 +317,7 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
|
|
|
var relationRecord = BuildFloorRelationRecord(relationSetting, startNode);
|
|
|
relationRecords.Add(relationRecord);
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
@@ -277,21 +326,29 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
+
|
|
|
//增加立管数据
|
|
|
ComputerVerticalPipes(UseLevel, verticalMepCurves, context);
|
|
|
context.FloorDrawRecords.AddRange(drawRecords);
|
|
|
context.FloorRelationRecords.AddRange(relationRecords);
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 风系统解析
|
|
|
+
|
|
|
public void ParseDuct(SystemComputerContext context, RelationTypeShell relationSetting)
|
|
|
- { }
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 解析立管
|
|
|
+
|
|
|
/*
|
|
|
* 1、解析立管需要考虑,竖直风管,水管,空间的情况;
|
|
|
*2、将各层数据汇总,才能统一计算立管的相关关系数据
|
|
@@ -305,7 +362,7 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
foreach (var pipe in mepCurves)
|
|
|
{
|
|
|
if (pipe == null)
|
|
|
- continue;
|
|
|
+ continue;
|
|
|
var vp = new VerticalPipe
|
|
|
{
|
|
|
Id = pipe.Id.IntegerValue.ToString(),
|
|
@@ -315,16 +372,21 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
DownPoint3D = PointConverter.XYZToPoint3D(pipe.GetVerticalBottomPoint()),
|
|
|
PipeSytemType = pipe.GetSystemTypeName()
|
|
|
};
|
|
|
+
|
|
|
#region 获取立管关联空间
|
|
|
+
|
|
|
var locationCurve = pipe.GetLocationCurve();
|
|
|
var midPoint = (locationCurve.StartPoint() + locationCurve.EndPoint()) / 2;
|
|
|
- Space refSpace = spaces.FirstOrDefault(s => s.IsPointInSpace(midPoint));//关联
|
|
|
+ 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;
|
|
|
+ vp.DisplayTip = tip ?? string.Empty;
|
|
|
+
|
|
|
#endregion
|
|
|
+
|
|
|
result.Add(vp);
|
|
|
}
|
|
|
+
|
|
|
LevelData levelData = new LevelData()
|
|
|
{
|
|
|
Id = refLevel.Id.ToString(),
|
|
@@ -333,6 +395,7 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
context.VerticalPipes.AddRange(result);
|
|
|
context.Levels.Add(levelData);
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
|
|
@@ -342,25 +405,29 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
{
|
|
|
return relationShell.RelationItem?.Name + "---未知";
|
|
|
}
|
|
|
- private FloorDrawRecord BuildFloorDrawRecord(RelationTypeShell relationShell,ElementTreeNode node)
|
|
|
+
|
|
|
+ private FloorDrawRecord BuildFloorDrawRecord(RelationTypeShell relationShell, ElementTreeNode node)
|
|
|
{
|
|
|
var floorDraw = new FloorDrawRecord();
|
|
|
floorDraw.SetFloorLevel(UseLevel);
|
|
|
floorDraw.RelationType = relationShell.RelationItem.Type;
|
|
|
- floorDraw.DrawIems = SystemParseManager.CreateDrawing(node)??new SystemDrawItems();
|
|
|
+ floorDraw.DrawIems = SystemParseManager.CreateDrawing(node) ?? new SystemDrawItems();
|
|
|
return floorDraw;
|
|
|
}
|
|
|
+
|
|
|
private FloorRelationRecord BuildFloorRelationRecord(RelationTypeShell relationShell, ElementTreeNode node)
|
|
|
{
|
|
|
var floorRelation = new FloorRelationRecord();
|
|
|
floorRelation.SetFloorLevel(UseLevel);
|
|
|
floorRelation.RelationType = relationShell.RelationItem.Type;
|
|
|
- floorRelation.RelationItems = SystemParseManager.CreateRelation(node)??new List<BinaryRelationItem>();
|
|
|
+ floorRelation.RelationItems = SystemParseManager.CreateRelation(node) ?? new List<BinaryRelationItem>();
|
|
|
return floorRelation;
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 初始化名称,分类
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 初始化节点扩展数据
|
|
|
/// </summary>
|
|
@@ -373,16 +440,20 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
while (nodeQueue.Any())
|
|
|
{
|
|
|
#region 控制验证
|
|
|
+
|
|
|
var currentNode = nodeQueue.Dequeue();
|
|
|
if (currentNode == null)
|
|
|
continue;
|
|
|
var element = currentNode.Current;
|
|
|
if (element == null)
|
|
|
continue;
|
|
|
+
|
|
|
#endregion
|
|
|
+
|
|
|
if (element is FamilyInstance fiEq)
|
|
|
- {
|
|
|
+ {
|
|
|
#region 判断是否是设备
|
|
|
+
|
|
|
if (MBIInfoUtil.IsEquipment(fiEq))
|
|
|
{
|
|
|
var equipItem = context.EquipmentItems.GetItem(fiEq.GetBimId());
|
|
@@ -390,15 +461,17 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
if (equipItem != null)
|
|
|
{
|
|
|
data.Name = equipItem.GetDisplay();
|
|
|
- data.Category = equipItem.Category;
|
|
|
+ data.Category = equipItem.Category;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
data.Name = fiEq.GetFamily()?.Name;
|
|
|
}
|
|
|
+
|
|
|
data.SystemType = node.PipeSystemTypeName;
|
|
|
currentNode.Tag = data;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
}
|
|
|
else if (element is Space revitSpace)
|
|
@@ -413,33 +486,72 @@ namespace SAGA.GplotRelationComputerManage
|
|
|
{
|
|
|
data.Name = revitSpace.Name;
|
|
|
}
|
|
|
+
|
|
|
data.SystemType = node.PipeSystemTypeName;
|
|
|
currentNode.Tag = data;
|
|
|
}
|
|
|
+
|
|
|
currentNode.Nodes.ForEach(e => nodeQueue.Enqueue(e));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region 解析机房数据
|
|
|
- private void ParseMachineRoomData()
|
|
|
+ /// <summary>
|
|
|
+ /// 解析机房数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="context"></param>
|
|
|
+ /// <param name="relationSetting"></param>
|
|
|
+ /// <param name="startElements"></param>
|
|
|
+ private List<string> ParseMachineRoomData(SystemComputerContext context, RelationTypeShell relationSetting,
|
|
|
+ List<Element> startElements)
|
|
|
{
|
|
|
- //GplotOptions options = new GplotOptions();
|
|
|
- //options.BaseOnDefinition(Definition);
|
|
|
- //SystemParse parse = new SystemParse(new SystemParseSetting(options));
|
|
|
- //StartElementsManager startManager = new StartElementsManager(options);
|
|
|
- ////所有项目中所有文档
|
|
|
- //List<Element> startElements = new List<Element>();
|
|
|
- //startElements.AddRange(startManager.GetStartElements(Document));
|
|
|
- //var arrays = parse.Execute(startElements);
|
|
|
- ////arrays.ForEach(a => parse.LoadEquipmentItem(a));
|
|
|
- ////去除不包含真实设备的拓扑
|
|
|
- //arrays.RemoveAll(c => c.GetAvailableVertexes(null).All(v => !v.IsRealEquipment()));
|
|
|
-
|
|
|
- ////GplotParseData data = new GplotParseData();
|
|
|
- //data.OriginalData = arrays;
|
|
|
+ /*
|
|
|
+ *1、解析过程中尽量少处理和后续相关的数据
|
|
|
+ * 2、设备整理,带缓存的设备信息读取
|
|
|
+ */
|
|
|
+ List<string> useEquipments = new List<string>();
|
|
|
+ SystemParse parse = new SystemParse(new SystemParseSetting(relationSetting));
|
|
|
+ List<Element> useStartElements = new List<Element>(startElements);
|
|
|
+ var arrays = parse.Execute(useStartElements);
|
|
|
+ arrays.RemoveAll(c => c.GetAvailableVertexes(null).All(v => !v.IsRealEquipment()));
|
|
|
+
|
|
|
+ #region 生成图形数据
|
|
|
+ ColdRoomManager manager = new ColdRoomManager();
|
|
|
+ var doc = manager.CreateDocument(new List<ElementEdgesArray>(arrays));
|
|
|
+ var drawData = SystemParseManager.CreateRoomDrawing(doc);
|
|
|
+ MachineRoomDrawRecord record = new MachineRoomDrawRecord();
|
|
|
+ record.RelationName = relationSetting.RelationItem.Name;
|
|
|
+ record.DrawIems = drawData;
|
|
|
+ context.MachineRoomDrawRecords.Add(record);
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 生成关系数据
|
|
|
+ var relations = manager.CreateRelation(arrays);
|
|
|
+ MachineRoomRelationRecord relationRecord = new MachineRoomRelationRecord();
|
|
|
+ relationRecord.RelationName = relationSetting.RelationItem.Name;
|
|
|
+ foreach (var item in relations)
|
|
|
+ {
|
|
|
+ var node = new BinaryRelationItem();
|
|
|
+ node.From = new EquipmentNode() { RevitId = item.EquipmentItem1.Id };
|
|
|
+ node.To = new EquipmentNode() { RevitId = item.EquipmentItem2.Id };
|
|
|
+ node.RelationType = item.LinkType;
|
|
|
+ relationRecord.RelationItems.Add(node);
|
|
|
+
|
|
|
+
|
|
|
+ var newIds = new List<string>() {item.EquipmentItem1.Id, item.EquipmentItem2.Id};
|
|
|
+ useEquipments.AddRange(newIds);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ context.MachineRoomRelationRecords.Add(relationRecord);
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ return useEquipments;
|
|
|
+
|
|
|
}
|
|
|
- #endregion
|
|
|
+ #endregion 解析机房数据
|
|
|
}
|
|
|
}
|