Salome HOME
Dump to Python script correction.
[modules/hydro.git] / src / HYDROData / HYDROData_Zone.cxx
1
2 #include "HYDROData_Zone.h"
3
4 #include "HYDROData_Document.h"
5 #include "HYDROData_Object.h"
6
7 #include <TNaming_Builder.hxx>
8 #include <TNaming_NamedShape.hxx>
9
10 #include <TopoDS_Shape.hxx>
11
12 #include <QStringList>
13
14 #define PYTHON_ZONE_ID "KIND_ZONE"
15
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity)
18
19
20 HYDROData_Zone::HYDROData_Zone()
21 : HYDROData_Entity()
22 {
23 }
24
25 HYDROData_Zone::~HYDROData_Zone()
26 {
27 }
28
29 QStringList HYDROData_Zone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
30 {
31   QStringList aResList;
32
33   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
34   if ( aDocument.IsNull() )
35     return aResList;
36
37   QString aDocName = aDocument->GetDocPyName();
38   QString aZoneName = GetName();
39
40   aResList << QString( "%1 = %2.CreateObject( %3 );" )
41               .arg( aZoneName ).arg( aDocName ).arg( PYTHON_ZONE_ID );
42   aResList << QString( "%1.SetName( \"%2\" );" )
43               .arg( aZoneName ).arg( aZoneName );
44   aResList << QString( "" );
45
46   HYDROData_SequenceOfObjects aGeomObjects = GetGeometryObjects();
47   HYDROData_SequenceOfObjects::Iterator aGeomObjsIter( aGeomObjects );
48   for ( ; aGeomObjsIter.More(); aGeomObjsIter.Next() )
49   {
50     Handle(HYDROData_Object) aRefGeomObj =
51       Handle(HYDROData_Object)::DownCast( aGeomObjsIter.Value() );
52     if ( !aRefGeomObj.IsNull() )
53       setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" );
54   }
55
56   // How can we get the shape? Mb Update() method to intersect the shapes of reference objects?
57   // TODO:  TopoDS_Shape aRefShape = GetShape();
58
59   return aResList;
60 }
61
62 void HYDROData_Zone::SetShape( const TopoDS_Shape& theShape )
63 {
64   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
65   aBuilder.Generated( theShape );
66 }
67
68 TopoDS_Shape HYDROData_Zone::GetShape() const
69 {
70   Handle(TNaming_NamedShape) aNamedShape;
71   if( myLab.FindChild( DataTag_Shape ).FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
72     return aNamedShape->Get();
73   return TopoDS_Shape();
74 }
75
76 int HYDROData_Zone::NbGeometryObjects() const
77 {
78   return NbReferenceObjects( DataTag_GeometryObject );
79 }
80
81 void HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject )
82 {
83   AddReferenceObject( theObject, DataTag_GeometryObject );
84 }
85
86 void HYDROData_Zone::SetGeometryObject( const int                       theIndex,
87                                         const Handle(HYDROData_Object)& theObject )
88 {
89   SetReferenceObject( theObject, DataTag_GeometryObject, theIndex );
90 }
91
92 void HYDROData_Zone::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects )
93 {
94   SetReferenceObjects( theObjects, DataTag_GeometryObject );
95 }
96
97 Handle(HYDROData_Object) HYDROData_Zone::GetGeometryObject( const int theIndex ) const
98 {
99   return Handle(HYDROData_Object)::DownCast( 
100            GetReferenceObject( DataTag_GeometryObject, theIndex ) );
101 }
102
103 HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const
104 {
105   return GetReferenceObjects( DataTag_GeometryObject );
106 }
107
108 void HYDROData_Zone::RemoveGeometryObjects()
109 {
110   ClearReferenceObjects( DataTag_GeometryObject );
111 }
112
113
114
115