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