Browse Source

mxg:添加 管网及相关设备检查

mengxiangge 6 years ago
parent
commit
fd5a63262b

+ 2 - 2
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -298,8 +298,8 @@
     <Compile Include="ToolsData\DataCheck\WinDataCheckSetting.xaml.cs">
       <DependentUpon>WinDataCheckSetting.xaml</DependentUpon>
     </Compile>
-    <Compile Include="ToolsData\ModeCheck\EquipmentLocationCenterComparer.cs" />
-    <Compile Include="ToolsData\ModeCheck\EquipmentLocationCenterComparerResult.cs" />
+    <Compile Include="ToolsData\ModeCheck\EquipReferSystemCheck.cs" />
+    <Compile Include="ToolsData\ModeCheck\EquipReferSystemCheckResult.cs" />
     <Compile Include="ToolsData\ModeCheck\ModeCheckBase.cs" />
     <Compile Include="ToolsData\ModeCheck\DataCheckRule.cs" />
     <Compile Include="ToolsData\CheckBase\DCElementType.cs" />

+ 69 - 3
MBI/SAGA.MBI/ToolsData/ModeCheck/DataCheckRule.cs

@@ -8,7 +8,9 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
+using SAGA.DotNetUtils;
 using SAGA.DotNetUtils.NPOI;
 using SAGA.MBI.Common;
 using SAGA.Models;
@@ -52,6 +54,22 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                 .ConvertExcelSheetToModel<DCR_MEPSystem>(DCRExport.MCRPath);
             return list;
         }
+        /// <summary>
+        /// 获取设备关联的系统类型
+        /// </summary>
+        /// <returns></returns>
+        public static List<DCR_EquipReferSystem> GetEquipReferSystems()
+        {
+            var list = NPOIHelper
+                .ConvertExcelSheetToModel<DCR_SystemReferEquip>(DCRExport.MCRPath);
+            List<Tuple<string, string>> tuples = new List<Tuple<string, string>>();
+            //将集合转化为:系统名称-设备名称
+            list.ForEach(t => t.Equips.ForEach(tt => tuples.Add(new Tuple<string, string>(t.SystemName, tt))));
+            //将集合转化为:设备名称-多个系统名称
+            var newList = tuples.GroupBy(t => t.Item2).Select(tt => new DCR_EquipReferSystem()
+            { EquipName = tt.Key, Systems = tt.Select(t => t.Item1).ToList() }).ToList();
+            return newList;
+        }
     }
     /// <summary>
     /// 参考-可识别的系统名称
@@ -61,9 +79,6 @@ namespace SAGA.MBI.ToolsData.ModeCheck
     {
         [CellIndex(0)]
         public string Name { get; set; }
-
-        [CellIndex(1)]
-        public string Discription { get; set; }
     }
     /// <summary>
     /// 参考-revit分类
@@ -98,4 +113,55 @@ namespace SAGA.MBI.ToolsData.ModeCheck
         [CellIndex(9)]
         public string PipeConnector { get; set; }
     }
+    /// <summary>
+    /// 参考-管网与相关设备
+    /// </summary>
+    [SheetInfo(SheetName = "参考-管网与相关设备", RowStartIndex = 1)]
+    public class DCR_SystemReferEquip
+    {
+        [CellIndex(4)]
+        public string SystemName { get; set; }
+        [CellIndex(5)]
+        public string ReferEquipName { get; set; }
+
+        private List<string> m_Equips;
+
+        public List<string> Equips
+        {
+            get
+            {
+                if (m_Equips == null)
+                    m_Equips = ConverToList(ReferEquipName);
+                return m_Equips;
+            }
+        }
+
+        public List<string> ConverToList(string str)
+        {
+            var list = new List<string>();
+            if (str.IsNotNullEmpty())
+            {
+                Regex regex = new Regex(@"^[A-Z]{4}");
+                list = str.Split(new[] { ',', ',' })
+                    .Where(t => Regex.IsMatch(t, @"^[A-Z]{4}\s*-\s*\S*"))
+                    .Select(tt => regex.Match(tt).Value).ToList();
+            }
+
+            return list;
+        }
+    }
+    /// <summary>
+    /// 设备关联的系统
+    /// </summary>
+    public class DCR_EquipReferSystem
+    {
+        /// <summary>
+        /// 设备名称
+        /// </summary>
+        public string EquipName { get; set; }
+        /// <summary>
+        /// 系统名称
+        /// </summary>
+        public List<string> Systems { get; set; }
+    }
 }

+ 228 - 0
MBI/SAGA.MBI/ToolsData/ModeCheck/EquipReferSystemCheck.cs

@@ -0,0 +1,228 @@
+/* ==============================================================================
+ * 功能描述:管网及相关设备检查检查
+ * 创 建 者:Garrett
+ * 创建日期:2018/10/23 15:08:55
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using NPOI.SS.UserModel;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Extend;
+using SAGA.DotNetUtils.Logger;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
+using SAGA.MBI.Tools;
+using SAGA.MBI.ToolsData.CheckBase;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
+
+namespace SAGA.MBI.ToolsData.ModeCheck
+{
+    /// <summary>
+    /// UnitCheck
+    /// </summary>
+    class EquipReferSystemCheck : ModeCheckBase
+    {
+        public EquipReferSystemCheck()
+        {
+            Name = "管网及相关设备检查";
+            RSPecificationSheet.Add("参考-官网及相关设备");
+        }
+        [DataCheckProcessAspect]
+        public override bool Check()
+        {
+            if (!RBase.IsRight)
+            {
+                IsRight = RBase.IsRight;
+                return IsRight;
+            }
+            IsRight = GetCheckResult();
+            return IsRight;
+        }
+
+        public override void Correct()
+        {
+            throw new NotImplementedException();
+        }
+
+        private List<DCR_EquipReferSystem> m_EquipReferSystems;
+        private bool GetCheckResult()
+        {
+            bool unitResult = true;
+            m_EquipReferSystems = DataCheckRule.GetEquipReferSystems();
+            foreach (SagaSignCheckResult signResult in RBase.Results)
+            {
+                var list = Check(signResult);
+                Results.AddRange(list);
+            }
+            return Results.All(t => t.IsRight);
+
+        }
+        /// <summary>
+        /// 获取所有的设备或者部件
+        /// </summary>
+        /// <param name="document"></param>
+        /// <returns></returns>
+        private List<ModeCheckResultBase> Check(SagaSignCheckResult signResult)
+        {
+            List<ModeCheckResultBase> list = new List<ModeCheckResultBase>();
+            var familyInstances = signResult.RDocument.GetFamilyInstances();
+
+            foreach (FamilyInstance fi in familyInstances)
+            {
+                if (fi.IsEquipment() || fi.IsEquipmentPart())
+                {
+                    var result = GetCheckResult(fi);
+                    if (result == null) continue;
+                    result.RBase = signResult;
+                    list.Add(result);
+                }
+            }
+            return list;
+        }
+
+        /// <summary>
+        /// 获取检测结果
+        /// </summary>
+        /// <param name="fi"></param>
+        /// <returns></returns>
+        private ModeCheckResultBase GetCheckResult(FamilyInstance fi)
+        {
+            var result = new EquipReferSystemCheckResult();
+            var code = fi.GetFamilyCode();
+            var referSystems = GetReferSystems(code);
+            if (referSystems.Count == 0) return null;
+
+            result.FamilyName = fi.GetFamily().Name;
+            result.Type = code.Length == 4 ? DCElementType.Equipment : DCElementType.EuipmentPart;
+            result.Id = fi.Id.ToString();
+
+            var tuple = CheckConType(fi, referSystems);
+            result.IsRight = !tuple.Item2.Any();
+            if (!result.IsRight)
+            {
+                result.RMessage = $"设备与管道系统类型不匹配;";
+                if (tuple.Item1.Any())
+                {
+                    result.RMessage += "匹配的系统类型有";
+                    result.RMessage += string.Join(",", tuple.Item1.ToArray());
+                }
+
+                result.RMessage += "不匹配的有:";
+                result.RMessage+= string.Join(",", tuple.Item2.ToArray());
+            }
+            return result;
+        }
+        /// <summary>
+        /// 可以与设备连接的系统
+        /// </summary>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        private List<string> GetReferSystems(string code)
+        {
+            var item = m_EquipReferSystems.First(t => t.EquipName == code)?.Systems ?? new List<string>();
+
+            return item;
+        }
+
+        /// <summary>
+        /// 检查连接件连接的管道系统是否符合规范
+        /// </summary>
+        /// <param name="result"></param>
+        /// <param name="domain"></param>
+        private Tuple<List<string>,List<string>> CheckConType(FamilyInstance fi, List<string> referSystems)
+        {
+            List<string> passList=new List<string>();
+            List<string> unpassList=new List<string>();
+
+            var connectors = fi.GetAllConnectors();
+            foreach (Connector connector in connectors)
+            {
+                try
+                {
+                    var mepSystem = connector.MEPSystem;
+                    if (mepSystem == null) continue;
+                    var elementId = mepSystem.GetTypeId();
+                    var type = fi.Document.GetElement(elementId);
+                    if (referSystems.Contains(type.Name))
+                    {
+                        passList.Add(mepSystem.Name);
+                    }
+                    else
+                    {
+                        unpassList.Add(mepSystem.Name);
+                    }
+                }
+                catch (Exception e)
+                {
+                   Log4Net.Info($"读取连接件系统错误。Id:{fi.Id},Path:{fi.Document.PathName}");
+                }
+            }
+
+            return new Tuple<List<string>, List<string>>(passList, unpassList);
+        }
+        
+
+
+        //[DataCheckProcessAspect]
+        public override void Export()
+        {
+            //   Check();
+            try
+            {
+                IWorkbook book = DCRExport.GetWorkbook();
+                //ISheet sheet = book.CreateSheet(Name);
+                ISheet sheet = book.GetSheet(Name);
+
+                #region 添加数据
+                int index = 3;
+                //添加 共检查XXX条数据,未通过检查的如下 提示
+                IRow rowTip = sheet.CreateRow(index - 1);
+                rowTip.AddCell(0, $"总检查{Results.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
+                //IRow row4 = sheet.CreateRow(index);
+                //row4.HeightInPoints = 15;
+
+                //row4.AddCell(0, "楼层本地名称", DataCheckNPOIStyle.Title);
+                //row4.AddCell(1, "文件名", DataCheckNPOIStyle.Title);
+                //row4.AddCell(2, "文件地址", DataCheckNPOIStyle.Title);
+                //row4.AddCell(3, "族名称", DataCheckNPOIStyle.Title);
+                //row4.AddCell(4, "类型", DataCheckNPOIStyle.Title);
+                //row4.AddCell(5, "ID", DataCheckNPOIStyle.Title);
+                //row4.AddCell(6, "通过", DataCheckNPOIStyle.Title);
+                //row4.AddCell(7, "备注(失败原因)", DataCheckNPOIStyle.Title);
+                foreach (EquipReferSystemCheckResult result in Results)
+                {
+                    SagaSignCheckResult rbase = result.RBase as SagaSignCheckResult;
+                    if (rbase == null)
+                        continue;
+                    //数量多过,只显示有问题的
+                    if (result.IsRight) continue;
+                    index++;
+                    IRow rowN = sheet.CreateRow(index);
+                    DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
+
+                    rowN.AddCell(0, rbase.RFloorName, style);
+                    rowN.AddCell(1, rbase.RFileName, style);
+                    rowN.AddCell(2, rbase.RPath, style);
+                    rowN.AddCell(3, result.FamilyName, style);
+                    rowN.AddCell(4, result.Type.GetDescription(), style);
+                    rowN.AddCell(5, result.Id, style);
+                    string rowN4 = result.IsRight ? "通过" : "不通过";
+                    rowN.AddCell(6, rowN4, style);
+                    rowN.AddCell(7, result.RMessage, style);
+                }
+                #endregion
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+    }
+}

+ 5 - 3
MBI/SAGA.MBI/ToolsData/ModeCheck/EquipmentLocationCenterComparerResult.cs

@@ -1,5 +1,5 @@
 /* ==============================================================================
- * 功能描述:设备部件定位点和中心点对比检查
+ * 功能描述:管网及相关设备检查检查结果
  * 创 建 者:Garrett
  * 创建日期:2018/10/23 15:13:17
  * ==============================================================================*/
@@ -9,17 +9,19 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB;
+using SAGA.MBI.ToolsData.CheckBase;
 
 namespace SAGA.MBI.ToolsData.ModeCheck
 {
     /// <summary>
     /// UnitCheckResult
     /// </summary>
-    class EquipmentLocationCenterComparerResult : ModeCheckResultBase
+    class EquipReferSystemCheckResult : ModeCheckResultBase
     {
-
         public string FamilyName { get; set; }
 
+        public DCElementType Type { get; set; }
+
         public string Id { get; set; }
         public override void Export()
         {

+ 0 - 145
MBI/SAGA.MBI/ToolsData/ModeCheck/EquipmentLocationCenterComparer.cs

@@ -1,145 +0,0 @@
-/* ==============================================================================
- * 功能描述:设备部件定位点和中心点对比检查
- * 创 建 者:Garrett
- * 创建日期:2018/10/23 15:08:55
- * ==============================================================================*/
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Autodesk.Revit.DB;
-using NPOI.SS.UserModel;
-using SAGA.DotNetUtils.Others;
-using SAGA.MBI.DataArrange;
-using SAGA.MBI.Tools;
-using SAGA.MBI.ToolsData.CheckBase;
-using SAGA.RevitUtils.Extends;
-
-namespace SAGA.MBI.ToolsData.ModeCheck
-{
-    /// <summary>
-    /// UnitCheck
-    /// </summary>
-    class EquipmentLocationCenterComparer : ModeCheckBase
-    {
-        public EquipmentLocationCenterComparer()
-        {
-            Name = "设备定位点检查";
-        }
-        [DataCheckProcessAspect]
-        public override bool Check()
-        {
-            if (!RBase.IsRight)
-            {
-                IsRight = RBase.IsRight;
-                return IsRight;
-            }
-            IsRight = GetCheckResult();
-            return IsRight;
-          
-        }
-
-        public override void Correct()
-        {
-            throw new NotImplementedException();
-        }
-
-        private bool GetCheckResult()
-        {
-            bool unitResult = true;
-            foreach (SagaSignCheckResult signResult in RBase.Results)
-            {
-                var document = signResult.RDocument;
-                var elements = document.GetFamilyInstances();
-                var equips = elements.Where(t =>  t.IsEquipmentPart()||t.IsEquipment());
-                foreach (FamilyInstance fi in equips)
-                {
-                    var result = GetCheckResult(fi);
-                    result.RBase = signResult;
-                    Results.Add(result);
-                }
-            }
-            return Results.All(t => t.IsRight);
-        }
-
-        /// <summary>
-        /// 获取检测结果
-        /// </summary>
-        /// <param name="fi"></param>
-        /// <returns></returns>
-        private ModeCheckResultBase GetCheckResult(FamilyInstance fi)
-        {
-            var result = new EquipmentPartRefEqCheckResult();
-            result.FamilyName = fi.GetFamily().Name;
-            result.Id = fi.Id.ToString();
-            XYZ location = fi.GetLocationPoint();
-            XYZ origin = fi.GetBoxCenter();
-            if (location.IsEqual2(origin))
-            {
-                result.IsRight = true;
-            }
-            else
-            {
-                result.IsRight = false;
-                result.RMessage = "定位点和中心点不重合,请检查";
-            }
-            result.LocationXYZ = location.ToString2D();
-            result.CenterXYZ = origin.ToString2D();
-            return result;
-        }
-        //[DataCheckProcessAspect]
-        public override void Export()
-        {
-            //   Check();
-            try
-            {
-                IWorkbook book = DCRExport.GetWorkbook();
-                //ISheet sheet = book.CreateSheet(Name);
-                ISheet sheet = book.GetSheet(Name);
-
-                #region 添加数据
-                int index = 3;
-                //IRow row4 = sheet.CreateRow(index);
-                //row4.HeightInPoints = 15;
-
-                //row4.AddCell(0, "楼层本地名称", DataCheckNPOIStyle.Title);
-                //row4.AddCell(1, "文件名", DataCheckNPOIStyle.Title);
-                //row4.AddCell(2, "文件地址", DataCheckNPOIStyle.Title);
-                //row4.AddCell(3, "族名称", DataCheckNPOIStyle.Title);
-                //row4.AddCell(4, "ID", DataCheckNPOIStyle.Title);
-                //row4.AddCell(4, "定位点", DataCheckNPOIStyle.Title);
-                //row4.AddCell(4, "中心点", DataCheckNPOIStyle.Title);
-                //row4.AddCell(5, "通过", DataCheckNPOIStyle.Title);
-                //row4.AddCell(6, "备注(失败原因)", DataCheckNPOIStyle.Title);
-                foreach (EquipmentPartRefEqCheckResult 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 i = 0;
-                    rowN.AddCell(i++, rbase.RFloorName, style);
-                    rowN.AddCell(i++, rbase.RFileName, style);
-                    rowN.AddCell(i++, rbase.RPath, style);
-                    rowN.AddCell(i++, result.FamilyName, style);
-                    rowN.AddCell(i++, result.Id, style);
-                    rowN.AddCell(i++, result.LocationXYZ, style);
-                    rowN.AddCell(i++, result.CenterXYZ, style);
-                    string rowN4 = result.IsRight ? "通过" : "不通过";
-                    rowN.AddCell(i++, rowN4, style);
-                    rowN.AddCell(i++, result.RMessage, style);
-                }
-
-                #endregion
-
-            }
-            catch (Exception e)
-            {
-                MessageShowBase.Show(e);
-            }
-        }
-    }
-}