소스 검색

Merge branch 'master' of http://dev.dp.sagacloud.cn:8886/r/Revit/SAGA.MBI

xulisong 6 년 전
부모
커밋
14e84d6816

BIN
MBI/MBIResource/DataCheck/垃圾数据检查结果输出-模版.xlsx


BIN
MBI/MBIResource/DataCheck/数据检查规范.xlsx


+ 0 - 14
MBI/SAGA.MBI/Common/MBIControl.cs

@@ -73,20 +73,6 @@ namespace SAGA.MBI.Common
                 return m_ProjectTree;
             }
         }
-        private  ObservableCollection<TreeNodeItem> m_ProjectTreeItems = null;
-
-        public  ObservableCollection<TreeNodeItem> ProjectTreeItems
-        {
-            get
-            {
-                if (m_ProjectTreeItems == null)
-                {
-                    m_ProjectTreeItems = new ObservableCollection<TreeNodeItem>() { ProjectTree };
-
-                }
-                return m_ProjectTreeItems;
-            }
-        }
 
 
 

+ 9 - 0
MBI/SAGA.MBI/DataArrange/DalCommon.cs

@@ -449,6 +449,15 @@ namespace SAGA.MBI.DataArrange
             }
             return rbase;
         }
+        /// <summary>
+        /// 缓存所有Revit数据,除了信标
+        /// </summary>
+        /// <param name="buildingId"></param>
+        /// <returns></returns>
+        public static List<MRevitEquipBase> GetAllDutys(string buildingId)
+        {
+            return CommonConvert.CacheAllData(buildingId); 
+        }
 
         /// <summary>
         /// 由BimID查询CloudID

+ 3 - 1
MBI/SAGA.MBI/Extend/MRevitEquipBaseExtend.cs

@@ -55,7 +55,9 @@ namespace SAGA.MBI.Extend
                 var rltmode = CommonConvert.QueryObjectById(dutyid);
                 if (!rltmode.IsNullOrDefaultEquip())
                 {
-                    rltmode.HasUpload = false;
+                    //之前要求没有上传模型的岗位信息只能看不能编辑,现在改为都可以编辑
+                    //rltmode.HasUpload = false;
+                    rltmode.HasUpload = true;
                     rltmode.BimID = mode?.BimID;
                     return rltmode;
                 }

+ 4 - 0
MBI/SAGA.MBI/RevitReference/RVTNoModeDutyOperate.cs

@@ -67,6 +67,10 @@ namespace SAGA.MBI.RevitReference
                                     afterAction?.Invoke(fi);
                                 }
                             }
+                            else
+                            {
+                                MessageShowBase.Infomation("自动创建只能创建基于点的族,请查看族类型");
+                            }
 
                         }
                         catch (Exception e)

+ 3 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -279,10 +279,13 @@
     <Compile Include="ToolsData\CheckBase\ICheckBase.cs" />
     <Compile Include="ToolsData\CheckDocumentData.cs" />
     <Compile Include="ToolsData\AddEquipLocation.cs" />
+    <Compile Include="ToolsData\CheckDuplicationBIMId.cs" />
     <Compile Include="ToolsData\DataCheck\DataCheckBase.cs" />
     <Compile Include="ToolsData\CheckBase\CheckContext.cs" />
     <Compile Include="ToolsData\DataCheck\DataCheckResultBase.cs" />
+    <Compile Include="ToolsData\DataCheck\BIMDuplicationCheck.cs" />
     <Compile Include="ToolsData\DataCheck\MissDutyOrModeCheck.cs" />
+    <Compile Include="ToolsData\DataCheck\BIMDuplicationCheckResult.cs" />
     <Compile Include="ToolsData\DataCheck\MissDutyOrModeCheckResult.cs" />
     <Compile Include="ToolsData\DataCheck\QRCodeContextCheck.cs" />
     <Compile Include="ToolsData\DataCheck\DutyFMInfoCheck.cs" />

+ 33 - 0
MBI/SAGA.MBI/ToolCommand.cs

@@ -66,6 +66,39 @@ namespace SAGA.MBI
             return true;
         }
     }
+    /// <summary>
+    /// 检查BimID是否重复,多个岗位对应一个模型
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class CheckDuplicationBIMIdCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                var tip = MessageShow.Question("确定要执行设备BIMID重复性检查?\r\n未在空间中的岗位将会被导出的excel中。");
+                if (tip)
+                    CheckDuplicationBIMId.CheckAll();
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+
+
+        /// <summary>
+        /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
+        /// when a document is open.
+        /// </summary>
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+    }
 
     /// <summary>
     /// 修正云平台族类型和本地族类型不一致

+ 1 - 0
MBI/SAGA.MBI/ToolsData/CheckBase/CheckOperation.cs

@@ -78,6 +78,7 @@ namespace SAGA.MBI.ToolsData.CheckBase
             list.Add(new DutyFMInfoCheck());
             list.Add(new QRCodeContextCheck());
             list.Add(new MissDutyOrMode());
+            list.Add(new BIMDuplicationCheck());
             list.ForEach(t =>
             {
                 t.RIsChecked = true;

+ 154 - 0
MBI/SAGA.MBI/ToolsData/CheckDuplicationBIMId.cs

@@ -0,0 +1,154 @@
+/* ==============================================================================
+ * 功能描述:检查BimID是否重复,多个岗位对应一个模型
+ * 创 建 者:Garrett
+ * 创建日期:2018/12/13 17:25:22
+ * ==============================================================================*/
+using SAGA.MBI.Calc;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
+using SAGA.MBI.RequestData;
+using SAGA.MBI.WinView.Upload;
+using SAGA.RevitUtils.Extends;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DevExpress.Data.Helpers;
+using Microsoft.Win32;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils.Extend;
+using SAGA.DotNetUtils.Logger;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Common;
+using SAGA.MBI.Tools;
+
+namespace SAGA.MBI.ToolsData
+{
+    /// <summary>
+    /// CheckDuplicationBIMId
+    /// </summary>
+    class CheckDuplicationBIMId
+    {
+        /// <summary>
+        /// 检查BIMId是否重复
+        /// </summary>
+        public static void CheckAll()
+        {
+            List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss=new List<IEnumerable<IGrouping<string, MRevitEquipBase>>>();
+            foreach (TreeNodeItem buildingItem in MBIControl.ProjectTree.Children)
+            {
+                string buildingId = buildingItem.Item.Id;
+                groupss.Add(Check(buildingId));
+            }
+            ExportToExcel(groupss);
+        }
+        /// <summary>
+        /// 检查BIMId是否重复
+        /// </summary>
+        private static IEnumerable<IGrouping<string, MRevitEquipBase>> Check(string buildingId)
+        {
+            var dutys = DalCommon.GetAllDutys(buildingId);
+            var bybimidGroups = dutys.GroupBy(t => t.BimID);
+            var exceptionGroups = bybimidGroups.Where(t => t.Count() >= 2 && !t.Key.IsOnlyDutyNoModelBIMID());
+            return exceptionGroups;
+        }
+
+
+        /// <summary>
+        /// 导出数据
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        public static void ExportToExcel(List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss)
+        {
+            SaveFileDialog sflg = new SaveFileDialog();
+            sflg.Filter = "Excel(*.xlsx)|*.xlsx";
+            if (sflg.ShowDialog() != true) return;
+            string fileName = sflg.FileName;
+            IWorkbook book = new XSSFWorkbook();
+            ISheet sheet = book.CreateSheet("Summary");
+            foreach (IEnumerable<IGrouping<string, MRevitEquipBase>> groups in groupss)
+            {
+                ExportToExcel(sheet, groups, fileName);
+            }
+            Save(book, fileName);
+        }
+
+        /// <summary>
+        /// 导出数据到指定目录
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        /// <param name="fileName"></param>
+        private static void ExportToExcel(ISheet sheet, IEnumerable<IGrouping<string, MRevitEquipBase>> groups, string fileName)
+        {
+            try
+            {
+                #region 添加表头
+
+                IRow row = sheet.CreateRow(0);
+                NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
+                cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell0.SetCellValue("BIMID");
+
+                ICell cell1 = row.CreateCell(1);
+                cell1.SetCellType(CellType.String);
+                cell1.SetCellValue("DutyId");
+
+                #endregion
+
+                #region 添加数据
+
+                int index = 1;
+                foreach (var group in groups)
+                {
+                    var bimid = group.Key;
+                    var dutys = "";
+                    foreach (var equip in group)
+                    {
+                        dutys += equip.Id + ";";
+                    }
+                    IRow rowN = sheet.CreateRow(index);
+                    NPOI.SS.UserModel.ICell cellN0 = rowN.CreateCell(0);
+                    cellN0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cellN0.SetCellValue(bimid);
+
+                    ICell cellN1 = rowN.CreateCell(1);
+                    cellN1.SetCellType(CellType.String);
+                    cellN1.SetCellValue(dutys);
+                    index++;
+
+                }
+
+                #endregion
+
+
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+
+        private static void Save(IWorkbook book, string fileName)
+        {
+            #region 写入
+
+            MemoryStream ms = new MemoryStream();
+            book.Write(ms);
+
+            using (System.IO.FileStream fs = new System.IO.FileStream(fileName, FileMode.Create, FileAccess.Write))
+            {
+                byte[] data = ms.ToArray();
+                fs.Write(data, 0, data.Length);
+                fs.Flush();
+            }
+            ms.Close();
+            ms.Dispose();
+
+            #endregion
+        }
+    }
+}

+ 155 - 0
MBI/SAGA.MBI/ToolsData/DataCheck/BIMDuplicationCheck.cs

@@ -0,0 +1,155 @@
+/* ==============================================================================
+ * 功能描述:检查BimID是否重复,多个岗位对应一个模型
+ * 创 建 者:Garrett
+ * 创建日期:2018/10/23 15:08:55
+ * ==============================================================================*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using Newtonsoft.Json.Linq;
+using NPOI.SS.UserModel;
+using SAGA.DotNetUtils.Extend;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Calc;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.JsonConvert;
+using SAGA.MBI.Model;
+using SAGA.MBI.RequestData;
+using SAGA.MBI.Tools;
+using SAGA.MBI.ToolsData.CheckBase;
+using SAGA.MBI.ToolsData.ModeCheck;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.ToolsData.DataCheck
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    class BIMDuplicationCheck : DataCheckBase
+    {
+        public BIMDuplicationCheck()
+        {
+            Name = "多个岗位共用一个bimID检查";
+        }
+        [DataCheckProcessAspect]
+        public override bool Check()
+        {
+            IsRight = GetCheckResult();
+            RMessage = IsRight ? "" : "多个岗位对应一个BIMID,请检查。";
+            return IsRight;
+        }
+
+        public override void Correct()
+        {
+        }
+
+        #region CheckMethod
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns></returns>
+        private bool GetCheckResult()
+        {            
+            bool result = true;
+            var mbuilding = DalProjectTree.GetSelectedBuilding();
+            var dutys = DalCommon.GetAllDutys(mbuilding.Id);
+            var bybimidGroups = dutys.GroupBy(t => t.BimID);
+            var exceptionGroups = bybimidGroups.Where(t => t.Count() >= 2 && !t.Key.IsOnlyDutyNoModelBIMID());
+            Results.AddRange(GetCheckResult(exceptionGroups));
+            return Results.Count==0;
+        }
+
+        private List<BIMDuplicationCheckResult> GetCheckResult(IEnumerable<IGrouping<string, MRevitEquipBase>> groups)
+        {
+            List<BIMDuplicationCheckResult> list = new List<BIMDuplicationCheckResult>();
+
+            try
+            {
+                foreach (var group in groups)
+                {
+                  list.AddRange(GetCheckResult(group));
+                }
+            }
+            catch (Exception e)
+            {
+            }
+            return list;
+        }
+
+        private List<BIMDuplicationCheckResult> GetCheckResult(IGrouping<string, MRevitEquipBase> group)
+        {
+            List<BIMDuplicationCheckResult> list = new List<BIMDuplicationCheckResult>();
+            try
+            {
+                string bimid = group.Key;
+                string revitId=bimid.GetBIMID().ToString();
+                string floorId = bimid.GetFloorId();
+                string floorName = DalProjectTree.GetFloorNameByFloorId(floorId);
+                foreach (MRevitEquipBase equipBase in group)
+                {
+                    BIMDuplicationCheckResult result=new BIMDuplicationCheckResult();
+                    result.FloorName = floorName;
+                    result.DutyId = equipBase.Id;
+                    result.DutyName = equipBase.ToString();
+                    result.BIMID = revitId;
+                    result.IsRight = false;
+                    list.Add(result);
+                }
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+            }
+            finally
+            {
+            
+            }
+            return list;
+        }
+
+        #endregion
+
+        //[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;
+                
+                foreach (MissDutyOrModeCheckResult result in Results)
+                {
+                    //数量过多,只显示有问题的
+                    //if (result.IsRight) continue;
+                    index++;
+                    IRow rowN = sheet.CreateRow(index);
+                    DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
+                    int i = 0;
+                    rowN.AddCell(i++, result.FloorName, style);
+                    rowN.AddCell(i++, result.DutyId, style);
+                    rowN.AddCell(i++, result.DutyName, style);
+                    rowN.AddCell(i++, result.BIMID, style);
+                    string rowN4 = result.IsRight ? "通过" : "不通过";
+                    rowN.AddCell(i++, rowN4, style);
+                    rowN.AddCell(i++, result.RMessage, style);
+                }
+                #endregion
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+    }
+}

+ 22 - 0
MBI/SAGA.MBI/ToolsData/DataCheck/BIMDuplicationCheckResult.cs

@@ -0,0 +1,22 @@
+/* ==============================================================================
+ * 功能描述:检查BimID是否重复,多个岗位对应一个模型
+ * 创 建 者:Garrett
+ * 创建日期:2018/10/23 15:13:17
+ * ==============================================================================*/
+
+using SAGA.MBI.ToolsData.CheckBase;
+using SAGA.MBI.ToolsData.ModeCheck;
+
+namespace SAGA.MBI.ToolsData.DataCheck
+{
+    /// <summary>
+    /// UnitCheckResult
+    /// </summary>
+    class BIMDuplicationCheckResult : DataCheckResultBase
+    {
+        public string FloorName { get; set; }
+        public string DutyId { get; set; }
+        public string DutyName { get; set; }
+        public string BIMID { get; set; }
+    }
+}

+ 8 - 6
MBI/SAGA.MBI/ToolsData/DataCheck/MissDutyOrModeCheck.cs

@@ -34,7 +34,7 @@ namespace SAGA.MBI.ToolsData.DataCheck
     {
         public MissDutyOrMode()
         {
-            Name = "岗位与模型一致性检查";
+            Name = "物理世界对象与模型一致性检查";
         }
         [DataCheckProcessAspect]
         public override bool Check()
@@ -89,13 +89,14 @@ namespace SAGA.MBI.ToolsData.DataCheck
                 //{
                 //    calcContext.OpenDocument();
                 //}
-                Action<List<MRevitEquipBase>, List<MissDutyOrModeCheckResult>> convetAction = (dutys, l) =>
+                Action<List<MRevitEquipBase>, List<MissDutyOrModeCheckResult>, DCElementType> convetAction = (dutys, l,type) =>
                 {
                     foreach (var duty in dutys)
                     {
                         MissDutyOrModeCheckResult result = new MissDutyOrModeCheckResult();
                         result.FloorName = calcContext.MFloor.ToString();
                         result.IsRight = false;
+                        result.Type = type;
                         if (isadd)
                         {
                             result.BIMID = duty.BimID.GetBIMID().ToString();
@@ -110,10 +111,10 @@ namespace SAGA.MBI.ToolsData.DataCheck
                         l.Add(result);
                     }
                 };
-                convetAction(calcContext.MEquipments.ToList<MRevitEquipBase>(), list);
-                convetAction(calcContext.MEquipmentParts.ToList<MRevitEquipBase>(), list);
-                convetAction(calcContext.MBeacons.ToList<MRevitEquipBase>(), list);
-                convetAction(calcContext.MSpaces.ToList<MRevitEquipBase>(), list);
+                convetAction(calcContext.MEquipments.ToList<MRevitEquipBase>(), list,DCElementType.Equipment);
+                convetAction(calcContext.MEquipmentParts.ToList<MRevitEquipBase>(), list,DCElementType.EuipmentPart);
+                convetAction(calcContext.MBeacons.ToList<MRevitEquipBase>(), list,DCElementType.Beacon);
+                convetAction(calcContext.MSpaces.ToList<MRevitEquipBase>(), list,DCElementType.Space);
             }
             catch (Exception e)
             {
@@ -155,6 +156,7 @@ namespace SAGA.MBI.ToolsData.DataCheck
                     rowN.AddCell(i++, result.FloorName, style);
                     rowN.AddCell(i++, result.DutyId, style);
                     rowN.AddCell(i++, result.DutyName, style);
+                    rowN.AddCell(i++, result.Type.GetDescription(), style);
                     rowN.AddCell(i++, result.BIMID, style);
                     string rowN4 = result.IsRight ? "通过" : "不通过";
                     rowN.AddCell(i++, rowN4, style);

+ 2 - 0
MBI/SAGA.MBI/ToolsData/DataCheck/MissDutyOrModeCheckResult.cs

@@ -4,6 +4,7 @@
  * 创建日期:2018/10/23 15:13:17
  * ==============================================================================*/
 
+using SAGA.MBI.ToolsData.CheckBase;
 using SAGA.MBI.ToolsData.ModeCheck;
 
 namespace SAGA.MBI.ToolsData.DataCheck
@@ -18,5 +19,6 @@ namespace SAGA.MBI.ToolsData.DataCheck
         public string DutyName { get; set; }
         public string BIMID { get; set; }
         public string FamilyName { get; set; }
+        public DCElementType Type { get; set; }
     }
 }

+ 1 - 1
MBI/SAGA.MBI/ToolsData/ModeCheck/DCRExport.cs

@@ -37,7 +37,7 @@ namespace SAGA.MBI.ToolsData.ModeCheck
         {
             SaveFileDialog sflg = new SaveFileDialog();
             if (File.Exists(defaultPath))
-                sflg.InitialDirectory = defaultPath;
+                sflg.FileName = defaultPath;
             sflg.Filter = "Excel(*.xlsx)|*.xlsx";
             if (sflg.ShowDialog() != true) return defaultPath;
             string fileName = sflg.FileName;

+ 2 - 2
MBI/SAGA.RevitUtils/Extends/FamilyInstanceExtend.cs

@@ -923,8 +923,8 @@ namespace SAGA.RevitUtils.Extends
         public static Line GetDoorWindowLocLine(this FamilyInstance instance, XYZ vect = null)
         {
             double dWidth = instance.GetBuiltInWidth()/2; //由于下边创建线的的方法是向两边延伸,所以宽度除以2
-            double dRotation = 0;
-            XYZ ptLoc = instance.Location.GetPoint(out dRotation);
+            double dRotation = instance.Location.GetRotation();
+            XYZ ptLoc = instance.Location.GetPoint();
 
             if (vect == null)
             {

+ 13 - 24
MBI/SAGA.RevitUtils/Extends/LocationExtend.cs

@@ -5,24 +5,6 @@ namespace SAGA.RevitUtils.Extends
 {
     public static class LocationExtend
     {
-        /// <summary>
-        /// 定位点
-        /// </summary>
-        /// <param name="loc"></param>
-        /// <param name="dRotate"></param>
-        /// <returns></returns>
-        public static XYZ GetPoint(this Location loc, out double dRotate)
-        {
-            dRotate = 0;
-            if (!(loc is LocationPoint)) return null;
-            LocationPoint lp = loc as LocationPoint;
-            try
-            {
-                dRotate = lp.Rotation;//MEP中有一些族获取此参数时抛出不明异常
-            }
-            catch { }
-            return lp.Point;
-        }
 
         /// <summary>
         /// 定位点
@@ -31,8 +13,10 @@ namespace SAGA.RevitUtils.Extends
         /// <returns></returns>
         public static XYZ GetPoint(this Location loc)
         {
-            double dR;
-            return loc.GetPoint(out dR);
+            XYZ point = null;
+            if (loc is LocationPoint lp)
+                point = lp?.Point;
+            return point;
         }
 
         /// <summary>
@@ -42,9 +26,14 @@ namespace SAGA.RevitUtils.Extends
         /// <returns></returns>
         public static double GetRotation(this Location loc)
         {
-            double dR;
-            loc.GetPoint(out dR);
-            return dR;
+            double dRotate = 0;
+            try
+            {
+                if (loc is LocationPoint lp)
+                    dRotate = lp.Rotation;//MEP中有一些族获取此参数时抛出不明异常
+            }
+            catch { }
+            return dRotate;
         }
 
         /// <summary>
@@ -54,7 +43,7 @@ namespace SAGA.RevitUtils.Extends
         /// <returns></returns>
         public static Curve GetCurve(this Location loc)
         {
-            if (!(loc is LocationCurve)) return null ;
+            if (!(loc is LocationCurve)) return null;
             LocationCurve lc = loc as LocationCurve;
             return lc.Curve;
         }