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 bool HYDROData_Zone::CanBeUpdated() const
71 bool HYDROData_Zone::CanRemove()
76 HYDROData_SequenceOfObjects HYDROData_Zone::GetAllReferenceObjects() const
78 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
80 HYDROData_SequenceOfObjects aSeqOfGeomObjects = GetGeometryObjects();
81 aResSeq.Append( aSeqOfGeomObjects );
86 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
88 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
89 aBuilder.Generated( theShape );
92 TopoDS_Shape HYDROData_Zone::GetShape() const
94 Handle(TNaming_NamedShape) aNamedShape;
95 if( myLab.FindChild( DataTag_Shape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
96 return aNamedShape->Get();
97 return TopoDS_Shape();
100 bool HYDROData_Zone::IsMergingNeed() const
102 Handle(HYDROData_Bathymetry) aRefBathymetry;
104 HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
105 HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
106 for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
108 Handle(HYDROData_Object) aRefGeomObj =
109 Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
110 if ( aRefGeomObj.IsNull() )
113 Handle(HYDROData_Bathymetry) anObjBathymetry = aRefGeomObj->GetBathymetry();
114 if ( anObjBathymetry.IsNull() )
117 if ( aRefBathymetry.IsNull() )
119 aRefBathymetry = anObjBathymetry;
123 if ( !IsEqual( aRefBathymetry, anObjBathymetry ) )
130 void HYDROData_Zone::SetMergeType( const MergeBathymetriesType& theType )
132 Handle(TDataStd_Integer) anInt;
133 if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
135 anInt->Set( (int)theType );
139 anInt = TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType );
143 HYDROData_Zone::MergeBathymetriesType HYDROData_Zone::GetMergeType() const
145 MergeBathymetriesType aMergeType = Merge_UNKNOWN;
147 Handle(TDataStd_Integer) anInt;
148 if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
149 aMergeType = (MergeBathymetriesType)anInt->Get();
154 void HYDROData_Zone::SetMergeBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
156 SetReferenceObject( theBathymetry, DataTag_Bathymetry );
159 Handle(HYDROData_Bathymetry) HYDROData_Zone::GetMergeBathymetry() const
161 return Handle(HYDROData_Bathymetry)::DownCast(
162 GetReferenceObject( DataTag_Bathymetry ) );
165 void HYDROData_Zone::RemoveMergeBathymetry()
167 ClearReferenceObjects( DataTag_Bathymetry );
170 bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
172 if ( theObject.IsNull() )
175 if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
176 !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
177 return false; // Wrong type of object
179 if ( HasReference( theObject, DataTag_GeometryObject ) )
180 return false; // Object is already in reference list
182 AddReferenceObject( theObject, DataTag_GeometryObject );
186 HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
188 return GetReferenceObjects( DataTag_GeometryObject );
191 void HYDROData_Zone::RemoveGeometryObjects()
193 ClearReferenceObjects( DataTag_GeometryObject );