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