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
#include "CivTrackingAnalysis.h"
#include "CivSimulResultCache.h"
#include "CivHydrSimulation.h"
#include "CivInpConvertor.h"
#include "CivInpDbHelper.h"
CivTrackingAnalysis::CivTrackingAnalysis(const std::string& uri)
:mGraph(new ALGraph<CivGraphJunction, CivGraphEdage>()),mUri(uri)
{
}
CivTrackingAnalysis::~CivTrackingAnalysis()
{
delete mGraph;
}
bool CivTrackingAnalysis::createGraphFrom()
{
CivInpConvertor convertor(mUri);
std::string inpFile = convertor.convertTrackInp("", "0");
if (inpFile.empty())
return false;
CivHydrCompute dyCompute;
if (!dyCompute.hdyrCompute())
return false;
NodeResultItems nodeItems;
LinkResultItems linkItems;
dyCompute.getNodeItemByInterval(0, nodeItems);
dyCompute.getPipeItemByInterval(0, linkItems);
if (nodeItems.size() <= 0)
return false;
// 顶点坐标
CivCoordinates coords;
CivInpDbHelper helper(mUri);
helper.getCoordinates(coords);
std::list<CivCoordinates::CoordTable> coordTableLis = coords.mTables;
std::list<CivCoordinates::CoordTable>::iterator iter;
for (iter = coordTableLis.begin(); iter != coordTableLis.end(); iter++)
{
CivCoordinates::CoordTable coordTable = *iter;
// 插入顶点数据
CivGraphJunction graphJunction(coordTable.ID, coordTable.XCoord, coordTable.YCoord);
auto iter = nodeItems.find(coordTable.ID);
if (iter != nodeItems.end())
{
graphJunction.setHead(iter->second.dHead);
}
mGraph->insertAVertex(graphJunction);
}
// 管段
CivPipe civPipe;
helper.getPipe(civPipe);
std::list<CivPipe::PipesTable> pipesTableLis = civPipe.mTables;
std::list<CivPipe::PipesTable>::iterator pIter;
for (pIter = pipesTableLis.begin(); pIter != pipesTableLis.end(); pIter++)
{
CivPipe::PipesTable pipeTable = *pIter;
// 获取管段起点坐标
CivGraphJunction graphJunction1(pipeTable.Node1);
int index1 = mGraph->getVertexIndex(graphJunction1);
CivGraphJunction sStartjuction = mGraph->getData(index1);
// 获取管段终点坐标值
CivGraphJunction graphJunction2(pipeTable.Node2);
int index2 = mGraph->getVertexIndex(graphJunction2);
CivGraphJunction endJunction = mGraph->getData(index2);
if (sStartjuction.getHead() > endJunction.getHead())
{
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, { sStartjuction.getXCoord(),sStartjuction.getYCoord(),endJunction.getXCoord(),endJunction.getYCoord() });
mGraph->insertAEdge(sStartjuction, endJunction, edAge);
}
else if (sStartjuction.getHead() == endJunction.getHead())
{
CivGraphEdage edAge1(pipeTable.ID, pipeTable.Length, { sStartjuction.getXCoord(),sStartjuction.getYCoord(),endJunction.getXCoord(),endJunction.getYCoord() });
mGraph->insertAEdge(sStartjuction, endJunction, edAge1);
CivGraphEdage edAge2(pipeTable.ID, pipeTable.Length, { endJunction.getXCoord(),endJunction.getYCoord(), sStartjuction.getXCoord(),sStartjuction.getYCoord() });
mGraph->insertAEdge(endJunction, sStartjuction, edAge2);
}
else
{
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, { endJunction.getXCoord(),endJunction.getYCoord(), sStartjuction.getXCoord(),sStartjuction.getYCoord() });
mGraph->insertAEdge(endJunction, sStartjuction, edAge);
}
}
return true;
}
bool CivTrackingAnalysis::transformJson(const std::vector<CivGraphJunction>& junctions,
const std::vector<CivGraphEdage>& pipes, std::string& jsonResult)
{
jsonResult.append("[");
// 管段
size_t pipesTotal = pipes.size();
for (int i = 0; i < pipesTotal; i++)
{
CivGraphEdage edge = pipes[i];
if (edge.getSN().empty())
continue;
jsonResult.append("[[");
jsonResult.append(edge.getStartX());
jsonResult.append(",");
jsonResult.append(edge.getStartY());
jsonResult.append("],[");
jsonResult.append(edge.getEndX());
jsonResult.append(",");
jsonResult.append(edge.getEndY());
jsonResult.append("]],");
}
jsonResult = jsonResult.substr(0, jsonResult.length() - 1);
jsonResult.append("]");
return true;
}
bool CivTrackingAnalysis::upstreamTracking(const std::string& sN, std::string& jsonResult)
{
std::vector<CivGraphJunction> junctions;
std::vector<CivGraphEdage> edges;
if (!upstreamTracking(sN, junctions, edges))
{
return false;
}
// 将查询到的信息拼接成字符串
if (!transformJson(junctions, edges, jsonResult))
{
return false;
}
return true;
}
bool CivTrackingAnalysis::downstreamTracking(const std::string& sN, std::string& jsonResult)
{
std::vector<CivGraphJunction> junctions;
std::vector<CivGraphEdage> edges;
if (!downstreamTracking(sN, junctions, edges))
{
return false;
}
// 将查询到的信息拼接成字符串
if (!transformJson(junctions, edges,jsonResult))
{
return false;
}
return true;
}
bool CivTrackingAnalysis::waterSupplyScopeAnalysis(const std::string& sN, std::string& jsonResult)
{
return true;
}
bool CivTrackingAnalysis::upstreamTracking(const std::string& sN,
std::vector<CivGraphJunction>& junctions,
std::vector<CivGraphEdage>& pipes)
{
// 上溯,图反向
ALGraph<CivGraphJunction, CivGraphEdage>* graph = mGraph->reverseGraph();
CivGraphJunction junction(sN);
graph->getVisitedResult(junction, junctions, pipes);
delete graph;
return true;
}
bool CivTrackingAnalysis::downstreamTracking(const std::string& sN,
std::vector<CivGraphJunction>& junctions,
std::vector<CivGraphEdage>& pipes)
{
CivGraphJunction junction(sN);
mGraph->getVisitedResult(junction, junctions, pipes);
return true;
}
bool CivTrackingAnalysis::waterSupplyScopeAnalysis(const std::string& sN,
std::vector<CivGraphJunction>& junctions,
std::vector<CivGraphEdage>& pipes)
{
return true;
}