Salome HOME
180f640481f2297b78088bdf50be42e764296068
[modules/hydro.git] / src / HYDROData / HYDROData_LandCover.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_LandCover.h"
20
21 #include "HYDROData_PolylineXY.h"
22
23 #include <TDataStd_AsciiString.hxx>
24 #include <TNaming_Builder.hxx>
25 #include <TopoDS_Shape.hxx>
26
27 #include <QStringList>
28
29 IMPLEMENT_STANDARD_HANDLE( HYDROData_LandCover, HYDROData_Entity )
30 IMPLEMENT_STANDARD_RTTIEXT( HYDROData_LandCover, HYDROData_Entity )
31
32 HYDROData_LandCover::HYDROData_LandCover()
33 {
34 }
35
36 HYDROData_LandCover::~HYDROData_LandCover()
37 {
38 }
39
40 const ObjectKind HYDROData_LandCover::GetKind() const
41 {
42   return KIND_LAND_COVER;
43 }
44
45 QStringList HYDROData_LandCover::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
46 {
47   QStringList aResList = dumpObjectCreation( theTreatedObjects );
48   QString aName = GetObjPyName();
49   
50   // Set Strickler type
51   QString aType = GetStricklerType();
52   if ( !aType.isEmpty() ) {
53     aResList << QString( "" );
54     ///< \TODO to be implemented:
55     // aResList << QString( "%1.SetStricklerType( \"%2\" );" ).arg( aName ).arg( aType );
56     aResList << QString( "" );
57   }
58
59   // Set polylines
60   ///< \TODO to be implemented: 
61   
62   aResList << QString( "" );
63   aResList << QString( "%1.Update();" ).arg( aName );
64   aResList << QString( "" );
65
66   return aResList;
67 }
68
69 HYDROData_SequenceOfObjects HYDROData_LandCover::GetAllReferenceObjects() const
70 {
71   HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
72
73   HYDROData_SequenceOfObjects aSeqOfPolylines = GetPolylines();
74   aResSeq.Append( aSeqOfPolylines );
75
76   return aResSeq;
77 }
78
79 bool HYDROData_LandCover::IsHas2dPrs() const
80 {
81   return true;
82 }
83
84 void HYDROData_LandCover::SetStricklerType( const QString& theType )
85 {
86   TCollection_AsciiString anAsciiStr( theType.toStdString().c_str() );
87   TDataStd_AsciiString::Set( myLab.FindChild( DataTag_StricklerType ), anAsciiStr );
88 }
89
90 QString HYDROData_LandCover::GetStricklerType() const
91 {
92   QString aType;
93
94   TDF_Label aLabel = myLab.FindChild( DataTag_StricklerType, false );
95   if ( !aLabel.IsNull() ) {
96     Handle(TDataStd_AsciiString) anAsciiStr;
97     if ( aLabel.FindAttribute( TDataStd_AsciiString::GetID(), anAsciiStr ) ) {
98       aType = QString( anAsciiStr->Get().ToCString() );
99     }
100   }
101
102   return aType;
103 }
104
105 void HYDROData_LandCover::Update()
106 {
107   HYDROData_Entity::Update();
108   
109   removeShape();
110
111   TopoDS_Shape aResShape = buildShape();
112   
113   setShape( aResShape );
114 }
115
116 void HYDROData_LandCover::SetPolylines( const HYDROData_SequenceOfObjects& thePolylines )
117 {
118   SetReferenceObjects( thePolylines, DataTag_Polylines );
119   SetToUpdate( true );
120 }
121
122 HYDROData_SequenceOfObjects HYDROData_LandCover::GetPolylines() const
123 {
124   return GetReferenceObjects( DataTag_Polylines );
125 }
126
127 void HYDROData_LandCover::setShape( const TopoDS_Shape& theShape )
128 {
129   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
130   aBuilder.Generated( theShape );
131 }
132
133 void HYDROData_LandCover::removeShape()
134 {
135   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
136   if ( !aLabel.IsNull() ) {
137     aLabel.ForgetAllAttributes();
138   }
139 }
140  
141 TopoDS_Shape HYDROData_LandCover::buildShape() const
142 {
143   TopoDS_Shape aResShape;
144
145   ///< \TODO to be reimplemented
146   HYDROData_SequenceOfObjects aRefPolylines = GetPolylines();
147   for ( int i = 1, n = aRefPolylines.Length(); i <= n; ++i ) {
148     Handle(HYDROData_PolylineXY) aPolyline = 
149       Handle(HYDROData_PolylineXY)::DownCast( aRefPolylines.Value( i ) );
150     
151     if ( aPolyline.IsNull() ) {
152       continue;
153     }
154
155     if ( aPolyline->IsClosed() ) {
156       aResShape = aPolyline->GetShape();
157       break;
158     }
159   }
160   return aResShape;
161 }