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