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