]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_IPolyline.cxx
Salome HOME
lots 3,8
[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 void HYDROData_IPolyline::getSectionColor( const int theSectionIndex,
172                                            QColor& theColor,
173                                            const bool theIsCreate ) const
174 {
175   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, theIsCreate );
176   if ( aLabel.IsNull() )
177     return;
178
179   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
180   if ( aSectLabel.IsNull() )
181     return;
182
183   Handle(TDataStd_IntegerArray) aColorArray;
184   if (theIsCreate)
185   {
186     if ( !aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
187       aColorArray = TDataStd_IntegerArray::Set( aSectLabel, 1, 4 );
188
189     aColorArray->SetValue( 1, theColor.red()   );
190     aColorArray->SetValue( 2, theColor.green() );
191     aColorArray->SetValue( 3, theColor.blue()  );
192     aColorArray->SetValue( 4, theColor.alpha() );
193   }
194   else
195   {
196     Handle(TDataStd_IntegerArray) aColorArray;
197     if ( aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
198     {
199       theColor.setRed(   aColorArray->Value( 1 ) );
200       theColor.setGreen( aColorArray->Value( 2 ) );
201       theColor.setBlue(  aColorArray->Value( 3 ) );
202       theColor.setAlpha( aColorArray->Value( 4 ) );
203     }
204   }
205 }
206
207 void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
208 {
209   TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
210   if ( aLabel.IsNull() )
211     return;
212
213   if ( theSectionIndex < 0 )
214   {
215     aLabel.ForgetAllAttributes();
216   }
217   else
218   {
219     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
220     if ( !aSectLabel.IsNull() )
221       aSectLabel.ForgetAllAttributes();
222   }
223 }