]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
One useful method added.
authoradv <adv@opencascade.com>
Thu, 16 Jan 2014 11:40:41 +0000 (11:40 +0000)
committeradv <adv@opencascade.com>
Thu, 16 Jan 2014 11:40:41 +0000 (11:40 +0000)
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h

index d754ec0f76ad4be3d286814f72faadef5f1f1093..072b0d2290baa22a03bf24b3bb9c701281c0d07c 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <limits>
 
+static int aMaxNameId = std::numeric_limits<int>::max();
+
 void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
                                          const QStringList& theStrings,
                                          const QString&     theSep )
@@ -93,8 +95,7 @@ QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& th
     aName = thePrefix;
   } else {
     int anId = 1;
-    int aMaxId = std::numeric_limits<int>::max();
-    while( anId < aMaxId )
+    while( anId < aMaxNameId )
     {
       aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
 
@@ -191,3 +192,22 @@ void HYDROData_Tool::UpdateChildObjectName( const QString&                  theO
   theObject->SetName( anObjName );
 }
 
+QString HYDROData_Tool::GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
+                                               const QString&             thePrefix )
+{
+  QString aName = thePrefix;
+  if ( !theTreatedObjects.contains( aName ) )
+    return aName;
+
+  int anId = 1;
+  while( anId < aMaxNameId )
+  {
+    aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
+
+    // check that there are no other objects with the same name
+    if ( !theTreatedObjects.contains( aName ) )
+      break;
+  }
+
+  return aName;
+}
\ No newline at end of file
index 99fd175489791f952786550bde8cdbd7de991b29..6dc38124e46804c95e8e3c162917be02e9c3f48f 100644 (file)
@@ -33,7 +33,7 @@ public:
 
   /**
    * \brief Generate name for new object.
-   * \param theModule module
+   * \param theDoc document
    * \param thePrefix name prefix
    * \param theUsedNames list of already used names
    * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy
@@ -83,6 +83,15 @@ public:
                                                                const QString&                  theNewStr,
                                                                const Handle(HYDROData_Entity)& theObject );
 
+
+  /**
+   * \brief Generate name for new object in python environment.
+   * \param theTreatedObjects objects which was alredy created by dump operation
+   * \param thePrefix name prefix
+   * \return generated name
+   */
+  static QString                        GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
+                                                               const QString&             thePrefix );
 };
 
 inline bool ValuesEquals( const double& theFirst, const double& theSecond )