123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /*-------------------------------------------------------------------------
- * 功能描述:SystemCalcUtil
- * 作者:xulisong
- * 创建时间: 2019/1/2 17:55:55
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using Autodesk.Revit.DB;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils.Cache;
- using SAGA.MBI.RequestData;
- using SAGA.Models;
- using SAGA.RevitUtils.Extends;
- using MBIEquipItem = SAGA.Models.EquipmentItem;
- namespace SAGA.GplotRelationComputerManage
- {
- /// <summary>
- /// 系统计算相关
- /// </summary>
- public class SystemCalcUtil
- {
- /// <summary>
- /// 判断元素是否是开始元素
- /// </summary>
- /// <param name="element"></param>
- /// <returns></returns>
- public static bool IsStart(Element element)
- {
- if (element is FamilyInstance)
- {
- var name = element.GetFamily().Name;
- return Regex.IsMatch(name, AppSetting.FamilyStartFlag);
- }
- return (element.GetParameterString(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)??string.Empty).StartsWith(AppSetting.StartFlag);
- }
- /// <summary>
- /// 创建房间缓冲集合
- /// </summary>
- /// <returns></returns>
- public static CacheItems<string,RoomItem> CreateRoomItems()
- {
- CacheItems<string, RoomItem> items = new CacheItems<string, RoomItem>((s) =>
- {
- var rooms = new Dictionary<string, RoomItem>();
- var str = new string[] {MBIBuiltInCategory.Si};
- List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
- foreach (var data in datas)
- {
- var roomItem = MBIItemFactory.Create<RoomItem>(data);
- rooms[roomItem.BimId] = roomItem;
- }
- return rooms;
- });
- return items;
- }
- /// <summary>
- /// 创建楼层缓冲集合
- /// </summary>
- /// <returns></returns>
- public static CacheItems<string, FloorSystemItem> CreateFloorItems()
- {
- CacheItems<string, FloorSystemItem> items = new CacheItems<string, FloorSystemItem>(null, (path) =>
- {
- var floorId = Path.GetFileNameWithoutExtension(path);
- Dictionary<string, FloorSystemItem> miss = new Dictionary<string, FloorSystemItem>();
- if (File.Exists(path))
- {
- var uiApp = ExternalDataWrapper.Current.UiApp.Application;
- var doc = uiApp.OpenDocumentFile(path);
- var floor = new FloorSystemItem(doc);
- miss[floorId] = floor;
- }
- return miss;
- }, Path.GetFileNameWithoutExtension);
- return items;
- }
- /// <summary>
- /// 创建关系类型壳对象
- /// </summary>
- /// <returns></returns>
- public static CacheItems<string, RelationTypeShell> CreateRelationShellItems()
- {
- CacheItems<string, RelationTypeShell> items = new CacheItems<string, RelationTypeShell>((s) =>
- {
- var shells = new Dictionary<string, RelationTypeShell>();
- foreach (var relationItem in RelationTypeManager.Items)
- {
- shells[relationItem.Type] = new RelationTypeShell(relationItem);
- }
- return shells;
- });
- return items;
- }
- /// <summary>
- /// 创建设备缓存对象
- /// </summary>
- /// <returns></returns>
- public static CacheItems<string, MBIEquipItem> CreateEquipmentItems()
- {
- CacheItems<string, MBIEquipItem> items = new CacheItems<string, MBIEquipItem>((s) =>
- {
- var equipmentItems = new Dictionary<string, MBIEquipItem>();
- var types = new string[] { MBIBuiltInCategory.Eq };
- List<JObject> equipDatas = CommonConvert.QueryObjectInfoByTypes(types);
- foreach (var jobject in equipDatas)
- {
- var item = MBIItemFactory.Create<MBIEquipItem>(jobject);
- if (item != null && string.IsNullOrWhiteSpace(item.BimId))
- {
- equipmentItems[item.BimId]= item;
- }
- }
-
- return equipmentItems;
- });
- return items;
-
- }
- }
- }
|