Simplify getting the absolute string tag for a label

It actually is roughly equivalent as TagList() does a loop to build the list but this is a bit cleaner to read
This commit is contained in:
Marek Roszko 2021-10-10 20:42:58 -04:00
parent e77cdad6fa
commit 4a3658027e
1 changed files with 19 additions and 30 deletions

View File

@ -74,6 +74,7 @@
#include <TDF_LabelSequence.hxx> #include <TDF_LabelSequence.hxx>
#include <TDF_ChildIterator.hxx> #include <TDF_ChildIterator.hxx>
#include <TDF_Tool.hxx>
#include <TDataStd_Name.hxx> #include <TDataStd_Name.hxx>
#include "plugins/3dapi/ifsg_all.h" #include "plugins/3dapi/ifsg_all.h"
@ -326,45 +327,33 @@ static wxString getLabelName( const TDF_Label& label )
return txt; return txt;
} }
/**
void getTag( TDF_Label& label, std::string& aTag ) * Gets the absolute tag string for a given label in the form of ##:##:##:##
*
* @param aLabel is the label to get the string for
* @param aTag is the resulting tag string based by reference
*/
void getTag( const TDF_Label& aLabel, std::string& aTag )
{ {
if( label.IsNull() ) std::ostringstream ostr;
if( aLabel.IsNull() )
{ {
wxLogTrace( MASK_OCE, "Null label passed to getTag" ); wxLogTrace( MASK_OCE, "Null label passed to getTag" );
return; return;
} }
std::string rtag; // tag in reverse TColStd_ListOfInteger tagList;
aTag.clear(); TDF_Tool::TagList( aLabel, tagList );
int id = label.Tag();
std::ostringstream ostr;
ostr << id;
rtag = ostr.str();
ostr.str( "" );
ostr.clear();
TDF_Label nlab = label.Father(); for( TColStd_ListOfInteger::Iterator it( tagList ); it.More(); it.Next() )
while( !nlab.IsNull() )
{ {
rtag.append( 1, ':' ); ostr << it.Value();
id = nlab.Tag(); ostr << ":";
ostr << id;
rtag.append( ostr.str() );
ostr.str( "" );
ostr.clear();
nlab = nlab.Father();
};
std::string::reverse_iterator bI = rtag.rbegin();
std::string::reverse_iterator eI = rtag.rend();
while( bI != eI )
{
aTag.append( 1, *bI );
++bI;
} }
aTag = ostr.str();
aTag.pop_back(); // kill the last colon
} }