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