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