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