Salome HOME
Undefined merge bathymetries type added for zones.
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
1
2 #include "HYDROData_Zone.h"
3
4 #include "HYDROData_ArtificialObject.h"
5 #include "HYDROData_Bathymetry.h"
6 #include "HYDROData_Document.h"
7 #include "HYDROData_NaturalObject.h"
8
9 #include <TNaming_Builder.hxx>
10 #include <TNaming_NamedShape.hxx>
11
12 #include <TopoDS_Shape.hxx>
13
14 #include <QStringList>
15
16 #include <TDataStd_Integer.hxx>
17
18 #define PYTHON_ZONE_ID "KIND_ZONE"
19
20 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
21 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
22
23
24 HYDROData_Zone::HYDROData_Zone()
25 : HYDROData_Entity()
26 {
27 }
28
29 HYDROData_Zone::~HYDROData_Zone()
30 {
31 }
32
33 QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
34 {
35   QStringList aResList;
36
37   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
38   if ( aDocument.IsNull() )
39     return aResList;
40
41   QString aDocName = aDocument->GetDocPyName();
42   QString aZoneName = GetName();
43
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( "" );
49
50   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
51   HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
52   for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
53   {
54     Handle(HYDROData_Object) aRefGeomObj =
55       Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
56     if ( !aRefGeomObj.IsNull() )
57       setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
58   }
59
60   // How can we get the shape? Mb Update() method to intersect the shapes of reference objects?
61   // TODO:  TopoDS_Shape aRefShape = GetShape();
62
63   return aResList;
64 }
65
66 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
67 {
68   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
69   aBuilder.Generated( theShape );
70 }
71
72 TopoDS_Shape HYDROData_Zone::GetShape() const
73 {
74   Handle(TNaming_NamedShape) aNamedShape;
75   if( myLab.FindChild( DataTag_Shape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
76     return aNamedShape->Get();
77   return TopoDS_Shape();
78 }
79
80 void HYDROData_Zone::SetMergeType( const MergeBathymetriesType& theType )
81 {
82   Handle(TDataStd_Integer) anInt;
83   if ( !myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
84     anInt = TDataStd_Integer::Set( myLab, 0 );
85   anInt->Set( (int)theType );
86 }
87
88 HYDROData_Zone::MergeBathymetriesType HYDROData_Zone::GetMergeType() const
89 {
90   MergeBathymetriesType aMergeType = Merge_UNKNOWN;
91   
92   Handle(TDataStd_Integer) anInt;
93   if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
94     aMergeType = (MergeBathymetriesType)anInt->Get();
95
96   return aMergeType;
97 }
98
99 void HYDROData_Zone::SetMergeBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
100 {
101   SetReferenceObject( theBathymetry, DataTag_Bathymetry );
102 }
103
104 Handle(HYDROData_Bathymetry) HYDROData_Zone::GetMergeBathymetry() const
105 {
106   return Handle(HYDROData_Bathymetry)::DownCast( 
107            GetReferenceObject( DataTag_Bathymetry ) );
108 }
109
110 void HYDROData_Zone::RemoveMergeBathymetry()
111 {
112   ClearReferenceObjects( DataTag_Bathymetry );
113 }
114
115 bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
116 {
117   if ( theObject.IsNull() )
118     return false;
119   
120   if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) &&
121        !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) )
122     return false; // Wrong type of object
123
124   if ( HasReference( theObject, DataTag_GeometryObject ) )
125     return false; // Object is already in reference list
126
127   AddReferenceObject( theObject, DataTag_GeometryObject );
128   return true;
129 }
130
131 HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
132 {
133   return GetReferenceObjects( DataTag_GeometryObject );
134 }
135
136 void HYDROData_Zone::RemoveGeometryObjects()
137 {
138   ClearReferenceObjects( DataTag_GeometryObject );
139 }
140
141
142