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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_IPolyline.h"
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>
31 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
33 HYDROData_IPolyline::HYDROData_IPolyline()
34 : HYDROData_Entity( Geom_2d )
38 HYDROData_IPolyline::~HYDROData_IPolyline()
42 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
44 SetColor( theColor, DataTag_WireColor );
47 QColor HYDROData_IPolyline::GetWireColor() const
49 return GetColor( DefaultWireColor(), DataTag_WireColor );
52 QColor HYDROData_IPolyline::DefaultWireColor()
54 return QColor( Qt::black );
57 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
59 return GetPoints( theSectionIndex ).Length();
62 TopoDS_Shape HYDROData_IPolyline::GetShape() const
64 return HYDROData_Entity::GetShape( DataTag_PolylineShape );
67 void HYDROData_IPolyline::SetShape( const TopoDS_Shape& theShape )
69 HYDROData_Entity::SetShape( DataTag_PolylineShape, theShape );
72 void HYDROData_IPolyline::RemovePolylineShape()
74 SetShape( TopoDS_Shape() );
77 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
78 Handle(TDataStd_IntegerList)& theTypesList,
79 Handle(TDataStd_BooleanList)& theClosuresList,
80 const bool theIsCreate ) const
82 theNamesList.Nullify();
83 theTypesList.Nullify();
84 theClosuresList.Nullify();
86 TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
87 if ( aSectLabel.IsNull() )
90 if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
92 theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
93 theNamesList->SetID(TDataStd_ExtStringList::GetID());
96 if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
98 theTypesList = TDataStd_IntegerList::Set( aSectLabel );
99 theTypesList->SetID(TDataStd_IntegerList::GetID());
102 if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
104 theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
105 theClosuresList->SetID(TDataStd_BooleanList::GetID());
109 void HYDROData_IPolyline::removeSectionsLists()
111 TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
112 if ( !aSectsLabel.IsNull() )
113 aSectsLabel.ForgetAllAttributes();
116 void HYDROData_IPolyline::getPointsLists( const int theSectionIndex,
117 Handle(TDataStd_RealList)& theListX,
118 Handle(TDataStd_RealList)& theListY,
119 const bool theIsCreate ) const
124 TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
125 if ( aLabel.IsNull() )
128 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
129 if ( aSectLabel.IsNull() )
132 TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
133 if ( !aLabelX.IsNull() )
135 if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
137 theListX = TDataStd_RealList::Set( aLabelX );
138 theListX->SetID(TDataStd_RealList::GetID());
142 TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
143 if ( !aLabelY.IsNull() )
145 if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
147 theListY = TDataStd_RealList::Set( aLabelY );
148 theListY->SetID(TDataStd_RealList::GetID());
153 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
155 TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
156 if ( aLabel.IsNull() )
159 if ( theSectionIndex < 0 )
161 aLabel.ForgetAllAttributes();
165 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
166 if ( !aSectLabel.IsNull() )
167 aSectLabel.ForgetAllAttributes();
171 bool HYDROData_IPolyline::getSectionColor( const int theSectionIndex, QColor &theColor) const
173 TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
174 if ( aLabel.IsNull() )
177 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
178 if ( aSectLabel.IsNull() )
181 Handle(TDataStd_IntegerArray) aColorArray;
183 if ( aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
185 theColor.setRed( aColorArray->Value( 1 ) );
186 theColor.setGreen( aColorArray->Value( 2 ) );
187 theColor.setBlue( aColorArray->Value( 3 ) );
188 theColor.setAlpha( aColorArray->Value( 4 ) );
192 void HYDROData_IPolyline::setSectionColor( const int theSectionIndex,
193 const QColor& theColor ) const
195 TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, true );
196 if ( aLabel.IsNull() )
199 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, true );
200 if ( aSectLabel.IsNull() )
203 Handle(TDataStd_IntegerArray) aColorArray;
205 if ( !aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
206 aColorArray = TDataStd_IntegerArray::Set( aSectLabel, 1, 4 );
208 aColorArray->SetValue( 1, theColor.red() );
209 aColorArray->SetValue( 2, theColor.green() );
210 aColorArray->SetValue( 3, theColor.blue() );
211 aColorArray->SetValue( 4, theColor.alpha() );
214 void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
216 TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
217 if ( aLabel.IsNull() )
220 if ( theSectionIndex < 0 )
222 aLabel.ForgetAllAttributes();
226 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
227 if ( !aSectLabel.IsNull() )
228 aSectLabel.ForgetAllAttributes();