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>
28 #include <TopoDS_Shape.hxx>
30 #include <TNaming_Builder.hxx>
31 #include <TNaming_NamedShape.hxx>
35 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
38 HYDROData_IPolyline::HYDROData_IPolyline()
39 : HYDROData_Entity( Geom_2d )
43 HYDROData_IPolyline::~HYDROData_IPolyline()
47 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
49 SetColor( theColor, DataTag_WireColor );
52 QColor HYDROData_IPolyline::GetWireColor() const
54 return GetColor( DefaultWireColor(), DataTag_WireColor );
57 QColor HYDROData_IPolyline::DefaultWireColor()
59 return QColor( Qt::black );
62 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
64 return GetPoints( theSectionIndex ).Length();
67 TopoDS_Shape HYDROData_IPolyline::getPolylineShape() const
69 TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
70 if ( !aShapeLabel.IsNull() )
72 Handle(TNaming_NamedShape) aNamedShape;
73 if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
74 return aNamedShape->Get();
76 return TopoDS_Shape();
79 void HYDROData_IPolyline::setPolylineShape( const TopoDS_Shape& theShape )
81 TNaming_Builder aBuilder( myLab.FindChild( DataTag_PolylineShape ) );
82 aBuilder.Generated( theShape );
85 void HYDROData_IPolyline::removePolylineShape()
87 TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
88 if ( !aShapeLabel.IsNull() )
89 aShapeLabel.ForgetAllAttributes();
92 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
93 Handle(TDataStd_IntegerList)& theTypesList,
94 Handle(TDataStd_BooleanList)& theClosuresList,
95 const bool theIsCreate ) const
97 theNamesList.Nullify();
98 theTypesList.Nullify();
99 theClosuresList.Nullify();
101 TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
102 if ( aSectLabel.IsNull() )
105 if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
106 theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
108 if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
109 theTypesList = TDataStd_IntegerList::Set( aSectLabel );
111 if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
112 theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
115 void HYDROData_IPolyline::removeSectionsLists()
117 TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
118 if ( !aSectsLabel.IsNull() )
119 aSectsLabel.ForgetAllAttributes();
122 void HYDROData_IPolyline::getPointsLists( const int theSectionIndex,
123 Handle(TDataStd_RealList)& theListX,
124 Handle(TDataStd_RealList)& theListY,
125 const bool theIsCreate ) const
130 TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
131 if ( aLabel.IsNull() )
134 TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
135 if ( aSectLabel.IsNull() )
138 TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
139 if ( !aLabelX.IsNull() )
141 if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
142 theListX = TDataStd_RealList::Set( aLabelX );
145 TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
146 if ( !aLabelY.IsNull() )
148 if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
149 theListY = TDataStd_RealList::Set( aLabelY );
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();