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
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using DevExpress.Utils.Extensions;
using Hydro.Core.Model;
using HStation.RevitDev.RevitDataExport.Utility;
using HStation.RevitDev.RevitDataExport.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
 
namespace HStation.RevitDev.RevitDataExport.Forms
{
    public partial class Form_CheckResult : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TabControl _pageContainer;
        private Form_SystemSelect _form_SystemSelect;
        private CheckModel model;
        private UIDocument _uiDocument;
        private Document _doc;
        public Form_CheckResult(CheckModel checkModel, System.Windows.Forms.TabControl pageContainer, ExternalCommandData data, Form_SystemSelect form_SystemSelect)
        {
            _uiDocument = data.Application.ActiveUIDocument;
            _doc = _uiDocument.Document;
            _pageContainer = pageContainer;
            _form_SystemSelect = form_SystemSelect;
            this.model = checkModel;
            InitializeComponent();
        }
 
        private void Form_CheckResult_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = model.FailList;
        }
 
        private View3D Set3DView()
        {
            var view3d = ViewHelper.Get3dView(_doc);
            _uiDocument.ActiveView = view3d;
            return view3d;
        }
 
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var rowIndex = e.RowIndex;
            var columnIndex = e.ColumnIndex;
            var cell = dataGridView1[columnIndex, rowIndex];
 
            if (cell.Value == null) { return; }
            var view = Set3DView();
 
            var cellText = cell.Value.ToString();
            if (dataGridView1.Columns[columnIndex].HeaderText == "ID")
            {
                var idContent = cellText.Split(':')?.Last();
                if (string.IsNullOrEmpty(idContent)) { return; }
                if (int.TryParse(idContent, out int id))
                {
                    if (!id.Equals(0))
                    {
                        var elementId = new ElementId(id);
                        var ids = new List<ElementId> { elementId };
                        view.Select(_uiDocument, ids);
                        view.Zoom(_uiDocument, ids);
                    }
                }
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            _form_SystemSelect.SetCheckIndexs();
            this.model = _form_SystemSelect.GetNetWrok();
            dataGridView1.Refresh();
        }
 
        private void ReCheck()
        {
            var nw = _form_SystemSelect._revitNetWork;
            var mod = this.model;
            if (checkBox1.Checked) //喷淋修复连接管件上游管道
            {
                var ps = mod.FailList.Where(c => c.Type == Hydro.Core.ObjectEnum.FailType.喷头只能连接管道);
                var ids = ps.Select(c => c.ID);
                var ms = ps.Select(c => c.ID).ToArray();
                var nos = nw.Nozzles.Where(c => ids.Contains(c.ID));
 
                nos.ForEach(c =>
                {
                    var gj = nw.Junctions.FirstOrDefault(b => b.ID == c.Node1);
                    if (gj != null)
                    {
                        var gjid = gj.ID;
                        var pipe = nw.Links.FirstOrDefault(b => b.Node1 == gjid || b.Node2 == gjid);
                        c.Node1 = pipe.ID;
                        if (pipe.Node1.Equals(gjid)) pipe.Node1 = c.ID;
                        if (pipe.Node2.Equals(gjid)) pipe.Node2 = c.ID;
                    }
                });
 
                for (var i = 0; i < ms.Count(); i++)
                {
                    var m = mod.FailList.FirstOrDefault(c => c.ID == ms[i] && c.Type == Hydro.Core.ObjectEnum.FailType.喷头只能连接管道);
                    mod.FailList.Remove(m);
                };
 
 
            }
            if (checkBox2.Checked) //管道修改缺少一个连接对象,增加闷头(虚拟结点)
            {
                var pipes = nw.Pipes.Where(c => (c.Node1 + "_" + c.Node2).Length > 1 && (c.Node1 + "_" + c.Node2).Length < 10);
                var ids = pipes.Select(c => c.ID);
                var ms = mod.FailList.Where(c => ids.Contains(c.ID)).Select(c => c.ID).ToArray();
                for (var i = 0; i < ms.Count(); i++)
                {
                    var m = mod.FailList.FirstOrDefault(c => c.ID == ms[i] && c.Type == Hydro.Core.ObjectEnum.FailType.缺少Node1或Node2连接属性);
                    mod.FailList.Remove(m);
                }
 
                pipes.ForEach(c =>
                {
                    nw.AddJunction(new Hydro.Revit.Model.JunctionViewModel()
                    {
                        ID = "10000" + c.ID,
                        Name = "闷头",
                        Elev = 0,
                        PositionJson = c.PositionJson,
                        Floor = c.Floor,
                        SystemType = c.SystemType,
                    });
                    if (string.IsNullOrEmpty(c.Node1)) c.Node1 = "10000" + c.ID;
                    if (string.IsNullOrEmpty(c.Node2)) c.Node2 = "10000" + c.ID;
                });
            }
            this.model.Result = !mod.FailList.Any();
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = this.model.FailList;
            dataGridView1.Refresh();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            //var j = JsonHelper.ReadJsonFile("d:\\revitMFire.json");
            //var r = JsonHelper.ToObject<NetWorkOutViewModel>(j);
            ReCheck();
 
            //if (this.model.Result)
            //{
            var json = JsonHelper.ToJson(_form_SystemSelect._revitNetWork);
 
            JsonHelper.WriteJson("d:\\revitMFire.json", json);
            _form_SystemSelect._revitNetWork.BuildToInp("d:\\mfire.inp");
            //}
            // else
            //    MessageBox.Show("检验未通过,不能导出");
 
        }
 
        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
 
        }
    }
}