Fixed bug in EN_deletelink (#312)
This commit is contained in:
19
src/epanet.c
19
src/epanet.c
@@ -5280,10 +5280,11 @@ int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, ch
|
|||||||
|
|
||||||
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index) {
|
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index) {
|
||||||
int i;
|
int i;
|
||||||
|
int pumpindex;
|
||||||
|
int valveindex;
|
||||||
|
|
||||||
EN_LinkType linkType;
|
EN_LinkType linkType;
|
||||||
|
|
||||||
EN_Project *p = (EN_Project*)ph;
|
EN_Project *p = (EN_Project*)ph;
|
||||||
|
|
||||||
EN_Network *net = &p->network;
|
EN_Network *net = &p->network;
|
||||||
Slink *link;
|
Slink *link;
|
||||||
|
|
||||||
@@ -5293,14 +5294,12 @@ int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index) {
|
|||||||
return set_error(p->error_handle, 203);
|
return set_error(p->error_handle, 203);
|
||||||
|
|
||||||
EN_getlinktype(p, index, &linkType);
|
EN_getlinktype(p, index, &linkType);
|
||||||
|
|
||||||
link = &net->Link[index];
|
link = &net->Link[index];
|
||||||
|
|
||||||
// remove from hash table
|
// remove from hash table
|
||||||
hashtable_delete(net->LinkHashTable, link->ID);
|
hashtable_delete(net->LinkHashTable, link->ID);
|
||||||
|
|
||||||
// shift link and pump arrays to re-sort link indices
|
// shift link and pump arrays to re-sort link indices
|
||||||
net->Nlinks--;
|
|
||||||
for (i = index; i <= net->Nlinks - 1; i++) {
|
for (i = index; i <= net->Nlinks - 1; i++) {
|
||||||
net->Link[i] = net->Link[i + 1];
|
net->Link[i] = net->Link[i + 1];
|
||||||
// update hashtable
|
// update hashtable
|
||||||
@@ -5317,25 +5316,27 @@ int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove any pump associated with the deleted link
|
||||||
// update pumps
|
|
||||||
if (linkType == EN_PUMP) {
|
if (linkType == EN_PUMP) {
|
||||||
int pumpindex = findpump(net,index);
|
pumpindex = findpump(net,index);
|
||||||
for (i = pumpindex; i <= net->Npumps - 1; i++) {
|
for (i = pumpindex; i <= net->Npumps - 1; i++) {
|
||||||
net->Pump[i] = net->Pump[i + 1];
|
net->Pump[i] = net->Pump[i + 1];
|
||||||
}
|
}
|
||||||
net->Npumps--;
|
net->Npumps--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update valves
|
// remove any valve associated with the deleted link
|
||||||
if (linkType > EN_PUMP) {
|
if (linkType > EN_PUMP) {
|
||||||
int valveindex = findvalve(net,index);
|
valveindex = findvalve(net,index);
|
||||||
for (i = valveindex; i <= net->Nvalves - 1; i++) {
|
for (i = valveindex; i <= net->Nvalves - 1; i++) {
|
||||||
net->Valve[i] = net->Valve[i + 1];
|
net->Valve[i] = net->Valve[i + 1];
|
||||||
}
|
}
|
||||||
net->Nvalves--;
|
net->Nvalves--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reduce total link count
|
||||||
|
net->Nlinks--;
|
||||||
|
|
||||||
return set_error(p->error_handle, 0);
|
return set_error(p->error_handle, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user