using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SAGA.RevitUtils.Extends;
using SAGA.RevitUtils.MEP;
using SAGA.RevitUtils;
using SAGA.MBI.Tools;
using System.Text.RegularExpressions;
namespace SAGA.GplotRelationComputerManage
{
///
/// 系统导出设置
///
public class SystemParseSetting
{
public SystemParseSetting(GplotOptions options)
{
//GplotOptions = options;
//var relationType = RelationTypeManager.GetRelationTypeItem(options.);
}
public SystemParseSetting(RelationTypeShell relationShell)
{
RelationTypeShell = relationShell;
Domain = relationShell.IsPipeSystem() ? Domain.DomainPiping : Domain.DomainHvac;
}
/////
///// 图相关设置
/////
//public GplotOptions GplotOptions { get; set; }
///
/// 关系类型相关
///
public RelationTypeShell RelationTypeShell { get;private set; }
///
/// 使用域枚举
///
public Domain Domain { get;private set; }
#region 设置相关信息
/*
* 1、确定边界:
* 哪些确定成点标记,哪些确定成边标记【用以处理非点标记甄别】
* 2、确定遇到什么情况断开
*
* 3、确定那些事旁通边
*/
#endregion
///
/// 判断是否是节点标记
///
///
///
public bool IsForkNode(Element element)
{
Domain domain = Domain;
var connectors = element.GetConnectors(domain);
return connectors.Count > 2;
}
public List GetJoinItems(Element element,List usedIds)
{
List joinItems = new List();
Domain domain = Domain;
var connectors = element.GetConnectors(domain);
foreach (var connector in connectors)
{
if (connector.IsLogical())
continue;
if (!(element is MEPCurve||connector.IsConnected))
{
continue;
}
if (IgnoreConnector(connector))
continue;
if (!connector.IsConnected)
{
joinItems.Add(new JoinItem(connector,null));
}
else
{
foreach (Connector refConnector in connector.AllRefs)
{
if (refConnector.IsLogical() || refConnector.Owner.Id == element.Id || usedIds.Any(id => refConnector.Owner.Id.IntegerValue == id))
continue;
if (IgnoreConnector(refConnector))
continue;
joinItems.Add(new JoinItem(connector, refConnector));
}
}
}
return joinItems;
}
///
/// 标识元素是否是设备
///
///
///
public bool IsEquipment(Element element)
{
if (!(element is FamilyInstance fi))
{
return false;
}
return MBIInfoUtil.IsEquipment(element);
}
///
/// 无用边,节点可连通
///
///
///
public bool UselessEdge(ElementsEdge edge)
{
//如果该边的断点含有空点,则证明是虚拟设备
if (edge.RealStart.IsEmpty() || edge.RealEnd.IsEmpty())
return false;
if (edge.RealStart.GetDisableCombine() || edge.RealEnd.GetDisableCombine())
return false;
if (edge.RealStart.RefData.Any(e => !e.IsWaterComponment()) ||
edge.RealEnd.RefData.Any(e => !e.IsWaterComponment()))
return false;
return edge.RefData.All(e => e.IsWaterComponment());
}
///
/// 忽略的连接关系
///
///
///
public bool IgnoreConnector(Connector connector)
{
bool result = false;
do
{
Element owner = connector.Owner;
#region 通用判断
if (owner is MEPCurve mepCurve)
{
string typeName = mepCurve.GetSystemTypeName();
result = !RelationTypeShell.IsMatchSystem(typeName);
break;
}
if (SystemCalcUtil.IsStartValve(owner))
{
result = Regex.IsMatch(connector.Description, AppSetting.EndFlag);// connector.Description != GplotOptions.ValveConnectorDescription;
break;
}
#endregion
if (!owner.IsWaterComponment())
{
var mepCurves= owner.GetFirstElements(connector);
if (mepCurves.Any())
{
string typeName = (mepCurves[0] as MEPCurve).GetSystemTypeName();
result = !RelationTypeShell.IsMatchSystem(typeName);// !GplotOptions.MatchSystemType(typeName);
}
break;
}
} while (false);
return result;
}
#region 制定特殊阀门判断
///
/// 判断制定元素是否是特定阀门
///
///
///
public bool IsSpecialValve(Element element)
{
if(element is FamilyInstance fi)
{
var name = fi.GetFamily().Name;
return Regex.IsMatch(name, AppSetting.FamilyStartFlag);
}
return false;
}
#endregion
}
}