Salome HOME
Merging with V7_main branch.
[modules/hydro.git] / src / HYDROPy / HYDROData_Bathymetry.sip
1 // Copyright (C) 2007-2013  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.
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 %ExportedHeaderCode
24 #include <HYDROData_Bathymetry.h>
25 #include <gp_XY.hxx>
26 #include <gp_XYZ.hxx>
27 %End
28
29 %ModuleCode
30
31 PyObject* convertToPythonAltitudeList( const HYDROData_Bathymetry::AltitudePoints& thePoints );
32 HYDROData_Bathymetry::AltitudePoints convertFromPythonAltitudeList( PyObject* thePythonList );
33
34 %End
35
36 class HYDROData_Bathymetry : HYDROData_Entity
37 {
38
39 %ConvertToSubClassCode
40     switch ( sipCpp->GetKind() )
41     {
42       case KIND_BATHYMETRY:
43         sipClass = sipClass_HYDROData_Bathymetry;
44         break;
45
46       default:
47         // We don't recognise the type.
48         sipClass = NULL;
49     }
50 %End
51
52 %TypeHeaderCode
53 #include <HYDROData_Bathymetry.h>
54 %End
55
56 %TypeCode
57
58 PyObject* convertToPythonAltitudeList( const HYDROData_Bathymetry::AltitudePoints& thePoints )
59
60   int aListSize = thePoints.size();
61
62   PyObject* aPythonList = NULL;
63   if ( ( aPythonList = PyList_New( aListSize ) ) == NULL )
64     return NULL;
65         
66   for ( int i = 0; i < aListSize; ++i )
67   {
68     const HYDROData_Bathymetry::AltitudePoint& aPoint = thePoints.at( i );
69
70     PyObject* aTypleObj = Py_BuildValue( "(ddd)", aPoint.X(), aPoint.Y(), aPoint.Z() );
71
72     PyList_SET_ITEM( aPythonList, i, aTypleObj );
73   }
74
75   return aPythonList;
76 }
77
78 HYDROData_Bathymetry::AltitudePoints convertFromPythonAltitudeList( PyObject* thePythonList )
79
80   HYDROData_Bathymetry::AltitudePoints aPoints;
81   if ( thePythonList == NULL )
82     return aPoints;
83
84   for ( int i = 0, n = PyList_GET_SIZE( thePythonList ); i < n; ++i )
85   {
86     PyObject* aTypleObj = PyList_GET_ITEM( thePythonList, i );
87
88     double anArr[ 3 ];
89     if ( !PyArg_ParseTuple( aTypleObj, "ddd", &anArr[ 0 ], &anArr[ 1 ], &anArr[ 2 ] ) )
90       continue;
91
92     HYDROData_Bathymetry::AltitudePoint aPoint;
93     aPoint.SetX( anArr[ 0 ] );
94     aPoint.SetY( anArr[ 1 ] );
95     aPoint.SetZ( anArr[ 2 ] );
96
97     aPoints.append( aPoint );
98   }
99   
100   return aPoints;
101 }
102
103 %End
104
105 public:      
106   // Public methods to work with Bathymetry altitudes.
107
108   /**
109    * Returns altitude points list.
110    * \return points list
111    */
112   static double             GetInvalidAltitude();
113
114   /**
115    * Replace current altitude points by new one.
116    * \param thePoints the altitude points list
117    */
118   virtual void             SetAltitudePoints( SIP_PYLIST ) [void (const HYDROData_Bathymetry::AltitudePoints&)] ;
119   %MethodCode
120   
121     // The C++ API takes a list of gp_XYZ objects,
122     // but we pass a list of python tuples.
123
124     HYDROData_Bathymetry::AltitudePoints aPoints =
125       convertFromPythonAltitudeList( a0 );
126
127     Py_BEGIN_ALLOW_THREADS
128     sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::SetAltitudePoints( aPoints ) : 
129                     sipCpp->SetAltitudePoints( aPoints );
130     Py_END_ALLOW_THREADS
131
132   %End
133   %VirtualCatcherCode
134   
135     PyObject* aPythonList = convertToPythonAltitudeList( a0 );
136     if ( aPythonList != NULL )
137     {
138       sipCallMethod( &sipIsErr, sipMethod, "O", aPythonList );
139       Py_DECREF( aPythonList );
140     }
141     
142   %End
143
144   /**
145    * Returns altitude points list.
146    * \return points list
147    */
148   SIP_PYLIST GetAltitudePoints() const [HYDROData_Bathymetry::AltitudePoints ()] ;
149   %MethodCode
150   
151     // The C++ API returns a list of gp_XYZ objects,
152     // we convert it to list of python tuples.
153
154     HYDROData_Bathymetry::AltitudePoints aPoints;
155     
156     Py_BEGIN_ALLOW_THREADS
157     aPoints = sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::GetAltitudePoints() : 
158                               sipCpp->GetAltitudePoints();
159     Py_END_ALLOW_THREADS
160
161     sipRes = convertToPythonAltitudeList( aPoints );
162     
163   %End
164
165   /**
166    * Remove all altitude points.
167    */
168   void              RemoveAltitudePoints();
169
170   /**
171    * Returns altitude for given point.
172    * \param thePoint the point to examine
173    * \return altitude value
174    */
175   double           GetAltitudeForPoint( const QPointF& thePoint ) const;
176   %MethodCode
177   
178     // The C++ API gets the gp_XY object, we convert it from QPointF.
179     gp_XY aPoint( a0->x(), a0->y() );
180     
181     Py_BEGIN_ALLOW_THREADS
182     sipRes = sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::GetAltitudeForPoint( aPoint ) : 
183                              sipCpp->GetAltitudeForPoint( aPoint );
184     Py_END_ALLOW_THREADS
185   %End
186
187
188 public:
189   // Public methods to work with files.
190
191   /**
192    * Imports Bathymetry data from file. The supported file types:
193    *  - xyz
194    * \param theFileName the path to file
195    * \return \c true if file has been successfully read
196    */
197   bool             ImportFromFile( const QString& theFileName );
198
199
200 protected:
201
202   /**
203    * Creates new object in the internal data structure. Use higher level objects 
204    * to create objects with real content.
205    */
206   HYDROData_Bathymetry();
207
208   /**
209    * Destructs properties of the object and object itself, removes it from the document.
210    */
211   ~HYDROData_Bathymetry();
212 };
213
214