Salome HOME
Merge branch 'BR_LAND_COVER_MAP' into BR_DBF_SUPPORT
[modules/hydro.git] / src / HYDROData / HYDROData_CalculationCase.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_CalculationCase_HeaderFile
20 #define HYDROData_CalculationCase_HeaderFile
21
22 #include <HYDROData_ShapesGroup.h>
23 #include <HYDROData_SplitToZonesTool.h>
24 #include <HYDROData_PriorityQueue.h>
25 #include <HYDROData_Zone.h>
26 #include <HYDROData_Warning.h>
27
28 #ifdef WIN32
29   #pragma warning ( disable: 4251 )
30 #endif
31
32 #ifndef LIGHT_MODE
33 // IDL includes
34 #include <SALOMEconfig.h>
35 #include CORBA_SERVER_HEADER(GEOM_Gen)
36 #endif
37
38 #ifdef WIN32
39   #pragma warning( default: 4251 )
40 #endif
41
42 class gp_XY;
43
44 class TopoDS_Shape;
45 class TopoDS_Shell;
46 class TopTools_ListOfShape;
47
48 class Handle(HYDROData_Object);
49 class Handle(HYDROData_Region);
50 class Handle(HYDROData_Zone);
51 class Handle(HYDROData_PolylineXY);
52 class Handle(HYDROData_ShapesGroup);
53 class Handle(HYDROData_SplittedShapesGroup);
54 class Handle(HYDROData_Document);
55 class Handle(HYDROData_StricklerTable);
56 class Handle(HYDROData_LandCover);
57
58 DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
59
60
61 /**\class HYDROData_CalculationCase
62  * \brief Calculation case is defined by selection of Geometry objects with or without \93Zone of water\94.
63  *
64  */
65 class HYDROData_CalculationCase : public HYDROData_Entity
66 {
67 public:
68
69   enum PointClassification
70   {
71     POINT_OUT,  ///< point is out of zone face
72     POINT_IN,   ///< point is inside of zone face
73     POINT_ON    ///< point is on the edge of zone face
74   };
75
76   enum AssignmentMode
77   {
78     MANUAL = 0,
79     AUTOMATIC,
80   };
81
82 public:
83
84   /**
85    * Enumeration of tags corresponding to the persistent object parameters.
86    */
87   enum DataTag
88   {
89     DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
90     DataTag_GeometryObject,            ///< reference geometry objects
91     DataTag_ChildRegion,               ///< child regions
92     DataTag_Region,                    ///< reference regions
93     DataTag_Polyline,                  ///< reference boundary polyline
94     DataTag_GeometryGroup,             ///< reference geometry groups
95     DataTag_SplittedGroups,            ///< reference splitted groups
96     DataTag_CustomRules,               ///< custom rules
97     DataTag_AssignmentMode,            ///< assignment mode
98     DataTag_StricklerTable,            ///< reference Strickler table
99     DataTag_LandCover,                 ///< reference land covers
100     DataTag_CustomLandCoverRules,      ///< custom rules for land covers priority
101     DataTag_AssignmentLandCoverMode,   ///< assignment mode of land covers priority
102     DataTag_ChildLandCoverRegion,      ///< child land cover regions
103     DataTag_LandCoverRegion            ///< reference land cover regions
104   };
105
106 public:
107
108   DEFINE_STANDARD_RTTI(HYDROData_CalculationCase);
109
110   /**
111    * Returns the kind of this object. Must be redefined in all objects of known type.
112    */
113   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_CALCULATION; }
114
115   /**
116    * Updates the name of this object.
117    * Reimplemented to update the names of regions, zones and splitted groups.
118    */
119   HYDRODATA_EXPORT virtual void SetName( const QString& theName );  
120
121   /**
122    * Dump Calculation object to Python script representation.
123    */
124   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
125
126   /**
127    * Update the calcualtion case object.
128    * Call this method whenever you made changes for object data.
129    */
130   HYDRODATA_EXPORT virtual void Update();
131
132   /**
133    * Returns the list of all reference objects of this object.
134    */
135   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
136
137 public:      
138   // Public methods to work with Calculation
139
140   /**
141    * Add new one reference geometry object for calculation case.
142    */
143   HYDRODATA_EXPORT virtual bool AddGeometryObject( const Handle(HYDROData_Object)& theObject );
144
145   /**
146    * Returns all reference geometry objects of calculation case.
147    */
148   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const;
149
150   /**
151    * Removes reference geometry object from calculation case.
152    * \param theObject the object to remove
153    */
154   HYDRODATA_EXPORT virtual void RemoveGeometryObject( const Handle(HYDROData_Object)& theObject );
155
156   /**
157    * Removes all reference geometry objects from calculation case.
158    */
159   HYDRODATA_EXPORT virtual void RemoveGeometryObjects();
160
161
162   /**
163    * Add new one reference geometry group for calculation case.
164    * \param theGroup the group to add
165    */
166   HYDRODATA_EXPORT virtual bool AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup );
167
168   /**
169    * Returns all reference geometry groups of calculation case.
170    */
171   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryGroups() const;
172
173   /**
174    * Removes reference geometry group from calculation case.
175    * \param theGroup the group to remove
176    */
177   HYDRODATA_EXPORT virtual void RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup );
178
179   /**
180    * Removes all reference geometry groups from calculation case.
181    */
182   HYDRODATA_EXPORT virtual void RemoveGeometryGroups();
183
184
185   /**
186    * Sets reference boundary polyline object for calculation case.
187    */
188   HYDRODATA_EXPORT virtual void SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline );
189
190   /**
191    * Returns reference boundary polyline object of calculation case.
192    */
193   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetBoundaryPolyline() const;
194
195   /**
196    * Remove reference boundary polyline object from calculation case.
197    */
198   HYDRODATA_EXPORT virtual void RemoveBoundaryPolyline();
199
200
201   /**
202    * Sets reference Strickler table for calculation case.
203    */
204   HYDRODATA_EXPORT virtual void SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable );
205
206   /**
207    * Returns reference Strickler table of calculation case.
208    */
209   HYDRODATA_EXPORT virtual Handle(HYDROData_StricklerTable) GetStricklerTable() const;
210
211   /**
212    * Remove reference Strickler table from calculation case.
213    */
214   HYDRODATA_EXPORT virtual void RemoveStricklerTable();
215
216
217   /**
218    * Add new one reference Land Cover for calculation case.
219    * \param theLandCover the Land Cover to add
220    * \return true in case of success
221    */
222   HYDRODATA_EXPORT virtual bool AddLandCover( const Handle(HYDROData_LandCover)& theLandCover );
223
224   /**
225    * Returns all reference Land Covers of calculation case.
226    * \return the list of referenced Land Covers
227    */
228   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetLandCovers() const;
229
230   /**
231    * Removes reference Land Cover from calculation case.
232    * \param theLandCover the Land Cover to remove
233    */
234   HYDRODATA_EXPORT virtual void RemoveLandCover( const Handle(HYDROData_LandCover)& theLandCover );
235
236   /**
237    * Removes all reference Land Covers from calculation case.
238    */
239   HYDRODATA_EXPORT virtual void RemoveLandCovers();
240
241
242   /**
243    * Add new one child region for calculation case.
244    * The new region is added into the list of reference regions.
245    * The label of theZone is changed during this operation
246    * because of new region becomes the new parent for this zone.
247    * \param theLandCover if true - Land Cover region will be added
248    * \return the created region
249    */
250   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion( const Handle(HYDROData_Zone)& theZone,
251                                                                   const bool theLandCover ); 
252
253
254   /**
255    * Add new one reference region for calculation case.
256    * The label of theRegion is changed in case if old parent is not this calculation.
257    * \param theLandCover if true - Land Cover region will bw created
258    * \return true in case of success
259    */
260   HYDRODATA_EXPORT virtual bool AddRegion( const Handle(HYDROData_Region)& theRegion,
261                                            const bool theLandCover );
262
263   /**
264    * Returns all reference regions of calculation case.
265    * \param theLandCover if true - Land Cover regions will be returned
266    * \return the list of reference regions
267    */
268   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetRegions( const bool theLandCover ) const;
269
270   /**
271    * Updates names of regions to correct order.
272    */
273   HYDRODATA_EXPORT virtual void UpdateRegionsOrder();
274
275   /**
276    * Removes reference region from calculation case.
277    * \param theRegion the region to remove
278    * \param theLandCover if true - it means that Land Cover region to be removed
279    */
280   HYDRODATA_EXPORT virtual void RemoveRegion( const Handle(HYDROData_Region)& theRegion,
281                                               const bool theLandCover ); 
282
283   /**
284    * Removes all reference regions from calculation case.
285    * \param theLandCover if true - it means that Land Cover regions to be removed
286    */
287   HYDRODATA_EXPORT virtual void RemoveRegions( const bool theLandCover );
288
289   /**
290    * Returns all reference geometry groups of calculation case.
291    */
292   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetSplittedGroups() const;
293
294   /**
295    * Removes all reference geometry groups from calculation case.
296    */
297   HYDRODATA_EXPORT virtual void RemoveSplittedGroups();
298
299   /**
300    * Exports the calculation case data (shell and groups) to GEOM module.
301    * \param theStudyId the id of the study where the GEOM module should be used for export
302    * \return the entry of the GEOM object (empty string in the case of error)
303    */
304   HYDRODATA_EXPORT virtual QString Export( int theStudyId ) const;
305
306   /**
307    * Exports the calculation case data (shell and groups) to GEOM module.
308    * \param theGeomEngine GEOM module engine
309    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
310    * \param theGeomObjEntry the published GEOM object entry
311    * \param theErrorMsg the error message
312    * \return true in case of success
313    */
314 #ifndef LIGHT_MODE
315   HYDRODATA_EXPORT virtual bool Export( GEOM::GEOM_Gen_var  theGeomEngine,
316                                         SALOMEDS::Study_ptr theStudy,
317                                         QString& theGeomObjEntry,
318                                         QString& theErrorMsg ) const;
319 #endif
320
321 public:      
322   // Public methods to work with Calculation services
323
324   /**
325    * Returns altitude for given point.
326    * \param thePoint the point to examine
327    * \return result altitude value
328    */
329   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const;
330
331   /**
332    * Returns altitude for given point on given region.
333    * \param thePoint the point to examine
334    * \param theRegion reference region to check
335    * \return result altitude value
336    */
337   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                    thePoint,
338                                                        const Handle(HYDROData_Region)& theRegion ) const;
339
340   /**
341    * Returns altitude for given point on given zone.
342    * \param thePoint the point to examine
343    * \param theZone reference zone to check
344    * \return result altitude value
345    */
346   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                  thePoint,
347                                                        const Handle(HYDROData_Zone)& theZone ) const;
348
349   /**
350    * Returns strickler coefficient for given point.
351    * \param thePoint the point to examine
352    * \return result strickler coefficient
353    */
354   HYDRODATA_EXPORT double GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const;
355
356   /**
357    * Returns altitudes for given points on given region.
358    * \param thePoints the points to examine
359    * \param theRegion reference region to check
360    * \return result altitude value
361    */
362   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
363     const NCollection_Sequence<gp_XY>& thePoints,
364     const Handle(HYDROData_Region)&    theRegion ) const;
365
366   /**
367    * Returns altitudes for given points on given zone.
368    * \param thePoints the points to examine
369    * \param theZone reference zone to check
370    * \return result altitude value
371    */
372   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
373     const NCollection_Sequence<gp_XY>& thePoints,
374     const Handle(HYDROData_Zone)&      theZone ) const;
375
376   /**
377    * Returns region to which the point is belongs.
378    * \param thePoint the point to examine
379    * \param theLandCover the flag indicating,
380    * if it is needed to search Land Cover region
381    * \return result region
382    */
383   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) GetRegionFromPoint( const gp_XY& thePoint,
384                                                                         const bool theLandCover ) const;
385
386   /**
387    * Returns zone to which the point is belongs.
388    * \param thePoint the point to examine
389    * \param theLandCover the flag indicating,
390    * if it is needed to search Land Cover zone
391    * \return result zone
392    */
393   HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZoneFromPoint( const gp_XY& thePoint,
394                                                                     const bool theLandCover ) const;
395
396   /**
397    * Returns classification of point for given zone.
398    * \param thePoint the point to examine
399    * \param theZone the zone to examine
400    * \return result classification
401    */
402   HYDRODATA_EXPORT virtual PointClassification GetPointClassification(
403     const gp_XY&                  thePoint,
404     const Handle(HYDROData_Zone)& theZone ) const;
405
406   HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode );
407   HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const;
408
409   HYDRODATA_EXPORT void ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
410                                     const bool theIsSetToUpdate = true );
411   HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Entity)&     theObject1,
412                                  HYDROData_PriorityType              thePriority,
413                                  const Handle(HYDROData_Entity)&     theObject2,
414                                  HYDROData_Zone::MergeType theMergeType,
415                                  HYDROData_CalculationCase::DataTag  theDataTag );
416   HYDRODATA_EXPORT bool GetRule( int theIndex, 
417                                  Handle(HYDROData_Entity)&           theObject1,
418                                  HYDROData_PriorityType&             thePriority,
419                                  Handle(HYDROData_Entity)&           theObject2,
420                                  HYDROData_Zone::MergeType& theMergeType,
421                                  HYDROData_CalculationCase::DataTag& theDataTag ) const;
422
423   HYDRODATA_EXPORT void SetAssignmentLandCoverMode( AssignmentMode theMode );
424   HYDRODATA_EXPORT AssignmentMode GetAssignmentLandCoverMode() const;
425
426   HYDRODATA_EXPORT QString DumpRules() const;
427   HYDRODATA_EXPORT QString DumpLandCoverRules() const;
428
429   HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const;
430
431 private:
432
433   /**
434    * Add new one region for calculation case.
435    * The new region is added into the list of reference regions.
436    */
437   Handle(HYDROData_Region) addNewRegion( const Handle(HYDROData_Document)& theDoc,
438                                          const QString& thePrefixOrName,
439                                          const bool theLandCover,
440                                          bool isPrefix = true );
441
442   /**
443    * Add new one splitted edges group for calculation case.
444    */
445   Handle(HYDROData_SplittedShapesGroup) addNewSplittedGroup( const QString& theName );
446
447   /**
448    * Exports the given faces as shell and the given groups to GEOM module.
449    * \param theGeomEngine GEOM module engine
450    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
451    * \param theFaces the list of faces to make shell 
452    * \param theSplittedGroups the list of groups
453    * \return true in case of success
454    */
455 #ifndef LIGHT_MODE
456   bool Export( GEOM::GEOM_Gen_var                            theGeomEngine,
457                SALOMEDS::Study_ptr                           theStudy,
458                const TopTools_ListOfShape&                   theFaces,
459                const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
460                QString& theGeomObjEntry ) const;
461 #endif
462   
463   void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
464                          const HYDROData_SplitToZonesTool::SplitDataList& theZones,
465                          const bool theLandCover );
466   void CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
467                           const HYDROData_SplitToZonesTool::SplitDataList& theZones,
468                           const bool theLandCover );
469
470   void CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
471                             const HYDROData_SplitToZonesTool::SplitDataList& theEdges );
472
473   void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const;
474   void DumpLandCoverRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const;
475
476   void SetWarning( HYDROData_WarningType theType = WARN_OK, const QString& theData = "" );
477
478   void UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
479                            const QString& theOldCaseName,
480                            const QString& theName );
481   
482   void DumpRegionsToPython( QStringList& theResList,
483                             MapOfTreatedObjects& theTreatedObjects,
484                             const HYDROData_SequenceOfObjects& theRegions ) const;
485
486 protected:
487   friend class HYDROData_Iterator;
488
489   /**
490    * Creates new object in the internal data structure. Use higher level objects 
491    * to create objects with real content.
492    */
493   HYDRODATA_EXPORT HYDROData_CalculationCase();
494
495   /**
496    * Destructs properties of the object and object itself, removes it from the document.
497    */
498   HYDRODATA_EXPORT ~HYDROData_CalculationCase();
499
500   void DumpSampleMeshing( QStringList& theScript,
501                           const QString& theStudyName,
502                           const QString& theGeomShapeName,
503                           const QString& theMeshName ) const;
504
505 private:
506   HYDROData_Warning myLastWarning;
507 };
508
509 #endif