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