Salome HOME
The bathymetry is changed to their base altitude class for geometry objects (Bug...
[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_IAltitudeObject
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 for given point.
110    * \param thePoint the point to examine
111    * \return altitude value
112    */
113   double           GetAltitudeForPoint( const QPointF& thePoint ) const [double (const gp_XY&)];
114   %MethodCode
115   
116     // The C++ API gets the gp_XY object, we convert it from QPointF.
117     gp_XY aPoint( a0->x(), a0->y() );
118     
119     Py_BEGIN_ALLOW_THREADS
120     sipRes = sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::GetAltitudeForPoint( aPoint ) : 
121                              sipCpp->GetAltitudeForPoint( aPoint );
122     Py_END_ALLOW_THREADS
123   %End
124
125
126
127   /**
128    * Replace current altitude points by new one.
129    * \param thePoints the altitude points list
130    */
131   virtual void             SetAltitudePoints( SIP_PYLIST ) [void (const HYDROData_Bathymetry::AltitudePoints&)] ;
132   %MethodCode
133   
134     // The C++ API takes a list of gp_XYZ objects,
135     // but we pass a list of python tuples.
136
137     HYDROData_Bathymetry::AltitudePoints aPoints =
138       convertFromPythonAltitudeList( a0 );
139
140     Py_BEGIN_ALLOW_THREADS
141     sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::SetAltitudePoints( aPoints ) : 
142                     sipCpp->SetAltitudePoints( aPoints );
143     Py_END_ALLOW_THREADS
144
145   %End
146   %VirtualCatcherCode
147   
148     PyObject* aPythonList = convertToPythonAltitudeList( a0 );
149     if ( aPythonList != NULL )
150     {
151       sipCallMethod( &sipIsErr, sipMethod, "O", aPythonList );
152       Py_DECREF( aPythonList );
153     }
154     
155   %End
156
157   /**
158    * Returns altitude points list.
159    * \return points list
160    */
161   SIP_PYLIST GetAltitudePoints() const [HYDROData_Bathymetry::AltitudePoints ()] ;
162   %MethodCode
163   
164     // The C++ API returns a list of gp_XYZ objects,
165     // we convert it to list of python tuples.
166
167     HYDROData_Bathymetry::AltitudePoints aPoints;
168     
169     Py_BEGIN_ALLOW_THREADS
170     aPoints = sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::GetAltitudePoints() : 
171                               sipCpp->GetAltitudePoints();
172     Py_END_ALLOW_THREADS
173
174     sipRes = convertToPythonAltitudeList( aPoints );
175     
176   %End
177
178   /**
179    * Remove all altitude points.
180    */
181   void              RemoveAltitudePoints();
182
183
184 public:
185   // Public methods to work with files.
186
187   /**
188    * Imports Bathymetry data from file. The supported file types:
189    *  - xyz
190    * \param theFileName the path to file
191    * \return \c true if file has been successfully read
192    */
193   bool             ImportFromFile( const QString& theFileName );
194
195
196 protected:
197
198   /**
199    * Creates new object in the internal data structure. Use higher level objects 
200    * to create objects with real content.
201    */
202   HYDROData_Bathymetry();
203
204   /**
205    * Destructs properties of the object and object itself, removes it from the document.
206    */
207   ~HYDROData_Bathymetry();
208 };
209
210