zhangyuekai
2024-08-13 839500b0fae58b5ff142508b1b32b1f107df9ea1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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 HStation.RevitDev.RevitDataExport.Utility;
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, List<string>> RevitModels = new Dictionary<RevitType, List<string>>();
 
        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 bool Contains(this Dictionary<RevitType, List<string>> dict, string id)
        {
            foreach (var pair in dict)
            {
                if (pair.Value.Contains(id))
                {
                    return true;
                }
            }
            return false;
        }
 
        public static void Add(this Dictionary<RevitType, List<string>> 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 List<string>());
                }
                if (!dict[type].Contains(id))
                {
                    dict[type].Add(id);
                }
            }
        }
 
        private static ElementModel CreateElementModel(Element elem, RevitType revitType)
        {
            return new ElementModel();
        }
 
        public static void Remove(this Dictionary<RevitType, List<string>> dict, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }
            foreach (var pair in dict)
            {
                if (pair.Value.Contains(id))
                {
                    pair.Value.Remove(id);
                }
            }
        }
 
        public static List<string> GetIds(this Dictionary<RevitType, List<string>> dict)
        {
            var ret = new List<string>();
 
            foreach (var pair in dict)
            {
                var subList = pair.Value;
                ret.AddRange(subList);
            }
 
            return ret;
        }
    }
}