Salome HOME
#refs 522 (very draft) //import only
[modules/hydro.git] / src / HYDROData / HYDROData_IPolyline.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROData_IPolyline.h"
24
25 #include <gp_XY.hxx>
26
27 #include <TDataStd_BooleanList.hxx>
28 #include <TDataStd_ExtStringList.hxx>
29 #include <TDataStd_IntegerList.hxx>
30 #include <TDataStd_RealList.hxx>
31
32 #include <TopoDS_Shape.hxx>
33
34 #include <TNaming_Builder.hxx>
35 #include <TNaming_NamedShape.hxx>
36
37 #include <QColor>
38
39 IMPLEMENT_STANDARD_HANDLE(HYDROData_IPolyline, HYDROData_Entity)
40 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
41
42 HYDROData_IPolyline::HYDROData_IPolyline()
43 : HYDROData_Entity()
44 {
45 }
46
47 HYDROData_IPolyline::~HYDROData_IPolyline()
48 {
49 }
50
51 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
52 {
53   SetColor( theColor, DataTag_WireColor );
54 }
55
56 QColor HYDROData_IPolyline::GetWireColor() const
57 {
58   return GetColor( DefaultWireColor(), DataTag_WireColor );
59 }
60
61 QColor HYDROData_IPolyline::DefaultWireColor()
62 {
63   return QColor( Qt::black );
64 }
65
66 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
67 {
68   return GetPoints( theSectionIndex ).Length();
69 }
70
71 TopoDS_Shape HYDROData_IPolyline::getPolylineShape() const
72 {
73   TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
74   if ( !aShapeLabel.IsNull() )
75   {
76     Handle(TNaming_NamedShape) aNamedShape;
77     if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
78       return aNamedShape->Get();
79   }
80   return TopoDS_Shape();
81 }
82
83 void HYDROData_IPolyline::setPolylineShape( const TopoDS_Shape& theShape )
84 {
85   TNaming_Builder aBuilder( myLab.FindChild( DataTag_PolylineShape ) );
86   aBuilder.Generated( theShape );
87 }
88
89 void HYDROData_IPolyline::removePolylineShape()
90 {
91   TDF_Label aShapeLabel = myLab.FindChild( DataTag_PolylineShape, false );
92   if ( !aShapeLabel.IsNull() )
93     aShapeLabel.ForgetAllAttributes();
94 }
95
96 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
97                                             Handle(TDataStd_IntegerList)&   theTypesList,
98                                             Handle(TDataStd_BooleanList)&   theClosuresList,
99                                             const bool                      theIsCreate ) const
100 {
101   theNamesList.Nullify();
102   theTypesList.Nullify();
103   theClosuresList.Nullify();
104
105   TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
106   if ( aSectLabel.IsNull() )
107     return;
108
109   if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
110     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
111
112   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
113     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
114
115   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
116     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
117 }
118
119 void HYDROData_IPolyline::removeSectionsLists()
120 {
121   TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
122   if ( !aSectsLabel.IsNull() )
123     aSectsLabel.ForgetAllAttributes();
124 }
125
126 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
127                                           Handle(TDataStd_RealList)& theListX,
128                                           Handle(TDataStd_RealList)& theListY,
129                                           const bool                 theIsCreate ) const
130 {
131   theListX.Nullify();
132   theListY.Nullify();
133
134   TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
135   if ( aLabel.IsNull() )
136     return;
137
138   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
139   if ( aSectLabel.IsNull() )
140     return;
141
142   TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
143   if ( !aLabelX.IsNull() )
144   {
145     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
146       theListX = TDataStd_RealList::Set( aLabelX );
147   }
148
149   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
150   if ( !aLabelY.IsNull() )
151   {
152     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
153       theListY = TDataStd_RealList::Set( aLabelY );
154   }
155 }
156
157 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
158 {
159   TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
160   if ( aLabel.IsNull() )
161     return;
162
163   if ( theSectionIndex < 0 )
164   {
165     aLabel.ForgetAllAttributes();
166   }
167   else
168   {
169     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
170     if ( !aSectLabel.IsNull() )
171       aSectLabel.ForgetAllAttributes();
172   }
173 }