Salome HOME
Minor changes.
[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 #include <QColor>
17
18 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
19 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
20
21 HYDROData_IPolyline::HYDROData_IPolyline()
22 : HYDROData_Entity()
23 {
24 }
25
26 HYDROData_IPolyline::~HYDROData_IPolyline()
27 {
28 }
29
30 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
31 {
32   SetColor( theColor, DataTag_WireColor );
33 }
34
35 QColor HYDROData_IPolyline::GetWireColor() const
36 {
37   return GetColor( DefaultWireColor(), DataTag_WireColor );
38 }
39
40 QColor HYDROData_IPolyline::DefaultWireColor()
41 {
42   return QColor( Qt::black );
43 }
44
45 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
46 {
47   return GetPoints( theSectionIndex ).Length();
48 }
49
50 TopoDS_Shape HYDROData_IPolyline::getPolylineShape() const
51 {
52   TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
53   if ( !aShapeLabel.IsNull() )
54   {
55     Handle(TNaming_NamedShape) aNamedShape;
56     if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
57       return aNamedShape->Get();
58   }
59   return TopoDS_Shape();
60 }
61
62 void HYDROData_IPolyline::setPolylineShape( const TopoDS_Shape& theShape )
63 {
64   TNaming_Builder aBuilder( myLab.FindChild( DataTag_PolylineShape ) );
65   aBuilder.Generated( theShape );
66 }
67
68 void HYDROData_IPolyline::removePolylineShape()
69 {
70   TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
71   if ( !aShapeLabel.IsNull() )
72     aShapeLabel.ForgetAllAttributes();
73 }
74
75 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
76                                             Handle(TDataStd_IntegerList)&   theTypesList,
77                                             Handle(TDataStd_BooleanList)&   theClosuresList,
78                                             const bool                      theIsCreate ) const
79 {
80   theNamesList.Nullify();
81   theTypesList.Nullify();
82   theClosuresList.Nullify();
83
84   TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
85   if ( aSectLabel.IsNull() )
86     return;
87
88   if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
89     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
90
91   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
92     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
93
94   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
95     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
96 }
97
98 void HYDROData_IPolyline::removeSectionsLists()
99 {
100   TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
101   if ( !aSectsLabel.IsNull() )
102     aSectsLabel.ForgetAllAttributes();
103 }
104
105 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
106                                           Handle(TDataStd_RealList)& theListX,
107                                           Handle(TDataStd_RealList)& theListY,
108                                           const bool                 theIsCreate ) const
109 {
110   theListX.Nullify();
111   theListY.Nullify();
112
113   TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
114   if ( aLabel.IsNull() )
115     return;
116
117   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
118   if ( aSectLabel.IsNull() )
119     return;
120
121   TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
122   if ( !aLabelX.IsNull() )
123   {
124     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
125       theListX = TDataStd_RealList::Set( aLabelX );
126   }
127
128   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
129   if ( !aLabelY.IsNull() )
130   {
131     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
132       theListY = TDataStd_RealList::Set( aLabelY );
133   }
134 }
135
136 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
137 {
138   TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
139   if ( aLabel.IsNull() )
140     return;
141
142   if ( theSectionIndex < 0 )
143   {
144     aLabel.ForgetAllAttributes();
145   }
146   else
147   {
148     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
149     if ( !aSectLabel.IsNull() )
150       aSectLabel.ForgetAllAttributes();
151   }
152 }