Salome HOME
Update mechanism is corrected (Bug #182).
[modules/hydro.git] / src / HYDROData / HYDROData_IPolyline.cxx
1
2 #include "HYDROData_IPolyline.h"
3
4 #include <gp_XY.hxx>
5
6 #include <TDataStd_BooleanList.hxx>
7 #include <TDataStd_ExtStringList.hxx>
8 #include <TDataStd_IntegerList.hxx>
9 #include <TDataStd_RealList.hxx>
10
11 #include <TopoDS_Shape.hxx>
12
13 #include <TNaming_Builder.hxx>
14 #include <TNaming_NamedShape.hxx>
15
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
18
19 HYDROData_IPolyline::HYDROData_IPolyline()
20 : HYDROData_Entity()
21 {
22 }
23
24 HYDROData_IPolyline::~HYDROData_IPolyline()
25 {
26 }
27
28 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
29 {
30   return GetPoints( theSectionIndex ).Length();
31 }
32
33 TopoDS_Shape HYDROData_IPolyline::getPolylineShape() const
34 {
35   TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
36   if ( !aShapeLabel.IsNull() )
37   {
38     Handle(TNaming_NamedShape) aNamedShape;
39     if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
40       return aNamedShape->Get();
41   }
42   return TopoDS_Shape();
43 }
44
45 void HYDROData_IPolyline::setPolylineShape( const TopoDS_Shape& theShape )
46 {
47   TNaming_Builder aBuilder( myLab.FindChild( DataTag_PolylineShape ) );
48   aBuilder.Generated( theShape );
49 }
50
51 void HYDROData_IPolyline::removePolylineShape()
52 {
53   TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
54   if ( !aShapeLabel.IsNull() )
55     aShapeLabel.ForgetAllAttributes();
56 }
57
58 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
59                                             Handle(TDataStd_IntegerList)&   theTypesList,
60                                             Handle(TDataStd_BooleanList)&   theClosuresList,
61                                             const bool                      theIsCreate ) const
62 {
63   theNamesList.Nullify();
64   theTypesList.Nullify();
65   theClosuresList.Nullify();
66
67   TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
68   if ( aSectLabel.IsNull() )
69     return;
70
71   if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
72     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
73
74   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
75     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
76
77   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
78     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
79 }
80
81 void HYDROData_IPolyline::removeSectionsLists()
82 {
83   TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
84   if ( !aSectsLabel.IsNull() )
85     aSectsLabel.ForgetAllAttributes();
86 }
87
88 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
89                                           Handle(TDataStd_RealList)& theListX,
90                                           Handle(TDataStd_RealList)& theListY,
91                                           const bool                 theIsCreate ) const
92 {
93   theListX.Nullify();
94   theListY.Nullify();
95
96   TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
97   if ( aLabel.IsNull() )
98     return;
99
100   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
101   if ( aSectLabel.IsNull() )
102     return;
103
104   TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
105   if ( !aLabelX.IsNull() )
106   {
107     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
108       theListX = TDataStd_RealList::Set( aLabelX );
109   }
110
111   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
112   if ( !aLabelY.IsNull() )
113   {
114     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
115       theListY = TDataStd_RealList::Set( aLabelY );
116   }
117 }
118
119 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
120 {
121   TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
122   if ( aLabel.IsNull() )
123     return;
124
125   if ( theSectionIndex < 0 )
126   {
127     aLabel.ForgetAllAttributes();
128   }
129   else
130   {
131     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
132     if ( !aSectLabel.IsNull() )
133       aSectLabel.ForgetAllAttributes();
134   }
135 }