From 4a3658027ecface01e1863a25d0521a784d2fe47 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 10 Oct 2021 20:42:58 -0400 Subject: [PATCH] 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 --- plugins/3d/oce/loadmodel.cpp | 49 ++++++++++++++---------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/plugins/3d/oce/loadmodel.cpp b/plugins/3d/oce/loadmodel.cpp index fb5914f33d..875fd37b65 100644 --- a/plugins/3d/oce/loadmodel.cpp +++ b/plugins/3d/oce/loadmodel.cpp @@ -74,6 +74,7 @@ #include #include +#include #include #include "plugins/3dapi/ifsg_all.h" @@ -326,45 +327,33 @@ static wxString getLabelName( const TDF_Label& label ) 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" ); return; } - std::string rtag; // tag in reverse - aTag.clear(); - int id = label.Tag(); - std::ostringstream ostr; - ostr << id; - rtag = ostr.str(); - ostr.str( "" ); - ostr.clear(); + TColStd_ListOfInteger tagList; + TDF_Tool::TagList( aLabel, tagList ); - TDF_Label nlab = label.Father(); - - while( !nlab.IsNull() ) + for( TColStd_ListOfInteger::Iterator it( tagList ); it.More(); it.Next() ) { - rtag.append( 1, ':' ); - id = nlab.Tag(); - 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; + ostr << it.Value(); + ostr << ":"; } + + aTag = ostr.str(); + aTag.pop_back(); // kill the last colon }