/* ============================================================================== * 功能描述:SagaCheck * 创 建 者:Garrett * 创建日期:2019/6/11 16:09:09 * ==============================================================================*/ using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Autodesk.Revit.DB; using SAGA.DotNetUtils.Extend; using ServiceRevitLib.Common; using SAGA.RevitUtils.Extends; using SAGA.RevitUtils.MEP; using ServiceRevitLib.Extend; using ServiceRevitLib.Utils; namespace ServiceRevitLib.Mode { /// /// SagaCheck /// class ConnectorCheck : CheckBase { public ConnectorCheck() { ReferenceSheet = "参考-连接件对照表"; } public override void Check() { base.Check(); #region bool unitResult = true; m_ProDefineConnectors = GetPreDefineConnectors(); var elements = m_Doc.GetEqEcElements(); foreach (var element in elements) { //检查设备或者部件 var result = GetCheckResult(element); if (result == null) continue; Content.Add(result); } #endregion } private string m_HaveConnectorSing = "√"; private List m_ProDefineConnectors; public List GetPreDefineConnectors() { var list = new List(); var alllist = DataCheckRule.GetPreDefineConnectors(); foreach (DCR_Connector connector in alllist) { var pipeType = connector.PipeConnector; var hvacType = connector.HvacConnector; if (pipeType == m_HaveConnectorSing || hvacType == m_HaveConnectorSing) { list.Add(connector); if (connector.PName.IsNotNullEmpty() && connector.PCode.IsNotNullEmpty()) { //部件单独提出来当做一项 var pconnector = new DCR_Connector() { Code = connector.PCode, Name = connector.Name, PipeConnector = connector.PipeConnector, HvacConnector = connector.HvacConnector }; list.Add(pconnector); } } } return list; } /// /// 获取检测结果 /// /// /// private ConnectorCheckResult GetCheckResult(Element element) { if (element == null) return null; var result = new ConnectorCheckResult(); var code = element.GetFamilyCode(); var defineConType = GetDefineConType(code); if (defineConType == null) return null; result.FamilyName = element.GetFamilyName(); result.Id = element.Id.ToString(); result.Result = ResultState.Success; CheckConType(result, element, defineConType.Item1); CheckConType(result, element, defineConType.Item2); return result; } /// /// 获取定义的风和水连接件类型 /// /// /// private Tuple GetDefineConType(string code) { var item = m_ProDefineConnectors.FirstOrDefault(t => t.Code == code); if (item == null) return null; var pipeType = item.PipeConnector; var hvacType = item.HvacConnector; var pipeConType = pipeType == m_HaveConnectorSing ? Domain.DomainPiping : Domain.DomainUndefined; var hvacConType = hvacType == m_HaveConnectorSing ? Domain.DomainHvac : Domain.DomainUndefined; return new Tuple(pipeConType, hvacConType); } /// /// 检查连接件类型是否存在 /// /// /// private void CheckConType(ConnectorCheckResult result, Element fi, Domain domain) { if (domain != Domain.DomainUndefined) { var connectors = fi.GetConnectors(domain); var domainStr = DomainToString(domain); if (connectors.Any()) { if (connectors.All(t => t.IsConnected)) return; result.Result = ResultState.Failure; result.ResultMsg += $"发现 {domainStr}连接件未连接;"; } else { result.Result = ResultState.Failure; result.ResultMsg += $"缺少 {domainStr} 连接件;"; } } } private string DomainToString(Domain domain) { string str = ""; switch (domain) { case Domain.DomainPiping: str = "水管"; break; case Domain.DomainHvac: str = "风管"; break; default: str = "未知"; break; } return str; } } }