Salome HOME
lots 3,8 - corrections
[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 <TDataStd_IntegerArray.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <QColor>
30
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   {
92     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
93     theNamesList->SetID(TDataStd_ExtStringList::GetID());
94   }
95
96   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
97   {
98     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
99     theTypesList->SetID(TDataStd_IntegerList::GetID());
100   }
101
102   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
103   {
104     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
105     theClosuresList->SetID(TDataStd_BooleanList::GetID());
106   }
107 }
108
109 void HYDROData_IPolyline::removeSectionsLists()
110 {
111   TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
112   if ( !aSectsLabel.IsNull() )
113     aSectsLabel.ForgetAllAttributes();
114 }
115
116 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
117                                           Handle(TDataStd_RealList)& theListX,
118                                           Handle(TDataStd_RealList)& theListY,
119                                           const bool                 theIsCreate ) const
120 {
121   theListX.Nullify();
122   theListY.Nullify();
123
124   TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
125   if ( aLabel.IsNull() )
126     return;
127
128   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
129   if ( aSectLabel.IsNull() )
130     return;
131
132   TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
133   if ( !aLabelX.IsNull() )
134   {
135     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
136     {
137       theListX = TDataStd_RealList::Set( aLabelX );
138       theListX->SetID(TDataStd_RealList::GetID());
139     }
140   }
141
142   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
143   if ( !aLabelY.IsNull() )
144   {
145     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
146     {
147       theListY = TDataStd_RealList::Set( aLabelY );
148       theListY->SetID(TDataStd_RealList::GetID());
149     }
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 }
170
171 bool HYDROData_IPolyline::getSectionColor( const int theSectionIndex, QColor &theColor) const
172 {
173   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
174   if ( aLabel.IsNull() )
175     return false;
176
177   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
178   if ( aSectLabel.IsNull() )
179     return false;
180
181   Handle(TDataStd_IntegerArray) aColorArray;
182
183   if ( aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
184   {
185     theColor.setRed(   aColorArray->Value( 1 ) );
186     theColor.setGreen( aColorArray->Value( 2 ) );
187     theColor.setBlue(  aColorArray->Value( 3 ) );
188     theColor.setAlpha( aColorArray->Value( 4 ) );
189   }
190 }
191
192 void HYDROData_IPolyline::setSectionColor( const int theSectionIndex,
193                                            const QColor& theColor ) const
194 {
195   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, true );
196   if ( aLabel.IsNull() )
197     return;
198
199   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, true );
200   if ( aSectLabel.IsNull() )
201     return;
202
203   Handle(TDataStd_IntegerArray) aColorArray;
204
205   if ( !aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
206     aColorArray = TDataStd_IntegerArray::Set( aSectLabel, 1, 4 );
207
208   aColorArray->SetValue( 1, theColor.red()   );
209   aColorArray->SetValue( 2, theColor.green() );
210   aColorArray->SetValue( 3, theColor.blue()  );
211   aColorArray->SetValue( 4, theColor.alpha() );
212 }
213
214 void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
215 {
216   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
217   if ( aLabel.IsNull() )
218     return;
219
220   if ( theSectionIndex < 0 )
221   {
222     aLabel.ForgetAllAttributes();
223   }
224   else
225   {
226     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
227     if ( !aSectLabel.IsNull() )
228       aSectLabel.ForgetAllAttributes();
229   }
230 }