using Autodesk.Revit.DB;
|
using Autodesk.Revit.UI;
|
using DevExpress.Data.Extensions;
|
using DevExpress.XtraPrinting.Native;
|
using HStation.RevitDev.Model.ModelEnum;
|
using HStation.RevitDev.RevitDataExport.Entity;
|
using HStation.RevitDev.RevitDataExport.Entity.ElementModels;
|
using HStation.RevitDev.RevitDataExport.Forms;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.IO;
|
using System.Linq;
|
using System.Reflection;
|
|
namespace HStation.RevitDev.RevitDataExport.Common
|
{
|
public static class GlobalResource
|
{
|
public static readonly string PluginName = "泵系统分析";
|
|
public static readonly string PanelName = "族库";
|
|
public static Document CurrentDocument = null;
|
|
public static UIDocument CurrentUIDocument = null;
|
|
public static AddInId CurrentAddinId = null;
|
|
public static string InstancePaneGuid = "A64C3186-4905-4CEC-AB1D-41B39CEA4352";
|
|
public static string LastFilePath = string.Empty;
|
|
public static Dictionary<RevitType, ObservableCollection<ElementModel>> RevitModels = new Dictionary<RevitType, ObservableCollection<ElementModel>>();
|
|
public static RevitType PlacingType = RevitType.RFT_Unknown;
|
|
public static Wpf_InstancePanel InstancePanel = null;
|
|
public static Wpf_FamilyPanel FamilyPanel = null;
|
|
public static int ThumbnailSize = 150;
|
|
public static string CurrentRevitVersion = string.Empty;
|
|
public static bool HideMode = false;
|
|
public static Dictionary<RevitType, string> DockablePanelDict => new Dictionary<RevitType, string>
|
{
|
{RevitType.RFT_Pump, "8AF8DA72-120F-44A0-81DD-5DD24EDAB919"},
|
{RevitType.RFT_Valve, "1A2728E3-51FF-4084-B0B6-F6DAD26A56FB"},
|
{RevitType.RFT_Pipe, "CB879681-B8E8-4FE2-BF57-4C86068D2C89"},
|
|
{RevitType.RFT_FourJoint, "AAB55EEE-8450-4848-9C89-0322BBE94F5A"},
|
{RevitType.RFT_Elbow, "C357EC81-09FF-41C5-8E32-FE71E30EA394"},
|
{RevitType.RFT_Blocker, "0250FA8F-56C3-4355-817D-60B515CAD90E"},
|
{RevitType.RFT_FireHydrant, "34E2EAD1-3D49-46C9-9942-451DD0192229"},
|
{RevitType.RFT_HeatExchanger, "056EAACD-ED75-4854-8F3C-A4A43007BF31"},
|
{RevitType.RFT_Converter, "51F22122-04D5-4C28-9E68-1ADED0EABD04"},
|
|
{RevitType.RFT_Shower, "D4AA8261-406E-44FF-A1EE-531153FA9709"},
|
{RevitType.RFT_ThreeJoint, "1BAA114A-E355-402C-B91D-569882D12987"},
|
{RevitType.RFT_WaterBox, "44951F67-0C2F-4B02-B988-8B5F06295A18"},
|
{RevitType.RFT_WaterMeter, "28354DCD-C11F-4EE8-89F8-72B9A93FD9E6"},
|
{RevitType.RFT_WaterPool, "2DFB190E-1FD9-4CC6-8F85-AD3B19745ACF"},
|
};
|
|
public static string BinDirectory
|
{
|
get
|
{
|
string result = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
return result;
|
}
|
}
|
|
public static string DataDirectory
|
{
|
get
|
{
|
string result = Path.Combine(Path.GetDirectoryName(BinDirectory), "Data");
|
return result;
|
}
|
}
|
|
public static string ExportFilePath
|
{
|
get
|
{
|
string result = Path.Combine(DataDirectory, "Export", "export.json");
|
return result;
|
}
|
}
|
|
public static string RecordFilePath
|
{
|
get
|
{
|
string result = Path.Combine(DataDirectory, "Config", "record.json");
|
return result;
|
}
|
}
|
|
public static string ConfigFilePath
|
{
|
get
|
{
|
string result = Path.Combine(DataDirectory, "Config", "config.json");
|
return result;
|
}
|
}
|
|
public static string FamilysDirectory
|
{
|
get
|
{
|
string result = Path.Combine(DataDirectory, "Familys");
|
return result;
|
}
|
}
|
|
public static string ImageDirectory
|
{
|
get
|
{
|
string result = Path.Combine(DataDirectory, "Image");
|
return result;
|
}
|
}
|
|
private static ConfigModel configModel = null;
|
public static ConfigModel ConfigModel
|
{
|
get
|
{
|
if (configModel != null)
|
{
|
return configModel;
|
}
|
if (!File.Exists(ConfigFilePath))
|
{
|
return new ConfigModel();
|
}
|
var strConfig = File.ReadAllText(ConfigFilePath);
|
if (string.IsNullOrEmpty(strConfig))
|
{
|
return new ConfigModel();
|
}
|
var ret = Newtonsoft.Json.JsonConvert.DeserializeObject<ConfigModel>(strConfig);
|
if (ret == null)
|
{
|
return new ConfigModel();
|
}
|
configModel = ret;
|
return configModel;
|
}
|
}
|
|
public static ElementModel GetElementModel(string id)
|
{
|
foreach (var pair in RevitModels)
|
{
|
var elemModels = pair.Value;
|
var matchModels = elemModels.Where(x => x.Id == id);
|
if (matchModels == null || matchModels.Count() == 0)
|
{
|
continue;
|
}
|
return matchModels.First();
|
}
|
return null;
|
}
|
|
public static bool Contains(this Dictionary<RevitType, ObservableCollection<ElementModel>> dict, string id)
|
{
|
foreach (var pair in dict)
|
{
|
if (pair.Value.Any(x => x.Id == id))
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public static void Add(this Dictionary<RevitType, ObservableCollection<ElementModel>> dict, Element elem, RevitType type = RevitType.RFT_Others)
|
{
|
if (elem == null)
|
{
|
return;
|
}
|
|
var id = elem.Id.IntegerValue.ToString();
|
if (!dict.Contains(id))
|
{
|
if (!dict.ContainsKey(type))
|
{
|
dict.Add(type, new ObservableCollection<ElementModel>());
|
}
|
if (!dict[type].Any(x => x.Id == id))
|
{
|
dict[type].Add(new ElementModel
|
{
|
Id = id,
|
Name = elem.Name,
|
LinkIds = string.Empty
|
});
|
}
|
}
|
}
|
|
private static ElementModel CreateElementModel(Element elem, RevitType revitType)
|
{
|
if (revitType == RevitType.RFT_Valve)
|
{
|
return new ValveModel();
|
}
|
return new ElementModel();
|
}
|
|
public static void Remove(this Dictionary<RevitType, ObservableCollection<ElementModel>> dict, string id)
|
{
|
if (string.IsNullOrEmpty(id))
|
{
|
return;
|
}
|
if (dict.Contains(id))
|
{
|
var models = dict.Values.Where(x => x.Any(y => y.Id == id))?.ToList();
|
if (models != null && models.Count() == 0)
|
{
|
for (int i = 0; i < models.Count(); i++)
|
{
|
models[i].RemoveAt(models[i].FindIndex(x=>x.Id == id));
|
}
|
}
|
}
|
}
|
|
public static List<string> GetIds(this Dictionary<RevitType, ObservableCollection<ElementModel>> dict)
|
{
|
var ret = new List<string>();
|
|
foreach (var pair in dict)
|
{
|
var subList = pair.Value.Select(x => x.Id);
|
ret.AddRange(subList);
|
}
|
|
return ret;
|
}
|
}
|
}
|