Skip to content

Commit

Permalink
Added ENgetcurvetype API
Browse files Browse the repository at this point in the history
Also update curve type on EN_setheadcurveindex.

Co-Authored-By: milad ghiami <[email protected]>
  • Loading branch information
eladsal and milad-ghiami committed Aug 20, 2018
1 parent 634651d commit 761199b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/epanet2.bas
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Public Const EN_G_CURVE = 4 ' General\default curve
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

Expand Down
14 changes: 12 additions & 2 deletions include/epanet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,19 @@ extern "C" {
@param linkIndex The index of the pump element
@param[out] outType The integer-typed pump curve type signifier (output parameter)
@return Error code
@see EN_CurveType
@see EN_PumpType
*/
int DLLEXPORT ENgetpumptype(int linkIndex, int *outType);


/**
@brief Get the type of a curve
@param curveIndex The index of the curve element
@param[out] outType The integer-typed curve curve type signifier (output parameter)
@return Error code
@see EN_CurveType
*/
int DLLEXPORT ENgetcurvetype(int curveIndex, int *outType);

/**
@brief Get the version number. This number is to be interpreted with implied decimals, i.e., "20100" == "2(.)01(.)00"
@param[out] version The version of EPANET
Expand Down Expand Up @@ -1189,6 +1198,7 @@ extern "C" {
int DLLEXPORT EN_getheadcurveindex(EN_Project *p, int pumpIndex, int *curveIndex);
int DLLEXPORT EN_setheadcurveindex(EN_Project *p, int pumpIndex, int curveIndex);
int DLLEXPORT EN_getpumptype(EN_Project *p, int linkIndex, int *outType);
int DLLEXPORT EN_getcurvetype(EN_Project *p, int curveIndex, int *outType);
int DLLEXPORT EN_getversion(int *version);
int DLLEXPORT EN_setcontrol(EN_Project *p, int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
int DLLEXPORT EN_setnodevalue(EN_Project *p, int index, int code, EN_API_FLOAT_TYPE v);
Expand Down
19 changes: 18 additions & 1 deletion src/epanet.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ int DLLEXPORT ENgetpumptype(int index, int *type) {
return EN_getpumptype(_defaultModel, index, type);
}

int DLLEXPORT ENgetcurvetype(int curveindex, int *type) {
return EN_getcurvetype(_defaultModel, curveindex, type);
}

int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands) {
return EN_getnumdemands(_defaultModel, nodeIndex, numDemands);
}
Expand Down Expand Up @@ -3349,7 +3353,8 @@ int DLLEXPORT EN_setheadcurveindex(EN_Project *p, int index, int curveindex) {
pump->Q0 /= Ucf[FLOW];
pump->Qmax /= Ucf[FLOW];
pump->Hmax /= Ucf[HEAD];


p->network.Curve[curveindex].Type = P_CURVE;
return (0);
}

Expand All @@ -3370,6 +3375,18 @@ int DLLEXPORT EN_getpumptype(EN_Project *p, int index, int *type) {
return (0);
}

int DLLEXPORT EN_getcurvetype(EN_Project *p, int curveindex, int *type) {

EN_Network *net = &p->network;

if (!p->Openflag)
return (102);
if (curveindex < 1 || curveindex > net->Ncurves)
return (206);
*type = net->Curve[curveindex].Type;
return (0);
}

/*
----------------------------------------------------------------
Functions for opening files
Expand Down
3 changes: 2 additions & 1 deletion win_build/WinSDK/epanet2.def
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ EXPORTS
ENaddlink = _ENaddlink@16
ENdeletelink = _ENdeletelink@4
ENdeletenode = _ENdeletenode@4
ENsetlinktype = _ENsetlinktype@8
ENsetlinktype = _ENsetlinktype@8
ENgetcurvetype = _ENgetcurvetype@8

8 comments on commit 761199b

@eladsal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes #209

@michaeltryby
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladsal nice work! I’m confused where is this code? In a PR? Also were you going to write a unit test?

@michaeltryby
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladsal your commits should not be pushed directly into dev. You should issue a PR instead.

If you don’t know how I would be happy to explain the process.

Also we are running a large testing deficit. Would really like to see a test on this.

@eladsal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will issue a PR depending on the size, complexity and nature of the push.

Where are those tests located?

@eladsal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I have the VB test script I used for this commit and can share it if needed.

@michaeltryby
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladsal we will discuss as a community and come to a consensus regarding the contribution workflow.

@eladsal
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. What was working when we were 2-3 committers might not be suitable now and we have to change they way we do things.

@michaeltryby
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Look forward to hearing your thoughts over at #222

Please sign in to comment.