#include "HYDROData_Zone.h"
+#include "HYDROData_ArtificialObject.h"
#include "HYDROData_Bathymetry.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_POLYLINE_ID "KIND_ZONE"
+#include <TDataStd_Integer.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_Object)
-IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Object)
HYDROData_Zone::HYDROData_Zone()
+: HYDROData_Entity()
{
}
{
QStringList aResList;
- Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
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( "" );
+
+ 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() )
+ setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
+ }
+
+ // How can we get the shape? Mb Update() method to intersect the shapes of reference objects?
+ // TODO: TopoDS_Shape aRefShape = GetShape();
+
return aResList;
}
-void HYDROData_Zone::SetColor( const QColor& theColor )
+bool HYDROData_Zone::CanRemove()
{
- Handle(TDataStd_IntegerArray) aColorArray;
- if ( !myLab.FindChild( DataTag_Color ).FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
- aColorArray = TDataStd_IntegerArray::Set( myLab.FindChild( DataTag_Color ), 1, 4 );
-
- aColorArray->SetValue( 1, theColor.red() );
- aColorArray->SetValue( 2, theColor.green() );
- aColorArray->SetValue( 3, theColor.blue() );
- aColorArray->SetValue( 4, theColor.alpha() );
+ return false;
}
-QColor HYDROData_Zone::GetColor() const
+HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
{
- QColor aResColor( Qt::green );
+ HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
- Handle(TDataStd_IntegerArray) aColorArray;
- if ( myLab.FindChild( DataTag_Color ).FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
- {
- aResColor.setRed( aColorArray->Value( 1 ) );
- aResColor.setGreen( aColorArray->Value( 2 ) );
- aResColor.setBlue( aColorArray->Value( 3 ) );
- aResColor.setAlpha( aColorArray->Value( 4 ) );
- }
+ HYDROData_SequenceOfObjects aSeqOfGeomObjects = GetGeometryObjects();
+ aResSeq.Append( aSeqOfGeomObjects );
- return aResColor;
+ return aResSeq;
}
-void HYDROData_Zone::SetPolyline( const Handle(HYDROData_Polyline)& thePolyline )
+void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
{
- SetReferenceObject( thePolyline, DataTag_Polyline );
+ TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
+ aBuilder.Generated( theShape );
}
-Handle(HYDROData_Polyline) HYDROData_Zone::GetPolyline() const
+TopoDS_Shape HYDROData_Zone::GetShape() const
{
- return Handle(HYDROData_Polyline)::DownCast(
- GetReferenceObject( DataTag_Polyline ) );
+ Handle(TNaming_NamedShape) aNamedShape;
+ if( myLab.FindChild( DataTag_Shape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
+ return aNamedShape->Get();
+ return TopoDS_Shape();
}
-void HYDROData_Zone::RemovePolyline()
+bool HYDROData_Zone::IsMergingNeed() const
{
- ClearReferenceObjects( DataTag_Polyline );
+ Handle(HYDROData_Bathymetry) aRefBathymetry;
+
+ 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_Bathymetry) anObjBathymetry = aRefGeomObj->GetBathymetry();
+ if ( anObjBathymetry.IsNull() )
+ continue;
+
+ if ( aRefBathymetry.IsNull() )
+ {
+ aRefBathymetry = anObjBathymetry;
+ continue;
+ }
+
+ if ( !IsEqual( aRefBathymetry, anObjBathymetry ) )
+ return true;
+ }
+
+ return false;
}
-int HYDROData_Zone::NbBathymetries() const
+void HYDROData_Zone::SetMergeType( const MergeBathymetriesType& theType )
{
- return NbReferenceObjects( DataTag_Bathymetry );
+ Handle(TDataStd_Integer) anInt;
+ if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
+ {
+ anInt->Set( (int)theType );
+ }
+ else
+ {
+ anInt = TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
+ }
}
-void HYDROData_Zone::AddBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
+HYDROData_Zone::MergeBathymetriesType HYDROData_Zone::GetMergeType() const
{
- AddReferenceObject( theBathymetry, DataTag_Bathymetry );
+ MergeBathymetriesType aMergeType = Merge_UNKNOWN;
+
+ Handle(TDataStd_Integer) anInt;
+ if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
+ aMergeType = (MergeBathymetriesType)anInt->Get();
+
+ return aMergeType;
}
-void HYDROData_Zone::SetBathymetry( const int theIndex,
- const Handle(HYDROData_Bathymetry)& theBathymetry )
+void HYDROData_Zone::SetMergeBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
{
- SetReferenceObject( theBathymetry, DataTag_Bathymetry, theIndex );
+ SetReferenceObject( theBathymetry, DataTag_Bathymetry );
}
-Handle(HYDROData_Bathymetry) HYDROData_Zone::GetBathymetry( const int theIndex ) const
+Handle(HYDROData_Bathymetry) HYDROData_Zone::GetMergeBathymetry() const
{
return Handle(HYDROData_Bathymetry)::DownCast(
- GetReferenceObject( DataTag_Bathymetry, theIndex ) );
+ GetReferenceObject( DataTag_Bathymetry ) );
}
-HYDROData_SequenceOfObjects HYDROData_Zone::GetBathymetries() const
+void HYDROData_Zone::RemoveMergeBathymetry()
{
- return GetReferenceObjects( DataTag_Bathymetry );
+ ClearReferenceObjects( DataTag_Bathymetry );
}
-void HYDROData_Zone::RemoveBathymetries()
+bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
{
- ClearReferenceObjects( 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;
}
-QPainterPath HYDROData_Zone::GetPainterPath() const
+HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
{
- QPainterPath aPath;
-
- Handle(HYDROData_Polyline) aPolyline = GetPolyline();
- if ( !aPolyline.IsNull() )
- {
- aPath = aPolyline->painterPath();
- }
+ return GetReferenceObjects( DataTag_GeometryObject );
+}
- return aPath;
+void HYDROData_Zone::RemoveGeometryObjects()
+{
+ ClearReferenceObjects( DataTag_GeometryObject );
}
+
+