Fixes bug #172 (adjust controls & rules when node/link added or deleted)

- Also adds new API function EN_deletecontrol
- Updates and re-arranges entries in the VBA and VB.Net headers
This commit is contained in:
Lew Rossman
2018-10-31 11:32:01 -04:00
parent 5ddb54ab90
commit ee335ab077
7 changed files with 535 additions and 331 deletions

View File

@@ -175,11 +175,15 @@ Public Const EN_G_CURVE = 4 ' General\default curve
'These are the external functions that comprise the DLL
'System Functions
Declare Function ENgetversion Lib "epanet2.dll" (value As Long) As Long
Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As Any) As Long
Declare Function ENinit Lib "epanet2.dll" (ByVal rptFile As String, ByVal binOutFile As String, ByVal UnitsType As Long, ByVal HeadlossFormula As Long) As Long
Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Long
Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Long
Declare Function ENclose Lib "epanet2.dll" () As Long
'Hydraulic Analysis Functions
Declare Function ENsolveH Lib "epanet2.dll" () As Long
Declare Function ENsaveH Lib "epanet2.dll" () As Long
Declare Function ENopenH Lib "epanet2.dll" () As Long
@@ -190,6 +194,7 @@ Public Const EN_G_CURVE = 4 ' General\default curve
Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Long
Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Long
'Water Quality Analysis Functions
Declare Function ENsolveQ Lib "epanet2.dll" () As Long
Declare Function ENopenQ Lib "epanet2.dll" () As Long
Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Long) As Long
@@ -198,82 +203,97 @@ Public Const EN_G_CURVE = 4 ' General\default curve
Declare Function ENstepQ Lib "epanet2.dll" (Tleft As Long) As Long
Declare Function ENcloseQ Lib "epanet2.dll" () As Long
'Reporting Functions
Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Long
Declare Function ENreport Lib "epanet2.dll" () As Long
Declare Function ENresetreport Lib "epanet2.dll" () As Long
Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Long
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, Ctype As Long, Lindex As Long, setting As Single, Nindex As Long, Level As Single) As Long
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENgetcount Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) As Long
'Analysis Options Functions
Declare Function ENgetoption Lib "epanet2.dll" (ByVal code As Long, value As Single) As Long
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long
Declare Function ENsetoption Lib "epanet2.dll" (ByVal code As Long, ByVal value As Single) As Long
Declare Function ENgetflowunits Lib "epanet2.dll" (code As Long) As Long
Declare Function ENsetflowunits Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal code As Long, value As Long) As Long
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal code As Long, ByVal value As Long) As Long
Declare Function ENgetqualtype Lib "epanet2.dll" (QualCode As Long, TraceNode As Long) As Long
Declare Function ENgetqualinfo Lib "epanet2.dll" (QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, TraceNode As Long) As Long
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Long
'Basic Node Functions
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Long) As Long
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal linkIndex As Long) As Long
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENsetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal newid As String) As Long
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal index As Long, X As Single, Y As Single) As Long
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Long, ByVal X As Single, ByVal Y As Single) As Long
'Nodal Demand Functions
Declare Function ENgetdemandmodel Lib "epanet2.dll" (mtype As Long, pmin As Single, preq As Single, pexp As Single) As Long
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal mtype As Long, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Long
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal index As Long, numDemands As Long) As Long
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, value As Single) As Long
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, ByVal BaseDemand As Single) As Long
Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, PatIndex As Long) As Long
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal Index As Long, ByVal DemandIndex As Long, ByVal PatIndex As Long) As Long
Declare Function ENgetdemandname Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
'Basic Link Functions
Declare Function ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Long, ByVal fromNode As String, ByVal toNode As String) As Long
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal nodeIndex As Long) As Long
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENsetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal newid As String) As Long
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENsetlinktype Lib "epanet2.dll" (index As Long, ByVal code As Long) As Long
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal index As Long, Node1 As Long, Node2 As Long) As Long
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Long, ByVal node1 As Long, ByVal node2 As Long) As Long
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
'Pump Functions
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, curveIndex As Long) As Long
Declare Function ENsetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, ByVal curveIndex As Long) As Long
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal index As Long, PumpType As Long) As Long
'Time Pattern Functions
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal id As String) As Long
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal index As Long, L As Long) As Long
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal Period As Long, value As Single) As Long
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Long, value As Single) As Long
Declare Function ENgetqualtype Lib "epanet2.dll" (QualCode As Long, TraceNode As Long) As Long
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Long, ByVal ErrMsg As String, ByVal N As Long) As Long
Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal code As Long, value As Single) As Long
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal index As Long, X As Single, Y As Single) As Long
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal index As Long, ByVal X As Single, ByVal Y As Single) As Long
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal index As Long, numDemands As Long) As Long
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, value As Single) As Long
Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, PatIndex As Long) As Long
Declare Function ENgetdemandname Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal DemandIndex As Long, ByVal demandName As String) As Long
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal index As Long, code As Long) As Long
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal index As Long, Node1 As Long, Node2 As Long) As Long
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, value As Single) As Long
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal curveIndex As Long, ByVal CurveID As String, nValues As Long, xValues As Any, yValues As Any) As Long
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, curveIndex As Long) As Long
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal index As Long, PumpType As Long) As Long
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal curveIndex As Long, CurveType As Long) As Long
Declare Function ENgetversion Lib "epanet2.dll" (value As Long) As Long
Declare Function ENgetdemandmodel Lib "epanet2.dll" (mtype As Long, pmin As Single, preq As Single, pexp As Single) As Long
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal mtype As Long, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Long
Declare Function ENsetflowunits Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENaddcontrol Lib "epanet2.dll" (Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
Declare Function ENsetnodeid Lib "epanet2.dll" (ByVal index As Long, ByVal newid As String) As Long
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENsetlinkid Lib "epanet2.dll" (ByVal index As Long, ByVal newid As String) As Long
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal index As Long, ByVal code As Long, ByVal value As Single) As Long
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal id As String) As Long
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Long, F As Any, ByVal N As Long) As Long
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal index As Long, ByVal Period As Long, ByVal value As Single) As Long
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal code As Long, ByVal value As Long) As Long
Declare Function ENsetoption Lib "epanet2.dll" (ByVal code As Long, ByVal value As Single) As Long
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal code As Long) As Long
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Long
Declare Function ENgetqualinfo Lib "epanet2.dll" (QualCode As Long, ByVal ChemName As String, ByVal ChemUnits As String, TraceNode As Long) As Long
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal DemandIndex As Long, ByVal BaseDemand As Single) As Long
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal index As Long, ByVal DemandIndex As Long, ByVal PatIndex As Long) As Long
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Long, value As Single) As Long
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal index As Long, F As Any, ByVal N As Long) As Long
'Data Curve Functions
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal id As String) As Long
Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal id As String, index As Long) As Long
Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal index As Long, ByVal id As String) As Long
Declare Function ENgetcurvelen Lib "epanet2.dll" (ByVal index As Long, L As Long) As Long
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal curveIndex As Long, CurveType As Long) As Long
Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal index As Long, ByVal Ptn As Long, X As Single, Y As Single) As Long
Declare Function ENsetcurvevalue Lib "epanet2.dll" (ByVal index As Long, ByVal Ptn As Long, ByVal X As Single, ByVal Y As Single) As Long
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal curveIndex As Long, ByVal CurveID As String, nValues As Long, xValues As Any, yValues As Any) As Long
Declare Function ENsetcurve Lib "epanet2.dll" (ByVal index As Long, X As Any, Y As Any, ByVal N As Long) As Long
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal id As String) As Long
'Simple Control Functions
Declare Function ENaddcontrol Lib "epanet2.dll" (Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
Declare Function ENdeletecontrol Lib "epanet2.dll" (ByVal Cindex as Long) As Long
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, Ctype As Long, Lindex As Long, setting As Single, Nindex As Long, Level As Single) As Long
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Long, ByVal Ctype As Long, ByVal Lindex As Long, ByVal setting As Single, ByVal Nindex As Long, ByVal Level As Single) As Long
'Rue-Based Control Functions
Declare Function ENgetrule Lib "epanet2.dll" (ByVal index As Long, nPremises As Long, nTrueActions As Long, nFalseActions As Long, priority As Single) As Long
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Long, ByVal id As String) As Long
Declare Function ENsetrulepriority Lib "epanet2.dll" (ByVal index As Long, ByVal priority As Single) As Long
Declare Function ENgetpremise Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexPremise As Long, logop As Long, object As Long, indexObj As Long, variable As Long, relop As Long, status As Long, value As Single) As Long
Declare Function ENsetpremise Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexPremise As Long, ByVal logop As Long, ByVal object As Long, ByVal indexObj As Long, ByVal variable As Long, ByVal relop As Long, ByVal status As Long, ByVal value As Single) As Long
@@ -284,13 +304,3 @@ Public Const EN_G_CURVE = 4 ' General\default curve
Declare Function ENsettrueaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, ByVal indexLink As Long, ByVal status As Long, ByVal setting As Single) As Long
Declare Function ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, indexLink As Long, status As Long, setting As Single) As Long
Declare Function ENsetfalseaction Lib "epanet2.dll" (ByVal indexRule As Long, ByVal indexAction As Long, ByVal indexLink As Long, ByVal status As Long, ByVal setting As Single) As Long
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Long, ByVal id As String) As Long
Declare Function ENinit Lib "epanet2.dll" (ByVal rptFile As String, ByVal binOutFile As String, ByVal UnitsType As Long, ByVal HeadlossFormula As Long) As Long
Declare Function ENsetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Long, ByVal curveIndex As Long) As Long
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Long, ByVal node1 As Long, ByVal node2 As Long) As Long
Declare Function ENsetlinktype Lib "epanet2.dll" (index As Long, ByVal code As Long) As Long
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Long) As Long
Declare Function ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Long, ByVal fromNode As String, ByVal toNode As String) As Long
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal nodeIndex As Long) As Long
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal linkIndex As Long) As Long

View File

@@ -833,6 +833,13 @@ extern "C" {
@return Error code.
*/
int DLLEXPORT ENaddcontrol(int *cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
/**
@brief Delete an existing simple control
@param cindex The index of the control. First control is index 1.
@return Error code.
*/
int DLLEXPORT ENdeletecontrol(int cindex);
/**
@brief Specify parameters to define a simple control
@@ -1371,6 +1378,7 @@ extern "C" {
int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, char *fromNode, char *toNode);
int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int nodeIndex);
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int linkIndex);
int DLLEXPORT EN_deletecontrol(EN_ProjectHandle ph, int controlIndex);
#if defined(__cplusplus)
}

View File

@@ -39,6 +39,7 @@ Public Const EN_MIXFRACTION = 22
Public Const EN_TANK_KBULK = 23
Public Const EN_TANKVOLUME = 24 'ES
Public Const EN_MAXVOLUME = 25
Public Const EN_DIAMETER = 0 ' Link parameters
Public Const EN_LENGTH = 1
@@ -60,6 +61,9 @@ Public Const EN_EFFICIENCY = 16
Public Const EN_HEADCURVE = 17
Public Const EN_EFFICIENCYCURVE = 18
Public Const EN_PRICEPATTERN = 19
Public Const EN_STATE = 20
Public Const EN_CONST_POWER = 21
Public Const EN_SPEED = 22
Public Const EN_DURATION = 0 ' Time parameters
Public Const EN_HYDSTEP = 1
@@ -115,6 +119,10 @@ Public Const EN_MASS = 1
Public Const EN_SETPOINT = 2
Public Const EN_FLOWPACED = 3
Public Const EN_HW = 0 ' Head loss formula
Public Const EN_DW = 1
Public Const EN_CM = 2
Public Const EN_CFS = 0 ' Flow units types
Public Const EN_GPM = 1
Public Const EN_MGD = 2
@@ -126,6 +134,9 @@ Public Const EN_MLD = 7
Public Const EN_CMH = 8
Public Const EN_CMD = 9
Public Const EN_DDA = 0 ' Demand driven analysis
Public Const EN_PDA = 1 ' Pressure driven analysis
Public Const EN_TRIALS = 0 ' Misc. options
Public Const EN_ACCURACY = 1
Public Const EN_TOLERANCE = 2
@@ -159,13 +170,23 @@ Public Const EN_CONST_HP = 0 ' constant horsepower
Public Const EN_POWER_FUNC = 1 ' power function
Public Const EN_CUSTOM = 2 ' user-defined custom curve
Public Const EN_V_CURVE = 0 ' volume curve
Public Const EN_P_CURVE = 1 ' pump curve
Public Const EN_E_CURVE = 2 ' efficiency curve
Public Const EN_H_CURVE = 3 ' head loss curve
Public Const EN_G_CURVE = 4 ' General\default curve
'These are the external functions that comprise the DLL
'System Functions
Declare Function ENgetversion Lib "epanet2.dll" (ByRef Value As Int32) As Int32
Declare Function ENepanet Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String, ByVal F4 As String) As Int32
Declare Function ENinit Lib "epanet2.dll" (ByVal rptFile As String, ByVal binOutFile As String, ByVal UnitsType As Int32, ByVal HeadlossFormula As Int32) As Int32
Declare Function ENopen Lib "epanet2.dll" (ByVal F1 As String, ByVal F2 As String, ByVal F3 As String) As Int32
Declare Function ENsaveinpfile Lib "epanet2.dll" (ByVal F As String) As Int32
Declare Function ENclose Lib "epanet2.dll" () As Int32
'Hydraulic Analysis Functions
Declare Function ENsolveH Lib "epanet2.dll" () As Int32
Declare Function ENsaveH Lib "epanet2.dll" () As Int32
Declare Function ENopenH Lib "epanet2.dll" () As Int32
@@ -176,6 +197,7 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve
Declare Function ENsavehydfile Lib "epanet2.dll" (ByVal F As String) As Int32
Declare Function ENusehydfile Lib "epanet2.dll" (ByVal F As String) As Int32
'Water Quality Analysis Functions
Declare Function ENsolveQ Lib "epanet2.dll" () As Int32
Declare Function ENopenQ Lib "epanet2.dll" () As Int32
Declare Function ENinitQ Lib "epanet2.dll" (ByVal SaveFlag As Int32) As Int32
@@ -184,75 +206,98 @@ Public Const EN_CUSTOM = 2 ' user-defined custom curve
Declare Function ENstepQ Lib "epanet2.dll" (ByRef Tleft As Int32) As Int32
Declare Function ENcloseQ Lib "epanet2.dll" () As Int32
'Reporting Functions
Declare Function ENwriteline Lib "epanet2.dll" (ByVal S As String) As Int32
Declare Function ENreport Lib "epanet2.dll" () As Int32
Declare Function ENresetreport Lib "epanet2.dll" () As Int32
Declare Function ENsetreport Lib "epanet2.dll" (ByVal S As String) As Int32
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByRef CtlType As Int32, ByRef Lindex As Int32, ByRef Setting As Single, ByRef Nindex As Int32, ByRef Level As Single) As Int32
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Int32) As Int32
Declare Function ENgetcount Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32
Declare Function ENgetoption Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32
Declare Function ENgetflowunits Lib "epanet2.dll" (ByRef Code As Int32) As Int32
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByRef Value As Single) As Int32
Declare Function ENgetqualtype Lib "epanet2.dll" (ByRef QualCode As Int32, ByRef TraceNode As Int32) As Int32
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Int32, ByVal ErrMsg As StringBuilder, ByVal N As Int32)
Declare Function ENgeterror Lib "epanet2.dll" (ByVal ErrCode As Int32, ByVal ErrMsg As StringBuilder, ByVal N As Int32) As Int32
Declare Function ENgetstatistic Lib "epanet2.dll" (ByVal code As Int32, ByRef value As Single) As Int32
'Analysis Options Functions
Declare Function ENgetoption Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetoption Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENgetflowunits Lib "epanet2.dll" (ByRef Code As Int32) As Int32
Declare Function ENsetflowunits Lib "epanet2.dll" (ByVal code As Int32) As Int32
Declare Function ENgettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByRef Value As Int32) As Int32
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Int32) As Int32
Declare Function ENgetqualtype Lib "epanet2.dll" (ByRef QualCode As Int32, ByRef TraceNode As Int32) As Int32
Declare Function ENgetqualinfo Lib "epanet2.dll" (ByRef QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByRef TraceNode As Int32) As Int32
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Int32
'Basic Node Functions
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Int32) As Int32
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal linkIndex As Long) As Long
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENsetnodeid Lib "epanet2.dll" (ByVal index As Int32, ByVal newid As String) As Int32
Declare Function ENgetnodetype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32
Declare Function ENgetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENgetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByRef X As Single, ByRef Y As Single) As Int32
Declare Function ENsetcoord Lib "epanet2.dll" (ByVal Index As Int32, ByVal X As Single, ByVal Y As Single) As Int32
'Nodal Demand Functions
Declare Function ENgetdemandmodel Lib "epanet2.dll" (ByRef mtype As Int32, ByRef pmin As Single, ByRef preq As Single, ByRef pexp As Single) As Int32
Declare Function ENsetdemandmodel Lib "epanet2.dll" (ByVal mtype As Int32, ByVal pmin As Single, ByVal preq As Single, ByVal pexp As Single) As Int32
Declare Function ENgetnumdemands Lib "epanet2.dll" (ByVal Index As Int32, ByRef numDemands As Int32) As Int32 'ES
Declare Function ENgetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef BaseDemand As Single) As Int32 'ES
Declare Function ENsetbasedemand Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByVal BaseDemand As Single) As Int32 'ES
Declare Function ENgetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByRef PatIndex As Int32) As Int32 'ES
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal Index As Int32, ByVal DemandIndex As Int32, ByVal PatIndex As Int32) As Int32 'ES
Declare Function ENsetdemandpattern Lib "epanet2.dll" (ByVal index As Int32, ByVal DemandIndex As Int32, ByVal PatIndex As Int32) As Int32
Declare Function ENgetdemandname Lib "epanet2.dll" (ByVal index As Int32, ByVal DemandIndex As Int32, ByVal demandName As String) As Int32
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal DemandIndex As Int32, ByVal demandName As String) As Int32
'Basic Link Functions
Declare Function ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Int32, ByVal fromNode As String, ByVal toNode As String) As Int32
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal nodeIndex As Long) As Long
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Int32, ByRef Node1 As Int32, ByRef Node2 As Int32) As Int32
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Int32, ByRef nValues As Int32, ByRef xValues As Single, ByRef yValues As Single) As Int32 'ES
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal Index As Int32, ByVal CurveIndex As int32) As Int32 'ES
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Int32, ByRef PumpType As Int32) As Int32 'ES
Declare Function ENgetversion Lib "epanet2.dll" (ByRef Value As Int32) As Int32
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal CtlType As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32
Declare Function ENsetnodeid Lib "epanet2.dll" (ByVal index As Int32, ByVal newid As String) As Int32
Declare Function ENsetnodevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetlinkid Lib "epanet2.dll" (ByVal index As Int32, ByVal newid As String) As Int32
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Int32, ByVal node1 As Int32, ByVal node2 As Int32) As Int32
Declare Function ENgetlinktype Lib "epanet2.dll" (ByVal Index As Int32, ByRef Code As Int32) As Int32
Declare Function ENsetlinktype Lib "epanet2.dll" (ByRef index As Int32, ByVal code As Int32) As Int32
Declare Function ENgetlinknodes Lib "epanet2.dll" (ByVal Index As Int32, ByRef Node1 As Int32, ByRef Node2 As Int32) As Int32
Declare Function ENsetlinknodes Lib "epanet2.dll" (ByVal index As Int32, ByVal node1 As Int32, ByVal node2 As Int32) As Int32
Declare Function ENgetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByRef Value As Single) As Int32
Declare Function ENsetlinkvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal Index as Int32, ByRef F as Single, ByVal N as Int32) as Int32
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByVal Value As Single) As Int32
Declare Function ENsettimeparam Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Int32) As Int32
Declare Function ENsetoption Lib "epanet2.dll" (ByVal Code As Int32, ByVal Value As Single) As Int32
Declare Function ENsetstatusreport Lib "epanet2.dll" (ByVal Code As Int32) As Int32
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal QualCode As Int32, ByVal ChemName As String, ByVal ChemUnits As String, ByVal TraceNode As String) As Int32
'Pump Functions
Declare Function ENgetheadcurveindex Lib "epanet2.dll" (ByVal Index As Int32, ByVal CurveIndex As int32) As Int32 'ES
Declare Function ENsetheadcurveindex Lib "epanet2.dll" (ByVal pumpIndex As Int32, ByVal curveIndex As Int32) As Int32
Declare Function ENgetpumptype Lib "epanet2.dll" (ByVal Index As Int32, ByRef PumpType As Int32) As Int32 'ES
'Time Pattern Functions
Declare Function ENaddpattern Lib "epanet2.dll" (ByVal ID As String) As Int32
Declare Function ENgetpatternindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetpatternid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENgetpatternlen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32
Declare Function ENgetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByRef Value As Single) As Int32
Declare Function ENsetpatternvalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Period As Int32, ByVal Value As Single) As Int32
Declare Function ENgetaveragepatternvalue Lib "epanet2.dll" (ByVal index As Int32, ByRef value As Single) As Int32
Declare Function ENsetpattern Lib "epanet2.dll" (ByVal Index as Int32, ByRef F as Single, ByVal N as Int32) as Int32
'Data Curve Functions
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Int32
Declare Function ENgetcurveindex Lib "epanet2.dll" (ByVal ID As String, ByRef Index As Int32) As Int32
Declare Function ENgetcurveid Lib "epanet2.dll" (ByVal Index As Int32, ByVal ID As StringBuilder) As Int32
Declare Function ENgetcurvelen Lib "epanet2.dll" (ByVal Index As Int32, ByRef L As Int32) As Int32
Declare Function ENgetcurvetype Lib "epanet2.dll" (ByVal curveIndex As Int32, ByRef CurveType As Int32) As Int32
Declare Function ENgetcurvevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Pnt As Int32, ByRef X As Single, ByRef Y As Single) As Int32
Declare Function ENsetcurvevalue Lib "epanet2.dll" (ByVal Index As Int32, ByVal Pnt As Int32, ByVal X As Single, ByVal Y As Single) As Int32
Declare Function ENgetcurve Lib "epanet2.dll" (ByVal CurveIndex As Int32, ByRef nValues As Int32, ByRef xValues As Single, ByRef yValues As Single) As Int32 'ES
Declare Function ENsetcurve Lib "epanet2.dll" (ByVal Index as Int32, ByRef X as Single, ByRef Y as Single, ByVal N as Int32) as Int32
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Int32
Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Long
'Simple Control Functions
Declare Function ENaddcontrol Lib "epanet2.dll" (ByRef Cindex As Int32, ByVal Ctype As Int32, ByVal Lindex As Int32, ByVal setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32
Declare Function ENdeletecontrol Lib "epanet2.dll" (ByVal Cindex as Int32) As Int32
Declare Function ENgetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByRef CtlType As Int32, ByRef Lindex As Int32, ByRef Setting As Single, ByRef Nindex As Int32, ByRef Level As Single) As Int32
Declare Function ENsetcontrol Lib "epanet2.dll" (ByVal Cindex As Int32, ByVal CtlType As Int32, ByVal Lindex As Int32, ByVal Setting As Single, ByVal Nindex As Int32, ByVal Level As Single) As Int32
'Rule-Based Control Functions
Declare Function ENgetrule Lib "epanet2.dll" (ByVal index As Int32, ByRef nPremises As Int32, ByRef nTrueActions As Int32, ByRef nFalseActions As Int32, ByRef priority As Single) As Int32
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal id As StringBuilder) As Int32
Declare Function ENsetrulepriority Lib "epanet2.dll" (ByVal index As Int32, ByVal priority As Single) As Int32
Declare Function ENgetpremise Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByRef logop As Int32, ByRef object As Int32, ByRef indexObj As Int32, ByRef variable As Int32, ByRef relop As Int32, ByRef status As Int32, ByRef value As Single) As Int32
Declare Function ENsetpremise Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByVal logop As Int32, ByVal object As Int32, ByVal indexObj As Int32, ByVal variable As Int32, ByVal relop As Int32, ByVal status As Int32, ByVal value As Single) As Int32
@@ -261,10 +306,7 @@ Declare Function ENaddcurve Lib "epanet2.dll" (ByVal ID As String) As Long
Declare Function ENsetpremisevalue Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexPremise As Int32, ByVal value As Single) As Int32
Declare Function ENgettrueaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32
Declare Function ENsettrueaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByVal indexLink As Int32, ByVal status As Int32, ByVal setting As Single) As Int32
Decalre FUnction ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32
Declare Function ENgetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByRef indexLink As Int32, ByRef status As Int32, ByRef setting As Single) As Int32
Declare Function ENsetfalseaction Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal indexAction As Int32, ByVal indexLink As Int32, ByVal status As Int32, ByVal setting As Single) As Int32
Declare Function ENgetruleID Lib "epanet2.dll" (ByVal indexRule As Int32, ByVal id As StringBuilder) As Int32
End Module

View File

@@ -138,6 +138,7 @@ void *_defaultModel;
// Local functions
void errorLookup(int errcode, char *errmsg, int len);
/****************************************************************
LEGACY (v <= 2.1) API: uses global project variable
@@ -403,6 +404,11 @@ int DLLEXPORT ENaddcontrol(int *cindex, int ctype, int lindex,
level);
}
int DLLEXPORT ENdeletecontrol(int cindex) {
return EN_deletecontrol(_defaultModel, cindex);
}
int DLLEXPORT ENsetnodeid(int index, char *newid) {
return EN_setnodeid(_defaultModel, index, newid);
}
@@ -4963,45 +4969,6 @@ int DLLEXPORT EN_setlinktype(EN_ProjectHandle ph, int *index, EN_LinkType type)
// Find the index of this new link
EN_getlinkindex(ph, id, index);
return set_error(p->error_handle, errcode);
/***********************************************
int i;
EN_LinkType fromType;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
if (!p->Openflag)
return set_error(p->error_handle, 102);
// Check if a link with the id exists
if (EN_getlinkindex(p, id, &i) != 0)
return set_error(p->error_handle, 215);
// Get the current type of the link
EN_getlinktype(p, i, &fromType);
if (fromType == toType)
return set_error(p->error_handle, 0);
// Change link from Pipe
if (toType <= EN_PIPE) {
net->Npipes++;
} else if (toType == EN_PUMP) {
net->Npumps++;
net->Pump[net->Npumps].Link = i;
} else {
net->Nvalves++;
net->Valve[net->Nvalves].Link = i;
}
if (fromType <= EN_PIPE) {
net->Npipes--;
} else if (fromType == EN_PUMP) {
net->Npumps--;
}
return set_error(p->error_handle, 0);
**********************************************/
}
int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
@@ -5010,7 +4977,6 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
struct Sdemand *demand;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
hydraulics_t *hyd = &p->hydraulics;
quality_t *qu = &p->quality;
@@ -5018,9 +4984,6 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
Snode *node;
Scoord *coord;
Scontrol *control;
// rules_t *rule;
Premise *pchain, *pnext;
/* Check if a node with same id already exists */
if (!p->Openflag)
@@ -5039,6 +5002,7 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, 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));
// Actions taken when a new Junction is added
if (nodeType == EN_JUNCTION) {
net->Njuncs++;
nIdx = net->Njuncs;
@@ -5082,43 +5046,10 @@ int DLLEXPORT EN_addnode(EN_ProjectHandle ph, char *id, EN_NodeType nodeType) {
}
}
// 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;
}
}
// adjust indices of tanks/reservoirs in Rule premises (see RULES.C)
adjusttankrules(p);
// Actions taken when a new Tank/Reservoir is added
} else {
nIdx = net->Nnodes+1;
node = &net->Node[nIdx];
@@ -5280,138 +5211,232 @@ int DLLEXPORT EN_addlink(EN_ProjectHandle ph, char *id, EN_LinkType linkType, ch
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index) {
int i;
int pumpindex;
int valveindex;
int DLLEXPORT EN_deletelink(EN_ProjectHandle ph, int index)
/*----------------------------------------------------------------
** Input: index = index of the control
** Output: none
** Returns: error code
** Purpose: deletes a link from a project.
**----------------------------------------------------------------
*/
{
int i;
int pumpindex;
int valveindex;
EN_LinkType linkType;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
Slink *link;
EN_LinkType linkType;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
Slink *link;
if (!p->Openflag)
return set_error(p->error_handle, 102);
if (index <= 0 || index > net->Nlinks)
return set_error(p->error_handle, 203);
// Check that link exists
if (!p->Openflag) return set_error(p->error_handle, 102);
if (index <= 0 || index > net->Nlinks) return set_error(p->error_handle, 203);
EN_getlinktype(p, index, &linkType);
link = &net->Link[index];
// Get references to the link and its type
link = &net->Link[index];
EN_getlinktype(p, index, &linkType);
// remove from hash table
hashtable_delete(net->LinkHashTable, link->ID);
// Remove link from hash table
hashtable_delete(net->LinkHashTable, link->ID);
// shift link and pump arrays to re-sort link indices
for (i = index; i <= net->Nlinks - 1; i++) {
net->Link[i] = net->Link[i + 1];
// update hashtable
hashtable_update(net->LinkHashTable, net->Link[i].ID, i);
}
for (i = 1; i <= net->Npumps; i++) {
if (net->Pump[i].Link > index) {
net->Pump[i].Link -= 1;
// Shift position of higher entries in Link array down one
for (i = index; i <= net->Nlinks - 1; i++)
{
net->Link[i] = net->Link[i + 1];
// ... update hashtable
hashtable_update(net->LinkHashTable, net->Link[i].ID, i);
}
}
for (i = 1; i <= net->Nvalves; i++) {
if (net->Valve[i].Link > index) {
net->Valve[i].Link -= 1;
}
}
// remove any pump associated with the deleted link
if (linkType == EN_PUMP) {
pumpindex = findpump(net,index);
for (i = pumpindex; i <= net->Npumps - 1; i++) {
net->Pump[i] = net->Pump[i + 1];
// Adjust references to higher numbered links for pumps & valves
for (i = 1; i <= net->Npumps; i++)
{
if (net->Pump[i].Link > index) net->Pump[i].Link -= 1;
}
for (i = 1; i <= net->Nvalves; i++)
{
if (net->Valve[i].Link > index) net->Valve[i].Link -= 1;
}
// Delete any pump associated with the deleted link
if (linkType == EN_PUMP)
{
pumpindex = findpump(net,index);
for (i = pumpindex; i <= net->Npumps - 1; i++)
{
net->Pump[i] = net->Pump[i + 1];
}
net->Npumps--;
}
net->Npumps--;
}
// remove any valve associated with the deleted link
if (linkType > EN_PUMP) {
valveindex = findvalve(net,index);
for (i = valveindex; i <= net->Nvalves - 1; i++) {
net->Valve[i] = net->Valve[i + 1];
// Delete any valve (linkType > EN_PUMP) associated with the deleted link
if (linkType > EN_PUMP)
{
valveindex = findvalve(net,index);
for (i = valveindex; i <= net->Nvalves - 1; i++)
{
net->Valve[i] = net->Valve[i + 1];
}
net->Nvalves--;
}
net->Nvalves--;
}
// reduce total link count
net->Nlinks--;
return set_error(p->error_handle, 0);
// Delete any control containing the link
for (i = net->Ncontrols; i >= 1; i--)
{
if (net->Control[i].Link == index) EN_deletecontrol(ph, i);
}
// Adjust higher numbered link indices in remaining controls
for (i = 1; i <= net->Ncontrols; i++)
{
if (net->Control[i].Link > index) net->Control[i].Link--;
}
// Make necessary adjustments to rule-based controls (r_LINK = 7)
adjustrules(p, 7, index); // see RULES.C
// Reduce link count by one
net->Nlinks--;
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int index) {
int DLLEXPORT EN_deletenode(EN_ProjectHandle ph, int index)
/*----------------------------------------------------------------
** Input: index = index of the control
** Output: none
** Returns: error code
** Purpose: deletes a node from a project.
**----------------------------------------------------------------
*/
{
int i, nodeType, tankindex;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
Snode *node;
Pdemand demand, nextdemand;
Psource source;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
int i, nodeType;
if (!p->Openflag)
return set_error(p->error_handle, 102);
if (index <= 0 || index > net->Nnodes)
return set_error(p->error_handle, 203);
EN_getnodetype(p, index, &nodeType);
// TODO: check for existing controls/rules that reference this node?
// remove from hash table
hashtable_delete(net->NodeHashTable, net->Node[index].ID);
// shift node and coord array to remove node
for (i = index; i <= net->Nnodes - 1; i++) {
net->Node[i] = net->Node[i + 1];
net->Coord[i] = net->Coord[i + 1];
// update hashtable
hashtable_update(net->NodeHashTable, net->Node[i].ID, i);
}
// update tank array
if (nodeType != EN_JUNCTION) {
int tankindex = findtank(net, index);
for (i = tankindex; i <= net->Ntanks - 1; i++) {
net->Tank[i] = net->Tank[i + 1];
// Check that node exists
if (!p->Openflag) return set_error(p->error_handle, 102);
if (index <= 0 || index > net->Nnodes)
{
return set_error(p->error_handle, 203);
}
}
// update tank node indices
for (i = 1; i <= net->Ntanks; i++) {
if (net->Tank[i].Node > index) {
net->Tank[i].Node -= 1;
// Get a reference to the node & its type
node = &net->Node[index];
EN_getnodetype(ph, index, &nodeType);
// Remove node from hash table
hashtable_delete(net->NodeHashTable, node->ID);
// Free memory allocated to node's demands & WQ source
demand = node->D;
while (demand != NULL)
{
nextdemand = demand->next;
free(demand);
demand = nextdemand;
}
}
// gather a list of link ids to remove in reverse order,
// so that re-shuffling doesn't destroy the indexing
for (i = net->Nlinks; i >= 1; i--) {
if (net->Link[i].N1 == index || net->Link[i].N2 == index) {
EN_deletelink(p,i);
source = node->S;
if (source != NULL) free(source);
// Shift position of higher entries in Node 7 Cord arrays down one
for (i = index; i <= net->Nnodes - 1; i++)
{
net->Node[i] = net->Node[i + 1];
net->Coord[i] = net->Coord[i + 1];
// ... update hashtable
hashtable_update(net->NodeHashTable, net->Node[i].ID, i);
}
}
for (i = 1; i <= net->Nlinks; i++) {
if (net->Link[i].N1 > index) {
net->Link[i].N1 -= 1;
// Remove references to demands & source in last (inactive) Node array entry
net->Node[net->Nnodes].D = NULL;
net->Node[net->Nnodes].S = NULL;
// If deleted node is a tank, remove it from the Tank array
if (nodeType != EN_JUNCTION)
{
tankindex = findtank(net, index);
for (i = tankindex; i <= net->Ntanks - 1; i++)
{
net->Tank[i] = net->Tank[i + 1];
}
}
if (net->Link[i].N2 > index) {
net->Link[i].N2 -= 1;
// Shift higher node indices in Tank array down one
for (i = 1; i <= net->Ntanks; i++)
{
if (net->Tank[i].Node > index) net->Tank[i].Node -= 1;
}
}
// update counters
if (nodeType == EN_JUNCTION) {
net->Njuncs--;
} else {
net->Ntanks--;
}
// Delete any links connected to the deleted node
// (Process links in reverse order to maintain their indexing)
for (i = net->Nlinks; i >= 1; i--)
{
if (net->Link[i].N1 == index ||
net->Link[i].N2 == index) EN_deletelink(ph, i);
}
net->Nnodes--;
// Adjust indices of all link end nodes
for (i = 1; i <= net->Nlinks; i++)
{
if (net->Link[i].N1 > index) net->Link[i].N1 -= 1;
if (net->Link[i].N2 > index) net->Link[i].N2 -= 1;
}
return set_error(p->error_handle, 0);
// Delete any control containing the node
for (i = net->Ncontrols; i >= 1; i--)
{
if (net->Control[i].Node == index) EN_deletecontrol(ph, i);
}
// Adjust higher numbered link indices in remaining controls
for (i = 1; i <= net->Ncontrols; i++)
{
if (net->Control[i].Node > index) net->Control[i].Node--;
}
// Make necessary adjustments to rule-based controls (r_NODE = 6)
adjustrules(p, 6, index);
// Set water quality analysis to NONE if deleted node is trace node
if (p->quality.Qualflag == TRACE && p->quality.TraceNode == index)
{
p->quality.TraceNode = 0;
p->quality.Qualflag = NONE;
}
// Reduce counts of node types
if (nodeType == EN_JUNCTION) net->Njuncs--;
else net->Ntanks--;
net->Nnodes--;
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_deletecontrol(EN_ProjectHandle ph, int index)
/*----------------------------------------------------------------
** Input: index = index of the control
** Output: none
** Returns: error code
** Purpose: deletes a simple control from a project.
**----------------------------------------------------------------
*/
{
int i;
EN_Project *p = (EN_Project*)ph;
EN_Network *net = &p->network;
if (index <= 0 || index > net->Ncontrols)
{
return set_error(p->error_handle, 241);
}
for (i = index; i <= net->Ncontrols - 1; i++)
{
net->Control[i] = net->Control[i + 1];
}
net->Ncontrols--;
return set_error(p->error_handle, 0);
}
int DLLEXPORT EN_getrule(EN_ProjectHandle ph, int index, int *nPremises, int *nTrueActions, int *nFalseActions, EN_API_FLOAT_TYPE *priority)

View File

@@ -121,6 +121,8 @@ void changestatus(EN_Network *net, int, StatType,
void initrules(rules_t *rules); /* Initializes rule base */
void addrule(parser_data_t *par, char *); /* Adds rule to rule base */
int allocrules(EN_Project *pr); /* Allocates memory for rule */
void adjustrules(EN_Project *pr, int, int); // Shifts object indices down
void adjusttankrules(EN_Project *pr); // Shifts tank indices up
int ruledata(EN_Project *pr); /* Processes rule input data */
int checkrules(EN_Project *pr, long); /* Checks all rules */
void freerules(EN_Project *pr); /* Frees rule base memory */

View File

@@ -90,29 +90,24 @@ char *Operator[] = {"=", "<>", "<=", ">=", "<", ">",
enum Values { IS_NUMBER, IS_OPEN, IS_CLOSED, IS_ACTIVE };
char *Value[] = {"XXXX", w_OPEN, w_CLOSED, w_ACTIVE, NULL};
/* External variables declared in INPUT2.C */
// Local Functions
static void newrule(EN_Project *pr);
static int newpremise(EN_Project *pr, int);
static int newaction(EN_Project *pr);
static int newpriority(EN_Project *pr);
static int evalpremises(EN_Project *pr, int);
static void updateactlist(rules_t *rules, int, Action *);
static int checkaction(rules_t *rules, int, Action *);
static int checkpremise(EN_Project *pr, Premise *);
static int checktime(EN_Project *pr, Premise *);
static int checkstatus(EN_Project *pr, Premise *);
static int checkvalue(EN_Project *pr, Premise *);
static int takeactions(EN_Project *pr);
static void clearactlist(rules_t *rules);
static void ruleerrmsg(EN_Project *pr, int);
static void clearrule(EN_Project *pr, int);
static void deleterule(EN_Project *pr, int);
/*
** Local function prototypes are defined here and not in FUNCS.H
** because some of them utilize the Premise and Action structures
** defined locally in this module.
*/
void newrule(EN_Project *pr);
int newpremise(EN_Project *pr, int);
int newaction(EN_Project *pr);
int newpriority(EN_Project *pr);
int evalpremises(EN_Project *pr, int);
void updateactlist(rules_t *rules, int, Action *);
int checkaction(rules_t *rules, int, Action *);
int checkpremise(EN_Project *pr, Premise *);
int checktime(EN_Project *pr, Premise *);
int checkstatus(EN_Project *pr, Premise *);
int checkvalue(EN_Project *pr, Premise *);
int takeactions(EN_Project *pr);
void clearactlist(rules_t *rules);
void clearrules(EN_Project *pr);
void ruleerrmsg(EN_Project *pr, int);
//int writeRuleinInp(EN_Project *pr, FILE *f, int RuleIdx);
void initrules(rules_t *rules)
/*
@@ -166,8 +161,9 @@ void freerules(EN_Project *pr)
**--------------------------------------------------------------
*/
{
clearrules(pr);
free(pr->rules.Rule);
int i;
for (i = 1; i <= pr->network.Nrules; i++) clearrule(pr, i);
free(pr->rules.Rule);
}
int checkrules(EN_Project *pr, long dt)
@@ -217,7 +213,7 @@ int ruledata(EN_Project *pr)
**--------------------------------------------------------------
** Parses a line from [RULES] section of input.
** Called by newline() in INPUT2.C module.
** Tok[] is global array of tokens parsed from input line.
** Tok[] is an array of tokens parsed from input line.
**--------------------------------------------------------------
*/
{
@@ -305,6 +301,132 @@ int ruledata(EN_Project *pr)
return (err);
}
void adjustrules(EN_Project *pr, int objtype, int index)
/*
**-----------------------------------------------------------
** Adjusts rules when a specific node or link is deleted.
** Called by EN_deletenode & EN_deletelink in EPANET.C.
**-----------------------------------------------------------
*/
{
int i, delete;
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
Premise *p;
Action *a;
// Delete rules that refer to objtype and index
for (i = net->Nrules; i >= 1; i--)
{
delete = FALSE;
p = rules->Rule[i].Pchain;
while (p != NULL && !delete)
{
if (objtype == p->object && p->index == index) delete = TRUE;
p = p->next;
}
if (objtype == r_LINK)
{
a = rules->Rule[i].Tchain;
while (a != NULL && !delete)
{
if (a->link == index) delete = TRUE;
a = a->next;
}
a = rules->Rule[i].Fchain;
while (a != NULL && !delete)
{
if (a->link == index) delete = TRUE;
a = a->next;
}
}
if (delete) deleterule(pr, i);
}
// Adjust all higher object indices to reflect deletion of object index
for (i = 1; i <= net->Nrules; i++)
{
p = rules->Rule[i].Pchain;
while (p != NULL)
{
if (objtype == p->object && p->index > index) p->index--;
p = p->next;
}
if (objtype == r_LINK)
{
a = rules->Rule[i].Tchain;
while (a != NULL)
{
if (a->link > index) a->link--;
a = a->next;
}
a = rules->Rule[i].Fchain;
while (a != NULL)
{
if (a->link > index) a->link--;
a = a->next;
}
}
}
}
void adjusttankrules(EN_Project *pr)
/*
**-----------------------------------------------------------
** Adjusts tank indices in rule premises.
** Called by EN_addnode in EPANET.C.
**-----------------------------------------------------------
*/
{
int i, njuncs;
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
Premise *p;
njuncs = net->Njuncs;
for (i = 1; i <= net->Nrules; i++)
{
p = rules->Rule[i].Pchain;
while (p != NULL)
{
if (p->object == r_NODE && p->index > njuncs) p->index++;
p = p->next;
}
}
}
void deleterule(EN_Project *pr, int index)
/*
**-----------------------------------------------------------
** Deletes a specific rule
**-----------------------------------------------------------
*/
{
int i;
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
aRule *lastRule;
// Free memory allocated to rule's premises & actions
clearrule(pr, index);
// Shift position of higher indexed rules down one
for (i = index; i <= net->Nrules - 1; i++)
{
rules->Rule[i] = rules->Rule[i + 1];
}
// Remove premises & actions from last (inactive) entry in Rule array
lastRule = &rules->Rule[net->Nrules];
lastRule->Pchain = NULL;
lastRule->Tchain = NULL;
lastRule->Fchain = NULL;
// Reduce active rule count by one
net->Nrules--;
}
void clearactlist(rules_t *rules)
/*
**----------------------------------------------------------
@@ -322,23 +444,19 @@ void clearactlist(rules_t *rules)
}
}
void clearrules(EN_Project *pr)
void clearrule(EN_Project *pr, int i)
/*
**-----------------------------------------------------------
** Clears memory used for premises & actions for all rules
** Clears memory used by a rule for premises & actions
**-----------------------------------------------------------
*/
{
EN_Network *net = &pr->network;
rules_t *rules = &pr->rules;
Premise *p;
Premise *pnext;
Action *a;
Action *anext;
rules_t *rules = &pr->rules;
Premise *p;
Premise *pnext;
Action *a;
Action *anext;
int i;
for (i = 1; i <= net->Nrules; i++) {
p = rules->Rule[i].Pchain;
while (p != NULL) {
pnext = p->next;
@@ -357,7 +475,6 @@ void clearrules(EN_Project *pr)
free(a);
a = anext;
}
}
}
void newrule(EN_Project *pr)

View File

@@ -531,7 +531,7 @@ typedef struct s_aRule /* Control Rule Structure */
Premise *Pchain; /* Linked list of premises */
Action *Tchain; /* Linked list of actions if true */
Action *Fchain; /* Linked list of actions if false */
struct s_aRule *next;
//struct s_aRule *next;
} aRule;
typedef struct s_ActItem /* Action list item */