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
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HStation.RevitDev.Model.ModelEnum;
using HStation.RevitDev.RevitDataExport.Common;
using HStation.RevitDev.RevitDataExport.Entity;
using HStation.RevitDev.RevitDataExport.Utility;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Media.Imaging;
 
namespace HStation.RevitDev.RevitDataExport.Plugin
{
    [Transaction(TransactionMode.Manual)]
    public class Application : IExternalApplication
    {
        UIControlledApplication m_application;
 
        public Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }
 
        public Result OnStartup(UIControlledApplication application)
        {
            m_application = application;
            
            GlobalResource.CurrentRevitVersion = application.ControlledApplication.VersionNumber;
            Ribbon ribbon = new Ribbon(application);
 
            //水力组件
            RibbonPanel panel1 = ribbon.CreatePanel("水力组件");
            CreateFamilyBottons(ribbon, panel1);
 
            //导入导出
            RibbonPanel panel2 = ribbon.CreatePanel("导入导出");
            CreateExportBottons(ribbon, panel2);
            CreateSystemSelectBotton(ribbon, panel2);
 
            //显示控制
            RibbonPanel panel3 = ribbon.CreatePanel("显示控制");
            CreateVisibleBotton(ribbon, panel3);
            CreateVisibleOtherBotton(ribbon, panel3);
 
            //拓扑检查
            RibbonPanel panel4 = ribbon.CreatePanel("拓扑检查");
            CreateCheckBotton(ribbon, panel4);
            DockPaneUtil.RegistInstanceDockablePanel(application);
 
            //计算分析
            RibbonPanel panel5 = ribbon.CreatePanel("计算分析");
            CreateAnalyBotton(ribbon, panel5);
 
            //系统管理
            RibbonPanel panel6 = ribbon.CreatePanel("系统管理");
            CreateAutoClassifiedBotton(ribbon, panel6);
            CreateFamilyManagerBotton(ribbon, panel6);
 
            RegistEvent();
            return Result.Succeeded;
        }
 
        private void CreateFamilyManagerBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //SystemSelect
            string className = "HStation.RevitDev.RevitDataExport.FamilyManager";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("FamilyManager", "族库管理", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"族库管理.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "族库管理";
        }
 
        private void CreateSystemSelectBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //SystemSelect
            string className = "HStation.RevitDev.RevitDataExport.SystemSelect";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("SystemSelect", "导入", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"系统分类.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "导入";
        }
 
        private void CreateAutoClassifiedBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //Classified Elements
            string className = "HStation.RevitDev.RevitDataExport.AutoClassified";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("AutoClassified", "构件分类", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"构件分类.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "构件分类";
        }
 
        private void CreateCheckBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //Check Links
            string className = "HStation.RevitDev.RevitDataExport.SystemCheck";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("Check", "系统检查", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"系统检查.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "系统检查";
        }
        private void CreateAnalyBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //Check Links
            string className = "HStation.RevitDev.RevitDataExport.Analy";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("Check", "水力计算", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"水力计算.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "水力计算";
        }
 
        private void CreateVisibleBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //Hide Or Display Models
            string className = "HStation.RevitDev.RevitDataExport.HideModels";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("Hide", "管网显隐", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"一键显隐.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "管网显隐";
        }
 
        private void CreateVisibleOtherBotton(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            //Hide Or Display Models
            string className = "HStation.RevitDev.RevitDataExport.HideOtherModels";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("HideOther", "其它显隐", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"一键显隐.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "其它显隐";
        }
 
        private void CreateExportBottons(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            string className = "HStation.RevitDev.RevitDataExport.ExportModels";
            string path = Assembly.GetExecutingAssembly().Location;
 
            PushButtonData pdata = new PushButtonData("Export", "导出", path, className);
            PushButton pBtn = ribbonPanel.AddItem(pdata) as PushButton;
 
            string imagePath = Path.Combine(GlobalResource.ImageDirectory, $"导出.png");
            pBtn.LargeImage = new BitmapImage(new Uri(imagePath));//32 * 32
            pBtn.ToolTip = "导出模型数据";
        }
 
        private static void CreateFamilyBottons(Ribbon ribbon, RibbonPanel ribbonPanel)
        {
            string className1 = "HStation.RevitDev.RevitDataExport.PumpSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Pump, className1);
 
            string className2 = "HStation.RevitDev.RevitDataExport.ValveSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Valve, className2);
 
            string className3 = "HStation.RevitDev.RevitDataExport.PipeSystem";
            ribbon.CreateButton_PipeSystem(ribbonPanel, RevitType.RFT_Pipe, className3);
 
            //换热器
            if (GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.All || GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.CirculatingWater)
            {
                string className4 = "HStation.RevitDev.RevitDataExport.HeatExchangerSystem";
                ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_HeatExchanger, className4);
            }
 
            string className5 = "HStation.RevitDev.RevitDataExport.BlockerSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Blocker, className5);
 
            //喷淋头
            if (GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.All || GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.Spray)
            {
                string className6 = "HStation.RevitDev.RevitDataExport.ShowerSystem";
                ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Shower, className6);
            }
 
            string className7 = "HStation.RevitDev.RevitDataExport.ThreeJointSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_ThreeJoint, className7);
 
            string className8 = "HStation.RevitDev.RevitDataExport.FourJointSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_FourJoint, className8);
 
            string className9 = "HStation.RevitDev.RevitDataExport.WaterMeterSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_WaterMeter, className9);
 
            string className10 = "HStation.RevitDev.RevitDataExport.WaterPoolSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_WaterPool, className10);
 
            string className11 = "HStation.RevitDev.RevitDataExport.WaterBoxSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_WaterBox, className11);
 
            string className12 = "HStation.RevitDev.RevitDataExport.ElbowSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Elbow, className12);
 
            //消火栓
            if (GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.All || GlobalResource.ConfigSettingModel.SystemType == ConfigHelper.SystemType.Fire)
            {
                string className13 = "HStation.RevitDev.RevitDataExport.FireHydrantSystem";
                ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_FireHydrant, className13);
            }
 
            string className14 = "HStation.RevitDev.RevitDataExport.ReducingSystem";
            ribbon.CreateButton_SystemAnalysis(ribbonPanel, RevitType.RFT_Converter, className14);
        }
 
        private void RegistEvent()
        {
            m_application.ControlledApplication.DocumentOpened += ControlledApplication_DocumentOpened;
            m_application.ControlledApplication.DocumentOpening += ControlledApplication_DocumentOpening;
            m_application.ControlledApplication.DocumentCreated += ControlledApplication_DocumentCreated;
            m_application.ControlledApplication.DocumentCreating += ControlledApplication_DocumentCreating;
 
            m_application.ControlledApplication.DocumentSaved += ControlledApplication_DocumentSaved;
            m_application.ControlledApplication.DocumentSavedAs += ControlledApplication_DocumentSavedAs;
            
        }
 
        private void ControlledApplication_DocumentSavedAs(object sender, Autodesk.Revit.DB.Events.DocumentSavedAsEventArgs e)
        {
            CacheUtil.SaveCache(e.Document);
        }
 
        private void ControlledApplication_DocumentSaved(object sender, Autodesk.Revit.DB.Events.DocumentSavedEventArgs e)
        {
            CacheUtil.SaveCache(e.Document);
        }
 
        private void ControlledApplication_DocumentOpening(object sender, Autodesk.Revit.DB.Events.DocumentOpeningEventArgs e)
        {
            DockPaneUtil.HideAllDockablePane(m_application);
        }
 
        private void ControlledApplication_DocumentCreated(object sender, Autodesk.Revit.DB.Events.DocumentCreatedEventArgs e)
        {
            var doc = e.Document;
            GlobalResource.CurrentDocument = e.Document;
            DockPaneUtil.HideAllDockablePane(m_application);
            var cache = GlobalResource.RevitModels.Find(x => x.Item1 == doc.Title);
            if (cache == null)
            {
                GlobalResource.RevitModels.Add(new Tuple<string, Dictionary<RevitType, List<string>>>(doc.Title, new Dictionary<RevitType, List<string>>()));
            }
        }
 
        private void ControlledApplication_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
        {
            DockPaneUtil.HideAllDockablePane(m_application);
            GlobalResource.CurrentDocument = e.Document;
            CacheUtil.InitCache(e.Document);
            DocumentUtil.UpdataDocumentCache(e.Document);
        }
 
        private void ControlledApplication_DocumentCreating(object sender, Autodesk.Revit.DB.Events.DocumentCreatingEventArgs e)
        {
            DockPaneUtil.HideAllDockablePane(m_application);
        }
    }
}