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