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