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 ); //DEPRECATED;
45 //set theColor for all sections
46 int nbSec = NbSections();
47 for (int i = 0; i < nbSec; i++)
48 SetSectionColor(i, theColor);
51 QColor HYDROData_IPolyline::GetWireColor() const
53 return GetColor( DefaultWireColor(), DataTag_WireColor );
56 QColor HYDROData_IPolyline::DefaultWireColor()
58 return QColor( Qt::black );
61 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
63 return GetPoints( theSectionIndex ).Length();
66 TopoDS_Shape HYDROData_IPolyline::GetShape() const
68 return HYDROData_Entity::GetShape( DataTag_PolylineShape );
71 void HYDROData_IPolyline::SetShape( const TopoDS_Shape& theShape )
73 HYDROData_Entity::SetShape( DataTag_PolylineShape, theShape );
76 void HYDROData_IPolyline::RemovePolylineShape()
78 SetShape( TopoDS_Shape() );
81 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
82 Handle(TDataStd_IntegerList)& theTypesList,
83 Handle(TDataStd_BooleanList)& theClosuresList,
84 const bool theIsCreate ) const
86 theNamesList.Nullify();
87 theTypesList.Nullify();
88 theClosuresList.Nullify();
90 TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
91 if ( aSectLabel.IsNull() )
94 if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
96 theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
97 theNamesList->SetID(TDataStd_ExtStringList::GetID());
100 if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
102 theTypesList = TDataStd_IntegerList::Set( aSectLabel );
103 theTypesList->SetID(TDataStd_IntegerList::GetID());
106 if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
108 theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
109 theClosuresList->SetID(TDataStd_BooleanList::GetID());
113 void HYDROData_IPolyline::removeSectionsLists()
115 TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
116 if ( !aSectsLabel.IsNull() )
117 aSectsLabel.ForgetAllAttributes();
120 void HYDROData_IPolyline::getPointsLists( const int theSectionIndex,
121 Handle(TDataStd_RealList)& theListX,
122 Handle(TDataStd_RealList)& theListY,
123 const bool theIsCreate ) const
128 TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
129 if ( aLabel.IsNull() )
132 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
133 if ( aSectLabel.IsNull() )
136 TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
137 if ( !aLabelX.IsNull() )
139 if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
141 theListX = TDataStd_RealList::Set( aLabelX );
142 theListX->SetID(TDataStd_RealList::GetID());
146 TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
147 if ( !aLabelY.IsNull() )
149 if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
151 theListY = TDataStd_RealList::Set( aLabelY );
152 theListY->SetID(TDataStd_RealList::GetID());
157 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
159 TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
160 if ( aLabel.IsNull() )
163 if ( theSectionIndex < 0 )
165 aLabel.ForgetAllAttributes();
169 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
170 if ( !aSectLabel.IsNull() )
171 aSectLabel.ForgetAllAttributes();
175 bool HYDROData_IPolyline::GetSectionColor( const int theSectionIndex, QColor &theColor) const
177 TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
178 if ( aLabel.IsNull() )
181 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
182 if ( aSectLabel.IsNull() )
185 Handle(TDataStd_IntegerArray) aColorArray;
187 if ( aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
189 theColor.setRed( aColorArray->Value( 1 ) );
190 theColor.setGreen( aColorArray->Value( 2 ) );
191 theColor.setBlue( aColorArray->Value( 3 ) );
192 theColor.setAlpha( aColorArray->Value( 4 ) );
196 void HYDROData_IPolyline::SetSectionColor( const int theSectionIndex,
197 const QColor& theColor )
199 TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, true );
200 if ( aLabel.IsNull() )
203 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, true );
204 if ( aSectLabel.IsNull() )
207 Handle(TDataStd_IntegerArray) aColorArray;
209 if ( !aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
210 aColorArray = TDataStd_IntegerArray::Set( aSectLabel, 1, 4 );
212 aColorArray->SetValue( 1, theColor.red() );
213 aColorArray->SetValue( 2, theColor.green() );
214 aColorArray->SetValue( 3, theColor.blue() );
215 aColorArray->SetValue( 4, theColor.alpha() );
218 void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
220 TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
221 if ( aLabel.IsNull() )
224 if ( theSectionIndex < 0 )
226 aLabel.ForgetAllAttributes();
230 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
231 if ( !aSectLabel.IsNull() )
232 aSectLabel.ForgetAllAttributes();
236 void HYDROData_IPolyline::setPythonPolylineSectionColor( QStringList& theScript,
237 const int theSectIndex,
238 const QColor& theColor ) const
240 QString anObjName = GetObjPyName();
241 theScript << QString( "%1.SetSectionColor( %2, QColor( %3, %4, %5, %6 ) )" )
242 .arg( anObjName ).arg( theSectIndex )
243 .arg( theColor.red() ).arg( theColor.green() )
244 .arg( theColor.blue() ).arg( theColor.alpha() );