Salome HOME
Merge commit '9dd90968eb8ad86e7e6ae67f48bb6110bd4ffbdc' into BR_LCM_COMP
[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_LandCoverMap);
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
100     DataTag_LandCover_Obsolete,                 ///< reference land covers
101     DataTag_CustomLandCoverRules_Obsolete,      ///< custom rules for land covers priority
102     DataTag_AssignmentLandCoverMode_Obsolete,   ///< assignment mode of land covers priority
103     DataTag_ChildLandCoverRegion_Obsolete,      ///< child land cover regions
104     DataTag_LandCoverRegion_Obsolete,           ///< reference land cover regions
105
106     DataTag_LandCoverMap,              ///< reference to land cover map
107   };
108
109 public:
110
111   DEFINE_STANDARD_RTTI(HYDROData_CalculationCase);
112
113   /**
114    * Returns the kind of this object. Must be redefined in all objects of known type.
115    */
116   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_CALCULATION; }
117
118   /**
119    * Updates the name of this object.
120    * Reimplemented to update the names of regions, zones and splitted groups.
121    */
122   HYDRODATA_EXPORT virtual void SetName( const QString& theName );  
123
124   /**
125    * Dump Calculation object to Python script representation.
126    */
127   HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
128                                                      MapOfTreatedObjects& theTreatedObjects ) const;
129
130   /**
131    * Update the calcualtion case object.
132    * Call this method whenever you made changes for object data.
133    */
134   HYDRODATA_EXPORT virtual void Update();
135
136   /**
137    * Returns the list of all reference objects of this object.
138    */
139   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
140
141 public:      
142   // Public methods to work with Calculation
143
144   /**
145    * Add new one reference geometry object for calculation case.
146    */
147   HYDRODATA_EXPORT virtual bool AddGeometryObject( const Handle(HYDROData_Object)& theObject );
148
149   /**
150    * Returns all reference geometry objects of calculation case.
151    */
152   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const;
153
154   /**
155    * Removes reference geometry object from calculation case.
156    * \param theObject the object to remove
157    */
158   HYDRODATA_EXPORT virtual void RemoveGeometryObject( const Handle(HYDROData_Object)& theObject );
159
160   /**
161    * Removes all reference geometry objects from calculation case.
162    */
163   HYDRODATA_EXPORT virtual void RemoveGeometryObjects();
164
165
166   /**
167    * Add new one reference geometry group for calculation case.
168    * \param theGroup the group to add
169    */
170   HYDRODATA_EXPORT virtual bool AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup );
171
172   /**
173    * Returns all reference geometry groups of calculation case.
174    */
175   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryGroups() const;
176
177   /**
178    * Removes reference geometry group from calculation case.
179    * \param theGroup the group to remove
180    */
181   HYDRODATA_EXPORT virtual void RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup );
182
183   /**
184    * Removes all reference geometry groups from calculation case.
185    */
186   HYDRODATA_EXPORT virtual void RemoveGeometryGroups();
187
188
189   /**
190    * Sets reference boundary polyline object for calculation case.
191    */
192   HYDRODATA_EXPORT virtual void SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline );
193
194   /**
195    * Returns reference boundary polyline object of calculation case.
196    */
197   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetBoundaryPolyline() const;
198
199   /**
200    * Remove reference boundary polyline object from calculation case.
201    */
202   HYDRODATA_EXPORT virtual void RemoveBoundaryPolyline();
203
204
205   /**
206    * Sets reference Strickler table for calculation case.
207    */
208   HYDRODATA_EXPORT virtual void SetStricklerTable( const Handle(HYDROData_StricklerTable)& theStricklerTable );
209
210   /**
211    * Returns reference Strickler table of calculation case.
212    */
213   HYDRODATA_EXPORT virtual Handle(HYDROData_StricklerTable) GetStricklerTable() const;
214
215   /**
216    * Remove reference Strickler table from calculation case.
217    */
218   HYDRODATA_EXPORT virtual void RemoveStricklerTable();
219
220   /**
221    * Returns reference Land Cover Map of calculation case.
222    * \return the referenced Land Cover Map
223    */
224   HYDRODATA_EXPORT Handle(HYDROData_LandCoverMap) GetLandCoverMap() const;
225
226   HYDRODATA_EXPORT void SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& );
227
228   /**
229    * Add new one child region for calculation case.
230    * The new region is added into the list of reference regions.
231    * The label of theZone is changed during this operation
232    * because of new region becomes the new parent for this zone.
233    * \return the created region
234    */
235   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion( const Handle(HYDROData_Zone)& theZone ); 
236
237
238   /**
239    * Add new one reference region for calculation case.
240    * The label of theRegion is changed in case if old parent is not this calculation.
241    * \return true in case of success
242    */
243   HYDRODATA_EXPORT virtual bool AddRegion( const Handle(HYDROData_Region)& theRegion );
244
245   /**
246    * Returns all reference regions of calculation case.
247    * \return the list of reference regions
248    */
249   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetRegions() const;
250
251   /**
252    * Updates names of regions to correct order.
253    */
254   HYDRODATA_EXPORT virtual void UpdateRegionsOrder();
255
256   /**
257    * Removes reference region from calculation case.
258    * \param theRegion the region to remove
259    */
260   HYDRODATA_EXPORT virtual void RemoveRegion( const Handle(HYDROData_Region)& theRegion ); 
261
262   /**
263    * Removes all reference regions from calculation case.
264    */
265   HYDRODATA_EXPORT virtual void RemoveRegions();
266
267   /**
268    * Returns all reference geometry groups of calculation case.
269    */
270   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetSplittedGroups() const;
271
272   /**
273    * Removes all reference geometry groups from calculation case.
274    */
275   HYDRODATA_EXPORT virtual void RemoveSplittedGroups();
276
277   /**
278    * Exports the calculation case data (shell and groups) to GEOM module.
279    * \param theStudyId the id of the study where the GEOM module should be used for export
280    * \return the entry of the GEOM object (empty string in the case of error)
281    */
282   HYDRODATA_EXPORT virtual QString Export( int theStudyId ) const;
283
284   /**
285    * Exports the calculation case data (shell and groups) to GEOM module.
286    * \param theGeomEngine GEOM module engine
287    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
288    * \param theGeomObjEntry the published GEOM object entry
289    * \param theErrorMsg the error message
290    * \return true in case of success
291    */
292 #ifndef LIGHT_MODE
293   HYDRODATA_EXPORT virtual bool Export( GEOM::GEOM_Gen_var  theGeomEngine,
294                                         SALOMEDS::Study_ptr theStudy,
295                                         QString& theGeomObjEntry,
296                                         QString& theErrorMsg ) const;
297 #endif
298
299 public:      
300   // Public methods to work with Calculation services
301
302   /**
303    * Returns altitude for given point.
304    * \param thePoint the point to examine
305    * \return result altitude value
306    */
307   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const;
308
309   /**
310    * Returns altitude for given point on given region.
311    * \param thePoint the point to examine
312    * \param theRegion reference region to check
313    * \return result altitude value
314    */
315   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                    thePoint,
316                                                        const Handle(HYDROData_Region)& theRegion ) const;
317
318   /**
319    * Returns altitude for given point on given zone.
320    * \param thePoint the point to examine
321    * \param theZone reference zone to check
322    * \return result altitude value
323    */
324   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                  thePoint,
325                                                        const Handle(HYDROData_Zone)& theZone ) const;
326
327   /**
328    * Returns strickler coefficient for given point.
329    * \param thePoint the point to examine
330    * \return result strickler coefficient
331    */
332   HYDRODATA_EXPORT double GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const;
333
334   /**
335    * Returns altitudes for given points on given region.
336    * \param thePoints the points to examine
337    * \param theRegion reference region to check
338    * \return result altitude value
339    */
340   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
341     const NCollection_Sequence<gp_XY>& thePoints,
342     const Handle(HYDROData_Region)&    theRegion ) const;
343
344   /**
345    * Returns altitudes for given points on given zone.
346    * \param thePoints the points to examine
347    * \param theZone reference zone 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_Zone)&      theZone ) const;
353
354   /**
355    * Returns region to which the point is belongs.
356    * \param thePoint the point to examine
357    * if it is needed to search Land Cover region
358    * \return result region
359    */
360   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) GetRegionFromPoint( const gp_XY& thePoint ) const;
361
362   /**
363    * Returns zone to which the point is belongs.
364    * \param thePoint the point to examine
365    * if it is needed to search Land Cover zone
366    * \return result zone
367    */
368   HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZoneFromPoint( const gp_XY& thePoint ) const;
369
370   /**
371    * Returns classification of point for given zone.
372    * \param thePoint the point to examine
373    * \param theZone the zone to examine
374    * \return result classification
375    */
376   HYDRODATA_EXPORT virtual PointClassification GetPointClassification(
377     const gp_XY&                  thePoint,
378     const Handle(HYDROData_Zone)& theZone ) const;
379
380   HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode );
381   HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const;
382
383   HYDRODATA_EXPORT void ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
384                                     const bool theIsSetToUpdate = true );
385   HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Entity)&     theObject1,
386                                  HYDROData_PriorityType              thePriority,
387                                  const Handle(HYDROData_Entity)&     theObject2,
388                                  HYDROData_Zone::MergeType theMergeType,
389                                  HYDROData_CalculationCase::DataTag  theDataTag );
390   HYDRODATA_EXPORT bool GetRule( int theIndex, 
391                                  Handle(HYDROData_Entity)&           theObject1,
392                                  HYDROData_PriorityType&             thePriority,
393                                  Handle(HYDROData_Entity)&           theObject2,
394                                  HYDROData_Zone::MergeType& theMergeType,
395                                  HYDROData_CalculationCase::DataTag& theDataTag ) const;
396
397   HYDRODATA_EXPORT QString DumpRules() const;
398
399   HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const;
400
401 private:
402
403   /**
404    * Add new one region for calculation case.
405    * The new region is added into the list of reference regions.
406    */
407   Handle(HYDROData_Region) addNewRegion( const Handle(HYDROData_Document)& theDoc,
408                                          const QString& thePrefixOrName,
409                                          bool isPrefix = true );
410
411   /**
412    * Add new one splitted edges group for calculation case.
413    */
414   Handle(HYDROData_SplittedShapesGroup) addNewSplittedGroup( const QString& theName );
415
416   /**
417    * Exports the given faces as shell and the given groups to GEOM module.
418    * \param theGeomEngine GEOM module engine
419    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
420    * \param theFaces the list of faces to make shell 
421    * \param theSplittedGroups the list of groups
422    * \return true in case of success
423    */
424 #ifndef LIGHT_MODE
425   bool Export( GEOM::GEOM_Gen_var                            theGeomEngine,
426                SALOMEDS::Study_ptr                           theStudy,
427                const TopTools_ListOfShape&                   theFaces,
428                const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
429                QString& theGeomObjEntry ) const;
430 #endif
431   
432   void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
433                          const HYDROData_SplitToZonesTool::SplitDataList& theZones );
434   void CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
435                           const HYDROData_SplitToZonesTool::SplitDataList& theZones );
436
437   void CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
438                             const HYDROData_SplitToZonesTool::SplitDataList& theEdges );
439
440   void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const;
441
442   void SetWarning( HYDROData_WarningType theType = WARN_OK, const QString& theData = "" );
443
444   void UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
445                            const QString& theOldCaseName,
446                            const QString& theName );
447   
448   void DumpRegionsToPython( QStringList&                       theResList,
449                             const QString&                     thePyScriptPath,
450                             MapOfTreatedObjects&               theTreatedObjects,
451                             const HYDROData_SequenceOfObjects& theRegions ) const;
452
453 protected:
454   friend class HYDROData_Iterator;
455
456   /**
457    * Creates new object in the internal data structure. Use higher level objects 
458    * to create objects with real content.
459    */
460   HYDRODATA_EXPORT HYDROData_CalculationCase();
461
462   /**
463    * Destructs properties of the object and object itself, removes it from the document.
464    */
465   HYDRODATA_EXPORT ~HYDROData_CalculationCase();
466
467   void DumpSampleMeshing( QStringList& theScript,
468                           const QString& theStudyName,
469                           const QString& theGeomShapeName,
470                           const QString& theMeshName ) const;
471
472 private:
473   HYDROData_Warning myLastWarning;
474 };
475
476 #endif