]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_IPolyline.cxx
Salome HOME
debug#2 (setID(); GetID())
[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 <TopoDS_Shape.hxx>
28 #include <QColor>
29
30 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_IPolyline, HYDROData_Entity)
31
32 HYDROData_IPolyline::HYDROData_IPolyline()
33 : HYDROData_Entity( Geom_2d )
34 {
35 }
36
37 HYDROData_IPolyline::~HYDROData_IPolyline()
38 {
39 }
40
41 void HYDROData_IPolyline::SetWireColor( const QColor& theColor )
42 {
43   SetColor( theColor, DataTag_WireColor );
44 }
45
46 QColor HYDROData_IPolyline::GetWireColor() const
47 {
48   return GetColor( DefaultWireColor(), DataTag_WireColor );
49 }
50
51 QColor HYDROData_IPolyline::DefaultWireColor()
52 {
53   return QColor( Qt::black );
54 }
55
56 int HYDROData_IPolyline::NbPoints( const int theSectionIndex ) const
57 {
58   return GetPoints( theSectionIndex ).Length();
59 }
60
61 TopoDS_Shape HYDROData_IPolyline::GetShape() const
62 {
63   return HYDROData_Entity::GetShape( DataTag_PolylineShape );
64 }
65
66 void HYDROData_IPolyline::SetShape( const TopoDS_Shape& theShape )
67 {
68   HYDROData_Entity::SetShape( DataTag_PolylineShape, theShape );
69 }
70
71 void HYDROData_IPolyline::RemovePolylineShape()
72 {
73   SetShape( TopoDS_Shape() );
74 }
75
76 void HYDROData_IPolyline::getSectionsLists( Handle(TDataStd_ExtStringList)& theNamesList,
77                                             Handle(TDataStd_IntegerList)&   theTypesList,
78                                             Handle(TDataStd_BooleanList)&   theClosuresList,
79                                             const bool                      theIsCreate ) const
80 {
81   theNamesList.Nullify();
82   theTypesList.Nullify();
83   theClosuresList.Nullify();
84
85   TDF_Label aSectLabel = myLab.FindChild( DataTag_Sections, theIsCreate );
86   if ( aSectLabel.IsNull() )
87     return;
88
89   if ( !aSectLabel.FindAttribute( TDataStd_ExtStringList::GetID(), theNamesList ) && theIsCreate )
90   {
91     theNamesList = TDataStd_ExtStringList::Set( aSectLabel );
92     theNamesList->SetID(TDataStd_ExtStringList::GetID());
93   }
94
95   if ( !aSectLabel.FindAttribute( TDataStd_IntegerList::GetID(), theTypesList ) && theIsCreate )
96   {
97     theTypesList = TDataStd_IntegerList::Set( aSectLabel );
98     theTypesList->SetID(TDataStd_IntegerList::GetID());
99   }
100
101   if ( !aSectLabel.FindAttribute( TDataStd_BooleanList::GetID(), theClosuresList ) && theIsCreate )
102   {
103     theClosuresList = TDataStd_BooleanList::Set( aSectLabel );
104     theClosuresList->SetID(TDataStd_BooleanList::GetID());
105   }
106 }
107
108 void HYDROData_IPolyline::removeSectionsLists()
109 {
110   TDF_Label aSectsLabel = myLab.FindChild( DataTag_Sections, false );
111   if ( !aSectsLabel.IsNull() )
112     aSectsLabel.ForgetAllAttributes();
113 }
114
115 void HYDROData_IPolyline::getPointsLists( const int                  theSectionIndex,
116                                           Handle(TDataStd_RealList)& theListX,
117                                           Handle(TDataStd_RealList)& theListY,
118                                           const bool                 theIsCreate ) const
119 {
120   theListX.Nullify();
121   theListY.Nullify();
122
123   TDF_Label aLabel = myLab.FindChild( DataTag_Points, theIsCreate );
124   if ( aLabel.IsNull() )
125     return;
126
127   TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
128   if ( aSectLabel.IsNull() )
129     return;
130
131   TDF_Label aLabelX = aSectLabel.FindChild( 0, theIsCreate );
132   if ( !aLabelX.IsNull() )
133   {
134     if ( !aLabelX.FindAttribute( TDataStd_RealList::GetID(), theListX ) && theIsCreate )
135     {
136       theListX = TDataStd_RealList::Set( aLabelX );
137       theListX->SetID(TDataStd_RealList::GetID());
138     }
139   }
140
141   TDF_Label aLabelY = aSectLabel.FindChild( 1, theIsCreate );
142   if ( !aLabelY.IsNull() )
143   {
144     if ( !aLabelY.FindAttribute( TDataStd_RealList::GetID(), theListY ) && theIsCreate )
145     {
146       theListY = TDataStd_RealList::Set( aLabelY );
147       theListY->SetID(TDataStd_RealList::GetID());
148     }
149   }
150 }
151
152 void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
153 {
154   TDF_Label aLabel = myLab.FindChild( DataTag_Points, false );
155   if ( aLabel.IsNull() )
156     return;
157
158   if ( theSectionIndex < 0 )
159   {
160     aLabel.ForgetAllAttributes();
161   }
162   else
163   {
164     TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
165     if ( !aSectLabel.IsNull() )
166       aSectLabel.ForgetAllAttributes();
167   }
168 }