Salome HOME
Dump Image data to python script (Feature #13).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Tool.cxx
index d98db72a4eaea477352a23a6442de3d30d7930f8..991dff2564ed7865717bc2d6fad8e44ae9f42eaf 100644 (file)
@@ -152,6 +152,14 @@ void HYDROGUI_Tool::DoubleToLambert( const double theCoord,
   theSeconds = aRemainder - theMinutes * 60;
 }
 
+bool HYDROGUI_Tool::IsEqual( const Handle(HYDROData_Object)& theObj1,
+                             const Handle(HYDROData_Object)& theObj2 )
+{
+  if( !theObj1.IsNull() && !theObj2.IsNull() )
+    return theObj1->Label() == theObj2->Label(); //ouv: check that the names can be used here
+  return false;
+}
+
 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
                                           SUIT_ViewManager* theViewManager )
 {
@@ -197,7 +205,7 @@ HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& th
       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
       {
         Handle(HYDROData_Object) anObj = aPrs->getObject();
-        if( !anObj.IsNull() && anObj->Label() == theObj->Label() )
+        if( IsEqual( anObj, theObj ) )
           return aPrs;
       }
     }
@@ -228,13 +236,21 @@ HYDROData_SequenceOfObjects HYDROGUI_Tool::GetSelectedObjects( HYDROGUI_Module*
   SUIT_DataOwnerPtrList anOwners;
   aSelectionMgr->selected( anOwners );
 
+  QStringList aCollectedNameList; // to avoid duplication
   foreach( SUIT_DataOwner* aSUITOwner, anOwners )
   {
     if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
     {
-      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry(), KIND_UNKNOWN );
+      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
       if( !anObject.IsNull() )
-        aSeq.Append( anObject );
+      {
+        QString aName = anObject->GetName();
+        if( !aCollectedNameList.contains( aName ) )
+        {
+          aSeq.Append( anObject );
+          aCollectedNameList.append( aName );
+        }
+      }
     }
   }
   return aSeq;
@@ -316,3 +332,58 @@ QList<size_t> HYDROGUI_Tool::GetGraphicsViewIdList( HYDROGUI_Module* theModule )
   }
   return aList;
 }
+
+void HYDROGUI_Tool::GetObjectReferences( const Handle(HYDROData_Image)& theImage,
+                                         HYDROData_SequenceOfObjects& theRefObjects,
+                                         QStringList& theRefNames )
+{
+  if( theImage.IsNull() )
+    return;
+
+  for( int anIndex = 0, aNbRef = theImage->NbReferences(); anIndex < aNbRef; anIndex++ )
+  {
+    Handle(HYDROData_Image) aRefImage = theImage->Reference( anIndex );
+    if( !aRefImage.IsNull() && !aRefImage->IsRemoved() )
+    {
+      QString aName = aRefImage->GetName();
+      if( !theRefNames.contains( aName ) )
+      {
+        theRefObjects.Append( aRefImage );
+        theRefNames.append( aRefImage->GetName() );
+        GetObjectReferences( aRefImage, theRefObjects, theRefNames );
+      }
+    }
+  }
+}
+
+void HYDROGUI_Tool::GetObjectBackReferences( HYDROGUI_Module* theModule,
+                                             const Handle(HYDROData_Object)& theObj,
+                                             HYDROData_SequenceOfObjects& theBackRefObjects,
+                                             QStringList& theBackRefNames )
+{
+  if( theObj.IsNull() )
+    return;
+
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() );
+  if( aDocument.IsNull() )
+    return;
+
+  QString aName = theObj->GetName();
+
+  HYDROData_Iterator anIterator( aDocument, KIND_IMAGE );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
+    if( !anImage.IsNull() )
+    {
+      HYDROData_SequenceOfObjects aRefObjects;
+      QStringList aRefNames;
+      GetObjectReferences( anImage, aRefObjects, aRefNames );
+      if( aRefNames.contains( aName ) )
+      {
+        theBackRefObjects.Append( anImage );
+        theBackRefNames.append( anImage->GetName() );
+      }
+    }
+  }
+}