Return object index from EN_addnode and EN_addlink (issue #432)

Adds an output argument to EN_addnode and EN_addlink that returns the index of the newly added object.
Also refactors the validity check on object ID names.
This commit is contained in:
Lew Rossman
2019-04-18 07:00:07 -04:00
parent 4494db8f56
commit 1583bea154
18 changed files with 149 additions and 154 deletions

View File

@@ -291,7 +291,7 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal qualType As Long, ByVal chemName As String, ByVal chemUnits As String, ByVal traceNode As String) As Long
'Node Functions
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Long) As Long
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Long, index As Long) As Long
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal index As Long, ByVal actionCode 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
@@ -316,7 +316,7 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Long, ByVal demandIndex As Long, ByVal demandName As String) As Long
'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 ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Long, ByVal fromNode As String, ByVal toNode As String, index As Long) As Long
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal index As Long, ByVal actionCode 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

View File

@@ -3,8 +3,8 @@ LIBRARY EPANET2.DLL
EXPORTS
ENaddcontrol = _ENaddcontrol@24
ENaddcurve = _ENaddcurve@4
ENaddlink = _ENaddlink@16
ENaddnode = _ENaddnode@8
ENaddlink = _ENaddlink@20
ENaddnode = _ENaddnode@12
ENaddpattern = _ENaddpattern@4
ENaddrule = _ENaddrule@4
ENclearreport = _ENclearreport@0

View File

@@ -190,7 +190,7 @@ extern "C" {
********************************************************************/
int DLLEXPORT ENaddnode(char *id, int nodeType);
int DLLEXPORT ENaddnode(char *id, int nodeType, int *index);
int DLLEXPORT ENdeletenode(int index, int actionCode);
@@ -252,7 +252,7 @@ extern "C" {
********************************************************************/
int DLLEXPORT ENaddlink(char *id, int linkType, char *fromNode, char *toNode);
int DLLEXPORT ENaddlink(char *id, int linkType, char *fromNode, char *toNode, int *index);
int DLLEXPORT ENdeletelink(int index, int actionCode);

View File

@@ -296,7 +296,7 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENsetqualtype Lib "epanet2.dll" (ByVal qualType As Int32, ByVal chemName As String, ByVal chemUnits As String, ByVal traceNode As String) As Int32
'Node Functions
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Int32) As Int32
Declare Function ENaddnode Lib "epanet2.dll" (ByVal id As String, ByVal nodeType As Int32, Index As Int32) As Int32
Declare Function ENdeletenode Lib "epanet2.dll" (ByVal index As Int32, ByVal actionCode As Int32) As Int32
Declare Function ENgetnodeindex Lib "epanet2.dll" (ByVal id As String, index As Int32) As Int32
Declare Function ENgetnodeid Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String) As Int32
@@ -321,7 +321,7 @@ Public Const EN_R_IS_ACTIVE = 3
Declare Function ENsetdemandname Lib "epanet2.dll" (ByVal nodeIndex As Int32, ByVal demandIndex As Int32, ByVal demandName As String) As Int32
'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 ENaddlink Lib "epanet2.dll" (ByVal id As String, ByVal linkType As Int32, ByVal fromNode As String, ByVal toNode As String, Index As Int32) As Int32
Declare Function ENdeletelink Lib "epanet2.dll" (ByVal index As Int32, ByVal actionCode As Int32) As Int32
Declare Function ENgetlinkindex Lib "epanet2.dll" (ByVal id As String, index As Int32) As Int32
Declare Function ENgetlinkid Lib "epanet2.dll" (ByVal index As Int32, ByVal id As String) As Int32

View File

@@ -752,11 +752,12 @@ typedef struct Project *EN_Project;
@param ph an EPANET project handle.
@param id the ID name of the node to be added.
@param nodeType the type of node being added (see @ref EN_NodeType)
@param[out] index the index of the newly added node
@return an error code.
When a new node is created all of it's properties (see @ref EN_NodeProperty) are set to 0.
*/
int DLLEXPORT EN_addnode(EN_Project ph, char *id, int nodeType);
int DLLEXPORT EN_addnode(EN_Project ph, char *id, int nodeType, int *index);
/**
@brief Deletes a node from a project.
@@ -1027,6 +1028,7 @@ typedef struct Project *EN_Project;
@param linkType The type of link being added (see @ref EN_LinkType)
@param fromNode The ID name of the link's starting node.
@param toNode The ID name of the link's ending node.
@param[out] index the index of the newly added link.
@return an error code.
A new pipe is assigned a diameter of 10 inches (or 254 mm), a length of 100
@@ -1039,7 +1041,8 @@ typedef struct Project *EN_Project;
See @ref EN_LinkProperty.
*/
int DLLEXPORT EN_addlink(EN_Project ph, char *id, int linkType, char *fromNode, char *toNode);
int DLLEXPORT EN_addlink(EN_Project ph, char *id, int linkType, char *fromNode,
char *toNode, int *index);
/**
@brief Deletes a link from the project.

View File

@@ -81,7 +81,7 @@ int EXPORT_PY_API anlys_getqualtype(Handle ph, int *qualcode, int *tracenode);
int EXPORT_PY_API anlys_setqualtype(Handle ph, EN_QualityType qualcode, char *chemname, char *chemunits, char *tracenode);
int EXPORT_PY_API node_add(Handle ph, char *id, EN_NodeType nodeType);
int EXPORT_PY_API node_add(Handle ph, char *id, EN_NodeType nodeType, int *index);
int EXPORT_PY_API node_delete(Handle ph, int index, int actionCode);
int EXPORT_PY_API node_getindex(Handle ph, char *id, int *index);
int EXPORT_PY_API node_getid(Handle ph, int index, char *id);
@@ -104,7 +104,7 @@ int EXPORT_PY_API dmnd_getname(Handle ph, int nodeIndex, int demandIdx, char *de
int EXPORT_PY_API dmnd_setname(Handle ph, int nodeIndex, int demandIdx, char *demandName);
int EXPORT_PY_API link_add(Handle ph, char *id, EN_LinkType linkType, char *fromNode, char *toNode);
int EXPORT_PY_API link_add(Handle ph, char *id, EN_LinkType linkType, char *fromNode, char *toNode, int *index);
int EXPORT_PY_API link_delete(Handle ph, int index, int actionCode);
int EXPORT_PY_API link_getindex(Handle ph, char *id, int *index);
int EXPORT_PY_API link_getid(Handle ph, int index, char *id);