2 #include "HYDROData_Zone.h"
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_Bathymetry.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_NaturalObject.h"
9 #include <TNaming_Builder.hxx>
10 #include <TNaming_NamedShape.hxx>
12 #include <TopoDS_Shape.hxx>
14 #include <QStringList>
16 #include <TDataStd_Integer.hxx>
18 #define PYTHON_ZONE_ID "KIND_ZONE"
20 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
21 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
24 HYDROData_Zone::HYDROData_Zone()
29 HYDROData_Zone::~HYDROData_Zone()
33 QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
37 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
38 if ( aDocument.IsNull() )
41 QString aDocName = aDocument->GetDocPyName();
42 QString aZoneName = GetName();
44 aResList << QString( "%1 = %2.CreateObject( %3 );" )
45 .arg( aZoneName ).arg( aDocName ).arg( PYTHON_ZONE_ID );
46 aResList << QString( "%1.SetName( \"%2\" );" )
47 .arg( aZoneName ).arg( aZoneName );
48 aResList << QString( "" );
50 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
51 HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
52 for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
54 Handle(HYDROData_Object) aRefGeomObj =
55 Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
56 if ( !aRefGeomObj.IsNull() )
57 setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
60 // How can we get the shape? Mb Update() method to intersect the shapes of reference objects?
61 // TODO: TopoDS_Shape aRefShape = GetShape();
66 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
68 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
69 aBuilder.Generated( theShape );
72 TopoDS_Shape HYDROData_Zone::GetShape() const
74 Handle(TNaming_NamedShape) aNamedShape;
75 if( myLab.FindChild( DataTag_Shape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
76 return aNamedShape->Get();
77 return TopoDS_Shape();
80 bool HYDROData_Zone::IsMergingNeed() const
82 Handle(HYDROData_Bathymetry) aRefBathymetry;
84 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
85 HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
86 for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
88 Handle(HYDROData_Object) aRefGeomObj =
89 Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
90 if ( aRefGeomObj.IsNull() )
93 Handle(HYDROData_Bathymetry) anObjBathymetry = aRefGeomObj->GetBathymetry();
94 if ( anObjBathymetry.IsNull() )
97 if ( aRefBathymetry.IsNull() )
99 aRefBathymetry = anObjBathymetry;
103 if ( !IsEqual( aRefBathymetry, anObjBathymetry ) )
110 void HYDROData_Zone::SetMergeType( const MergeBathymetriesType& theType )
112 Handle(TDataStd_Integer) anInt;
113 if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
115 anInt->Set( (int)theType );
119 anInt = TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
123 HYDROData_Zone::MergeBathymetriesType HYDROData_Zone::GetMergeType() const
125 MergeBathymetriesType aMergeType = Merge_UNKNOWN;
127 Handle(TDataStd_Integer) anInt;
128 if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
129 aMergeType = (MergeBathymetriesType)anInt->Get();
134 void HYDROData_Zone::SetMergeBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
136 SetReferenceObject( theBathymetry, DataTag_Bathymetry );
139 Handle(HYDROData_Bathymetry) HYDROData_Zone::GetMergeBathymetry() const
141 return Handle(HYDROData_Bathymetry)::DownCast(
142 GetReferenceObject( DataTag_Bathymetry ) );
145 void HYDROData_Zone::RemoveMergeBathymetry()
147 ClearReferenceObjects( DataTag_Bathymetry );
150 bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
152 if ( theObject.IsNull() )
155 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
156 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
157 return false; // Wrong type of object
159 if ( HasReference( theObject, DataTag_GeometryObject ) )
160 return false; // Object is already in reference list
162 AddReferenceObject( theObject, DataTag_GeometryObject );
166 HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
168 return GetReferenceObjects( DataTag_GeometryObject );
171 void HYDROData_Zone::RemoveGeometryObjects()
173 ClearReferenceObjects( DataTag_GeometryObject );