Salome HOME
Bug #487: dump/load script - problem with obstacle.
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
index 91765f5f79dbe4ad8f98cb05426a17dda04609cc..2df7c740f396f90872503c1d23684646412405de 100644 (file)
 
 #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 "HYDROData_NaturalObject.h"
 
-#include <TDataStd_IntegerArray.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+
+#include <TopoDS_Shape.hxx>
 
-#include <QColor>
 #include <QStringList>
 
-#define PYTHON_ZONE_ID "KIND_ZONE"
+#include <TDataStd_Integer.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
+IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Object)
-IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Object)
 
 HYDROData_Zone::HYDROData_Zone()
+: HYDROData_Entity()
 {
+  myInterpolator = NULL;
 }
 
 HYDROData_Zone::~HYDROData_Zone()
 {
 }
 
-QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+bool HYDROData_Zone::CanBeUpdated() const
 {
-  QStringList aResList;
-
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
-  if ( aDocument.IsNull() )
-    return aResList;
-
-  QString aDocName = aDocument->GetDocPyName();
-  QString aZoneName = GetName();
-
-  aResList << QString( "%1 = %2.CreateObject( %3 );" )
-              .arg( aZoneName ).arg( aDocName ).arg( PYTHON_ZONE_ID );
-  aResList << QString( "%1.SetName( \"%2\" );" )
-              .arg( aZoneName ).arg( aZoneName );
-  aResList << QString( "" );
-
-  QColor aFillingColor = GetFillingColor();
-  aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" )
-              .arg( aFillingColor.red()  ).arg( aFillingColor.green() )
-              .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() );
-  aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName );
-  aResList << QString( "" );
-
-  QColor aBorderColor = GetBorderColor();
-  aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" )
-              .arg( aBorderColor.red()  ).arg( aBorderColor.green() )
-              .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() );
-  aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName );
-  aResList << QString( "" );
-
-  Handle(HYDROData_Polyline) aRefPolyline = GetPolyline();
-  setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" );
-  aResList << QString( "" );
-
-  HYDROData_SequenceOfObjects aZoneBaths = GetBathymetries();
-  HYDROData_SequenceOfObjects::Iterator aBathsIter( aZoneBaths );
-  for ( ; aBathsIter.More(); aBathsIter.Next() )
-  {
-    Handle(HYDROData_Bathymetry) aRefBath =
-      Handle(HYDROData_Bathymetry)::DownCast( aBathsIter.Value() );
-    if ( !aRefBath.IsNull() )
-      setPythonReferenceObject( theTreatedObjects, aResList, aRefBath, "AddBathymetry" );
-  }
-
-  return aResList;
+  return false;
 }
 
-QColor HYDROData_Zone::DefaultFillingColor()
+bool HYDROData_Zone::IsHas2dPrs() const
 {
-  return QColor( Qt::green );
+  return true;
 }
 
-void HYDROData_Zone::SetFillingColor( const QColor& theColor )
+bool HYDROData_Zone::CanRemove()
 {
-  return SetColor( theColor, DataTag_FillingColor );
+  return false;
 }
 
-QColor HYDROData_Zone::GetFillingColor() const
+HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
 {
-  return GetColor( DefaultFillingColor(), DataTag_FillingColor );
+  HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
+
+  HYDROData_SequenceOfObjects aSeqOfGeomObjects = GetGeometryObjects();
+  aResSeq.Append( aSeqOfGeomObjects );
+
+  return aResSeq;
 }
 
-QColor HYDROData_Zone::DefaultBorderColor()
+void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
 {
-  return QColor( Qt::transparent );
+  TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
+  aBuilder.Generated( theShape );
 }
 
-void HYDROData_Zone::SetBorderColor( const QColor& theColor )
+TopoDS_Shape HYDROData_Zone::GetShape() const
 {
-  return SetColor( theColor, DataTag_BorderColor );
+  TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
+  if ( !aLabel.IsNull() )
+  {
+    Handle(TNaming_NamedShape) aNamedShape;
+    if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
+      return aNamedShape->Get();
+  }
+
+  return TopoDS_Shape();
 }
 
-QColor HYDROData_Zone::GetBorderColor() const
+bool HYDROData_Zone::IsMergingNeed() const
 {
-  return GetColor( DefaultBorderColor(), DataTag_BorderColor );
+  Handle(HYDROData_IAltitudeObject) aRefAltitude;
+
+  HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
+  HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
+  for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
+  {
+    Handle(HYDROData_Object) aRefGeomObj =
+      Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
+    if ( aRefGeomObj.IsNull() )
+      continue;
+
+    Handle(HYDROData_IAltitudeObject) anObjAltitude = aRefGeomObj->GetAltitudeObject();
+    if ( anObjAltitude.IsNull() )
+      continue;
+
+    if ( aRefAltitude.IsNull() )
+    {
+      aRefAltitude = anObjAltitude;
+      continue;
+    }
+
+    if ( !IsEqual( aRefAltitude, anObjAltitude ) )
+      return true;
+  }
+
+  return false;
 }
 
-void HYDROData_Zone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
+void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter )
 {
-  SetReferenceObject( thePolyline, DataTag_Polyline );
+  myInterpolator = theInter;
 }
 
-Handle(HYDROData_Polyline) HYDROData_Zone::GetPolyline() const
+HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const
 {
-  return Handle(HYDROData_Polyline)::DownCast( 
-           GetReferenceObject( DataTag_Polyline ) );
+  return myInterpolator;
 }
 
-void HYDROData_Zone::RemovePolyline()
+void HYDROData_Zone::SetMergeType( const MergeAltitudesType& theType )
 {
-  ClearReferenceObjects( DataTag_Polyline );
+  TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
 }
 
-int HYDROData_Zone::NbBathymetries() const
+HYDROData_Zone::MergeAltitudesType HYDROData_Zone::GetMergeType() const
 {
-  return NbReferenceObjects( DataTag_Bathymetry );
+  MergeAltitudesType 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 = (MergeAltitudesType)anInt->Get();
+  }
+
+  return aMergeType;
 }
 
-void HYDROData_Zone::AddBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
+void HYDROData_Zone::SetMergeAltitude( const Handle(HYDROData_IAltitudeObject)& theAltitude )
 {
-  AddReferenceObject( theBathymetry, DataTag_Bathymetry );
+  SetReferenceObject( theAltitude, DataTag_MergeAltitude );
 }
 
-void HYDROData_Zone::SetBathymetry( const int                           theIndex,
-                                    const Handle(HYDROData_Bathymetry)& theBathymetry )
+Handle(HYDROData_IAltitudeObject) HYDROData_Zone::GetMergeAltitude() const
 {
-  SetReferenceObject( theBathymetry, DataTag_Bathymetry, theIndex );
+  return Handle(HYDROData_IAltitudeObject)::DownCast( 
+           GetReferenceObject( DataTag_MergeAltitude ) );
 }
 
-Handle(HYDROData_Bathymetry) HYDROData_Zone::GetBathymetry( const int theIndex ) const
+void HYDROData_Zone::RemoveMergeAltitude()
 {
-  return Handle(HYDROData_Bathymetry)::DownCast( 
-           GetReferenceObject( DataTag_Bathymetry, theIndex ) );
+  ClearReferenceObjects( DataTag_MergeAltitude );
 }
 
-HYDROData_SequenceOfObjects HYDROData_Zone::GetBathymetries() const
+bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
 {
-  return GetReferenceObjects( DataTag_Bathymetry );
+  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_GeometryObject ) )
+    return false; // Object is already in reference list
+
+  AddReferenceObject( theObject, DataTag_GeometryObject );
+
+  return true;
 }
 
-void HYDROData_Zone::RemoveBathymetries()
+HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
 {
-  ClearReferenceObjects( DataTag_Bathymetry );
+  return GetReferenceObjects( DataTag_GeometryObject );
 }
 
-QPainterPath HYDROData_Zone::GetPainterPath() const
+void HYDROData_Zone::RemoveGeometryObjects()
 {
-  QPainterPath aPath;
+  ClearReferenceObjects( DataTag_GeometryObject );
+}
 
-  Handle(HYDROData_Polyline) aPolyline = GetPolyline();
-  if ( !aPolyline.IsNull() )
-  {
-    aPath = aPolyline->painterPath();
-  }
 
-  return aPath;
-}