From a66f5a2c9226b68147753de9961c764040cf283d Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Tue, 18 Dec 2018 15:35:06 -0500 Subject: [PATCH] Checks addded to prevent changing network structure when solver active (#361) --- src/epanet.c | 28 +++++++++++++++++++++++----- src/errors.dat | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 9f2d13b..265e69f 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -1542,8 +1542,11 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, EN_NodeType nodeType) Snode *node; Scontrol *control; - // Check if a node with same id already exists + // Cannot modify network structure while solvers are active if (!p->Openflag) return 102; + if (hyd->OpenHflag || qual->OpenQflag) return 262; + + // Check if a node with same id already exists if (EN_getnodeindex(p, id, &i) == 0) return 215; // Check that id name is not too long @@ -1670,8 +1673,11 @@ int DLLEXPORT EN_deletenode(EN_Project p, int index, int actionCode) Pdemand demand, nextdemand; Psource source; - // Check that node exists + // Cannot modify network structure while solvers are active if (!p->Openflag) return 102; + if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262; + + // Check that node exists if (index <= 0 || index > net->Nnodes) return 203; if (actionCode < EN_UNCONDITIONAL || actionCode > EN_CONDITIONAL) return 251; @@ -2591,8 +2597,11 @@ int DLLEXPORT EN_addlink(EN_Project p, char *id, EN_LinkType linkType, Slink *link; Spump *pump; - // Check if a link with same id already exists + // Cannot modify network structure while solvers are active if (!p->Openflag) return 102; + if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262; + + // Check if a link with same id already exists if (EN_getlinkindex(p, id, &i) == 0) return 215; // Lookup the link's from and to nodes @@ -2708,8 +2717,11 @@ int DLLEXPORT EN_deletelink(EN_Project p, int index, int actionCode) EN_LinkType linkType; Slink *link; - // Check that link exists + // Cannot modify network structure while solvers are active if (!p->Openflag) return 102; + if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262; + + // Check that link exists if (index <= 0 || index > net->Nlinks) 204; if (actionCode < EN_UNCONDITIONAL || actionCode > EN_CONDITIONAL) return 251; @@ -2887,8 +2899,11 @@ int DLLEXPORT EN_setlinktype(EN_Project p, int *index, EN_LinkType type, int act int errcode; EN_LinkType oldtype; - // Check for valid input parameters + // Cannot modify network structure while solvers are active if (!p->Openflag) return 102; + if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262; + + // Check for valid input parameters if (type < 0 || type > GPV || actionCode < EN_UNCONDITIONAL || actionCode > EN_CONDITIONAL) { @@ -2966,6 +2981,9 @@ int DLLEXPORT EN_setlinknodes(EN_Project p, int index, int node1, int node2) Network *net = &p->network; int type; + // Cannot modify network structure while solvers are active + if (p->hydraul.OpenHflag || p->quality.OpenQflag) return 262; + // Check that nodes exist if (node1 < 0 || node1 > net->Nnodes) return 203; if (node2 < 0 || node2 > net->Nnodes) return 203; diff --git a/src/errors.dat b/src/errors.dat index 3e8b448..842f59b 100644 --- a/src/errors.dat +++ b/src/errors.dat @@ -58,6 +58,7 @@ DAT(257,"nonexistent rule") DAT(258,"nonexistent rule clause") DAT(260,"attempt to delete node assigned as a Trace Node") DAT(261,"attempt to delete a node or link contained in a control") +DAT(262,"attempt to modify network structure while solver is active") // File errors DAT(301,"identical file names")