Salome HOME
Image positioning by two points.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Zone.cxx
index 8b6ecfb811b17f2e598057e57977a042dec4dba4..3ec240f04002479255ce3a13a672ce8ba9d70c55 100644 (file)
@@ -90,7 +90,8 @@ QString HYDROGUI_Zone::getBathimetryName() const
   if ( !aZone.IsNull() )
   {
     HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
-    if ( aZone->IsMergingNeed() || aSeq.Length() == 1 )
+    if ( ( aZone->IsMergingNeed() && aZone->GetMergeType() == HYDROData_Zone::Merge_UNKNOWN ) 
+      || aSeq.Length() == 1 )
     {
       // Collect all used bathymetries names when merging is necessary
       // or just get the name of bathymetry of a single geometry object
@@ -159,27 +160,102 @@ 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 );
   }
   return aRes;
 }
+
+QStringList HYDROGUI_Zone::getBathymetries() const
+{
+  QStringList aRes;
+  Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
+  if ( !aZone.IsNull() )
+  {
+    HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
+    // Collect all used bathymetries names when merging is necessary
+    // or just get the name of bathymetry of a single geometry object
+    HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Object) aRefGeomObj =
+        Handle(HYDROData_Object)::DownCast( anIter.Value() );
+      if ( !aRefGeomObj.IsNull() )
+      {
+        // Get bathymetry name
+        Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
+        if ( !aBathymetry.IsNull() && !aRes.contains( aBathymetry->GetName() ))
+        {
+          aRes.append( aBathymetry->GetName() );
+        }
+      }
+    }
+  }
+  return aRes;
+}
+
+HYDROData_Zone::MergeBathymetriesType HYDROGUI_Zone::getMergeType() const
+{
+  HYDROData_Zone::MergeBathymetriesType aRes = HYDROData_Zone::Merge_UNKNOWN;
+  Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
+  if ( !aZone.IsNull() )
+  {
+    aRes = aZone->GetMergeType();
+  }
+  return aRes;
+}
+
+void HYDROGUI_Zone::setMergeType( int theMergeType, QString theBathymetryName )
+{
+  Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( modelObject() );
+  if ( !aZone.IsNull() )
+  {
+    HYDROData_Zone::MergeBathymetriesType aMergeType = 
+      ( HYDROData_Zone::MergeBathymetriesType )theMergeType;
+    aZone->SetMergeType( aMergeType );
+    if ( aMergeType == HYDROData_Zone::Merge_Object )
+    {
+      // Find a bathymetry by the given name and set it as the zone's merge bathymetry
+      HYDROData_SequenceOfObjects aSeq = aZone->GetGeometryObjects();
+      HYDROData_SequenceOfObjects::Iterator anIter( aSeq );
+      for ( ; anIter.More(); anIter.Next() )
+      {
+        Handle(HYDROData_Object) aRefGeomObj =
+          Handle(HYDROData_Object)::DownCast( anIter.Value() );
+        if ( !aRefGeomObj.IsNull() )
+        {
+          // Get bathymetry name
+          Handle(HYDROData_Bathymetry) aBathymetry = aRefGeomObj->GetBathymetry();
+          if ( !aBathymetry.IsNull() && theBathymetryName == aBathymetry->GetName() )
+          {
+            aZone->SetMergeBathymetry( aBathymetry );
+            break;
+          }
+        }
+      }
+    }
+  }
+}