Set/Get node & link tags added
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
Project: OWA EPANET
|
||||
Version: 2.2
|
||||
Version: 2.3
|
||||
Module: project.c
|
||||
Description: project data management routines
|
||||
Authors: see AUTHORS
|
||||
Copyright: see AUTHORS
|
||||
License: see LICENSE
|
||||
Last Updated: 02/08/2025
|
||||
Last Updated: 02/14/2025
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@@ -448,11 +448,13 @@ int allocdata(Project *pr)
|
||||
pr->network.Node[n].D = NULL; // node demand
|
||||
pr->network.Node[n].S = NULL; // node source
|
||||
pr->network.Node[n].Comment = NULL;
|
||||
pr->network.Node[n].Tag = NULL;
|
||||
}
|
||||
for (n = 0; n <= pr->parser.MaxLinks; n++)
|
||||
{
|
||||
pr->network.Link[n].Vertices = NULL;
|
||||
pr->network.Link[n].Comment = NULL;
|
||||
pr->network.Link[n].Tag = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,6 +497,7 @@ void freedata(Project *pr)
|
||||
freedemands(&(pr->network.Node[j]));
|
||||
free(pr->network.Node[j].S);
|
||||
free(pr->network.Node[j].Comment);
|
||||
free(pr->network.Node[j].Tag);
|
||||
}
|
||||
free(pr->network.Node);
|
||||
}
|
||||
@@ -506,6 +509,7 @@ void freedata(Project *pr)
|
||||
{
|
||||
freelinkvertices(&pr->network.Link[j]);
|
||||
free(pr->network.Link[j].Comment);
|
||||
free(pr->network.Link[j].Tag);
|
||||
}
|
||||
}
|
||||
free(pr->network.Link);
|
||||
@@ -1357,6 +1361,64 @@ int setcomment(Network *network, int object, int index, const char *newcomment)
|
||||
network->Curve[index].Comment = xstrcpy(&comment, newcomment, MAXMSG);
|
||||
return 0;
|
||||
|
||||
|
||||
int gettag(Network *network, int object, int index, char *tag)
|
||||
//----------------------------------------------------------------
|
||||
// Input: object = a type of network object
|
||||
// index = index of the specified object
|
||||
// tag = the object's tag string
|
||||
// Output: error code
|
||||
// Purpose: gets the tag string assigned to an object.
|
||||
//----------------------------------------------------------------
|
||||
{
|
||||
char *currenttag;
|
||||
|
||||
// Get pointer to specified object's tag
|
||||
switch (object)
|
||||
{
|
||||
case NODE:
|
||||
if (index < 1 || index > network->Nnodes) return 251;
|
||||
currenttag = network->Node[index].Tag;
|
||||
break;
|
||||
case LINK:
|
||||
if (index < 1 || index > network->Nlinks) return 251;
|
||||
currenttag = network->Link[index].Tag;
|
||||
break;
|
||||
default:
|
||||
strcpy(tag, "");
|
||||
return 251;
|
||||
}
|
||||
// Copy the object's tag to the returned string
|
||||
if (currenttag) strcpy(tag, currenttag);
|
||||
else tag[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
int settag(Network *network, int object, int index, const char *newtag)
|
||||
//----------------------------------------------------------------
|
||||
// Input: object = a type of network object
|
||||
// index = index of the specified object
|
||||
// newtag = new tag string
|
||||
// Output: error code
|
||||
// Purpose: sets the tag string of an object.
|
||||
//----------------------------------------------------------------
|
||||
{
|
||||
char *tag;
|
||||
|
||||
switch (object)
|
||||
{
|
||||
case NODE:
|
||||
if (index < 1 || index > network->Nnodes) return 251;
|
||||
tag = network->Node[index].Tag;
|
||||
network->Node[index].Tag = xstrcpy(&tag, newtag, MAXMSG);
|
||||
return 0;
|
||||
|
||||
case LINK:
|
||||
if (index < 1 || index > network->Nlinks) return 251;
|
||||
tag = network->Link[index].Tag;
|
||||
network->Link[index].Tag = xstrcpy(&tag, newtag, MAXMSG);
|
||||
return 0;
|
||||
|
||||
default: return 251;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user