1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| /** @brief The function search and scan all DATAS block into the NODES block.
*
* @param NodesElem is the element in the XML witch is the begin of the NODES block.
*
* First it retrieves a header which give destination variables and then it retrieves the datas stocked in table format.
**/
void CStudySytem::LoadXML_TabNodesValues( TiXmlElement *NodesElem)
{
TiXmlElement *DatasElem,*HeaderElem,*ValuesElem;
char *HeaderString=NULL, *HeaderWord=NULL, *ValuesString=NULL, *ValueWord=NULL, *Separators = " ,;\t";
DatasElem = NodesElem->FirstChildElement(XML_DatasTable);
while ( DatasElem)
{ // Here I'm in a DATAS block
// I search the first Header element :
HeaderElem=DatasElem->FirstChildElement(XML_DatasHeader);
// and the first block Values element :
ValuesElem=DatasElem->FirstChildElement(XML_DatasValues);
if (!HeaderElem or !ValuesElem)
{ // No header or no Values! I leave this DATAS block and continue
DatasElem=DatasElem->NextSiblingElement(XML_DatasTable); // I loop on all possible datas block
continue; // go to the next DATAS block
}
// I stock each header element seperatly in a list
HeaderString = strdup(HeaderElem->GetText());
list<string> Header;
HeaderWord = strtok (HeaderString,Separators); // scan with space, coma, semicolon and tab caracter
while (HeaderWord)
{
Header.push_back( HeaderWord);
HeaderWord = strtok (NULL,Separators);
}
if( Header.empty())
{ // No header : I leave this DATAS block and continue
DatasElem=DatasElem->NextSiblingElement(XML_DatasTable); // I loop on all possible datas block
continue; // go to the next DATAS block
}
ValuesString = strdup(ValuesElem->GetText());
ValueWord = strtok (ValuesString,Separators); // scan with space, coma, semicolon and tab caracter
list<string>::iterator iHeader = Header.begin(); // I place a pointer on the first header
TIndex Index = 0;
TNumeric X=0.0f,Y=0.0f,Z=0.0f;
while ( ValueWord)
{
// cout<<*iHeader<<" = "<<ValueWord<<endl;
if ( strcmp((*iHeader).c_str(),XML_NodeIndex.c_str()) == 0 )
Index = strtol(ValueWord,NULL,10);
else if ( strcmp((*iHeader).c_str(),XML_NodeXCoord.c_str()) == 0 )
X = strtof(ValueWord,NULL);
else if ( strcmp((*iHeader).c_str(),XML_NodeYCoord.c_str()) == 0 )
Y = strtof(ValueWord,NULL);
else if ( strcmp((*iHeader).c_str(),XML_NodeZCoord.c_str()) == 0 )
Z = strtof(ValueWord,NULL);
// else // Error, header unknown !
// treat the next value :
ValueWord = strtok (NULL,Separators);
++iHeader;
if ( iHeader == Header.end())
{
// I create the new node with his properties :
TIteratorOnANode iNewNode = AddANode(Index);
if (iNewNode!=NULL)
iNewNode->SetPositionInSpace(X,Y,Z);
// Next value will be for the first header, with blank properties :
Index = 0;
X=0.0f;
Y=0.0f;
Z=0.0f;
iHeader = Header.begin();
}
}
DatasElem=DatasElem->NextSiblingElement(XML_DatasTable); // I loop on all possible datas block
}
free(HeaderString);
free(HeaderWord);
free(ValuesString);
free(ValueWord);
// free(Separators);
} |
Partager