Salome HOME
Feature #86: The hierarchy in the Object Browser (T 19).
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Zone.cxx
index 195afa157a1b47eb7d11a8cf9efdf4cea3dc3114..26aa2f08878e24ebc3d2992d8233402d8533ce05 100644 (file)
@@ -27,6 +27,7 @@
 #include <HYDROData_Bathymetry.h>
 
 #include <SUIT_DataObject.h>
+#include <QSet>
 
 HYDROGUI_Zone::HYDROGUI_Zone( SUIT_DataObject* theParent, 
                                           Handle(HYDROData_Zone) theData,
@@ -90,11 +91,16 @@ QString HYDROGUI_Zone::getBathimetryName() const
   if ( !aZone.IsNull() )
   {
     HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
-    if ( aZone->IsMergingNeed() || aSeq.Length() == 1 )
+    bool isMergingNeed = aZone->IsMergingNeed();
+    if ( ( isMergingNeed && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) 
+      || ( aSeq.Length() == 1 ) || ( !isMergingNeed ) )
     {
       // Collect all used bathymetries names when merging is necessary
       // or just get the name of bathymetry of a single geometry object
+      // or just get the name of a single bathymetry
       HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+      QSet<QString> aNamesSet;
+      QString aName;
       for ( ; anIter.More(); anIter.Next() )
       {
         Handle(HYDROData_Object) aRefGeomObj =
@@ -105,11 +111,24 @@ QString HYDROGUI_Zone::getBathimetryName() const
           Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
           if ( !aBathymetry.IsNull() )
           {
-            aRes += aBathymetry->GetName() + ", ";
+            aName = aBathymetry->GetName();
+            if ( !isMergingNeed )
+            {
+              // Get the first geometry object's bathymetry name and go out
+              aRes = aName;
+              break;
+            }
+
+            if ( !aNamesSet.contains( aName ) )
+            {
+              aRes += aName + ", ";
+              aNamesSet.insert( aName );
+            }
           }
         }
       }
-      if ( aRes.length() > 1 )
+      // Remove the last comma if necessary
+      if ( isMergingNeed && ( aRes.length() > 1 ) )
       {
         aRes.remove( aRes.length() - 2, 2 );
       }
@@ -159,25 +178,29 @@ QColor HYDROGUI_Zone::color( const ColorRole theColorRole, const int theColumnId
 {
   // Implement red color for bathymetry conflicts in case creation dialog
   QColor aRes;
-  if( isMergingNeed() )
+  Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
+  if ( !aZone.IsNull() )
   {
-    switch( theColorRole )
+    if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) )
     {
-      case Text:            // editor foreground (text) color
-      case Foreground:      // foreground (text) color
-        aRes = Qt::red;
-        break;
-      case HighlightedText: // highlighted foreground (text) color
-        aRes = Qt::black;
-        break;
-      case Base:            // editor background color
-      case Background:      // background color
-      case Highlight:       // highlight background color
-      default:
-        aRes = Qt::red;
+      switch( theColorRole )
+      {
+        case Text:            // editor foreground (text) color
+        case Foreground:      // foreground (text) color
+          aRes = Qt::red;
+          break;
+        case HighlightedText: // highlighted foreground (text) color
+          aRes = Qt::black;
+          break;
+        case Base:            // editor background color
+        case Background:      // background color
+        case Highlight:       // highlight background color
+        default:
+          aRes = Qt::red;
+      }
     }
   }
-  else
+  if ( !aRes.isValid() )
   {
     aRes = LightApp_DataObject::color( theColorRole, theColumnId );
   }