|
@@ -0,0 +1,152 @@
|
|
|
+/* ==============================================================================
|
|
|
+ * 功能描述:检查设备所在楼层
|
|
|
+ * 创 建 者:Garrett
|
|
|
+ * 创建日期:2018/8/10 16:36:26
|
|
|
+ * ==============================================================================*/
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Autodesk.Revit.DB;
|
|
|
+using Autodesk.Revit.DB.Mechanical;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using SAGA.DotNetUtils;
|
|
|
+using SAGA.DotNetUtils.Logger;
|
|
|
+using SAGA.DotNetUtils.Others;
|
|
|
+using SAGA.MBI.Calc;
|
|
|
+using SAGA.MBI.Common;
|
|
|
+using SAGA.MBI.DataArrange;
|
|
|
+using SAGA.MBI.Model;
|
|
|
+using SAGA.MBI.RequestData;
|
|
|
+using SAGA.MBI.Tools;
|
|
|
+using SAGA.MBI.WinView.Upload;
|
|
|
+using SAGA.RevitUtils.Extends;
|
|
|
+
|
|
|
+namespace SAGA.MBI.ToolsData
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// UpdateRelationEquipinFloor
|
|
|
+ /// </summary>
|
|
|
+ public class UpdateRelationEquipinSpace
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// 检查并处理所有楼层
|
|
|
+ /// </summary>
|
|
|
+ public static void OperateAll()
|
|
|
+ {
|
|
|
+ var floors = DalUploadFloor.GetHasFileFloors();
|
|
|
+ foreach (UploadFloor floor in floors)
|
|
|
+ {
|
|
|
+ Operate(floor.MFloor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 只处理当前楼层
|
|
|
+ /// </summary>
|
|
|
+ public static void OperateCurFloor()
|
|
|
+ {
|
|
|
+ MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
|
|
|
+ if (floor != null)
|
|
|
+ Operate(floor);
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 检查并处理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="floor"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private static void Operate(MFloor floor)
|
|
|
+ {
|
|
|
+ var context = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ RebuildCloudData(context);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ MessageShowBase.Show(e);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 检查设备所在楼层关系
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="baseContext"></param>
|
|
|
+ private static void RebuildCloudData(CalcContext baseContext)
|
|
|
+ {
|
|
|
+ baseContext.OpenDocument();
|
|
|
+ var doc = baseContext.RevitDoc;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ JObject jobject = new JObject();
|
|
|
+ JArray jcriterias = new JArray();
|
|
|
+ string graphtype = RelationConst.EquipInSpaceGraphId;
|
|
|
+ string reltyp = RelationConst.EquipInSpaceGraphRelationType;
|
|
|
+ string graphid = RelationRequest.GetCurrentGraphId(graphtype);
|
|
|
+ if (graphid == null) return;
|
|
|
+ if (baseContext.MEquipments.Count == 0 && baseContext.MEquipmentParts.Count == 0) return;
|
|
|
+ //空间不处理
|
|
|
+ //检查设备
|
|
|
+ foreach (var mode in baseContext.MEquipments)
|
|
|
+ {
|
|
|
+ string equipid = mode.Id;
|
|
|
+ string spaceId = GetMSpace(doc, mode.BimID, baseContext.MSpaces.ToList());
|
|
|
+ if (spaceId.IsNullOrEmpty()) continue;
|
|
|
+
|
|
|
+ JObject jitem = new JObject();
|
|
|
+ jitem.Add("from_id", equipid);
|
|
|
+ jitem.Add("to_id", spaceId);
|
|
|
+ jitem.Add("graph_id", graphid);
|
|
|
+ jitem.Add("rel_type", reltyp);
|
|
|
+ jcriterias.Add(jitem);
|
|
|
+ }
|
|
|
+ //检查部件
|
|
|
+ foreach (var mode in baseContext.MEquipmentParts)
|
|
|
+ {
|
|
|
+ string equipid = mode.Id;
|
|
|
+ string spaceId = GetMSpace(doc, mode.BimID, baseContext.MSpaces.ToList());
|
|
|
+ if (spaceId.IsNullOrEmpty()) continue;
|
|
|
+ JObject jitem = new JObject();
|
|
|
+ jitem.Add("from_id", equipid);
|
|
|
+ jitem.Add("to_id", spaceId);
|
|
|
+ jitem.Add("graph_id", graphid);
|
|
|
+ jitem.Add("rel_type", reltyp);
|
|
|
+ jcriterias.Add(jitem);
|
|
|
+ }
|
|
|
+ //信标不用检查
|
|
|
+ jobject.Add("criterias", jcriterias);
|
|
|
+ RelationRequest.AddRelation(jobject);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine(e);
|
|
|
+
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ baseContext.CloseDocument();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static string GetMSpace(Document doc,string bimid,List<MSpace> spaces)
|
|
|
+ {
|
|
|
+ FamilyInstance fi = doc.GetElement(bimid.GetBIMID()) as FamilyInstance;
|
|
|
+ if (fi == null) return null;
|
|
|
+ var space = fi.GetReferenceSpace();
|
|
|
+ if (space == null) return null;
|
|
|
+ var spaceid = space.GetCloudBIMId();
|
|
|
+ var mspace = spaces.FirstOrDefault(t => t.BimID == spaceid);
|
|
|
+ if (mspace == null)
|
|
|
+ {
|
|
|
+ mspace = DalSpace.GetSpace(space);
|
|
|
+ mspace.Operator = DocumentChangedOperator.Add;
|
|
|
+ mspace.AddObject();
|
|
|
+ }
|
|
|
+ return mspace?.Id;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|