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