Merge pull request #555 from OpenWaterAnalytics/lrossman-EN_getrule

EN_getrule bug fix and EN_MISSING addition
This commit is contained in:
Lew Rossman
2019-11-08 09:55:59 -05:00
committed by GitHub
6 changed files with 23 additions and 20 deletions

View File

@@ -298,6 +298,7 @@ These are the toolkit's enumerated types whose members are used as function argu
\enum EN_RuleVariable \enum EN_RuleVariable
\enum EN_RuleOperator \enum EN_RuleOperator
\enum EN_RuleStatus \enum EN_RuleStatus
\def EN_MISSING
@} @}
*/ */

View File

@@ -5,7 +5,7 @@ Attribute VB_Name = "Module1"
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT 'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL) '(EPANET2.DLL)
'Last updated on 10/29/2019 'Last updated on 11/04/2019
' These are codes used by the DLL functions ' These are codes used by the DLL functions
Public Const EN_ELEVATION = 0 ' Node parameters Public Const EN_ELEVATION = 0 ' Node parameters
@@ -239,6 +239,8 @@ Public Const EN_R_IS_OPEN = 1 ' Rule status types
Public Const EN_R_IS_CLOSED = 2 Public Const EN_R_IS_CLOSED = 2
Public Const EN_R_IS_ACTIVE = 3 Public Const EN_R_IS_ACTIVE = 3
Public Const EN_MISSING As Double = -1.0E10
'These are the external functions that comprise the DLL 'These are the external functions that comprise the DLL
'Project Functions 'Project Functions

View File

@@ -3,7 +3,7 @@ unit epanet2;
{ Declarations of imported procedures from the EPANET PROGRAMMERs TOOLKIT } { Declarations of imported procedures from the EPANET PROGRAMMERs TOOLKIT }
{ (EPANET2.DLL) } { (EPANET2.DLL) }
{Last updated on 11/02/19} {Last updated on 11/04/19}
interface interface
@@ -12,6 +12,7 @@ const
{ These are codes used by the DLL functions } { These are codes used by the DLL functions }
EN_MAXID = 31; { Max. # characters in ID name } EN_MAXID = 31; { Max. # characters in ID name }
EN_MAXMSG = 255; { Max. # characters in strings } EN_MAXMSG = 255; { Max. # characters in strings }
EN_MISSING = -1.E10;
EN_ELEVATION = 0; { Node parameters } EN_ELEVATION = 0; { Node parameters }
EN_BASEDEMAND = 1; EN_BASEDEMAND = 1;
@@ -331,7 +332,7 @@ const
function ENgetnumdemands(NodeIndex: Integer; var NumDemands: Integer): Integer; stdcall; external EpanetLib; function ENgetnumdemands(NodeIndex: Integer; var NumDemands: Integer): Integer; stdcall; external EpanetLib;
function ENadddemand(NodeIndex: Integer; BaseDemand: Single; PatIndex: Integer; DemandName: PAnsiChar): Integer; stdcall; external EpanetLib; function ENadddemand(NodeIndex: Integer; BaseDemand: Single; PatIndex: Integer; DemandName: PAnsiChar): Integer; stdcall; external EpanetLib;
function ENdeletedemand(NodeIndex: Integer; DemandIndex: Integer): Integer; stdcall; external EpanetLib; function ENdeletedemand(NodeIndex: Integer; DemandIndex: Integer): Integer; stdcall; external EpanetLib;
function ENgetdemandindex(NodeIndex: Integer; DemandName: PAnsiString; var DemandIndex: Integer): Integer; stdcall; external EpanetLib; function ENgetdemandindex(NodeIndex: Integer; DemandName: PAnsiChar; var DemandIndex: Integer): Integer; stdcall; external EpanetLib;
function ENgetbasedemand(NodeIndex: Integer; DemandIndex: Integer; var BaseDemand: Single): Integer; stdcall; external EpanetLib; function ENgetbasedemand(NodeIndex: Integer; DemandIndex: Integer; var BaseDemand: Single): Integer; stdcall; external EpanetLib;
function ENsetbasedemand(NodeIndex: Integer; DemandIndex: Integer; BaseDemand: Single): Integer; stdcall; external EpanetLib; function ENsetbasedemand(NodeIndex: Integer; DemandIndex: Integer; BaseDemand: Single): Integer; stdcall; external EpanetLib;
function ENgetdemandpattern(NodeIndex: Integer; DemandIndex: Integer; var PatIndex: Integer): Integer; stdcall; external EpanetLib; function ENgetdemandpattern(NodeIndex: Integer; DemandIndex: Integer; var PatIndex: Integer): Integer; stdcall; external EpanetLib;
@@ -394,11 +395,11 @@ const
function ENsetcontrol(Index: Integer; Ctype: Integer; Link: Integer; Setting: Single; Node: Integer; Level: Single): Integer; stdcall; external EpanetLib; function ENsetcontrol(Index: Integer; Ctype: Integer; Link: Integer; Setting: Single; Node: Integer; Level: Single): Integer; stdcall; external EpanetLib;
{Rule-Based Control Functions} {Rule-Based Control Functions}
function ENaddrule(Rule: PAnsiString): Integer; stdcall; external EpanetLib; function ENaddrule(Rule: PAnsiChar): Integer; stdcall; external EpanetLib;
function ENdeleterule(Index: Integer): Integer; stdcall; external EpanetLib; function ENdeleterule(Index: Integer): Integer; stdcall; external EpanetLib;
function ENgetrule(Index: Integer; var Npremises: Integer; var NthenActions: Integer; function ENgetrule(Index: Integer; var Npremises: Integer; var NthenActions: Integer;
var NelseActions: Integer; var Priority: Single): Integer; stdcall; external EpanetLib; var NelseActions: Integer; var Priority: Single): Integer; stdcall; external EpanetLib;
function ENgetruleID(Index: Integer; ID: PAnsiString): Integer; stdcall; external EpanetLib; function ENgetruleID(Index: Integer; ID: PAnsiChar): Integer; stdcall; external EpanetLib;
function ENsetrulepriority(Index: Integer; Priority: Single): Integer; stdcall; external EpanetLib; function ENsetrulepriority(Index: Integer; Priority: Single): Integer; stdcall; external EpanetLib;
function ENgetpremise(RuleIndex: Integer; PremiseIndex: Integer; var LogOp: Integer; function ENgetpremise(RuleIndex: Integer; PremiseIndex: Integer; var LogOp: Integer;
var ObjType: Integer; var ObjIndex: Integer; var Param: Integer; var RelOp: Integer; var ObjType: Integer; var ObjIndex: Integer; var Param: Integer; var RelOp: Integer;

View File

@@ -4,7 +4,7 @@
'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT 'Declarations of functions in the EPANET PROGRAMMERs TOOLKIT
'(EPANET2.DLL) for use with VB.Net. '(EPANET2.DLL) for use with VB.Net.
'Last updated on 10/29/2019 'Last updated on 11/04/2019
Imports System.Runtime.InteropServices Imports System.Runtime.InteropServices
Imports System.Text Imports System.Text
@@ -244,6 +244,8 @@ Public Const EN_R_IS_OPEN = 1 ' Rule status types
Public Const EN_R_IS_CLOSED = 2 Public Const EN_R_IS_CLOSED = 2
Public Const EN_R_IS_ACTIVE = 3 Public Const EN_R_IS_ACTIVE = 3
Public Const EN_MISSING As Double = -1.0E10
'These are the external functions that comprise the DLL 'These are the external functions that comprise the DLL
'Project Functions 'Project Functions

View File

@@ -9,7 +9,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 07/22/2019 Last Updated: 11/06/2019
****************************************************************************** ******************************************************************************
*/ */
@@ -463,5 +463,6 @@ typedef enum {
EN_R_IS_ACTIVE = 3 //!< Control valve is active EN_R_IS_ACTIVE = 3 //!< Control valve is active
} EN_RuleStatus; } EN_RuleStatus;
#define EN_MISSING -1.E10 //!< Missing value indicator
#endif //EPANET2_ENUMS_H #endif //EPANET2_ENUMS_H

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 11/02/2019 Last Updated: 11/04/2019
****************************************************************************** ******************************************************************************
*/ */
@@ -5227,34 +5227,30 @@ int DLLEXPORT EN_getrule(EN_Project p, int index, int *nPremises,
if (index < 1 || index > net->Nrules) return 257; if (index < 1 || index > net->Nrules) return 257;
*priority = (double)p->network.Rule[index].priority; *priority = (double)p->network.Rule[index].priority;
count = 1; count = 0;
premise = net->Rule[index].Premises; premise = net->Rule[index].Premises;
while (premise->next != NULL) while (premise != NULL)
{ {
count++; count++;
premise = premise->next; premise = premise->next;
} }
*nPremises = count; *nPremises = count;
count = 1; count = 0;
action = net->Rule[index].ThenActions; action = net->Rule[index].ThenActions;
while (action->next != NULL) while (action != NULL)
{ {
count++; count++;
action = action->next; action = action->next;
} }
*nThenActions = count; *nThenActions = count;
action = net->Rule[index].ElseActions;
count = 0; count = 0;
if (action != NULL) action = net->Rule[index].ElseActions;
while (action != NULL)
{ {
count = 1; count++;
while (action->next != NULL) action = action->next;
{
count++;
action = action->next;
}
} }
*nElseActions = count; *nElseActions = count;
return 0; return 0;