From a46652f47c80edcb902563ebe0738849e4ebaf2b Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Tue, 17 Apr 2018 21:46:09 +0300 Subject: [PATCH] Fix bug when adding a junction --- src/epanet.c | 15 ++++++++------- win_build/WinSDK/epanet2.def | 7 ++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 77ae5cc..ade6969 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -4157,13 +4157,12 @@ int DLLEXPORT EN_addnode(EN_Project *p, char *id, EN_NodeType nodeType) { qu->NodeQual = (double *)realloc(qu->NodeQual, (net->Nnodes + 2) * sizeof(double)); hyd->NodeHead = (double *)realloc(hyd->NodeHead, (net->Nnodes + 2) * sizeof(double)); - nIdx = net->Nnodes + 1; - node = &net->Node[nIdx]; - coord = &net->Coord[nIdx]; - if (nodeType == EN_JUNCTION) { net->Njuncs++; - + nIdx = net->Njuncs; + node = &net->Node[nIdx]; + coord = &net->Coord[nIdx]; + demand = (struct Sdemand *)malloc(sizeof(struct Sdemand)); demand->Base = 0.0; demand->Pat = 0; @@ -4191,6 +4190,9 @@ int DLLEXPORT EN_addnode(EN_Project *p, char *id, EN_NodeType nodeType) { } } } else { + nIdx = net->Nnodes++; + node = &net->Node[nIdx]; + coord = &net->Coord[nIdx]; net->Ntanks++; /* resize tanks array */ @@ -4231,8 +4233,7 @@ int DLLEXPORT EN_addnode(EN_Project *p, char *id, EN_NodeType nodeType) { node->C0 = 0; node->Ke = 0; node->Rpt = 0; - - + coord->HaveCoords = FALSE; coord->X = 0; coord->Y = 0; diff --git a/win_build/WinSDK/epanet2.def b/win_build/WinSDK/epanet2.def index f6376d6..09acdb7 100644 --- a/win_build/WinSDK/epanet2.def +++ b/win_build/WinSDK/epanet2.def @@ -87,4 +87,9 @@ EXPORTS ENgetfalseaction = _ENgetfalseaction@20 ENsetfalseaction = _ENsetfalseaction@20 ENgetruleID = _ENgetruleID@8 - ENsetflowunits = _ENsetflowunits@4 \ No newline at end of file + ENsetflowunits = _ENsetflowunits@4 + ENaddnode = _ENaddnode@8 + ENaddlink = _ENaddlink@16 + ENdeletelink = _ENdeletelink@4 + ENdeletenode = _ENdeletenode@4 + ENsetlinktype = _ENsetlinktype@8 \ No newline at end of file