Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshUtils.cxx
index 9c8d313c63d8cac9693af24dd7f85957b37ccec0..ccbdaff7d5855e096ec46ea9cdd8bcc07e2902a8 100644 (file)
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
 
 #include "SMESHGUI_MeshUtils.h"
 #include "SMESHGUI_Utils.h"
+#include "SALOMEDSClient_Study.hxx"
 
 #include "SALOMEconfig.h"
 #include CORBA_SERVER_HEADER(SMESH_Group)
@@ -44,4 +45,27 @@ namespace SMESH
     return SMESH_Mesh::_nil();
   }
 
+  QString UniqueMeshName(const char* theBaseName, const char* thePostfix)
+  {
+    QString baseName = theBaseName;
+    if ( thePostfix/* && !name.contains( postfix )*/) { // add postfix
+      baseName += "_";
+      baseName += thePostfix;
+    }
+    if(_PTR(Study) aStudy = GetActiveStudyDocument()) {
+      QString name = baseName;
+      while ( !aStudy->FindObjectByName( name.latin1(), "SMESH" ).empty() ) {
+        int nb = 0;
+        if ( name[ name.length()-1 ].isNumber() ) {
+          int nbBeg = name.findRev("_");
+          nb = name.right( name.length() - nbBeg - 1 ).toInt();
+          name = name.left( nbBeg );
+        }
+        name += QString("_%1").arg( nb+1 );
+      }
+      return name;
+    }
+    return QString("");
+  }
+
 }