qin
2024-09-28 e358beb08f5be49703009b64f058ecfbcfeefbd9
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using DevExpress.Data.Extensions;
using DevExpress.XtraPrinting.Native;
using Glodon.Revit.Utility;
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 List<Tuple<string, Dictionary<RevitType, List<string>>>> RevitModels =
            new List<Tuple<string, 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 bool IsOtherHidden = 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 ParamsFilePath
        {
            get
            {
                string result = Path.Combine(DataDirectory, "Config", "familyparams.json");
                return result;
            }
        }
 
        public static string ConfigFilePath
        {
            get
            {
                string result = Path.Combine(DataDirectory, "Config", "config.json");
                return result;
            }
        }
 
        public static string SettingFilePath
        {
            get
            {
                string result = Path.Combine(DataDirectory, "Config", "setting.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;
        private static ConfigSettingModel configSettingModel = null;
 
        public static ConfigSettingModel ConfigSettingModel
        {
            get
            {
                if (configSettingModel != null)
                {
                    return configSettingModel;
                }
                if (!File.Exists(ConfigFilePath))
                {
                    return new ConfigSettingModel() { SystemType= ConfigHelper.SystemType.All };
                }
                var strConfig = File.ReadAllText(SettingFilePath);
                if (string.IsNullOrEmpty(strConfig))
                {
                    return new  ConfigSettingModel() { SystemType = ConfigHelper.SystemType.All };
                }
                var ret = Newtonsoft.Json.JsonConvert.DeserializeObject<ConfigSettingModel>(strConfig);
                if (ret == null)
                {
                    return new ConfigSettingModel() { SystemType = ConfigHelper.SystemType.All };
                }
                configSettingModel = ret;
                return configSettingModel;
            }
        }
        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 List<Tuple<string, Dictionary<RevitType, List<string>>>> tuples, string id)
        {
            var dict = tuples.Find(x => x.Item1 == CurrentDocument.Title)?.Item2;
            if (dict == null) { return false; }
 
            foreach (var pair in dict)
            {
                if (pair.Value.Contains(id))
                {
                    return true;
                }
            }
            return false;
        }
 
        public static void Add(this List<Tuple<string, Dictionary<RevitType, List<string>>>> tuples, Element elem, RevitType type = RevitType.RFT_Others)
        {
            if (elem == null)
            {
                return;
            }
 
            //var ps = elem.GetParameterByProName("是否自定义");
            //if ((type != RevitType.RFT_Others && type != RevitType.RFT_Pipe) && (ps == null || !ps.AsString().Equals("是")))
            //{
            //    return;
            //}
 
            var id = elem.Id.IntegerValue.ToString();
            if (!tuples.Contains(id))
            {
                var dict = tuples.Find(x => x.Item1 == CurrentDocument.Title)?.Item2;
                if (dict == null)
                {
                    dict = new Dictionary<RevitType, List<string>>();
                    tuples.Add(new Tuple<string, Dictionary<RevitType, List<string>>>(elem.Document.Title, dict));
                }
 
                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 List<Tuple<string, Dictionary<RevitType, List<string>>>> tuples, string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }
 
            var dict = tuples.Find(x => x.Item1 == CurrentDocument.Title)?.Item2;
            if (dict == null) { return; }
 
            foreach (var pair in dict)
            {
                if (pair.Value.Contains(id))
                {
                    pair.Value.Remove(id);
                }
            }
        }
 
        public static List<string> GetIds(this List<Tuple<string, Dictionary<RevitType, List<string>>>> tuples)
        {
            var ret = new List<string>();
 
            var dict = tuples.Find(x => x.Item1 == CurrentDocument.Title)?.Item2;
            if (dict == null) { return ret; }
 
            foreach (var pair in dict)
            {
                if (pair.Key != RevitType.RFT_Others)
                {
                    var subList = pair.Value;
                    ret.AddRange(subList);
                }
            }
 
            return ret;
        }
 
        public static List<string> GetOtherIds(this List<Tuple<string, Dictionary<RevitType, List<string>>>> tuples)
        {
            var ret = new List<string>();
 
            var dict = tuples.Find(x => x.Item1 == CurrentDocument.Title)?.Item2;
            if (dict == null) { return ret; }
 
            foreach (var pair in dict)
            {
                if (pair.Key == RevitType.RFT_Others)
                {
                    var subList = pair.Value;
                    ret.AddRange(subList);
                }
            }
 
            return ret;
        }
 
        public static bool ContainsKey(this List<Tuple<string, Dictionary<RevitType, List<string>>>> tuples, RevitType type)
        {
            var dict = tuples.Find(x => x.Item1 == CurrentDocument.Title)?.Item2;
            if (dict == null) { return false; }
            return dict.ContainsKey(type);
        }
    }
}