Salome HOME
Merge remote-tracking branch 'origin/BR_SHAPE_RECOGNITION' into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Region.cxx
index ac6a4f757ca6b2ed550d0f98e7b3085005363f74..0cbb266d27f1f5388730078fb6768ac00ee58b67 100644 (file)
@@ -1,11 +1,30 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "HYDROData_Region.h"
 
 #include "HYDROData_CalculationCase.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_Iterator.h"
+#include "HYDROData_Object.h"
 #include "HYDROData_ShapesTool.h"
 #include "HYDROData_Zone.h"
+#include "HYDROData_Tool.h"
 
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
@@ -74,6 +93,8 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetAllReferenceObjects() const
 
 bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
 {
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+
   if ( theZone.IsNull() )
     return false;
   
@@ -85,7 +106,7 @@ bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
     Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
   if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
   {
-    Handle(HYDROData_Zone) aNewZone = addNewZone();
+    Handle(HYDROData_Zone) aNewZone = addNewZone( aDocument, "", TopoDS_Face(), QStringList() );
     theZone->CopyTo( aNewZone );
 
     // To prevent changing of stored shape
@@ -133,7 +154,10 @@ void HYDROData_Region::RemoveZones()
   myLab.FindChild( DataTag_ChildZone ).ForgetAllAttributes( true );
 }
 
-Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone( const Handle(HYDROData_Document)& theDoc,
+                                                     const QString& thePrefix,
+                                                     const TopoDS_Face& theFace,
+                                                     const QStringList& theRefObjects )
 {
   TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
 
@@ -141,6 +165,23 @@ Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
     Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );
   AddZone( aNewZone );
 
+  QString aZoneName = HYDROData_Tool::GenerateObjectName( theDoc, thePrefix );
+  aNewZone->SetName( aZoneName );
+
+  aNewZone->SetShape( theFace );
+
+  // Add the reference object for zone
+  for ( int i = 0, n = theRefObjects.length(); i < n; ++i )
+  {
+    const QString& anObjName = theRefObjects.at( i );
+    Handle(HYDROData_Object) aRefObject = 
+      Handle(HYDROData_Object)::DownCast( theDoc->FindObjectByName( anObjName ) );
+    if ( aRefObject.IsNull() )
+      continue;
+
+    aNewZone->AddGeometryObject( aRefObject );
+  }
+
   return aNewZone;
 }
 
@@ -347,3 +388,68 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs*
   
   return aResShape;
 }
+
+QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+  QStringList aResList;
+
+  // Find region
+  findPythonReferenceObject( theTreatedObjects, aResList );
+
+  // Add zones
+  HYDROData_SequenceOfObjects aZones = GetZones();
+  HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+  for ( ; aZonesIter.More(); aZonesIter.Next() ) {
+    Handle(HYDROData_Zone) aZone =
+      Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
+    if ( aZone.IsNull() ) {
+      continue;
+    }
+    
+    // find zone
+    aZone->findPythonReferenceObject( theTreatedObjects, aResList );
+    theTreatedObjects.insert( aZone->GetName(), aZone );
+    
+    // set zone merge type
+    QString aMergeTypeStr;
+    HYDROData_Zone::MergeAltitudesType aMergeType = aZone->GetMergeType();
+    if ( aMergeType == HYDROData_Zone::Merge_ZMIN ) {
+      aMergeTypeStr = "HYDROData_Zone.Merge_ZMIN";
+    } else if ( aMergeType == HYDROData_Zone::Merge_ZMAX ) {
+      aMergeTypeStr = "HYDROData_Zone.Merge_ZMAX";
+    } else if ( aMergeType == HYDROData_Zone::Merge_Object ) {
+      aMergeTypeStr = "HYDROData_Zone.Merge_Object";
+    }
+
+    if ( !aMergeTypeStr.isEmpty() ) {
+      aResList << QString( "%1.SetMergeType( %2 )" ).arg( aZone->GetObjPyName() ).arg( aMergeTypeStr );
+    }
+    if ( aMergeType == HYDROData_Zone::Merge_Object ) {
+      Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude();
+      if ( !aMergeAltitude.IsNull() ) {
+        aMergeAltitude->findPythonReferenceObject( theTreatedObjects, aResList );
+        aResList << QString( "%1.SetMergeAltitude( %2 )" ).arg( aZone->GetObjPyName() )
+                                                          .arg( aMergeAltitude->GetObjPyName() );
+      }
+    }
+
+    // add zone
+    setPythonReferenceObject( theTreatedObjects, aResList, aZone, "AddZone" );
+  }
+
+  return aResList;
+}
+
+bool HYDROData_Region::IsSubmersible() const
+{
+  HYDROData_SequenceOfObjects aZones = GetZones();
+  HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+  for ( ; aZonesIter.More(); aZonesIter.Next() )
+  {
+    Handle(HYDROData_Zone) aZone =
+      Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
+    if ( !aZone->IsSubmersible() )
+      return false; //if one of zones is not submersible the region is considered as not submersible
+  }
+  return true;
+}