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