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