From 6316f6757d18adbf093a1a1cceed93ffa19fb085 Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Mon, 27 Aug 2018 16:02:00 -0400 Subject: [PATCH 1/2] re-adds header/dat files to IDE cmake output --- .gitignore | 2 +- CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9359679..6fa430d 100755 --- a/.gitignore +++ b/.gitignore @@ -61,7 +61,7 @@ xcuserdata [Dd]ebug/ [Rr]elease/ x64/ -#build/ +build/ [Bb]in/ [Oo]bj/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 466e964..a3f0e50 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ source_group("Library" FILES ${EPANET_LIB_ALL}) # the shared library -add_library(epanet SHARED ${EPANET_SOURCES}) #${EPANET_API_HEADER}) +add_library(epanet SHARED ${EPANET_LIB_ALL}) #${EPANET_API_HEADER}) target_include_directories(epanet PUBLIC ${PROJECT_SOURCE_DIR}/include) From 8f69f2f975026475d6ca5af742c987d915d09d32 Mon Sep 17 00:00:00 2001 From: Sam Hatchett Date: Mon, 27 Aug 2018 16:28:27 -0400 Subject: [PATCH 2/2] re-index nodes in controls/rules fixes #172 but opens another issue. --- src/epanet.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/epanet.c b/src/epanet.c index 6463c08..d33d311 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -4614,6 +4614,10 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) { Stank *tank; Snode *node; Scoord *coord; + Scontrol *control; + rules_t *rule; + Premise *pchain, *pnext; + /* Check if a node with same id already exists */ if (!p->Openflag) @@ -4664,6 +4668,53 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) { 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 { nIdx = net->Nnodes+1; node = &net->Node[nIdx]; @@ -4908,6 +4959,8 @@ int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int index) { EN_getnodetype(p, index, &nodeType); + // TODO: check for existing controls/rules that reference this node? + // remove from hash table ENHashTableDelete(net->NodeHashTable, net->Node[index].ID);