123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- /* ==============================================================================
- * 功能描述:SagaCheck
- * 创 建 者:Garrett
- * 创建日期:2019/6/11 16:09:09
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Autodesk.Revit.DB;
- using SAGA.DotNetUtils.Extend;
- using SAGA.RevitUtils.MEP;
- using ServiceRevitLib.Extend;
- using ServiceRevitLib.Mode;
- using ServiceRevitLib.Utils;
- namespace ServiceRevitLib.DataCheck.Mode
- {
- /// <summary>
- /// SagaCheck
- /// </summary>
- class ConnectorCheck : CheckBase
- {
- public ConnectorCheck()
- {
- ReferenceSheet = "参考-连接件对照表";
- }
- public override void Check()
- {
- try
- {
- 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
- }
- catch (Exception e)
- {
- Result = ResultState.Failure;
- ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
- }
- }
-
- private string m_HaveConnectorSing = "√";
- private List<DCR_Connector> m_ProDefineConnectors;
- public List<DCR_Connector> GetPreDefineConnectors()
- {
- var list = new List<DCR_Connector>();
- 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;
- }
- /// <summary>
- /// 获取检测结果
- /// </summary>
- /// <param name="fi"></param>
- /// <returns></returns>
- 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;
- var type= code.Length == 4 ? ElementRangeCheck.DCElementType.Equipment : ElementRangeCheck.DCElementType.EuipmentPart;
- result.Type = type.GetDescription();
- 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;
- }
- /// <summary>
- /// 获取定义的风和水连接件类型
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- private Tuple<Domain, Domain> 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<Domain, Domain>(pipeConType, hvacConType);
- }
- /// <summary>
- /// 检查连接件类型是否存在
- /// </summary>
- /// <param name="result"></param>
- /// <param name="domain"></param>
- 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;
- }
- }
- }
|