Salome HOME
Image positioning by two points.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index 58511d16cea71b587a10df916512f4b35cc7e28b..fda98c6134bb9807f150190aaac67f7f445e8ced 100644 (file)
@@ -24,7 +24,7 @@ void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
 }
 
 void HYDROData_Tool::SetMustBeUpdatedImages(
-  Handle_HYDROData_Document theDoc)
+  const Handle(HYDROData_Document)& theDoc  )
 {
   bool aChanged = true;
 
@@ -55,3 +55,90 @@ void HYDROData_Tool::SetMustBeUpdatedImages(
     }
   }
 }
+
+QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
+                                            const QString&                    thePrefix,
+                                            const QStringList&                theUsedNames )
+{
+  QStringList aNamesList( theUsedNames );
+
+  // Collect all used names in the document
+  HYDROData_Iterator anIter( theDoc );
+  for( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_Entity) anObject = anIter.Current();
+    if( anObject.IsNull() )
+      continue;
+
+    QString anObjName = anObject->GetName();
+    if ( anObjName.isEmpty() )
+      continue;
+
+    aNamesList.append( anObjName );
+  }
+
+  QString aName;
+
+  int anId = 1;
+  while( anId < 1000 )
+  {
+    aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
+
+    // check that there are no other objects with the same name in the document
+    if ( !aNamesList.contains( aName ) )
+      break;
+  }
+
+  return aName;
+}
+
+Handle(HYDROData_Entity) HYDROData_Tool::FindObjectByName( const Handle(HYDROData_Document)& theDoc,
+                                                           const QString&                    theName,
+                                                           const ObjectKind                  theObjectKind )
+{
+  Handle(HYDROData_Entity) anObject;
+  if ( theName.isEmpty() || theDoc.IsNull() )
+    return anObject;
+
+  QStringList aNamesList;
+  aNamesList << theName;
+
+  HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( theDoc, aNamesList, theObjectKind );
+  if( aSeqOfObjs.IsEmpty() )
+    return anObject;
+  
+  anObject = aSeqOfObjs.First();
+  return anObject;
+}
+
+HYDROData_SequenceOfObjects HYDROData_Tool::FindObjectsByNames( const Handle(HYDROData_Document)& theDoc,
+                                                                const QStringList&                theNames,
+                                                                const ObjectKind                  theObjectKind )
+{
+  HYDROData_SequenceOfObjects aResSeq;
+  if( theDoc.IsNull() )
+    return aResSeq;
+
+  QStringList aNamesList = theNames;
+
+  HYDROData_Iterator anIter( theDoc, theObjectKind );
+  for( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_Entity) anObject = anIter.Current();
+    if( anObject.IsNull() )
+      continue;
+
+    QString anObjName = anObject->GetName();
+    if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
+      continue;
+
+    aResSeq.Append( anObject );
+
+    aNamesList.removeAll( anObjName );
+    if ( aNamesList.isEmpty() )
+      break;
+  }
+
+  return aResSeq;
+}
+