Merge pull request #238 from OpenWaterAnalytics/issue-172

Issue 172
This commit is contained in:
Michael Tryby
2018-09-04 15:12:03 -04:00
committed by GitHub
3 changed files with 55 additions and 2 deletions

2
.gitignore vendored
View File

@@ -61,7 +61,7 @@ xcuserdata
[Dd]ebug/ [Dd]ebug/
[Rr]elease/ [Rr]elease/
x64/ x64/
#build/ build/
[Bb]in/ [Bb]in/
[Oo]bj/ [Oo]bj/

View File

@@ -75,7 +75,7 @@ source_group("Library" FILES ${EPANET_LIB_ALL})
# the shared library # the shared library
add_library(epanet SHARED ${EPANET_SOURCES}) add_library(epanet SHARED ${EPANET_LIB_ALL})
target_include_directories(epanet PUBLIC ${PROJECT_SOURCE_DIR}/include) target_include_directories(epanet PUBLIC ${PROJECT_SOURCE_DIR}/include)

View File

@@ -4680,6 +4680,10 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
Stank *tank; Stank *tank;
Snode *node; Snode *node;
Scoord *coord; Scoord *coord;
Scontrol *control;
rules_t *rule;
Premise *pchain, *pnext;
/* Check if a node with same id already exists */ /* Check if a node with same id already exists */
if (!p->Openflag) if (!p->Openflag)
@@ -4730,6 +4734,53 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
net->Link[index].N2 += 1; net->Link[index].N2 += 1;
} }
} }
// shift indices of Controls,
// for high-index nodes (tanks/reservoirs)
for (index = 1; index <= net->Ncontrols; ++index) {
control = &net->Control[index];
if (control->Node > net->Njuncs - 1) {
control->Node += 1;
}
}
// shift indices of Rules for tanks/reservoirs
for (index = 1; index <= net->Nrules; ++index) {
pchain = (&p->rules)->Rule[i].Pchain;
while (pchain != NULL) {
pnext = pchain->next;
// object types are: (duplicated here from rules.c --> TODO: move these to external definition?
// enum Objects {
// r_JUNC,
// r_RESERV,
// r_TANK,
// r_PIPE,
// r_PUMP,
// r_VALVE,
// r_NODE,
// r_LINK,
// r_SYSTEM
// };
// if object is a node
switch (pchain->object) {
case 0: // junc
case 1: // reservoir
case 2: // tank
case 6: // node
// if the junction needs to be re-indexed:
if (pchain->index > net->Njuncs) {
pchain->index += 1;
}
break;
default:
break;
}
// next premise in the chain
pchain = pnext;
}
}
} else { } else {
nIdx = net->Nnodes+1; nIdx = net->Nnodes+1;
node = &net->Node[nIdx]; node = &net->Node[nIdx];
@@ -4966,6 +5017,8 @@ int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int index) {
EN_getnodetype(p, index, &nodeType); EN_getnodetype(p, index, &nodeType);
// TODO: check for existing controls/rules that reference this node?
// remove from hash table // remove from hash table
ENHashTableDelete(net->NodeHashTable, net->Node[index].ID); ENHashTableDelete(net->NodeHashTable, net->Node[index].ID);