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