Salome HOME
refs #651: wrapping land cover map by Python
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
index 3af90622deec733c285953a517d81db4c80b5332..661e23c9b6a757a4ba1df0d1047fad084edf98c1 100644 (file)
+// 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_Zone.h"
 
-#include "HYDROData_Bathymetry.h"
+#include "HYDROData_ArtificialObject.h"
+#include "HYDROData_IAltitudeObject.h"
 #include "HYDROData_Document.h"
-#include "HYDROData_Polyline.h"
-#include "HYDROData_Iterator.h"
-
-#include <BRepBuilderAPI_MakeFace.hxx>
-#include <TDataStd_IntegerArray.hxx>
-#include <TopoDS_Wire.hxx>
-
-#include <QColor>
+#include "HYDROData_NaturalObject.h"
 #include <QStringList>
+#include <TDataStd_Integer.hxx>
+#include <TopoDS_Shape.hxx>
 
-#define PYTHON_ZONE_ID "KIND_ZONE"
+IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
+IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Domain)
-IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Domain)
 
 HYDROData_Zone::HYDROData_Zone()
+: HYDROData_Entity( Geom_2d )
 {
+  myInterpolator = NULL;
 }
 
 HYDROData_Zone::~HYDROData_Zone()
 {
 }
 
-QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+bool HYDROData_Zone::CanBeUpdated() const
 {
-  QStringList aResList = HYDROData_Domain::DumpToPython( theTreatedObjects );
-  if ( aResList.isEmpty() )
-    return aResList;
-
-  aResList << QString( "" );
+  return false;
+}
 
-  Handle(HYDROData_Polyline) aRefPolyline = GetPolyline();
-  setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
+bool HYDROData_Zone::IsHas2dPrs() const
+{
+  return true;
+}
 
-  return aResList;
+bool HYDROData_Zone::CanRemove()
+{
+  return false;
 }
 
-void HYDROData_Zone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
+HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
 {
-  SetReferenceObject( thePolyline, DataTag_Polyline );
+  HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
+
+  HYDROData_SequenceOfObjects aSeqOfObjects = GetObjects();
+  aResSeq.Append( aSeqOfObjects );
+
+  return aResSeq;
 }
 
-Handle(HYDROData_Polyline) HYDROData_Zone::GetPolyline() const
+void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
 {
-  return Handle(HYDROData_Polyline)::DownCast( 
-           GetReferenceObject( DataTag_Polyline ) );
+  HYDROData_Entity::SetShape( DataTag_Shape, theShape );
 }
 
-void HYDROData_Zone::RemovePolyline()
+TopoDS_Shape HYDROData_Zone::GetShape() const
 {
-  ClearReferenceObjects( DataTag_Polyline );
+  return HYDROData_Entity::GetShape( DataTag_Shape );
 }
 
-TopoDS_Face HYDROData_Zone::Face() const
+bool HYDROData_Zone::IsMergingNeed() const
 {
-  Handle(HYDROData_Polyline) aPolyline = GetPolyline();
-  if( !aPolyline.IsNull() )
+  // Zones based on geometry objects (compare altitudes)
+  Handle(HYDROData_IAltitudeObject) aRefAltitude;
+
+  HYDROData_SequenceOfObjects anObjects = GetObjects();
+  HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
+  for ( ; anObjsIter.More(); anObjsIter.Next() )
   {
-    TopoDS_Wire aWire = aPolyline->Wire();
-    if( !aWire.IsNull() )
+    Handle(HYDROData_Object) aRefGeomObj =
+      Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
+    if ( aRefGeomObj.IsNull() )
+      continue;
+
+    Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
+    if ( anObjAltitude.IsNull() )
+      continue;
+
+    if ( aRefAltitude.IsNull() )
     {
-      BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
-      aMakeFace.Build();
-      if( aMakeFace.IsDone() )
-        return aMakeFace.Face();
+      aRefAltitude = anObjAltitude;
+      continue;
     }
+
+    if ( !IsEqual( aRefAltitude, anObjAltitude ) )
+      return true;
   }
-  return TopoDS_Face();
+
+  return false;
 }
 
-QString HYDROData_Zone::getPythonKindId() const
+void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
 {
-  return QString( PYTHON_ZONE_ID );
+  myInterpolator = theInter;
 }
 
+HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
+{
+  return myInterpolator;
+}
 
+void HYDROData_Zone::SetMergeType( const MergeType& theType )
+{
+  TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
+}
+
+HYDROData_Zone::MergeType HYDROData_Zone::GetMergeType() const
+{
+  MergeType aMergeType = Merge_UNKNOWN;
+  
+  TDF_Label aLabel = myLab.FindChild( DataTag_MergeType, false );
+  if ( !aLabel.IsNull() )
+  {
+    Handle(TDataStd_Integer) anInt;
+    if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anInt ) )
+      aMergeType = (MergeType)anInt->Get();
+  }
+
+  return aMergeType;
+}
+
+void HYDROData_Zone::SetMergeObject( const Handle(HYDROData_Entity)& theObject )
+{
+  SetReferenceObject( theObject, DataTag_MergeObject );
+}
+
+Handle(HYDROData_Entity) HYDROData_Zone::GetMergeObject() const
+{
+  return Handle(HYDROData_Entity)::DownCast( 
+           GetReferenceObject( DataTag_MergeObject ) );
+}
+
+void HYDROData_Zone::RemoveMergeObject()
+{
+  ClearReferenceObjects( DataTag_MergeObject );
+}
+
+bool HYDROData_Zone::AddObject( const Handle(HYDROData_Entity)& theObject )
+{
+  if ( theObject.IsNull() )
+    return false;
+  
+  if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
+       !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
+    return false; // Wrong type of object
+
+  if ( HasReference( theObject, DataTag_Object ) )
+    return false; // Object is already in reference list
+
+  AddReferenceObject( theObject, DataTag_Object );
+
+  return true;
+}
+
+HYDROData_SequenceOfObjects HYDROData_Zone::GetObjects() const
+{
+  return GetReferenceObjects( DataTag_Object );
+}
+
+void HYDROData_Zone::RemoveObjects()
+{
+  ClearReferenceObjects( DataTag_Object );
+}
+
+bool HYDROData_Zone::IsSubmersible() const
+{
+  HYDROData_SequenceOfObjects anObjects = GetObjects();
+  HYDROData_SequenceOfObjects::Iterator anObjsIter( anObjects );
+  for ( ; anObjsIter.More(); anObjsIter.Next() )
+  {
+    Handle(HYDROData_Object) aRefGeomObj =
+      Handle(HYDROData_Object)::DownCast( anObjsIter.Value() );
+    if ( aRefGeomObj.IsNull() )
+      continue;
+
+    if( !aRefGeomObj->IsSubmersible() )
+      return false; //if one of geometry objects is not submersible the zone is considered as not submersible
+  }
+  return true;
+}