Salome HOME
correct update status of stream and DTM
[modules/hydro.git] / src / HYDROData / HYDROData_IPolyline.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_IPolyline.h"
20
21 #include <gp_XY.hxx>
22
23 #include <TDataStd_BooleanList.hxx>
24 #include <TDataStd_ExtStringList.hxx>
25 #include <TDataStd_IntegerList.hxx>
26 #include <TDataStd_RealList.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <QColor>
29
30 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
31 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
32
33 HYDROData_IPolyline::HYDROData_IPolyline()
34 : HYDROData_Entity( Geom_2d )
35 {
36 }
37
38 HYDROData_IPolyline::~HYDROData_IPolyline()
39 {
40 }
41
42 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
43 {
44   SetColor( theColor, DataTag_WireColor );
45 }
46
47 QColor HYDROData_IPolyline::GetWireColor() const
48 {
49   return GetColor( DefaultWireColor(), DataTag_WireColor );
50 }
51
52 QColor HYDROData_IPolyline::DefaultWireColor()
53 {
54   return QColor( Qt::black );
55 }
56
57 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
58 {
59   return GetPoints( theSectionIndex ).Length();
60 }
61
62 TopoDS_Shape HYDROData_IPolyline::GetShape() const
63 {
64   return HYDROData_Entity::GetShape( DataTag_PolylineShape );
65 }
66
67 void HYDROData_IPolyline::SetShape( const TopoDS_Shape& theShape )
68 {
69   HYDROData_Entity::SetShape( DataTag_PolylineShape, theShape );
70 }
71
72 void HYDROData_IPolyline::RemovePolylineShape()
73 {
74   SetShape( TopoDS_Shape() );
75 }
76
77 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
78                                             Handle(TDataStd_IntegerList)&   theTypesList,
79                                             Handle(TDataStd_BooleanList)&   theClosuresList,
80                                             const bool                      theIsCreate ) const
81 {
82   theNamesList.Nullify();
83   theTypesList.Nullify();
84   theClosuresList.Nullify();
85
86   TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
87   if ( aSectLabel.IsNull() )
88     return;
89
90   if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
91     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
92
93   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
94     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
95
96   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
97     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
98 }
99
100 void HYDROData_IPolyline::removeSectionsLists()
101 {
102   TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
103   if ( !aSectsLabel.IsNull() )
104     aSectsLabel.ForgetAllAttributes();
105 }
106
107 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
108                                           Handle(TDataStd_RealList)& theListX,
109                                           Handle(TDataStd_RealList)& theListY,
110                                           const bool                 theIsCreate ) const
111 {
112   theListX.Nullify();
113   theListY.Nullify();
114
115   TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
116   if ( aLabel.IsNull() )
117     return;
118
119   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
120   if ( aSectLabel.IsNull() )
121     return;
122
123   TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
124   if ( !aLabelX.IsNull() )
125   {
126     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
127       theListX = TDataStd_RealList::Set( aLabelX );
128   }
129
130   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
131   if ( !aLabelY.IsNull() )
132   {
133     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
134       theListY = TDataStd_RealList::Set( aLabelY );
135   }
136 }
137
138 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
139 {
140   TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
141   if ( aLabel.IsNull() )
142     return;
143
144   if ( theSectionIndex < 0 )
145   {
146     aLabel.ForgetAllAttributes();
147   }
148   else
149   {
150     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
151     if ( !aSectLabel.IsNull() )
152       aSectLabel.ForgetAllAttributes();
153   }
154 }