/* ==============================================================================
* 功能描述:拓扑计算系统名称检查
* 创 建 者:Garrett
* 创建日期:2018/10/23 15:08:55
* ==============================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using NPOI.SS.UserModel;
using SAGA.DotNetUtils.Extend;
using SAGA.DotNetUtils.Others;
using SAGA.RevitUtils.MEP;
namespace Saga.PlugIn.ModelCheck
{
///
/// UnitCheck
///
[ParseIndex(Index = 8)]
class SystemCheck : ModeCheckBase
{
public SystemCheck()
{
Name = "系统类型名称检查";
RSPecificationSheet.Add("参考-可识别的系统名称");
}
public override bool Check()
{
if (!RBase.IsRight)
{
IsRight = RBase.IsRight;
return IsRight;
}
IsRight = GetCheckResult();
return IsRight;
}
private bool GetCheckResult()
{
bool unitResult = true;
m_MEPSystems = DataCheckRule.GetMepSystems();
foreach (SagaSignCheckResult signResult in RBase.Results)
{
var list = Check(signResult);
Results.AddRange(list);
}
return Results.All(t => t.IsRight);
}
private List m_MEPSystems;
///
/// 获取本楼层的检查结果
///
///
///
private List Check(SagaSignCheckResult signResult)
{
List list = new List();
var mepsystemTypes = new List();
mepsystemTypes.AddRange(signResult.RDocument.GetMechanicalSystemTypes());
mepsystemTypes.AddRange(signResult.RDocument.GetPipingSystemTypes());
mepsystemTypes.ForEach(t=>
{
var result = GetCheckResult(t);
result.RBase = signResult;
list.Add(result);
});
return list;
}
///
/// 获取检测结果
///
///
///
private ModeCheckResultBase GetCheckResult(MEPSystemType system)
{
var result = new SystemCheckResult();
string systemName = system.Name;
result.RSystemName = systemName;
result.Type = system is MechanicalSystemType ? "风管系统" : "管道系统";
result.IsRight = true;
var item = m_MEPSystems.Where(t => SystemNameIsEqual(systemName,t.Name));
if (!item.Any())
{
result.IsRight = false;
result.RMessage = $"未知的系统名称,请按照系统类型命名规范修改";
}
return result;
}
///
/// 系统名称相等
///
///
///
///
private bool SystemNameIsEqual(string originName,string targetName)
{
bool result = false;
string n1 = originName.ToLower();
string n2 = targetName.ToLower();
return n1.Equals(n2);
}
public override void Export()
{
try
{
IWorkbook book = DCRExport.GetWorkbook();
//ISheet sheet = book.CreateSheet(Name);
ISheet sheet = book.GetSheet(Name);
#region 添加数据
int index = 3;
foreach (SystemCheckResult result in Results)
{
SagaSignCheckResult rbase = result.RBase as SagaSignCheckResult;
if (rbase == null)
continue;
index++;
IRow rowN = sheet.CreateRow(index);
DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
int j = -1;
rowN.AddCell(++j, result.RSystemName, style);
rowN.AddCell(++j, result.Type, style);
string rowN4 = result.IsRight ? "通过" : "不通过";
rowN.AddCell(++j, rowN4, style);
rowN.AddCell(++j, result.RMessage, style);
}
#endregion
}
catch (Exception e)
{
MessageShowBase.Show(e);
}
}
}
class SystemCheckResult : ModeCheckResultBase
{
public string RSystemName { get; set; }
public string Type { get; set; }
}
}