Salome HOME
fix test on stream linear interpolation
[modules/hydro.git] / src / HYDROData / HYDROData_Profile.h
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 #ifndef HYDROData_Profile_HeaderFile
20 #define HYDROData_Profile_HeaderFile
21
22 #include "HYDROData_Object.h"
23 #include "HYDROData_ProfileUZ.h"
24
25 class gp_XYZ;
26 class OSD_File;
27 class HYDROData_Document;
28
29 /**\class HYDROData_Profile
30  * \brief Class that stores/retreives information about the profile.
31  */
32 class HYDROData_Profile : public HYDROData_Object
33 {
34 public:
35
36   typedef gp_XYZ                             ProfilePoint;
37   typedef NCollection_Sequence<ProfilePoint> ProfilePoints;
38
39 protected:
40   /**
41    * Enumeration of tags corresponding to the persistent object parameters.
42    */
43   enum DataTag
44   {
45     DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve
46     DataTag_FirstPoint,       ///< first(left) point
47     DataTag_LastPoint,        ///< last(right) point
48     DataTag_ChildProfileUZ,   ///< child parametric profile
49     DataTag_FilePath,          ///< profile imported file path
50     DataTag_ProfileColor      ///< color of profile
51   };
52
53 public:
54   DEFINE_STANDARD_RTTIEXT(HYDROData_Profile, HYDROData_Object);
55
56   /**
57    * Returns the kind of this object. Must be redefined in all objects of known type.
58    */
59   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_PROFILE; }
60
61   /**
62    * Dump object to Python script representation.
63    */
64   HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
65                                                      MapOfTreatedObjects& theTreatedObjects ) const;
66
67   /**
68    * Returns the top shape of the object.
69    */
70   HYDRODATA_EXPORT virtual TopoDS_Shape GetTopShape() const;
71
72   /**
73    * Returns the 3d shape of the object.
74    */
75   HYDRODATA_EXPORT virtual TopoDS_Shape GetShape3D(bool forceRebuild = false, bool reverseXCoord = false) const;
76
77   /**
78    * Updates profile 3D presentation.
79    * Call this method whenever you made changes in data structure.
80    * This method does not called automatically since it may take a very long time.
81    */
82   HYDRODATA_EXPORT virtual void Update();
83
84   HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
85
86   HYDRODATA_EXPORT static ProfilePoints CalculateProfilePoints(const HYDROData_ProfileUZ::PointsList& theParametricPoints, 
87   const gp_XY& aFirstPoint, const gp_XY& aLastPoint);
88
89   /**
90    * Returns default filling color for new profile.
91    */
92   HYDRODATA_EXPORT virtual QColor DefaultFillingColor() const;
93
94   /**
95    * Returns default border color for new profile.
96    */
97   HYDRODATA_EXPORT virtual QColor DefaultBorderColor() const;
98
99
100 public:
101
102   /**
103    * Check profile data and returns true if profile is valid.
104    * Validity is determined by:
105    *   - First(left) and Last(right) point was set
106    *   - Parametric points size is more than 1
107    */
108   HYDRODATA_EXPORT bool IsValid() const;
109
110   /**
111    * Invalidate profile first and last points.
112    */
113   HYDRODATA_EXPORT void Invalidate();
114   
115 public:
116
117   // Public methods to work with profile points.
118
119   /**
120    * Set first(left) point for profile.
121    * \param thePoint the point
122    */
123   HYDRODATA_EXPORT void SetLeftPoint( const gp_XY& thePoint, bool IsConvertFromGlobal = false );
124
125   /**
126    * Returns first(left) point of profile.
127    * \param thePoint[out] profile first point
128    * \return true if point has been set
129    */
130   HYDRODATA_EXPORT bool GetLeftPoint( gp_XY& thePoint, bool IsConvertToGlobal = false,
131                                       bool CanUseDefault = false ) const;
132
133   /**
134    * Set last(right) point for profile.
135    * \param thePoint the point
136    */
137   HYDRODATA_EXPORT void SetRightPoint( const gp_XY& thePoint, bool IsConvertFromGlobal = false );
138
139   /**
140    * Returns last(right) point of profile.
141    * \param thePoint[out] profile last point
142    * \return true if point has been set
143    */
144   HYDRODATA_EXPORT bool GetRightPoint( gp_XY& thePoint, bool IsConvertToGlobal = false,
145                                        bool CanUseDefault = false ) const;
146
147   /**
148    * Returns object which store parametric presentation of profile points.
149    * \return profile U,Z
150    */
151   HYDRODATA_EXPORT Handle(HYDROData_ProfileUZ) GetProfileUZ( const bool theIsCreate = true ) const;
152
153
154   /**
155    * Return number of profile points.
156    * \return number of points
157    */
158   HYDRODATA_EXPORT int NbPoints() const;
159
160   /**
161    * Remove all profile points.
162    */
163   HYDRODATA_EXPORT void RemovePoints();
164
165
166   /**
167    * Replace current profile parametric points by new one.
168    * \param thePoints the list with new points in parametric form
169    */
170   HYDRODATA_EXPORT void SetParametricPoints( const HYDROData_ProfileUZ::PointsList& thePoints );
171
172   /**
173    * Returns profile points in parametric form.
174    * \return points list
175    */
176   HYDRODATA_EXPORT HYDROData_ProfileUZ::PointsList GetParametricPoints() const;
177
178
179   /**
180    * Replace current profile points by new one.
181    * First and last points will be automatically updated.
182    * \param thePoints the list with new profile points
183    */
184   HYDRODATA_EXPORT void SetProfilePoints( const ProfilePoints& thePoints, bool IsConvertFromGlobal = true );
185
186   /**
187    * Returns profile points.
188    * Empty sequence is returned if first or last point was not set.
189    * \return profile points list
190    */
191   HYDRODATA_EXPORT ProfilePoints GetProfilePoints( bool IsConvertToGlobal = false,
192                                                    bool CanUseDefaultLeftRight = false ) const;
193
194
195   /**
196    * Return profile point with minimal Z value.
197    * \return non-parametric profile point
198    */
199   HYDRODATA_EXPORT ProfilePoint GetBottomPoint(bool IsConvertToGlobal = false) const;
200
201   /**
202    * Return profile middle point.
203    * \return non-parametric profile point
204    */
205   HYDRODATA_EXPORT ProfilePoint GetMiddlePoint( bool CanUseDefault ) const;
206
207 public:
208   // Public methods to work with files.
209
210   /**
211    * Stores the profile file path
212    * \param theFilePath profile file path
213    */
214   HYDRODATA_EXPORT void SetFilePath( const TCollection_AsciiString& theFilePath );
215
216   /**
217    * Returns uploaded profile file path
218    */
219   HYDRODATA_EXPORT TCollection_AsciiString  GetFilePath() const;
220
221
222   HYDRODATA_EXPORT void SetProfileColor( const QColor& theColor );
223
224   HYDRODATA_EXPORT bool GetProfileColor(QColor&) const;
225
226
227   /**
228    * Imports Profile data from file. The supported file types:
229    *  - parametric presentation of profile (2 points in line U,Z)
230    *  - georeferenced presentation of profile (3 points in line X,Y,Z)
231    * Create as many objects as many profiles in the file are defined.
232    * \param theFileName the path to file
233    * \return \c number of successfully imported profiles
234    */
235   HYDRODATA_EXPORT static int ImportFromFile( const Handle(HYDROData_Document)& theDoc,
236                                                const TCollection_AsciiString&    theFileName,
237                                                NCollection_Sequence<int>&        theBadProfilesIds,
238                                                bool isToProject = true );
239
240   /**
241    * Imports Profile data from file.
242    * \param theFileName the path to file
243    * \param theIsRead set to true if at least one non empty string was read from file
244    * \return \c true if file has been successfully read
245    */
246   HYDRODATA_EXPORT virtual bool ImportFromFile( const TCollection_AsciiString& theFileName,
247                                                 bool isToProject = true,
248                                                 bool* isNotEmpty = 0 );
249
250   /**
251    * Imports Profile data from file. 
252    * \param theFile file to read
253    * \param theIsRead set to true if at least one non empty string was read from file
254    * \return \c true if file has been successfully read
255    */
256   HYDRODATA_EXPORT virtual bool ImportFromFile( OSD_File& theFile,
257                                                 bool isToProject = true,
258                                                 bool* isNotEmpty = 0 );
259
260 protected:
261   /**
262    * Checks and if necessary create child 3D object.
263    * Reimplemented to prevent creation of 3D child object.
264    */
265   HYDRODATA_EXPORT virtual void checkAndSetObject3D() {}
266
267   TopoDS_Shape CreateProfileWire( bool canUseDefaultPoints, bool reverseXCoord = false) const;
268
269   static void ProjectProfilePoints( ProfilePoints& thePoints );
270
271 protected:
272
273   friend class HYDROData_Iterator;
274
275   /**
276    * Creates new object in the internal data structure. Use higher level objects 
277    * to create objects with real content.
278    */
279   HYDRODATA_EXPORT HYDROData_Profile();
280
281   /**
282    * Destructs properties of the object and object itself, removes it from the document.
283    */
284   HYDRODATA_EXPORT ~HYDROData_Profile();
285 };
286
287 #endif