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